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 (*dri2_dpy
->core
->destroyDrawable
)(dri2_surf
->dri_drawable
);
391 if (dri2_dpy
->dri2
) {
392 xcb_dri2_destroy_drawable (dri2_dpy
->conn
, dri2_surf
->drawable
);
394 assert(dri2_dpy
->swrast
);
395 swrastDestroyDrawable(dri2_dpy
, dri2_surf
);
398 if (surf
->Type
== EGL_PBUFFER_BIT
)
399 xcb_free_pixmap (dri2_dpy
->conn
, dri2_surf
->drawable
);
407 * Process list of buffer received from the server
409 * Processes the list of buffers received in a reply from the server to either
410 * \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat.
413 dri2_x11_process_buffers(struct dri2_egl_surface
*dri2_surf
,
414 xcb_dri2_dri2_buffer_t
*buffers
, unsigned count
)
416 struct dri2_egl_display
*dri2_dpy
=
417 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
418 xcb_rectangle_t rectangle
;
421 dri2_surf
->buffer_count
= count
;
422 dri2_surf
->have_fake_front
= 0;
424 /* This assumes the DRI2 buffer attachment tokens matches the
425 * __DRIbuffer tokens. */
426 for (i
= 0; i
< count
; i
++) {
427 dri2_surf
->buffers
[i
].attachment
= buffers
[i
].attachment
;
428 dri2_surf
->buffers
[i
].name
= buffers
[i
].name
;
429 dri2_surf
->buffers
[i
].pitch
= buffers
[i
].pitch
;
430 dri2_surf
->buffers
[i
].cpp
= buffers
[i
].cpp
;
431 dri2_surf
->buffers
[i
].flags
= buffers
[i
].flags
;
433 /* We only use the DRI drivers single buffer configs. This
434 * means that if we try to render to a window, DRI2 will give us
435 * the fake front buffer, which we'll use as a back buffer.
436 * Note that EGL doesn't require that several clients rendering
437 * to the same window must see the same aux buffers. */
438 if (dri2_surf
->buffers
[i
].attachment
== __DRI_BUFFER_FAKE_FRONT_LEFT
)
439 dri2_surf
->have_fake_front
= 1;
442 if (dri2_surf
->region
!= XCB_NONE
)
443 xcb_xfixes_destroy_region(dri2_dpy
->conn
, dri2_surf
->region
);
447 rectangle
.width
= dri2_surf
->base
.Width
;
448 rectangle
.height
= dri2_surf
->base
.Height
;
449 dri2_surf
->region
= xcb_generate_id(dri2_dpy
->conn
);
450 xcb_xfixes_create_region(dri2_dpy
->conn
, dri2_surf
->region
, 1, &rectangle
);
454 dri2_x11_get_buffers(__DRIdrawable
* driDrawable
,
455 int *width
, int *height
,
456 unsigned int *attachments
, int count
,
457 int *out_count
, void *loaderPrivate
)
459 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
460 struct dri2_egl_display
*dri2_dpy
=
461 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
462 xcb_dri2_dri2_buffer_t
*buffers
;
463 xcb_dri2_get_buffers_reply_t
*reply
;
464 xcb_dri2_get_buffers_cookie_t cookie
;
468 cookie
= xcb_dri2_get_buffers_unchecked (dri2_dpy
->conn
,
470 count
, count
, attachments
);
471 reply
= xcb_dri2_get_buffers_reply (dri2_dpy
->conn
, cookie
, NULL
);
474 buffers
= xcb_dri2_get_buffers_buffers (reply
);
478 *out_count
= reply
->count
;
479 dri2_surf
->base
.Width
= *width
= reply
->width
;
480 dri2_surf
->base
.Height
= *height
= reply
->height
;
481 dri2_x11_process_buffers(dri2_surf
, buffers
, *out_count
);
485 return dri2_surf
->buffers
;
489 dri2_x11_get_buffers_with_format(__DRIdrawable
* driDrawable
,
490 int *width
, int *height
,
491 unsigned int *attachments
, int count
,
492 int *out_count
, void *loaderPrivate
)
494 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
495 struct dri2_egl_display
*dri2_dpy
=
496 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
497 xcb_dri2_dri2_buffer_t
*buffers
;
498 xcb_dri2_get_buffers_with_format_reply_t
*reply
;
499 xcb_dri2_get_buffers_with_format_cookie_t cookie
;
500 xcb_dri2_attach_format_t
*format_attachments
;
504 format_attachments
= (xcb_dri2_attach_format_t
*) attachments
;
505 cookie
= xcb_dri2_get_buffers_with_format_unchecked (dri2_dpy
->conn
,
510 reply
= xcb_dri2_get_buffers_with_format_reply (dri2_dpy
->conn
,
515 buffers
= xcb_dri2_get_buffers_with_format_buffers (reply
);
516 dri2_surf
->base
.Width
= *width
= reply
->width
;
517 dri2_surf
->base
.Height
= *height
= reply
->height
;
518 *out_count
= reply
->count
;
519 dri2_x11_process_buffers(dri2_surf
, buffers
, *out_count
);
523 return dri2_surf
->buffers
;
527 dri2_x11_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
531 /* FIXME: Does EGL support front buffer rendering at all? */
534 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
536 dri2WaitGL(dri2_surf
);
538 (void) loaderPrivate
;
543 dri2_x11_do_authenticate(struct dri2_egl_display
*dri2_dpy
, uint32_t id
)
545 xcb_dri2_authenticate_reply_t
*authenticate
;
546 xcb_dri2_authenticate_cookie_t authenticate_cookie
;
547 xcb_screen_iterator_t s
;
548 xcb_screen_t
*screen
;
551 s
= xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy
->conn
));
553 screen
= get_xcb_screen(s
, dri2_dpy
->screen
);
555 _eglLog(_EGL_WARNING
, "DRI2: failed to get xcb screen");
559 authenticate_cookie
=
560 xcb_dri2_authenticate_unchecked(dri2_dpy
->conn
, screen
->root
, id
);
562 xcb_dri2_authenticate_reply(dri2_dpy
->conn
, authenticate_cookie
, NULL
);
564 if (authenticate
== NULL
|| !authenticate
->authenticated
)
573 dri2_x11_local_authenticate(struct dri2_egl_display
*dri2_dpy
)
578 if (drmGetMagic(dri2_dpy
->fd
, &magic
)) {
579 _eglLog(_EGL_WARNING
, "DRI2: failed to get drm magic");
583 if (dri2_x11_do_authenticate(dri2_dpy
, magic
) < 0) {
584 _eglLog(_EGL_WARNING
, "DRI2: failed to authenticate");
592 dri2_x11_connect(struct dri2_egl_display
*dri2_dpy
)
594 xcb_xfixes_query_version_reply_t
*xfixes_query
;
595 xcb_xfixes_query_version_cookie_t xfixes_query_cookie
;
596 xcb_dri2_query_version_reply_t
*dri2_query
;
597 xcb_dri2_query_version_cookie_t dri2_query_cookie
;
598 xcb_dri2_connect_reply_t
*connect
;
599 xcb_dri2_connect_cookie_t connect_cookie
;
600 xcb_generic_error_t
*error
;
601 xcb_screen_iterator_t s
;
602 xcb_screen_t
*screen
;
603 char *driver_name
, *loader_driver_name
, *device_name
;
604 const xcb_query_extension_reply_t
*extension
;
606 xcb_prefetch_extension_data (dri2_dpy
->conn
, &xcb_xfixes_id
);
607 xcb_prefetch_extension_data (dri2_dpy
->conn
, &xcb_dri2_id
);
609 extension
= xcb_get_extension_data(dri2_dpy
->conn
, &xcb_xfixes_id
);
610 if (!(extension
&& extension
->present
))
613 extension
= xcb_get_extension_data(dri2_dpy
->conn
, &xcb_dri2_id
);
614 if (!(extension
&& extension
->present
))
617 xfixes_query_cookie
= xcb_xfixes_query_version(dri2_dpy
->conn
,
618 XCB_XFIXES_MAJOR_VERSION
,
619 XCB_XFIXES_MINOR_VERSION
);
621 dri2_query_cookie
= xcb_dri2_query_version (dri2_dpy
->conn
,
622 XCB_DRI2_MAJOR_VERSION
,
623 XCB_DRI2_MINOR_VERSION
);
625 s
= xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy
->conn
));
626 screen
= get_xcb_screen(s
, dri2_dpy
->screen
);
628 _eglLog(_EGL_WARNING
, "DRI2: failed to get xcb screen");
631 connect_cookie
= xcb_dri2_connect_unchecked(dri2_dpy
->conn
, screen
->root
,
632 XCB_DRI2_DRIVER_TYPE_DRI
);
635 xcb_xfixes_query_version_reply (dri2_dpy
->conn
,
636 xfixes_query_cookie
, &error
);
637 if (xfixes_query
== NULL
||
638 error
!= NULL
|| xfixes_query
->major_version
< 2) {
639 _eglLog(_EGL_WARNING
, "DRI2: failed to query xfixes version");
646 xcb_dri2_query_version_reply (dri2_dpy
->conn
, dri2_query_cookie
, &error
);
647 if (dri2_query
== NULL
|| error
!= NULL
) {
648 _eglLog(_EGL_WARNING
, "DRI2: failed to query version");
652 dri2_dpy
->dri2_major
= dri2_query
->major_version
;
653 dri2_dpy
->dri2_minor
= dri2_query
->minor_version
;
656 connect
= xcb_dri2_connect_reply (dri2_dpy
->conn
, connect_cookie
, NULL
);
657 if (connect
== NULL
||
658 connect
->driver_name_length
+ connect
->device_name_length
== 0) {
659 _eglLog(_EGL_WARNING
, "DRI2: failed to authenticate");
663 device_name
= xcb_dri2_connect_device_name (connect
);
665 dri2_dpy
->fd
= loader_open_device(device_name
);
666 if (dri2_dpy
->fd
== -1) {
667 _eglLog(_EGL_WARNING
,
668 "DRI2: could not open %s (%s)", device_name
, strerror(errno
));
673 if (!dri2_x11_local_authenticate(dri2_dpy
)) {
679 driver_name
= xcb_dri2_connect_driver_name (connect
);
681 /* If Mesa knows about the appropriate driver for this fd, then trust it.
682 * Otherwise, default to the server's value.
684 loader_driver_name
= loader_get_driver_for_fd(dri2_dpy
->fd
, 0);
685 if (loader_driver_name
) {
686 dri2_dpy
->driver_name
= loader_driver_name
;
688 dri2_dpy
->driver_name
=
690 xcb_dri2_connect_driver_name_length(connect
));
693 if (dri2_dpy
->driver_name
== NULL
) {
695 free(dri2_dpy
->driver_name
);
700 #ifdef HAVE_WAYLAND_PLATFORM
701 dri2_dpy
->device_name
=
703 xcb_dri2_connect_device_name_length(connect
));
712 dri2_x11_authenticate(_EGLDisplay
*disp
, uint32_t id
)
714 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
716 return dri2_x11_do_authenticate(dri2_dpy
, id
);
720 dri2_x11_add_configs_for_visuals(struct dri2_egl_display
*dri2_dpy
,
721 _EGLDisplay
*disp
, bool supports_preserved
)
723 xcb_screen_iterator_t s
;
724 xcb_depth_iterator_t d
;
725 xcb_visualtype_t
*visuals
;
727 unsigned int rgba_masks
[4];
729 EGLint config_attrs
[] = {
730 EGL_NATIVE_VISUAL_ID
, 0,
731 EGL_NATIVE_VISUAL_TYPE
, 0,
735 s
= xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy
->conn
));
736 d
= xcb_screen_allowed_depths_iterator(get_xcb_screen(s
, dri2_dpy
->screen
));
744 if (supports_preserved
)
745 surface_type
|= EGL_SWAP_BEHAVIOR_PRESERVED_BIT
;
748 EGLBoolean class_added
[6] = { 0, };
750 visuals
= xcb_depth_visuals(d
.data
);
751 for (i
= 0; i
< xcb_depth_visuals_length(d
.data
); i
++) {
752 if (class_added
[visuals
[i
]._class
])
755 class_added
[visuals
[i
]._class
] = EGL_TRUE
;
756 for (j
= 0; dri2_dpy
->driver_configs
[j
]; j
++) {
757 config_attrs
[1] = visuals
[i
].visual_id
;
758 config_attrs
[3] = visuals
[i
]._class
;
760 rgba_masks
[0] = visuals
[i
].red_mask
;
761 rgba_masks
[1] = visuals
[i
].green_mask
;
762 rgba_masks
[2] = visuals
[i
].blue_mask
;
764 dri2_add_config(disp
, dri2_dpy
->driver_configs
[j
], id
++,
765 surface_type
, config_attrs
, rgba_masks
);
767 /* Allow a 24-bit RGB visual to match a 32-bit RGBA EGLConfig.
768 * Otherwise it will only match a 32-bit RGBA visual. On a
769 * composited window manager on X11, this will make all of the
770 * EGLConfigs with destination alpha get blended by the
771 * compositor. This is probably not what the application
772 * wants... especially on drivers that only have 32-bit RGBA
774 if (d
.data
->depth
== 24) {
776 ~(rgba_masks
[0] | rgba_masks
[1] | rgba_masks
[2]);
777 dri2_add_config(disp
, dri2_dpy
->driver_configs
[j
], id
++,
778 surface_type
, config_attrs
, rgba_masks
);
786 if (!_eglGetArraySize(disp
->Configs
)) {
787 _eglLog(_EGL_WARNING
, "DRI2: failed to create any config");
795 dri2_copy_region(_EGLDriver
*drv
, _EGLDisplay
*disp
,
796 _EGLSurface
*draw
, xcb_xfixes_region_t region
)
798 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
799 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
800 enum xcb_dri2_attachment_t render_attachment
;
801 xcb_dri2_copy_region_cookie_t cookie
;
803 /* No-op for a pixmap or pbuffer surface */
804 if (draw
->Type
== EGL_PIXMAP_BIT
|| draw
->Type
== EGL_PBUFFER_BIT
)
808 (*dri2_dpy
->flush
->flush
)(dri2_surf
->dri_drawable
);
810 if (dri2_surf
->have_fake_front
)
811 render_attachment
= XCB_DRI2_ATTACHMENT_BUFFER_FAKE_FRONT_LEFT
;
813 render_attachment
= XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT
;
815 cookie
= xcb_dri2_copy_region_unchecked(dri2_dpy
->conn
,
818 XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT
,
820 free(xcb_dri2_copy_region_reply(dri2_dpy
->conn
, cookie
, NULL
));
826 dri2_x11_swap_buffers_msc(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
,
827 int64_t msc
, int64_t divisor
, int64_t remainder
)
829 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
830 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
831 uint32_t msc_hi
= msc
>> 32;
832 uint32_t msc_lo
= msc
& 0xffffffff;
833 uint32_t divisor_hi
= divisor
>> 32;
834 uint32_t divisor_lo
= divisor
& 0xffffffff;
835 uint32_t remainder_hi
= remainder
>> 32;
836 uint32_t remainder_lo
= remainder
& 0xffffffff;
837 xcb_dri2_swap_buffers_cookie_t cookie
;
838 xcb_dri2_swap_buffers_reply_t
*reply
;
839 int64_t swap_count
= -1;
841 /* No-op for a pixmap or pbuffer surface */
842 if (draw
->Type
== EGL_PIXMAP_BIT
|| draw
->Type
== EGL_PBUFFER_BIT
)
845 if (draw
->SwapBehavior
== EGL_BUFFER_PRESERVED
|| !dri2_dpy
->swap_available
)
846 return dri2_copy_region(drv
, disp
, draw
, dri2_surf
->region
) ? 0 : -1;
848 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
850 cookie
= xcb_dri2_swap_buffers_unchecked(dri2_dpy
->conn
, dri2_surf
->drawable
,
851 msc_hi
, msc_lo
, divisor_hi
, divisor_lo
, remainder_hi
, remainder_lo
);
853 reply
= xcb_dri2_swap_buffers_reply(dri2_dpy
->conn
, cookie
, NULL
);
856 swap_count
= (((int64_t)reply
->swap_hi
) << 32) | reply
->swap_lo
;
860 /* Since we aren't watching for the server's invalidate events like we're
861 * supposed to (due to XCB providing no mechanism for filtering the events
862 * the way xlib does), and SwapBuffers is a common cause of invalidate
863 * events, just shove one down to the driver, even though we haven't told
864 * the driver that we're the kind of loader that provides reliable
865 * invalidate events. This causes the driver to request buffers again at
866 * its next draw, so that we get the correct buffers if a pageflip
867 * happened. The driver should still be using the viewport hack to catch
870 if (dri2_dpy
->flush
&&
871 dri2_dpy
->flush
->base
.version
>= 3 && dri2_dpy
->flush
->invalidate
)
872 (*dri2_dpy
->flush
->invalidate
)(dri2_surf
->dri_drawable
);
878 dri2_x11_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
880 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
881 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
883 if (dri2_dpy
->dri2
) {
884 if (dri2_x11_swap_buffers_msc(drv
, disp
, draw
, 0, 0, 0) != -1) {
887 /* Swap failed with a window drawable. */
888 _eglError(EGL_BAD_NATIVE_WINDOW
, __FUNCTION__
);
891 assert(dri2_dpy
->swrast
);
893 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
899 dri2_x11_swap_buffers_region(_EGLDriver
*drv
, _EGLDisplay
*disp
,
901 EGLint numRects
, const EGLint
*rects
)
903 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
904 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
906 xcb_xfixes_region_t region
;
907 xcb_rectangle_t rectangles
[16];
910 if (numRects
> (int)ARRAY_SIZE(rectangles
))
911 return dri2_copy_region(drv
, disp
, draw
, dri2_surf
->region
);
913 for (i
= 0; i
< numRects
; i
++) {
914 rectangles
[i
].x
= rects
[i
* 4];
915 rectangles
[i
].y
= dri2_surf
->base
.Height
- rects
[i
* 4 + 1] - rects
[i
* 4 + 3];
916 rectangles
[i
].width
= rects
[i
* 4 + 2];
917 rectangles
[i
].height
= rects
[i
* 4 + 3];
920 region
= xcb_generate_id(dri2_dpy
->conn
);
921 xcb_xfixes_create_region(dri2_dpy
->conn
, region
, numRects
, rectangles
);
922 ret
= dri2_copy_region(drv
, disp
, draw
, region
);
923 xcb_xfixes_destroy_region(dri2_dpy
->conn
, region
);
929 dri2_x11_post_sub_buffer(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
,
930 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
932 const EGLint rect
[4] = { x
, y
, width
, height
};
934 if (x
< 0 || y
< 0 || width
< 0 || height
< 0)
935 _eglError(EGL_BAD_PARAMETER
, "eglPostSubBufferNV");
937 return dri2_x11_swap_buffers_region(drv
, disp
, draw
, 1, rect
);
941 dri2_x11_swap_interval(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
,
944 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
945 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
947 if (interval
> surf
->Config
->MaxSwapInterval
)
948 interval
= surf
->Config
->MaxSwapInterval
;
949 else if (interval
< surf
->Config
->MinSwapInterval
)
950 interval
= surf
->Config
->MinSwapInterval
;
952 if (interval
!= surf
->SwapInterval
&& dri2_dpy
->swap_available
)
953 xcb_dri2_swap_interval(dri2_dpy
->conn
, dri2_surf
->drawable
, interval
);
955 surf
->SwapInterval
= interval
;
961 dri2_x11_copy_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
,
962 void *native_pixmap_target
)
964 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
965 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
969 STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_pixmap_target
));
970 target
= (uintptr_t) native_pixmap_target
;
974 (*dri2_dpy
->flush
->flush
)(dri2_surf
->dri_drawable
);
976 gc
= xcb_generate_id(dri2_dpy
->conn
);
977 xcb_create_gc(dri2_dpy
->conn
, gc
, target
, 0, NULL
);
978 xcb_copy_area(dri2_dpy
->conn
,
984 dri2_surf
->base
.Width
,
985 dri2_surf
->base
.Height
);
986 xcb_free_gc(dri2_dpy
->conn
, gc
);
992 dri2_create_image_khr_pixmap(_EGLDisplay
*disp
, _EGLContext
*ctx
,
993 EGLClientBuffer buffer
, const EGLint
*attr_list
)
995 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
996 struct dri2_egl_image
*dri2_img
;
997 unsigned int attachments
[1];
998 xcb_drawable_t drawable
;
999 xcb_dri2_get_buffers_cookie_t buffers_cookie
;
1000 xcb_dri2_get_buffers_reply_t
*buffers_reply
;
1001 xcb_dri2_dri2_buffer_t
*buffers
;
1002 xcb_get_geometry_cookie_t geometry_cookie
;
1003 xcb_get_geometry_reply_t
*geometry_reply
;
1004 xcb_generic_error_t
*error
;
1009 drawable
= (xcb_drawable_t
) (uintptr_t) buffer
;
1010 xcb_dri2_create_drawable (dri2_dpy
->conn
, drawable
);
1011 attachments
[0] = XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT
;
1013 xcb_dri2_get_buffers_unchecked (dri2_dpy
->conn
,
1014 drawable
, 1, 1, attachments
);
1015 geometry_cookie
= xcb_get_geometry (dri2_dpy
->conn
, drawable
);
1016 buffers_reply
= xcb_dri2_get_buffers_reply (dri2_dpy
->conn
,
1017 buffers_cookie
, NULL
);
1018 if (buffers_reply
== NULL
)
1021 buffers
= xcb_dri2_get_buffers_buffers (buffers_reply
);
1022 if (buffers
== NULL
) {
1026 geometry_reply
= xcb_get_geometry_reply (dri2_dpy
->conn
,
1027 geometry_cookie
, &error
);
1028 if (geometry_reply
== NULL
|| error
!= NULL
) {
1029 _eglError(EGL_BAD_ALLOC
, "xcb_get_geometry");
1031 free(buffers_reply
);
1035 switch (geometry_reply
->depth
) {
1037 format
= __DRI_IMAGE_FORMAT_RGB565
;
1040 format
= __DRI_IMAGE_FORMAT_XRGB8888
;
1043 format
= __DRI_IMAGE_FORMAT_ARGB8888
;
1046 _eglError(EGL_BAD_PARAMETER
,
1047 "dri2_create_image_khr: unsupported pixmap depth");
1048 free(buffers_reply
);
1049 free(geometry_reply
);
1053 dri2_img
= malloc(sizeof *dri2_img
);
1055 free(buffers_reply
);
1056 free(geometry_reply
);
1057 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
1058 return EGL_NO_IMAGE_KHR
;
1061 if (!_eglInitImage(&dri2_img
->base
, disp
)) {
1062 free(buffers_reply
);
1063 free(geometry_reply
);
1065 return EGL_NO_IMAGE_KHR
;
1068 stride
= buffers
[0].pitch
/ buffers
[0].cpp
;
1069 dri2_img
->dri_image
=
1070 dri2_dpy
->image
->createImageFromName(dri2_dpy
->dri_screen
,
1071 buffers_reply
->width
,
1072 buffers_reply
->height
,
1078 free(buffers_reply
);
1079 free(geometry_reply
);
1081 return &dri2_img
->base
;
1085 dri2_x11_create_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
,
1086 _EGLContext
*ctx
, EGLenum target
,
1087 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1092 case EGL_NATIVE_PIXMAP_KHR
:
1093 return dri2_create_image_khr_pixmap(disp
, ctx
, buffer
, attr_list
);
1095 return dri2_create_image_khr(drv
, disp
, ctx
, target
, buffer
, attr_list
);
1100 dri2_x11_get_sync_values(_EGLDisplay
*display
, _EGLSurface
*surface
,
1101 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
1104 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(display
);
1105 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
1106 xcb_dri2_get_msc_cookie_t cookie
;
1107 xcb_dri2_get_msc_reply_t
*reply
;
1109 cookie
= xcb_dri2_get_msc(dri2_dpy
->conn
, dri2_surf
->drawable
);
1110 reply
= xcb_dri2_get_msc_reply(dri2_dpy
->conn
, cookie
, NULL
);
1113 _eglError(EGL_BAD_ACCESS
, __func__
);
1117 *ust
= ((EGLuint64KHR
) reply
->ust_hi
<< 32) | reply
->ust_lo
;
1118 *msc
= ((EGLuint64KHR
) reply
->msc_hi
<< 32) | reply
->msc_lo
;
1119 *sbc
= ((EGLuint64KHR
) reply
->sbc_hi
<< 32) | reply
->sbc_lo
;
1125 static struct dri2_egl_display_vtbl dri2_x11_swrast_display_vtbl
= {
1126 .authenticate
= NULL
,
1127 .create_window_surface
= dri2_x11_create_window_surface
,
1128 .create_pixmap_surface
= dri2_x11_create_pixmap_surface
,
1129 .create_pbuffer_surface
= dri2_x11_create_pbuffer_surface
,
1130 .destroy_surface
= dri2_x11_destroy_surface
,
1131 .create_image
= dri2_fallback_create_image_khr
,
1132 .swap_interval
= dri2_fallback_swap_interval
,
1133 .swap_buffers
= dri2_x11_swap_buffers
,
1134 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1135 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1136 .copy_buffers
= dri2_x11_copy_buffers
,
1137 .query_buffer_age
= dri2_fallback_query_buffer_age
,
1138 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
1139 .get_sync_values
= dri2_fallback_get_sync_values
,
1140 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1143 static struct dri2_egl_display_vtbl dri2_x11_display_vtbl
= {
1144 .authenticate
= dri2_x11_authenticate
,
1145 .create_window_surface
= dri2_x11_create_window_surface
,
1146 .create_pixmap_surface
= dri2_x11_create_pixmap_surface
,
1147 .create_pbuffer_surface
= dri2_x11_create_pbuffer_surface
,
1148 .destroy_surface
= dri2_x11_destroy_surface
,
1149 .create_image
= dri2_x11_create_image_khr
,
1150 .swap_interval
= dri2_x11_swap_interval
,
1151 .swap_buffers
= dri2_x11_swap_buffers
,
1152 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
1153 .swap_buffers_region
= dri2_x11_swap_buffers_region
,
1154 .post_sub_buffer
= dri2_x11_post_sub_buffer
,
1155 .copy_buffers
= dri2_x11_copy_buffers
,
1156 .query_buffer_age
= dri2_fallback_query_buffer_age
,
1157 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
1158 .get_sync_values
= dri2_x11_get_sync_values
,
1159 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1162 static const __DRIswrastLoaderExtension swrast_loader_extension
= {
1163 .base
= { __DRI_SWRAST_LOADER
, 1 },
1165 .getDrawableInfo
= swrastGetDrawableInfo
,
1166 .putImage
= swrastPutImage
,
1167 .getImage
= swrastGetImage
,
1170 static const __DRIextension
*swrast_loader_extensions
[] = {
1171 &swrast_loader_extension
.base
,
1176 dri2_initialize_x11_swrast(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1178 struct dri2_egl_display
*dri2_dpy
;
1180 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1182 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1184 disp
->DriverData
= (void *) dri2_dpy
;
1185 if (disp
->PlatformDisplay
== NULL
) {
1186 dri2_dpy
->conn
= xcb_connect(0, &dri2_dpy
->screen
);
1187 dri2_dpy
->own_device
= true;
1189 Display
*dpy
= disp
->PlatformDisplay
;
1191 dri2_dpy
->conn
= XGetXCBConnection(dpy
);
1192 dri2_dpy
->screen
= DefaultScreen(dpy
);
1195 if (!dri2_dpy
->conn
|| xcb_connection_has_error(dri2_dpy
->conn
)) {
1196 _eglLog(_EGL_WARNING
, "DRI2: xcb_connect failed");
1201 * Every hardware driver_name is set using strdup. Doing the same in
1202 * here will allow is to simply free the memory at dri2_terminate().
1205 dri2_dpy
->driver_name
= strdup("swrast");
1206 if (!dri2_load_driver_swrast(disp
))
1209 dri2_dpy
->loader_extensions
= swrast_loader_extensions
;
1211 if (!dri2_create_screen(disp
))
1212 goto cleanup_driver
;
1214 if (!dri2_x11_add_configs_for_visuals(dri2_dpy
, disp
, true))
1215 goto cleanup_configs
;
1217 /* Fill vtbl last to prevent accidentally calling virtual function during
1220 dri2_dpy
->vtbl
= &dri2_x11_swrast_display_vtbl
;
1225 _eglCleanupDisplay(disp
);
1226 dri2_dpy
->core
->destroyScreen(dri2_dpy
->dri_screen
);
1228 dlclose(dri2_dpy
->driver
);
1230 free(dri2_dpy
->driver_name
);
1231 if (disp
->PlatformDisplay
== NULL
)
1232 xcb_disconnect(dri2_dpy
->conn
);
1235 disp
->DriverData
= NULL
;
1241 dri2_x11_setup_swap_interval(struct dri2_egl_display
*dri2_dpy
)
1243 GLint vblank_mode
= DRI_CONF_VBLANK_DEF_INTERVAL_1
;
1244 int arbitrary_max_interval
= 1000;
1246 /* default behavior for no SwapBuffers support: no vblank syncing
1249 dri2_dpy
->min_swap_interval
= 0;
1250 dri2_dpy
->max_swap_interval
= 0;
1252 if (!dri2_dpy
->swap_available
)
1255 /* If we do have swapbuffers, then we can support pretty much any swap
1256 * interval, but we allow driconf to override applications.
1258 if (dri2_dpy
->config
)
1259 dri2_dpy
->config
->configQueryi(dri2_dpy
->dri_screen
,
1260 "vblank_mode", &vblank_mode
);
1261 switch (vblank_mode
) {
1262 case DRI_CONF_VBLANK_NEVER
:
1263 dri2_dpy
->min_swap_interval
= 0;
1264 dri2_dpy
->max_swap_interval
= 0;
1265 dri2_dpy
->default_swap_interval
= 0;
1267 case DRI_CONF_VBLANK_ALWAYS_SYNC
:
1268 dri2_dpy
->min_swap_interval
= 1;
1269 dri2_dpy
->max_swap_interval
= arbitrary_max_interval
;
1270 dri2_dpy
->default_swap_interval
= 1;
1272 case DRI_CONF_VBLANK_DEF_INTERVAL_0
:
1273 dri2_dpy
->min_swap_interval
= 0;
1274 dri2_dpy
->max_swap_interval
= arbitrary_max_interval
;
1275 dri2_dpy
->default_swap_interval
= 0;
1278 case DRI_CONF_VBLANK_DEF_INTERVAL_1
:
1279 dri2_dpy
->min_swap_interval
= 0;
1280 dri2_dpy
->max_swap_interval
= arbitrary_max_interval
;
1281 dri2_dpy
->default_swap_interval
= 1;
1288 static const __DRIextension
*dri3_image_loader_extensions
[] = {
1289 &dri3_image_loader_extension
.base
,
1290 &image_lookup_extension
.base
,
1291 &use_invalidate
.base
,
1296 dri2_initialize_x11_dri3(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1298 struct dri2_egl_display
*dri2_dpy
;
1300 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1302 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1304 disp
->DriverData
= (void *) dri2_dpy
;
1305 if (disp
->PlatformDisplay
== NULL
) {
1306 dri2_dpy
->conn
= xcb_connect(0, &dri2_dpy
->screen
);
1307 dri2_dpy
->own_device
= true;
1309 Display
*dpy
= disp
->PlatformDisplay
;
1311 dri2_dpy
->conn
= XGetXCBConnection(dpy
);
1312 dri2_dpy
->screen
= DefaultScreen(dpy
);
1315 if (xcb_connection_has_error(dri2_dpy
->conn
)) {
1316 _eglLog(_EGL_WARNING
, "DRI3: xcb_connect failed");
1320 if (dri2_dpy
->conn
) {
1321 if (!dri3_x11_connect(dri2_dpy
))
1325 if (!dri2_load_driver_dri3(disp
))
1328 dri2_dpy
->loader_extensions
= dri3_image_loader_extensions
;
1330 dri2_dpy
->swap_available
= true;
1331 dri2_dpy
->invalidate_available
= true;
1333 if (!dri2_create_screen(disp
))
1336 dri2_x11_setup_swap_interval(dri2_dpy
);
1338 if (!dri2_dpy
->is_different_gpu
)
1339 disp
->Extensions
.KHR_image_pixmap
= EGL_TRUE
;
1340 disp
->Extensions
.NOK_texture_from_pixmap
= EGL_TRUE
;
1341 disp
->Extensions
.CHROMIUM_sync_control
= EGL_TRUE
;
1342 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
1344 #ifdef HAVE_WAYLAND_PLATFORM
1345 if (dri2_dpy
->device_name
)
1346 disp
->Extensions
.WL_bind_wayland_display
= EGL_TRUE
;
1349 if (dri2_dpy
->conn
) {
1350 if (!dri2_x11_add_configs_for_visuals(dri2_dpy
, disp
, false))
1351 goto cleanup_configs
;
1354 dri2_dpy
->loader_dri3_ext
.core
= dri2_dpy
->core
;
1355 dri2_dpy
->loader_dri3_ext
.image_driver
= dri2_dpy
->image_driver
;
1356 dri2_dpy
->loader_dri3_ext
.flush
= dri2_dpy
->flush
;
1357 dri2_dpy
->loader_dri3_ext
.tex_buffer
= dri2_dpy
->tex_buffer
;
1358 dri2_dpy
->loader_dri3_ext
.image
= dri2_dpy
->image
;
1359 dri2_dpy
->loader_dri3_ext
.config
= dri2_dpy
->config
;
1361 /* Fill vtbl last to prevent accidentally calling virtual function during
1364 dri2_dpy
->vtbl
= &dri3_x11_display_vtbl
;
1366 _eglLog(_EGL_INFO
, "Using DRI3");
1371 _eglCleanupDisplay(disp
);
1372 dri2_dpy
->core
->destroyScreen(dri2_dpy
->dri_screen
);
1373 dlclose(dri2_dpy
->driver
);
1375 close(dri2_dpy
->fd
);
1377 if (disp
->PlatformDisplay
== NULL
)
1378 xcb_disconnect(dri2_dpy
->conn
);
1381 disp
->DriverData
= NULL
;
1387 static const __DRIdri2LoaderExtension dri2_loader_extension_old
= {
1388 .base
= { __DRI_DRI2_LOADER
, 2 },
1390 .getBuffers
= dri2_x11_get_buffers
,
1391 .flushFrontBuffer
= dri2_x11_flush_front_buffer
,
1392 .getBuffersWithFormat
= NULL
,
1395 static const __DRIdri2LoaderExtension dri2_loader_extension
= {
1396 .base
= { __DRI_DRI2_LOADER
, 3 },
1398 .getBuffers
= dri2_x11_get_buffers
,
1399 .flushFrontBuffer
= dri2_x11_flush_front_buffer
,
1400 .getBuffersWithFormat
= dri2_x11_get_buffers_with_format
,
1403 static const __DRIextension
*dri2_loader_extensions_old
[] = {
1404 &dri2_loader_extension_old
.base
,
1405 &image_lookup_extension
.base
,
1409 static const __DRIextension
*dri2_loader_extensions
[] = {
1410 &dri2_loader_extension
.base
,
1411 &image_lookup_extension
.base
,
1416 dri2_initialize_x11_dri2(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1418 struct dri2_egl_display
*dri2_dpy
;
1420 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1422 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1424 disp
->DriverData
= (void *) dri2_dpy
;
1425 if (disp
->PlatformDisplay
== NULL
) {
1426 dri2_dpy
->conn
= xcb_connect(0, &dri2_dpy
->screen
);
1427 dri2_dpy
->own_device
= true;
1429 Display
*dpy
= disp
->PlatformDisplay
;
1431 dri2_dpy
->conn
= XGetXCBConnection(dpy
);
1432 dri2_dpy
->screen
= DefaultScreen(dpy
);
1435 if (!dri2_dpy
->conn
|| xcb_connection_has_error(dri2_dpy
->conn
)) {
1436 _eglLog(_EGL_WARNING
, "DRI2: xcb_connect failed");
1440 if (!dri2_x11_connect(dri2_dpy
))
1443 if (!dri2_load_driver(disp
))
1446 if (dri2_dpy
->dri2_minor
>= 1)
1447 dri2_dpy
->loader_extensions
= dri2_loader_extensions
;
1449 dri2_dpy
->loader_extensions
= dri2_loader_extensions_old
;
1451 dri2_dpy
->swap_available
= (dri2_dpy
->dri2_minor
>= 2);
1452 dri2_dpy
->invalidate_available
= (dri2_dpy
->dri2_minor
>= 3);
1454 if (!dri2_create_screen(disp
))
1455 goto cleanup_driver
;
1457 dri2_x11_setup_swap_interval(dri2_dpy
);
1459 disp
->Extensions
.KHR_image_pixmap
= EGL_TRUE
;
1460 disp
->Extensions
.NOK_swap_region
= EGL_TRUE
;
1461 disp
->Extensions
.NOK_texture_from_pixmap
= EGL_TRUE
;
1462 disp
->Extensions
.NV_post_sub_buffer
= EGL_TRUE
;
1463 disp
->Extensions
.CHROMIUM_sync_control
= EGL_TRUE
;
1465 #ifdef HAVE_WAYLAND_PLATFORM
1466 disp
->Extensions
.WL_bind_wayland_display
= EGL_TRUE
;
1469 if (!dri2_x11_add_configs_for_visuals(dri2_dpy
, disp
, true))
1470 goto cleanup_configs
;
1472 /* Fill vtbl last to prevent accidentally calling virtual function during
1475 dri2_dpy
->vtbl
= &dri2_x11_display_vtbl
;
1477 _eglLog(_EGL_INFO
, "Using DRI2");
1482 _eglCleanupDisplay(disp
);
1483 dri2_dpy
->core
->destroyScreen(dri2_dpy
->dri_screen
);
1485 dlclose(dri2_dpy
->driver
);
1487 close(dri2_dpy
->fd
);
1489 if (disp
->PlatformDisplay
== NULL
)
1490 xcb_disconnect(dri2_dpy
->conn
);
1493 disp
->DriverData
= NULL
;
1499 dri2_initialize_x11(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1501 EGLBoolean initialized
= EGL_TRUE
;
1503 int x11_dri2_accel
= (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL
);
1505 if (x11_dri2_accel
) {
1507 if (getenv("LIBGL_DRI3_DISABLE") != NULL
||
1508 !dri2_initialize_x11_dri3(drv
, disp
)) {
1510 if (!dri2_initialize_x11_dri2(drv
, disp
)) {
1511 initialized
= dri2_initialize_x11_swrast(drv
, disp
);
1517 initialized
= dri2_initialize_x11_swrast(drv
, disp
);