2 * Copyright © 2011-2012 Intel Corporation
3 * Copyright © 2012 Collabora, Ltd.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
26 * Kristian Høgsberg <krh@bitplanet.net>
27 * Benjamin Franzke <benjaminfranzke@googlemail.com>
39 #include <drm_fourcc.h>
43 #include "egl_dri2_fallbacks.h"
45 #include "util/u_vector.h"
46 #include "eglglobals.h"
48 #include <wayland-client.h>
49 #include "wayland-drm-client-protocol.h"
50 #include "linux-dmabuf-unstable-v1-client-protocol.h"
52 #include "wayland/wayland-egl/wayland-egl-backend.h"
54 #ifndef DRM_FORMAT_MOD_INVALID
55 #define DRM_FORMAT_MOD_INVALID ((1ULL << 56) - 1)
58 #ifndef DRM_FORMAT_MOD_LINEAR
59 #define DRM_FORMAT_MOD_LINEAR 0
63 * The index of entries in this table is used as a bitmask in
64 * dri2_dpy->formats, which tracks the formats supported by our server.
66 static const struct dri2_wl_visual
{
67 const char *format_name
;
68 uint32_t wl_drm_format
;
69 uint32_t wl_shm_format
;
72 unsigned int rgba_masks
[4];
73 } dri2_wl_visuals
[] = {
76 WL_DRM_FORMAT_XRGB2101010
, WL_SHM_FORMAT_XRGB2101010
,
77 __DRI_IMAGE_FORMAT_XRGB2101010
, 32,
78 { 0x3ff00000, 0x000ffc00, 0x000003ff, 0x00000000 }
82 WL_DRM_FORMAT_ARGB2101010
, WL_SHM_FORMAT_ARGB2101010
,
83 __DRI_IMAGE_FORMAT_ARGB2101010
, 32,
84 { 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 }
88 WL_DRM_FORMAT_XRGB8888
, WL_SHM_FORMAT_XRGB8888
,
89 __DRI_IMAGE_FORMAT_XRGB8888
, 32,
90 { 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 }
94 WL_DRM_FORMAT_ARGB8888
, WL_SHM_FORMAT_ARGB8888
,
95 __DRI_IMAGE_FORMAT_ARGB8888
, 32,
96 { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }
100 WL_DRM_FORMAT_RGB565
, WL_SHM_FORMAT_RGB565
,
101 __DRI_IMAGE_FORMAT_RGB565
, 16,
102 { 0xf800, 0x07e0, 0x001f, 0x0000 }
107 dri2_wl_visual_idx_from_config(struct dri2_egl_display
*dri2_dpy
,
108 const __DRIconfig
*config
)
110 unsigned int red
, green
, blue
, alpha
;
112 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_RED_MASK
, &red
);
113 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_GREEN_MASK
, &green
);
114 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_BLUE_MASK
, &blue
);
115 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_ALPHA_MASK
, &alpha
);
117 for (unsigned int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
118 const struct dri2_wl_visual
*wl_visual
= &dri2_wl_visuals
[i
];
120 if (red
== wl_visual
->rgba_masks
[0] &&
121 green
== wl_visual
->rgba_masks
[1] &&
122 blue
== wl_visual
->rgba_masks
[2] &&
123 alpha
== wl_visual
->rgba_masks
[3]) {
132 dri2_wl_visual_idx_from_fourcc(uint32_t fourcc
)
134 for (int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
135 /* wl_drm format codes overlap with DRIImage FourCC codes for all formats
137 if (dri2_wl_visuals
[i
].wl_drm_format
== fourcc
)
145 dri2_wl_visual_idx_from_dri_image_format(uint32_t dri_image_format
)
147 for (int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
148 if (dri2_wl_visuals
[i
].dri_image_format
== dri_image_format
)
156 dri2_wl_visual_idx_from_shm_format(uint32_t shm_format
)
158 for (int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
159 if (dri2_wl_visuals
[i
].wl_shm_format
== shm_format
)
167 roundtrip(struct dri2_egl_display
*dri2_dpy
)
169 return wl_display_roundtrip_queue(dri2_dpy
->wl_dpy
, dri2_dpy
->wl_queue
);
173 wl_buffer_release(void *data
, struct wl_buffer
*buffer
)
175 struct dri2_egl_surface
*dri2_surf
= data
;
178 for (i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); ++i
)
179 if (dri2_surf
->color_buffers
[i
].wl_buffer
== buffer
)
182 if (i
== ARRAY_SIZE(dri2_surf
->color_buffers
)) {
183 wl_buffer_destroy(buffer
);
187 dri2_surf
->color_buffers
[i
].locked
= false;
190 static const struct wl_buffer_listener wl_buffer_listener
= {
191 .release
= wl_buffer_release
195 resize_callback(struct wl_egl_window
*wl_win
, void *data
)
197 struct dri2_egl_surface
*dri2_surf
= data
;
198 struct dri2_egl_display
*dri2_dpy
=
199 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
201 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
205 destroy_window_callback(void *data
)
207 struct dri2_egl_surface
*dri2_surf
= data
;
208 dri2_surf
->wl_win
= NULL
;
211 static struct wl_surface
*
212 get_wl_surface_proxy(struct wl_egl_window
*window
)
214 /* Version 3 of wl_egl_window introduced a version field at the same
215 * location where a pointer to wl_surface was stored. Thus, if
216 * window->version is dereferencable, we've been given an older version of
217 * wl_egl_window, and window->version points to wl_surface */
218 if (_eglPointerIsDereferencable((void *)(window
->version
))) {
219 return wl_proxy_create_wrapper((void *)(window
->version
));
221 return wl_proxy_create_wrapper(window
->surface
);
225 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
228 dri2_wl_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
229 _EGLConfig
*conf
, void *native_window
,
230 const EGLint
*attrib_list
)
232 __DRIcreateNewDrawableFunc createNewDrawable
;
233 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
234 struct dri2_egl_config
*dri2_conf
= dri2_egl_config(conf
);
235 struct wl_egl_window
*window
= native_window
;
236 struct dri2_egl_surface
*dri2_surf
;
238 const __DRIconfig
*config
;
240 dri2_surf
= calloc(1, sizeof *dri2_surf
);
242 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
246 if (!dri2_init_surface(&dri2_surf
->base
, disp
, EGL_WINDOW_BIT
, conf
,
250 config
= dri2_get_dri_config(dri2_conf
, EGL_WINDOW_BIT
,
251 dri2_surf
->base
.GLColorspace
);
252 visual_idx
= dri2_wl_visual_idx_from_config(dri2_dpy
, config
);
253 assert(visual_idx
!= -1);
255 if (dri2_dpy
->wl_dmabuf
|| dri2_dpy
->wl_drm
) {
256 dri2_surf
->format
= dri2_wl_visuals
[visual_idx
].wl_drm_format
;
258 assert(dri2_dpy
->wl_shm
);
259 dri2_surf
->format
= dri2_wl_visuals
[visual_idx
].wl_shm_format
;
262 dri2_surf
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
263 if (!dri2_surf
->wl_queue
) {
264 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
268 if (dri2_dpy
->wl_drm
) {
269 dri2_surf
->wl_drm_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_drm
);
270 if (!dri2_surf
->wl_drm_wrapper
) {
271 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
274 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_drm_wrapper
,
275 dri2_surf
->wl_queue
);
278 dri2_surf
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
279 if (!dri2_surf
->wl_dpy_wrapper
) {
280 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
283 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_dpy_wrapper
,
284 dri2_surf
->wl_queue
);
286 dri2_surf
->wl_surface_wrapper
= get_wl_surface_proxy(window
);
287 if (!dri2_surf
->wl_surface_wrapper
) {
288 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
289 goto cleanup_dpy_wrapper
;
291 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_surface_wrapper
,
292 dri2_surf
->wl_queue
);
294 dri2_surf
->wl_win
= window
;
295 dri2_surf
->wl_win
->private = dri2_surf
;
296 dri2_surf
->wl_win
->destroy_window_callback
= destroy_window_callback
;
298 dri2_surf
->wl_win
->resize_callback
= resize_callback
;
300 if (dri2_dpy
->image_driver
)
301 createNewDrawable
= dri2_dpy
->image_driver
->createNewDrawable
;
302 else if (dri2_dpy
->dri2
)
303 createNewDrawable
= dri2_dpy
->dri2
->createNewDrawable
;
305 createNewDrawable
= dri2_dpy
->swrast
->createNewDrawable
;
307 dri2_surf
->dri_drawable
= (*createNewDrawable
)(dri2_dpy
->dri_screen
, config
,
309 if (dri2_surf
->dri_drawable
== NULL
) {
310 _eglError(EGL_BAD_ALLOC
, "createNewDrawable");
311 goto cleanup_surf_wrapper
;
314 dri2_surf
->base
.SwapInterval
= dri2_dpy
->default_swap_interval
;
316 return &dri2_surf
->base
;
318 cleanup_surf_wrapper
:
319 wl_proxy_wrapper_destroy(dri2_surf
->wl_surface_wrapper
);
321 wl_proxy_wrapper_destroy(dri2_surf
->wl_dpy_wrapper
);
323 if (dri2_surf
->wl_drm_wrapper
)
324 wl_proxy_wrapper_destroy(dri2_surf
->wl_drm_wrapper
);
326 wl_event_queue_destroy(dri2_surf
->wl_queue
);
334 dri2_wl_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
335 _EGLConfig
*conf
, void *native_window
,
336 const EGLint
*attrib_list
)
338 /* From the EGL_EXT_platform_wayland spec, version 3:
340 * It is not valid to call eglCreatePlatformPixmapSurfaceEXT with a <dpy>
341 * that belongs to Wayland. Any such call fails and generates
344 _eglError(EGL_BAD_PARAMETER
, "cannot create EGL pixmap surfaces on "
350 * Called via eglDestroySurface(), drv->API.DestroySurface().
353 dri2_wl_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
355 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
356 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
360 dri2_dpy
->core
->destroyDrawable(dri2_surf
->dri_drawable
);
362 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
363 if (dri2_surf
->color_buffers
[i
].wl_buffer
)
364 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
365 if (dri2_surf
->color_buffers
[i
].dri_image
)
366 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
367 if (dri2_surf
->color_buffers
[i
].linear_copy
)
368 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
369 if (dri2_surf
->color_buffers
[i
].data
)
370 munmap(dri2_surf
->color_buffers
[i
].data
,
371 dri2_surf
->color_buffers
[i
].data_size
);
375 dri2_egl_surface_free_local_buffers(dri2_surf
);
377 if (dri2_surf
->throttle_callback
)
378 wl_callback_destroy(dri2_surf
->throttle_callback
);
380 if (dri2_surf
->wl_win
) {
381 dri2_surf
->wl_win
->private = NULL
;
382 dri2_surf
->wl_win
->resize_callback
= NULL
;
383 dri2_surf
->wl_win
->destroy_window_callback
= NULL
;
386 wl_proxy_wrapper_destroy(dri2_surf
->wl_surface_wrapper
);
387 wl_proxy_wrapper_destroy(dri2_surf
->wl_dpy_wrapper
);
388 if (dri2_surf
->wl_drm_wrapper
)
389 wl_proxy_wrapper_destroy(dri2_surf
->wl_drm_wrapper
);
390 wl_event_queue_destroy(dri2_surf
->wl_queue
);
392 dri2_fini_surface(surf
);
399 dri2_wl_release_buffers(struct dri2_egl_surface
*dri2_surf
)
401 struct dri2_egl_display
*dri2_dpy
=
402 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
404 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
405 if (dri2_surf
->color_buffers
[i
].wl_buffer
&&
406 !dri2_surf
->color_buffers
[i
].locked
)
407 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
408 if (dri2_surf
->color_buffers
[i
].dri_image
)
409 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
410 if (dri2_surf
->color_buffers
[i
].linear_copy
)
411 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
412 if (dri2_surf
->color_buffers
[i
].data
)
413 munmap(dri2_surf
->color_buffers
[i
].data
,
414 dri2_surf
->color_buffers
[i
].data_size
);
416 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
417 dri2_surf
->color_buffers
[i
].dri_image
= NULL
;
418 dri2_surf
->color_buffers
[i
].linear_copy
= NULL
;
419 dri2_surf
->color_buffers
[i
].data
= NULL
;
420 dri2_surf
->color_buffers
[i
].locked
= false;
424 dri2_egl_surface_free_local_buffers(dri2_surf
);
428 get_back_bo(struct dri2_egl_surface
*dri2_surf
)
430 struct dri2_egl_display
*dri2_dpy
=
431 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
434 unsigned int dri_image_format
;
438 visual_idx
= dri2_wl_visual_idx_from_fourcc(dri2_surf
->format
);
439 assert(visual_idx
!= -1);
440 dri_image_format
= dri2_wl_visuals
[visual_idx
].dri_image_format
;
441 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
[visual_idx
]);
442 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
[visual_idx
]);
444 /* There might be a buffer release already queued that wasn't processed */
445 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
447 while (dri2_surf
->back
== NULL
) {
448 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
449 /* Get an unlocked buffer, preferrably one with a dri_buffer
450 * already allocated. */
451 if (dri2_surf
->color_buffers
[i
].locked
)
453 if (dri2_surf
->back
== NULL
)
454 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
455 else if (dri2_surf
->back
->dri_image
== NULL
)
456 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
462 /* If we don't have a buffer, then block on the server to release one for
463 * us, and try again. wl_display_dispatch_queue will process any pending
464 * events, however not all servers flush on issuing a buffer release
465 * event. So, we spam the server with roundtrips as they always cause a
468 if (wl_display_roundtrip_queue(dri2_dpy
->wl_dpy
,
469 dri2_surf
->wl_queue
) < 0)
473 if (dri2_surf
->back
== NULL
)
476 use_flags
= __DRI_IMAGE_USE_SHARE
| __DRI_IMAGE_USE_BACKBUFFER
;
478 if (dri2_dpy
->is_different_gpu
&&
479 dri2_surf
->back
->linear_copy
== NULL
) {
480 /* The LINEAR modifier should be a perfect alias of the LINEAR use
481 * flag; try the new interface first before the old, then fall back. */
482 if (dri2_dpy
->image
->base
.version
>= 15 &&
483 dri2_dpy
->image
->createImageWithModifiers
) {
484 uint64_t linear_mod
= DRM_FORMAT_MOD_LINEAR
;
486 dri2_surf
->back
->linear_copy
=
487 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
488 dri2_surf
->base
.Width
,
489 dri2_surf
->base
.Height
,
495 dri2_surf
->back
->linear_copy
=
496 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
497 dri2_surf
->base
.Width
,
498 dri2_surf
->base
.Height
,
501 __DRI_IMAGE_USE_LINEAR
,
504 if (dri2_surf
->back
->linear_copy
== NULL
)
508 if (dri2_surf
->back
->dri_image
== NULL
) {
509 /* If our DRIImage implementation does not support
510 * createImageWithModifiers, then fall back to the old createImage,
511 * and hope it allocates an image which is acceptable to the winsys.
513 if (num_modifiers
&& dri2_dpy
->image
->base
.version
>= 15 &&
514 dri2_dpy
->image
->createImageWithModifiers
) {
515 dri2_surf
->back
->dri_image
=
516 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
517 dri2_surf
->base
.Width
,
518 dri2_surf
->base
.Height
,
524 dri2_surf
->back
->dri_image
=
525 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
526 dri2_surf
->base
.Width
,
527 dri2_surf
->base
.Height
,
529 dri2_dpy
->is_different_gpu
?
534 dri2_surf
->back
->age
= 0;
536 if (dri2_surf
->back
->dri_image
== NULL
)
539 dri2_surf
->back
->locked
= true;
546 back_bo_to_dri_buffer(struct dri2_egl_surface
*dri2_surf
, __DRIbuffer
*buffer
)
548 struct dri2_egl_display
*dri2_dpy
=
549 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
553 image
= dri2_surf
->back
->dri_image
;
555 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
556 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &pitch
);
558 buffer
->attachment
= __DRI_BUFFER_BACK_LEFT
;
560 buffer
->pitch
= pitch
;
566 update_buffers(struct dri2_egl_surface
*dri2_surf
)
568 struct dri2_egl_display
*dri2_dpy
=
569 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
571 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->width
||
572 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->height
) {
574 dri2_wl_release_buffers(dri2_surf
);
576 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
577 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
578 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
579 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
582 if (get_back_bo(dri2_surf
) < 0) {
583 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
587 /* If we have an extra unlocked buffer at this point, we had to do triple
588 * buffering for a while, but now can go back to just double buffering.
589 * That means we can free any unlocked buffer now. */
590 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
591 if (!dri2_surf
->color_buffers
[i
].locked
&&
592 dri2_surf
->color_buffers
[i
].wl_buffer
) {
593 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
594 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
595 if (dri2_dpy
->is_different_gpu
)
596 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
597 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
598 dri2_surf
->color_buffers
[i
].dri_image
= NULL
;
599 dri2_surf
->color_buffers
[i
].linear_copy
= NULL
;
607 dri2_wl_get_buffers_with_format(__DRIdrawable
* driDrawable
,
608 int *width
, int *height
,
609 unsigned int *attachments
, int count
,
610 int *out_count
, void *loaderPrivate
)
612 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
615 if (update_buffers(dri2_surf
) < 0)
618 for (i
= 0, j
= 0; i
< 2 * count
; i
+= 2, j
++) {
621 switch (attachments
[i
]) {
622 case __DRI_BUFFER_BACK_LEFT
:
623 back_bo_to_dri_buffer(dri2_surf
, &dri2_surf
->buffers
[j
]);
626 local
= dri2_egl_surface_alloc_local_buffer(dri2_surf
, attachments
[i
],
630 _eglError(EGL_BAD_ALLOC
, "failed to allocate local buffer");
633 dri2_surf
->buffers
[j
] = *local
;
642 *width
= dri2_surf
->base
.Width
;
643 *height
= dri2_surf
->base
.Height
;
645 return dri2_surf
->buffers
;
649 dri2_wl_get_buffers(__DRIdrawable
* driDrawable
,
650 int *width
, int *height
,
651 unsigned int *attachments
, int count
,
652 int *out_count
, void *loaderPrivate
)
654 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
655 unsigned int *attachments_with_format
;
657 int visual_idx
= dri2_wl_visual_idx_from_fourcc(dri2_surf
->format
);
659 if (visual_idx
== -1)
662 attachments_with_format
= calloc(count
, 2 * sizeof(unsigned int));
663 if (!attachments_with_format
) {
668 for (int i
= 0; i
< count
; ++i
) {
669 attachments_with_format
[2*i
] = attachments
[i
];
670 attachments_with_format
[2*i
+ 1] = dri2_wl_visuals
[visual_idx
].bpp
;
674 dri2_wl_get_buffers_with_format(driDrawable
,
676 attachments_with_format
, count
,
677 out_count
, loaderPrivate
);
679 free(attachments_with_format
);
685 image_get_buffers(__DRIdrawable
*driDrawable
,
689 uint32_t buffer_mask
,
690 struct __DRIimageList
*buffers
)
692 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
694 if (update_buffers(dri2_surf
) < 0)
697 buffers
->image_mask
= __DRI_IMAGE_BUFFER_BACK
;
698 buffers
->back
= dri2_surf
->back
->dri_image
;
704 dri2_wl_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
707 (void) loaderPrivate
;
710 static const __DRIdri2LoaderExtension dri2_loader_extension
= {
711 .base
= { __DRI_DRI2_LOADER
, 3 },
713 .getBuffers
= dri2_wl_get_buffers
,
714 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
715 .getBuffersWithFormat
= dri2_wl_get_buffers_with_format
,
718 static const __DRIimageLoaderExtension image_loader_extension
= {
719 .base
= { __DRI_IMAGE_LOADER
, 1 },
721 .getBuffers
= image_get_buffers
,
722 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
726 wayland_throttle_callback(void *data
,
727 struct wl_callback
*callback
,
730 struct dri2_egl_surface
*dri2_surf
= data
;
732 dri2_surf
->throttle_callback
= NULL
;
733 wl_callback_destroy(callback
);
736 static const struct wl_callback_listener throttle_listener
= {
737 .done
= wayland_throttle_callback
741 get_fourcc(struct dri2_egl_display
*dri2_dpy
,
742 __DRIimage
*image
, int *fourcc
)
748 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FOURCC
,
753 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
,
758 visual_idx
= dri2_wl_visual_idx_from_dri_image_format(dri_format
);
759 if (visual_idx
== -1)
762 *fourcc
= dri2_wl_visuals
[visual_idx
].wl_drm_format
;
766 static struct wl_buffer
*
767 create_wl_buffer(struct dri2_egl_display
*dri2_dpy
,
768 struct dri2_egl_surface
*dri2_surf
,
771 struct wl_buffer
*ret
;
773 int width
, height
, fourcc
, num_planes
;
774 uint64_t modifier
= DRM_FORMAT_MOD_INVALID
;
776 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_WIDTH
, &width
);
777 query
&= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_HEIGHT
,
779 query
&= get_fourcc(dri2_dpy
, image
, &fourcc
);
783 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NUM_PLANES
,
788 if (dri2_dpy
->image
->base
.version
>= 15) {
791 query
= dri2_dpy
->image
->queryImage(image
,
792 __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
,
794 query
&= dri2_dpy
->image
->queryImage(image
,
795 __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
,
798 modifier
= (uint64_t) mod_hi
<< 32;
799 modifier
|= (uint64_t) (mod_lo
& 0xffffffff);
803 if (dri2_dpy
->wl_dmabuf
&& modifier
!= DRM_FORMAT_MOD_INVALID
) {
804 struct zwp_linux_buffer_params_v1
*params
;
807 /* We don't need a wrapper for wl_dmabuf objects, because we have to
808 * create the intermediate params object; we can set the queue on this,
809 * and the wl_buffer inherits it race-free. */
810 params
= zwp_linux_dmabuf_v1_create_params(dri2_dpy
->wl_dmabuf
);
812 wl_proxy_set_queue((struct wl_proxy
*) params
, dri2_surf
->wl_queue
);
814 for (i
= 0; i
< num_planes
; i
++) {
819 p_image
= dri2_dpy
->image
->fromPlanar(image
, i
, NULL
);
825 query
= dri2_dpy
->image
->queryImage(p_image
,
826 __DRI_IMAGE_ATTRIB_FD
,
828 query
&= dri2_dpy
->image
->queryImage(p_image
,
829 __DRI_IMAGE_ATTRIB_STRIDE
,
831 query
&= dri2_dpy
->image
->queryImage(p_image
,
832 __DRI_IMAGE_ATTRIB_OFFSET
,
834 if (image
!= p_image
)
835 dri2_dpy
->image
->destroyImage(p_image
);
840 zwp_linux_buffer_params_v1_destroy(params
);
844 zwp_linux_buffer_params_v1_add(params
, fd
, i
, offset
, stride
,
845 modifier
>> 32, modifier
& 0xffffffff);
849 ret
= zwp_linux_buffer_params_v1_create_immed(params
, width
, height
,
851 zwp_linux_buffer_params_v1_destroy(params
);
852 } else if (dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
) {
853 struct wl_drm
*wl_drm
=
854 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
860 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FD
, &fd
);
861 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
862 ret
= wl_drm_create_prime_buffer(wl_drm
, fd
, width
, height
, fourcc
, 0,
866 struct wl_drm
*wl_drm
=
867 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
873 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
874 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
875 ret
= wl_drm_create_buffer(wl_drm
, name
, width
, height
, stride
, fourcc
);
882 try_damage_buffer(struct dri2_egl_surface
*dri2_surf
,
886 if (wl_proxy_get_version((struct wl_proxy
*) dri2_surf
->wl_surface_wrapper
)
887 < WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION
)
890 for (int i
= 0; i
< n_rects
; i
++) {
891 const int *rect
= &rects
[i
* 4];
893 wl_surface_damage_buffer(dri2_surf
->wl_surface_wrapper
,
895 dri2_surf
->base
.Height
- rect
[1] - rect
[3],
901 * Called via eglSwapBuffers(), drv->API.SwapBuffers().
904 dri2_wl_swap_buffers_with_damage(_EGLDriver
*drv
,
910 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
911 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
913 while (dri2_surf
->throttle_callback
!= NULL
)
914 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
915 dri2_surf
->wl_queue
) == -1)
918 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
919 if (dri2_surf
->color_buffers
[i
].age
> 0)
920 dri2_surf
->color_buffers
[i
].age
++;
922 /* Make sure we have a back buffer in case we're swapping without ever
924 if (get_back_bo(dri2_surf
) < 0)
925 return _eglError(EGL_BAD_ALLOC
, "dri2_swap_buffers");
927 if (draw
->SwapInterval
> 0) {
928 dri2_surf
->throttle_callback
=
929 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
930 wl_callback_add_listener(dri2_surf
->throttle_callback
,
931 &throttle_listener
, dri2_surf
);
934 dri2_surf
->back
->age
= 1;
935 dri2_surf
->current
= dri2_surf
->back
;
936 dri2_surf
->back
= NULL
;
938 if (!dri2_surf
->current
->wl_buffer
) {
941 if (dri2_dpy
->is_different_gpu
)
942 image
= dri2_surf
->current
->linear_copy
;
944 image
= dri2_surf
->current
->dri_image
;
946 dri2_surf
->current
->wl_buffer
=
947 create_wl_buffer(dri2_dpy
, dri2_surf
, image
);
949 wl_buffer_add_listener(dri2_surf
->current
->wl_buffer
,
950 &wl_buffer_listener
, dri2_surf
);
953 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
954 dri2_surf
->current
->wl_buffer
,
955 dri2_surf
->dx
, dri2_surf
->dy
);
957 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
958 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
959 /* reset resize growing parameters */
963 /* If the compositor doesn't support damage_buffer, we deliberately
964 * ignore the damage region and post maximum damage, due to
965 * https://bugs.freedesktop.org/78190 */
966 if (!n_rects
|| !try_damage_buffer(dri2_surf
, rects
, n_rects
))
967 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
968 0, 0, INT32_MAX
, INT32_MAX
);
970 if (dri2_dpy
->is_different_gpu
) {
971 _EGLContext
*ctx
= _eglGetCurrentContext();
972 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
973 dri2_dpy
->image
->blitImage(dri2_ctx
->dri_context
,
974 dri2_surf
->current
->linear_copy
,
975 dri2_surf
->current
->dri_image
,
976 0, 0, dri2_surf
->base
.Width
,
977 dri2_surf
->base
.Height
,
978 0, 0, dri2_surf
->base
.Width
,
979 dri2_surf
->base
.Height
, 0);
982 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
983 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
985 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
987 /* If we're not waiting for a frame callback then we'll at least throttle
988 * to a sync callback so that we always give a chance for the compositor to
989 * handle the commit and send a release event before checking for a free
991 if (dri2_surf
->throttle_callback
== NULL
) {
992 dri2_surf
->throttle_callback
= wl_display_sync(dri2_surf
->wl_dpy_wrapper
);
993 wl_callback_add_listener(dri2_surf
->throttle_callback
,
994 &throttle_listener
, dri2_surf
);
997 wl_display_flush(dri2_dpy
->wl_dpy
);
1003 dri2_wl_query_buffer_age(_EGLDriver
*drv
,
1004 _EGLDisplay
*disp
, _EGLSurface
*surface
)
1006 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
1008 if (get_back_bo(dri2_surf
) < 0) {
1009 _eglError(EGL_BAD_ALLOC
, "dri2_query_buffer_age");
1013 return dri2_surf
->back
->age
;
1017 dri2_wl_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1019 return dri2_wl_swap_buffers_with_damage(drv
, disp
, draw
, NULL
, 0);
1022 static struct wl_buffer
*
1023 dri2_wl_create_wayland_buffer_from_image(_EGLDriver
*drv
,
1027 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1028 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
1029 __DRIimage
*image
= dri2_img
->dri_image
;
1030 struct wl_buffer
*buffer
;
1031 int format
, visual_idx
;
1033 /* Check the upstream display supports this buffer's format. */
1034 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
, &format
);
1035 visual_idx
= dri2_wl_visual_idx_from_dri_image_format(format
);
1036 if (visual_idx
== -1)
1039 if (!(dri2_dpy
->formats
& (1 << visual_idx
)))
1042 buffer
= create_wl_buffer(dri2_dpy
, NULL
, image
);
1044 /* The buffer object will have been created with our internal event queue
1045 * because it is using wl_dmabuf/wl_drm as a proxy factory. We want the
1046 * buffer to be used by the application so we'll reset it to the display's
1047 * default event queue. This isn't actually racy, as the only event the
1048 * buffer can get is a buffer release, which doesn't happen with an explicit
1051 wl_proxy_set_queue((struct wl_proxy
*) buffer
, NULL
);
1056 _eglError(EGL_BAD_MATCH
, "unsupported image format");
1061 dri2_wl_authenticate(_EGLDisplay
*disp
, uint32_t id
)
1063 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1066 if (dri2_dpy
->is_render_node
) {
1067 _eglLog(_EGL_WARNING
, "wayland-egl: client asks server to "
1068 "authenticate for render-nodes");
1071 dri2_dpy
->authenticated
= false;
1073 wl_drm_authenticate(dri2_dpy
->wl_drm
, id
);
1074 if (roundtrip(dri2_dpy
) < 0)
1077 if (!dri2_dpy
->authenticated
)
1080 /* reset authenticated */
1081 dri2_dpy
->authenticated
= true;
1087 drm_handle_device(void *data
, struct wl_drm
*drm
, const char *device
)
1089 struct dri2_egl_display
*dri2_dpy
= data
;
1092 dri2_dpy
->device_name
= strdup(device
);
1093 if (!dri2_dpy
->device_name
)
1096 dri2_dpy
->fd
= loader_open_device(dri2_dpy
->device_name
);
1097 if (dri2_dpy
->fd
== -1) {
1098 _eglLog(_EGL_WARNING
, "wayland-egl: could not open %s (%s)",
1099 dri2_dpy
->device_name
, strerror(errno
));
1103 if (drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
) {
1104 dri2_dpy
->authenticated
= true;
1106 drmGetMagic(dri2_dpy
->fd
, &magic
);
1107 wl_drm_authenticate(dri2_dpy
->wl_drm
, magic
);
1112 drm_handle_format(void *data
, struct wl_drm
*drm
, uint32_t format
)
1114 struct dri2_egl_display
*dri2_dpy
= data
;
1115 int visual_idx
= dri2_wl_visual_idx_from_fourcc(format
);
1117 if (visual_idx
== -1)
1120 dri2_dpy
->formats
|= (1 << visual_idx
);
1124 drm_handle_capabilities(void *data
, struct wl_drm
*drm
, uint32_t value
)
1126 struct dri2_egl_display
*dri2_dpy
= data
;
1128 dri2_dpy
->capabilities
= value
;
1132 drm_handle_authenticated(void *data
, struct wl_drm
*drm
)
1134 struct dri2_egl_display
*dri2_dpy
= data
;
1136 dri2_dpy
->authenticated
= true;
1139 static const struct wl_drm_listener drm_listener
= {
1140 .device
= drm_handle_device
,
1141 .format
= drm_handle_format
,
1142 .authenticated
= drm_handle_authenticated
,
1143 .capabilities
= drm_handle_capabilities
1147 dmabuf_ignore_format(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1150 /* formats are implicitly advertised by the 'modifier' event, so ignore */
1154 dmabuf_handle_modifier(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1155 uint32_t format
, uint32_t modifier_hi
,
1156 uint32_t modifier_lo
)
1158 struct dri2_egl_display
*dri2_dpy
= data
;
1159 int visual_idx
= dri2_wl_visual_idx_from_fourcc(format
);
1162 if (visual_idx
== -1)
1165 if (modifier_hi
== (DRM_FORMAT_MOD_INVALID
>> 32) &&
1166 modifier_lo
== (DRM_FORMAT_MOD_INVALID
& 0xffffffff))
1169 dri2_dpy
->formats
|= (1 << visual_idx
);
1171 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
[visual_idx
]);
1172 *mod
= (uint64_t) modifier_hi
<< 32;
1173 *mod
|= (uint64_t) (modifier_lo
& 0xffffffff);
1176 static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener
= {
1177 .format
= dmabuf_ignore_format
,
1178 .modifier
= dmabuf_handle_modifier
,
1182 registry_handle_global_drm(void *data
, struct wl_registry
*registry
,
1183 uint32_t name
, const char *interface
,
1186 struct dri2_egl_display
*dri2_dpy
= data
;
1188 if (strcmp(interface
, "wl_drm") == 0) {
1190 wl_registry_bind(registry
, name
, &wl_drm_interface
, MIN2(version
, 2));
1191 wl_drm_add_listener(dri2_dpy
->wl_drm
, &drm_listener
, dri2_dpy
);
1192 } else if (strcmp(interface
, "zwp_linux_dmabuf_v1") == 0 && version
>= 3) {
1193 dri2_dpy
->wl_dmabuf
=
1194 wl_registry_bind(registry
, name
, &zwp_linux_dmabuf_v1_interface
,
1196 zwp_linux_dmabuf_v1_add_listener(dri2_dpy
->wl_dmabuf
, &dmabuf_listener
,
1202 registry_handle_global_remove(void *data
, struct wl_registry
*registry
,
1207 static const struct wl_registry_listener registry_listener_drm
= {
1208 .global
= registry_handle_global_drm
,
1209 .global_remove
= registry_handle_global_remove
1213 dri2_wl_setup_swap_interval(_EGLDisplay
*disp
)
1215 /* We can't use values greater than 1 on Wayland because we are using the
1216 * frame callback to synchronise the frame and the only way we be sure to
1217 * get a frame callback is to attach a new buffer. Therefore we can't just
1218 * sit drawing nothing to wait until the next ‘n’ frame callbacks */
1220 dri2_setup_swap_interval(disp
, 1);
1223 static const struct dri2_egl_display_vtbl dri2_wl_display_vtbl
= {
1224 .authenticate
= dri2_wl_authenticate
,
1225 .create_window_surface
= dri2_wl_create_window_surface
,
1226 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1227 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1228 .destroy_surface
= dri2_wl_destroy_surface
,
1229 .create_image
= dri2_create_image_khr
,
1230 .swap_buffers
= dri2_wl_swap_buffers
,
1231 .swap_buffers_with_damage
= dri2_wl_swap_buffers_with_damage
,
1232 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1233 .set_damage_region
= dri2_fallback_set_damage_region
,
1234 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1235 .copy_buffers
= dri2_fallback_copy_buffers
,
1236 .query_buffer_age
= dri2_wl_query_buffer_age
,
1237 .create_wayland_buffer_from_image
= dri2_wl_create_wayland_buffer_from_image
,
1238 .get_sync_values
= dri2_fallback_get_sync_values
,
1239 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1242 static const __DRIextension
*dri2_loader_extensions
[] = {
1243 &dri2_loader_extension
.base
,
1244 &image_loader_extension
.base
,
1245 &image_lookup_extension
.base
,
1246 &use_invalidate
.base
,
1250 static const __DRIextension
*image_loader_extensions
[] = {
1251 &image_loader_extension
.base
,
1252 &image_lookup_extension
.base
,
1253 &use_invalidate
.base
,
1258 dri2_wl_add_configs_for_visuals(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1260 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1261 unsigned int format_count
[ARRAY_SIZE(dri2_wl_visuals
)] = { 0 };
1262 unsigned int count
= 0;
1264 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
1265 for (unsigned j
= 0; j
< ARRAY_SIZE(dri2_wl_visuals
); j
++) {
1266 struct dri2_egl_config
*dri2_conf
;
1268 if (!(dri2_dpy
->formats
& (1 << j
)))
1271 dri2_conf
= dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
1272 count
+ 1, EGL_WINDOW_BIT
, NULL
, dri2_wl_visuals
[j
].rgba_masks
);
1274 if (dri2_conf
->base
.ConfigID
== count
+ 1)
1281 for (unsigned i
= 0; i
< ARRAY_SIZE(format_count
); i
++) {
1282 if (!format_count
[i
]) {
1283 _eglLog(_EGL_DEBUG
, "No DRI config supports native format %s",
1284 dri2_wl_visuals
[i
].format_name
);
1288 return (count
!= 0);
1292 dri2_initialize_wayland_drm(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1294 struct dri2_egl_display
*dri2_dpy
;
1296 loader_set_logger(_eglLog
);
1298 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1300 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1303 disp
->DriverData
= (void *) dri2_dpy
;
1304 if (disp
->PlatformDisplay
== NULL
) {
1305 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1306 if (dri2_dpy
->wl_dpy
== NULL
)
1308 dri2_dpy
->own_device
= true;
1310 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
1313 dri2_dpy
->wl_modifiers
=
1314 calloc(ARRAY_SIZE(dri2_wl_visuals
), sizeof(*dri2_dpy
->wl_modifiers
));
1315 if (!dri2_dpy
->wl_modifiers
)
1317 for (int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
1318 if (!u_vector_init(&dri2_dpy
->wl_modifiers
[i
], sizeof(uint64_t), 32))
1322 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
1324 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
1325 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
1328 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
1329 dri2_dpy
->wl_queue
);
1331 if (dri2_dpy
->own_device
)
1332 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
1334 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
1335 wl_registry_add_listener(dri2_dpy
->wl_registry
,
1336 ®istry_listener_drm
, dri2_dpy
);
1337 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_drm
== NULL
)
1340 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->fd
== -1)
1343 if (roundtrip(dri2_dpy
) < 0 || !dri2_dpy
->authenticated
)
1346 dri2_dpy
->fd
= loader_get_user_preferred_fd(dri2_dpy
->fd
,
1347 &dri2_dpy
->is_different_gpu
);
1348 if (dri2_dpy
->is_different_gpu
) {
1349 free(dri2_dpy
->device_name
);
1350 dri2_dpy
->device_name
= loader_get_device_name_for_fd(dri2_dpy
->fd
);
1351 if (!dri2_dpy
->device_name
) {
1352 _eglError(EGL_BAD_ALLOC
, "wayland-egl: failed to get device name "
1353 "for requested GPU");
1358 /* we have to do the check now, because loader_get_user_preferred_fd
1359 * will return a render-node when the requested gpu is different
1360 * to the server, but also if the client asks for the same gpu than
1361 * the server by requesting its pci-id */
1362 dri2_dpy
->is_render_node
= drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
;
1364 dri2_dpy
->driver_name
= loader_get_driver_for_fd(dri2_dpy
->fd
);
1365 if (dri2_dpy
->driver_name
== NULL
) {
1366 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to get driver name");
1370 /* render nodes cannot use Gem names, and thus do not support
1371 * the __DRI_DRI2_LOADER extension */
1372 if (!dri2_dpy
->is_render_node
) {
1373 dri2_dpy
->loader_extensions
= dri2_loader_extensions
;
1374 if (!dri2_load_driver(disp
)) {
1375 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to load driver");
1379 dri2_dpy
->loader_extensions
= image_loader_extensions
;
1380 if (!dri2_load_driver_dri3(disp
)) {
1381 _eglError(EGL_BAD_ALLOC
, "DRI3: failed to load driver");
1386 if (!dri2_create_screen(disp
))
1389 if (!dri2_setup_extensions(disp
))
1392 dri2_setup_screen(disp
);
1394 dri2_wl_setup_swap_interval(disp
);
1396 /* To use Prime, we must have _DRI_IMAGE v7 at least.
1397 * createImageFromFds support indicates that Prime export/import
1398 * is supported by the driver. Fall back to
1399 * gem names if we don't have Prime support. */
1401 if (dri2_dpy
->image
->base
.version
< 7 ||
1402 dri2_dpy
->image
->createImageFromFds
== NULL
)
1403 dri2_dpy
->capabilities
&= ~WL_DRM_CAPABILITY_PRIME
;
1405 /* We cannot use Gem names with render-nodes, only prime fds (dma-buf).
1406 * The server needs to accept them */
1407 if (dri2_dpy
->is_render_node
&&
1408 !(dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
)) {
1409 _eglLog(_EGL_WARNING
, "wayland-egl: display is not render-node capable");
1413 if (dri2_dpy
->is_different_gpu
&&
1414 (dri2_dpy
->image
->base
.version
< 9 ||
1415 dri2_dpy
->image
->blitImage
== NULL
)) {
1416 _eglLog(_EGL_WARNING
, "wayland-egl: Different GPU selected, but the "
1417 "Image extension in the driver is not "
1418 "compatible. Version 9 or later and blitImage() "
1423 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
1424 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
1428 dri2_set_WL_bind_wayland_display(drv
, disp
);
1429 /* When cannot convert EGLImage to wl_buffer when on a different gpu,
1430 * because the buffer of the EGLImage has likely a tiling mode the server
1431 * gpu won't support. These is no way to check for now. Thus do not support the
1433 if (!dri2_dpy
->is_different_gpu
)
1434 disp
->Extensions
.WL_create_wayland_buffer_from_image
= EGL_TRUE
;
1436 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
1438 disp
->Extensions
.EXT_swap_buffers_with_damage
= EGL_TRUE
;
1440 /* Fill vtbl last to prevent accidentally calling virtual function during
1443 dri2_dpy
->vtbl
= &dri2_wl_display_vtbl
;
1448 dri2_display_destroy(disp
);
1453 dri2_wl_swrast_get_stride_for_format(int format
, int w
)
1455 int visual_idx
= dri2_wl_visual_idx_from_shm_format(format
);
1457 assume(visual_idx
!= -1);
1459 return w
* (dri2_wl_visuals
[visual_idx
].bpp
/ 8);
1463 * Taken from weston shared/os-compatibility.c
1466 #ifndef HAVE_MKOSTEMP
1469 set_cloexec_or_close(int fd
)
1476 flags
= fcntl(fd
, F_GETFD
);
1480 if (fcntl(fd
, F_SETFD
, flags
| FD_CLOEXEC
) == -1)
1493 * Taken from weston shared/os-compatibility.c
1497 create_tmpfile_cloexec(char *tmpname
)
1501 #ifdef HAVE_MKOSTEMP
1502 fd
= mkostemp(tmpname
, O_CLOEXEC
);
1506 fd
= mkstemp(tmpname
);
1508 fd
= set_cloexec_or_close(fd
);
1517 * Taken from weston shared/os-compatibility.c
1519 * Create a new, unique, anonymous file of the given size, and
1520 * return the file descriptor for it. The file descriptor is set
1521 * CLOEXEC. The file is immediately suitable for mmap()'ing
1522 * the given size at offset zero.
1524 * The file should not have a permanent backing store like a disk,
1525 * but may have if XDG_RUNTIME_DIR is not properly implemented in OS.
1527 * The file name is deleted from the file system.
1529 * The file is suitable for buffer sharing between processes by
1530 * transmitting the file descriptor over Unix sockets using the
1531 * SCM_RIGHTS methods.
1533 * If the C library implements posix_fallocate(), it is used to
1534 * guarantee that disk space is available for the file at the
1535 * given size. If disk space is insufficent, errno is set to ENOSPC.
1536 * If posix_fallocate() is not supported, program may receive
1537 * SIGBUS on accessing mmap()'ed file contents instead.
1540 os_create_anonymous_file(off_t size
)
1542 static const char templ
[] = "/mesa-shared-XXXXXX";
1548 path
= getenv("XDG_RUNTIME_DIR");
1554 name
= malloc(strlen(path
) + sizeof(templ
));
1559 strcat(name
, templ
);
1561 fd
= create_tmpfile_cloexec(name
);
1568 ret
= ftruncate(fd
, size
);
1579 dri2_wl_swrast_allocate_buffer(struct dri2_egl_surface
*dri2_surf
,
1580 int format
, int w
, int h
,
1581 void **data
, int *size
,
1582 struct wl_buffer
**buffer
)
1584 struct dri2_egl_display
*dri2_dpy
=
1585 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1586 struct wl_shm_pool
*pool
;
1587 int fd
, stride
, size_map
;
1590 stride
= dri2_wl_swrast_get_stride_for_format(format
, w
);
1591 size_map
= h
* stride
;
1593 /* Create a sharable buffer */
1594 fd
= os_create_anonymous_file(size_map
);
1598 data_map
= mmap(NULL
, size_map
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
1599 if (data_map
== MAP_FAILED
) {
1604 /* Share it in a wl_buffer */
1605 pool
= wl_shm_create_pool(dri2_dpy
->wl_shm
, fd
, size_map
);
1606 wl_proxy_set_queue((struct wl_proxy
*)pool
, dri2_surf
->wl_queue
);
1607 *buffer
= wl_shm_pool_create_buffer(pool
, 0, w
, h
, stride
, format
);
1608 wl_shm_pool_destroy(pool
);
1617 swrast_update_buffers(struct dri2_egl_surface
*dri2_surf
)
1619 struct dri2_egl_display
*dri2_dpy
=
1620 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1622 /* we need to do the following operations only once per frame */
1623 if (dri2_surf
->back
)
1626 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->width
||
1627 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->height
) {
1629 dri2_wl_release_buffers(dri2_surf
);
1631 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
1632 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
1633 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
1634 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
1635 dri2_surf
->current
= NULL
;
1638 /* find back buffer */
1640 /* There might be a buffer release already queued that wasn't processed */
1641 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
1643 /* try get free buffer already created */
1644 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1645 if (!dri2_surf
->color_buffers
[i
].locked
&&
1646 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1647 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1652 /* else choose any another free location */
1653 if (!dri2_surf
->back
) {
1654 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1655 if (!dri2_surf
->color_buffers
[i
].locked
) {
1656 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1657 if (!dri2_wl_swrast_allocate_buffer(dri2_surf
,
1659 dri2_surf
->base
.Width
,
1660 dri2_surf
->base
.Height
,
1661 &dri2_surf
->back
->data
,
1662 &dri2_surf
->back
->data_size
,
1663 &dri2_surf
->back
->wl_buffer
)) {
1664 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
1667 wl_buffer_add_listener(dri2_surf
->back
->wl_buffer
,
1668 &wl_buffer_listener
, dri2_surf
);
1674 if (!dri2_surf
->back
) {
1675 _eglError(EGL_BAD_ALLOC
, "failed to find free buffer");
1679 dri2_surf
->back
->locked
= true;
1681 /* If we have an extra unlocked buffer at this point, we had to do triple
1682 * buffering for a while, but now can go back to just double buffering.
1683 * That means we can free any unlocked buffer now. */
1684 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1685 if (!dri2_surf
->color_buffers
[i
].locked
&&
1686 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1687 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
1688 munmap(dri2_surf
->color_buffers
[i
].data
,
1689 dri2_surf
->color_buffers
[i
].data_size
);
1690 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
1691 dri2_surf
->color_buffers
[i
].data
= NULL
;
1699 dri2_wl_swrast_get_frontbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1701 /* if there has been a resize: */
1702 if (!dri2_surf
->current
)
1705 return dri2_surf
->current
->data
;
1709 dri2_wl_swrast_get_backbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1711 assert(dri2_surf
->back
);
1712 return dri2_surf
->back
->data
;
1716 dri2_wl_swrast_commit_backbuffer(struct dri2_egl_surface
*dri2_surf
)
1718 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1720 while (dri2_surf
->throttle_callback
!= NULL
)
1721 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
1722 dri2_surf
->wl_queue
) == -1)
1725 if (dri2_surf
->base
.SwapInterval
> 0) {
1726 dri2_surf
->throttle_callback
=
1727 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
1728 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1729 &throttle_listener
, dri2_surf
);
1732 dri2_surf
->current
= dri2_surf
->back
;
1733 dri2_surf
->back
= NULL
;
1735 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
1736 dri2_surf
->current
->wl_buffer
,
1737 dri2_surf
->dx
, dri2_surf
->dy
);
1739 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
1740 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
1741 /* reset resize growing parameters */
1745 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
1746 0, 0, INT32_MAX
, INT32_MAX
);
1747 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
1749 /* If we're not waiting for a frame callback then we'll at least throttle
1750 * to a sync callback so that we always give a chance for the compositor to
1751 * handle the commit and send a release event before checking for a free
1753 if (dri2_surf
->throttle_callback
== NULL
) {
1754 dri2_surf
->throttle_callback
= wl_display_sync(dri2_dpy
->wl_dpy_wrapper
);
1755 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1756 &throttle_listener
, dri2_surf
);
1759 wl_display_flush(dri2_dpy
->wl_dpy
);
1763 dri2_wl_swrast_get_drawable_info(__DRIdrawable
* draw
,
1764 int *x
, int *y
, int *w
, int *h
,
1765 void *loaderPrivate
)
1767 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1769 (void) swrast_update_buffers(dri2_surf
);
1772 *w
= dri2_surf
->base
.Width
;
1773 *h
= dri2_surf
->base
.Height
;
1777 dri2_wl_swrast_get_image(__DRIdrawable
* read
,
1778 int x
, int y
, int w
, int h
,
1779 char *data
, void *loaderPrivate
)
1781 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1782 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1783 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1784 int src_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1785 int dst_stride
= copy_width
;
1788 src
= dri2_wl_swrast_get_frontbuffer_data(dri2_surf
);
1790 memset(data
, 0, copy_width
* h
);
1794 assert(data
!= src
);
1795 assert(copy_width
<= src_stride
);
1798 src
+= y
* src_stride
;
1801 if (copy_width
> src_stride
-x_offset
)
1802 copy_width
= src_stride
-x_offset
;
1803 if (h
> dri2_surf
->base
.Height
-y
)
1804 h
= dri2_surf
->base
.Height
-y
;
1807 memcpy(dst
, src
, copy_width
);
1814 dri2_wl_swrast_put_image2(__DRIdrawable
* draw
, int op
,
1815 int x
, int y
, int w
, int h
, int stride
,
1816 char *data
, void *loaderPrivate
)
1818 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1819 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1820 int dst_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1821 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1824 assert(copy_width
<= stride
);
1826 (void) swrast_update_buffers(dri2_surf
);
1827 dst
= dri2_wl_swrast_get_backbuffer_data(dri2_surf
);
1829 /* partial copy, copy old content */
1830 if (copy_width
< dst_stride
)
1831 dri2_wl_swrast_get_image(draw
, 0, 0,
1832 dri2_surf
->base
.Width
, dri2_surf
->base
.Height
,
1833 dst
, loaderPrivate
);
1836 dst
+= y
* dst_stride
;
1840 /* drivers expect we do these checks (and some rely on it) */
1841 if (copy_width
> dst_stride
-x_offset
)
1842 copy_width
= dst_stride
-x_offset
;
1843 if (h
> dri2_surf
->base
.Height
-y
)
1844 h
= dri2_surf
->base
.Height
-y
;
1847 memcpy(dst
, src
, copy_width
);
1851 dri2_wl_swrast_commit_backbuffer(dri2_surf
);
1855 dri2_wl_swrast_put_image(__DRIdrawable
* draw
, int op
,
1856 int x
, int y
, int w
, int h
,
1857 char *data
, void *loaderPrivate
)
1859 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1862 stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1863 dri2_wl_swrast_put_image2(draw
, op
, x
, y
, w
, h
,
1864 stride
, data
, loaderPrivate
);
1868 dri2_wl_swrast_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1870 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1871 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
1873 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
1878 shm_handle_format(void *data
, struct wl_shm
*shm
, uint32_t format
)
1880 struct dri2_egl_display
*dri2_dpy
= data
;
1881 int visual_idx
= dri2_wl_visual_idx_from_shm_format(format
);
1883 if (visual_idx
== -1)
1886 dri2_dpy
->formats
|= (1 << visual_idx
);
1889 static const struct wl_shm_listener shm_listener
= {
1890 .format
= shm_handle_format
1894 registry_handle_global_swrast(void *data
, struct wl_registry
*registry
,
1895 uint32_t name
, const char *interface
,
1898 struct dri2_egl_display
*dri2_dpy
= data
;
1900 if (strcmp(interface
, "wl_shm") == 0) {
1902 wl_registry_bind(registry
, name
, &wl_shm_interface
, 1);
1903 wl_shm_add_listener(dri2_dpy
->wl_shm
, &shm_listener
, dri2_dpy
);
1907 static const struct wl_registry_listener registry_listener_swrast
= {
1908 .global
= registry_handle_global_swrast
,
1909 .global_remove
= registry_handle_global_remove
1912 static const struct dri2_egl_display_vtbl dri2_wl_swrast_display_vtbl
= {
1913 .authenticate
= NULL
,
1914 .create_window_surface
= dri2_wl_create_window_surface
,
1915 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1916 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1917 .destroy_surface
= dri2_wl_destroy_surface
,
1918 .create_image
= dri2_create_image_khr
,
1919 .swap_buffers
= dri2_wl_swrast_swap_buffers
,
1920 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
1921 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1922 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1923 .copy_buffers
= dri2_fallback_copy_buffers
,
1924 .query_buffer_age
= dri2_fallback_query_buffer_age
,
1925 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
1926 .get_sync_values
= dri2_fallback_get_sync_values
,
1927 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1930 static const __DRIswrastLoaderExtension swrast_loader_extension
= {
1931 .base
= { __DRI_SWRAST_LOADER
, 2 },
1933 .getDrawableInfo
= dri2_wl_swrast_get_drawable_info
,
1934 .putImage
= dri2_wl_swrast_put_image
,
1935 .getImage
= dri2_wl_swrast_get_image
,
1936 .putImage2
= dri2_wl_swrast_put_image2
,
1939 static const __DRIextension
*swrast_loader_extensions
[] = {
1940 &swrast_loader_extension
.base
,
1941 &image_lookup_extension
.base
,
1946 dri2_initialize_wayland_swrast(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1948 struct dri2_egl_display
*dri2_dpy
;
1950 loader_set_logger(_eglLog
);
1952 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1954 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1957 disp
->DriverData
= (void *) dri2_dpy
;
1958 if (disp
->PlatformDisplay
== NULL
) {
1959 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1960 if (dri2_dpy
->wl_dpy
== NULL
)
1962 dri2_dpy
->own_device
= true;
1964 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
1967 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
1969 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
1970 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
1973 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
1974 dri2_dpy
->wl_queue
);
1976 if (dri2_dpy
->own_device
)
1977 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
1979 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
1980 wl_registry_add_listener(dri2_dpy
->wl_registry
,
1981 ®istry_listener_swrast
, dri2_dpy
);
1983 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_shm
== NULL
)
1986 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->formats
== 0)
1989 dri2_dpy
->driver_name
= strdup("swrast");
1990 if (!dri2_load_driver_swrast(disp
))
1993 dri2_dpy
->loader_extensions
= swrast_loader_extensions
;
1995 if (!dri2_create_screen(disp
))
1998 if (!dri2_setup_extensions(disp
))
2001 dri2_setup_screen(disp
);
2003 dri2_wl_setup_swap_interval(disp
);
2005 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
2006 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
2010 /* Fill vtbl last to prevent accidentally calling virtual function during
2013 dri2_dpy
->vtbl
= &dri2_wl_swrast_display_vtbl
;
2018 dri2_display_destroy(disp
);
2023 dri2_initialize_wayland(_EGLDriver
*drv
, _EGLDisplay
*disp
)
2025 EGLBoolean initialized
= EGL_FALSE
;
2027 if (!disp
->Options
.ForceSoftware
)
2028 initialized
= dri2_initialize_wayland_drm(drv
, disp
);
2031 initialized
= dri2_initialize_wayland_swrast(drv
, disp
);
2038 dri2_teardown_wayland(struct dri2_egl_display
*dri2_dpy
)
2040 if (dri2_dpy
->wl_drm
)
2041 wl_drm_destroy(dri2_dpy
->wl_drm
);
2042 if (dri2_dpy
->wl_dmabuf
)
2043 zwp_linux_dmabuf_v1_destroy(dri2_dpy
->wl_dmabuf
);
2044 if (dri2_dpy
->wl_shm
)
2045 wl_shm_destroy(dri2_dpy
->wl_shm
);
2046 if (dri2_dpy
->wl_registry
)
2047 wl_registry_destroy(dri2_dpy
->wl_registry
);
2048 if (dri2_dpy
->wl_queue
)
2049 wl_event_queue_destroy(dri2_dpy
->wl_queue
);
2050 if (dri2_dpy
->wl_dpy_wrapper
)
2051 wl_proxy_wrapper_destroy(dri2_dpy
->wl_dpy_wrapper
);
2053 for (int i
= 0; dri2_dpy
->wl_modifiers
&& i
< ARRAY_SIZE(dri2_wl_visuals
); i
++)
2054 u_vector_finish(&dri2_dpy
->wl_modifiers
[i
]);
2055 free(dri2_dpy
->wl_modifiers
);
2057 if (dri2_dpy
->own_device
)
2058 wl_display_disconnect(dri2_dpy
->wl_dpy
);