dri2.c revision c72d7df16879e3210946ba92a7edc823815b6f16
1/* 2 * Mesa 3-D graphics library 3 * Version: 7.9 4 * 5 * Copyright 2009, VMware, Inc. 6 * All Rights Reserved. 7 * Copyright (C) 2010 LunarG Inc. 8 * 9 * Permission is hereby granted, free of charge, to any person obtaining a 10 * copy of this software and associated documentation files (the "Software"), 11 * to deal in the Software without restriction, including without limitation 12 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 * and/or sell copies of the Software, and to permit persons to whom the 14 * Software is furnished to do so, subject to the following conditions: 15 * 16 * The above copyright notice and this permission notice shall be included 17 * in all copies or substantial portions of the Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 * Authors: 27 * Keith Whitwell <keithw@vmware.com> 28 * Jakob Bornecrantz <wallbraker@gmail.com> 29 * Chia-I Wu <olv@lunarg.com> 30 */ 31 32#include "util/u_memory.h" 33#include "util/u_inlines.h" 34#include "util/u_format.h" 35#include "util/u_debug.h" 36#include "state_tracker/drm_driver.h" 37 38#include "dri_screen.h" 39#include "dri_context.h" 40#include "dri_drawable.h" 41#include "dri2_buffer.h" 42 43/** 44 * DRI2 flush extension. 45 */ 46static void 47dri2_flush_drawable(__DRIdrawable *dPriv) 48{ 49 struct dri_context *ctx = dri_get_current(dPriv->driScreenPriv); 50 struct dri_drawable *drawable = dri_drawable(dPriv); 51 52 struct pipe_resource *ptex = drawable->textures[ST_ATTACHMENT_BACK_LEFT]; 53 54 if (ctx) { 55 if (ptex && ctx->pp && drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL]) 56 pp_run(ctx->pp, ptex, ptex, drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL]); 57 58 ctx->st->flush(ctx->st, 0, NULL); 59 } 60} 61 62static void 63dri2_invalidate_drawable(__DRIdrawable *dPriv) 64{ 65 struct dri_drawable *drawable = dri_drawable(dPriv); 66 67 dri2InvalidateDrawable(dPriv); 68 drawable->dPriv->lastStamp = drawable->dPriv->dri2.stamp; 69 70 p_atomic_inc(&drawable->base.stamp); 71} 72 73static const __DRI2flushExtension dri2FlushExtension = { 74 { __DRI2_FLUSH, __DRI2_FLUSH_VERSION }, 75 dri2_flush_drawable, 76 dri2_invalidate_drawable, 77}; 78 79/** 80 * Retrieve __DRIbuffer from the DRI loader. 81 */ 82static __DRIbuffer * 83dri2_drawable_get_buffers(struct dri_drawable *drawable, 84 const enum st_attachment_type *statts, 85 unsigned *count) 86{ 87 __DRIdrawable *dri_drawable = drawable->dPriv; 88 struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; 89 boolean with_format; 90 __DRIbuffer *buffers; 91 int num_buffers; 92 unsigned attachments[10]; 93 unsigned num_attachments, i; 94 95 assert(loader); 96 with_format = dri_with_format(drawable->sPriv); 97 98 num_attachments = 0; 99 100 /* for Xserver 1.6.0 (DRI2 version 1) we always need to ask for the front */ 101 if (!with_format) 102 attachments[num_attachments++] = __DRI_BUFFER_FRONT_LEFT; 103 104 for (i = 0; i < *count; i++) { 105 enum pipe_format format; 106 unsigned bind; 107 int att, depth; 108 109 dri_drawable_get_format(drawable, statts[i], &format, &bind); 110 if (format == PIPE_FORMAT_NONE) 111 continue; 112 113 switch (statts[i]) { 114 case ST_ATTACHMENT_FRONT_LEFT: 115 /* already added */ 116 if (!with_format) 117 continue; 118 att = __DRI_BUFFER_FRONT_LEFT; 119 break; 120 case ST_ATTACHMENT_BACK_LEFT: 121 att = __DRI_BUFFER_BACK_LEFT; 122 break; 123 case ST_ATTACHMENT_FRONT_RIGHT: 124 att = __DRI_BUFFER_FRONT_RIGHT; 125 break; 126 case ST_ATTACHMENT_BACK_RIGHT: 127 att = __DRI_BUFFER_BACK_RIGHT; 128 break; 129 case ST_ATTACHMENT_DEPTH_STENCIL: 130 att = __DRI_BUFFER_DEPTH_STENCIL; 131 break; 132 default: 133 att = -1; 134 break; 135 } 136 137 /* 138 * In this switch statement we must support all formats that 139 * may occur as the stvis->color_format or 140 * stvis->depth_stencil_format. 141 */ 142 switch(format) { 143 case PIPE_FORMAT_B8G8R8A8_UNORM: 144 depth = 32; 145 break; 146 case PIPE_FORMAT_B8G8R8X8_UNORM: 147 depth = 24; 148 break; 149 case PIPE_FORMAT_B5G6R5_UNORM: 150 depth = 16; 151 break; 152 case PIPE_FORMAT_Z16_UNORM: 153 att = __DRI_BUFFER_DEPTH; 154 depth = 16; 155 break; 156 case PIPE_FORMAT_Z24X8_UNORM: 157 case PIPE_FORMAT_X8Z24_UNORM: 158 att = __DRI_BUFFER_DEPTH; 159 depth = 24; 160 break; 161 case PIPE_FORMAT_Z24_UNORM_S8_UINT: 162 case PIPE_FORMAT_S8_UINT_Z24_UNORM: 163 depth = 32; 164 break; 165 case PIPE_FORMAT_Z32_UNORM: 166 att = __DRI_BUFFER_DEPTH; 167 depth = 32; 168 break; 169 default: 170 depth = util_format_get_blocksizebits(format); 171 assert(!"Unexpected format in dri2_drawable_get_buffers()"); 172 } 173 174 if (att >= 0) { 175 attachments[num_attachments++] = att; 176 if (with_format) { 177 attachments[num_attachments++] = depth; 178 } 179 } 180 } 181 182 if (with_format) { 183 num_attachments /= 2; 184 buffers = loader->getBuffersWithFormat(dri_drawable, 185 &dri_drawable->w, &dri_drawable->h, 186 attachments, num_attachments, 187 &num_buffers, dri_drawable->loaderPrivate); 188 } 189 else { 190 buffers = loader->getBuffers(dri_drawable, 191 &dri_drawable->w, &dri_drawable->h, 192 attachments, num_attachments, 193 &num_buffers, dri_drawable->loaderPrivate); 194 } 195 196 if (buffers) 197 *count = num_buffers; 198 199 return buffers; 200} 201 202/** 203 * Process __DRIbuffer and convert them into pipe_resources. 204 */ 205static void 206dri2_drawable_process_buffers(struct dri_drawable *drawable, 207 __DRIbuffer *buffers, unsigned count) 208{ 209 struct dri_screen *screen = dri_screen(drawable->sPriv); 210 __DRIdrawable *dri_drawable = drawable->dPriv; 211 struct pipe_resource templ; 212 struct winsys_handle whandle; 213 boolean have_depth = FALSE; 214 unsigned i, bind; 215 216 if (drawable->old_num == count && 217 drawable->old_w == dri_drawable->w && 218 drawable->old_h == dri_drawable->h && 219 memcmp(drawable->old, buffers, sizeof(__DRIbuffer) * count) == 0) 220 return; 221 222 for (i = 0; i < ST_ATTACHMENT_COUNT; i++) 223 pipe_resource_reference(&drawable->textures[i], NULL); 224 225 memset(&templ, 0, sizeof(templ)); 226 templ.target = screen->target; 227 templ.last_level = 0; 228 templ.width0 = dri_drawable->w; 229 templ.height0 = dri_drawable->h; 230 templ.depth0 = 1; 231 templ.array_size = 1; 232 233 memset(&whandle, 0, sizeof(whandle)); 234 235 for (i = 0; i < count; i++) { 236 __DRIbuffer *buf = &buffers[i]; 237 enum st_attachment_type statt; 238 enum pipe_format format; 239 240 switch (buf->attachment) { 241 case __DRI_BUFFER_FRONT_LEFT: 242 if (!screen->auto_fake_front) { 243 statt = ST_ATTACHMENT_INVALID; 244 break; 245 } 246 /* fallthrough */ 247 case __DRI_BUFFER_FAKE_FRONT_LEFT: 248 statt = ST_ATTACHMENT_FRONT_LEFT; 249 break; 250 case __DRI_BUFFER_BACK_LEFT: 251 statt = ST_ATTACHMENT_BACK_LEFT; 252 break; 253 case __DRI_BUFFER_DEPTH: 254 case __DRI_BUFFER_DEPTH_STENCIL: 255 case __DRI_BUFFER_STENCIL: 256 /* use only the first depth/stencil buffer */ 257 if (!have_depth) { 258 have_depth = TRUE; 259 statt = ST_ATTACHMENT_DEPTH_STENCIL; 260 } 261 else { 262 statt = ST_ATTACHMENT_INVALID; 263 } 264 break; 265 default: 266 statt = ST_ATTACHMENT_INVALID; 267 break; 268 } 269 270 dri_drawable_get_format(drawable, statt, &format, &bind); 271 if (statt == ST_ATTACHMENT_INVALID || format == PIPE_FORMAT_NONE) 272 continue; 273 274 templ.format = format; 275 templ.bind = bind; 276 whandle.handle = buf->name; 277 whandle.stride = buf->pitch; 278 279 drawable->textures[statt] = 280 screen->base.screen->resource_from_handle(screen->base.screen, 281 &templ, &whandle); 282 } 283 284 drawable->old_num = count; 285 drawable->old_w = dri_drawable->w; 286 drawable->old_h = dri_drawable->h; 287 memcpy(drawable->old, buffers, sizeof(__DRIbuffer) * count); 288} 289 290static __DRIbuffer * 291dri2_allocate_buffer(__DRIscreen *sPriv, 292 unsigned attachment, unsigned format, 293 int width, int height) 294{ 295 struct dri_screen *screen = dri_screen(sPriv); 296 struct dri2_buffer *buffer; 297 struct pipe_resource templ; 298 enum pipe_format pf; 299 unsigned bind = 0; 300 struct winsys_handle whandle; 301 302 switch (attachment) { 303 case __DRI_BUFFER_FRONT_LEFT: 304 case __DRI_BUFFER_FAKE_FRONT_LEFT: 305 bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW; 306 break; 307 case __DRI_BUFFER_BACK_LEFT: 308 bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW; 309 break; 310 case __DRI_BUFFER_DEPTH: 311 case __DRI_BUFFER_DEPTH_STENCIL: 312 case __DRI_BUFFER_STENCIL: 313 bind = PIPE_BIND_DEPTH_STENCIL; /* XXX sampler? */ 314 break; 315 } 316 317 switch (format) { 318 case 32: 319 pf = PIPE_FORMAT_B8G8R8A8_UNORM; 320 break; 321 case 24: 322 pf = PIPE_FORMAT_B8G8R8X8_UNORM; 323 break; 324 case 16: 325 pf = PIPE_FORMAT_Z16_UNORM; 326 break; 327 default: 328 return NULL; 329 } 330 331 buffer = CALLOC_STRUCT(dri2_buffer); 332 if (!buffer) 333 return NULL; 334 335 memset(&templ, 0, sizeof(templ)); 336 templ.bind = bind; 337 templ.format = pf; 338 templ.target = PIPE_TEXTURE_2D; 339 templ.last_level = 0; 340 templ.width0 = width; 341 templ.height0 = height; 342 templ.depth0 = 1; 343 templ.array_size = 1; 344 345 buffer->resource = 346 screen->base.screen->resource_create(screen->base.screen, &templ); 347 if (!buffer->resource) { 348 FREE(buffer); 349 return NULL; 350 } 351 352 memset(&whandle, 0, sizeof(whandle)); 353 whandle.type = DRM_API_HANDLE_TYPE_SHARED; 354 screen->base.screen->resource_get_handle(screen->base.screen, 355 buffer->resource, &whandle); 356 357 buffer->base.attachment = attachment; 358 buffer->base.name = whandle.handle; 359 buffer->base.cpp = util_format_get_blocksize(pf); 360 buffer->base.pitch = whandle.stride; 361 362 return &buffer->base; 363} 364 365static void 366dri2_release_buffer(__DRIscreen *sPriv, __DRIbuffer *bPriv) 367{ 368 struct dri2_buffer *buffer = dri2_buffer(bPriv); 369 370 pipe_resource_reference(&buffer->resource, NULL); 371 FREE(buffer); 372} 373 374/* 375 * Backend functions for st_framebuffer interface. 376 */ 377 378static void 379dri2_allocate_textures(struct dri_drawable *drawable, 380 const enum st_attachment_type *statts, 381 unsigned count) 382{ 383 __DRIbuffer *buffers; 384 unsigned num_buffers = count; 385 386 buffers = dri2_drawable_get_buffers(drawable, statts, &num_buffers); 387 if (buffers) 388 dri2_drawable_process_buffers(drawable, buffers, num_buffers); 389} 390 391static void 392dri2_flush_frontbuffer(struct dri_drawable *drawable, 393 enum st_attachment_type statt) 394{ 395 __DRIdrawable *dri_drawable = drawable->dPriv; 396 struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; 397 398 if (loader->flushFrontBuffer == NULL) 399 return; 400 401 if (statt == ST_ATTACHMENT_FRONT_LEFT) { 402 loader->flushFrontBuffer(dri_drawable, dri_drawable->loaderPrivate); 403 } 404} 405 406static void 407dri2_update_tex_buffer(struct dri_drawable *drawable, 408 struct dri_context *ctx, 409 struct pipe_resource *res) 410{ 411 /* no-op */ 412} 413 414static __DRIimage * 415dri2_lookup_egl_image(struct dri_screen *screen, void *handle) 416{ 417 __DRIimageLookupExtension *loader = screen->sPriv->dri2.image; 418 __DRIimage *img; 419 420 if (!loader->lookupEGLImage) 421 return NULL; 422 423 img = loader->lookupEGLImage(screen->sPriv, 424 handle, screen->sPriv->loaderPrivate); 425 426 return img; 427} 428 429static __DRIimage * 430dri2_create_image_from_name(__DRIscreen *_screen, 431 int width, int height, int format, 432 int name, int pitch, void *loaderPrivate) 433{ 434 struct dri_screen *screen = dri_screen(_screen); 435 __DRIimage *img; 436 struct pipe_resource templ; 437 struct winsys_handle whandle; 438 unsigned tex_usage; 439 enum pipe_format pf; 440 441 tex_usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW; 442 443 switch (format) { 444 case __DRI_IMAGE_FORMAT_RGB565: 445 pf = PIPE_FORMAT_B5G6R5_UNORM; 446 break; 447 case __DRI_IMAGE_FORMAT_XRGB8888: 448 pf = PIPE_FORMAT_B8G8R8X8_UNORM; 449 break; 450 case __DRI_IMAGE_FORMAT_ARGB8888: 451 pf = PIPE_FORMAT_B8G8R8A8_UNORM; 452 break; 453 case __DRI_IMAGE_FORMAT_ABGR8888: 454 pf = PIPE_FORMAT_R8G8B8A8_UNORM; 455 break; 456 default: 457 pf = PIPE_FORMAT_NONE; 458 break; 459 } 460 if (pf == PIPE_FORMAT_NONE) 461 return NULL; 462 463 img = CALLOC_STRUCT(__DRIimageRec); 464 if (!img) 465 return NULL; 466 467 memset(&templ, 0, sizeof(templ)); 468 templ.bind = tex_usage; 469 templ.format = pf; 470 templ.target = screen->target; 471 templ.last_level = 0; 472 templ.width0 = width; 473 templ.height0 = height; 474 templ.depth0 = 1; 475 templ.array_size = 1; 476 477 memset(&whandle, 0, sizeof(whandle)); 478 whandle.handle = name; 479 whandle.stride = pitch * util_format_get_blocksize(pf); 480 481 img->texture = screen->base.screen->resource_from_handle(screen->base.screen, 482 &templ, &whandle); 483 if (!img->texture) { 484 FREE(img); 485 return NULL; 486 } 487 488 img->level = 0; 489 img->layer = 0; 490 img->loader_private = loaderPrivate; 491 492 return img; 493} 494 495static __DRIimage * 496dri2_create_image_from_renderbuffer(__DRIcontext *context, 497 int renderbuffer, void *loaderPrivate) 498{ 499 struct dri_context *ctx = dri_context(context); 500 501 if (!ctx->st->get_resource_for_egl_image) 502 return NULL; 503 504 /* TODO */ 505 return NULL; 506} 507 508static __DRIimage * 509dri2_create_image(__DRIscreen *_screen, 510 int width, int height, int format, 511 unsigned int use, void *loaderPrivate) 512{ 513 struct dri_screen *screen = dri_screen(_screen); 514 __DRIimage *img; 515 struct pipe_resource templ; 516 unsigned tex_usage; 517 enum pipe_format pf; 518 519 tex_usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW; 520 if (use & __DRI_IMAGE_USE_SCANOUT) 521 tex_usage |= PIPE_BIND_SCANOUT; 522 if (use & __DRI_IMAGE_USE_SHARE) 523 tex_usage |= PIPE_BIND_SHARED; 524 if (use & __DRI_IMAGE_USE_CURSOR) { 525 if (width != 64 || height != 64) 526 return NULL; 527 tex_usage |= PIPE_BIND_CURSOR; 528 } 529 530 switch (format) { 531 case __DRI_IMAGE_FORMAT_RGB565: 532 pf = PIPE_FORMAT_B5G6R5_UNORM; 533 break; 534 case __DRI_IMAGE_FORMAT_XRGB8888: 535 pf = PIPE_FORMAT_B8G8R8X8_UNORM; 536 break; 537 case __DRI_IMAGE_FORMAT_ARGB8888: 538 pf = PIPE_FORMAT_B8G8R8A8_UNORM; 539 break; 540 case __DRI_IMAGE_FORMAT_ABGR8888: 541 pf = PIPE_FORMAT_R8G8B8A8_UNORM; 542 break; 543 default: 544 pf = PIPE_FORMAT_NONE; 545 break; 546 } 547 if (pf == PIPE_FORMAT_NONE) 548 return NULL; 549 550 img = CALLOC_STRUCT(__DRIimageRec); 551 if (!img) 552 return NULL; 553 554 memset(&templ, 0, sizeof(templ)); 555 templ.bind = tex_usage; 556 templ.format = pf; 557 templ.target = PIPE_TEXTURE_2D; 558 templ.last_level = 0; 559 templ.width0 = width; 560 templ.height0 = height; 561 templ.depth0 = 1; 562 templ.array_size = 1; 563 564 img->texture = screen->base.screen->resource_create(screen->base.screen, &templ); 565 if (!img->texture) { 566 FREE(img); 567 return NULL; 568 } 569 570 img->level = 0; 571 img->layer = 0; 572 573 img->loader_private = loaderPrivate; 574 return img; 575} 576 577static GLboolean 578dri2_query_image(__DRIimage *image, int attrib, int *value) 579{ 580 struct winsys_handle whandle; 581 memset(&whandle, 0, sizeof(whandle)); 582 583 switch (attrib) { 584 case __DRI_IMAGE_ATTRIB_STRIDE: 585 image->texture->screen->resource_get_handle(image->texture->screen, 586 image->texture, &whandle); 587 *value = whandle.stride; 588 return GL_TRUE; 589 case __DRI_IMAGE_ATTRIB_HANDLE: 590 whandle.type = DRM_API_HANDLE_TYPE_KMS; 591 image->texture->screen->resource_get_handle(image->texture->screen, 592 image->texture, &whandle); 593 *value = whandle.handle; 594 return GL_TRUE; 595 case __DRI_IMAGE_ATTRIB_NAME: 596 whandle.type = DRM_API_HANDLE_TYPE_SHARED; 597 image->texture->screen->resource_get_handle(image->texture->screen, 598 image->texture, &whandle); 599 *value = whandle.handle; 600 return GL_TRUE; 601 default: 602 return GL_FALSE; 603 } 604} 605 606static __DRIimage * 607dri2_dup_image(__DRIimage *image, void *loaderPrivate) 608{ 609 __DRIimage *img; 610 611 img = CALLOC_STRUCT(__DRIimageRec); 612 if (!img) 613 return NULL; 614 615 img->texture = NULL; 616 pipe_resource_reference(&img->texture, image->texture); 617 img->level = image->level; 618 img->layer = image->layer; 619 img->loader_private = loaderPrivate; 620 621 return img; 622} 623 624static void 625dri2_destroy_image(__DRIimage *img) 626{ 627 pipe_resource_reference(&img->texture, NULL); 628 FREE(img); 629} 630 631static struct __DRIimageExtensionRec dri2ImageExtension = { 632 { __DRI_IMAGE, 1 }, 633 dri2_create_image_from_name, 634 dri2_create_image_from_renderbuffer, 635 dri2_destroy_image, 636 dri2_create_image, 637 dri2_query_image, 638 dri2_dup_image, 639}; 640 641/* 642 * Backend function init_screen. 643 */ 644 645static const __DRIextension *dri_screen_extensions[] = { 646 &driTexBufferExtension.base, 647 &dri2FlushExtension.base, 648 &dri2ImageExtension.base, 649 &dri2ConfigQueryExtension.base, 650 NULL 651}; 652 653static const __DRIextension *dri_screen_extensions_throttle[] = { 654 &driTexBufferExtension.base, 655 &dri2FlushExtension.base, 656 &dri2ImageExtension.base, 657 &dri2ConfigQueryExtension.base, 658 &dri2ThrottleExtension.base, 659 NULL 660}; 661 662/** 663 * This is the driver specific part of the createNewScreen entry point. 664 * 665 * Returns the struct gl_config supported by this driver. 666 */ 667static const __DRIconfig ** 668dri2_init_screen(__DRIscreen * sPriv) 669{ 670 const __DRIconfig **configs; 671 struct dri_screen *screen; 672 struct pipe_screen *pscreen; 673 const struct drm_conf_ret *throttle_ret = NULL; 674 675 screen = CALLOC_STRUCT(dri_screen); 676 if (!screen) 677 return NULL; 678 679 screen->sPriv = sPriv; 680 screen->fd = sPriv->fd; 681 682 sPriv->driverPrivate = (void *)screen; 683 684 pscreen = driver_descriptor.create_screen(screen->fd); 685 if (driver_descriptor.configuration) 686 throttle_ret = driver_descriptor.configuration(DRM_CONF_THROTTLE); 687 688 if (throttle_ret && throttle_ret->val.val_int != -1) { 689 sPriv->extensions = dri_screen_extensions_throttle; 690 screen->default_throttle_frames = throttle_ret->val.val_int; 691 } else 692 sPriv->extensions = dri_screen_extensions; 693 694 /* dri_init_screen_helper checks pscreen for us */ 695 696 configs = dri_init_screen_helper(screen, pscreen, 32); 697 if (!configs) 698 goto fail; 699 700 sPriv->api_mask = 0; 701 if (screen->st_api->profile_mask & ST_PROFILE_DEFAULT_MASK) 702 sPriv->api_mask |= 1 << __DRI_API_OPENGL; 703 if (screen->st_api->profile_mask & ST_PROFILE_OPENGL_ES1_MASK) 704 sPriv->api_mask |= 1 << __DRI_API_GLES; 705 if (screen->st_api->profile_mask & ST_PROFILE_OPENGL_ES2_MASK) 706 sPriv->api_mask |= 1 << __DRI_API_GLES2; 707 708 screen->auto_fake_front = dri_with_format(sPriv); 709 screen->broken_invalidate = !sPriv->dri2.useInvalidate; 710 screen->lookup_egl_image = dri2_lookup_egl_image; 711 712 return configs; 713fail: 714 dri_destroy_screen_helper(screen); 715 FREE(screen); 716 return NULL; 717} 718 719static boolean 720dri2_create_buffer(__DRIscreen * sPriv, 721 __DRIdrawable * dPriv, 722 const struct gl_config * visual, boolean isPixmap) 723{ 724 struct dri_drawable *drawable = NULL; 725 726 if (!dri_create_buffer(sPriv, dPriv, visual, isPixmap)) 727 return FALSE; 728 729 drawable = dPriv->driverPrivate; 730 731 drawable->allocate_textures = dri2_allocate_textures; 732 drawable->flush_frontbuffer = dri2_flush_frontbuffer; 733 drawable->update_tex_buffer = dri2_update_tex_buffer; 734 735 return TRUE; 736} 737 738/** 739 * DRI driver virtual function table. 740 * 741 * DRI versions differ in their implementation of init_screen and swap_buffers. 742 */ 743const struct __DriverAPIRec driDriverAPI = { 744 .InitScreen = dri2_init_screen, 745 .DestroyScreen = dri_destroy_screen, 746 .CreateContext = dri_create_context, 747 .DestroyContext = dri_destroy_context, 748 .CreateBuffer = dri2_create_buffer, 749 .DestroyBuffer = dri_destroy_buffer, 750 .MakeCurrent = dri_make_current, 751 .UnbindContext = dri_unbind_context, 752 753 .AllocateBuffer = dri2_allocate_buffer, 754 .ReleaseBuffer = dri2_release_buffer, 755}; 756 757/* This is the table of extensions that the loader will dlsym() for. */ 758PUBLIC const __DRIextension *__driDriverExtensions[] = { 759 &driCoreExtension.base, 760 &driDRI2Extension.base, 761 NULL 762}; 763 764/* vim: set sw=3 ts=8 sts=3 expandtab: */ 765