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 #ifndef DRM_FORMAT_MOD_INVALID
53 #define DRM_FORMAT_MOD_INVALID ((1ULL << 56) - 1)
56 #ifndef DRM_FORMAT_MOD_LINEAR
57 #define DRM_FORMAT_MOD_LINEAR 0
61 * The index of entries in this table is used as a bitmask in
62 * dri2_dpy->formats, which tracks the formats supported by our server.
64 static const struct dri2_wl_visual
{
65 const char *format_name
;
66 uint32_t wl_drm_format
;
67 uint32_t wl_shm_format
;
70 unsigned int rgba_masks
[4];
71 } dri2_wl_visuals
[] = {
74 WL_DRM_FORMAT_XRGB2101010
, WL_SHM_FORMAT_XRGB2101010
,
75 __DRI_IMAGE_FORMAT_XRGB2101010
, 32,
76 { 0x3ff00000, 0x000ffc00, 0x000003ff, 0x00000000 }
80 WL_DRM_FORMAT_ARGB2101010
, WL_SHM_FORMAT_ARGB2101010
,
81 __DRI_IMAGE_FORMAT_ARGB2101010
, 32,
82 { 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 }
86 WL_DRM_FORMAT_XRGB8888
, WL_SHM_FORMAT_XRGB8888
,
87 __DRI_IMAGE_FORMAT_XRGB8888
, 32,
88 { 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 }
92 WL_DRM_FORMAT_ARGB8888
, WL_SHM_FORMAT_ARGB8888
,
93 __DRI_IMAGE_FORMAT_ARGB8888
, 32,
94 { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }
98 WL_DRM_FORMAT_RGB565
, WL_SHM_FORMAT_RGB565
,
99 __DRI_IMAGE_FORMAT_RGB565
, 16,
100 { 0xf800, 0x07e0, 0x001f, 0x0000 }
105 dri2_wl_visual_idx_from_config(struct dri2_egl_display
*dri2_dpy
,
106 const __DRIconfig
*config
)
108 unsigned int red
, green
, blue
, alpha
;
110 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_RED_MASK
, &red
);
111 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_GREEN_MASK
, &green
);
112 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_BLUE_MASK
, &blue
);
113 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_ALPHA_MASK
, &alpha
);
115 for (unsigned int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
116 const struct dri2_wl_visual
*wl_visual
= &dri2_wl_visuals
[i
];
118 if (red
== wl_visual
->rgba_masks
[0] &&
119 green
== wl_visual
->rgba_masks
[1] &&
120 blue
== wl_visual
->rgba_masks
[2] &&
121 alpha
== wl_visual
->rgba_masks
[3]) {
130 dri2_wl_visual_idx_from_fourcc(uint32_t fourcc
)
132 for (int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
133 /* wl_drm format codes overlap with DRIImage FourCC codes for all formats
135 if (dri2_wl_visuals
[i
].wl_drm_format
== fourcc
)
143 dri2_wl_visual_idx_from_dri_image_format(uint32_t dri_image_format
)
145 for (int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
146 if (dri2_wl_visuals
[i
].dri_image_format
== dri_image_format
)
154 dri2_wl_visual_idx_from_shm_format(uint32_t shm_format
)
156 for (int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
157 if (dri2_wl_visuals
[i
].wl_shm_format
== shm_format
)
165 roundtrip(struct dri2_egl_display
*dri2_dpy
)
167 return wl_display_roundtrip_queue(dri2_dpy
->wl_dpy
, dri2_dpy
->wl_queue
);
171 wl_buffer_release(void *data
, struct wl_buffer
*buffer
)
173 struct dri2_egl_surface
*dri2_surf
= data
;
176 for (i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); ++i
)
177 if (dri2_surf
->color_buffers
[i
].wl_buffer
== buffer
)
180 if (i
== ARRAY_SIZE(dri2_surf
->color_buffers
)) {
181 wl_buffer_destroy(buffer
);
185 dri2_surf
->color_buffers
[i
].locked
= false;
188 static const struct wl_buffer_listener wl_buffer_listener
= {
189 .release
= wl_buffer_release
193 resize_callback(struct wl_egl_window
*wl_win
, void *data
)
195 struct dri2_egl_surface
*dri2_surf
= data
;
196 struct dri2_egl_display
*dri2_dpy
=
197 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
199 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
203 destroy_window_callback(void *data
)
205 struct dri2_egl_surface
*dri2_surf
= data
;
206 dri2_surf
->wl_win
= NULL
;
209 static struct wl_surface
*
210 get_wl_surface_proxy(struct wl_egl_window
*window
)
212 /* Version 3 of wl_egl_window introduced a version field at the same
213 * location where a pointer to wl_surface was stored. Thus, if
214 * window->version is dereferencable, we've been given an older version of
215 * wl_egl_window, and window->version points to wl_surface */
216 if (_eglPointerIsDereferencable((void *)(window
->version
))) {
217 return wl_proxy_create_wrapper((void *)(window
->version
));
219 return wl_proxy_create_wrapper(window
->surface
);
223 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
226 dri2_wl_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
227 _EGLConfig
*conf
, void *native_window
,
228 const EGLint
*attrib_list
)
230 __DRIcreateNewDrawableFunc createNewDrawable
;
231 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
232 struct dri2_egl_config
*dri2_conf
= dri2_egl_config(conf
);
233 struct wl_egl_window
*window
= native_window
;
234 struct dri2_egl_surface
*dri2_surf
;
236 const __DRIconfig
*config
;
238 dri2_surf
= calloc(1, sizeof *dri2_surf
);
240 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
244 if (!dri2_init_surface(&dri2_surf
->base
, disp
, EGL_WINDOW_BIT
, conf
,
248 config
= dri2_get_dri_config(dri2_conf
, EGL_WINDOW_BIT
,
249 dri2_surf
->base
.GLColorspace
);
250 visual_idx
= dri2_wl_visual_idx_from_config(dri2_dpy
, config
);
251 assert(visual_idx
!= -1);
253 if (dri2_dpy
->wl_dmabuf
|| dri2_dpy
->wl_drm
) {
254 dri2_surf
->format
= dri2_wl_visuals
[visual_idx
].wl_drm_format
;
256 assert(dri2_dpy
->wl_shm
);
257 dri2_surf
->format
= dri2_wl_visuals
[visual_idx
].wl_shm_format
;
260 dri2_surf
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
261 if (!dri2_surf
->wl_queue
) {
262 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
266 if (dri2_dpy
->wl_drm
) {
267 dri2_surf
->wl_drm_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_drm
);
268 if (!dri2_surf
->wl_drm_wrapper
) {
269 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
272 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_drm_wrapper
,
273 dri2_surf
->wl_queue
);
276 dri2_surf
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
277 if (!dri2_surf
->wl_dpy_wrapper
) {
278 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
281 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_dpy_wrapper
,
282 dri2_surf
->wl_queue
);
284 dri2_surf
->wl_surface_wrapper
= get_wl_surface_proxy(window
);
285 if (!dri2_surf
->wl_surface_wrapper
) {
286 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
287 goto cleanup_dpy_wrapper
;
289 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_surface_wrapper
,
290 dri2_surf
->wl_queue
);
292 dri2_surf
->wl_win
= window
;
293 dri2_surf
->wl_win
->private = dri2_surf
;
294 dri2_surf
->wl_win
->destroy_window_callback
= destroy_window_callback
;
296 dri2_surf
->wl_win
->resize_callback
= resize_callback
;
298 if (dri2_dpy
->image_driver
)
299 createNewDrawable
= dri2_dpy
->image_driver
->createNewDrawable
;
300 else if (dri2_dpy
->dri2
)
301 createNewDrawable
= dri2_dpy
->dri2
->createNewDrawable
;
303 createNewDrawable
= dri2_dpy
->swrast
->createNewDrawable
;
305 dri2_surf
->dri_drawable
= (*createNewDrawable
)(dri2_dpy
->dri_screen
, config
,
307 if (dri2_surf
->dri_drawable
== NULL
) {
308 _eglError(EGL_BAD_ALLOC
, "createNewDrawable");
309 goto cleanup_surf_wrapper
;
312 dri2_surf
->base
.SwapInterval
= dri2_dpy
->default_swap_interval
;
314 return &dri2_surf
->base
;
316 cleanup_surf_wrapper
:
317 wl_proxy_wrapper_destroy(dri2_surf
->wl_surface_wrapper
);
319 wl_proxy_wrapper_destroy(dri2_surf
->wl_dpy_wrapper
);
321 if (dri2_surf
->wl_drm_wrapper
)
322 wl_proxy_wrapper_destroy(dri2_surf
->wl_drm_wrapper
);
324 wl_event_queue_destroy(dri2_surf
->wl_queue
);
332 dri2_wl_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
333 _EGLConfig
*conf
, void *native_window
,
334 const EGLint
*attrib_list
)
336 /* From the EGL_EXT_platform_wayland spec, version 3:
338 * It is not valid to call eglCreatePlatformPixmapSurfaceEXT with a <dpy>
339 * that belongs to Wayland. Any such call fails and generates
342 _eglError(EGL_BAD_PARAMETER
, "cannot create EGL pixmap surfaces on "
348 * Called via eglDestroySurface(), drv->API.DestroySurface().
351 dri2_wl_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
353 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
354 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
358 dri2_dpy
->core
->destroyDrawable(dri2_surf
->dri_drawable
);
360 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
361 if (dri2_surf
->color_buffers
[i
].wl_buffer
)
362 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
363 if (dri2_surf
->color_buffers
[i
].dri_image
)
364 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
365 if (dri2_surf
->color_buffers
[i
].linear_copy
)
366 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
367 if (dri2_surf
->color_buffers
[i
].data
)
368 munmap(dri2_surf
->color_buffers
[i
].data
,
369 dri2_surf
->color_buffers
[i
].data_size
);
373 dri2_egl_surface_free_local_buffers(dri2_surf
);
375 if (dri2_surf
->throttle_callback
)
376 wl_callback_destroy(dri2_surf
->throttle_callback
);
378 if (dri2_surf
->wl_win
) {
379 dri2_surf
->wl_win
->private = NULL
;
380 dri2_surf
->wl_win
->resize_callback
= NULL
;
381 dri2_surf
->wl_win
->destroy_window_callback
= NULL
;
384 wl_proxy_wrapper_destroy(dri2_surf
->wl_surface_wrapper
);
385 wl_proxy_wrapper_destroy(dri2_surf
->wl_dpy_wrapper
);
386 if (dri2_surf
->wl_drm_wrapper
)
387 wl_proxy_wrapper_destroy(dri2_surf
->wl_drm_wrapper
);
388 wl_event_queue_destroy(dri2_surf
->wl_queue
);
390 dri2_fini_surface(surf
);
397 dri2_wl_release_buffers(struct dri2_egl_surface
*dri2_surf
)
399 struct dri2_egl_display
*dri2_dpy
=
400 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
402 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
403 if (dri2_surf
->color_buffers
[i
].wl_buffer
&&
404 !dri2_surf
->color_buffers
[i
].locked
)
405 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
406 if (dri2_surf
->color_buffers
[i
].dri_image
)
407 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
408 if (dri2_surf
->color_buffers
[i
].linear_copy
)
409 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
410 if (dri2_surf
->color_buffers
[i
].data
)
411 munmap(dri2_surf
->color_buffers
[i
].data
,
412 dri2_surf
->color_buffers
[i
].data_size
);
414 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
415 dri2_surf
->color_buffers
[i
].dri_image
= NULL
;
416 dri2_surf
->color_buffers
[i
].linear_copy
= NULL
;
417 dri2_surf
->color_buffers
[i
].data
= NULL
;
418 dri2_surf
->color_buffers
[i
].locked
= false;
422 dri2_egl_surface_free_local_buffers(dri2_surf
);
426 get_back_bo(struct dri2_egl_surface
*dri2_surf
)
428 struct dri2_egl_display
*dri2_dpy
=
429 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
432 unsigned int dri_image_format
;
436 visual_idx
= dri2_wl_visual_idx_from_fourcc(dri2_surf
->format
);
437 assert(visual_idx
!= -1);
438 dri_image_format
= dri2_wl_visuals
[visual_idx
].dri_image_format
;
439 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
[visual_idx
]);
440 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
[visual_idx
]);
442 /* There might be a buffer release already queued that wasn't processed */
443 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
445 while (dri2_surf
->back
== NULL
) {
446 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
447 /* Get an unlocked buffer, preferrably one with a dri_buffer
448 * already allocated. */
449 if (dri2_surf
->color_buffers
[i
].locked
)
451 if (dri2_surf
->back
== NULL
)
452 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
453 else if (dri2_surf
->back
->dri_image
== NULL
)
454 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
460 /* If we don't have a buffer, then block on the server to release one for
461 * us, and try again. wl_display_dispatch_queue will process any pending
462 * events, however not all servers flush on issuing a buffer release
463 * event. So, we spam the server with roundtrips as they always cause a
466 if (wl_display_roundtrip_queue(dri2_dpy
->wl_dpy
,
467 dri2_surf
->wl_queue
) < 0)
471 if (dri2_surf
->back
== NULL
)
474 use_flags
= __DRI_IMAGE_USE_SHARE
| __DRI_IMAGE_USE_BACKBUFFER
;
476 if (dri2_dpy
->is_different_gpu
&&
477 dri2_surf
->back
->linear_copy
== NULL
) {
478 /* The LINEAR modifier should be a perfect alias of the LINEAR use
479 * flag; try the new interface first before the old, then fall back. */
480 if (dri2_dpy
->image
->base
.version
>= 15 &&
481 dri2_dpy
->image
->createImageWithModifiers
) {
482 uint64_t linear_mod
= DRM_FORMAT_MOD_LINEAR
;
484 dri2_surf
->back
->linear_copy
=
485 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
486 dri2_surf
->base
.Width
,
487 dri2_surf
->base
.Height
,
493 dri2_surf
->back
->linear_copy
=
494 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
495 dri2_surf
->base
.Width
,
496 dri2_surf
->base
.Height
,
499 __DRI_IMAGE_USE_LINEAR
,
502 if (dri2_surf
->back
->linear_copy
== NULL
)
506 if (dri2_surf
->back
->dri_image
== NULL
) {
507 /* If our DRIImage implementation does not support
508 * createImageWithModifiers, then fall back to the old createImage,
509 * and hope it allocates an image which is acceptable to the winsys.
511 if (num_modifiers
&& dri2_dpy
->image
->base
.version
>= 15 &&
512 dri2_dpy
->image
->createImageWithModifiers
) {
513 dri2_surf
->back
->dri_image
=
514 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
515 dri2_surf
->base
.Width
,
516 dri2_surf
->base
.Height
,
522 dri2_surf
->back
->dri_image
=
523 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
524 dri2_surf
->base
.Width
,
525 dri2_surf
->base
.Height
,
527 dri2_dpy
->is_different_gpu
?
532 dri2_surf
->back
->age
= 0;
534 if (dri2_surf
->back
->dri_image
== NULL
)
537 dri2_surf
->back
->locked
= true;
544 back_bo_to_dri_buffer(struct dri2_egl_surface
*dri2_surf
, __DRIbuffer
*buffer
)
546 struct dri2_egl_display
*dri2_dpy
=
547 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
551 image
= dri2_surf
->back
->dri_image
;
553 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
554 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &pitch
);
556 buffer
->attachment
= __DRI_BUFFER_BACK_LEFT
;
558 buffer
->pitch
= pitch
;
564 update_buffers(struct dri2_egl_surface
*dri2_surf
)
566 struct dri2_egl_display
*dri2_dpy
=
567 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
569 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->width
||
570 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->height
) {
572 dri2_wl_release_buffers(dri2_surf
);
574 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
575 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
576 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
577 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
580 if (get_back_bo(dri2_surf
) < 0) {
581 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
585 /* If we have an extra unlocked buffer at this point, we had to do triple
586 * buffering for a while, but now can go back to just double buffering.
587 * That means we can free any unlocked buffer now. */
588 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
589 if (!dri2_surf
->color_buffers
[i
].locked
&&
590 dri2_surf
->color_buffers
[i
].wl_buffer
) {
591 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
592 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
593 if (dri2_dpy
->is_different_gpu
)
594 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
595 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
596 dri2_surf
->color_buffers
[i
].dri_image
= NULL
;
597 dri2_surf
->color_buffers
[i
].linear_copy
= NULL
;
605 dri2_wl_get_buffers_with_format(__DRIdrawable
* driDrawable
,
606 int *width
, int *height
,
607 unsigned int *attachments
, int count
,
608 int *out_count
, void *loaderPrivate
)
610 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
613 if (update_buffers(dri2_surf
) < 0)
616 for (i
= 0, j
= 0; i
< 2 * count
; i
+= 2, j
++) {
619 switch (attachments
[i
]) {
620 case __DRI_BUFFER_BACK_LEFT
:
621 back_bo_to_dri_buffer(dri2_surf
, &dri2_surf
->buffers
[j
]);
624 local
= dri2_egl_surface_alloc_local_buffer(dri2_surf
, attachments
[i
],
628 _eglError(EGL_BAD_ALLOC
, "failed to allocate local buffer");
631 dri2_surf
->buffers
[j
] = *local
;
640 *width
= dri2_surf
->base
.Width
;
641 *height
= dri2_surf
->base
.Height
;
643 return dri2_surf
->buffers
;
647 dri2_wl_get_buffers(__DRIdrawable
* driDrawable
,
648 int *width
, int *height
,
649 unsigned int *attachments
, int count
,
650 int *out_count
, void *loaderPrivate
)
652 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
653 unsigned int *attachments_with_format
;
655 int visual_idx
= dri2_wl_visual_idx_from_fourcc(dri2_surf
->format
);
657 if (visual_idx
== -1)
660 attachments_with_format
= calloc(count
, 2 * sizeof(unsigned int));
661 if (!attachments_with_format
) {
666 for (int i
= 0; i
< count
; ++i
) {
667 attachments_with_format
[2*i
] = attachments
[i
];
668 attachments_with_format
[2*i
+ 1] = dri2_wl_visuals
[visual_idx
].bpp
;
672 dri2_wl_get_buffers_with_format(driDrawable
,
674 attachments_with_format
, count
,
675 out_count
, loaderPrivate
);
677 free(attachments_with_format
);
683 image_get_buffers(__DRIdrawable
*driDrawable
,
687 uint32_t buffer_mask
,
688 struct __DRIimageList
*buffers
)
690 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
692 if (update_buffers(dri2_surf
) < 0)
695 buffers
->image_mask
= __DRI_IMAGE_BUFFER_BACK
;
696 buffers
->back
= dri2_surf
->back
->dri_image
;
702 dri2_wl_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
705 (void) loaderPrivate
;
708 static const __DRIdri2LoaderExtension dri2_loader_extension
= {
709 .base
= { __DRI_DRI2_LOADER
, 3 },
711 .getBuffers
= dri2_wl_get_buffers
,
712 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
713 .getBuffersWithFormat
= dri2_wl_get_buffers_with_format
,
716 static const __DRIimageLoaderExtension image_loader_extension
= {
717 .base
= { __DRI_IMAGE_LOADER
, 1 },
719 .getBuffers
= image_get_buffers
,
720 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
724 wayland_throttle_callback(void *data
,
725 struct wl_callback
*callback
,
728 struct dri2_egl_surface
*dri2_surf
= data
;
730 dri2_surf
->throttle_callback
= NULL
;
731 wl_callback_destroy(callback
);
734 static const struct wl_callback_listener throttle_listener
= {
735 .done
= wayland_throttle_callback
739 get_fourcc(struct dri2_egl_display
*dri2_dpy
,
740 __DRIimage
*image
, int *fourcc
)
746 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FOURCC
,
751 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
,
756 visual_idx
= dri2_wl_visual_idx_from_dri_image_format(dri_format
);
757 if (visual_idx
== -1)
760 *fourcc
= dri2_wl_visuals
[visual_idx
].wl_drm_format
;
764 static struct wl_buffer
*
765 create_wl_buffer(struct dri2_egl_display
*dri2_dpy
,
766 struct dri2_egl_surface
*dri2_surf
,
769 struct wl_buffer
*ret
;
771 int width
, height
, fourcc
, num_planes
;
772 uint64_t modifier
= DRM_FORMAT_MOD_INVALID
;
774 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_WIDTH
, &width
);
775 query
&= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_HEIGHT
,
777 query
&= get_fourcc(dri2_dpy
, image
, &fourcc
);
781 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NUM_PLANES
,
786 if (dri2_dpy
->image
->base
.version
>= 15) {
789 query
= dri2_dpy
->image
->queryImage(image
,
790 __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
,
792 query
&= dri2_dpy
->image
->queryImage(image
,
793 __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
,
796 modifier
= (uint64_t) mod_hi
<< 32;
797 modifier
|= (uint64_t) (mod_lo
& 0xffffffff);
801 if (dri2_dpy
->wl_dmabuf
&& modifier
!= DRM_FORMAT_MOD_INVALID
) {
802 struct zwp_linux_buffer_params_v1
*params
;
805 /* We don't need a wrapper for wl_dmabuf objects, because we have to
806 * create the intermediate params object; we can set the queue on this,
807 * and the wl_buffer inherits it race-free. */
808 params
= zwp_linux_dmabuf_v1_create_params(dri2_dpy
->wl_dmabuf
);
810 wl_proxy_set_queue((struct wl_proxy
*) params
, dri2_surf
->wl_queue
);
812 for (i
= 0; i
< num_planes
; i
++) {
820 p_image
= dri2_dpy
->image
->fromPlanar(image
, i
, NULL
);
822 zwp_linux_buffer_params_v1_destroy(params
);
826 query
= dri2_dpy
->image
->queryImage(p_image
,
827 __DRI_IMAGE_ATTRIB_FD
,
829 query
&= dri2_dpy
->image
->queryImage(p_image
,
830 __DRI_IMAGE_ATTRIB_STRIDE
,
832 query
&= dri2_dpy
->image
->queryImage(p_image
,
833 __DRI_IMAGE_ATTRIB_OFFSET
,
835 if (image
!= p_image
)
836 dri2_dpy
->image
->destroyImage(p_image
);
841 zwp_linux_buffer_params_v1_destroy(params
);
845 zwp_linux_buffer_params_v1_add(params
, fd
, i
, offset
, stride
,
846 modifier
>> 32, modifier
& 0xffffffff);
850 ret
= zwp_linux_buffer_params_v1_create_immed(params
, width
, height
,
852 zwp_linux_buffer_params_v1_destroy(params
);
853 } else if (dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
) {
854 struct wl_drm
*wl_drm
=
855 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
861 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FD
, &fd
);
862 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
863 ret
= wl_drm_create_prime_buffer(wl_drm
, fd
, width
, height
, fourcc
, 0,
867 struct wl_drm
*wl_drm
=
868 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
874 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
875 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
876 ret
= wl_drm_create_buffer(wl_drm
, name
, width
, height
, stride
, fourcc
);
883 try_damage_buffer(struct dri2_egl_surface
*dri2_surf
,
887 if (wl_proxy_get_version((struct wl_proxy
*) dri2_surf
->wl_surface_wrapper
)
888 < WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION
)
891 for (int i
= 0; i
< n_rects
; i
++) {
892 const int *rect
= &rects
[i
* 4];
894 wl_surface_damage_buffer(dri2_surf
->wl_surface_wrapper
,
896 dri2_surf
->base
.Height
- rect
[1] - rect
[3],
902 * Called via eglSwapBuffers(), drv->API.SwapBuffers().
905 dri2_wl_swap_buffers_with_damage(_EGLDriver
*drv
,
911 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
912 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
914 while (dri2_surf
->throttle_callback
!= NULL
)
915 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
916 dri2_surf
->wl_queue
) == -1)
919 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
920 if (dri2_surf
->color_buffers
[i
].age
> 0)
921 dri2_surf
->color_buffers
[i
].age
++;
923 /* Make sure we have a back buffer in case we're swapping without ever
925 if (get_back_bo(dri2_surf
) < 0)
926 return _eglError(EGL_BAD_ALLOC
, "dri2_swap_buffers");
928 if (draw
->SwapInterval
> 0) {
929 dri2_surf
->throttle_callback
=
930 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
931 wl_callback_add_listener(dri2_surf
->throttle_callback
,
932 &throttle_listener
, dri2_surf
);
935 dri2_surf
->back
->age
= 1;
936 dri2_surf
->current
= dri2_surf
->back
;
937 dri2_surf
->back
= NULL
;
939 if (!dri2_surf
->current
->wl_buffer
) {
942 if (dri2_dpy
->is_different_gpu
)
943 image
= dri2_surf
->current
->linear_copy
;
945 image
= dri2_surf
->current
->dri_image
;
947 dri2_surf
->current
->wl_buffer
=
948 create_wl_buffer(dri2_dpy
, dri2_surf
, image
);
950 wl_buffer_add_listener(dri2_surf
->current
->wl_buffer
,
951 &wl_buffer_listener
, dri2_surf
);
954 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
955 dri2_surf
->current
->wl_buffer
,
956 dri2_surf
->dx
, dri2_surf
->dy
);
958 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
959 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
960 /* reset resize growing parameters */
964 /* If the compositor doesn't support damage_buffer, we deliberately
965 * ignore the damage region and post maximum damage, due to
966 * https://bugs.freedesktop.org/78190 */
967 if (!n_rects
|| !try_damage_buffer(dri2_surf
, rects
, n_rects
))
968 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
969 0, 0, INT32_MAX
, INT32_MAX
);
971 if (dri2_dpy
->is_different_gpu
) {
972 _EGLContext
*ctx
= _eglGetCurrentContext();
973 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
974 dri2_dpy
->image
->blitImage(dri2_ctx
->dri_context
,
975 dri2_surf
->current
->linear_copy
,
976 dri2_surf
->current
->dri_image
,
977 0, 0, dri2_surf
->base
.Width
,
978 dri2_surf
->base
.Height
,
979 0, 0, dri2_surf
->base
.Width
,
980 dri2_surf
->base
.Height
, 0);
983 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
984 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
986 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
988 /* If we're not waiting for a frame callback then we'll at least throttle
989 * to a sync callback so that we always give a chance for the compositor to
990 * handle the commit and send a release event before checking for a free
992 if (dri2_surf
->throttle_callback
== NULL
) {
993 dri2_surf
->throttle_callback
= wl_display_sync(dri2_surf
->wl_dpy_wrapper
);
994 wl_callback_add_listener(dri2_surf
->throttle_callback
,
995 &throttle_listener
, dri2_surf
);
998 wl_display_flush(dri2_dpy
->wl_dpy
);
1004 dri2_wl_query_buffer_age(_EGLDriver
*drv
,
1005 _EGLDisplay
*disp
, _EGLSurface
*surface
)
1007 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
1009 if (get_back_bo(dri2_surf
) < 0) {
1010 _eglError(EGL_BAD_ALLOC
, "dri2_query_buffer_age");
1014 return dri2_surf
->back
->age
;
1018 dri2_wl_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1020 return dri2_wl_swap_buffers_with_damage(drv
, disp
, draw
, NULL
, 0);
1023 static struct wl_buffer
*
1024 dri2_wl_create_wayland_buffer_from_image(_EGLDriver
*drv
,
1028 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1029 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
1030 __DRIimage
*image
= dri2_img
->dri_image
;
1031 struct wl_buffer
*buffer
;
1032 int format
, visual_idx
;
1034 /* Check the upstream display supports this buffer's format. */
1035 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
, &format
);
1036 visual_idx
= dri2_wl_visual_idx_from_dri_image_format(format
);
1037 if (visual_idx
== -1)
1040 if (!(dri2_dpy
->formats
& (1 << visual_idx
)))
1043 buffer
= create_wl_buffer(dri2_dpy
, NULL
, image
);
1045 /* The buffer object will have been created with our internal event queue
1046 * because it is using wl_dmabuf/wl_drm as a proxy factory. We want the
1047 * buffer to be used by the application so we'll reset it to the display's
1048 * default event queue. This isn't actually racy, as the only event the
1049 * buffer can get is a buffer release, which doesn't happen with an explicit
1052 wl_proxy_set_queue((struct wl_proxy
*) buffer
, NULL
);
1057 _eglError(EGL_BAD_MATCH
, "unsupported image format");
1062 dri2_wl_authenticate(_EGLDisplay
*disp
, uint32_t id
)
1064 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1067 if (dri2_dpy
->is_render_node
) {
1068 _eglLog(_EGL_WARNING
, "wayland-egl: client asks server to "
1069 "authenticate for render-nodes");
1072 dri2_dpy
->authenticated
= false;
1074 wl_drm_authenticate(dri2_dpy
->wl_drm
, id
);
1075 if (roundtrip(dri2_dpy
) < 0)
1078 if (!dri2_dpy
->authenticated
)
1081 /* reset authenticated */
1082 dri2_dpy
->authenticated
= true;
1088 drm_handle_device(void *data
, struct wl_drm
*drm
, const char *device
)
1090 struct dri2_egl_display
*dri2_dpy
= data
;
1093 dri2_dpy
->device_name
= strdup(device
);
1094 if (!dri2_dpy
->device_name
)
1097 dri2_dpy
->fd
= loader_open_device(dri2_dpy
->device_name
);
1098 if (dri2_dpy
->fd
== -1) {
1099 _eglLog(_EGL_WARNING
, "wayland-egl: could not open %s (%s)",
1100 dri2_dpy
->device_name
, strerror(errno
));
1104 if (drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
) {
1105 dri2_dpy
->authenticated
= true;
1107 drmGetMagic(dri2_dpy
->fd
, &magic
);
1108 wl_drm_authenticate(dri2_dpy
->wl_drm
, magic
);
1113 drm_handle_format(void *data
, struct wl_drm
*drm
, uint32_t format
)
1115 struct dri2_egl_display
*dri2_dpy
= data
;
1116 int visual_idx
= dri2_wl_visual_idx_from_fourcc(format
);
1118 if (visual_idx
== -1)
1121 dri2_dpy
->formats
|= (1 << visual_idx
);
1125 drm_handle_capabilities(void *data
, struct wl_drm
*drm
, uint32_t value
)
1127 struct dri2_egl_display
*dri2_dpy
= data
;
1129 dri2_dpy
->capabilities
= value
;
1133 drm_handle_authenticated(void *data
, struct wl_drm
*drm
)
1135 struct dri2_egl_display
*dri2_dpy
= data
;
1137 dri2_dpy
->authenticated
= true;
1140 static const struct wl_drm_listener drm_listener
= {
1141 .device
= drm_handle_device
,
1142 .format
= drm_handle_format
,
1143 .authenticated
= drm_handle_authenticated
,
1144 .capabilities
= drm_handle_capabilities
1148 dmabuf_ignore_format(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1151 /* formats are implicitly advertised by the 'modifier' event, so ignore */
1155 dmabuf_handle_modifier(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1156 uint32_t format
, uint32_t modifier_hi
,
1157 uint32_t modifier_lo
)
1159 struct dri2_egl_display
*dri2_dpy
= data
;
1160 int visual_idx
= dri2_wl_visual_idx_from_fourcc(format
);
1163 if (visual_idx
== -1)
1166 if (modifier_hi
== (DRM_FORMAT_MOD_INVALID
>> 32) &&
1167 modifier_lo
== (DRM_FORMAT_MOD_INVALID
& 0xffffffff))
1170 dri2_dpy
->formats
|= (1 << visual_idx
);
1172 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
[visual_idx
]);
1173 *mod
= (uint64_t) modifier_hi
<< 32;
1174 *mod
|= (uint64_t) (modifier_lo
& 0xffffffff);
1177 static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener
= {
1178 .format
= dmabuf_ignore_format
,
1179 .modifier
= dmabuf_handle_modifier
,
1183 registry_handle_global_drm(void *data
, struct wl_registry
*registry
,
1184 uint32_t name
, const char *interface
,
1187 struct dri2_egl_display
*dri2_dpy
= data
;
1189 if (strcmp(interface
, "wl_drm") == 0) {
1191 wl_registry_bind(registry
, name
, &wl_drm_interface
, MIN2(version
, 2));
1192 wl_drm_add_listener(dri2_dpy
->wl_drm
, &drm_listener
, dri2_dpy
);
1193 } else if (strcmp(interface
, "zwp_linux_dmabuf_v1") == 0 && version
>= 3) {
1194 dri2_dpy
->wl_dmabuf
=
1195 wl_registry_bind(registry
, name
, &zwp_linux_dmabuf_v1_interface
,
1197 zwp_linux_dmabuf_v1_add_listener(dri2_dpy
->wl_dmabuf
, &dmabuf_listener
,
1203 registry_handle_global_remove(void *data
, struct wl_registry
*registry
,
1208 static const struct wl_registry_listener registry_listener_drm
= {
1209 .global
= registry_handle_global_drm
,
1210 .global_remove
= registry_handle_global_remove
1214 dri2_wl_setup_swap_interval(_EGLDisplay
*disp
)
1216 /* We can't use values greater than 1 on Wayland because we are using the
1217 * frame callback to synchronise the frame and the only way we be sure to
1218 * get a frame callback is to attach a new buffer. Therefore we can't just
1219 * sit drawing nothing to wait until the next ‘n’ frame callbacks */
1221 dri2_setup_swap_interval(disp
, 1);
1224 static const struct dri2_egl_display_vtbl dri2_wl_display_vtbl
= {
1225 .authenticate
= dri2_wl_authenticate
,
1226 .create_window_surface
= dri2_wl_create_window_surface
,
1227 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1228 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1229 .destroy_surface
= dri2_wl_destroy_surface
,
1230 .create_image
= dri2_create_image_khr
,
1231 .swap_buffers
= dri2_wl_swap_buffers
,
1232 .swap_buffers_with_damage
= dri2_wl_swap_buffers_with_damage
,
1233 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1234 .set_damage_region
= dri2_fallback_set_damage_region
,
1235 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1236 .copy_buffers
= dri2_fallback_copy_buffers
,
1237 .query_buffer_age
= dri2_wl_query_buffer_age
,
1238 .create_wayland_buffer_from_image
= dri2_wl_create_wayland_buffer_from_image
,
1239 .get_sync_values
= dri2_fallback_get_sync_values
,
1240 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1243 static const __DRIextension
*dri2_loader_extensions
[] = {
1244 &dri2_loader_extension
.base
,
1245 &image_loader_extension
.base
,
1246 &image_lookup_extension
.base
,
1247 &use_invalidate
.base
,
1251 static const __DRIextension
*image_loader_extensions
[] = {
1252 &image_loader_extension
.base
,
1253 &image_lookup_extension
.base
,
1254 &use_invalidate
.base
,
1259 dri2_wl_add_configs_for_visuals(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1261 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1262 unsigned int format_count
[ARRAY_SIZE(dri2_wl_visuals
)] = { 0 };
1263 unsigned int count
= 0;
1265 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
1266 for (unsigned j
= 0; j
< ARRAY_SIZE(dri2_wl_visuals
); j
++) {
1267 struct dri2_egl_config
*dri2_conf
;
1269 if (!(dri2_dpy
->formats
& (1 << j
)))
1272 dri2_conf
= dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
1273 count
+ 1, EGL_WINDOW_BIT
, NULL
, dri2_wl_visuals
[j
].rgba_masks
);
1275 if (dri2_conf
->base
.ConfigID
== count
+ 1)
1282 for (unsigned i
= 0; i
< ARRAY_SIZE(format_count
); i
++) {
1283 if (!format_count
[i
]) {
1284 _eglLog(_EGL_DEBUG
, "No DRI config supports native format %s",
1285 dri2_wl_visuals
[i
].format_name
);
1289 return (count
!= 0);
1293 dri2_initialize_wayland_drm(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1295 struct dri2_egl_display
*dri2_dpy
;
1297 loader_set_logger(_eglLog
);
1299 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1301 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1304 disp
->DriverData
= (void *) dri2_dpy
;
1305 if (disp
->PlatformDisplay
== NULL
) {
1306 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1307 if (dri2_dpy
->wl_dpy
== NULL
)
1309 dri2_dpy
->own_device
= true;
1311 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
1314 dri2_dpy
->wl_modifiers
=
1315 calloc(ARRAY_SIZE(dri2_wl_visuals
), sizeof(*dri2_dpy
->wl_modifiers
));
1316 if (!dri2_dpy
->wl_modifiers
)
1318 for (int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
1319 if (!u_vector_init(&dri2_dpy
->wl_modifiers
[i
], sizeof(uint64_t), 32))
1323 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
1325 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
1326 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
1329 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
1330 dri2_dpy
->wl_queue
);
1332 if (dri2_dpy
->own_device
)
1333 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
1335 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
1336 wl_registry_add_listener(dri2_dpy
->wl_registry
,
1337 ®istry_listener_drm
, dri2_dpy
);
1338 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_drm
== NULL
)
1341 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->fd
== -1)
1344 if (roundtrip(dri2_dpy
) < 0 || !dri2_dpy
->authenticated
)
1347 dri2_dpy
->fd
= loader_get_user_preferred_fd(dri2_dpy
->fd
,
1348 &dri2_dpy
->is_different_gpu
);
1349 if (dri2_dpy
->is_different_gpu
) {
1350 free(dri2_dpy
->device_name
);
1351 dri2_dpy
->device_name
= loader_get_device_name_for_fd(dri2_dpy
->fd
);
1352 if (!dri2_dpy
->device_name
) {
1353 _eglError(EGL_BAD_ALLOC
, "wayland-egl: failed to get device name "
1354 "for requested GPU");
1359 /* we have to do the check now, because loader_get_user_preferred_fd
1360 * will return a render-node when the requested gpu is different
1361 * to the server, but also if the client asks for the same gpu than
1362 * the server by requesting its pci-id */
1363 dri2_dpy
->is_render_node
= drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
;
1365 dri2_dpy
->driver_name
= loader_get_driver_for_fd(dri2_dpy
->fd
);
1366 if (dri2_dpy
->driver_name
== NULL
) {
1367 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to get driver name");
1371 /* render nodes cannot use Gem names, and thus do not support
1372 * the __DRI_DRI2_LOADER extension */
1373 if (!dri2_dpy
->is_render_node
) {
1374 dri2_dpy
->loader_extensions
= dri2_loader_extensions
;
1375 if (!dri2_load_driver(disp
)) {
1376 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to load driver");
1380 dri2_dpy
->loader_extensions
= image_loader_extensions
;
1381 if (!dri2_load_driver_dri3(disp
)) {
1382 _eglError(EGL_BAD_ALLOC
, "DRI3: failed to load driver");
1387 if (!dri2_create_screen(disp
))
1390 if (!dri2_setup_extensions(disp
))
1393 dri2_setup_screen(disp
);
1395 dri2_wl_setup_swap_interval(disp
);
1397 /* To use Prime, we must have _DRI_IMAGE v7 at least.
1398 * createImageFromFds support indicates that Prime export/import
1399 * is supported by the driver. Fall back to
1400 * gem names if we don't have Prime support. */
1402 if (dri2_dpy
->image
->base
.version
< 7 ||
1403 dri2_dpy
->image
->createImageFromFds
== NULL
)
1404 dri2_dpy
->capabilities
&= ~WL_DRM_CAPABILITY_PRIME
;
1406 /* We cannot use Gem names with render-nodes, only prime fds (dma-buf).
1407 * The server needs to accept them */
1408 if (dri2_dpy
->is_render_node
&&
1409 !(dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
)) {
1410 _eglLog(_EGL_WARNING
, "wayland-egl: display is not render-node capable");
1414 if (dri2_dpy
->is_different_gpu
&&
1415 (dri2_dpy
->image
->base
.version
< 9 ||
1416 dri2_dpy
->image
->blitImage
== NULL
)) {
1417 _eglLog(_EGL_WARNING
, "wayland-egl: Different GPU selected, but the "
1418 "Image extension in the driver is not "
1419 "compatible. Version 9 or later and blitImage() "
1424 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
1425 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
1429 dri2_set_WL_bind_wayland_display(drv
, disp
);
1430 /* When cannot convert EGLImage to wl_buffer when on a different gpu,
1431 * because the buffer of the EGLImage has likely a tiling mode the server
1432 * gpu won't support. These is no way to check for now. Thus do not support the
1434 if (!dri2_dpy
->is_different_gpu
)
1435 disp
->Extensions
.WL_create_wayland_buffer_from_image
= EGL_TRUE
;
1437 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
1439 disp
->Extensions
.EXT_swap_buffers_with_damage
= EGL_TRUE
;
1441 /* Fill vtbl last to prevent accidentally calling virtual function during
1444 dri2_dpy
->vtbl
= &dri2_wl_display_vtbl
;
1449 dri2_display_destroy(disp
);
1454 dri2_wl_swrast_get_stride_for_format(int format
, int w
)
1456 int visual_idx
= dri2_wl_visual_idx_from_shm_format(format
);
1458 return w
* (dri2_wl_visuals
[visual_idx
].bpp
/ 8);
1462 * Taken from weston shared/os-compatibility.c
1465 #ifndef HAVE_MKOSTEMP
1468 set_cloexec_or_close(int fd
)
1475 flags
= fcntl(fd
, F_GETFD
);
1479 if (fcntl(fd
, F_SETFD
, flags
| FD_CLOEXEC
) == -1)
1492 * Taken from weston shared/os-compatibility.c
1496 create_tmpfile_cloexec(char *tmpname
)
1500 #ifdef HAVE_MKOSTEMP
1501 fd
= mkostemp(tmpname
, O_CLOEXEC
);
1505 fd
= mkstemp(tmpname
);
1507 fd
= set_cloexec_or_close(fd
);
1516 * Taken from weston shared/os-compatibility.c
1518 * Create a new, unique, anonymous file of the given size, and
1519 * return the file descriptor for it. The file descriptor is set
1520 * CLOEXEC. The file is immediately suitable for mmap()'ing
1521 * the given size at offset zero.
1523 * The file should not have a permanent backing store like a disk,
1524 * but may have if XDG_RUNTIME_DIR is not properly implemented in OS.
1526 * The file name is deleted from the file system.
1528 * The file is suitable for buffer sharing between processes by
1529 * transmitting the file descriptor over Unix sockets using the
1530 * SCM_RIGHTS methods.
1532 * If the C library implements posix_fallocate(), it is used to
1533 * guarantee that disk space is available for the file at the
1534 * given size. If disk space is insufficent, errno is set to ENOSPC.
1535 * If posix_fallocate() is not supported, program may receive
1536 * SIGBUS on accessing mmap()'ed file contents instead.
1539 os_create_anonymous_file(off_t size
)
1541 static const char templ
[] = "/mesa-shared-XXXXXX";
1547 path
= getenv("XDG_RUNTIME_DIR");
1553 name
= malloc(strlen(path
) + sizeof(templ
));
1558 strcat(name
, templ
);
1560 fd
= create_tmpfile_cloexec(name
);
1567 ret
= ftruncate(fd
, size
);
1578 dri2_wl_swrast_allocate_buffer(struct dri2_egl_surface
*dri2_surf
,
1579 int format
, int w
, int h
,
1580 void **data
, int *size
,
1581 struct wl_buffer
**buffer
)
1583 struct dri2_egl_display
*dri2_dpy
=
1584 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1585 struct wl_shm_pool
*pool
;
1586 int fd
, stride
, size_map
;
1589 stride
= dri2_wl_swrast_get_stride_for_format(format
, w
);
1590 size_map
= h
* stride
;
1592 /* Create a sharable buffer */
1593 fd
= os_create_anonymous_file(size_map
);
1597 data_map
= mmap(NULL
, size_map
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
1598 if (data_map
== MAP_FAILED
) {
1603 /* Share it in a wl_buffer */
1604 pool
= wl_shm_create_pool(dri2_dpy
->wl_shm
, fd
, size_map
);
1605 wl_proxy_set_queue((struct wl_proxy
*)pool
, dri2_surf
->wl_queue
);
1606 *buffer
= wl_shm_pool_create_buffer(pool
, 0, w
, h
, stride
, format
);
1607 wl_shm_pool_destroy(pool
);
1616 swrast_update_buffers(struct dri2_egl_surface
*dri2_surf
)
1618 struct dri2_egl_display
*dri2_dpy
=
1619 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1621 /* we need to do the following operations only once per frame */
1622 if (dri2_surf
->back
)
1625 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->width
||
1626 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->height
) {
1628 dri2_wl_release_buffers(dri2_surf
);
1630 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
1631 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
1632 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
1633 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
1634 dri2_surf
->current
= NULL
;
1637 /* find back buffer */
1639 /* There might be a buffer release already queued that wasn't processed */
1640 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
1642 /* try get free buffer already created */
1643 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1644 if (!dri2_surf
->color_buffers
[i
].locked
&&
1645 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1646 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1651 /* else choose any another free location */
1652 if (!dri2_surf
->back
) {
1653 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1654 if (!dri2_surf
->color_buffers
[i
].locked
) {
1655 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1656 if (!dri2_wl_swrast_allocate_buffer(dri2_surf
,
1658 dri2_surf
->base
.Width
,
1659 dri2_surf
->base
.Height
,
1660 &dri2_surf
->back
->data
,
1661 &dri2_surf
->back
->data_size
,
1662 &dri2_surf
->back
->wl_buffer
)) {
1663 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
1666 wl_buffer_add_listener(dri2_surf
->back
->wl_buffer
,
1667 &wl_buffer_listener
, dri2_surf
);
1673 if (!dri2_surf
->back
) {
1674 _eglError(EGL_BAD_ALLOC
, "failed to find free buffer");
1678 dri2_surf
->back
->locked
= true;
1680 /* If we have an extra unlocked buffer at this point, we had to do triple
1681 * buffering for a while, but now can go back to just double buffering.
1682 * That means we can free any unlocked buffer now. */
1683 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1684 if (!dri2_surf
->color_buffers
[i
].locked
&&
1685 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1686 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
1687 munmap(dri2_surf
->color_buffers
[i
].data
,
1688 dri2_surf
->color_buffers
[i
].data_size
);
1689 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
1690 dri2_surf
->color_buffers
[i
].data
= NULL
;
1698 dri2_wl_swrast_get_frontbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1700 /* if there has been a resize: */
1701 if (!dri2_surf
->current
)
1704 return dri2_surf
->current
->data
;
1708 dri2_wl_swrast_get_backbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1710 assert(dri2_surf
->back
);
1711 return dri2_surf
->back
->data
;
1715 dri2_wl_swrast_commit_backbuffer(struct dri2_egl_surface
*dri2_surf
)
1717 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1719 while (dri2_surf
->throttle_callback
!= NULL
)
1720 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
1721 dri2_surf
->wl_queue
) == -1)
1724 if (dri2_surf
->base
.SwapInterval
> 0) {
1725 dri2_surf
->throttle_callback
=
1726 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
1727 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1728 &throttle_listener
, dri2_surf
);
1731 dri2_surf
->current
= dri2_surf
->back
;
1732 dri2_surf
->back
= NULL
;
1734 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
1735 dri2_surf
->current
->wl_buffer
,
1736 dri2_surf
->dx
, dri2_surf
->dy
);
1738 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
1739 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
1740 /* reset resize growing parameters */
1744 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
1745 0, 0, INT32_MAX
, INT32_MAX
);
1746 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
1748 /* If we're not waiting for a frame callback then we'll at least throttle
1749 * to a sync callback so that we always give a chance for the compositor to
1750 * handle the commit and send a release event before checking for a free
1752 if (dri2_surf
->throttle_callback
== NULL
) {
1753 dri2_surf
->throttle_callback
= wl_display_sync(dri2_dpy
->wl_dpy_wrapper
);
1754 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1755 &throttle_listener
, dri2_surf
);
1758 wl_display_flush(dri2_dpy
->wl_dpy
);
1762 dri2_wl_swrast_get_drawable_info(__DRIdrawable
* draw
,
1763 int *x
, int *y
, int *w
, int *h
,
1764 void *loaderPrivate
)
1766 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1768 (void) swrast_update_buffers(dri2_surf
);
1771 *w
= dri2_surf
->base
.Width
;
1772 *h
= dri2_surf
->base
.Height
;
1776 dri2_wl_swrast_get_image(__DRIdrawable
* read
,
1777 int x
, int y
, int w
, int h
,
1778 char *data
, void *loaderPrivate
)
1780 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1781 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1782 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1783 int src_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1784 int dst_stride
= copy_width
;
1787 src
= dri2_wl_swrast_get_frontbuffer_data(dri2_surf
);
1789 memset(data
, 0, copy_width
* h
);
1793 assert(data
!= src
);
1794 assert(copy_width
<= src_stride
);
1797 src
+= y
* src_stride
;
1800 if (copy_width
> src_stride
-x_offset
)
1801 copy_width
= src_stride
-x_offset
;
1802 if (h
> dri2_surf
->base
.Height
-y
)
1803 h
= dri2_surf
->base
.Height
-y
;
1806 memcpy(dst
, src
, copy_width
);
1813 dri2_wl_swrast_put_image2(__DRIdrawable
* draw
, int op
,
1814 int x
, int y
, int w
, int h
, int stride
,
1815 char *data
, void *loaderPrivate
)
1817 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1818 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1819 int dst_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1820 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1823 assert(copy_width
<= stride
);
1825 (void) swrast_update_buffers(dri2_surf
);
1826 dst
= dri2_wl_swrast_get_backbuffer_data(dri2_surf
);
1828 /* partial copy, copy old content */
1829 if (copy_width
< dst_stride
)
1830 dri2_wl_swrast_get_image(draw
, 0, 0,
1831 dri2_surf
->base
.Width
, dri2_surf
->base
.Height
,
1832 dst
, loaderPrivate
);
1835 dst
+= y
* dst_stride
;
1839 /* drivers expect we do these checks (and some rely on it) */
1840 if (copy_width
> dst_stride
-x_offset
)
1841 copy_width
= dst_stride
-x_offset
;
1842 if (h
> dri2_surf
->base
.Height
-y
)
1843 h
= dri2_surf
->base
.Height
-y
;
1846 memcpy(dst
, src
, copy_width
);
1850 dri2_wl_swrast_commit_backbuffer(dri2_surf
);
1854 dri2_wl_swrast_put_image(__DRIdrawable
* draw
, int op
,
1855 int x
, int y
, int w
, int h
,
1856 char *data
, void *loaderPrivate
)
1858 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1861 stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1862 dri2_wl_swrast_put_image2(draw
, op
, x
, y
, w
, h
,
1863 stride
, data
, loaderPrivate
);
1867 dri2_wl_swrast_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1869 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1870 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
1872 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
1877 shm_handle_format(void *data
, struct wl_shm
*shm
, uint32_t format
)
1879 struct dri2_egl_display
*dri2_dpy
= data
;
1880 int visual_idx
= dri2_wl_visual_idx_from_shm_format(format
);
1882 if (visual_idx
== -1)
1885 dri2_dpy
->formats
|= (1 << visual_idx
);
1888 static const struct wl_shm_listener shm_listener
= {
1889 .format
= shm_handle_format
1893 registry_handle_global_swrast(void *data
, struct wl_registry
*registry
,
1894 uint32_t name
, const char *interface
,
1897 struct dri2_egl_display
*dri2_dpy
= data
;
1899 if (strcmp(interface
, "wl_shm") == 0) {
1901 wl_registry_bind(registry
, name
, &wl_shm_interface
, 1);
1902 wl_shm_add_listener(dri2_dpy
->wl_shm
, &shm_listener
, dri2_dpy
);
1906 static const struct wl_registry_listener registry_listener_swrast
= {
1907 .global
= registry_handle_global_swrast
,
1908 .global_remove
= registry_handle_global_remove
1911 static const struct dri2_egl_display_vtbl dri2_wl_swrast_display_vtbl
= {
1912 .authenticate
= NULL
,
1913 .create_window_surface
= dri2_wl_create_window_surface
,
1914 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1915 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1916 .destroy_surface
= dri2_wl_destroy_surface
,
1917 .create_image
= dri2_create_image_khr
,
1918 .swap_buffers
= dri2_wl_swrast_swap_buffers
,
1919 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
1920 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1921 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1922 .copy_buffers
= dri2_fallback_copy_buffers
,
1923 .query_buffer_age
= dri2_fallback_query_buffer_age
,
1924 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
1925 .get_sync_values
= dri2_fallback_get_sync_values
,
1926 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1929 static const __DRIswrastLoaderExtension swrast_loader_extension
= {
1930 .base
= { __DRI_SWRAST_LOADER
, 2 },
1932 .getDrawableInfo
= dri2_wl_swrast_get_drawable_info
,
1933 .putImage
= dri2_wl_swrast_put_image
,
1934 .getImage
= dri2_wl_swrast_get_image
,
1935 .putImage2
= dri2_wl_swrast_put_image2
,
1938 static const __DRIextension
*swrast_loader_extensions
[] = {
1939 &swrast_loader_extension
.base
,
1940 &image_lookup_extension
.base
,
1945 dri2_initialize_wayland_swrast(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1947 struct dri2_egl_display
*dri2_dpy
;
1949 loader_set_logger(_eglLog
);
1951 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1953 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1956 disp
->DriverData
= (void *) dri2_dpy
;
1957 if (disp
->PlatformDisplay
== NULL
) {
1958 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1959 if (dri2_dpy
->wl_dpy
== NULL
)
1961 dri2_dpy
->own_device
= true;
1963 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
1966 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
1968 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
1969 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
1972 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
1973 dri2_dpy
->wl_queue
);
1975 if (dri2_dpy
->own_device
)
1976 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
1978 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
1979 wl_registry_add_listener(dri2_dpy
->wl_registry
,
1980 ®istry_listener_swrast
, dri2_dpy
);
1982 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_shm
== NULL
)
1985 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->formats
== 0)
1988 dri2_dpy
->driver_name
= strdup("swrast");
1989 if (!dri2_load_driver_swrast(disp
))
1992 dri2_dpy
->loader_extensions
= swrast_loader_extensions
;
1994 if (!dri2_create_screen(disp
))
1997 if (!dri2_setup_extensions(disp
))
2000 dri2_setup_screen(disp
);
2002 dri2_wl_setup_swap_interval(disp
);
2004 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
2005 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
2009 /* Fill vtbl last to prevent accidentally calling virtual function during
2012 dri2_dpy
->vtbl
= &dri2_wl_swrast_display_vtbl
;
2017 dri2_display_destroy(disp
);
2022 dri2_initialize_wayland(_EGLDriver
*drv
, _EGLDisplay
*disp
)
2024 EGLBoolean initialized
= EGL_FALSE
;
2026 if (!disp
->Options
.ForceSoftware
)
2027 initialized
= dri2_initialize_wayland_drm(drv
, disp
);
2030 initialized
= dri2_initialize_wayland_swrast(drv
, disp
);
2037 dri2_teardown_wayland(struct dri2_egl_display
*dri2_dpy
)
2039 if (dri2_dpy
->wl_drm
)
2040 wl_drm_destroy(dri2_dpy
->wl_drm
);
2041 if (dri2_dpy
->wl_dmabuf
)
2042 zwp_linux_dmabuf_v1_destroy(dri2_dpy
->wl_dmabuf
);
2043 if (dri2_dpy
->wl_shm
)
2044 wl_shm_destroy(dri2_dpy
->wl_shm
);
2045 if (dri2_dpy
->wl_registry
)
2046 wl_registry_destroy(dri2_dpy
->wl_registry
);
2047 if (dri2_dpy
->wl_queue
)
2048 wl_event_queue_destroy(dri2_dpy
->wl_queue
);
2049 if (dri2_dpy
->wl_dpy_wrapper
)
2050 wl_proxy_wrapper_destroy(dri2_dpy
->wl_dpy_wrapper
);
2052 for (int i
= 0; dri2_dpy
->wl_modifiers
&& i
< ARRAY_SIZE(dri2_wl_visuals
); i
++)
2053 u_vector_finish(&dri2_dpy
->wl_modifiers
[i
]);
2054 free(dri2_dpy
->wl_modifiers
);
2056 if (dri2_dpy
->own_device
)
2057 wl_display_disconnect(dri2_dpy
->wl_dpy
);