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