swrast.c revision 6e0f9001fe3fb191c2928bd09aa9e9d05ddf4ea9
1/* 2 * Copyright 2008, 2010 George Sapountzis <gsapountzis@gmail.com> 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/formats.h" 37#include "main/framebuffer.h" 38#include "main/imports.h" 39#include "main/renderbuffer.h" 40#include "swrast/swrast.h" 41#include "swrast_setup/swrast_setup.h" 42#include "tnl/tnl.h" 43#include "tnl/t_context.h" 44#include "tnl/t_pipeline.h" 45#include "vbo/vbo.h" 46#include "drivers/common/driverfuncs.h" 47#include "drivers/common/meta.h" 48#include "utils.h" 49 50#include "main/teximage.h" 51#include "main/texformat.h" 52#include "main/texstate.h" 53 54#include "swrast_priv.h" 55#include "swrast/s_context.h" 56 57 58/** 59 * Screen and config-related functions 60 */ 61 62static void swrastSetTexBuffer2(__DRIcontext *pDRICtx, GLint target, 63 GLint texture_format, __DRIdrawable *dPriv) 64{ 65 struct dri_context *dri_ctx; 66 int x, y, w, h; 67 __DRIscreen *sPriv = dPriv->driScreenPriv; 68 struct gl_texture_unit *texUnit; 69 struct gl_texture_object *texObj; 70 struct gl_texture_image *texImage; 71 struct swrast_texture_image *swImage; 72 uint32_t internalFormat; 73 gl_format texFormat; 74 75 dri_ctx = pDRICtx->driverPrivate; 76 77 internalFormat = (texture_format == __DRI_TEXTURE_FORMAT_RGB ? 3 : 4); 78 79 texUnit = _mesa_get_current_tex_unit(&dri_ctx->Base); 80 texObj = _mesa_select_tex_object(&dri_ctx->Base, texUnit, target); 81 texImage = _mesa_get_tex_image(&dri_ctx->Base, texObj, target, 0); 82 swImage = swrast_texture_image(texImage); 83 84 _mesa_lock_texture(&dri_ctx->Base, texObj); 85 86 sPriv->swrast_loader->getDrawableInfo(dPriv, &x, &y, &w, &h, dPriv->loaderPrivate); 87 88 if (texture_format == __DRI_TEXTURE_FORMAT_RGB) 89 texFormat = MESA_FORMAT_XRGB8888; 90 else 91 texFormat = MESA_FORMAT_ARGB8888; 92 93 _mesa_init_teximage_fields(&dri_ctx->Base, target, texImage, 94 w, h, 1, 0, internalFormat, texFormat); 95 96 sPriv->swrast_loader->getImage(dPriv, x, y, w, h, (char *)swImage->Data, 97 dPriv->loaderPrivate); 98 99 _mesa_unlock_texture(&dri_ctx->Base, texObj); 100} 101 102static void swrastSetTexBuffer(__DRIcontext *pDRICtx, GLint target, 103 __DRIdrawable *dPriv) 104{ 105 swrastSetTexBuffer2(pDRICtx, target, __DRI_TEXTURE_FORMAT_RGBA, dPriv); 106} 107 108static const __DRItexBufferExtension swrastTexBufferExtension = { 109 { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION }, 110 swrastSetTexBuffer, 111 swrastSetTexBuffer2, 112}; 113 114static const __DRIextension *dri_screen_extensions[] = { 115 &swrastTexBufferExtension.base, 116 NULL 117}; 118 119static __DRIconfig ** 120swrastFillInModes(__DRIscreen *psp, 121 unsigned pixel_bits, unsigned depth_bits, 122 unsigned stencil_bits, GLboolean have_back_buffer) 123{ 124 __DRIconfig **configs; 125 unsigned depth_buffer_factor; 126 unsigned back_buffer_factor; 127 GLenum fb_format; 128 GLenum fb_type; 129 130 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't 131 * support pageflipping at all. 132 */ 133 static const GLenum back_buffer_modes[] = { 134 GLX_NONE, GLX_SWAP_UNDEFINED_OML 135 }; 136 137 uint8_t depth_bits_array[4]; 138 uint8_t stencil_bits_array[4]; 139 uint8_t msaa_samples_array[1]; 140 141 (void) psp; 142 (void) have_back_buffer; 143 144 depth_bits_array[0] = 0; 145 depth_bits_array[1] = 0; 146 depth_bits_array[2] = depth_bits; 147 depth_bits_array[3] = depth_bits; 148 149 /* Just like with the accumulation buffer, always provide some modes 150 * with a stencil buffer. 151 */ 152 stencil_bits_array[0] = 0; 153 stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits; 154 stencil_bits_array[2] = 0; 155 stencil_bits_array[3] = (stencil_bits == 0) ? 8 : stencil_bits; 156 157 msaa_samples_array[0] = 0; 158 159 depth_buffer_factor = 4; 160 back_buffer_factor = 2; 161 162 switch (pixel_bits) { 163 case 8: 164 fb_format = GL_RGB; 165 fb_type = GL_UNSIGNED_BYTE_2_3_3_REV; 166 break; 167 case 16: 168 fb_format = GL_RGB; 169 fb_type = GL_UNSIGNED_SHORT_5_6_5; 170 break; 171 case 24: 172 fb_format = GL_BGR; 173 fb_type = GL_UNSIGNED_INT_8_8_8_8_REV; 174 break; 175 case 32: 176 fb_format = GL_BGRA; 177 fb_type = GL_UNSIGNED_INT_8_8_8_8_REV; 178 break; 179 default: 180 fprintf(stderr, "[%s:%u] bad depth %d\n", __func__, __LINE__, 181 pixel_bits); 182 return NULL; 183 } 184 185 configs = driCreateConfigs(fb_format, fb_type, 186 depth_bits_array, stencil_bits_array, 187 depth_buffer_factor, back_buffer_modes, 188 back_buffer_factor, msaa_samples_array, 1, 189 GL_TRUE); 190 if (configs == NULL) { 191 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, 192 __LINE__); 193 return NULL; 194 } 195 196 return configs; 197} 198 199static const __DRIconfig ** 200dri_init_screen(__DRIscreen * psp) 201{ 202 __DRIconfig **configs8, **configs16, **configs24, **configs32; 203 204 TRACE; 205 206 psp->extensions = dri_screen_extensions; 207 208 configs8 = swrastFillInModes(psp, 8, 8, 0, 1); 209 configs16 = swrastFillInModes(psp, 16, 16, 0, 1); 210 configs24 = swrastFillInModes(psp, 24, 24, 8, 1); 211 configs32 = swrastFillInModes(psp, 32, 24, 8, 1); 212 213 configs16 = driConcatConfigs(configs8, configs16); 214 configs24 = driConcatConfigs(configs16, configs24); 215 configs32 = driConcatConfigs(configs24, configs32); 216 217 return (const __DRIconfig **)configs32; 218} 219 220static void 221dri_destroy_screen(__DRIscreen * sPriv) 222{ 223 TRACE; 224 (void) sPriv; 225} 226 227 228/** 229 * Framebuffer and renderbuffer-related functions. 230 */ 231 232static GLuint 233choose_pixel_format(const struct gl_config *v) 234{ 235 int depth = v->rgbBits; 236 237 if (depth == 32 238 && v->redMask == 0xff0000 239 && v->greenMask == 0x00ff00 240 && v->blueMask == 0x0000ff) 241 return PF_A8R8G8B8; 242 else if (depth == 24 243 && v->redMask == 0xff0000 244 && v->greenMask == 0x00ff00 245 && v->blueMask == 0x0000ff) 246 return PF_X8R8G8B8; 247 else if (depth == 16 248 && v->redMask == 0xf800 249 && v->greenMask == 0x07e0 250 && v->blueMask == 0x001f) 251 return PF_R5G6B5; 252 else if (depth == 8 253 && v->redMask == 0x07 254 && v->greenMask == 0x38 255 && v->blueMask == 0xc0) 256 return PF_R3G3B2; 257 258 _mesa_problem( NULL, "unexpected format in %s", __FUNCTION__ ); 259 return 0; 260} 261 262static void 263swrast_delete_renderbuffer(struct gl_renderbuffer *rb) 264{ 265 TRACE; 266 267 free(rb->Data); 268 free(rb); 269} 270 271/* see bytes_per_line in libGL */ 272static INLINE int 273bytes_per_line(unsigned pitch_bits, unsigned mul) 274{ 275 unsigned mask = mul - 1; 276 277 return ((pitch_bits + mask) & ~mask) / 8; 278} 279 280static GLboolean 281swrast_alloc_front_storage(struct gl_context *ctx, struct gl_renderbuffer *rb, 282 GLenum internalFormat, GLuint width, GLuint height) 283{ 284 struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb); 285 286 TRACE; 287 288 (void) ctx; 289 (void) internalFormat; 290 291 rb->Data = NULL; 292 rb->Width = width; 293 rb->Height = height; 294 295 xrb->pitch = bytes_per_line(width * xrb->bpp, 32); 296 297 return GL_TRUE; 298} 299 300static GLboolean 301swrast_alloc_back_storage(struct gl_context *ctx, struct gl_renderbuffer *rb, 302 GLenum internalFormat, GLuint width, GLuint height) 303{ 304 struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb); 305 306 TRACE; 307 308 free(rb->Data); 309 310 swrast_alloc_front_storage(ctx, rb, internalFormat, width, height); 311 312 rb->Data = malloc(height * xrb->pitch); 313 314 return GL_TRUE; 315} 316 317static struct swrast_renderbuffer * 318swrast_new_renderbuffer(const struct gl_config *visual, GLboolean front) 319{ 320 struct swrast_renderbuffer *xrb = calloc(1, sizeof *xrb); 321 GLuint pixel_format; 322 323 TRACE; 324 325 if (!xrb) 326 return NULL; 327 328 _mesa_init_renderbuffer(&xrb->Base, 0); 329 330 pixel_format = choose_pixel_format(visual); 331 332 xrb->Base.Delete = swrast_delete_renderbuffer; 333 if (front) { 334 xrb->Base.AllocStorage = swrast_alloc_front_storage; 335 swrast_set_span_funcs_front(xrb, pixel_format); 336 } 337 else { 338 xrb->Base.AllocStorage = swrast_alloc_back_storage; 339 swrast_set_span_funcs_back(xrb, pixel_format); 340 } 341 342 switch (pixel_format) { 343 case PF_A8R8G8B8: 344 xrb->Base.Format = MESA_FORMAT_ARGB8888; 345 xrb->Base.InternalFormat = GL_RGBA; 346 xrb->Base._BaseFormat = GL_RGBA; 347 xrb->Base.DataType = GL_UNSIGNED_BYTE; 348 xrb->bpp = 32; 349 break; 350 case PF_X8R8G8B8: 351 xrb->Base.Format = MESA_FORMAT_ARGB8888; /* XXX */ 352 xrb->Base.InternalFormat = GL_RGB; 353 xrb->Base._BaseFormat = GL_RGB; 354 xrb->Base.DataType = GL_UNSIGNED_BYTE; 355 xrb->bpp = 32; 356 break; 357 case PF_R5G6B5: 358 xrb->Base.Format = MESA_FORMAT_RGB565; 359 xrb->Base.InternalFormat = GL_RGB; 360 xrb->Base._BaseFormat = GL_RGB; 361 xrb->Base.DataType = GL_UNSIGNED_BYTE; 362 xrb->bpp = 16; 363 break; 364 case PF_R3G3B2: 365 xrb->Base.Format = MESA_FORMAT_RGB332; 366 xrb->Base.InternalFormat = GL_RGB; 367 xrb->Base._BaseFormat = GL_RGB; 368 xrb->Base.DataType = GL_UNSIGNED_BYTE; 369 xrb->bpp = 8; 370 break; 371 default: 372 return NULL; 373 } 374 375 return xrb; 376} 377 378static GLboolean 379dri_create_buffer(__DRIscreen * sPriv, 380 __DRIdrawable * dPriv, 381 const struct gl_config * visual, GLboolean isPixmap) 382{ 383 struct dri_drawable *drawable = NULL; 384 struct gl_framebuffer *fb; 385 struct swrast_renderbuffer *frontrb, *backrb; 386 387 TRACE; 388 389 (void) sPriv; 390 (void) isPixmap; 391 392 drawable = CALLOC_STRUCT(dri_drawable); 393 if (drawable == NULL) 394 goto drawable_fail; 395 396 dPriv->driverPrivate = drawable; 397 drawable->dPriv = dPriv; 398 399 drawable->row = malloc(MAX_WIDTH * 4); 400 if (drawable->row == NULL) 401 goto drawable_fail; 402 403 fb = &drawable->Base; 404 405 /* basic framebuffer setup */ 406 _mesa_initialize_window_framebuffer(fb, visual); 407 408 /* add front renderbuffer */ 409 frontrb = swrast_new_renderbuffer(visual, GL_TRUE); 410 _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontrb->Base); 411 412 /* add back renderbuffer */ 413 if (visual->doubleBufferMode) { 414 backrb = swrast_new_renderbuffer(visual, GL_FALSE); 415 _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backrb->Base); 416 } 417 418 /* add software renderbuffers */ 419 _mesa_add_soft_renderbuffers(fb, 420 GL_FALSE, /* color */ 421 visual->haveDepthBuffer, 422 visual->haveStencilBuffer, 423 visual->haveAccumBuffer, 424 GL_FALSE, /* alpha */ 425 GL_FALSE /* aux bufs */); 426 427 return GL_TRUE; 428 429drawable_fail: 430 431 if (drawable) 432 free(drawable->row); 433 434 FREE(drawable); 435 436 return GL_FALSE; 437} 438 439static void 440dri_destroy_buffer(__DRIdrawable * dPriv) 441{ 442 TRACE; 443 444 if (dPriv) { 445 struct dri_drawable *drawable = dri_drawable(dPriv); 446 struct gl_framebuffer *fb; 447 448 free(drawable->row); 449 450 fb = &drawable->Base; 451 452 fb->DeletePending = GL_TRUE; 453 _mesa_reference_framebuffer(&fb, NULL); 454 } 455} 456 457static void 458dri_swap_buffers(__DRIdrawable * dPriv) 459{ 460 __DRIscreen *sPriv = dPriv->driScreenPriv; 461 462 GET_CURRENT_CONTEXT(ctx); 463 464 struct dri_drawable *drawable = dri_drawable(dPriv); 465 struct gl_framebuffer *fb; 466 struct swrast_renderbuffer *frontrb, *backrb; 467 468 TRACE; 469 470 fb = &drawable->Base; 471 472 frontrb = 473 swrast_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer); 474 backrb = 475 swrast_renderbuffer(fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer); 476 477 /* check for signle-buffered */ 478 if (backrb == NULL) 479 return; 480 481 /* check if swapping currently bound buffer */ 482 if (ctx && ctx->DrawBuffer == fb) { 483 /* flush pending rendering */ 484 _mesa_notifySwapBuffers(ctx); 485 } 486 487 sPriv->swrast_loader->putImage(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP, 488 0, 0, 489 frontrb->Base.Width, 490 frontrb->Base.Height, 491 backrb->Base.Data, 492 dPriv->loaderPrivate); 493} 494 495 496/** 497 * General device driver functions. 498 */ 499 500static void 501get_window_size( struct gl_framebuffer *fb, GLsizei *w, GLsizei *h ) 502{ 503 __DRIdrawable *dPriv = swrast_drawable(fb)->dPriv; 504 __DRIscreen *sPriv = dPriv->driScreenPriv; 505 int x, y; 506 507 sPriv->swrast_loader->getDrawableInfo(dPriv, 508 &x, &y, w, h, 509 dPriv->loaderPrivate); 510} 511 512static void 513swrast_check_and_update_window_size( struct gl_context *ctx, struct gl_framebuffer *fb ) 514{ 515 GLsizei width, height; 516 517 get_window_size(fb, &width, &height); 518 if (fb->Width != width || fb->Height != height) { 519 _mesa_resize_framebuffer(ctx, fb, width, height); 520 } 521} 522 523static const GLubyte * 524get_string(struct gl_context *ctx, GLenum pname) 525{ 526 (void) ctx; 527 switch (pname) { 528 case GL_VENDOR: 529 return (const GLubyte *) "Mesa Project"; 530 case GL_RENDERER: 531 return (const GLubyte *) "Software Rasterizer"; 532 default: 533 return NULL; 534 } 535} 536 537static void 538update_state( struct gl_context *ctx, GLuint new_state ) 539{ 540 /* not much to do here - pass it on */ 541 _swrast_InvalidateState( ctx, new_state ); 542 _swsetup_InvalidateState( ctx, new_state ); 543 _vbo_InvalidateState( ctx, new_state ); 544 _tnl_InvalidateState( ctx, new_state ); 545} 546 547static void 548viewport(struct gl_context *ctx, GLint x, GLint y, GLsizei w, GLsizei h) 549{ 550 struct gl_framebuffer *draw = ctx->WinSysDrawBuffer; 551 struct gl_framebuffer *read = ctx->WinSysReadBuffer; 552 553 (void) x; 554 (void) y; 555 (void) w; 556 (void) h; 557 swrast_check_and_update_window_size(ctx, draw); 558 swrast_check_and_update_window_size(ctx, read); 559} 560 561static gl_format swrastChooseTextureFormat(struct gl_context * ctx, 562 GLint internalFormat, 563 GLenum format, 564 GLenum type) 565{ 566 if (internalFormat == GL_RGB) 567 return MESA_FORMAT_XRGB8888; 568 return _mesa_choose_tex_format(ctx, internalFormat, format, type); 569} 570 571static void 572swrast_init_driver_functions(struct dd_function_table *driver) 573{ 574 driver->GetString = get_string; 575 driver->UpdateState = update_state; 576 driver->GetBufferSize = NULL; 577 driver->Viewport = viewport; 578 driver->ChooseTextureFormat = swrastChooseTextureFormat; 579} 580 581static const char *es2_extensions[] = { 582 /* Used by mesa internally (cf all_mesa_extensions in ../common/utils.c) */ 583 "GL_ARB_transpose_matrix", 584 "GL_ARB_window_pos", 585 "GL_EXT_blend_func_separate", 586 "GL_EXT_compiled_vertex_array", 587 "GL_EXT_framebuffer_blit", 588 "GL_IBM_multimode_draw_arrays", 589 "GL_MESA_window_pos", 590 "GL_NV_vertex_program", 591 592 /* Required by GLES2 */ 593 "GL_ARB_fragment_program", 594 "GL_ARB_fragment_shader", 595 "GL_ARB_shader_objects", 596 "GL_ARB_texture_cube_map", 597 "GL_ARB_texture_non_power_of_two", 598 "GL_ARB_vertex_shader", 599 "GL_EXT_blend_color", 600 "GL_EXT_blend_equation_separate", 601 "GL_EXT_blend_minmax", 602 603 /* Optional GLES2 */ 604 "GL_ARB_framebuffer_object", 605 "GL_EXT_texture_filter_anisotropic", 606 "GL_ARB_depth_texture", 607 "GL_EXT_packed_depth_stencil", 608 "GL_EXT_framebuffer_object", 609 NULL, 610}; 611 612static void 613InitExtensionsES2(struct gl_context *ctx) 614{ 615 int i; 616 617 for (i = 0; es2_extensions[i]; i++) 618 _mesa_enable_extension(ctx, es2_extensions[i]); 619} 620 621/** 622 * Context-related functions. 623 */ 624 625static GLboolean 626dri_create_context(gl_api api, 627 const struct gl_config * visual, 628 __DRIcontext * cPriv, void *sharedContextPrivate) 629{ 630 struct dri_context *ctx = NULL; 631 struct dri_context *share = (struct dri_context *)sharedContextPrivate; 632 struct gl_context *mesaCtx = NULL; 633 struct gl_context *sharedCtx = NULL; 634 struct dd_function_table functions; 635 636 TRACE; 637 638 ctx = CALLOC_STRUCT(dri_context); 639 if (ctx == NULL) 640 goto context_fail; 641 642 cPriv->driverPrivate = ctx; 643 ctx->cPriv = cPriv; 644 645 /* build table of device driver functions */ 646 _mesa_init_driver_functions(&functions); 647 swrast_init_driver_functions(&functions); 648 649 if (share) { 650 sharedCtx = &share->Base; 651 } 652 653 mesaCtx = &ctx->Base; 654 655 /* basic context setup */ 656 if (!_mesa_initialize_context(mesaCtx, api, visual, sharedCtx, &functions, (void *) cPriv)) { 657 goto context_fail; 658 } 659 660 /* do bounds checking to prevent segfaults and server crashes! */ 661 mesaCtx->Const.CheckArrayBounds = GL_TRUE; 662 663 /* create module contexts */ 664 _swrast_CreateContext( mesaCtx ); 665 _vbo_CreateContext( mesaCtx ); 666 _tnl_CreateContext( mesaCtx ); 667 _swsetup_CreateContext( mesaCtx ); 668 _swsetup_Wakeup( mesaCtx ); 669 670 /* use default TCL pipeline */ 671 { 672 TNLcontext *tnl = TNL_CONTEXT(mesaCtx); 673 tnl->Driver.RunPipeline = _tnl_run_pipeline; 674 } 675 676 _mesa_meta_init(mesaCtx); 677 _mesa_enable_sw_extensions(mesaCtx); 678 679 switch (api) { 680 case API_OPENGL: 681 _mesa_enable_1_3_extensions(mesaCtx); 682 _mesa_enable_1_4_extensions(mesaCtx); 683 _mesa_enable_1_5_extensions(mesaCtx); 684 _mesa_enable_2_0_extensions(mesaCtx); 685 _mesa_enable_2_1_extensions(mesaCtx); 686 break; 687 case API_OPENGLES: 688 _mesa_enable_1_3_extensions(mesaCtx); 689 _mesa_enable_1_4_extensions(mesaCtx); 690 _mesa_enable_1_5_extensions(mesaCtx); 691 692 break; 693 case API_OPENGLES2: 694 InitExtensionsES2( mesaCtx); 695 break; 696 } 697 698 return GL_TRUE; 699 700context_fail: 701 702 FREE(ctx); 703 704 return GL_FALSE; 705} 706 707static void 708dri_destroy_context(__DRIcontext * cPriv) 709{ 710 TRACE; 711 712 if (cPriv) { 713 struct dri_context *ctx = dri_context(cPriv); 714 struct gl_context *mesaCtx; 715 716 mesaCtx = &ctx->Base; 717 718 _mesa_meta_free(mesaCtx); 719 _swsetup_DestroyContext( mesaCtx ); 720 _swrast_DestroyContext( mesaCtx ); 721 _tnl_DestroyContext( mesaCtx ); 722 _vbo_DestroyContext( mesaCtx ); 723 _mesa_destroy_context( mesaCtx ); 724 } 725} 726 727static GLboolean 728dri_make_current(__DRIcontext * cPriv, 729 __DRIdrawable * driDrawPriv, 730 __DRIdrawable * driReadPriv) 731{ 732 struct gl_context *mesaCtx; 733 struct gl_framebuffer *mesaDraw; 734 struct gl_framebuffer *mesaRead; 735 TRACE; 736 737 if (cPriv) { 738 struct dri_context *ctx = dri_context(cPriv); 739 struct dri_drawable *draw; 740 struct dri_drawable *read; 741 742 if (!driDrawPriv || !driReadPriv) 743 return GL_FALSE; 744 745 draw = dri_drawable(driDrawPriv); 746 read = dri_drawable(driReadPriv); 747 mesaCtx = &ctx->Base; 748 mesaDraw = &draw->Base; 749 mesaRead = &read->Base; 750 751 /* check for same context and buffer */ 752 if (mesaCtx == _mesa_get_current_context() 753 && mesaCtx->DrawBuffer == mesaDraw 754 && mesaCtx->ReadBuffer == mesaRead) { 755 return GL_TRUE; 756 } 757 758 _glapi_check_multithread(); 759 760 swrast_check_and_update_window_size(mesaCtx, mesaDraw); 761 if (mesaRead != mesaDraw) 762 swrast_check_and_update_window_size(mesaCtx, mesaRead); 763 764 _mesa_make_current( mesaCtx, 765 mesaDraw, 766 mesaRead ); 767 } 768 else { 769 /* unbind */ 770 _mesa_make_current( NULL, NULL, NULL ); 771 } 772 773 return GL_TRUE; 774} 775 776static GLboolean 777dri_unbind_context(__DRIcontext * cPriv) 778{ 779 TRACE; 780 (void) cPriv; 781 782 /* Unset current context and dispath table */ 783 _mesa_make_current(NULL, NULL, NULL); 784 785 return GL_TRUE; 786} 787 788 789const struct __DriverAPIRec driDriverAPI = { 790 .InitScreen = dri_init_screen, 791 .DestroyScreen = dri_destroy_screen, 792 .CreateContext = dri_create_context, 793 .DestroyContext = dri_destroy_context, 794 .CreateBuffer = dri_create_buffer, 795 .DestroyBuffer = dri_destroy_buffer, 796 .SwapBuffers = dri_swap_buffers, 797 .MakeCurrent = dri_make_current, 798 .UnbindContext = dri_unbind_context, 799}; 800 801/* This is the table of extensions that the loader will dlsym() for. */ 802PUBLIC const __DRIextension *__driDriverExtensions[] = { 803 &driCoreExtension.base, 804 &driSWRastExtension.base, 805 NULL 806}; 807