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 #include "platform_x11_dri3.h"
53 dri2_x11_swap_interval(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
,
57 swrastCreateDrawable(struct dri2_egl_display
* dri2_dpy
,
58 struct dri2_egl_surface
* dri2_surf
)
61 const uint32_t function
= GXcopy
;
65 dri2_surf
->gc
= xcb_generate_id(dri2_dpy
->conn
);
66 mask
= XCB_GC_FUNCTION
;
67 xcb_create_gc(dri2_dpy
->conn
, dri2_surf
->gc
, dri2_surf
->drawable
, mask
, &function
);
69 dri2_surf
->swapgc
= xcb_generate_id(dri2_dpy
->conn
);
70 mask
= XCB_GC_FUNCTION
| XCB_GC_GRAPHICS_EXPOSURES
;
73 xcb_create_gc(dri2_dpy
->conn
, dri2_surf
->swapgc
, dri2_surf
->drawable
, mask
, valgc
);
74 switch (dri2_surf
->depth
) {
77 dri2_surf
->bytes_per_pixel
= 4;
80 dri2_surf
->bytes_per_pixel
= 2;
83 dri2_surf
->bytes_per_pixel
= 1;
86 dri2_surf
->bytes_per_pixel
= 0;
89 _eglLog(_EGL_WARNING
, "unsupported depth %d", dri2_surf
->depth
);
94 swrastDestroyDrawable(struct dri2_egl_display
* dri2_dpy
,
95 struct dri2_egl_surface
* dri2_surf
)
97 xcb_free_gc(dri2_dpy
->conn
, dri2_surf
->gc
);
98 xcb_free_gc(dri2_dpy
->conn
, dri2_surf
->swapgc
);
102 swrastGetDrawableInfo(__DRIdrawable
* draw
,
103 int *x
, int *y
, int *w
, int *h
,
106 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
107 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
109 xcb_get_geometry_cookie_t cookie
;
110 xcb_get_geometry_reply_t
*reply
;
111 xcb_generic_error_t
*error
;
114 cookie
= xcb_get_geometry (dri2_dpy
->conn
, dri2_surf
->drawable
);
115 reply
= xcb_get_geometry_reply (dri2_dpy
->conn
, cookie
, &error
);
120 _eglLog(_EGL_WARNING
, "error in xcb_get_geometry");
130 swrastPutImage(__DRIdrawable
* draw
, int op
,
131 int x
, int y
, int w
, int h
,
132 char *data
, void *loaderPrivate
)
134 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
135 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
140 case __DRI_SWRAST_IMAGE_OP_DRAW
:
143 case __DRI_SWRAST_IMAGE_OP_SWAP
:
144 gc
= dri2_surf
->swapgc
;
150 xcb_put_image(dri2_dpy
->conn
, XCB_IMAGE_FORMAT_Z_PIXMAP
, dri2_surf
->drawable
,
151 gc
, w
, h
, x
, y
, 0, dri2_surf
->depth
,
152 w
*h
*dri2_surf
->bytes_per_pixel
, (const uint8_t *)data
);
156 swrastGetImage(__DRIdrawable
* read
,
157 int x
, int y
, int w
, int h
,
158 char *data
, void *loaderPrivate
)
160 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
161 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
163 xcb_get_image_cookie_t cookie
;
164 xcb_get_image_reply_t
*reply
;
165 xcb_generic_error_t
*error
;
167 cookie
= xcb_get_image (dri2_dpy
->conn
, XCB_IMAGE_FORMAT_Z_PIXMAP
,
168 dri2_surf
->drawable
, x
, y
, w
, h
, ~0);
169 reply
= xcb_get_image_reply (dri2_dpy
->conn
, cookie
, &error
);
174 _eglLog(_EGL_WARNING
, "error in xcb_get_image");
177 uint32_t bytes
= xcb_get_image_data_length(reply
);
178 uint8_t *idata
= xcb_get_image_data(reply
);
179 memcpy(data
, idata
, bytes
);
185 static xcb_screen_t
*
186 get_xcb_screen(xcb_screen_iterator_t iter
, int screen
)
188 for (; iter
.rem
; --screen
, xcb_screen_next(&iter
))
197 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
200 dri2_x11_create_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, EGLint type
,
201 _EGLConfig
*conf
, void *native_surface
,
202 const EGLint
*attrib_list
)
204 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
205 struct dri2_egl_config
*dri2_conf
= dri2_egl_config(conf
);
206 struct dri2_egl_surface
*dri2_surf
;
207 xcb_get_geometry_cookie_t cookie
;
208 xcb_get_geometry_reply_t
*reply
;
209 xcb_screen_iterator_t s
;
210 xcb_generic_error_t
*error
;
211 xcb_drawable_t drawable
;
212 xcb_screen_t
*screen
;
213 const __DRIconfig
*config
;
215 STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_surface
));
216 drawable
= (uintptr_t) native_surface
;
220 dri2_surf
= malloc(sizeof *dri2_surf
);
222 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
226 if (!_eglInitSurface(&dri2_surf
->base
, disp
, type
, conf
, attrib_list
))
229 dri2_surf
->region
= XCB_NONE
;
230 if (type
== EGL_PBUFFER_BIT
) {
231 s
= xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy
->conn
));
232 screen
= get_xcb_screen(s
, dri2_dpy
->screen
);
234 _eglError(EGL_BAD_ALLOC
, "failed to get xcb screen");
238 dri2_surf
->drawable
= xcb_generate_id(dri2_dpy
->conn
);
239 xcb_create_pixmap(dri2_dpy
->conn
, conf
->BufferSize
,
240 dri2_surf
->drawable
, screen
->root
,
241 dri2_surf
->base
.Width
, dri2_surf
->base
.Height
);
244 if (type
== EGL_WINDOW_BIT
)
245 _eglError(EGL_BAD_NATIVE_WINDOW
, "dri2_create_surface");
247 _eglError(EGL_BAD_NATIVE_PIXMAP
, "dri2_create_surface");
250 dri2_surf
->drawable
= drawable
;
253 config
= dri2_get_dri_config(dri2_conf
, type
,
254 dri2_surf
->base
.GLColorspace
);
256 if (dri2_dpy
->dri2
) {
257 dri2_surf
->dri_drawable
=
258 (*dri2_dpy
->dri2
->createNewDrawable
)(dri2_dpy
->dri_screen
, config
,
261 assert(dri2_dpy
->swrast
);
262 dri2_surf
->dri_drawable
=
263 (*dri2_dpy
->swrast
->createNewDrawable
)(dri2_dpy
->dri_screen
, config
,
267 if (dri2_surf
->dri_drawable
== NULL
) {
268 _eglError(EGL_BAD_ALLOC
, "dri2->createNewDrawable");
272 if (type
!= EGL_PBUFFER_BIT
) {
273 cookie
= xcb_get_geometry (dri2_dpy
->conn
, dri2_surf
->drawable
);
274 reply
= xcb_get_geometry_reply (dri2_dpy
->conn
, cookie
, &error
);
276 if (error
->error_code
== BadAlloc
)
277 _eglError(EGL_BAD_ALLOC
, "xcb_get_geometry");
278 else if (type
== EGL_WINDOW_BIT
)
279 _eglError(EGL_BAD_NATIVE_WINDOW
, "xcb_get_geometry");
281 _eglError(EGL_BAD_NATIVE_PIXMAP
, "xcb_get_geometry");
283 goto cleanup_dri_drawable
;
284 } else if (reply
== NULL
) {
285 _eglError(EGL_BAD_ALLOC
, "xcb_get_geometry");
286 goto cleanup_dri_drawable
;
289 dri2_surf
->base
.Width
= reply
->width
;
290 dri2_surf
->base
.Height
= reply
->height
;
291 dri2_surf
->depth
= reply
->depth
;
295 if (dri2_dpy
->dri2
) {
296 xcb_void_cookie_t cookie
;
299 cookie
= xcb_dri2_create_drawable_checked(dri2_dpy
->conn
,
300 dri2_surf
->drawable
);
301 error
= xcb_request_check(dri2_dpy
->conn
, cookie
);
302 conn_error
= xcb_connection_has_error(dri2_dpy
->conn
);
303 if (conn_error
|| error
!= NULL
) {
304 if (type
== EGL_PBUFFER_BIT
|| conn_error
|| error
->error_code
== BadAlloc
)
305 _eglError(EGL_BAD_ALLOC
, "xcb_dri2_create_drawable_checked");
306 else if (type
== EGL_WINDOW_BIT
)
307 _eglError(EGL_BAD_NATIVE_WINDOW
,
308 "xcb_dri2_create_drawable_checked");
310 _eglError(EGL_BAD_NATIVE_PIXMAP
,
311 "xcb_dri2_create_drawable_checked");
313 goto cleanup_dri_drawable
;
316 if (type
== EGL_PBUFFER_BIT
) {
317 dri2_surf
->depth
= _eglGetConfigKey(conf
, EGL_BUFFER_SIZE
);
319 swrastCreateDrawable(dri2_dpy
, dri2_surf
);
322 /* we always copy the back buffer to front */
323 dri2_surf
->base
.PostSubBufferSupportedNV
= EGL_TRUE
;
325 return &dri2_surf
->base
;
327 cleanup_dri_drawable
:
328 dri2_dpy
->core
->destroyDrawable(dri2_surf
->dri_drawable
);
330 if (type
== EGL_PBUFFER_BIT
)
331 xcb_free_pixmap(dri2_dpy
->conn
, dri2_surf
->drawable
);
339 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
342 dri2_x11_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
343 _EGLConfig
*conf
, void *native_window
,
344 const EGLint
*attrib_list
)
346 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
349 surf
= dri2_x11_create_surface(drv
, disp
, EGL_WINDOW_BIT
, conf
,
350 native_window
, attrib_list
);
352 /* When we first create the DRI2 drawable, its swap interval on the
355 surf
->SwapInterval
= 1;
357 /* Override that with a driconf-set value. */
358 dri2_x11_swap_interval(drv
, disp
, surf
, dri2_dpy
->default_swap_interval
);
365 dri2_x11_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
366 _EGLConfig
*conf
, void *native_pixmap
,
367 const EGLint
*attrib_list
)
369 return dri2_x11_create_surface(drv
, disp
, EGL_PIXMAP_BIT
, conf
,
370 native_pixmap
, attrib_list
);
374 dri2_x11_create_pbuffer_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
375 _EGLConfig
*conf
, const EGLint
*attrib_list
)
377 return dri2_x11_create_surface(drv
, disp
, EGL_PBUFFER_BIT
, conf
,
378 XCB_WINDOW_NONE
, attrib_list
);
382 dri2_x11_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
384 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
385 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
389 if (!_eglPutSurface(surf
))
392 (*dri2_dpy
->core
->destroyDrawable
)(dri2_surf
->dri_drawable
);
394 if (dri2_dpy
->dri2
) {
395 xcb_dri2_destroy_drawable (dri2_dpy
->conn
, dri2_surf
->drawable
);
397 assert(dri2_dpy
->swrast
);
398 swrastDestroyDrawable(dri2_dpy
, dri2_surf
);
401 if (surf
->Type
== EGL_PBUFFER_BIT
)
402 xcb_free_pixmap (dri2_dpy
->conn
, dri2_surf
->drawable
);
410 * Process list of buffer received from the server
412 * Processes the list of buffers received in a reply from the server to either
413 * \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat.
416 dri2_x11_process_buffers(struct dri2_egl_surface
*dri2_surf
,
417 xcb_dri2_dri2_buffer_t
*buffers
, unsigned count
)
419 struct dri2_egl_display
*dri2_dpy
=
420 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
421 xcb_rectangle_t rectangle
;
424 dri2_surf
->buffer_count
= count
;
425 dri2_surf
->have_fake_front
= 0;
427 /* This assumes the DRI2 buffer attachment tokens matches the
428 * __DRIbuffer tokens. */
429 for (i
= 0; i
< count
; i
++) {
430 dri2_surf
->buffers
[i
].attachment
= buffers
[i
].attachment
;
431 dri2_surf
->buffers
[i
].name
= buffers
[i
].name
;
432 dri2_surf
->buffers
[i
].pitch
= buffers
[i
].pitch
;
433 dri2_surf
->buffers
[i
].cpp
= buffers
[i
].cpp
;
434 dri2_surf
->buffers
[i
].flags
= buffers
[i
].flags
;
436 /* We only use the DRI drivers single buffer configs. This
437 * means that if we try to render to a window, DRI2 will give us
438 * the fake front buffer, which we'll use as a back buffer.
439 * Note that EGL doesn't require that several clients rendering
440 * to the same window must see the same aux buffers. */
441 if (dri2_surf
->buffers
[i
].attachment
== __DRI_BUFFER_FAKE_FRONT_LEFT
)
442 dri2_surf
->have_fake_front
= 1;
445 if (dri2_surf
->region
!= XCB_NONE
)
446 xcb_xfixes_destroy_region(dri2_dpy
->conn
, dri2_surf
->region
);
450 rectangle
.width
= dri2_surf
->base
.Width
;
451 rectangle
.height
= dri2_surf
->base
.Height
;
452 dri2_surf
->region
= xcb_generate_id(dri2_dpy
->conn
);
453 xcb_xfixes_create_region(dri2_dpy
->conn
, dri2_surf
->region
, 1, &rectangle
);
457 dri2_x11_get_buffers(__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_reply_t
*reply
;
467 xcb_dri2_get_buffers_cookie_t cookie
;
471 cookie
= xcb_dri2_get_buffers_unchecked (dri2_dpy
->conn
,
473 count
, count
, attachments
);
474 reply
= xcb_dri2_get_buffers_reply (dri2_dpy
->conn
, cookie
, NULL
);
477 buffers
= xcb_dri2_get_buffers_buffers (reply
);
481 *out_count
= reply
->count
;
482 dri2_surf
->base
.Width
= *width
= reply
->width
;
483 dri2_surf
->base
.Height
= *height
= reply
->height
;
484 dri2_x11_process_buffers(dri2_surf
, buffers
, *out_count
);
488 return dri2_surf
->buffers
;
492 dri2_x11_get_buffers_with_format(__DRIdrawable
* driDrawable
,
493 int *width
, int *height
,
494 unsigned int *attachments
, int count
,
495 int *out_count
, void *loaderPrivate
)
497 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
498 struct dri2_egl_display
*dri2_dpy
=
499 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
500 xcb_dri2_dri2_buffer_t
*buffers
;
501 xcb_dri2_get_buffers_with_format_reply_t
*reply
;
502 xcb_dri2_get_buffers_with_format_cookie_t cookie
;
503 xcb_dri2_attach_format_t
*format_attachments
;
507 format_attachments
= (xcb_dri2_attach_format_t
*) attachments
;
508 cookie
= xcb_dri2_get_buffers_with_format_unchecked (dri2_dpy
->conn
,
513 reply
= xcb_dri2_get_buffers_with_format_reply (dri2_dpy
->conn
,
518 buffers
= xcb_dri2_get_buffers_with_format_buffers (reply
);
519 dri2_surf
->base
.Width
= *width
= reply
->width
;
520 dri2_surf
->base
.Height
= *height
= reply
->height
;
521 *out_count
= reply
->count
;
522 dri2_x11_process_buffers(dri2_surf
, buffers
, *out_count
);
526 return dri2_surf
->buffers
;
530 dri2_x11_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
534 /* FIXME: Does EGL support front buffer rendering at all? */
537 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
539 dri2WaitGL(dri2_surf
);
541 (void) loaderPrivate
;
546 dri2_x11_authenticate(struct dri2_egl_display
*dri2_dpy
, uint32_t id
)
548 xcb_dri2_authenticate_reply_t
*authenticate
;
549 xcb_dri2_authenticate_cookie_t authenticate_cookie
;
550 xcb_screen_iterator_t s
;
551 xcb_screen_t
*screen
;
554 s
= xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy
->conn
));
556 screen
= get_xcb_screen(s
, dri2_dpy
->screen
);
558 _eglLog(_EGL_WARNING
, "DRI2: failed to get xcb screen");
562 authenticate_cookie
=
563 xcb_dri2_authenticate_unchecked(dri2_dpy
->conn
, screen
->root
, id
);
565 xcb_dri2_authenticate_reply(dri2_dpy
->conn
, authenticate_cookie
, NULL
);
567 if (authenticate
== NULL
|| !authenticate
->authenticated
)
576 dri2_x11_local_authenticate(struct dri2_egl_display
*dri2_dpy
)
581 if (drmGetMagic(dri2_dpy
->fd
, &magic
)) {
582 _eglLog(_EGL_WARNING
, "DRI2: failed to get drm magic");
586 if (dri2_x11_authenticate(dri2_dpy
, magic
) < 0) {
587 _eglLog(_EGL_WARNING
, "DRI2: failed to authenticate");
595 dri2_x11_connect(struct dri2_egl_display
*dri2_dpy
)
597 xcb_xfixes_query_version_reply_t
*xfixes_query
;
598 xcb_xfixes_query_version_cookie_t xfixes_query_cookie
;
599 xcb_dri2_query_version_reply_t
*dri2_query
;
600 xcb_dri2_query_version_cookie_t dri2_query_cookie
;
601 xcb_dri2_connect_reply_t
*connect
;
602 xcb_dri2_connect_cookie_t connect_cookie
;
603 xcb_generic_error_t
*error
;
604 xcb_screen_iterator_t s
;
605 xcb_screen_t
*screen
;
606 char *driver_name
, *loader_driver_name
, *device_name
;
607 const xcb_query_extension_reply_t
*extension
;
609 xcb_prefetch_extension_data (dri2_dpy
->conn
, &xcb_xfixes_id
);
610 xcb_prefetch_extension_data (dri2_dpy
->conn
, &xcb_dri2_id
);
612 extension
= xcb_get_extension_data(dri2_dpy
->conn
, &xcb_xfixes_id
);
613 if (!(extension
&& extension
->present
))
616 extension
= xcb_get_extension_data(dri2_dpy
->conn
, &xcb_dri2_id
);
617 if (!(extension
&& extension
->present
))
620 xfixes_query_cookie
= xcb_xfixes_query_version(dri2_dpy
->conn
,
621 XCB_XFIXES_MAJOR_VERSION
,
622 XCB_XFIXES_MINOR_VERSION
);
624 dri2_query_cookie
= xcb_dri2_query_version (dri2_dpy
->conn
,
625 XCB_DRI2_MAJOR_VERSION
,
626 XCB_DRI2_MINOR_VERSION
);
628 s
= xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy
->conn
));
629 screen
= get_xcb_screen(s
, dri2_dpy
->screen
);
631 _eglLog(_EGL_WARNING
, "DRI2: failed to get xcb screen");
634 connect_cookie
= xcb_dri2_connect_unchecked(dri2_dpy
->conn
, screen
->root
,
635 XCB_DRI2_DRIVER_TYPE_DRI
);
638 xcb_xfixes_query_version_reply (dri2_dpy
->conn
,
639 xfixes_query_cookie
, &error
);
640 if (xfixes_query
== NULL
||
641 error
!= NULL
|| xfixes_query
->major_version
< 2) {
642 _eglLog(_EGL_WARNING
, "DRI2: failed to query xfixes version");
649 xcb_dri2_query_version_reply (dri2_dpy
->conn
, dri2_query_cookie
, &error
);
650 if (dri2_query
== NULL
|| error
!= NULL
) {
651 _eglLog(_EGL_WARNING
, "DRI2: failed to query version");
655 dri2_dpy
->dri2_major
= dri2_query
->major_version
;
656 dri2_dpy
->dri2_minor
= dri2_query
->minor_version
;
659 connect
= xcb_dri2_connect_reply (dri2_dpy
->conn
, connect_cookie
, NULL
);
660 if (connect
== NULL
||
661 connect
->driver_name_length
+ connect
->device_name_length
== 0) {
662 _eglLog(_EGL_WARNING
, "DRI2: failed to authenticate");
666 device_name
= xcb_dri2_connect_device_name (connect
);
668 dri2_dpy
->device_name
=
670 xcb_dri2_connect_device_name_length(connect
));
672 dri2_dpy
->fd
= loader_open_device(dri2_dpy
->device_name
);
673 if (dri2_dpy
->fd
== -1) {
674 _eglLog(_EGL_WARNING
,
675 "DRI2: could not open %s (%s)", dri2_dpy
->device_name
,
677 free(dri2_dpy
->device_name
);
682 if (!dri2_x11_local_authenticate(dri2_dpy
)) {
684 free(dri2_dpy
->device_name
);
689 driver_name
= xcb_dri2_connect_driver_name (connect
);
691 /* If Mesa knows about the appropriate driver for this fd, then trust it.
692 * Otherwise, default to the server's value.
694 loader_driver_name
= loader_get_driver_for_fd(dri2_dpy
->fd
, 0);
695 if (loader_driver_name
) {
696 dri2_dpy
->driver_name
= loader_driver_name
;
698 dri2_dpy
->driver_name
=
700 xcb_dri2_connect_driver_name_length(connect
));
703 if (dri2_dpy
->device_name
== NULL
|| dri2_dpy
->driver_name
== NULL
) {
705 free(dri2_dpy
->device_name
);
706 free(dri2_dpy
->driver_name
);
716 dri2_x11_add_configs_for_visuals(struct dri2_egl_display
*dri2_dpy
,
717 _EGLDisplay
*disp
, bool supports_preserved
)
719 xcb_screen_iterator_t s
;
720 xcb_depth_iterator_t d
;
721 xcb_visualtype_t
*visuals
;
723 unsigned int rgba_masks
[4];
725 EGLint config_attrs
[] = {
726 EGL_NATIVE_VISUAL_ID
, 0,
727 EGL_NATIVE_VISUAL_TYPE
, 0,
731 s
= xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy
->conn
));
732 d
= xcb_screen_allowed_depths_iterator(get_xcb_screen(s
, dri2_dpy
->screen
));
740 if (supports_preserved
)
741 surface_type
|= EGL_SWAP_BEHAVIOR_PRESERVED_BIT
;
744 EGLBoolean class_added
[6] = { 0, };
746 visuals
= xcb_depth_visuals(d
.data
);
747 for (i
= 0; i
< xcb_depth_visuals_length(d
.data
); i
++) {
748 if (class_added
[visuals
[i
]._class
])
751 class_added
[visuals
[i
]._class
] = EGL_TRUE
;
752 for (j
= 0; dri2_dpy
->driver_configs
[j
]; j
++) {
753 config_attrs
[1] = visuals
[i
].visual_id
;
754 config_attrs
[3] = visuals
[i
]._class
;
756 rgba_masks
[0] = visuals
[i
].red_mask
;
757 rgba_masks
[1] = visuals
[i
].green_mask
;
758 rgba_masks
[2] = visuals
[i
].blue_mask
;
760 dri2_add_config(disp
, dri2_dpy
->driver_configs
[j
], id
++,
761 surface_type
, config_attrs
, rgba_masks
);
763 /* Allow a 24-bit RGB visual to match a 32-bit RGBA EGLConfig.
764 * Otherwise it will only match a 32-bit RGBA visual. On a
765 * composited window manager on X11, this will make all of the
766 * EGLConfigs with destination alpha get blended by the
767 * compositor. This is probably not what the application
768 * wants... especially on drivers that only have 32-bit RGBA
770 if (d
.data
->depth
== 24) {
772 ~(rgba_masks
[0] | rgba_masks
[1] | rgba_masks
[2]);
773 dri2_add_config(disp
, dri2_dpy
->driver_configs
[j
], id
++,
774 surface_type
, config_attrs
, rgba_masks
);
782 if (!_eglGetArraySize(disp
->Configs
)) {
783 _eglLog(_EGL_WARNING
, "DRI2: failed to create any config");
791 dri2_copy_region(_EGLDriver
*drv
, _EGLDisplay
*disp
,
792 _EGLSurface
*draw
, xcb_xfixes_region_t region
)
794 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
795 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
796 enum xcb_dri2_attachment_t render_attachment
;
797 xcb_dri2_copy_region_cookie_t cookie
;
799 /* No-op for a pixmap or pbuffer surface */
800 if (draw
->Type
== EGL_PIXMAP_BIT
|| draw
->Type
== EGL_PBUFFER_BIT
)
804 (*dri2_dpy
->flush
->flush
)(dri2_surf
->dri_drawable
);
806 if (dri2_surf
->have_fake_front
)
807 render_attachment
= XCB_DRI2_ATTACHMENT_BUFFER_FAKE_FRONT_LEFT
;
809 render_attachment
= XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT
;
811 cookie
= xcb_dri2_copy_region_unchecked(dri2_dpy
->conn
,
814 XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT
,
816 free(xcb_dri2_copy_region_reply(dri2_dpy
->conn
, cookie
, NULL
));
822 dri2_x11_swap_buffers_msc(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
,
823 int64_t msc
, int64_t divisor
, int64_t remainder
)
825 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
826 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
827 uint32_t msc_hi
= msc
>> 32;
828 uint32_t msc_lo
= msc
& 0xffffffff;
829 uint32_t divisor_hi
= divisor
>> 32;
830 uint32_t divisor_lo
= divisor
& 0xffffffff;
831 uint32_t remainder_hi
= remainder
>> 32;
832 uint32_t remainder_lo
= remainder
& 0xffffffff;
833 xcb_dri2_swap_buffers_cookie_t cookie
;
834 xcb_dri2_swap_buffers_reply_t
*reply
;
835 int64_t swap_count
= -1;
837 /* No-op for a pixmap or pbuffer surface */
838 if (draw
->Type
== EGL_PIXMAP_BIT
|| draw
->Type
== EGL_PBUFFER_BIT
)
841 if (draw
->SwapBehavior
== EGL_BUFFER_PRESERVED
|| !dri2_dpy
->swap_available
)
842 return dri2_copy_region(drv
, disp
, draw
, dri2_surf
->region
) ? 0 : -1;
844 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
846 cookie
= xcb_dri2_swap_buffers_unchecked(dri2_dpy
->conn
, dri2_surf
->drawable
,
847 msc_hi
, msc_lo
, divisor_hi
, divisor_lo
, remainder_hi
, remainder_lo
);
849 reply
= xcb_dri2_swap_buffers_reply(dri2_dpy
->conn
, cookie
, NULL
);
852 swap_count
= (((int64_t)reply
->swap_hi
) << 32) | reply
->swap_lo
;
856 /* Since we aren't watching for the server's invalidate events like we're
857 * supposed to (due to XCB providing no mechanism for filtering the events
858 * the way xlib does), and SwapBuffers is a common cause of invalidate
859 * events, just shove one down to the driver, even though we haven't told
860 * the driver that we're the kind of loader that provides reliable
861 * invalidate events. This causes the driver to request buffers again at
862 * its next draw, so that we get the correct buffers if a pageflip
863 * happened. The driver should still be using the viewport hack to catch
866 if (dri2_dpy
->flush
&&
867 dri2_dpy
->flush
->base
.version
>= 3 && dri2_dpy
->flush
->invalidate
)
868 (*dri2_dpy
->flush
->invalidate
)(dri2_surf
->dri_drawable
);
874 dri2_x11_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
876 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
877 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
879 if (dri2_dpy
->dri2
) {
880 if (dri2_x11_swap_buffers_msc(drv
, disp
, draw
, 0, 0, 0) != -1) {
883 /* Swap failed with a window drawable. */
884 _eglError(EGL_BAD_NATIVE_WINDOW
, __FUNCTION__
);
887 assert(dri2_dpy
->swrast
);
889 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
895 dri2_x11_swap_buffers_region(_EGLDriver
*drv
, _EGLDisplay
*disp
,
897 EGLint numRects
, const EGLint
*rects
)
899 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
900 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
902 xcb_xfixes_region_t region
;
903 xcb_rectangle_t rectangles
[16];
906 if (numRects
> (int)ARRAY_SIZE(rectangles
))
907 return dri2_copy_region(drv
, disp
, draw
, dri2_surf
->region
);
909 for (i
= 0; i
< numRects
; i
++) {
910 rectangles
[i
].x
= rects
[i
* 4];
911 rectangles
[i
].y
= dri2_surf
->base
.Height
- rects
[i
* 4 + 1] - rects
[i
* 4 + 3];
912 rectangles
[i
].width
= rects
[i
* 4 + 2];
913 rectangles
[i
].height
= rects
[i
* 4 + 3];
916 region
= xcb_generate_id(dri2_dpy
->conn
);
917 xcb_xfixes_create_region(dri2_dpy
->conn
, region
, numRects
, rectangles
);
918 ret
= dri2_copy_region(drv
, disp
, draw
, region
);
919 xcb_xfixes_destroy_region(dri2_dpy
->conn
, region
);
925 dri2_x11_post_sub_buffer(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
,
926 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
928 const EGLint rect
[4] = { x
, y
, width
, height
};
930 if (x
< 0 || y
< 0 || width
< 0 || height
< 0)
931 _eglError(EGL_BAD_PARAMETER
, "eglPostSubBufferNV");
933 return dri2_x11_swap_buffers_region(drv
, disp
, draw
, 1, rect
);
937 dri2_x11_swap_interval(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
,
940 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
941 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
943 if (interval
> surf
->Config
->MaxSwapInterval
)
944 interval
= surf
->Config
->MaxSwapInterval
;
945 else if (interval
< surf
->Config
->MinSwapInterval
)
946 interval
= surf
->Config
->MinSwapInterval
;
948 if (interval
!= surf
->SwapInterval
&& dri2_dpy
->swap_available
)
949 xcb_dri2_swap_interval(dri2_dpy
->conn
, dri2_surf
->drawable
, interval
);
951 surf
->SwapInterval
= interval
;
957 dri2_x11_copy_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
,
958 void *native_pixmap_target
)
960 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
961 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
965 STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_pixmap_target
));
966 target
= (uintptr_t) native_pixmap_target
;
970 (*dri2_dpy
->flush
->flush
)(dri2_surf
->dri_drawable
);
972 gc
= xcb_generate_id(dri2_dpy
->conn
);
973 xcb_create_gc(dri2_dpy
->conn
, gc
, target
, 0, NULL
);
974 xcb_copy_area(dri2_dpy
->conn
,
980 dri2_surf
->base
.Width
,
981 dri2_surf
->base
.Height
);
982 xcb_free_gc(dri2_dpy
->conn
, gc
);
988 dri2_create_image_khr_pixmap(_EGLDisplay
*disp
, _EGLContext
*ctx
,
989 EGLClientBuffer buffer
, const EGLint
*attr_list
)
991 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
992 struct dri2_egl_image
*dri2_img
;
993 unsigned int attachments
[1];
994 xcb_drawable_t drawable
;
995 xcb_dri2_get_buffers_cookie_t buffers_cookie
;
996 xcb_dri2_get_buffers_reply_t
*buffers_reply
;
997 xcb_dri2_dri2_buffer_t
*buffers
;
998 xcb_get_geometry_cookie_t geometry_cookie
;
999 xcb_get_geometry_reply_t
*geometry_reply
;
1000 xcb_generic_error_t
*error
;
1005 drawable
= (xcb_drawable_t
) (uintptr_t) buffer
;
1006 xcb_dri2_create_drawable (dri2_dpy
->conn
, drawable
);
1007 attachments
[0] = XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT
;
1009 xcb_dri2_get_buffers_unchecked (dri2_dpy
->conn
,
1010 drawable
, 1, 1, attachments
);
1011 geometry_cookie
= xcb_get_geometry (dri2_dpy
->conn
, drawable
);
1012 buffers_reply
= xcb_dri2_get_buffers_reply (dri2_dpy
->conn
,
1013 buffers_cookie
, NULL
);
1014 if (buffers_reply
== NULL
)
1017 buffers
= xcb_dri2_get_buffers_buffers (buffers_reply
);
1018 if (buffers
== NULL
) {
1022 geometry_reply
= xcb_get_geometry_reply (dri2_dpy
->conn
,
1023 geometry_cookie
, &error
);
1024 if (geometry_reply
== NULL
|| error
!= NULL
) {
1025 _eglError(EGL_BAD_ALLOC
, "xcb_get_geometry");
1027 free(buffers_reply
);
1031 switch (geometry_reply
->depth
) {
1033 format
= __DRI_IMAGE_FORMAT_RGB565
;
1036 format
= __DRI_IMAGE_FORMAT_XRGB8888
;
1039 format
= __DRI_IMAGE_FORMAT_ARGB8888
;
1042 _eglError(EGL_BAD_PARAMETER
,
1043 "dri2_create_image_khr: unsupported pixmap depth");
1044 free(buffers_reply
);
1045 free(geometry_reply
);
1049 dri2_img
= malloc(sizeof *dri2_img
);
1051 free(buffers_reply
);
1052 free(geometry_reply
);
1053 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
1054 return EGL_NO_IMAGE_KHR
;
1057 if (!_eglInitImage(&dri2_img
->base
, disp
)) {
1058 free(buffers_reply
);
1059 free(geometry_reply
);
1061 return EGL_NO_IMAGE_KHR
;
1064 stride
= buffers
[0].pitch
/ buffers
[0].cpp
;
1065 dri2_img
->dri_image
=
1066 dri2_dpy
->image
->createImageFromName(dri2_dpy
->dri_screen
,
1067 buffers_reply
->width
,
1068 buffers_reply
->height
,
1074 free(buffers_reply
);
1075 free(geometry_reply
);
1077 return &dri2_img
->base
;
1081 dri2_x11_create_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
,
1082 _EGLContext
*ctx
, EGLenum target
,
1083 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1088 case EGL_NATIVE_PIXMAP_KHR
:
1089 return dri2_create_image_khr_pixmap(disp
, ctx
, buffer
, attr_list
);
1091 return dri2_create_image_khr(drv
, disp
, ctx
, target
, buffer
, attr_list
);
1096 dri2_x11_get_sync_values(_EGLDisplay
*display
, _EGLSurface
*surface
,
1097 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
1100 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(display
);
1101 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
1102 xcb_dri2_get_msc_cookie_t cookie
;
1103 xcb_dri2_get_msc_reply_t
*reply
;
1105 cookie
= xcb_dri2_get_msc(dri2_dpy
->conn
, dri2_surf
->drawable
);
1106 reply
= xcb_dri2_get_msc_reply(dri2_dpy
->conn
, cookie
, NULL
);
1109 _eglError(EGL_BAD_ACCESS
, __func__
);
1113 *ust
= ((EGLuint64KHR
) reply
->ust_hi
<< 32) | reply
->ust_lo
;
1114 *msc
= ((EGLuint64KHR
) reply
->msc_hi
<< 32) | reply
->msc_lo
;
1115 *sbc
= ((EGLuint64KHR
) reply
->sbc_hi
<< 32) | reply
->sbc_lo
;
1121 static struct dri2_egl_display_vtbl dri2_x11_swrast_display_vtbl
= {
1122 .authenticate
= NULL
,
1123 .create_window_surface
= dri2_x11_create_window_surface
,
1124 .create_pixmap_surface
= dri2_x11_create_pixmap_surface
,
1125 .create_pbuffer_surface
= dri2_x11_create_pbuffer_surface
,
1126 .destroy_surface
= dri2_x11_destroy_surface
,
1127 .create_image
= dri2_fallback_create_image_khr
,
1128 .swap_interval
= dri2_fallback_swap_interval
,
1129 .swap_buffers
= dri2_x11_swap_buffers
,
1130 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1131 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1132 .copy_buffers
= dri2_x11_copy_buffers
,
1133 .query_buffer_age
= dri2_fallback_query_buffer_age
,
1134 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
1135 .get_sync_values
= dri2_fallback_get_sync_values
,
1136 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1139 static struct dri2_egl_display_vtbl dri2_x11_display_vtbl
= {
1140 .authenticate
= dri2_x11_authenticate
,
1141 .create_window_surface
= dri2_x11_create_window_surface
,
1142 .create_pixmap_surface
= dri2_x11_create_pixmap_surface
,
1143 .create_pbuffer_surface
= dri2_x11_create_pbuffer_surface
,
1144 .destroy_surface
= dri2_x11_destroy_surface
,
1145 .create_image
= dri2_x11_create_image_khr
,
1146 .swap_interval
= dri2_x11_swap_interval
,
1147 .swap_buffers
= dri2_x11_swap_buffers
,
1148 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
1149 .swap_buffers_region
= dri2_x11_swap_buffers_region
,
1150 .post_sub_buffer
= dri2_x11_post_sub_buffer
,
1151 .copy_buffers
= dri2_x11_copy_buffers
,
1152 .query_buffer_age
= dri2_fallback_query_buffer_age
,
1153 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
1154 .get_sync_values
= dri2_x11_get_sync_values
,
1155 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1159 dri2_initialize_x11_swrast(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1161 struct dri2_egl_display
*dri2_dpy
;
1163 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1165 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1167 disp
->DriverData
= (void *) dri2_dpy
;
1168 if (disp
->PlatformDisplay
== NULL
) {
1169 dri2_dpy
->conn
= xcb_connect(0, &dri2_dpy
->screen
);
1170 dri2_dpy
->own_device
= true;
1172 Display
*dpy
= disp
->PlatformDisplay
;
1174 dri2_dpy
->conn
= XGetXCBConnection(dpy
);
1175 dri2_dpy
->screen
= DefaultScreen(dpy
);
1178 if (!dri2_dpy
->conn
|| xcb_connection_has_error(dri2_dpy
->conn
)) {
1179 _eglLog(_EGL_WARNING
, "DRI2: xcb_connect failed");
1184 * Every hardware driver_name is set using strdup. Doing the same in
1185 * here will allow is to simply free the memory at dri2_terminate().
1188 dri2_dpy
->driver_name
= strdup("swrast");
1189 if (!dri2_load_driver_swrast(disp
))
1192 dri2_dpy
->swrast_loader_extension
.base
.name
= __DRI_SWRAST_LOADER
;
1193 dri2_dpy
->swrast_loader_extension
.base
.version
= 2;
1194 dri2_dpy
->swrast_loader_extension
.getDrawableInfo
= swrastGetDrawableInfo
;
1195 dri2_dpy
->swrast_loader_extension
.putImage
= swrastPutImage
;
1196 dri2_dpy
->swrast_loader_extension
.getImage
= swrastGetImage
;
1198 dri2_dpy
->extensions
[0] = &dri2_dpy
->swrast_loader_extension
.base
;
1199 dri2_dpy
->extensions
[1] = NULL
;
1200 dri2_dpy
->extensions
[2] = NULL
;
1202 if (!dri2_create_screen(disp
))
1203 goto cleanup_driver
;
1205 if (!dri2_x11_add_configs_for_visuals(dri2_dpy
, disp
, true))
1206 goto cleanup_configs
;
1208 /* Fill vtbl last to prevent accidentally calling virtual function during
1211 dri2_dpy
->vtbl
= &dri2_x11_swrast_display_vtbl
;
1216 _eglCleanupDisplay(disp
);
1217 dri2_dpy
->core
->destroyScreen(dri2_dpy
->dri_screen
);
1219 dlclose(dri2_dpy
->driver
);
1221 free(dri2_dpy
->driver_name
);
1222 if (disp
->PlatformDisplay
== NULL
)
1223 xcb_disconnect(dri2_dpy
->conn
);
1231 dri2_x11_setup_swap_interval(struct dri2_egl_display
*dri2_dpy
)
1233 GLint vblank_mode
= DRI_CONF_VBLANK_DEF_INTERVAL_1
;
1234 int arbitrary_max_interval
= 1000;
1236 /* default behavior for no SwapBuffers support: no vblank syncing
1239 dri2_dpy
->min_swap_interval
= 0;
1240 dri2_dpy
->max_swap_interval
= 0;
1242 if (!dri2_dpy
->swap_available
)
1245 /* If we do have swapbuffers, then we can support pretty much any swap
1246 * interval, but we allow driconf to override applications.
1248 if (dri2_dpy
->config
)
1249 dri2_dpy
->config
->configQueryi(dri2_dpy
->dri_screen
,
1250 "vblank_mode", &vblank_mode
);
1251 switch (vblank_mode
) {
1252 case DRI_CONF_VBLANK_NEVER
:
1253 dri2_dpy
->min_swap_interval
= 0;
1254 dri2_dpy
->max_swap_interval
= 0;
1255 dri2_dpy
->default_swap_interval
= 0;
1257 case DRI_CONF_VBLANK_ALWAYS_SYNC
:
1258 dri2_dpy
->min_swap_interval
= 1;
1259 dri2_dpy
->max_swap_interval
= arbitrary_max_interval
;
1260 dri2_dpy
->default_swap_interval
= 1;
1262 case DRI_CONF_VBLANK_DEF_INTERVAL_0
:
1263 dri2_dpy
->min_swap_interval
= 0;
1264 dri2_dpy
->max_swap_interval
= arbitrary_max_interval
;
1265 dri2_dpy
->default_swap_interval
= 0;
1268 case DRI_CONF_VBLANK_DEF_INTERVAL_1
:
1269 dri2_dpy
->min_swap_interval
= 0;
1270 dri2_dpy
->max_swap_interval
= arbitrary_max_interval
;
1271 dri2_dpy
->default_swap_interval
= 1;
1278 dri2_initialize_x11_dri3(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1280 struct dri2_egl_display
*dri2_dpy
;
1282 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1284 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1286 disp
->DriverData
= (void *) dri2_dpy
;
1287 if (disp
->PlatformDisplay
== NULL
) {
1288 dri2_dpy
->conn
= xcb_connect(0, &dri2_dpy
->screen
);
1289 dri2_dpy
->own_device
= true;
1291 Display
*dpy
= disp
->PlatformDisplay
;
1293 dri2_dpy
->conn
= XGetXCBConnection(dpy
);
1294 dri2_dpy
->screen
= DefaultScreen(dpy
);
1297 if (xcb_connection_has_error(dri2_dpy
->conn
)) {
1298 _eglLog(_EGL_WARNING
, "DRI3: xcb_connect failed");
1302 if (dri2_dpy
->conn
) {
1303 if (!dri3_x11_connect(dri2_dpy
))
1307 if (!dri2_load_driver_dri3(disp
))
1310 dri2_dpy
->extensions
[0] = &dri3_image_loader_extension
.base
;
1311 dri2_dpy
->extensions
[1] = &use_invalidate
.base
;
1312 dri2_dpy
->extensions
[2] = &image_lookup_extension
.base
;
1313 dri2_dpy
->extensions
[3] = NULL
;
1315 dri2_dpy
->swap_available
= true;
1316 dri2_dpy
->invalidate_available
= true;
1318 if (!dri2_create_screen(disp
))
1321 dri2_x11_setup_swap_interval(dri2_dpy
);
1323 if (!dri2_dpy
->is_different_gpu
)
1324 disp
->Extensions
.KHR_image_pixmap
= EGL_TRUE
;
1325 disp
->Extensions
.NOK_texture_from_pixmap
= EGL_TRUE
;
1326 disp
->Extensions
.CHROMIUM_sync_control
= EGL_TRUE
;
1327 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
1329 #ifdef HAVE_WAYLAND_PLATFORM
1330 disp
->Extensions
.WL_bind_wayland_display
= EGL_TRUE
;
1333 if (dri2_dpy
->conn
) {
1334 if (!dri2_x11_add_configs_for_visuals(dri2_dpy
, disp
, false))
1335 goto cleanup_configs
;
1338 dri2_dpy
->loader_dri3_ext
.core
= dri2_dpy
->core
;
1339 dri2_dpy
->loader_dri3_ext
.image_driver
= dri2_dpy
->image_driver
;
1340 dri2_dpy
->loader_dri3_ext
.flush
= dri2_dpy
->flush
;
1341 dri2_dpy
->loader_dri3_ext
.tex_buffer
= dri2_dpy
->tex_buffer
;
1342 dri2_dpy
->loader_dri3_ext
.image
= dri2_dpy
->image
;
1343 dri2_dpy
->loader_dri3_ext
.config
= dri2_dpy
->config
;
1345 /* Fill vtbl last to prevent accidentally calling virtual function during
1348 dri2_dpy
->vtbl
= &dri3_x11_display_vtbl
;
1350 _eglLog(_EGL_INFO
, "Using DRI3");
1355 _eglCleanupDisplay(disp
);
1356 dri2_dpy
->core
->destroyScreen(dri2_dpy
->dri_screen
);
1357 dlclose(dri2_dpy
->driver
);
1359 close(dri2_dpy
->fd
);
1361 if (disp
->PlatformDisplay
== NULL
)
1362 xcb_disconnect(dri2_dpy
->conn
);
1371 dri2_initialize_x11_dri2(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1373 struct dri2_egl_display
*dri2_dpy
;
1375 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1377 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1379 disp
->DriverData
= (void *) dri2_dpy
;
1380 if (disp
->PlatformDisplay
== NULL
) {
1381 dri2_dpy
->conn
= xcb_connect(0, &dri2_dpy
->screen
);
1382 dri2_dpy
->own_device
= true;
1384 Display
*dpy
= disp
->PlatformDisplay
;
1386 dri2_dpy
->conn
= XGetXCBConnection(dpy
);
1387 dri2_dpy
->screen
= DefaultScreen(dpy
);
1390 if (!dri2_dpy
->conn
|| xcb_connection_has_error(dri2_dpy
->conn
)) {
1391 _eglLog(_EGL_WARNING
, "DRI2: xcb_connect failed");
1395 if (!dri2_x11_connect(dri2_dpy
))
1398 if (!dri2_load_driver(disp
))
1401 if (dri2_dpy
->dri2_minor
>= 1) {
1402 dri2_dpy
->dri2_loader_extension
.base
.name
= __DRI_DRI2_LOADER
;
1403 dri2_dpy
->dri2_loader_extension
.base
.version
= 3;
1404 dri2_dpy
->dri2_loader_extension
.getBuffers
= dri2_x11_get_buffers
;
1405 dri2_dpy
->dri2_loader_extension
.flushFrontBuffer
= dri2_x11_flush_front_buffer
;
1406 dri2_dpy
->dri2_loader_extension
.getBuffersWithFormat
=
1407 dri2_x11_get_buffers_with_format
;
1409 dri2_dpy
->dri2_loader_extension
.base
.name
= __DRI_DRI2_LOADER
;
1410 dri2_dpy
->dri2_loader_extension
.base
.version
= 2;
1411 dri2_dpy
->dri2_loader_extension
.getBuffers
= dri2_x11_get_buffers
;
1412 dri2_dpy
->dri2_loader_extension
.flushFrontBuffer
= dri2_x11_flush_front_buffer
;
1413 dri2_dpy
->dri2_loader_extension
.getBuffersWithFormat
= NULL
;
1416 dri2_dpy
->extensions
[0] = &dri2_dpy
->dri2_loader_extension
.base
;
1417 dri2_dpy
->extensions
[1] = &image_lookup_extension
.base
;
1418 dri2_dpy
->extensions
[2] = NULL
;
1420 dri2_dpy
->swap_available
= (dri2_dpy
->dri2_minor
>= 2);
1421 dri2_dpy
->invalidate_available
= (dri2_dpy
->dri2_minor
>= 3);
1423 if (!dri2_create_screen(disp
))
1424 goto cleanup_driver
;
1426 dri2_x11_setup_swap_interval(dri2_dpy
);
1428 disp
->Extensions
.KHR_image_pixmap
= EGL_TRUE
;
1429 disp
->Extensions
.NOK_swap_region
= EGL_TRUE
;
1430 disp
->Extensions
.NOK_texture_from_pixmap
= EGL_TRUE
;
1431 disp
->Extensions
.NV_post_sub_buffer
= EGL_TRUE
;
1432 disp
->Extensions
.CHROMIUM_sync_control
= EGL_TRUE
;
1434 #ifdef HAVE_WAYLAND_PLATFORM
1435 disp
->Extensions
.WL_bind_wayland_display
= EGL_TRUE
;
1438 if (!dri2_x11_add_configs_for_visuals(dri2_dpy
, disp
, true))
1439 goto cleanup_configs
;
1441 /* Fill vtbl last to prevent accidentally calling virtual function during
1444 dri2_dpy
->vtbl
= &dri2_x11_display_vtbl
;
1446 _eglLog(_EGL_INFO
, "Using DRI2");
1451 _eglCleanupDisplay(disp
);
1452 dri2_dpy
->core
->destroyScreen(dri2_dpy
->dri_screen
);
1454 dlclose(dri2_dpy
->driver
);
1456 close(dri2_dpy
->fd
);
1458 if (disp
->PlatformDisplay
== NULL
)
1459 xcb_disconnect(dri2_dpy
->conn
);
1467 dri2_initialize_x11(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1469 EGLBoolean initialized
= EGL_TRUE
;
1471 int x11_dri2_accel
= (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL
);
1473 if (x11_dri2_accel
) {
1475 if (getenv("LIBGL_DRI3_DISABLE") != NULL
||
1476 !dri2_initialize_x11_dri3(drv
, disp
)) {
1478 if (!dri2_initialize_x11_dri2(drv
, disp
)) {
1479 initialized
= dri2_initialize_x11_swrast(drv
, disp
);
1485 initialized
= dri2_initialize_x11_swrast(drv
, disp
);