Merge branch 'mesa_7_5_branch'
[mesa.git] / src / mesa / drivers / dri / swrast / swrast.c
1 /*
2 * Copyright (C) 2008 George Sapountzis <gsap7@yahoo.gr>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 */
21
22 /*
23 * DRI software rasterizer
24 *
25 * This is the mesa swrast module packaged into a DRI driver structure.
26 *
27 * The front-buffer is allocated by the loader. The loader provides read/write
28 * callbacks for access to the front-buffer. The driver uses a scratch row for
29 * front-buffer rendering to avoid repeated calls to the loader.
30 *
31 * The back-buffer is allocated by the driver and is private.
32 */
33
34 #include "main/context.h"
35 #include "main/extensions.h"
36 #include "main/framebuffer.h"
37 #include "main/imports.h"
38 #include "main/renderbuffer.h"
39 #include "swrast/swrast.h"
40 #include "swrast_setup/swrast_setup.h"
41 #include "tnl/tnl.h"
42 #include "tnl/t_context.h"
43 #include "tnl/t_pipeline.h"
44 #include "vbo/vbo.h"
45 #include "drivers/common/driverfuncs.h"
46 #include "utils.h"
47
48 #include "swrast_priv.h"
49
50
51 #define need_GL_VERSION_1_3
52 #define need_GL_VERSION_1_4
53 #define need_GL_VERSION_1_5
54 #define need_GL_VERSION_2_0
55 #define need_GL_VERSION_2_1
56
57 /* sw extensions for imaging */
58 #define need_GL_EXT_blend_color
59 #define need_GL_EXT_blend_minmax
60 #define need_GL_EXT_convolution
61 #define need_GL_EXT_histogram
62 #define need_GL_SGI_color_table
63
64 /* sw extensions not associated with some GL version */
65 #define need_GL_ARB_shader_objects
66 #define need_GL_ARB_vertex_array_object
67 #define need_GL_ARB_vertex_program
68 #define need_GL_APPLE_vertex_array_object
69 #define need_GL_ATI_fragment_shader
70 #define need_GL_ATI_separate_stencil
71 #define need_GL_EXT_depth_bounds_test
72 #define need_GL_EXT_framebuffer_object
73 #define need_GL_EXT_framebuffer_blit
74 #define need_GL_EXT_gpu_program_parameters
75 #define need_GL_EXT_paletted_texture
76 #define need_GL_EXT_stencil_two_side
77 #define need_GL_MESA_resize_buffers
78 #define need_GL_NV_vertex_program
79 #define need_GL_NV_fragment_program
80
81 #include "extension_helper.h"
82
83 const struct dri_extension card_extensions[] =
84 {
85 { "GL_VERSION_1_3", GL_VERSION_1_3_functions },
86 { "GL_VERSION_1_4", GL_VERSION_1_4_functions },
87 { "GL_VERSION_1_5", GL_VERSION_1_5_functions },
88 { "GL_VERSION_2_0", GL_VERSION_2_0_functions },
89 { "GL_VERSION_2_1", GL_VERSION_2_1_functions },
90
91 { "GL_EXT_blend_color", GL_EXT_blend_color_functions },
92 { "GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions },
93 { "GL_EXT_convolution", GL_EXT_convolution_functions },
94 { "GL_EXT_histogram", GL_EXT_histogram_functions },
95 { "GL_SGI_color_table", GL_SGI_color_table_functions },
96
97 { "GL_ARB_shader_objects", GL_ARB_shader_objects_functions },
98 { "GL_ARB_vertex_array_object", GL_ARB_vertex_array_object_functions },
99 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions },
100 { "GL_APPLE_vertex_array_object", GL_APPLE_vertex_array_object_functions },
101 { "GL_ATI_fragment_shader", GL_ATI_fragment_shader_functions },
102 { "GL_ATI_separate_stencil", GL_ATI_separate_stencil_functions },
103 { "GL_EXT_depth_bounds_test", GL_EXT_depth_bounds_test_functions },
104 { "GL_EXT_framebuffer_object", GL_EXT_framebuffer_object_functions },
105 { "GL_EXT_framebuffer_blit", GL_EXT_framebuffer_blit_functions },
106 { "GL_EXT_gpu_program_parameters", GL_EXT_gpu_program_parameters_functions },
107 { "GL_EXT_paletted_texture", GL_EXT_paletted_texture_functions },
108 { "GL_EXT_stencil_two_side", GL_EXT_stencil_two_side_functions },
109 { "GL_MESA_resize_buffers", GL_MESA_resize_buffers_functions },
110 { "GL_NV_vertex_program", GL_NV_vertex_program_functions },
111 { "GL_NV_fragment_program", GL_NV_fragment_program_functions },
112 { NULL, NULL }
113 };
114
115
116 /**
117 * Screen and config-related functions
118 */
119
120 static void
121 setupLoaderExtensions(__DRIscreen *psp,
122 const __DRIextension **extensions)
123 {
124 int i;
125
126 for (i = 0; extensions[i]; i++) {
127 if (strcmp(extensions[i]->name, __DRI_SWRAST_LOADER) == 0)
128 psp->swrast_loader = (__DRIswrastLoaderExtension *) extensions[i];
129 }
130 }
131
132 static __DRIconfig **
133 swrastFillInModes(__DRIscreen *psp,
134 unsigned pixel_bits, unsigned depth_bits,
135 unsigned stencil_bits, GLboolean have_back_buffer)
136 {
137 __DRIconfig **configs;
138 unsigned depth_buffer_factor;
139 unsigned back_buffer_factor;
140 GLenum fb_format;
141 GLenum fb_type;
142
143 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
144 * support pageflipping at all.
145 */
146 static const GLenum back_buffer_modes[] = {
147 GLX_NONE, GLX_SWAP_UNDEFINED_OML
148 };
149
150 uint8_t depth_bits_array[4];
151 uint8_t stencil_bits_array[4];
152 uint8_t msaa_samples_array[1];
153
154 depth_bits_array[0] = 0;
155 depth_bits_array[1] = 0;
156 depth_bits_array[2] = depth_bits;
157 depth_bits_array[3] = depth_bits;
158
159 /* Just like with the accumulation buffer, always provide some modes
160 * with a stencil buffer.
161 */
162 stencil_bits_array[0] = 0;
163 stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits;
164 stencil_bits_array[2] = 0;
165 stencil_bits_array[3] = (stencil_bits == 0) ? 8 : stencil_bits;
166
167 msaa_samples_array[0] = 0;
168
169 depth_buffer_factor = 4;
170 back_buffer_factor = 2;
171
172 switch (pixel_bits) {
173 case 8:
174 fb_format = GL_RGB;
175 fb_type = GL_UNSIGNED_BYTE_2_3_3_REV;
176 break;
177 case 16:
178 fb_format = GL_RGB;
179 fb_type = GL_UNSIGNED_SHORT_5_6_5;
180 break;
181 case 24:
182 fb_format = GL_BGR;
183 fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
184 break;
185 case 32:
186 fb_format = GL_BGRA;
187 fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
188 break;
189 default:
190 fprintf(stderr, "[%s:%u] bad depth %d\n", __func__, __LINE__,
191 pixel_bits);
192 return NULL;
193 }
194
195 configs = driCreateConfigs(fb_format, fb_type,
196 depth_bits_array, stencil_bits_array,
197 depth_buffer_factor, back_buffer_modes,
198 back_buffer_factor, msaa_samples_array, 1);
199 if (configs == NULL) {
200 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
201 __LINE__);
202 return NULL;
203 }
204
205 return configs;
206 }
207
208 static __DRIscreen *
209 driCreateNewScreen(int scrn, const __DRIextension **extensions,
210 const __DRIconfig ***driver_configs, void *data)
211 {
212 static const __DRIextension *emptyExtensionList[] = { NULL };
213 __DRIscreen *psp;
214 __DRIconfig **configs8, **configs16, **configs24, **configs32;
215
216 (void) data;
217
218 TRACE;
219
220 psp = _mesa_calloc(sizeof(*psp));
221 if (!psp)
222 return NULL;
223
224 setupLoaderExtensions(psp, extensions);
225
226 psp->num = scrn;
227 psp->extensions = emptyExtensionList;
228
229 configs8 = swrastFillInModes(psp, 8, 8, 0, 1);
230 configs16 = swrastFillInModes(psp, 16, 16, 0, 1);
231 configs24 = swrastFillInModes(psp, 24, 24, 8, 1);
232 configs32 = swrastFillInModes(psp, 32, 24, 8, 1);
233
234 configs16 = driConcatConfigs(configs8, configs16);
235 configs24 = driConcatConfigs(configs16, configs24);
236 *driver_configs = (const __DRIconfig **)
237 driConcatConfigs(configs24, configs32);
238
239 driInitExtensions( NULL, card_extensions, GL_FALSE );
240
241 return psp;
242 }
243
244 static void driDestroyScreen(__DRIscreen *psp)
245 {
246 TRACE;
247
248 if (psp) {
249 _mesa_free(psp);
250 }
251 }
252
253 static const __DRIextension **driGetExtensions(__DRIscreen *psp)
254 {
255 TRACE;
256
257 return psp->extensions;
258 }
259
260
261 /**
262 * Framebuffer and renderbuffer-related functions.
263 */
264
265 static GLuint
266 choose_pixel_format(const GLvisual *v)
267 {
268 if (v->rgbMode) {
269 int depth = v->rgbBits;
270
271 if (depth == 32
272 && v->redMask == 0xff0000
273 && v->greenMask == 0x00ff00
274 && v->blueMask == 0x0000ff)
275 return PF_A8R8G8B8;
276 else if (depth == 24
277 && v->redMask == 0xff0000
278 && v->greenMask == 0x00ff00
279 && v->blueMask == 0x0000ff)
280 return PF_X8R8G8B8;
281 else if (depth == 16
282 && v->redMask == 0xf800
283 && v->greenMask == 0x07e0
284 && v->blueMask == 0x001f)
285 return PF_R5G6B5;
286 else if (depth == 8
287 && v->redMask == 0x07
288 && v->greenMask == 0x38
289 && v->blueMask == 0xc0)
290 return PF_R3G3B2;
291 }
292 else {
293 if (v->indexBits == 8)
294 return PF_CI8;
295 }
296
297 _mesa_problem( NULL, "unexpected format in %s", __FUNCTION__ );
298 return 0;
299 }
300
301 static void
302 swrast_delete_renderbuffer(struct gl_renderbuffer *rb)
303 {
304 TRACE;
305
306 _mesa_free(rb->Data);
307 _mesa_free(rb);
308 }
309
310 static GLboolean
311 swrast_alloc_front_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
312 GLenum internalFormat, GLuint width, GLuint height)
313 {
314 struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
315 unsigned mask = PITCH_ALIGN_BITS - 1;
316
317 TRACE;
318
319 rb->Data = NULL;
320 rb->Width = width;
321 rb->Height = height;
322
323 /* always pad to PITCH_ALIGN_BITS */
324 xrb->pitch = ((width * xrb->bpp + mask) & ~mask) / 8;
325
326 return GL_TRUE;
327 }
328
329 static GLboolean
330 swrast_alloc_back_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
331 GLenum internalFormat, GLuint width, GLuint height)
332 {
333 struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
334
335 TRACE;
336
337 _mesa_free(rb->Data);
338
339 swrast_alloc_front_storage(ctx, rb, internalFormat, width, height);
340
341 rb->Data = _mesa_malloc(height * xrb->pitch);
342
343 return GL_TRUE;
344 }
345
346 static struct swrast_renderbuffer *
347 swrast_new_renderbuffer(const GLvisual *visual, GLboolean front)
348 {
349 struct swrast_renderbuffer *xrb = _mesa_calloc(sizeof *xrb);
350 GLuint pixel_format;
351
352 TRACE;
353
354 if (!xrb)
355 return NULL;
356
357 _mesa_init_renderbuffer(&xrb->Base, 0);
358
359 pixel_format = choose_pixel_format(visual);
360
361 xrb->Base.Delete = swrast_delete_renderbuffer;
362 if (front) {
363 xrb->Base.AllocStorage = swrast_alloc_front_storage;
364 swrast_set_span_funcs_front(xrb, pixel_format);
365 }
366 else {
367 xrb->Base.AllocStorage = swrast_alloc_back_storage;
368 swrast_set_span_funcs_back(xrb, pixel_format);
369 }
370
371 switch (pixel_format) {
372 case PF_A8R8G8B8:
373 xrb->Base.InternalFormat = GL_RGBA;
374 xrb->Base._BaseFormat = GL_RGBA;
375 xrb->Base.DataType = GL_UNSIGNED_BYTE;
376 xrb->Base.RedBits = 8 * sizeof(GLubyte);
377 xrb->Base.GreenBits = 8 * sizeof(GLubyte);
378 xrb->Base.BlueBits = 8 * sizeof(GLubyte);
379 xrb->Base.AlphaBits = 8 * sizeof(GLubyte);
380 xrb->bpp = 32;
381 break;
382 case PF_X8R8G8B8:
383 xrb->Base.InternalFormat = GL_RGB;
384 xrb->Base._BaseFormat = GL_RGB;
385 xrb->Base.DataType = GL_UNSIGNED_BYTE;
386 xrb->Base.RedBits = 8 * sizeof(GLubyte);
387 xrb->Base.GreenBits = 8 * sizeof(GLubyte);
388 xrb->Base.BlueBits = 8 * sizeof(GLubyte);
389 xrb->Base.AlphaBits = 0;
390 xrb->bpp = 32;
391 break;
392 case PF_R5G6B5:
393 xrb->Base.InternalFormat = GL_RGB;
394 xrb->Base._BaseFormat = GL_RGB;
395 xrb->Base.DataType = GL_UNSIGNED_BYTE;
396 xrb->Base.RedBits = 5 * sizeof(GLubyte);
397 xrb->Base.GreenBits = 6 * sizeof(GLubyte);
398 xrb->Base.BlueBits = 5 * sizeof(GLubyte);
399 xrb->Base.AlphaBits = 0;
400 xrb->bpp = 16;
401 break;
402 case PF_R3G3B2:
403 xrb->Base.InternalFormat = GL_RGB;
404 xrb->Base._BaseFormat = GL_RGB;
405 xrb->Base.DataType = GL_UNSIGNED_BYTE;
406 xrb->Base.RedBits = 3 * sizeof(GLubyte);
407 xrb->Base.GreenBits = 3 * sizeof(GLubyte);
408 xrb->Base.BlueBits = 2 * sizeof(GLubyte);
409 xrb->Base.AlphaBits = 0;
410 xrb->bpp = 8;
411 break;
412 case PF_CI8:
413 xrb->Base.InternalFormat = GL_COLOR_INDEX8_EXT;
414 xrb->Base._BaseFormat = GL_COLOR_INDEX;
415 xrb->Base.DataType = GL_UNSIGNED_BYTE;
416 xrb->Base.IndexBits = 8 * sizeof(GLubyte);
417 xrb->bpp = 8;
418 break;
419 default:
420 return NULL;
421 }
422
423 return xrb;
424 }
425
426 static __DRIdrawable *
427 driCreateNewDrawable(__DRIscreen *screen,
428 const __DRIconfig *config, void *data)
429 {
430 __DRIdrawable *buf;
431 struct swrast_renderbuffer *frontrb, *backrb;
432
433 TRACE;
434
435 buf = _mesa_calloc(sizeof *buf);
436 if (!buf)
437 return NULL;
438
439 buf->loaderPrivate = data;
440
441 buf->driScreenPriv = screen;
442
443 buf->row = _mesa_malloc(MAX_WIDTH * 4);
444
445 /* basic framebuffer setup */
446 _mesa_initialize_framebuffer(&buf->Base, &config->modes);
447
448 /* add front renderbuffer */
449 frontrb = swrast_new_renderbuffer(&config->modes, GL_TRUE);
450 _mesa_add_renderbuffer(&buf->Base, BUFFER_FRONT_LEFT, &frontrb->Base);
451
452 /* add back renderbuffer */
453 if (config->modes.doubleBufferMode) {
454 backrb = swrast_new_renderbuffer(&config->modes, GL_FALSE);
455 _mesa_add_renderbuffer(&buf->Base, BUFFER_BACK_LEFT, &backrb->Base);
456 }
457
458 /* add software renderbuffers */
459 _mesa_add_soft_renderbuffers(&buf->Base,
460 GL_FALSE, /* color */
461 config->modes.haveDepthBuffer,
462 config->modes.haveStencilBuffer,
463 config->modes.haveAccumBuffer,
464 GL_FALSE, /* alpha */
465 GL_FALSE /* aux bufs */);
466
467 return buf;
468 }
469
470 static void
471 driDestroyDrawable(__DRIdrawable *buf)
472 {
473 TRACE;
474
475 if (buf) {
476 struct gl_framebuffer *fb = &buf->Base;
477
478 _mesa_free(buf->row);
479
480 fb->DeletePending = GL_TRUE;
481 _mesa_reference_framebuffer(&fb, NULL);
482 }
483 }
484
485 static void driSwapBuffers(__DRIdrawable *buf)
486 {
487 GET_CURRENT_CONTEXT(ctx);
488
489 struct swrast_renderbuffer *frontrb =
490 swrast_renderbuffer(buf->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer);
491 struct swrast_renderbuffer *backrb =
492 swrast_renderbuffer(buf->Base.Attachment[BUFFER_BACK_LEFT].Renderbuffer);
493
494 __DRIscreen *screen = buf->driScreenPriv;
495
496 TRACE;
497
498 /* check for signle-buffered */
499 if (backrb == NULL)
500 return;
501
502 /* check if swapping currently bound buffer */
503 if (ctx && ctx->DrawBuffer == &(buf->Base)) {
504 /* flush pending rendering */
505 _mesa_notifySwapBuffers(ctx);
506 }
507
508 screen->swrast_loader->putImage(buf, __DRI_SWRAST_IMAGE_OP_SWAP,
509 0, 0,
510 frontrb->Base.Width,
511 frontrb->Base.Height,
512 backrb->Base.Data,
513 buf->loaderPrivate);
514 }
515
516
517 /**
518 * General device driver functions.
519 */
520
521 static void
522 get_window_size( GLframebuffer *fb, GLsizei *w, GLsizei *h )
523 {
524 __DRIdrawable *buf = swrast_drawable(fb);
525 __DRIscreen *screen = buf->driScreenPriv;
526 int x, y;
527
528 screen->swrast_loader->getDrawableInfo(buf,
529 &x, &y, w, h,
530 buf->loaderPrivate);
531 }
532
533 static void
534 swrast_check_and_update_window_size( GLcontext *ctx, GLframebuffer *fb )
535 {
536 GLsizei width, height;
537
538 get_window_size(fb, &width, &height);
539 if (fb->Width != width || fb->Height != height) {
540 _mesa_resize_framebuffer(ctx, fb, width, height);
541 }
542 }
543
544 static const GLubyte *
545 get_string(GLcontext *ctx, GLenum pname)
546 {
547 (void) ctx;
548 switch (pname) {
549 case GL_VENDOR:
550 return (const GLubyte *) "Mesa Project";
551 case GL_RENDERER:
552 return (const GLubyte *) "Software Rasterizer";
553 default:
554 return NULL;
555 }
556 }
557
558 static void
559 update_state( GLcontext *ctx, GLuint new_state )
560 {
561 /* not much to do here - pass it on */
562 _swrast_InvalidateState( ctx, new_state );
563 _swsetup_InvalidateState( ctx, new_state );
564 _vbo_InvalidateState( ctx, new_state );
565 _tnl_InvalidateState( ctx, new_state );
566 }
567
568 static void
569 viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h)
570 {
571 GLframebuffer *draw = ctx->WinSysDrawBuffer;
572 GLframebuffer *read = ctx->WinSysReadBuffer;
573
574 swrast_check_and_update_window_size(ctx, draw);
575 swrast_check_and_update_window_size(ctx, read);
576 }
577
578 static void
579 swrast_init_driver_functions(struct dd_function_table *driver)
580 {
581 driver->GetString = get_string;
582 driver->UpdateState = update_state;
583 driver->GetBufferSize = NULL;
584 driver->Viewport = viewport;
585 }
586
587
588 /**
589 * Context-related functions.
590 */
591
592 static __DRIcontext *
593 driCreateNewContext(__DRIscreen *screen, const __DRIconfig *config,
594 __DRIcontext *shared, void *data)
595 {
596 __DRIcontext *ctx;
597 GLcontext *mesaCtx;
598 struct dd_function_table functions;
599
600 TRACE;
601
602 ctx = _mesa_calloc(sizeof *ctx);
603 if (!ctx)
604 return NULL;
605
606 ctx->loaderPrivate = data;
607
608 ctx->driScreenPriv = screen;
609
610 /* build table of device driver functions */
611 _mesa_init_driver_functions(&functions);
612 swrast_init_driver_functions(&functions);
613
614 if (!_mesa_initialize_context(&ctx->Base, &config->modes,
615 shared ? &shared->Base : NULL,
616 &functions, (void *) ctx)) {
617 _mesa_free(ctx);
618 return NULL;
619 }
620
621 mesaCtx = &ctx->Base;
622
623 /* do bounds checking to prevent segfaults and server crashes! */
624 mesaCtx->Const.CheckArrayBounds = GL_TRUE;
625
626 /* create module contexts */
627 _swrast_CreateContext( mesaCtx );
628 _vbo_CreateContext( mesaCtx );
629 _tnl_CreateContext( mesaCtx );
630 _swsetup_CreateContext( mesaCtx );
631 _swsetup_Wakeup( mesaCtx );
632
633 /* use default TCL pipeline */
634 {
635 TNLcontext *tnl = TNL_CONTEXT(mesaCtx);
636 tnl->Driver.RunPipeline = _tnl_run_pipeline;
637 }
638
639 _mesa_enable_sw_extensions(mesaCtx);
640 _mesa_enable_1_3_extensions(mesaCtx);
641 _mesa_enable_1_4_extensions(mesaCtx);
642 _mesa_enable_1_5_extensions(mesaCtx);
643 _mesa_enable_2_0_extensions(mesaCtx);
644 _mesa_enable_2_1_extensions(mesaCtx);
645
646 return ctx;
647 }
648
649 static void
650 driDestroyContext(__DRIcontext *ctx)
651 {
652 GLcontext *mesaCtx;
653 TRACE;
654
655 if (ctx) {
656 mesaCtx = &ctx->Base;
657 _swsetup_DestroyContext( mesaCtx );
658 _swrast_DestroyContext( mesaCtx );
659 _tnl_DestroyContext( mesaCtx );
660 _vbo_DestroyContext( mesaCtx );
661 _mesa_destroy_context( mesaCtx );
662 }
663 }
664
665 static int
666 driCopyContext(__DRIcontext *dst, __DRIcontext *src, unsigned long mask)
667 {
668 TRACE;
669
670 _mesa_copy_context(&src->Base, &dst->Base, mask);
671 return GL_TRUE;
672 }
673
674 static int driBindContext(__DRIcontext *ctx,
675 __DRIdrawable *draw,
676 __DRIdrawable *read)
677 {
678 GLcontext *mesaCtx;
679 GLframebuffer *mesaDraw;
680 GLframebuffer *mesaRead;
681 TRACE;
682
683 if (ctx) {
684 if (!draw || !read)
685 return GL_FALSE;
686
687 mesaCtx = &ctx->Base;
688 mesaDraw = &draw->Base;
689 mesaRead = &read->Base;
690
691 /* check for same context and buffer */
692 if (mesaCtx == _mesa_get_current_context()
693 && mesaCtx->DrawBuffer == mesaDraw
694 && mesaCtx->ReadBuffer == mesaRead) {
695 return GL_TRUE;
696 }
697
698 _glapi_check_multithread();
699
700 swrast_check_and_update_window_size(mesaCtx, mesaDraw);
701 if (read != draw)
702 swrast_check_and_update_window_size(mesaCtx, mesaRead);
703
704 _mesa_make_current( mesaCtx,
705 mesaDraw,
706 mesaRead );
707 }
708 else {
709 /* unbind */
710 _mesa_make_current( NULL, NULL, NULL );
711 }
712
713 return GL_TRUE;
714 }
715
716 static int driUnbindContext(__DRIcontext *ctx)
717 {
718 TRACE;
719 (void) ctx;
720 return GL_TRUE;
721 }
722
723
724 static const __DRIcoreExtension driCoreExtension = {
725 { __DRI_CORE, __DRI_CORE_VERSION },
726 NULL, /* driCreateNewScreen */
727 driDestroyScreen,
728 driGetExtensions,
729 driGetConfigAttrib,
730 driIndexConfigAttrib,
731 NULL, /* driCreateNewDrawable */
732 driDestroyDrawable,
733 driSwapBuffers,
734 driCreateNewContext,
735 driCopyContext,
736 driDestroyContext,
737 driBindContext,
738 driUnbindContext
739 };
740
741 static const __DRIswrastExtension driSWRastExtension = {
742 { __DRI_SWRAST, __DRI_SWRAST_VERSION },
743 driCreateNewScreen,
744 driCreateNewDrawable
745 };
746
747 /* This is the table of extensions that the loader will dlsym() for. */
748 PUBLIC const __DRIextension *__driDriverExtensions[] = {
749 &driCoreExtension.base,
750 &driSWRastExtension.base,
751 NULL
752 };