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