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-egl-backend.h>
49 #include <wayland-client.h>
50 #include "wayland-drm-client-protocol.h"
51 #include "linux-dmabuf-unstable-v1-client-protocol.h"
54 * The index of entries in this table is used as a bitmask in
55 * dri2_dpy->formats, which tracks the formats supported by our server.
57 static const struct dri2_wl_visual
{
58 const char *format_name
;
59 uint32_t wl_drm_format
;
60 uint32_t wl_shm_format
;
63 unsigned int rgba_masks
[4];
64 } dri2_wl_visuals
[] = {
67 WL_DRM_FORMAT_XRGB2101010
, WL_SHM_FORMAT_XRGB2101010
,
68 __DRI_IMAGE_FORMAT_XRGB2101010
, 32,
69 { 0x3ff00000, 0x000ffc00, 0x000003ff, 0x00000000 }
73 WL_DRM_FORMAT_ARGB2101010
, WL_SHM_FORMAT_ARGB2101010
,
74 __DRI_IMAGE_FORMAT_ARGB2101010
, 32,
75 { 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 }
79 WL_DRM_FORMAT_XRGB8888
, WL_SHM_FORMAT_XRGB8888
,
80 __DRI_IMAGE_FORMAT_XRGB8888
, 32,
81 { 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 }
85 WL_DRM_FORMAT_ARGB8888
, WL_SHM_FORMAT_ARGB8888
,
86 __DRI_IMAGE_FORMAT_ARGB8888
, 32,
87 { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }
91 WL_DRM_FORMAT_RGB565
, WL_SHM_FORMAT_RGB565
,
92 __DRI_IMAGE_FORMAT_RGB565
, 16,
93 { 0xf800, 0x07e0, 0x001f, 0x0000 }
98 dri2_wl_visual_idx_from_config(struct dri2_egl_display
*dri2_dpy
,
99 const __DRIconfig
*config
)
101 unsigned int red
, green
, blue
, alpha
;
103 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_RED_MASK
, &red
);
104 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_GREEN_MASK
, &green
);
105 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_BLUE_MASK
, &blue
);
106 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_ALPHA_MASK
, &alpha
);
108 for (unsigned int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
109 const struct dri2_wl_visual
*wl_visual
= &dri2_wl_visuals
[i
];
111 if (red
== wl_visual
->rgba_masks
[0] &&
112 green
== wl_visual
->rgba_masks
[1] &&
113 blue
== wl_visual
->rgba_masks
[2] &&
114 alpha
== wl_visual
->rgba_masks
[3]) {
123 dri2_wl_visual_idx_from_fourcc(uint32_t fourcc
)
125 for (int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
126 /* wl_drm format codes overlap with DRIImage FourCC codes for all formats
128 if (dri2_wl_visuals
[i
].wl_drm_format
== fourcc
)
136 dri2_wl_visual_idx_from_dri_image_format(uint32_t dri_image_format
)
138 for (int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
139 if (dri2_wl_visuals
[i
].dri_image_format
== dri_image_format
)
147 dri2_wl_visual_idx_from_shm_format(uint32_t shm_format
)
149 for (int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
150 if (dri2_wl_visuals
[i
].wl_shm_format
== shm_format
)
158 roundtrip(struct dri2_egl_display
*dri2_dpy
)
160 return wl_display_roundtrip_queue(dri2_dpy
->wl_dpy
, dri2_dpy
->wl_queue
);
164 wl_buffer_release(void *data
, struct wl_buffer
*buffer
)
166 struct dri2_egl_surface
*dri2_surf
= data
;
169 for (i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); ++i
)
170 if (dri2_surf
->color_buffers
[i
].wl_buffer
== buffer
)
173 if (i
== ARRAY_SIZE(dri2_surf
->color_buffers
)) {
174 wl_buffer_destroy(buffer
);
178 dri2_surf
->color_buffers
[i
].locked
= false;
181 static const struct wl_buffer_listener wl_buffer_listener
= {
182 .release
= wl_buffer_release
186 resize_callback(struct wl_egl_window
*wl_win
, void *data
)
188 struct dri2_egl_surface
*dri2_surf
= data
;
189 struct dri2_egl_display
*dri2_dpy
=
190 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
192 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
196 destroy_window_callback(void *data
)
198 struct dri2_egl_surface
*dri2_surf
= data
;
199 dri2_surf
->wl_win
= NULL
;
202 static struct wl_surface
*
203 get_wl_surface_proxy(struct wl_egl_window
*window
)
205 /* Version 3 of wl_egl_window introduced a version field at the same
206 * location where a pointer to wl_surface was stored. Thus, if
207 * window->version is dereferencable, we've been given an older version of
208 * wl_egl_window, and window->version points to wl_surface */
209 if (_eglPointerIsDereferencable((void *)(window
->version
))) {
210 return wl_proxy_create_wrapper((void *)(window
->version
));
212 return wl_proxy_create_wrapper(window
->surface
);
216 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
219 dri2_wl_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
220 _EGLConfig
*conf
, void *native_window
,
221 const EGLint
*attrib_list
)
223 __DRIcreateNewDrawableFunc createNewDrawable
;
224 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
225 struct dri2_egl_config
*dri2_conf
= dri2_egl_config(conf
);
226 struct wl_egl_window
*window
= native_window
;
227 struct dri2_egl_surface
*dri2_surf
;
229 const __DRIconfig
*config
;
231 dri2_surf
= calloc(1, sizeof *dri2_surf
);
233 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
237 if (!dri2_init_surface(&dri2_surf
->base
, disp
, EGL_WINDOW_BIT
, conf
,
241 config
= dri2_get_dri_config(dri2_conf
, EGL_WINDOW_BIT
,
242 dri2_surf
->base
.GLColorspace
);
245 _eglError(EGL_BAD_MATCH
, "Unsupported surfacetype/colorspace configuration");
249 visual_idx
= dri2_wl_visual_idx_from_config(dri2_dpy
, config
);
250 assert(visual_idx
!= -1);
252 if (dri2_dpy
->wl_dmabuf
|| dri2_dpy
->wl_drm
) {
253 dri2_surf
->format
= dri2_wl_visuals
[visual_idx
].wl_drm_format
;
255 assert(dri2_dpy
->wl_shm
);
256 dri2_surf
->format
= dri2_wl_visuals
[visual_idx
].wl_shm_format
;
259 dri2_surf
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
260 if (!dri2_surf
->wl_queue
) {
261 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
265 if (dri2_dpy
->wl_drm
) {
266 dri2_surf
->wl_drm_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_drm
);
267 if (!dri2_surf
->wl_drm_wrapper
) {
268 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
271 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_drm_wrapper
,
272 dri2_surf
->wl_queue
);
275 dri2_surf
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
276 if (!dri2_surf
->wl_dpy_wrapper
) {
277 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
280 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_dpy_wrapper
,
281 dri2_surf
->wl_queue
);
283 dri2_surf
->wl_surface_wrapper
= get_wl_surface_proxy(window
);
284 if (!dri2_surf
->wl_surface_wrapper
) {
285 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
286 goto cleanup_dpy_wrapper
;
288 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_surface_wrapper
,
289 dri2_surf
->wl_queue
);
291 dri2_surf
->wl_win
= window
;
292 dri2_surf
->wl_win
->driver_private
= dri2_surf
;
293 dri2_surf
->wl_win
->destroy_window_callback
= destroy_window_callback
;
295 dri2_surf
->wl_win
->resize_callback
= resize_callback
;
297 if (dri2_dpy
->image_driver
)
298 createNewDrawable
= dri2_dpy
->image_driver
->createNewDrawable
;
299 else if (dri2_dpy
->dri2
)
300 createNewDrawable
= dri2_dpy
->dri2
->createNewDrawable
;
302 createNewDrawable
= dri2_dpy
->swrast
->createNewDrawable
;
304 dri2_surf
->dri_drawable
= (*createNewDrawable
)(dri2_dpy
->dri_screen
, config
,
306 if (dri2_surf
->dri_drawable
== NULL
) {
307 _eglError(EGL_BAD_ALLOC
, "createNewDrawable");
308 goto cleanup_surf_wrapper
;
311 dri2_surf
->base
.SwapInterval
= dri2_dpy
->default_swap_interval
;
313 return &dri2_surf
->base
;
315 cleanup_surf_wrapper
:
316 wl_proxy_wrapper_destroy(dri2_surf
->wl_surface_wrapper
);
318 wl_proxy_wrapper_destroy(dri2_surf
->wl_dpy_wrapper
);
320 if (dri2_surf
->wl_drm_wrapper
)
321 wl_proxy_wrapper_destroy(dri2_surf
->wl_drm_wrapper
);
323 wl_event_queue_destroy(dri2_surf
->wl_queue
);
331 dri2_wl_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
332 _EGLConfig
*conf
, void *native_window
,
333 const EGLint
*attrib_list
)
335 /* From the EGL_EXT_platform_wayland spec, version 3:
337 * It is not valid to call eglCreatePlatformPixmapSurfaceEXT with a <dpy>
338 * that belongs to Wayland. Any such call fails and generates
341 _eglError(EGL_BAD_PARAMETER
, "cannot create EGL pixmap surfaces on "
347 * Called via eglDestroySurface(), drv->API.DestroySurface().
350 dri2_wl_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
352 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
353 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
357 dri2_dpy
->core
->destroyDrawable(dri2_surf
->dri_drawable
);
359 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
360 if (dri2_surf
->color_buffers
[i
].wl_buffer
)
361 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
362 if (dri2_surf
->color_buffers
[i
].dri_image
)
363 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
364 if (dri2_surf
->color_buffers
[i
].linear_copy
)
365 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
366 if (dri2_surf
->color_buffers
[i
].data
)
367 munmap(dri2_surf
->color_buffers
[i
].data
,
368 dri2_surf
->color_buffers
[i
].data_size
);
372 dri2_egl_surface_free_local_buffers(dri2_surf
);
374 if (dri2_surf
->throttle_callback
)
375 wl_callback_destroy(dri2_surf
->throttle_callback
);
377 if (dri2_surf
->wl_win
) {
378 dri2_surf
->wl_win
->driver_private
= NULL
;
379 dri2_surf
->wl_win
->resize_callback
= NULL
;
380 dri2_surf
->wl_win
->destroy_window_callback
= NULL
;
383 wl_proxy_wrapper_destroy(dri2_surf
->wl_surface_wrapper
);
384 wl_proxy_wrapper_destroy(dri2_surf
->wl_dpy_wrapper
);
385 if (dri2_surf
->wl_drm_wrapper
)
386 wl_proxy_wrapper_destroy(dri2_surf
->wl_drm_wrapper
);
387 wl_event_queue_destroy(dri2_surf
->wl_queue
);
389 dri2_fini_surface(surf
);
396 dri2_wl_release_buffers(struct dri2_egl_surface
*dri2_surf
)
398 struct dri2_egl_display
*dri2_dpy
=
399 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
401 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
402 if (dri2_surf
->color_buffers
[i
].wl_buffer
&&
403 !dri2_surf
->color_buffers
[i
].locked
)
404 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
405 if (dri2_surf
->color_buffers
[i
].dri_image
)
406 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
407 if (dri2_surf
->color_buffers
[i
].linear_copy
)
408 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
409 if (dri2_surf
->color_buffers
[i
].data
)
410 munmap(dri2_surf
->color_buffers
[i
].data
,
411 dri2_surf
->color_buffers
[i
].data_size
);
413 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
414 dri2_surf
->color_buffers
[i
].dri_image
= NULL
;
415 dri2_surf
->color_buffers
[i
].linear_copy
= NULL
;
416 dri2_surf
->color_buffers
[i
].data
= NULL
;
417 dri2_surf
->color_buffers
[i
].locked
= false;
421 dri2_egl_surface_free_local_buffers(dri2_surf
);
425 get_back_bo(struct dri2_egl_surface
*dri2_surf
)
427 struct dri2_egl_display
*dri2_dpy
=
428 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
431 unsigned int dri_image_format
;
435 visual_idx
= dri2_wl_visual_idx_from_fourcc(dri2_surf
->format
);
436 assert(visual_idx
!= -1);
437 dri_image_format
= dri2_wl_visuals
[visual_idx
].dri_image_format
;
438 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
[visual_idx
]);
439 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
[visual_idx
]);
441 /* There might be a buffer release already queued that wasn't processed */
442 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
444 while (dri2_surf
->back
== NULL
) {
445 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
446 /* Get an unlocked buffer, preferrably one with a dri_buffer
447 * already allocated. */
448 if (dri2_surf
->color_buffers
[i
].locked
)
450 if (dri2_surf
->back
== NULL
)
451 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
452 else if (dri2_surf
->back
->dri_image
== NULL
)
453 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
459 /* If we don't have a buffer, then block on the server to release one for
460 * us, and try again. wl_display_dispatch_queue will process any pending
461 * events, however not all servers flush on issuing a buffer release
462 * event. So, we spam the server with roundtrips as they always cause a
465 if (wl_display_roundtrip_queue(dri2_dpy
->wl_dpy
,
466 dri2_surf
->wl_queue
) < 0)
470 if (dri2_surf
->back
== NULL
)
473 use_flags
= __DRI_IMAGE_USE_SHARE
| __DRI_IMAGE_USE_BACKBUFFER
;
475 if (dri2_dpy
->is_different_gpu
&&
476 dri2_surf
->back
->linear_copy
== NULL
) {
477 /* The LINEAR modifier should be a perfect alias of the LINEAR use
478 * flag; try the new interface first before the old, then fall back. */
479 if (dri2_dpy
->image
->base
.version
>= 15 &&
480 dri2_dpy
->image
->createImageWithModifiers
) {
481 uint64_t linear_mod
= DRM_FORMAT_MOD_LINEAR
;
483 dri2_surf
->back
->linear_copy
=
484 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
485 dri2_surf
->base
.Width
,
486 dri2_surf
->base
.Height
,
492 dri2_surf
->back
->linear_copy
=
493 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
494 dri2_surf
->base
.Width
,
495 dri2_surf
->base
.Height
,
498 __DRI_IMAGE_USE_LINEAR
,
501 if (dri2_surf
->back
->linear_copy
== NULL
)
505 if (dri2_surf
->back
->dri_image
== NULL
) {
506 /* If our DRIImage implementation does not support
507 * createImageWithModifiers, then fall back to the old createImage,
508 * and hope it allocates an image which is acceptable to the winsys.
510 if (num_modifiers
&& dri2_dpy
->image
->base
.version
>= 15 &&
511 dri2_dpy
->image
->createImageWithModifiers
) {
512 dri2_surf
->back
->dri_image
=
513 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
514 dri2_surf
->base
.Width
,
515 dri2_surf
->base
.Height
,
521 dri2_surf
->back
->dri_image
=
522 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
523 dri2_surf
->base
.Width
,
524 dri2_surf
->base
.Height
,
526 dri2_dpy
->is_different_gpu
?
531 dri2_surf
->back
->age
= 0;
533 if (dri2_surf
->back
->dri_image
== NULL
)
536 dri2_surf
->back
->locked
= true;
543 back_bo_to_dri_buffer(struct dri2_egl_surface
*dri2_surf
, __DRIbuffer
*buffer
)
545 struct dri2_egl_display
*dri2_dpy
=
546 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
550 image
= dri2_surf
->back
->dri_image
;
552 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
553 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &pitch
);
555 buffer
->attachment
= __DRI_BUFFER_BACK_LEFT
;
557 buffer
->pitch
= pitch
;
563 update_buffers(struct dri2_egl_surface
*dri2_surf
)
565 struct dri2_egl_display
*dri2_dpy
=
566 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
568 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->width
||
569 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->height
) {
571 dri2_wl_release_buffers(dri2_surf
);
573 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
574 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
575 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
576 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
579 if (get_back_bo(dri2_surf
) < 0) {
580 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
584 /* If we have an extra unlocked buffer at this point, we had to do triple
585 * buffering for a while, but now can go back to just double buffering.
586 * That means we can free any unlocked buffer now. */
587 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
588 if (!dri2_surf
->color_buffers
[i
].locked
&&
589 dri2_surf
->color_buffers
[i
].wl_buffer
) {
590 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
591 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
592 if (dri2_dpy
->is_different_gpu
)
593 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
594 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
595 dri2_surf
->color_buffers
[i
].dri_image
= NULL
;
596 dri2_surf
->color_buffers
[i
].linear_copy
= NULL
;
604 dri2_wl_get_buffers_with_format(__DRIdrawable
* driDrawable
,
605 int *width
, int *height
,
606 unsigned int *attachments
, int count
,
607 int *out_count
, void *loaderPrivate
)
609 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
612 if (update_buffers(dri2_surf
) < 0)
615 for (i
= 0, j
= 0; i
< 2 * count
; i
+= 2, j
++) {
618 switch (attachments
[i
]) {
619 case __DRI_BUFFER_BACK_LEFT
:
620 back_bo_to_dri_buffer(dri2_surf
, &dri2_surf
->buffers
[j
]);
623 local
= dri2_egl_surface_alloc_local_buffer(dri2_surf
, attachments
[i
],
627 _eglError(EGL_BAD_ALLOC
, "failed to allocate local buffer");
630 dri2_surf
->buffers
[j
] = *local
;
639 *width
= dri2_surf
->base
.Width
;
640 *height
= dri2_surf
->base
.Height
;
642 return dri2_surf
->buffers
;
646 dri2_wl_get_buffers(__DRIdrawable
* driDrawable
,
647 int *width
, int *height
,
648 unsigned int *attachments
, int count
,
649 int *out_count
, void *loaderPrivate
)
651 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
652 unsigned int *attachments_with_format
;
654 int visual_idx
= dri2_wl_visual_idx_from_fourcc(dri2_surf
->format
);
656 if (visual_idx
== -1)
659 attachments_with_format
= calloc(count
, 2 * sizeof(unsigned int));
660 if (!attachments_with_format
) {
665 for (int i
= 0; i
< count
; ++i
) {
666 attachments_with_format
[2*i
] = attachments
[i
];
667 attachments_with_format
[2*i
+ 1] = dri2_wl_visuals
[visual_idx
].bpp
;
671 dri2_wl_get_buffers_with_format(driDrawable
,
673 attachments_with_format
, count
,
674 out_count
, loaderPrivate
);
676 free(attachments_with_format
);
682 image_get_buffers(__DRIdrawable
*driDrawable
,
686 uint32_t buffer_mask
,
687 struct __DRIimageList
*buffers
)
689 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
691 if (update_buffers(dri2_surf
) < 0)
694 buffers
->image_mask
= __DRI_IMAGE_BUFFER_BACK
;
695 buffers
->back
= dri2_surf
->back
->dri_image
;
701 dri2_wl_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
704 (void) loaderPrivate
;
707 static const __DRIdri2LoaderExtension dri2_loader_extension
= {
708 .base
= { __DRI_DRI2_LOADER
, 3 },
710 .getBuffers
= dri2_wl_get_buffers
,
711 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
712 .getBuffersWithFormat
= dri2_wl_get_buffers_with_format
,
715 static const __DRIimageLoaderExtension image_loader_extension
= {
716 .base
= { __DRI_IMAGE_LOADER
, 1 },
718 .getBuffers
= image_get_buffers
,
719 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
723 wayland_throttle_callback(void *data
,
724 struct wl_callback
*callback
,
727 struct dri2_egl_surface
*dri2_surf
= data
;
729 dri2_surf
->throttle_callback
= NULL
;
730 wl_callback_destroy(callback
);
733 static const struct wl_callback_listener throttle_listener
= {
734 .done
= wayland_throttle_callback
738 get_fourcc(struct dri2_egl_display
*dri2_dpy
,
739 __DRIimage
*image
, int *fourcc
)
745 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FOURCC
,
750 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
,
755 visual_idx
= dri2_wl_visual_idx_from_dri_image_format(dri_format
);
756 if (visual_idx
== -1)
759 *fourcc
= dri2_wl_visuals
[visual_idx
].wl_drm_format
;
763 static struct wl_buffer
*
764 create_wl_buffer(struct dri2_egl_display
*dri2_dpy
,
765 struct dri2_egl_surface
*dri2_surf
,
768 struct wl_buffer
*ret
;
770 int width
, height
, fourcc
, num_planes
;
771 uint64_t modifier
= DRM_FORMAT_MOD_INVALID
;
773 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_WIDTH
, &width
);
774 query
&= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_HEIGHT
,
776 query
&= get_fourcc(dri2_dpy
, image
, &fourcc
);
780 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NUM_PLANES
,
785 if (dri2_dpy
->image
->base
.version
>= 15) {
788 query
= dri2_dpy
->image
->queryImage(image
,
789 __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
,
791 query
&= dri2_dpy
->image
->queryImage(image
,
792 __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
,
795 modifier
= (uint64_t) mod_hi
<< 32;
796 modifier
|= (uint64_t) (mod_lo
& 0xffffffff);
800 if (dri2_dpy
->wl_dmabuf
&& modifier
!= DRM_FORMAT_MOD_INVALID
) {
801 struct zwp_linux_buffer_params_v1
*params
;
804 /* We don't need a wrapper for wl_dmabuf objects, because we have to
805 * create the intermediate params object; we can set the queue on this,
806 * and the wl_buffer inherits it race-free. */
807 params
= zwp_linux_dmabuf_v1_create_params(dri2_dpy
->wl_dmabuf
);
809 wl_proxy_set_queue((struct wl_proxy
*) params
, dri2_surf
->wl_queue
);
811 for (i
= 0; i
< num_planes
; i
++) {
816 p_image
= dri2_dpy
->image
->fromPlanar(image
, i
, NULL
);
822 query
= dri2_dpy
->image
->queryImage(p_image
,
823 __DRI_IMAGE_ATTRIB_FD
,
825 query
&= dri2_dpy
->image
->queryImage(p_image
,
826 __DRI_IMAGE_ATTRIB_STRIDE
,
828 query
&= dri2_dpy
->image
->queryImage(p_image
,
829 __DRI_IMAGE_ATTRIB_OFFSET
,
831 if (image
!= p_image
)
832 dri2_dpy
->image
->destroyImage(p_image
);
837 zwp_linux_buffer_params_v1_destroy(params
);
841 zwp_linux_buffer_params_v1_add(params
, fd
, i
, offset
, stride
,
842 modifier
>> 32, modifier
& 0xffffffff);
846 ret
= zwp_linux_buffer_params_v1_create_immed(params
, width
, height
,
848 zwp_linux_buffer_params_v1_destroy(params
);
849 } else if (dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
) {
850 struct wl_drm
*wl_drm
=
851 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
857 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FD
, &fd
);
858 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
859 ret
= wl_drm_create_prime_buffer(wl_drm
, fd
, width
, height
, fourcc
, 0,
863 struct wl_drm
*wl_drm
=
864 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
870 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
871 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
872 ret
= wl_drm_create_buffer(wl_drm
, name
, width
, height
, stride
, fourcc
);
879 try_damage_buffer(struct dri2_egl_surface
*dri2_surf
,
883 if (wl_proxy_get_version((struct wl_proxy
*) dri2_surf
->wl_surface_wrapper
)
884 < WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION
)
887 for (int i
= 0; i
< n_rects
; i
++) {
888 const int *rect
= &rects
[i
* 4];
890 wl_surface_damage_buffer(dri2_surf
->wl_surface_wrapper
,
892 dri2_surf
->base
.Height
- rect
[1] - rect
[3],
898 * Called via eglSwapBuffers(), drv->API.SwapBuffers().
901 dri2_wl_swap_buffers_with_damage(_EGLDriver
*drv
,
907 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
908 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
910 while (dri2_surf
->throttle_callback
!= NULL
)
911 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
912 dri2_surf
->wl_queue
) == -1)
915 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
916 if (dri2_surf
->color_buffers
[i
].age
> 0)
917 dri2_surf
->color_buffers
[i
].age
++;
919 /* Make sure we have a back buffer in case we're swapping without ever
921 if (get_back_bo(dri2_surf
) < 0)
922 return _eglError(EGL_BAD_ALLOC
, "dri2_swap_buffers");
924 if (draw
->SwapInterval
> 0) {
925 dri2_surf
->throttle_callback
=
926 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
927 wl_callback_add_listener(dri2_surf
->throttle_callback
,
928 &throttle_listener
, dri2_surf
);
931 dri2_surf
->back
->age
= 1;
932 dri2_surf
->current
= dri2_surf
->back
;
933 dri2_surf
->back
= NULL
;
935 if (!dri2_surf
->current
->wl_buffer
) {
938 if (dri2_dpy
->is_different_gpu
)
939 image
= dri2_surf
->current
->linear_copy
;
941 image
= dri2_surf
->current
->dri_image
;
943 dri2_surf
->current
->wl_buffer
=
944 create_wl_buffer(dri2_dpy
, dri2_surf
, image
);
946 wl_buffer_add_listener(dri2_surf
->current
->wl_buffer
,
947 &wl_buffer_listener
, dri2_surf
);
950 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
951 dri2_surf
->current
->wl_buffer
,
952 dri2_surf
->dx
, dri2_surf
->dy
);
954 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
955 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
956 /* reset resize growing parameters */
960 /* If the compositor doesn't support damage_buffer, we deliberately
961 * ignore the damage region and post maximum damage, due to
962 * https://bugs.freedesktop.org/78190 */
963 if (!n_rects
|| !try_damage_buffer(dri2_surf
, rects
, n_rects
))
964 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
965 0, 0, INT32_MAX
, INT32_MAX
);
967 if (dri2_dpy
->is_different_gpu
) {
968 _EGLContext
*ctx
= _eglGetCurrentContext();
969 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
970 dri2_dpy
->image
->blitImage(dri2_ctx
->dri_context
,
971 dri2_surf
->current
->linear_copy
,
972 dri2_surf
->current
->dri_image
,
973 0, 0, dri2_surf
->base
.Width
,
974 dri2_surf
->base
.Height
,
975 0, 0, dri2_surf
->base
.Width
,
976 dri2_surf
->base
.Height
, 0);
979 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
980 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
982 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
984 /* If we're not waiting for a frame callback then we'll at least throttle
985 * to a sync callback so that we always give a chance for the compositor to
986 * handle the commit and send a release event before checking for a free
988 if (dri2_surf
->throttle_callback
== NULL
) {
989 dri2_surf
->throttle_callback
= wl_display_sync(dri2_surf
->wl_dpy_wrapper
);
990 wl_callback_add_listener(dri2_surf
->throttle_callback
,
991 &throttle_listener
, dri2_surf
);
994 wl_display_flush(dri2_dpy
->wl_dpy
);
1000 dri2_wl_query_buffer_age(_EGLDriver
*drv
,
1001 _EGLDisplay
*disp
, _EGLSurface
*surface
)
1003 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
1005 if (get_back_bo(dri2_surf
) < 0) {
1006 _eglError(EGL_BAD_ALLOC
, "dri2_query_buffer_age");
1010 return dri2_surf
->back
->age
;
1014 dri2_wl_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1016 return dri2_wl_swap_buffers_with_damage(drv
, disp
, draw
, NULL
, 0);
1019 static struct wl_buffer
*
1020 dri2_wl_create_wayland_buffer_from_image(_EGLDriver
*drv
,
1024 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1025 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
1026 __DRIimage
*image
= dri2_img
->dri_image
;
1027 struct wl_buffer
*buffer
;
1028 int format
, visual_idx
;
1030 /* Check the upstream display supports this buffer's format. */
1031 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
, &format
);
1032 visual_idx
= dri2_wl_visual_idx_from_dri_image_format(format
);
1033 if (visual_idx
== -1)
1036 if (!(dri2_dpy
->formats
& (1 << visual_idx
)))
1039 buffer
= create_wl_buffer(dri2_dpy
, NULL
, image
);
1041 /* The buffer object will have been created with our internal event queue
1042 * because it is using wl_dmabuf/wl_drm as a proxy factory. We want the
1043 * buffer to be used by the application so we'll reset it to the display's
1044 * default event queue. This isn't actually racy, as the only event the
1045 * buffer can get is a buffer release, which doesn't happen with an explicit
1048 wl_proxy_set_queue((struct wl_proxy
*) buffer
, NULL
);
1053 _eglError(EGL_BAD_MATCH
, "unsupported image format");
1058 dri2_wl_authenticate(_EGLDisplay
*disp
, uint32_t id
)
1060 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1063 if (dri2_dpy
->is_render_node
) {
1064 _eglLog(_EGL_WARNING
, "wayland-egl: client asks server to "
1065 "authenticate for render-nodes");
1068 dri2_dpy
->authenticated
= false;
1070 wl_drm_authenticate(dri2_dpy
->wl_drm
, id
);
1071 if (roundtrip(dri2_dpy
) < 0)
1074 if (!dri2_dpy
->authenticated
)
1077 /* reset authenticated */
1078 dri2_dpy
->authenticated
= true;
1084 drm_handle_device(void *data
, struct wl_drm
*drm
, const char *device
)
1086 struct dri2_egl_display
*dri2_dpy
= data
;
1089 dri2_dpy
->device_name
= strdup(device
);
1090 if (!dri2_dpy
->device_name
)
1093 dri2_dpy
->fd
= loader_open_device(dri2_dpy
->device_name
);
1094 if (dri2_dpy
->fd
== -1) {
1095 _eglLog(_EGL_WARNING
, "wayland-egl: could not open %s (%s)",
1096 dri2_dpy
->device_name
, strerror(errno
));
1100 if (drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
) {
1101 dri2_dpy
->authenticated
= true;
1103 drmGetMagic(dri2_dpy
->fd
, &magic
);
1104 wl_drm_authenticate(dri2_dpy
->wl_drm
, magic
);
1109 drm_handle_format(void *data
, struct wl_drm
*drm
, uint32_t format
)
1111 struct dri2_egl_display
*dri2_dpy
= data
;
1112 int visual_idx
= dri2_wl_visual_idx_from_fourcc(format
);
1114 if (visual_idx
== -1)
1117 dri2_dpy
->formats
|= (1 << visual_idx
);
1121 drm_handle_capabilities(void *data
, struct wl_drm
*drm
, uint32_t value
)
1123 struct dri2_egl_display
*dri2_dpy
= data
;
1125 dri2_dpy
->capabilities
= value
;
1129 drm_handle_authenticated(void *data
, struct wl_drm
*drm
)
1131 struct dri2_egl_display
*dri2_dpy
= data
;
1133 dri2_dpy
->authenticated
= true;
1136 static const struct wl_drm_listener drm_listener
= {
1137 .device
= drm_handle_device
,
1138 .format
= drm_handle_format
,
1139 .authenticated
= drm_handle_authenticated
,
1140 .capabilities
= drm_handle_capabilities
1144 dmabuf_ignore_format(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1147 /* formats are implicitly advertised by the 'modifier' event, so ignore */
1151 dmabuf_handle_modifier(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1152 uint32_t format
, uint32_t modifier_hi
,
1153 uint32_t modifier_lo
)
1155 struct dri2_egl_display
*dri2_dpy
= data
;
1156 int visual_idx
= dri2_wl_visual_idx_from_fourcc(format
);
1159 if (visual_idx
== -1)
1162 if (modifier_hi
== (DRM_FORMAT_MOD_INVALID
>> 32) &&
1163 modifier_lo
== (DRM_FORMAT_MOD_INVALID
& 0xffffffff))
1166 dri2_dpy
->formats
|= (1 << visual_idx
);
1168 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
[visual_idx
]);
1169 *mod
= (uint64_t) modifier_hi
<< 32;
1170 *mod
|= (uint64_t) (modifier_lo
& 0xffffffff);
1173 static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener
= {
1174 .format
= dmabuf_ignore_format
,
1175 .modifier
= dmabuf_handle_modifier
,
1179 registry_handle_global_drm(void *data
, struct wl_registry
*registry
,
1180 uint32_t name
, const char *interface
,
1183 struct dri2_egl_display
*dri2_dpy
= data
;
1185 if (strcmp(interface
, "wl_drm") == 0) {
1187 wl_registry_bind(registry
, name
, &wl_drm_interface
, MIN2(version
, 2));
1188 wl_drm_add_listener(dri2_dpy
->wl_drm
, &drm_listener
, dri2_dpy
);
1189 } else if (strcmp(interface
, "zwp_linux_dmabuf_v1") == 0 && version
>= 3) {
1190 dri2_dpy
->wl_dmabuf
=
1191 wl_registry_bind(registry
, name
, &zwp_linux_dmabuf_v1_interface
,
1193 zwp_linux_dmabuf_v1_add_listener(dri2_dpy
->wl_dmabuf
, &dmabuf_listener
,
1199 registry_handle_global_remove(void *data
, struct wl_registry
*registry
,
1204 static const struct wl_registry_listener registry_listener_drm
= {
1205 .global
= registry_handle_global_drm
,
1206 .global_remove
= registry_handle_global_remove
1210 dri2_wl_setup_swap_interval(_EGLDisplay
*disp
)
1212 /* We can't use values greater than 1 on Wayland because we are using the
1213 * frame callback to synchronise the frame and the only way we be sure to
1214 * get a frame callback is to attach a new buffer. Therefore we can't just
1215 * sit drawing nothing to wait until the next ‘n’ frame callbacks */
1217 dri2_setup_swap_interval(disp
, 1);
1220 static const struct dri2_egl_display_vtbl dri2_wl_display_vtbl
= {
1221 .authenticate
= dri2_wl_authenticate
,
1222 .create_window_surface
= dri2_wl_create_window_surface
,
1223 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1224 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1225 .destroy_surface
= dri2_wl_destroy_surface
,
1226 .create_image
= dri2_create_image_khr
,
1227 .swap_buffers
= dri2_wl_swap_buffers
,
1228 .swap_buffers_with_damage
= dri2_wl_swap_buffers_with_damage
,
1229 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1230 .set_damage_region
= dri2_fallback_set_damage_region
,
1231 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1232 .copy_buffers
= dri2_fallback_copy_buffers
,
1233 .query_buffer_age
= dri2_wl_query_buffer_age
,
1234 .create_wayland_buffer_from_image
= dri2_wl_create_wayland_buffer_from_image
,
1235 .get_sync_values
= dri2_fallback_get_sync_values
,
1236 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1239 static const __DRIextension
*dri2_loader_extensions
[] = {
1240 &dri2_loader_extension
.base
,
1241 &image_loader_extension
.base
,
1242 &image_lookup_extension
.base
,
1243 &use_invalidate
.base
,
1247 static const __DRIextension
*image_loader_extensions
[] = {
1248 &image_loader_extension
.base
,
1249 &image_lookup_extension
.base
,
1250 &use_invalidate
.base
,
1255 dri2_wl_add_configs_for_visuals(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1257 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1258 unsigned int format_count
[ARRAY_SIZE(dri2_wl_visuals
)] = { 0 };
1259 unsigned int count
= 0;
1261 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
1262 for (unsigned j
= 0; j
< ARRAY_SIZE(dri2_wl_visuals
); j
++) {
1263 struct dri2_egl_config
*dri2_conf
;
1265 if (!(dri2_dpy
->formats
& (1 << j
)))
1268 dri2_conf
= dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
1269 count
+ 1, EGL_WINDOW_BIT
, NULL
, dri2_wl_visuals
[j
].rgba_masks
);
1271 if (dri2_conf
->base
.ConfigID
== count
+ 1)
1278 for (unsigned i
= 0; i
< ARRAY_SIZE(format_count
); i
++) {
1279 if (!format_count
[i
]) {
1280 _eglLog(_EGL_DEBUG
, "No DRI config supports native format %s",
1281 dri2_wl_visuals
[i
].format_name
);
1285 return (count
!= 0);
1289 dri2_initialize_wayland_drm(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1291 struct dri2_egl_display
*dri2_dpy
;
1293 loader_set_logger(_eglLog
);
1295 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1297 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1300 disp
->DriverData
= (void *) dri2_dpy
;
1301 if (disp
->PlatformDisplay
== NULL
) {
1302 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1303 if (dri2_dpy
->wl_dpy
== NULL
)
1305 dri2_dpy
->own_device
= true;
1307 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
1310 dri2_dpy
->wl_modifiers
=
1311 calloc(ARRAY_SIZE(dri2_wl_visuals
), sizeof(*dri2_dpy
->wl_modifiers
));
1312 if (!dri2_dpy
->wl_modifiers
)
1314 for (int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
1315 if (!u_vector_init(&dri2_dpy
->wl_modifiers
[i
], sizeof(uint64_t), 32))
1319 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
1321 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
1322 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
1325 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
1326 dri2_dpy
->wl_queue
);
1328 if (dri2_dpy
->own_device
)
1329 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
1331 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
1332 wl_registry_add_listener(dri2_dpy
->wl_registry
,
1333 ®istry_listener_drm
, dri2_dpy
);
1334 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_drm
== NULL
)
1337 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->fd
== -1)
1340 if (roundtrip(dri2_dpy
) < 0 || !dri2_dpy
->authenticated
)
1343 dri2_dpy
->fd
= loader_get_user_preferred_fd(dri2_dpy
->fd
,
1344 &dri2_dpy
->is_different_gpu
);
1345 if (dri2_dpy
->is_different_gpu
) {
1346 free(dri2_dpy
->device_name
);
1347 dri2_dpy
->device_name
= loader_get_device_name_for_fd(dri2_dpy
->fd
);
1348 if (!dri2_dpy
->device_name
) {
1349 _eglError(EGL_BAD_ALLOC
, "wayland-egl: failed to get device name "
1350 "for requested GPU");
1355 /* we have to do the check now, because loader_get_user_preferred_fd
1356 * will return a render-node when the requested gpu is different
1357 * to the server, but also if the client asks for the same gpu than
1358 * the server by requesting its pci-id */
1359 dri2_dpy
->is_render_node
= drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
;
1361 dri2_dpy
->driver_name
= loader_get_driver_for_fd(dri2_dpy
->fd
);
1362 if (dri2_dpy
->driver_name
== NULL
) {
1363 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to get driver name");
1367 /* render nodes cannot use Gem names, and thus do not support
1368 * the __DRI_DRI2_LOADER extension */
1369 if (!dri2_dpy
->is_render_node
) {
1370 dri2_dpy
->loader_extensions
= dri2_loader_extensions
;
1371 if (!dri2_load_driver(disp
)) {
1372 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to load driver");
1376 dri2_dpy
->loader_extensions
= image_loader_extensions
;
1377 if (!dri2_load_driver_dri3(disp
)) {
1378 _eglError(EGL_BAD_ALLOC
, "DRI3: failed to load driver");
1383 if (!dri2_create_screen(disp
))
1386 if (!dri2_setup_extensions(disp
))
1389 dri2_setup_screen(disp
);
1391 dri2_wl_setup_swap_interval(disp
);
1393 /* To use Prime, we must have _DRI_IMAGE v7 at least.
1394 * createImageFromFds support indicates that Prime export/import
1395 * is supported by the driver. Fall back to
1396 * gem names if we don't have Prime support. */
1398 if (dri2_dpy
->image
->base
.version
< 7 ||
1399 dri2_dpy
->image
->createImageFromFds
== NULL
)
1400 dri2_dpy
->capabilities
&= ~WL_DRM_CAPABILITY_PRIME
;
1402 /* We cannot use Gem names with render-nodes, only prime fds (dma-buf).
1403 * The server needs to accept them */
1404 if (dri2_dpy
->is_render_node
&&
1405 !(dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
)) {
1406 _eglLog(_EGL_WARNING
, "wayland-egl: display is not render-node capable");
1410 if (dri2_dpy
->is_different_gpu
&&
1411 (dri2_dpy
->image
->base
.version
< 9 ||
1412 dri2_dpy
->image
->blitImage
== NULL
)) {
1413 _eglLog(_EGL_WARNING
, "wayland-egl: Different GPU selected, but the "
1414 "Image extension in the driver is not "
1415 "compatible. Version 9 or later and blitImage() "
1420 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
1421 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
1425 dri2_set_WL_bind_wayland_display(drv
, disp
);
1426 /* When cannot convert EGLImage to wl_buffer when on a different gpu,
1427 * because the buffer of the EGLImage has likely a tiling mode the server
1428 * gpu won't support. These is no way to check for now. Thus do not support the
1430 if (!dri2_dpy
->is_different_gpu
)
1431 disp
->Extensions
.WL_create_wayland_buffer_from_image
= EGL_TRUE
;
1433 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
1435 disp
->Extensions
.EXT_swap_buffers_with_damage
= EGL_TRUE
;
1437 /* Fill vtbl last to prevent accidentally calling virtual function during
1440 dri2_dpy
->vtbl
= &dri2_wl_display_vtbl
;
1445 dri2_display_destroy(disp
);
1450 dri2_wl_swrast_get_stride_for_format(int format
, int w
)
1452 int visual_idx
= dri2_wl_visual_idx_from_shm_format(format
);
1454 assume(visual_idx
!= -1);
1456 return w
* (dri2_wl_visuals
[visual_idx
].bpp
/ 8);
1460 * Taken from weston shared/os-compatibility.c
1463 #ifndef HAVE_MKOSTEMP
1466 set_cloexec_or_close(int fd
)
1473 flags
= fcntl(fd
, F_GETFD
);
1477 if (fcntl(fd
, F_SETFD
, flags
| FD_CLOEXEC
) == -1)
1490 * Taken from weston shared/os-compatibility.c
1494 create_tmpfile_cloexec(char *tmpname
)
1498 #ifdef HAVE_MKOSTEMP
1499 fd
= mkostemp(tmpname
, O_CLOEXEC
);
1503 fd
= mkstemp(tmpname
);
1505 fd
= set_cloexec_or_close(fd
);
1514 * Taken from weston shared/os-compatibility.c
1516 * Create a new, unique, anonymous file of the given size, and
1517 * return the file descriptor for it. The file descriptor is set
1518 * CLOEXEC. The file is immediately suitable for mmap()'ing
1519 * the given size at offset zero.
1521 * The file should not have a permanent backing store like a disk,
1522 * but may have if XDG_RUNTIME_DIR is not properly implemented in OS.
1524 * The file name is deleted from the file system.
1526 * The file is suitable for buffer sharing between processes by
1527 * transmitting the file descriptor over Unix sockets using the
1528 * SCM_RIGHTS methods.
1530 * If the C library implements posix_fallocate(), it is used to
1531 * guarantee that disk space is available for the file at the
1532 * given size. If disk space is insufficent, errno is set to ENOSPC.
1533 * If posix_fallocate() is not supported, program may receive
1534 * SIGBUS on accessing mmap()'ed file contents instead.
1537 os_create_anonymous_file(off_t size
)
1539 static const char templ
[] = "/mesa-shared-XXXXXX";
1545 path
= getenv("XDG_RUNTIME_DIR");
1551 name
= malloc(strlen(path
) + sizeof(templ
));
1556 strcat(name
, templ
);
1558 fd
= create_tmpfile_cloexec(name
);
1565 ret
= ftruncate(fd
, size
);
1576 dri2_wl_swrast_allocate_buffer(struct dri2_egl_surface
*dri2_surf
,
1577 int format
, int w
, int h
,
1578 void **data
, int *size
,
1579 struct wl_buffer
**buffer
)
1581 struct dri2_egl_display
*dri2_dpy
=
1582 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1583 struct wl_shm_pool
*pool
;
1584 int fd
, stride
, size_map
;
1587 stride
= dri2_wl_swrast_get_stride_for_format(format
, w
);
1588 size_map
= h
* stride
;
1590 /* Create a sharable buffer */
1591 fd
= os_create_anonymous_file(size_map
);
1595 data_map
= mmap(NULL
, size_map
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
1596 if (data_map
== MAP_FAILED
) {
1601 /* Share it in a wl_buffer */
1602 pool
= wl_shm_create_pool(dri2_dpy
->wl_shm
, fd
, size_map
);
1603 wl_proxy_set_queue((struct wl_proxy
*)pool
, dri2_surf
->wl_queue
);
1604 *buffer
= wl_shm_pool_create_buffer(pool
, 0, w
, h
, stride
, format
);
1605 wl_shm_pool_destroy(pool
);
1614 swrast_update_buffers(struct dri2_egl_surface
*dri2_surf
)
1616 struct dri2_egl_display
*dri2_dpy
=
1617 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1619 /* we need to do the following operations only once per frame */
1620 if (dri2_surf
->back
)
1623 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->width
||
1624 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->height
) {
1626 dri2_wl_release_buffers(dri2_surf
);
1628 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
1629 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
1630 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
1631 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
1632 dri2_surf
->current
= NULL
;
1635 /* find back buffer */
1637 /* There might be a buffer release already queued that wasn't processed */
1638 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
1640 /* try get free buffer already created */
1641 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1642 if (!dri2_surf
->color_buffers
[i
].locked
&&
1643 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1644 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1649 /* else choose any another free location */
1650 if (!dri2_surf
->back
) {
1651 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1652 if (!dri2_surf
->color_buffers
[i
].locked
) {
1653 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1654 if (!dri2_wl_swrast_allocate_buffer(dri2_surf
,
1656 dri2_surf
->base
.Width
,
1657 dri2_surf
->base
.Height
,
1658 &dri2_surf
->back
->data
,
1659 &dri2_surf
->back
->data_size
,
1660 &dri2_surf
->back
->wl_buffer
)) {
1661 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
1664 wl_buffer_add_listener(dri2_surf
->back
->wl_buffer
,
1665 &wl_buffer_listener
, dri2_surf
);
1671 if (!dri2_surf
->back
) {
1672 _eglError(EGL_BAD_ALLOC
, "failed to find free buffer");
1676 dri2_surf
->back
->locked
= true;
1678 /* If we have an extra unlocked buffer at this point, we had to do triple
1679 * buffering for a while, but now can go back to just double buffering.
1680 * That means we can free any unlocked buffer now. */
1681 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1682 if (!dri2_surf
->color_buffers
[i
].locked
&&
1683 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1684 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
1685 munmap(dri2_surf
->color_buffers
[i
].data
,
1686 dri2_surf
->color_buffers
[i
].data_size
);
1687 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
1688 dri2_surf
->color_buffers
[i
].data
= NULL
;
1696 dri2_wl_swrast_get_frontbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1698 /* if there has been a resize: */
1699 if (!dri2_surf
->current
)
1702 return dri2_surf
->current
->data
;
1706 dri2_wl_swrast_get_backbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1708 assert(dri2_surf
->back
);
1709 return dri2_surf
->back
->data
;
1713 dri2_wl_swrast_commit_backbuffer(struct dri2_egl_surface
*dri2_surf
)
1715 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1717 while (dri2_surf
->throttle_callback
!= NULL
)
1718 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
1719 dri2_surf
->wl_queue
) == -1)
1722 if (dri2_surf
->base
.SwapInterval
> 0) {
1723 dri2_surf
->throttle_callback
=
1724 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
1725 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1726 &throttle_listener
, dri2_surf
);
1729 dri2_surf
->current
= dri2_surf
->back
;
1730 dri2_surf
->back
= NULL
;
1732 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
1733 dri2_surf
->current
->wl_buffer
,
1734 dri2_surf
->dx
, dri2_surf
->dy
);
1736 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
1737 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
1738 /* reset resize growing parameters */
1742 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
1743 0, 0, INT32_MAX
, INT32_MAX
);
1744 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
1746 /* If we're not waiting for a frame callback then we'll at least throttle
1747 * to a sync callback so that we always give a chance for the compositor to
1748 * handle the commit and send a release event before checking for a free
1750 if (dri2_surf
->throttle_callback
== NULL
) {
1751 dri2_surf
->throttle_callback
= wl_display_sync(dri2_surf
->wl_dpy_wrapper
);
1752 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1753 &throttle_listener
, dri2_surf
);
1756 wl_display_flush(dri2_dpy
->wl_dpy
);
1760 dri2_wl_swrast_get_drawable_info(__DRIdrawable
* draw
,
1761 int *x
, int *y
, int *w
, int *h
,
1762 void *loaderPrivate
)
1764 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1766 (void) swrast_update_buffers(dri2_surf
);
1769 *w
= dri2_surf
->base
.Width
;
1770 *h
= dri2_surf
->base
.Height
;
1774 dri2_wl_swrast_get_image(__DRIdrawable
* read
,
1775 int x
, int y
, int w
, int h
,
1776 char *data
, void *loaderPrivate
)
1778 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1779 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1780 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1781 int src_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1782 int dst_stride
= copy_width
;
1785 src
= dri2_wl_swrast_get_frontbuffer_data(dri2_surf
);
1787 memset(data
, 0, copy_width
* h
);
1791 assert(data
!= src
);
1792 assert(copy_width
<= src_stride
);
1795 src
+= y
* src_stride
;
1798 if (copy_width
> src_stride
-x_offset
)
1799 copy_width
= src_stride
-x_offset
;
1800 if (h
> dri2_surf
->base
.Height
-y
)
1801 h
= dri2_surf
->base
.Height
-y
;
1804 memcpy(dst
, src
, copy_width
);
1811 dri2_wl_swrast_put_image2(__DRIdrawable
* draw
, int op
,
1812 int x
, int y
, int w
, int h
, int stride
,
1813 char *data
, void *loaderPrivate
)
1815 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1816 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1817 int dst_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1818 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1821 assert(copy_width
<= stride
);
1823 (void) swrast_update_buffers(dri2_surf
);
1824 dst
= dri2_wl_swrast_get_backbuffer_data(dri2_surf
);
1826 /* partial copy, copy old content */
1827 if (copy_width
< dst_stride
)
1828 dri2_wl_swrast_get_image(draw
, 0, 0,
1829 dri2_surf
->base
.Width
, dri2_surf
->base
.Height
,
1830 dst
, loaderPrivate
);
1833 dst
+= y
* dst_stride
;
1837 /* drivers expect we do these checks (and some rely on it) */
1838 if (copy_width
> dst_stride
-x_offset
)
1839 copy_width
= dst_stride
-x_offset
;
1840 if (h
> dri2_surf
->base
.Height
-y
)
1841 h
= dri2_surf
->base
.Height
-y
;
1844 memcpy(dst
, src
, copy_width
);
1848 dri2_wl_swrast_commit_backbuffer(dri2_surf
);
1852 dri2_wl_swrast_put_image(__DRIdrawable
* draw
, int op
,
1853 int x
, int y
, int w
, int h
,
1854 char *data
, void *loaderPrivate
)
1856 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1859 stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1860 dri2_wl_swrast_put_image2(draw
, op
, x
, y
, w
, h
,
1861 stride
, data
, loaderPrivate
);
1865 dri2_wl_swrast_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1867 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1868 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
1870 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
1875 shm_handle_format(void *data
, struct wl_shm
*shm
, uint32_t format
)
1877 struct dri2_egl_display
*dri2_dpy
= data
;
1878 int visual_idx
= dri2_wl_visual_idx_from_shm_format(format
);
1880 if (visual_idx
== -1)
1883 dri2_dpy
->formats
|= (1 << visual_idx
);
1886 static const struct wl_shm_listener shm_listener
= {
1887 .format
= shm_handle_format
1891 registry_handle_global_swrast(void *data
, struct wl_registry
*registry
,
1892 uint32_t name
, const char *interface
,
1895 struct dri2_egl_display
*dri2_dpy
= data
;
1897 if (strcmp(interface
, "wl_shm") == 0) {
1899 wl_registry_bind(registry
, name
, &wl_shm_interface
, 1);
1900 wl_shm_add_listener(dri2_dpy
->wl_shm
, &shm_listener
, dri2_dpy
);
1904 static const struct wl_registry_listener registry_listener_swrast
= {
1905 .global
= registry_handle_global_swrast
,
1906 .global_remove
= registry_handle_global_remove
1909 static const struct dri2_egl_display_vtbl dri2_wl_swrast_display_vtbl
= {
1910 .authenticate
= NULL
,
1911 .create_window_surface
= dri2_wl_create_window_surface
,
1912 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1913 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1914 .destroy_surface
= dri2_wl_destroy_surface
,
1915 .create_image
= dri2_create_image_khr
,
1916 .swap_buffers
= dri2_wl_swrast_swap_buffers
,
1917 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
1918 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1919 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1920 .copy_buffers
= dri2_fallback_copy_buffers
,
1921 .query_buffer_age
= dri2_fallback_query_buffer_age
,
1922 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
1923 .get_sync_values
= dri2_fallback_get_sync_values
,
1924 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1927 static const __DRIswrastLoaderExtension swrast_loader_extension
= {
1928 .base
= { __DRI_SWRAST_LOADER
, 2 },
1930 .getDrawableInfo
= dri2_wl_swrast_get_drawable_info
,
1931 .putImage
= dri2_wl_swrast_put_image
,
1932 .getImage
= dri2_wl_swrast_get_image
,
1933 .putImage2
= dri2_wl_swrast_put_image2
,
1936 static const __DRIextension
*swrast_loader_extensions
[] = {
1937 &swrast_loader_extension
.base
,
1938 &image_lookup_extension
.base
,
1943 dri2_initialize_wayland_swrast(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1945 struct dri2_egl_display
*dri2_dpy
;
1947 loader_set_logger(_eglLog
);
1949 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1951 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1954 disp
->DriverData
= (void *) dri2_dpy
;
1955 if (disp
->PlatformDisplay
== NULL
) {
1956 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1957 if (dri2_dpy
->wl_dpy
== NULL
)
1959 dri2_dpy
->own_device
= true;
1961 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
1964 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
1966 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
1967 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
1970 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
1971 dri2_dpy
->wl_queue
);
1973 if (dri2_dpy
->own_device
)
1974 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
1976 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
1977 wl_registry_add_listener(dri2_dpy
->wl_registry
,
1978 ®istry_listener_swrast
, dri2_dpy
);
1980 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_shm
== NULL
)
1983 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->formats
== 0)
1986 dri2_dpy
->driver_name
= strdup("swrast");
1987 if (!dri2_load_driver_swrast(disp
))
1990 dri2_dpy
->loader_extensions
= swrast_loader_extensions
;
1992 if (!dri2_create_screen(disp
))
1995 if (!dri2_setup_extensions(disp
))
1998 dri2_setup_screen(disp
);
2000 dri2_wl_setup_swap_interval(disp
);
2002 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
2003 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
2007 /* Fill vtbl last to prevent accidentally calling virtual function during
2010 dri2_dpy
->vtbl
= &dri2_wl_swrast_display_vtbl
;
2015 dri2_display_destroy(disp
);
2020 dri2_initialize_wayland(_EGLDriver
*drv
, _EGLDisplay
*disp
)
2022 EGLBoolean initialized
= EGL_FALSE
;
2024 if (!disp
->Options
.ForceSoftware
)
2025 initialized
= dri2_initialize_wayland_drm(drv
, disp
);
2028 initialized
= dri2_initialize_wayland_swrast(drv
, disp
);
2035 dri2_teardown_wayland(struct dri2_egl_display
*dri2_dpy
)
2037 if (dri2_dpy
->wl_drm
)
2038 wl_drm_destroy(dri2_dpy
->wl_drm
);
2039 if (dri2_dpy
->wl_dmabuf
)
2040 zwp_linux_dmabuf_v1_destroy(dri2_dpy
->wl_dmabuf
);
2041 if (dri2_dpy
->wl_shm
)
2042 wl_shm_destroy(dri2_dpy
->wl_shm
);
2043 if (dri2_dpy
->wl_registry
)
2044 wl_registry_destroy(dri2_dpy
->wl_registry
);
2045 if (dri2_dpy
->wl_queue
)
2046 wl_event_queue_destroy(dri2_dpy
->wl_queue
);
2047 if (dri2_dpy
->wl_dpy_wrapper
)
2048 wl_proxy_wrapper_destroy(dri2_dpy
->wl_dpy_wrapper
);
2050 for (int i
= 0; dri2_dpy
->wl_modifiers
&& i
< ARRAY_SIZE(dri2_wl_visuals
); i
++)
2051 u_vector_finish(&dri2_dpy
->wl_modifiers
[i
]);
2052 free(dri2_dpy
->wl_modifiers
);
2054 if (dri2_dpy
->own_device
)
2055 wl_display_disconnect(dri2_dpy
->wl_dpy
);