2 * Copyright © 2011 Intel Corporation
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:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Kristian Høgsberg <krh@bitplanet.net>
41 #include <sys/types.h>
45 #include "egl_dri2_fallbacks.h"
49 dri2_x11_swap_interval(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
,
53 swrastCreateDrawable(struct dri2_egl_display
* dri2_dpy
,
54 struct dri2_egl_surface
* dri2_surf
)
57 const uint32_t function
= GXcopy
;
61 dri2_surf
->gc
= xcb_generate_id(dri2_dpy
->conn
);
62 mask
= XCB_GC_FUNCTION
;
63 xcb_create_gc(dri2_dpy
->conn
, dri2_surf
->gc
, dri2_surf
->drawable
, mask
, &function
);
65 dri2_surf
->swapgc
= xcb_generate_id(dri2_dpy
->conn
);
66 mask
= XCB_GC_FUNCTION
| XCB_GC_GRAPHICS_EXPOSURES
;
69 xcb_create_gc(dri2_dpy
->conn
, dri2_surf
->swapgc
, dri2_surf
->drawable
, mask
, valgc
);
70 switch (dri2_surf
->depth
) {
73 dri2_surf
->bytes_per_pixel
= 4;
76 dri2_surf
->bytes_per_pixel
= 2;
79 dri2_surf
->bytes_per_pixel
= 1;
82 dri2_surf
->bytes_per_pixel
= 0;
85 _eglLog(_EGL_WARNING
, "unsupported depth %d", dri2_surf
->depth
);
90 swrastDestroyDrawable(struct dri2_egl_display
* dri2_dpy
,
91 struct dri2_egl_surface
* dri2_surf
)
93 xcb_free_gc(dri2_dpy
->conn
, dri2_surf
->gc
);
94 xcb_free_gc(dri2_dpy
->conn
, dri2_surf
->swapgc
);
98 swrastGetDrawableInfo(__DRIdrawable
* draw
,
99 int *x
, int *y
, int *w
, int *h
,
102 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
103 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
105 xcb_get_geometry_cookie_t cookie
;
106 xcb_get_geometry_reply_t
*reply
;
107 xcb_generic_error_t
*error
;
110 cookie
= xcb_get_geometry (dri2_dpy
->conn
, dri2_surf
->drawable
);
111 reply
= xcb_get_geometry_reply (dri2_dpy
->conn
, cookie
, &error
);
116 _eglLog(_EGL_WARNING
, "error in xcb_get_geometry");
126 swrastPutImage(__DRIdrawable
* draw
, int op
,
127 int x
, int y
, int w
, int h
,
128 char *data
, void *loaderPrivate
)
130 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
131 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
136 case __DRI_SWRAST_IMAGE_OP_DRAW
:
139 case __DRI_SWRAST_IMAGE_OP_SWAP
:
140 gc
= dri2_surf
->swapgc
;
146 xcb_put_image(dri2_dpy
->conn
, XCB_IMAGE_FORMAT_Z_PIXMAP
, dri2_surf
->drawable
,
147 gc
, w
, h
, x
, y
, 0, dri2_surf
->depth
,
148 w
*h
*dri2_surf
->bytes_per_pixel
, (const uint8_t *)data
);
152 swrastGetImage(__DRIdrawable
* read
,
153 int x
, int y
, int w
, int h
,
154 char *data
, void *loaderPrivate
)
156 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
157 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
159 xcb_get_image_cookie_t cookie
;
160 xcb_get_image_reply_t
*reply
;
161 xcb_generic_error_t
*error
;
163 cookie
= xcb_get_image (dri2_dpy
->conn
, XCB_IMAGE_FORMAT_Z_PIXMAP
,
164 dri2_surf
->drawable
, x
, y
, w
, h
, ~0);
165 reply
= xcb_get_image_reply (dri2_dpy
->conn
, cookie
, &error
);
170 _eglLog(_EGL_WARNING
, "error in xcb_get_image");
173 uint32_t bytes
= xcb_get_image_data_length(reply
);
174 uint8_t *idata
= xcb_get_image_data(reply
);
175 memcpy(data
, idata
, bytes
);
181 static xcb_screen_t
*
182 get_xcb_screen(xcb_screen_iterator_t iter
, int screen
)
184 for (; iter
.rem
; --screen
, xcb_screen_next(&iter
))
193 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
196 dri2_x11_create_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, EGLint type
,
197 _EGLConfig
*conf
, void *native_surface
,
198 const EGLint
*attrib_list
)
200 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
201 struct dri2_egl_config
*dri2_conf
= dri2_egl_config(conf
);
202 struct dri2_egl_surface
*dri2_surf
;
203 xcb_get_geometry_cookie_t cookie
;
204 xcb_get_geometry_reply_t
*reply
;
205 xcb_screen_iterator_t s
;
206 xcb_generic_error_t
*error
;
207 xcb_drawable_t drawable
;
208 xcb_screen_t
*screen
;
210 STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_surface
));
211 drawable
= (uintptr_t) native_surface
;
215 dri2_surf
= malloc(sizeof *dri2_surf
);
217 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
221 if (!_eglInitSurface(&dri2_surf
->base
, disp
, type
, conf
, attrib_list
))
224 dri2_surf
->region
= XCB_NONE
;
225 if (type
== EGL_PBUFFER_BIT
) {
226 s
= xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy
->conn
));
227 screen
= get_xcb_screen(s
, dri2_dpy
->screen
);
229 _eglError(EGL_BAD_NATIVE_WINDOW
, "dri2_create_surface");
233 dri2_surf
->drawable
= xcb_generate_id(dri2_dpy
->conn
);
234 xcb_create_pixmap(dri2_dpy
->conn
, conf
->BufferSize
,
235 dri2_surf
->drawable
, screen
->root
,
236 dri2_surf
->base
.Width
, dri2_surf
->base
.Height
);
239 _eglError(EGL_BAD_NATIVE_WINDOW
, "dri2_create_surface");
242 dri2_surf
->drawable
= drawable
;
245 if (dri2_dpy
->dri2
) {
246 const __DRIconfig
*config
=
247 dri2_get_dri_config(dri2_conf
, type
, dri2_surf
->base
.GLColorspace
);
249 dri2_surf
->dri_drawable
=
250 (*dri2_dpy
->dri2
->createNewDrawable
)(dri2_dpy
->dri_screen
, config
,
253 assert(dri2_dpy
->swrast
);
254 dri2_surf
->dri_drawable
=
255 (*dri2_dpy
->swrast
->createNewDrawable
) (dri2_dpy
->dri_screen
,
256 dri2_conf
->dri_double_config
,
260 if (dri2_surf
->dri_drawable
== NULL
) {
261 _eglError(EGL_BAD_ALLOC
, "dri2->createNewDrawable");
265 if (type
!= EGL_PBUFFER_BIT
) {
266 cookie
= xcb_get_geometry (dri2_dpy
->conn
, dri2_surf
->drawable
);
267 reply
= xcb_get_geometry_reply (dri2_dpy
->conn
, cookie
, &error
);
268 if (reply
== NULL
|| error
!= NULL
) {
269 _eglError(EGL_BAD_ALLOC
, "xcb_get_geometry");
271 goto cleanup_dri_drawable
;
274 dri2_surf
->base
.Width
= reply
->width
;
275 dri2_surf
->base
.Height
= reply
->height
;
276 dri2_surf
->depth
= reply
->depth
;
280 if (dri2_dpy
->dri2
) {
281 xcb_dri2_create_drawable (dri2_dpy
->conn
, dri2_surf
->drawable
);
283 if (type
== EGL_PBUFFER_BIT
) {
284 dri2_surf
->depth
= _eglGetConfigKey(conf
, EGL_BUFFER_SIZE
);
286 swrastCreateDrawable(dri2_dpy
, dri2_surf
);
289 /* we always copy the back buffer to front */
290 dri2_surf
->base
.PostSubBufferSupportedNV
= EGL_TRUE
;
292 return &dri2_surf
->base
;
294 cleanup_dri_drawable
:
295 dri2_dpy
->core
->destroyDrawable(dri2_surf
->dri_drawable
);
297 if (type
== EGL_PBUFFER_BIT
)
298 xcb_free_pixmap(dri2_dpy
->conn
, dri2_surf
->drawable
);
306 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
309 dri2_x11_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
310 _EGLConfig
*conf
, void *native_window
,
311 const EGLint
*attrib_list
)
313 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
316 surf
= dri2_x11_create_surface(drv
, disp
, EGL_WINDOW_BIT
, conf
,
317 native_window
, attrib_list
);
319 /* When we first create the DRI2 drawable, its swap interval on the
322 surf
->SwapInterval
= 1;
324 /* Override that with a driconf-set value. */
325 dri2_x11_swap_interval(drv
, disp
, surf
, dri2_dpy
->default_swap_interval
);
332 dri2_x11_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
333 _EGLConfig
*conf
, void *native_pixmap
,
334 const EGLint
*attrib_list
)
336 return dri2_x11_create_surface(drv
, disp
, EGL_PIXMAP_BIT
, conf
,
337 native_pixmap
, attrib_list
);
341 dri2_x11_create_pbuffer_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
342 _EGLConfig
*conf
, const EGLint
*attrib_list
)
344 return dri2_x11_create_surface(drv
, disp
, EGL_PBUFFER_BIT
, conf
,
345 XCB_WINDOW_NONE
, attrib_list
);
349 dri2_x11_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
351 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
352 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
356 if (!_eglPutSurface(surf
))
359 (*dri2_dpy
->core
->destroyDrawable
)(dri2_surf
->dri_drawable
);
361 if (dri2_dpy
->dri2
) {
362 xcb_dri2_destroy_drawable (dri2_dpy
->conn
, dri2_surf
->drawable
);
364 assert(dri2_dpy
->swrast
);
365 swrastDestroyDrawable(dri2_dpy
, dri2_surf
);
368 if (surf
->Type
== EGL_PBUFFER_BIT
)
369 xcb_free_pixmap (dri2_dpy
->conn
, dri2_surf
->drawable
);
377 * Process list of buffer received from the server
379 * Processes the list of buffers received in a reply from the server to either
380 * \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat.
383 dri2_x11_process_buffers(struct dri2_egl_surface
*dri2_surf
,
384 xcb_dri2_dri2_buffer_t
*buffers
, unsigned count
)
386 struct dri2_egl_display
*dri2_dpy
=
387 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
388 xcb_rectangle_t rectangle
;
391 dri2_surf
->buffer_count
= count
;
392 dri2_surf
->have_fake_front
= 0;
394 /* This assumes the DRI2 buffer attachment tokens matches the
395 * __DRIbuffer tokens. */
396 for (i
= 0; i
< count
; i
++) {
397 dri2_surf
->buffers
[i
].attachment
= buffers
[i
].attachment
;
398 dri2_surf
->buffers
[i
].name
= buffers
[i
].name
;
399 dri2_surf
->buffers
[i
].pitch
= buffers
[i
].pitch
;
400 dri2_surf
->buffers
[i
].cpp
= buffers
[i
].cpp
;
401 dri2_surf
->buffers
[i
].flags
= buffers
[i
].flags
;
403 /* We only use the DRI drivers single buffer configs. This
404 * means that if we try to render to a window, DRI2 will give us
405 * the fake front buffer, which we'll use as a back buffer.
406 * Note that EGL doesn't require that several clients rendering
407 * to the same window must see the same aux buffers. */
408 if (dri2_surf
->buffers
[i
].attachment
== __DRI_BUFFER_FAKE_FRONT_LEFT
)
409 dri2_surf
->have_fake_front
= 1;
412 if (dri2_surf
->region
!= XCB_NONE
)
413 xcb_xfixes_destroy_region(dri2_dpy
->conn
, dri2_surf
->region
);
417 rectangle
.width
= dri2_surf
->base
.Width
;
418 rectangle
.height
= dri2_surf
->base
.Height
;
419 dri2_surf
->region
= xcb_generate_id(dri2_dpy
->conn
);
420 xcb_xfixes_create_region(dri2_dpy
->conn
, dri2_surf
->region
, 1, &rectangle
);
424 dri2_x11_get_buffers(__DRIdrawable
* driDrawable
,
425 int *width
, int *height
,
426 unsigned int *attachments
, int count
,
427 int *out_count
, void *loaderPrivate
)
429 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
430 struct dri2_egl_display
*dri2_dpy
=
431 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
432 xcb_dri2_dri2_buffer_t
*buffers
;
433 xcb_dri2_get_buffers_reply_t
*reply
;
434 xcb_dri2_get_buffers_cookie_t cookie
;
438 cookie
= xcb_dri2_get_buffers_unchecked (dri2_dpy
->conn
,
440 count
, count
, attachments
);
441 reply
= xcb_dri2_get_buffers_reply (dri2_dpy
->conn
, cookie
, NULL
);
442 buffers
= xcb_dri2_get_buffers_buffers (reply
);
446 *out_count
= reply
->count
;
447 dri2_surf
->base
.Width
= *width
= reply
->width
;
448 dri2_surf
->base
.Height
= *height
= reply
->height
;
449 dri2_x11_process_buffers(dri2_surf
, buffers
, *out_count
);
453 return dri2_surf
->buffers
;
457 dri2_x11_get_buffers_with_format(__DRIdrawable
* driDrawable
,
458 int *width
, int *height
,
459 unsigned int *attachments
, int count
,
460 int *out_count
, void *loaderPrivate
)
462 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
463 struct dri2_egl_display
*dri2_dpy
=
464 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
465 xcb_dri2_dri2_buffer_t
*buffers
;
466 xcb_dri2_get_buffers_with_format_reply_t
*reply
;
467 xcb_dri2_get_buffers_with_format_cookie_t cookie
;
468 xcb_dri2_attach_format_t
*format_attachments
;
472 format_attachments
= (xcb_dri2_attach_format_t
*) attachments
;
473 cookie
= xcb_dri2_get_buffers_with_format_unchecked (dri2_dpy
->conn
,
478 reply
= xcb_dri2_get_buffers_with_format_reply (dri2_dpy
->conn
,
483 buffers
= xcb_dri2_get_buffers_with_format_buffers (reply
);
484 dri2_surf
->base
.Width
= *width
= reply
->width
;
485 dri2_surf
->base
.Height
= *height
= reply
->height
;
486 *out_count
= reply
->count
;
487 dri2_x11_process_buffers(dri2_surf
, buffers
, *out_count
);
491 return dri2_surf
->buffers
;
495 dri2_x11_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
499 /* FIXME: Does EGL support front buffer rendering at all? */
502 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
504 dri2WaitGL(dri2_surf
);
506 (void) loaderPrivate
;
511 dri2_x11_connect(struct dri2_egl_display
*dri2_dpy
)
513 xcb_xfixes_query_version_reply_t
*xfixes_query
;
514 xcb_xfixes_query_version_cookie_t xfixes_query_cookie
;
515 xcb_dri2_query_version_reply_t
*dri2_query
;
516 xcb_dri2_query_version_cookie_t dri2_query_cookie
;
517 xcb_dri2_connect_reply_t
*connect
;
518 xcb_dri2_connect_cookie_t connect_cookie
;
519 xcb_generic_error_t
*error
;
520 xcb_screen_iterator_t s
;
521 xcb_screen_t
*screen
;
522 char *driver_name
, *device_name
;
523 const xcb_query_extension_reply_t
*extension
;
525 xcb_prefetch_extension_data (dri2_dpy
->conn
, &xcb_xfixes_id
);
526 xcb_prefetch_extension_data (dri2_dpy
->conn
, &xcb_dri2_id
);
528 extension
= xcb_get_extension_data(dri2_dpy
->conn
, &xcb_xfixes_id
);
529 if (!(extension
&& extension
->present
))
532 extension
= xcb_get_extension_data(dri2_dpy
->conn
, &xcb_dri2_id
);
533 if (!(extension
&& extension
->present
))
536 xfixes_query_cookie
= xcb_xfixes_query_version(dri2_dpy
->conn
,
537 XCB_XFIXES_MAJOR_VERSION
,
538 XCB_XFIXES_MINOR_VERSION
);
540 dri2_query_cookie
= xcb_dri2_query_version (dri2_dpy
->conn
,
541 XCB_DRI2_MAJOR_VERSION
,
542 XCB_DRI2_MINOR_VERSION
);
544 s
= xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy
->conn
));
545 screen
= get_xcb_screen(s
, dri2_dpy
->screen
);
547 _eglError(EGL_BAD_NATIVE_WINDOW
, "dri2_x11_connect");
550 connect_cookie
= xcb_dri2_connect_unchecked(dri2_dpy
->conn
, screen
->root
,
551 XCB_DRI2_DRIVER_TYPE_DRI
);
554 xcb_xfixes_query_version_reply (dri2_dpy
->conn
,
555 xfixes_query_cookie
, &error
);
556 if (xfixes_query
== NULL
||
557 error
!= NULL
|| xfixes_query
->major_version
< 2) {
558 _eglLog(_EGL_WARNING
, "DRI2: failed to query xfixes version");
565 xcb_dri2_query_version_reply (dri2_dpy
->conn
, dri2_query_cookie
, &error
);
566 if (dri2_query
== NULL
|| error
!= NULL
) {
567 _eglLog(_EGL_WARNING
, "DRI2: failed to query version");
571 dri2_dpy
->dri2_major
= dri2_query
->major_version
;
572 dri2_dpy
->dri2_minor
= dri2_query
->minor_version
;
575 connect
= xcb_dri2_connect_reply (dri2_dpy
->conn
, connect_cookie
, NULL
);
576 if (connect
== NULL
||
577 connect
->driver_name_length
+ connect
->device_name_length
== 0) {
578 _eglLog(_EGL_WARNING
, "DRI2: failed to authenticate");
582 driver_name
= xcb_dri2_connect_driver_name (connect
);
583 dri2_dpy
->driver_name
=
585 xcb_dri2_connect_driver_name_length(connect
));
587 device_name
= xcb_dri2_connect_device_name (connect
);
589 dri2_dpy
->device_name
=
591 xcb_dri2_connect_device_name_length(connect
));
593 if (dri2_dpy
->device_name
== NULL
|| dri2_dpy
->driver_name
== NULL
) {
594 free(dri2_dpy
->device_name
);
595 free(dri2_dpy
->driver_name
);
605 dri2_x11_authenticate(_EGLDisplay
*disp
, uint32_t id
)
607 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
608 xcb_dri2_authenticate_reply_t
*authenticate
;
609 xcb_dri2_authenticate_cookie_t authenticate_cookie
;
610 xcb_screen_iterator_t s
;
611 xcb_screen_t
*screen
;
614 s
= xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy
->conn
));
616 screen
= get_xcb_screen(s
, dri2_dpy
->screen
);
618 _eglError(EGL_BAD_NATIVE_WINDOW
, "dri2_x11_authenticate");
622 authenticate_cookie
=
623 xcb_dri2_authenticate_unchecked(dri2_dpy
->conn
, screen
->root
, id
);
625 xcb_dri2_authenticate_reply(dri2_dpy
->conn
, authenticate_cookie
, NULL
);
627 if (authenticate
== NULL
|| !authenticate
->authenticated
)
636 dri2_x11_local_authenticate(_EGLDisplay
*disp
)
639 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
642 if (drmGetMagic(dri2_dpy
->fd
, &magic
)) {
643 _eglLog(_EGL_WARNING
, "DRI2: failed to get drm magic");
647 if (dri2_x11_authenticate(disp
, magic
) < 0) {
648 _eglLog(_EGL_WARNING
, "DRI2: failed to authenticate");
656 dri2_x11_add_configs_for_visuals(struct dri2_egl_display
*dri2_dpy
,
659 xcb_screen_iterator_t s
;
660 xcb_depth_iterator_t d
;
661 xcb_visualtype_t
*visuals
;
663 unsigned int rgba_masks
[4];
665 EGLint config_attrs
[] = {
666 EGL_NATIVE_VISUAL_ID
, 0,
667 EGL_NATIVE_VISUAL_TYPE
, 0,
671 s
= xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy
->conn
));
672 d
= xcb_screen_allowed_depths_iterator(get_xcb_screen(s
, dri2_dpy
->screen
));
679 EGL_SWAP_BEHAVIOR_PRESERVED_BIT
;
682 EGLBoolean class_added
[6] = { 0, };
684 visuals
= xcb_depth_visuals(d
.data
);
685 for (i
= 0; i
< xcb_depth_visuals_length(d
.data
); i
++) {
686 if (class_added
[visuals
[i
]._class
])
689 class_added
[visuals
[i
]._class
] = EGL_TRUE
;
690 for (j
= 0; dri2_dpy
->driver_configs
[j
]; j
++) {
691 config_attrs
[1] = visuals
[i
].visual_id
;
692 config_attrs
[3] = visuals
[i
]._class
;
694 rgba_masks
[0] = visuals
[i
].red_mask
;
695 rgba_masks
[1] = visuals
[i
].green_mask
;
696 rgba_masks
[2] = visuals
[i
].blue_mask
;
698 dri2_add_config(disp
, dri2_dpy
->driver_configs
[j
], id
++,
699 surface_type
, config_attrs
, rgba_masks
);
701 /* Allow a 24-bit RGB visual to match a 32-bit RGBA EGLConfig.
702 * Otherwise it will only match a 32-bit RGBA visual. On a
703 * composited window manager on X11, this will make all of the
704 * EGLConfigs with destination alpha get blended by the
705 * compositor. This is probably not what the application
706 * wants... especially on drivers that only have 32-bit RGBA
708 if (d
.data
->depth
== 24) {
710 ~(rgba_masks
[0] | rgba_masks
[1] | rgba_masks
[2]);
711 dri2_add_config(disp
, dri2_dpy
->driver_configs
[j
], id
++,
712 surface_type
, config_attrs
, rgba_masks
);
720 if (!_eglGetArraySize(disp
->Configs
)) {
721 _eglLog(_EGL_WARNING
, "DRI2: failed to create any config");
729 dri2_copy_region(_EGLDriver
*drv
, _EGLDisplay
*disp
,
730 _EGLSurface
*draw
, xcb_xfixes_region_t region
)
732 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
733 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
734 enum xcb_dri2_attachment_t render_attachment
;
735 xcb_dri2_copy_region_cookie_t cookie
;
737 /* No-op for a pixmap or pbuffer surface */
738 if (draw
->Type
== EGL_PIXMAP_BIT
|| draw
->Type
== EGL_PBUFFER_BIT
)
742 (*dri2_dpy
->flush
->flush
)(dri2_surf
->dri_drawable
);
744 if (dri2_surf
->have_fake_front
)
745 render_attachment
= XCB_DRI2_ATTACHMENT_BUFFER_FAKE_FRONT_LEFT
;
747 render_attachment
= XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT
;
749 cookie
= xcb_dri2_copy_region_unchecked(dri2_dpy
->conn
,
752 XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT
,
754 free(xcb_dri2_copy_region_reply(dri2_dpy
->conn
, cookie
, NULL
));
760 dri2_x11_swap_buffers_msc(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
,
761 int64_t msc
, int64_t divisor
, int64_t remainder
)
763 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
764 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
765 uint32_t msc_hi
= msc
>> 32;
766 uint32_t msc_lo
= msc
& 0xffffffff;
767 uint32_t divisor_hi
= divisor
>> 32;
768 uint32_t divisor_lo
= divisor
& 0xffffffff;
769 uint32_t remainder_hi
= remainder
>> 32;
770 uint32_t remainder_lo
= remainder
& 0xffffffff;
771 xcb_dri2_swap_buffers_cookie_t cookie
;
772 xcb_dri2_swap_buffers_reply_t
*reply
;
773 int64_t swap_count
= -1;
775 /* No-op for a pixmap or pbuffer surface */
776 if (draw
->Type
== EGL_PIXMAP_BIT
|| draw
->Type
== EGL_PBUFFER_BIT
)
779 if (draw
->SwapBehavior
== EGL_BUFFER_PRESERVED
|| !dri2_dpy
->swap_available
)
780 return dri2_copy_region(drv
, disp
, draw
, dri2_surf
->region
) ? 0 : -1;
782 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
784 cookie
= xcb_dri2_swap_buffers_unchecked(dri2_dpy
->conn
, dri2_surf
->drawable
,
785 msc_hi
, msc_lo
, divisor_hi
, divisor_lo
, remainder_hi
, remainder_lo
);
787 reply
= xcb_dri2_swap_buffers_reply(dri2_dpy
->conn
, cookie
, NULL
);
790 swap_count
= (((int64_t)reply
->swap_hi
) << 32) | reply
->swap_lo
;
794 /* Since we aren't watching for the server's invalidate events like we're
795 * supposed to (due to XCB providing no mechanism for filtering the events
796 * the way xlib does), and SwapBuffers is a common cause of invalidate
797 * events, just shove one down to the driver, even though we haven't told
798 * the driver that we're the kind of loader that provides reliable
799 * invalidate events. This causes the driver to request buffers again at
800 * its next draw, so that we get the correct buffers if a pageflip
801 * happened. The driver should still be using the viewport hack to catch
804 if (dri2_dpy
->flush
&&
805 dri2_dpy
->flush
->base
.version
>= 3 && dri2_dpy
->flush
->invalidate
)
806 (*dri2_dpy
->flush
->invalidate
)(dri2_surf
->dri_drawable
);
812 dri2_x11_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
814 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
815 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
817 if (dri2_dpy
->dri2
) {
818 return dri2_x11_swap_buffers_msc(drv
, disp
, draw
, 0, 0, 0) != -1;
820 assert(dri2_dpy
->swrast
);
822 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
828 dri2_x11_swap_buffers_region(_EGLDriver
*drv
, _EGLDisplay
*disp
,
830 EGLint numRects
, const EGLint
*rects
)
832 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
833 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
835 xcb_xfixes_region_t region
;
836 xcb_rectangle_t rectangles
[16];
839 if (numRects
> (int)ARRAY_SIZE(rectangles
))
840 return dri2_copy_region(drv
, disp
, draw
, dri2_surf
->region
);
842 for (i
= 0; i
< numRects
; i
++) {
843 rectangles
[i
].x
= rects
[i
* 4];
844 rectangles
[i
].y
= dri2_surf
->base
.Height
- rects
[i
* 4 + 1] - rects
[i
* 4 + 3];
845 rectangles
[i
].width
= rects
[i
* 4 + 2];
846 rectangles
[i
].height
= rects
[i
* 4 + 3];
849 region
= xcb_generate_id(dri2_dpy
->conn
);
850 xcb_xfixes_create_region(dri2_dpy
->conn
, region
, numRects
, rectangles
);
851 ret
= dri2_copy_region(drv
, disp
, draw
, region
);
852 xcb_xfixes_destroy_region(dri2_dpy
->conn
, region
);
858 dri2_x11_post_sub_buffer(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
,
859 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
861 const EGLint rect
[4] = { x
, y
, width
, height
};
863 if (x
< 0 || y
< 0 || width
< 0 || height
< 0)
864 _eglError(EGL_BAD_PARAMETER
, "eglPostSubBufferNV");
866 return dri2_x11_swap_buffers_region(drv
, disp
, draw
, 1, rect
);
870 dri2_x11_swap_interval(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
,
873 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
874 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
876 if (interval
> surf
->Config
->MaxSwapInterval
)
877 interval
= surf
->Config
->MaxSwapInterval
;
878 else if (interval
< surf
->Config
->MinSwapInterval
)
879 interval
= surf
->Config
->MinSwapInterval
;
881 if (interval
!= surf
->SwapInterval
&& dri2_dpy
->swap_available
)
882 xcb_dri2_swap_interval(dri2_dpy
->conn
, dri2_surf
->drawable
, interval
);
884 surf
->SwapInterval
= interval
;
890 dri2_x11_copy_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
,
891 void *native_pixmap_target
)
893 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
894 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
898 STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_pixmap_target
));
899 target
= (uintptr_t) native_pixmap_target
;
903 (*dri2_dpy
->flush
->flush
)(dri2_surf
->dri_drawable
);
905 gc
= xcb_generate_id(dri2_dpy
->conn
);
906 xcb_create_gc(dri2_dpy
->conn
, gc
, target
, 0, NULL
);
907 xcb_copy_area(dri2_dpy
->conn
,
913 dri2_surf
->base
.Width
,
914 dri2_surf
->base
.Height
);
915 xcb_free_gc(dri2_dpy
->conn
, gc
);
921 dri2_create_image_khr_pixmap(_EGLDisplay
*disp
, _EGLContext
*ctx
,
922 EGLClientBuffer buffer
, const EGLint
*attr_list
)
924 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
925 struct dri2_egl_image
*dri2_img
;
926 unsigned int attachments
[1];
927 xcb_drawable_t drawable
;
928 xcb_dri2_get_buffers_cookie_t buffers_cookie
;
929 xcb_dri2_get_buffers_reply_t
*buffers_reply
;
930 xcb_dri2_dri2_buffer_t
*buffers
;
931 xcb_get_geometry_cookie_t geometry_cookie
;
932 xcb_get_geometry_reply_t
*geometry_reply
;
933 xcb_generic_error_t
*error
;
938 drawable
= (xcb_drawable_t
) (uintptr_t) buffer
;
939 xcb_dri2_create_drawable (dri2_dpy
->conn
, drawable
);
940 attachments
[0] = XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT
;
942 xcb_dri2_get_buffers_unchecked (dri2_dpy
->conn
,
943 drawable
, 1, 1, attachments
);
944 geometry_cookie
= xcb_get_geometry (dri2_dpy
->conn
, drawable
);
945 buffers_reply
= xcb_dri2_get_buffers_reply (dri2_dpy
->conn
,
946 buffers_cookie
, NULL
);
947 buffers
= xcb_dri2_get_buffers_buffers (buffers_reply
);
948 if (buffers
== NULL
) {
952 geometry_reply
= xcb_get_geometry_reply (dri2_dpy
->conn
,
953 geometry_cookie
, &error
);
954 if (geometry_reply
== NULL
|| error
!= NULL
) {
955 _eglError(EGL_BAD_ALLOC
, "xcb_get_geometry");
961 switch (geometry_reply
->depth
) {
963 format
= __DRI_IMAGE_FORMAT_RGB565
;
966 format
= __DRI_IMAGE_FORMAT_XRGB8888
;
969 format
= __DRI_IMAGE_FORMAT_ARGB8888
;
972 _eglError(EGL_BAD_PARAMETER
,
973 "dri2_create_image_khr: unsupported pixmap depth");
975 free(geometry_reply
);
979 dri2_img
= malloc(sizeof *dri2_img
);
982 free(geometry_reply
);
983 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
984 return EGL_NO_IMAGE_KHR
;
987 if (!_eglInitImage(&dri2_img
->base
, disp
)) {
989 free(geometry_reply
);
991 return EGL_NO_IMAGE_KHR
;
994 stride
= buffers
[0].pitch
/ buffers
[0].cpp
;
995 dri2_img
->dri_image
=
996 dri2_dpy
->image
->createImageFromName(dri2_dpy
->dri_screen
,
997 buffers_reply
->width
,
998 buffers_reply
->height
,
1004 free(buffers_reply
);
1005 free(geometry_reply
);
1007 return &dri2_img
->base
;
1011 dri2_x11_create_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
,
1012 _EGLContext
*ctx
, EGLenum target
,
1013 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1018 case EGL_NATIVE_PIXMAP_KHR
:
1019 return dri2_create_image_khr_pixmap(disp
, ctx
, buffer
, attr_list
);
1021 return dri2_create_image_khr(drv
, disp
, ctx
, target
, buffer
, attr_list
);
1026 dri2_x11_get_sync_values(_EGLDisplay
*display
, _EGLSurface
*surface
,
1027 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
1030 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(display
);
1031 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
1032 xcb_dri2_get_msc_cookie_t cookie
;
1033 xcb_dri2_get_msc_reply_t
*reply
;
1035 cookie
= xcb_dri2_get_msc(dri2_dpy
->conn
, dri2_surf
->drawable
);
1036 reply
= xcb_dri2_get_msc_reply(dri2_dpy
->conn
, cookie
, NULL
);
1039 _eglError(EGL_BAD_ACCESS
, __func__
);
1043 *ust
= ((EGLuint64KHR
) reply
->ust_hi
<< 32) | reply
->ust_lo
;
1044 *msc
= ((EGLuint64KHR
) reply
->msc_hi
<< 32) | reply
->msc_lo
;
1045 *sbc
= ((EGLuint64KHR
) reply
->sbc_hi
<< 32) | reply
->sbc_lo
;
1051 static struct dri2_egl_display_vtbl dri2_x11_swrast_display_vtbl
= {
1052 .authenticate
= NULL
,
1053 .create_window_surface
= dri2_x11_create_window_surface
,
1054 .create_pixmap_surface
= dri2_x11_create_pixmap_surface
,
1055 .create_pbuffer_surface
= dri2_x11_create_pbuffer_surface
,
1056 .destroy_surface
= dri2_x11_destroy_surface
,
1057 .create_image
= dri2_fallback_create_image_khr
,
1058 .swap_interval
= dri2_fallback_swap_interval
,
1059 .swap_buffers
= dri2_x11_swap_buffers
,
1060 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1061 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1062 .copy_buffers
= dri2_x11_copy_buffers
,
1063 .query_buffer_age
= dri2_fallback_query_buffer_age
,
1064 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
1065 .get_sync_values
= dri2_fallback_get_sync_values
,
1068 static struct dri2_egl_display_vtbl dri2_x11_display_vtbl
= {
1069 .authenticate
= dri2_x11_authenticate
,
1070 .create_window_surface
= dri2_x11_create_window_surface
,
1071 .create_pixmap_surface
= dri2_x11_create_pixmap_surface
,
1072 .create_pbuffer_surface
= dri2_x11_create_pbuffer_surface
,
1073 .destroy_surface
= dri2_x11_destroy_surface
,
1074 .create_image
= dri2_x11_create_image_khr
,
1075 .swap_interval
= dri2_x11_swap_interval
,
1076 .swap_buffers
= dri2_x11_swap_buffers
,
1077 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
1078 .swap_buffers_region
= dri2_x11_swap_buffers_region
,
1079 .post_sub_buffer
= dri2_x11_post_sub_buffer
,
1080 .copy_buffers
= dri2_x11_copy_buffers
,
1081 .query_buffer_age
= dri2_fallback_query_buffer_age
,
1082 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
1083 .get_sync_values
= dri2_x11_get_sync_values
,
1087 dri2_initialize_x11_swrast(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1089 struct dri2_egl_display
*dri2_dpy
;
1091 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1093 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1095 disp
->DriverData
= (void *) dri2_dpy
;
1096 if (disp
->PlatformDisplay
== NULL
) {
1097 dri2_dpy
->conn
= xcb_connect(0, &dri2_dpy
->screen
);
1098 dri2_dpy
->own_device
= true;
1100 Display
*dpy
= disp
->PlatformDisplay
;
1102 dri2_dpy
->conn
= XGetXCBConnection(dpy
);
1103 dri2_dpy
->screen
= DefaultScreen(dpy
);
1106 if (xcb_connection_has_error(dri2_dpy
->conn
)) {
1107 _eglLog(_EGL_WARNING
, "DRI2: xcb_connect failed");
1112 * Every hardware driver_name is set using strdup. Doing the same in
1113 * here will allow is to simply free the memory at dri2_terminate().
1115 dri2_dpy
->driver_name
= strdup("swrast");
1116 if (!dri2_load_driver_swrast(disp
))
1119 dri2_dpy
->swrast_loader_extension
.base
.name
= __DRI_SWRAST_LOADER
;
1120 dri2_dpy
->swrast_loader_extension
.base
.version
= 2;
1121 dri2_dpy
->swrast_loader_extension
.getDrawableInfo
= swrastGetDrawableInfo
;
1122 dri2_dpy
->swrast_loader_extension
.putImage
= swrastPutImage
;
1123 dri2_dpy
->swrast_loader_extension
.getImage
= swrastGetImage
;
1125 dri2_dpy
->extensions
[0] = &dri2_dpy
->swrast_loader_extension
.base
;
1126 dri2_dpy
->extensions
[1] = NULL
;
1127 dri2_dpy
->extensions
[2] = NULL
;
1129 if (!dri2_create_screen(disp
))
1130 goto cleanup_driver
;
1132 if (dri2_dpy
->conn
) {
1133 if (!dri2_x11_add_configs_for_visuals(dri2_dpy
, disp
))
1134 goto cleanup_configs
;
1137 /* Fill vtbl last to prevent accidentally calling virtual function during
1140 dri2_dpy
->vtbl
= &dri2_x11_swrast_display_vtbl
;
1145 _eglCleanupDisplay(disp
);
1146 dri2_dpy
->core
->destroyScreen(dri2_dpy
->dri_screen
);
1148 dlclose(dri2_dpy
->driver
);
1150 free(dri2_dpy
->driver_name
);
1151 if (disp
->PlatformDisplay
== NULL
)
1152 xcb_disconnect(dri2_dpy
->conn
);
1160 dri2_x11_setup_swap_interval(struct dri2_egl_display
*dri2_dpy
)
1162 GLint vblank_mode
= DRI_CONF_VBLANK_DEF_INTERVAL_1
;
1163 int arbitrary_max_interval
= 1000;
1165 /* default behavior for no SwapBuffers support: no vblank syncing
1168 dri2_dpy
->min_swap_interval
= 0;
1169 dri2_dpy
->max_swap_interval
= 0;
1171 if (!dri2_dpy
->swap_available
)
1174 /* If we do have swapbuffers, then we can support pretty much any swap
1175 * interval, but we allow driconf to override applications.
1177 if (dri2_dpy
->config
)
1178 dri2_dpy
->config
->configQueryi(dri2_dpy
->dri_screen
,
1179 "vblank_mode", &vblank_mode
);
1180 switch (vblank_mode
) {
1181 case DRI_CONF_VBLANK_NEVER
:
1182 dri2_dpy
->min_swap_interval
= 0;
1183 dri2_dpy
->max_swap_interval
= 0;
1184 dri2_dpy
->default_swap_interval
= 0;
1186 case DRI_CONF_VBLANK_ALWAYS_SYNC
:
1187 dri2_dpy
->min_swap_interval
= 1;
1188 dri2_dpy
->max_swap_interval
= arbitrary_max_interval
;
1189 dri2_dpy
->default_swap_interval
= 1;
1191 case DRI_CONF_VBLANK_DEF_INTERVAL_0
:
1192 dri2_dpy
->min_swap_interval
= 0;
1193 dri2_dpy
->max_swap_interval
= arbitrary_max_interval
;
1194 dri2_dpy
->default_swap_interval
= 0;
1197 case DRI_CONF_VBLANK_DEF_INTERVAL_1
:
1198 dri2_dpy
->min_swap_interval
= 0;
1199 dri2_dpy
->max_swap_interval
= arbitrary_max_interval
;
1200 dri2_dpy
->default_swap_interval
= 1;
1206 dri2_initialize_x11_dri2(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1208 struct dri2_egl_display
*dri2_dpy
;
1210 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1212 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1214 disp
->DriverData
= (void *) dri2_dpy
;
1215 if (disp
->PlatformDisplay
== NULL
) {
1216 dri2_dpy
->conn
= xcb_connect(0, &dri2_dpy
->screen
);
1217 dri2_dpy
->own_device
= true;
1219 Display
*dpy
= disp
->PlatformDisplay
;
1221 dri2_dpy
->conn
= XGetXCBConnection(dpy
);
1222 dri2_dpy
->screen
= DefaultScreen(dpy
);
1225 if (xcb_connection_has_error(dri2_dpy
->conn
)) {
1226 _eglLog(_EGL_WARNING
, "DRI2: xcb_connect failed");
1230 if (dri2_dpy
->conn
) {
1231 if (!dri2_x11_connect(dri2_dpy
))
1235 if (!dri2_load_driver(disp
))
1238 dri2_dpy
->fd
= loader_open_device(dri2_dpy
->device_name
);
1239 if (dri2_dpy
->fd
== -1) {
1240 _eglLog(_EGL_WARNING
,
1241 "DRI2: could not open %s (%s)", dri2_dpy
->device_name
,
1243 goto cleanup_driver
;
1246 if (dri2_dpy
->conn
) {
1247 if (!dri2_x11_local_authenticate(disp
))
1251 if (dri2_dpy
->dri2_minor
>= 1) {
1252 dri2_dpy
->dri2_loader_extension
.base
.name
= __DRI_DRI2_LOADER
;
1253 dri2_dpy
->dri2_loader_extension
.base
.version
= 3;
1254 dri2_dpy
->dri2_loader_extension
.getBuffers
= dri2_x11_get_buffers
;
1255 dri2_dpy
->dri2_loader_extension
.flushFrontBuffer
= dri2_x11_flush_front_buffer
;
1256 dri2_dpy
->dri2_loader_extension
.getBuffersWithFormat
=
1257 dri2_x11_get_buffers_with_format
;
1259 dri2_dpy
->dri2_loader_extension
.base
.name
= __DRI_DRI2_LOADER
;
1260 dri2_dpy
->dri2_loader_extension
.base
.version
= 2;
1261 dri2_dpy
->dri2_loader_extension
.getBuffers
= dri2_x11_get_buffers
;
1262 dri2_dpy
->dri2_loader_extension
.flushFrontBuffer
= dri2_x11_flush_front_buffer
;
1263 dri2_dpy
->dri2_loader_extension
.getBuffersWithFormat
= NULL
;
1266 dri2_dpy
->extensions
[0] = &dri2_dpy
->dri2_loader_extension
.base
;
1267 dri2_dpy
->extensions
[1] = &image_lookup_extension
.base
;
1268 dri2_dpy
->extensions
[2] = NULL
;
1270 dri2_dpy
->swap_available
= (dri2_dpy
->dri2_minor
>= 2);
1271 dri2_dpy
->invalidate_available
= (dri2_dpy
->dri2_minor
>= 3);
1273 if (!dri2_create_screen(disp
))
1276 dri2_x11_setup_swap_interval(dri2_dpy
);
1278 disp
->Extensions
.KHR_image_pixmap
= EGL_TRUE
;
1279 disp
->Extensions
.NOK_swap_region
= EGL_TRUE
;
1280 disp
->Extensions
.NOK_texture_from_pixmap
= EGL_TRUE
;
1281 disp
->Extensions
.NV_post_sub_buffer
= EGL_TRUE
;
1282 disp
->Extensions
.CHROMIUM_sync_control
= EGL_TRUE
;
1284 #ifdef HAVE_WAYLAND_PLATFORM
1285 disp
->Extensions
.WL_bind_wayland_display
= EGL_TRUE
;
1288 if (dri2_dpy
->conn
) {
1289 if (!dri2_x11_add_configs_for_visuals(dri2_dpy
, disp
))
1290 goto cleanup_configs
;
1293 /* Fill vtbl last to prevent accidentally calling virtual function during
1296 dri2_dpy
->vtbl
= &dri2_x11_display_vtbl
;
1301 _eglCleanupDisplay(disp
);
1302 dri2_dpy
->core
->destroyScreen(dri2_dpy
->dri_screen
);
1304 close(dri2_dpy
->fd
);
1306 dlclose(dri2_dpy
->driver
);
1308 if (disp
->PlatformDisplay
== NULL
)
1309 xcb_disconnect(dri2_dpy
->conn
);
1317 dri2_initialize_x11(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1319 EGLBoolean initialized
= EGL_TRUE
;
1321 int x11_dri2_accel
= (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL
);
1323 if (x11_dri2_accel
) {
1324 if (!dri2_initialize_x11_dri2(drv
, disp
)) {
1325 initialized
= dri2_initialize_x11_swrast(drv
, disp
);
1328 initialized
= dri2_initialize_x11_swrast(drv
, disp
);