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_XBGR2101010
, WL_SHM_FORMAT_XBGR2101010
,
80 __DRI_IMAGE_FORMAT_XBGR2101010
, 32,
81 { 0x000003ff, 0x000ffc00, 0x3ff00000, 0x00000000 }
85 WL_DRM_FORMAT_ABGR2101010
, WL_SHM_FORMAT_ABGR2101010
,
86 __DRI_IMAGE_FORMAT_ABGR2101010
, 32,
87 { 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000 }
91 WL_DRM_FORMAT_XRGB8888
, WL_SHM_FORMAT_XRGB8888
,
92 __DRI_IMAGE_FORMAT_XRGB8888
, 32,
93 { 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 }
97 WL_DRM_FORMAT_ARGB8888
, WL_SHM_FORMAT_ARGB8888
,
98 __DRI_IMAGE_FORMAT_ARGB8888
, 32,
99 { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }
103 WL_DRM_FORMAT_RGB565
, WL_SHM_FORMAT_RGB565
,
104 __DRI_IMAGE_FORMAT_RGB565
, 16,
105 { 0xf800, 0x07e0, 0x001f, 0x0000 }
110 dri2_wl_visual_idx_from_config(struct dri2_egl_display
*dri2_dpy
,
111 const __DRIconfig
*config
)
113 unsigned int red
, green
, blue
, alpha
;
115 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_RED_MASK
, &red
);
116 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_GREEN_MASK
, &green
);
117 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_BLUE_MASK
, &blue
);
118 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_ALPHA_MASK
, &alpha
);
120 for (unsigned int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
121 const struct dri2_wl_visual
*wl_visual
= &dri2_wl_visuals
[i
];
123 if (red
== wl_visual
->rgba_masks
[0] &&
124 green
== wl_visual
->rgba_masks
[1] &&
125 blue
== wl_visual
->rgba_masks
[2] &&
126 alpha
== wl_visual
->rgba_masks
[3]) {
135 dri2_wl_visual_idx_from_fourcc(uint32_t fourcc
)
137 for (int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
138 /* wl_drm format codes overlap with DRIImage FourCC codes for all formats
140 if (dri2_wl_visuals
[i
].wl_drm_format
== fourcc
)
148 dri2_wl_visual_idx_from_dri_image_format(uint32_t dri_image_format
)
150 for (int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
151 if (dri2_wl_visuals
[i
].dri_image_format
== dri_image_format
)
159 dri2_wl_visual_idx_from_shm_format(uint32_t shm_format
)
161 for (int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
162 if (dri2_wl_visuals
[i
].wl_shm_format
== shm_format
)
170 roundtrip(struct dri2_egl_display
*dri2_dpy
)
172 return wl_display_roundtrip_queue(dri2_dpy
->wl_dpy
, dri2_dpy
->wl_queue
);
176 wl_buffer_release(void *data
, struct wl_buffer
*buffer
)
178 struct dri2_egl_surface
*dri2_surf
= data
;
181 for (i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); ++i
)
182 if (dri2_surf
->color_buffers
[i
].wl_buffer
== buffer
)
185 if (i
== ARRAY_SIZE(dri2_surf
->color_buffers
)) {
186 wl_buffer_destroy(buffer
);
190 dri2_surf
->color_buffers
[i
].locked
= false;
193 static const struct wl_buffer_listener wl_buffer_listener
= {
194 .release
= wl_buffer_release
198 resize_callback(struct wl_egl_window
*wl_win
, void *data
)
200 struct dri2_egl_surface
*dri2_surf
= data
;
201 struct dri2_egl_display
*dri2_dpy
=
202 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
204 /* Update the surface size as soon as native window is resized; from user
205 * pov, this makes the effect that resize is done immediately after native
206 * window resize, without requiring to wait until the first draw.
208 * A more detailed and lengthy explanation can be found at
209 * https://lists.freedesktop.org/archives/mesa-dev/2018-June/196474.html
211 if (!dri2_surf
->back
) {
212 dri2_surf
->base
.Width
= wl_win
->width
;
213 dri2_surf
->base
.Height
= wl_win
->height
;
215 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
219 destroy_window_callback(void *data
)
221 struct dri2_egl_surface
*dri2_surf
= data
;
222 dri2_surf
->wl_win
= NULL
;
225 static struct wl_surface
*
226 get_wl_surface_proxy(struct wl_egl_window
*window
)
228 /* Version 3 of wl_egl_window introduced a version field at the same
229 * location where a pointer to wl_surface was stored. Thus, if
230 * window->version is dereferenceable, we've been given an older version of
231 * wl_egl_window, and window->version points to wl_surface */
232 if (_eglPointerIsDereferencable((void *)(window
->version
))) {
233 return wl_proxy_create_wrapper((void *)(window
->version
));
235 return wl_proxy_create_wrapper(window
->surface
);
239 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
242 dri2_wl_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
243 _EGLConfig
*conf
, void *native_window
,
244 const EGLint
*attrib_list
)
246 __DRIcreateNewDrawableFunc createNewDrawable
;
247 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
248 struct dri2_egl_config
*dri2_conf
= dri2_egl_config(conf
);
249 struct wl_egl_window
*window
= native_window
;
250 struct dri2_egl_surface
*dri2_surf
;
252 const __DRIconfig
*config
;
254 dri2_surf
= calloc(1, sizeof *dri2_surf
);
256 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
260 if (!dri2_init_surface(&dri2_surf
->base
, disp
, EGL_WINDOW_BIT
, conf
,
264 config
= dri2_get_dri_config(dri2_conf
, EGL_WINDOW_BIT
,
265 dri2_surf
->base
.GLColorspace
);
268 _eglError(EGL_BAD_MATCH
, "Unsupported surfacetype/colorspace configuration");
272 dri2_surf
->base
.Width
= window
->width
;
273 dri2_surf
->base
.Height
= window
->height
;
275 visual_idx
= dri2_wl_visual_idx_from_config(dri2_dpy
, config
);
276 assert(visual_idx
!= -1);
278 if (dri2_dpy
->wl_dmabuf
|| dri2_dpy
->wl_drm
) {
279 dri2_surf
->format
= dri2_wl_visuals
[visual_idx
].wl_drm_format
;
281 assert(dri2_dpy
->wl_shm
);
282 dri2_surf
->format
= dri2_wl_visuals
[visual_idx
].wl_shm_format
;
285 dri2_surf
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
286 if (!dri2_surf
->wl_queue
) {
287 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
291 if (dri2_dpy
->wl_drm
) {
292 dri2_surf
->wl_drm_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_drm
);
293 if (!dri2_surf
->wl_drm_wrapper
) {
294 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
297 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_drm_wrapper
,
298 dri2_surf
->wl_queue
);
301 dri2_surf
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
302 if (!dri2_surf
->wl_dpy_wrapper
) {
303 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
306 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_dpy_wrapper
,
307 dri2_surf
->wl_queue
);
309 dri2_surf
->wl_surface_wrapper
= get_wl_surface_proxy(window
);
310 if (!dri2_surf
->wl_surface_wrapper
) {
311 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
312 goto cleanup_dpy_wrapper
;
314 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_surface_wrapper
,
315 dri2_surf
->wl_queue
);
317 dri2_surf
->wl_win
= window
;
318 dri2_surf
->wl_win
->driver_private
= dri2_surf
;
319 dri2_surf
->wl_win
->destroy_window_callback
= destroy_window_callback
;
321 dri2_surf
->wl_win
->resize_callback
= resize_callback
;
323 if (dri2_dpy
->image_driver
)
324 createNewDrawable
= dri2_dpy
->image_driver
->createNewDrawable
;
325 else if (dri2_dpy
->dri2
)
326 createNewDrawable
= dri2_dpy
->dri2
->createNewDrawable
;
328 createNewDrawable
= dri2_dpy
->swrast
->createNewDrawable
;
330 dri2_surf
->dri_drawable
= (*createNewDrawable
)(dri2_dpy
->dri_screen
, config
,
332 if (dri2_surf
->dri_drawable
== NULL
) {
333 _eglError(EGL_BAD_ALLOC
, "createNewDrawable");
334 goto cleanup_surf_wrapper
;
337 dri2_surf
->base
.SwapInterval
= dri2_dpy
->default_swap_interval
;
339 return &dri2_surf
->base
;
341 cleanup_surf_wrapper
:
342 wl_proxy_wrapper_destroy(dri2_surf
->wl_surface_wrapper
);
344 wl_proxy_wrapper_destroy(dri2_surf
->wl_dpy_wrapper
);
346 if (dri2_surf
->wl_drm_wrapper
)
347 wl_proxy_wrapper_destroy(dri2_surf
->wl_drm_wrapper
);
349 wl_event_queue_destroy(dri2_surf
->wl_queue
);
357 dri2_wl_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
358 _EGLConfig
*conf
, void *native_window
,
359 const EGLint
*attrib_list
)
361 /* From the EGL_EXT_platform_wayland spec, version 3:
363 * It is not valid to call eglCreatePlatformPixmapSurfaceEXT with a <dpy>
364 * that belongs to Wayland. Any such call fails and generates
367 _eglError(EGL_BAD_PARAMETER
, "cannot create EGL pixmap surfaces on "
373 * Called via eglDestroySurface(), drv->API.DestroySurface().
376 dri2_wl_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
378 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
379 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
383 dri2_dpy
->core
->destroyDrawable(dri2_surf
->dri_drawable
);
385 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
386 if (dri2_surf
->color_buffers
[i
].wl_buffer
)
387 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
388 if (dri2_surf
->color_buffers
[i
].dri_image
)
389 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
390 if (dri2_surf
->color_buffers
[i
].linear_copy
)
391 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
392 if (dri2_surf
->color_buffers
[i
].data
)
393 munmap(dri2_surf
->color_buffers
[i
].data
,
394 dri2_surf
->color_buffers
[i
].data_size
);
398 dri2_egl_surface_free_local_buffers(dri2_surf
);
400 if (dri2_surf
->throttle_callback
)
401 wl_callback_destroy(dri2_surf
->throttle_callback
);
403 if (dri2_surf
->wl_win
) {
404 dri2_surf
->wl_win
->driver_private
= NULL
;
405 dri2_surf
->wl_win
->resize_callback
= NULL
;
406 dri2_surf
->wl_win
->destroy_window_callback
= NULL
;
409 wl_proxy_wrapper_destroy(dri2_surf
->wl_surface_wrapper
);
410 wl_proxy_wrapper_destroy(dri2_surf
->wl_dpy_wrapper
);
411 if (dri2_surf
->wl_drm_wrapper
)
412 wl_proxy_wrapper_destroy(dri2_surf
->wl_drm_wrapper
);
413 wl_event_queue_destroy(dri2_surf
->wl_queue
);
415 dri2_fini_surface(surf
);
422 dri2_wl_release_buffers(struct dri2_egl_surface
*dri2_surf
)
424 struct dri2_egl_display
*dri2_dpy
=
425 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
427 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
428 if (dri2_surf
->color_buffers
[i
].wl_buffer
&&
429 !dri2_surf
->color_buffers
[i
].locked
)
430 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
431 if (dri2_surf
->color_buffers
[i
].dri_image
)
432 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
433 if (dri2_surf
->color_buffers
[i
].linear_copy
)
434 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
435 if (dri2_surf
->color_buffers
[i
].data
)
436 munmap(dri2_surf
->color_buffers
[i
].data
,
437 dri2_surf
->color_buffers
[i
].data_size
);
439 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
440 dri2_surf
->color_buffers
[i
].dri_image
= NULL
;
441 dri2_surf
->color_buffers
[i
].linear_copy
= NULL
;
442 dri2_surf
->color_buffers
[i
].data
= NULL
;
443 dri2_surf
->color_buffers
[i
].locked
= false;
447 dri2_egl_surface_free_local_buffers(dri2_surf
);
451 get_back_bo(struct dri2_egl_surface
*dri2_surf
)
453 struct dri2_egl_display
*dri2_dpy
=
454 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
457 unsigned int dri_image_format
;
461 visual_idx
= dri2_wl_visual_idx_from_fourcc(dri2_surf
->format
);
462 assert(visual_idx
!= -1);
463 dri_image_format
= dri2_wl_visuals
[visual_idx
].dri_image_format
;
464 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
[visual_idx
]);
465 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
[visual_idx
]);
467 /* There might be a buffer release already queued that wasn't processed */
468 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
470 while (dri2_surf
->back
== NULL
) {
471 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
472 /* Get an unlocked buffer, preferably one with a dri_buffer
473 * already allocated. */
474 if (dri2_surf
->color_buffers
[i
].locked
)
476 if (dri2_surf
->back
== NULL
)
477 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
478 else if (dri2_surf
->back
->dri_image
== NULL
)
479 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
485 /* If we don't have a buffer, then block on the server to release one for
486 * us, and try again. wl_display_dispatch_queue will process any pending
487 * events, however not all servers flush on issuing a buffer release
488 * event. So, we spam the server with roundtrips as they always cause a
491 if (wl_display_roundtrip_queue(dri2_dpy
->wl_dpy
,
492 dri2_surf
->wl_queue
) < 0)
496 if (dri2_surf
->back
== NULL
)
499 use_flags
= __DRI_IMAGE_USE_SHARE
| __DRI_IMAGE_USE_BACKBUFFER
;
501 if (dri2_dpy
->is_different_gpu
&&
502 dri2_surf
->back
->linear_copy
== NULL
) {
503 /* The LINEAR modifier should be a perfect alias of the LINEAR use
504 * flag; try the new interface first before the old, then fall back. */
505 if (dri2_dpy
->image
->base
.version
>= 15 &&
506 dri2_dpy
->image
->createImageWithModifiers
) {
507 uint64_t linear_mod
= DRM_FORMAT_MOD_LINEAR
;
509 dri2_surf
->back
->linear_copy
=
510 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
511 dri2_surf
->base
.Width
,
512 dri2_surf
->base
.Height
,
518 dri2_surf
->back
->linear_copy
=
519 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
520 dri2_surf
->base
.Width
,
521 dri2_surf
->base
.Height
,
524 __DRI_IMAGE_USE_LINEAR
,
527 if (dri2_surf
->back
->linear_copy
== NULL
)
531 if (dri2_surf
->back
->dri_image
== NULL
) {
532 /* If our DRIImage implementation does not support
533 * createImageWithModifiers, then fall back to the old createImage,
534 * and hope it allocates an image which is acceptable to the winsys.
536 if (num_modifiers
&& dri2_dpy
->image
->base
.version
>= 15 &&
537 dri2_dpy
->image
->createImageWithModifiers
) {
538 dri2_surf
->back
->dri_image
=
539 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
540 dri2_surf
->base
.Width
,
541 dri2_surf
->base
.Height
,
547 dri2_surf
->back
->dri_image
=
548 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
549 dri2_surf
->base
.Width
,
550 dri2_surf
->base
.Height
,
552 dri2_dpy
->is_different_gpu
?
557 dri2_surf
->back
->age
= 0;
559 if (dri2_surf
->back
->dri_image
== NULL
)
562 dri2_surf
->back
->locked
= true;
569 back_bo_to_dri_buffer(struct dri2_egl_surface
*dri2_surf
, __DRIbuffer
*buffer
)
571 struct dri2_egl_display
*dri2_dpy
=
572 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
576 image
= dri2_surf
->back
->dri_image
;
578 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
579 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &pitch
);
581 buffer
->attachment
= __DRI_BUFFER_BACK_LEFT
;
583 buffer
->pitch
= pitch
;
589 update_buffers(struct dri2_egl_surface
*dri2_surf
)
591 struct dri2_egl_display
*dri2_dpy
=
592 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
594 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->attached_width
||
595 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->attached_height
) {
597 dri2_wl_release_buffers(dri2_surf
);
599 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
600 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
601 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
602 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
605 if (get_back_bo(dri2_surf
) < 0) {
606 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
610 /* If we have an extra unlocked buffer at this point, we had to do triple
611 * buffering for a while, but now can go back to just double buffering.
612 * That means we can free any unlocked buffer now. */
613 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
614 if (!dri2_surf
->color_buffers
[i
].locked
&&
615 dri2_surf
->color_buffers
[i
].wl_buffer
) {
616 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
617 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
618 if (dri2_dpy
->is_different_gpu
)
619 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
620 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
621 dri2_surf
->color_buffers
[i
].dri_image
= NULL
;
622 dri2_surf
->color_buffers
[i
].linear_copy
= NULL
;
630 dri2_wl_get_buffers_with_format(__DRIdrawable
* driDrawable
,
631 int *width
, int *height
,
632 unsigned int *attachments
, int count
,
633 int *out_count
, void *loaderPrivate
)
635 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
638 if (update_buffers(dri2_surf
) < 0)
641 for (i
= 0, j
= 0; i
< 2 * count
; i
+= 2, j
++) {
644 switch (attachments
[i
]) {
645 case __DRI_BUFFER_BACK_LEFT
:
646 back_bo_to_dri_buffer(dri2_surf
, &dri2_surf
->buffers
[j
]);
649 local
= dri2_egl_surface_alloc_local_buffer(dri2_surf
, attachments
[i
],
653 _eglError(EGL_BAD_ALLOC
, "failed to allocate local buffer");
656 dri2_surf
->buffers
[j
] = *local
;
665 *width
= dri2_surf
->base
.Width
;
666 *height
= dri2_surf
->base
.Height
;
668 return dri2_surf
->buffers
;
672 dri2_wl_get_buffers(__DRIdrawable
* driDrawable
,
673 int *width
, int *height
,
674 unsigned int *attachments
, int count
,
675 int *out_count
, void *loaderPrivate
)
677 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
678 unsigned int *attachments_with_format
;
680 int visual_idx
= dri2_wl_visual_idx_from_fourcc(dri2_surf
->format
);
682 if (visual_idx
== -1)
685 attachments_with_format
= calloc(count
, 2 * sizeof(unsigned int));
686 if (!attachments_with_format
) {
691 for (int i
= 0; i
< count
; ++i
) {
692 attachments_with_format
[2*i
] = attachments
[i
];
693 attachments_with_format
[2*i
+ 1] = dri2_wl_visuals
[visual_idx
].bpp
;
697 dri2_wl_get_buffers_with_format(driDrawable
,
699 attachments_with_format
, count
,
700 out_count
, loaderPrivate
);
702 free(attachments_with_format
);
708 image_get_buffers(__DRIdrawable
*driDrawable
,
712 uint32_t buffer_mask
,
713 struct __DRIimageList
*buffers
)
715 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
717 if (update_buffers(dri2_surf
) < 0)
720 buffers
->image_mask
= __DRI_IMAGE_BUFFER_BACK
;
721 buffers
->back
= dri2_surf
->back
->dri_image
;
727 dri2_wl_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
730 (void) loaderPrivate
;
733 static const __DRIdri2LoaderExtension dri2_loader_extension
= {
734 .base
= { __DRI_DRI2_LOADER
, 3 },
736 .getBuffers
= dri2_wl_get_buffers
,
737 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
738 .getBuffersWithFormat
= dri2_wl_get_buffers_with_format
,
741 static const __DRIimageLoaderExtension image_loader_extension
= {
742 .base
= { __DRI_IMAGE_LOADER
, 1 },
744 .getBuffers
= image_get_buffers
,
745 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
749 wayland_throttle_callback(void *data
,
750 struct wl_callback
*callback
,
753 struct dri2_egl_surface
*dri2_surf
= data
;
755 dri2_surf
->throttle_callback
= NULL
;
756 wl_callback_destroy(callback
);
759 static const struct wl_callback_listener throttle_listener
= {
760 .done
= wayland_throttle_callback
764 get_fourcc(struct dri2_egl_display
*dri2_dpy
,
765 __DRIimage
*image
, int *fourcc
)
771 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FOURCC
,
776 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
,
781 visual_idx
= dri2_wl_visual_idx_from_dri_image_format(dri_format
);
782 if (visual_idx
== -1)
785 *fourcc
= dri2_wl_visuals
[visual_idx
].wl_drm_format
;
789 static struct wl_buffer
*
790 create_wl_buffer(struct dri2_egl_display
*dri2_dpy
,
791 struct dri2_egl_surface
*dri2_surf
,
794 struct wl_buffer
*ret
;
796 int width
, height
, fourcc
, num_planes
;
797 uint64_t modifier
= DRM_FORMAT_MOD_INVALID
;
799 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_WIDTH
, &width
);
800 query
&= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_HEIGHT
,
802 query
&= get_fourcc(dri2_dpy
, image
, &fourcc
);
806 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NUM_PLANES
,
811 if (dri2_dpy
->image
->base
.version
>= 15) {
814 query
= dri2_dpy
->image
->queryImage(image
,
815 __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
,
817 query
&= dri2_dpy
->image
->queryImage(image
,
818 __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
,
821 modifier
= combine_u32_into_u64(mod_hi
, mod_lo
);
825 if (dri2_dpy
->wl_dmabuf
&& modifier
!= DRM_FORMAT_MOD_INVALID
) {
826 struct zwp_linux_buffer_params_v1
*params
;
829 /* We don't need a wrapper for wl_dmabuf objects, because we have to
830 * create the intermediate params object; we can set the queue on this,
831 * and the wl_buffer inherits it race-free. */
832 params
= zwp_linux_dmabuf_v1_create_params(dri2_dpy
->wl_dmabuf
);
834 wl_proxy_set_queue((struct wl_proxy
*) params
, dri2_surf
->wl_queue
);
836 for (i
= 0; i
< num_planes
; i
++) {
841 p_image
= dri2_dpy
->image
->fromPlanar(image
, i
, NULL
);
847 query
= dri2_dpy
->image
->queryImage(p_image
,
848 __DRI_IMAGE_ATTRIB_FD
,
850 query
&= dri2_dpy
->image
->queryImage(p_image
,
851 __DRI_IMAGE_ATTRIB_STRIDE
,
853 query
&= dri2_dpy
->image
->queryImage(p_image
,
854 __DRI_IMAGE_ATTRIB_OFFSET
,
856 if (image
!= p_image
)
857 dri2_dpy
->image
->destroyImage(p_image
);
862 zwp_linux_buffer_params_v1_destroy(params
);
866 zwp_linux_buffer_params_v1_add(params
, fd
, i
, offset
, stride
,
867 modifier
>> 32, modifier
& 0xffffffff);
871 ret
= zwp_linux_buffer_params_v1_create_immed(params
, width
, height
,
873 zwp_linux_buffer_params_v1_destroy(params
);
874 } else if (dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
) {
875 struct wl_drm
*wl_drm
=
876 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
882 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FD
, &fd
);
883 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
884 ret
= wl_drm_create_prime_buffer(wl_drm
, fd
, width
, height
, fourcc
, 0,
888 struct wl_drm
*wl_drm
=
889 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
895 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
896 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
897 ret
= wl_drm_create_buffer(wl_drm
, name
, width
, height
, stride
, fourcc
);
904 try_damage_buffer(struct dri2_egl_surface
*dri2_surf
,
908 if (wl_proxy_get_version((struct wl_proxy
*) dri2_surf
->wl_surface_wrapper
)
909 < WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION
)
912 for (int i
= 0; i
< n_rects
; i
++) {
913 const int *rect
= &rects
[i
* 4];
915 wl_surface_damage_buffer(dri2_surf
->wl_surface_wrapper
,
917 dri2_surf
->base
.Height
- rect
[1] - rect
[3],
923 * Called via eglSwapBuffers(), drv->API.SwapBuffers().
926 dri2_wl_swap_buffers_with_damage(_EGLDriver
*drv
,
932 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
933 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
935 while (dri2_surf
->throttle_callback
!= NULL
)
936 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
937 dri2_surf
->wl_queue
) == -1)
940 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
941 if (dri2_surf
->color_buffers
[i
].age
> 0)
942 dri2_surf
->color_buffers
[i
].age
++;
944 /* Make sure we have a back buffer in case we're swapping without ever
946 if (get_back_bo(dri2_surf
) < 0)
947 return _eglError(EGL_BAD_ALLOC
, "dri2_swap_buffers");
949 if (draw
->SwapInterval
> 0) {
950 dri2_surf
->throttle_callback
=
951 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
952 wl_callback_add_listener(dri2_surf
->throttle_callback
,
953 &throttle_listener
, dri2_surf
);
956 dri2_surf
->back
->age
= 1;
957 dri2_surf
->current
= dri2_surf
->back
;
958 dri2_surf
->back
= NULL
;
960 if (!dri2_surf
->current
->wl_buffer
) {
963 if (dri2_dpy
->is_different_gpu
)
964 image
= dri2_surf
->current
->linear_copy
;
966 image
= dri2_surf
->current
->dri_image
;
968 dri2_surf
->current
->wl_buffer
=
969 create_wl_buffer(dri2_dpy
, dri2_surf
, image
);
971 wl_buffer_add_listener(dri2_surf
->current
->wl_buffer
,
972 &wl_buffer_listener
, dri2_surf
);
975 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
976 dri2_surf
->current
->wl_buffer
,
977 dri2_surf
->dx
, dri2_surf
->dy
);
979 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
980 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
981 /* reset resize growing parameters */
985 /* If the compositor doesn't support damage_buffer, we deliberately
986 * ignore the damage region and post maximum damage, due to
987 * https://bugs.freedesktop.org/78190 */
988 if (!n_rects
|| !try_damage_buffer(dri2_surf
, rects
, n_rects
))
989 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
990 0, 0, INT32_MAX
, INT32_MAX
);
992 if (dri2_dpy
->is_different_gpu
) {
993 _EGLContext
*ctx
= _eglGetCurrentContext();
994 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
995 dri2_dpy
->image
->blitImage(dri2_ctx
->dri_context
,
996 dri2_surf
->current
->linear_copy
,
997 dri2_surf
->current
->dri_image
,
998 0, 0, dri2_surf
->base
.Width
,
999 dri2_surf
->base
.Height
,
1000 0, 0, dri2_surf
->base
.Width
,
1001 dri2_surf
->base
.Height
, 0);
1004 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
1005 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
1007 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
1009 /* If we're not waiting for a frame callback then we'll at least throttle
1010 * to a sync callback so that we always give a chance for the compositor to
1011 * handle the commit and send a release event before checking for a free
1013 if (dri2_surf
->throttle_callback
== NULL
) {
1014 dri2_surf
->throttle_callback
= wl_display_sync(dri2_surf
->wl_dpy_wrapper
);
1015 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1016 &throttle_listener
, dri2_surf
);
1019 wl_display_flush(dri2_dpy
->wl_dpy
);
1025 dri2_wl_query_buffer_age(_EGLDriver
*drv
,
1026 _EGLDisplay
*disp
, _EGLSurface
*surface
)
1028 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
1030 if (get_back_bo(dri2_surf
) < 0) {
1031 _eglError(EGL_BAD_ALLOC
, "dri2_query_buffer_age");
1035 return dri2_surf
->back
->age
;
1039 dri2_wl_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1041 return dri2_wl_swap_buffers_with_damage(drv
, disp
, draw
, NULL
, 0);
1044 static struct wl_buffer
*
1045 dri2_wl_create_wayland_buffer_from_image(_EGLDriver
*drv
,
1049 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1050 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
1051 __DRIimage
*image
= dri2_img
->dri_image
;
1052 struct wl_buffer
*buffer
;
1053 int format
, visual_idx
;
1055 /* Check the upstream display supports this buffer's format. */
1056 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
, &format
);
1057 visual_idx
= dri2_wl_visual_idx_from_dri_image_format(format
);
1058 if (visual_idx
== -1)
1061 if (!(dri2_dpy
->formats
& (1u << visual_idx
)))
1064 buffer
= create_wl_buffer(dri2_dpy
, NULL
, image
);
1066 /* The buffer object will have been created with our internal event queue
1067 * because it is using wl_dmabuf/wl_drm as a proxy factory. We want the
1068 * buffer to be used by the application so we'll reset it to the display's
1069 * default event queue. This isn't actually racy, as the only event the
1070 * buffer can get is a buffer release, which doesn't happen with an explicit
1073 wl_proxy_set_queue((struct wl_proxy
*) buffer
, NULL
);
1078 _eglError(EGL_BAD_MATCH
, "unsupported image format");
1083 dri2_wl_authenticate(_EGLDisplay
*disp
, uint32_t id
)
1085 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1088 if (dri2_dpy
->is_render_node
) {
1089 _eglLog(_EGL_WARNING
, "wayland-egl: client asks server to "
1090 "authenticate for render-nodes");
1093 dri2_dpy
->authenticated
= false;
1095 wl_drm_authenticate(dri2_dpy
->wl_drm
, id
);
1096 if (roundtrip(dri2_dpy
) < 0)
1099 if (!dri2_dpy
->authenticated
)
1102 /* reset authenticated */
1103 dri2_dpy
->authenticated
= true;
1109 drm_handle_device(void *data
, struct wl_drm
*drm
, const char *device
)
1111 struct dri2_egl_display
*dri2_dpy
= data
;
1114 dri2_dpy
->device_name
= strdup(device
);
1115 if (!dri2_dpy
->device_name
)
1118 dri2_dpy
->fd
= loader_open_device(dri2_dpy
->device_name
);
1119 if (dri2_dpy
->fd
== -1) {
1120 _eglLog(_EGL_WARNING
, "wayland-egl: could not open %s (%s)",
1121 dri2_dpy
->device_name
, strerror(errno
));
1125 if (drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
) {
1126 dri2_dpy
->authenticated
= true;
1128 drmGetMagic(dri2_dpy
->fd
, &magic
);
1129 wl_drm_authenticate(dri2_dpy
->wl_drm
, magic
);
1134 drm_handle_format(void *data
, struct wl_drm
*drm
, uint32_t format
)
1136 struct dri2_egl_display
*dri2_dpy
= data
;
1137 int visual_idx
= dri2_wl_visual_idx_from_fourcc(format
);
1139 if (visual_idx
== -1)
1142 dri2_dpy
->formats
|= (1u << visual_idx
);
1146 drm_handle_capabilities(void *data
, struct wl_drm
*drm
, uint32_t value
)
1148 struct dri2_egl_display
*dri2_dpy
= data
;
1150 dri2_dpy
->capabilities
= value
;
1154 drm_handle_authenticated(void *data
, struct wl_drm
*drm
)
1156 struct dri2_egl_display
*dri2_dpy
= data
;
1158 dri2_dpy
->authenticated
= true;
1161 static const struct wl_drm_listener drm_listener
= {
1162 .device
= drm_handle_device
,
1163 .format
= drm_handle_format
,
1164 .authenticated
= drm_handle_authenticated
,
1165 .capabilities
= drm_handle_capabilities
1169 dmabuf_ignore_format(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1172 /* formats are implicitly advertised by the 'modifier' event, so ignore */
1176 dmabuf_handle_modifier(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1177 uint32_t format
, uint32_t modifier_hi
,
1178 uint32_t modifier_lo
)
1180 struct dri2_egl_display
*dri2_dpy
= data
;
1181 int visual_idx
= dri2_wl_visual_idx_from_fourcc(format
);
1184 if (visual_idx
== -1)
1187 if (modifier_hi
== (DRM_FORMAT_MOD_INVALID
>> 32) &&
1188 modifier_lo
== (DRM_FORMAT_MOD_INVALID
& 0xffffffff))
1191 dri2_dpy
->formats
|= (1u << visual_idx
);
1193 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
[visual_idx
]);
1194 *mod
= combine_u32_into_u64(modifier_hi
, modifier_lo
);
1197 static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener
= {
1198 .format
= dmabuf_ignore_format
,
1199 .modifier
= dmabuf_handle_modifier
,
1203 registry_handle_global_drm(void *data
, struct wl_registry
*registry
,
1204 uint32_t name
, const char *interface
,
1207 struct dri2_egl_display
*dri2_dpy
= data
;
1209 if (strcmp(interface
, "wl_drm") == 0) {
1211 wl_registry_bind(registry
, name
, &wl_drm_interface
, MIN2(version
, 2));
1212 wl_drm_add_listener(dri2_dpy
->wl_drm
, &drm_listener
, dri2_dpy
);
1213 } else if (strcmp(interface
, "zwp_linux_dmabuf_v1") == 0 && version
>= 3) {
1214 dri2_dpy
->wl_dmabuf
=
1215 wl_registry_bind(registry
, name
, &zwp_linux_dmabuf_v1_interface
,
1217 zwp_linux_dmabuf_v1_add_listener(dri2_dpy
->wl_dmabuf
, &dmabuf_listener
,
1223 registry_handle_global_remove(void *data
, struct wl_registry
*registry
,
1228 static const struct wl_registry_listener registry_listener_drm
= {
1229 .global
= registry_handle_global_drm
,
1230 .global_remove
= registry_handle_global_remove
1234 dri2_wl_setup_swap_interval(_EGLDisplay
*disp
)
1236 /* We can't use values greater than 1 on Wayland because we are using the
1237 * frame callback to synchronise the frame and the only way we be sure to
1238 * get a frame callback is to attach a new buffer. Therefore we can't just
1239 * sit drawing nothing to wait until the next ‘n’ frame callbacks */
1241 dri2_setup_swap_interval(disp
, 1);
1244 static const struct dri2_egl_display_vtbl dri2_wl_display_vtbl
= {
1245 .authenticate
= dri2_wl_authenticate
,
1246 .create_window_surface
= dri2_wl_create_window_surface
,
1247 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1248 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1249 .destroy_surface
= dri2_wl_destroy_surface
,
1250 .create_image
= dri2_create_image_khr
,
1251 .swap_buffers
= dri2_wl_swap_buffers
,
1252 .swap_buffers_with_damage
= dri2_wl_swap_buffers_with_damage
,
1253 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1254 .set_damage_region
= dri2_fallback_set_damage_region
,
1255 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1256 .copy_buffers
= dri2_fallback_copy_buffers
,
1257 .query_buffer_age
= dri2_wl_query_buffer_age
,
1258 .create_wayland_buffer_from_image
= dri2_wl_create_wayland_buffer_from_image
,
1259 .get_sync_values
= dri2_fallback_get_sync_values
,
1260 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1263 static const __DRIextension
*dri2_loader_extensions
[] = {
1264 &dri2_loader_extension
.base
,
1265 &image_loader_extension
.base
,
1266 &image_lookup_extension
.base
,
1267 &use_invalidate
.base
,
1271 static const __DRIextension
*image_loader_extensions
[] = {
1272 &image_loader_extension
.base
,
1273 &image_lookup_extension
.base
,
1274 &use_invalidate
.base
,
1279 dri2_wl_add_configs_for_visuals(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1281 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1282 unsigned int format_count
[ARRAY_SIZE(dri2_wl_visuals
)] = { 0 };
1283 unsigned int count
= 0;
1285 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
1286 for (unsigned j
= 0; j
< ARRAY_SIZE(dri2_wl_visuals
); j
++) {
1287 struct dri2_egl_config
*dri2_conf
;
1289 if (!(dri2_dpy
->formats
& (1u << j
)))
1292 dri2_conf
= dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
1293 count
+ 1, EGL_WINDOW_BIT
, NULL
, dri2_wl_visuals
[j
].rgba_masks
);
1295 if (dri2_conf
->base
.ConfigID
== count
+ 1)
1302 for (unsigned i
= 0; i
< ARRAY_SIZE(format_count
); i
++) {
1303 if (!format_count
[i
]) {
1304 _eglLog(_EGL_DEBUG
, "No DRI config supports native format %s",
1305 dri2_wl_visuals
[i
].format_name
);
1309 return (count
!= 0);
1313 dri2_initialize_wayland_drm(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1315 struct dri2_egl_display
*dri2_dpy
;
1317 loader_set_logger(_eglLog
);
1319 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1321 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1324 disp
->DriverData
= (void *) dri2_dpy
;
1325 if (disp
->PlatformDisplay
== NULL
) {
1326 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1327 if (dri2_dpy
->wl_dpy
== NULL
)
1329 dri2_dpy
->own_device
= true;
1331 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
1334 dri2_dpy
->wl_modifiers
=
1335 calloc(ARRAY_SIZE(dri2_wl_visuals
), sizeof(*dri2_dpy
->wl_modifiers
));
1336 if (!dri2_dpy
->wl_modifiers
)
1338 for (int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
1339 if (!u_vector_init(&dri2_dpy
->wl_modifiers
[i
], sizeof(uint64_t), 32))
1343 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
1345 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
1346 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
1349 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
1350 dri2_dpy
->wl_queue
);
1352 if (dri2_dpy
->own_device
)
1353 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
1355 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
1356 wl_registry_add_listener(dri2_dpy
->wl_registry
,
1357 ®istry_listener_drm
, dri2_dpy
);
1358 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_drm
== NULL
)
1361 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->fd
== -1)
1364 if (roundtrip(dri2_dpy
) < 0 || !dri2_dpy
->authenticated
)
1367 dri2_dpy
->fd
= loader_get_user_preferred_fd(dri2_dpy
->fd
,
1368 &dri2_dpy
->is_different_gpu
);
1369 if (dri2_dpy
->is_different_gpu
) {
1370 free(dri2_dpy
->device_name
);
1371 dri2_dpy
->device_name
= loader_get_device_name_for_fd(dri2_dpy
->fd
);
1372 if (!dri2_dpy
->device_name
) {
1373 _eglError(EGL_BAD_ALLOC
, "wayland-egl: failed to get device name "
1374 "for requested GPU");
1379 /* we have to do the check now, because loader_get_user_preferred_fd
1380 * will return a render-node when the requested gpu is different
1381 * to the server, but also if the client asks for the same gpu than
1382 * the server by requesting its pci-id */
1383 dri2_dpy
->is_render_node
= drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
;
1385 dri2_dpy
->driver_name
= loader_get_driver_for_fd(dri2_dpy
->fd
);
1386 if (dri2_dpy
->driver_name
== NULL
) {
1387 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to get driver name");
1391 /* render nodes cannot use Gem names, and thus do not support
1392 * the __DRI_DRI2_LOADER extension */
1393 if (!dri2_dpy
->is_render_node
) {
1394 dri2_dpy
->loader_extensions
= dri2_loader_extensions
;
1395 if (!dri2_load_driver(disp
)) {
1396 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to load driver");
1400 dri2_dpy
->loader_extensions
= image_loader_extensions
;
1401 if (!dri2_load_driver_dri3(disp
)) {
1402 _eglError(EGL_BAD_ALLOC
, "DRI3: failed to load driver");
1407 if (!dri2_create_screen(disp
))
1410 if (!dri2_setup_extensions(disp
))
1413 dri2_setup_screen(disp
);
1415 dri2_wl_setup_swap_interval(disp
);
1417 /* To use Prime, we must have _DRI_IMAGE v7 at least.
1418 * createImageFromFds support indicates that Prime export/import
1419 * is supported by the driver. Fall back to
1420 * gem names if we don't have Prime support. */
1422 if (dri2_dpy
->image
->base
.version
< 7 ||
1423 dri2_dpy
->image
->createImageFromFds
== NULL
)
1424 dri2_dpy
->capabilities
&= ~WL_DRM_CAPABILITY_PRIME
;
1426 /* We cannot use Gem names with render-nodes, only prime fds (dma-buf).
1427 * The server needs to accept them */
1428 if (dri2_dpy
->is_render_node
&&
1429 !(dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
)) {
1430 _eglLog(_EGL_WARNING
, "wayland-egl: display is not render-node capable");
1434 if (dri2_dpy
->is_different_gpu
&&
1435 (dri2_dpy
->image
->base
.version
< 9 ||
1436 dri2_dpy
->image
->blitImage
== NULL
)) {
1437 _eglLog(_EGL_WARNING
, "wayland-egl: Different GPU selected, but the "
1438 "Image extension in the driver is not "
1439 "compatible. Version 9 or later and blitImage() "
1444 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
1445 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
1449 dri2_set_WL_bind_wayland_display(drv
, disp
);
1450 /* When cannot convert EGLImage to wl_buffer when on a different gpu,
1451 * because the buffer of the EGLImage has likely a tiling mode the server
1452 * gpu won't support. These is no way to check for now. Thus do not support the
1454 if (!dri2_dpy
->is_different_gpu
)
1455 disp
->Extensions
.WL_create_wayland_buffer_from_image
= EGL_TRUE
;
1457 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
1459 disp
->Extensions
.EXT_swap_buffers_with_damage
= EGL_TRUE
;
1461 /* Fill vtbl last to prevent accidentally calling virtual function during
1464 dri2_dpy
->vtbl
= &dri2_wl_display_vtbl
;
1469 dri2_display_destroy(disp
);
1474 dri2_wl_swrast_get_stride_for_format(int format
, int w
)
1476 int visual_idx
= dri2_wl_visual_idx_from_shm_format(format
);
1478 assume(visual_idx
!= -1);
1480 return w
* (dri2_wl_visuals
[visual_idx
].bpp
/ 8);
1484 * Taken from weston shared/os-compatibility.c
1487 #ifndef HAVE_MKOSTEMP
1490 set_cloexec_or_close(int fd
)
1497 flags
= fcntl(fd
, F_GETFD
);
1501 if (fcntl(fd
, F_SETFD
, flags
| FD_CLOEXEC
) == -1)
1514 * Taken from weston shared/os-compatibility.c
1518 create_tmpfile_cloexec(char *tmpname
)
1522 #ifdef HAVE_MKOSTEMP
1523 fd
= mkostemp(tmpname
, O_CLOEXEC
);
1527 fd
= mkstemp(tmpname
);
1529 fd
= set_cloexec_or_close(fd
);
1538 * Taken from weston shared/os-compatibility.c
1540 * Create a new, unique, anonymous file of the given size, and
1541 * return the file descriptor for it. The file descriptor is set
1542 * CLOEXEC. The file is immediately suitable for mmap()'ing
1543 * the given size at offset zero.
1545 * The file should not have a permanent backing store like a disk,
1546 * but may have if XDG_RUNTIME_DIR is not properly implemented in OS.
1548 * The file name is deleted from the file system.
1550 * The file is suitable for buffer sharing between processes by
1551 * transmitting the file descriptor over Unix sockets using the
1552 * SCM_RIGHTS methods.
1554 * If the C library implements posix_fallocate(), it is used to
1555 * guarantee that disk space is available for the file at the
1556 * given size. If disk space is insufficient, errno is set to ENOSPC.
1557 * If posix_fallocate() is not supported, program may receive
1558 * SIGBUS on accessing mmap()'ed file contents instead.
1561 os_create_anonymous_file(off_t size
)
1563 static const char templ
[] = "/mesa-shared-XXXXXX";
1569 path
= getenv("XDG_RUNTIME_DIR");
1575 name
= malloc(strlen(path
) + sizeof(templ
));
1580 strcat(name
, templ
);
1582 fd
= create_tmpfile_cloexec(name
);
1589 ret
= ftruncate(fd
, size
);
1600 dri2_wl_swrast_allocate_buffer(struct dri2_egl_surface
*dri2_surf
,
1601 int format
, int w
, int h
,
1602 void **data
, int *size
,
1603 struct wl_buffer
**buffer
)
1605 struct dri2_egl_display
*dri2_dpy
=
1606 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1607 struct wl_shm_pool
*pool
;
1608 int fd
, stride
, size_map
;
1611 stride
= dri2_wl_swrast_get_stride_for_format(format
, w
);
1612 size_map
= h
* stride
;
1614 /* Create a shareable buffer */
1615 fd
= os_create_anonymous_file(size_map
);
1619 data_map
= mmap(NULL
, size_map
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
1620 if (data_map
== MAP_FAILED
) {
1625 /* Share it in a wl_buffer */
1626 pool
= wl_shm_create_pool(dri2_dpy
->wl_shm
, fd
, size_map
);
1627 wl_proxy_set_queue((struct wl_proxy
*)pool
, dri2_surf
->wl_queue
);
1628 *buffer
= wl_shm_pool_create_buffer(pool
, 0, w
, h
, stride
, format
);
1629 wl_shm_pool_destroy(pool
);
1638 swrast_update_buffers(struct dri2_egl_surface
*dri2_surf
)
1640 struct dri2_egl_display
*dri2_dpy
=
1641 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1643 /* we need to do the following operations only once per frame */
1644 if (dri2_surf
->back
)
1647 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->attached_width
||
1648 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->attached_height
) {
1650 dri2_wl_release_buffers(dri2_surf
);
1652 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
1653 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
1654 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
1655 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
1656 dri2_surf
->current
= NULL
;
1659 /* find back buffer */
1661 /* There might be a buffer release already queued that wasn't processed */
1662 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
1664 /* try get free buffer already created */
1665 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1666 if (!dri2_surf
->color_buffers
[i
].locked
&&
1667 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1668 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1673 /* else choose any another free location */
1674 if (!dri2_surf
->back
) {
1675 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1676 if (!dri2_surf
->color_buffers
[i
].locked
) {
1677 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1678 if (!dri2_wl_swrast_allocate_buffer(dri2_surf
,
1680 dri2_surf
->base
.Width
,
1681 dri2_surf
->base
.Height
,
1682 &dri2_surf
->back
->data
,
1683 &dri2_surf
->back
->data_size
,
1684 &dri2_surf
->back
->wl_buffer
)) {
1685 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
1688 wl_buffer_add_listener(dri2_surf
->back
->wl_buffer
,
1689 &wl_buffer_listener
, dri2_surf
);
1695 if (!dri2_surf
->back
) {
1696 _eglError(EGL_BAD_ALLOC
, "failed to find free buffer");
1700 dri2_surf
->back
->locked
= true;
1702 /* If we have an extra unlocked buffer at this point, we had to do triple
1703 * buffering for a while, but now can go back to just double buffering.
1704 * That means we can free any unlocked buffer now. */
1705 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1706 if (!dri2_surf
->color_buffers
[i
].locked
&&
1707 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1708 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
1709 munmap(dri2_surf
->color_buffers
[i
].data
,
1710 dri2_surf
->color_buffers
[i
].data_size
);
1711 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
1712 dri2_surf
->color_buffers
[i
].data
= NULL
;
1720 dri2_wl_swrast_get_frontbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1722 /* if there has been a resize: */
1723 if (!dri2_surf
->current
)
1726 return dri2_surf
->current
->data
;
1730 dri2_wl_swrast_get_backbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1732 assert(dri2_surf
->back
);
1733 return dri2_surf
->back
->data
;
1737 dri2_wl_swrast_commit_backbuffer(struct dri2_egl_surface
*dri2_surf
)
1739 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1741 while (dri2_surf
->throttle_callback
!= NULL
)
1742 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
1743 dri2_surf
->wl_queue
) == -1)
1746 if (dri2_surf
->base
.SwapInterval
> 0) {
1747 dri2_surf
->throttle_callback
=
1748 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
1749 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1750 &throttle_listener
, dri2_surf
);
1753 dri2_surf
->current
= dri2_surf
->back
;
1754 dri2_surf
->back
= NULL
;
1756 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
1757 dri2_surf
->current
->wl_buffer
,
1758 dri2_surf
->dx
, dri2_surf
->dy
);
1760 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
1761 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
1762 /* reset resize growing parameters */
1766 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
1767 0, 0, INT32_MAX
, INT32_MAX
);
1768 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
1770 /* If we're not waiting for a frame callback then we'll at least throttle
1771 * to a sync callback so that we always give a chance for the compositor to
1772 * handle the commit and send a release event before checking for a free
1774 if (dri2_surf
->throttle_callback
== NULL
) {
1775 dri2_surf
->throttle_callback
= wl_display_sync(dri2_surf
->wl_dpy_wrapper
);
1776 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1777 &throttle_listener
, dri2_surf
);
1780 wl_display_flush(dri2_dpy
->wl_dpy
);
1784 dri2_wl_swrast_get_drawable_info(__DRIdrawable
* draw
,
1785 int *x
, int *y
, int *w
, int *h
,
1786 void *loaderPrivate
)
1788 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1790 (void) swrast_update_buffers(dri2_surf
);
1793 *w
= dri2_surf
->base
.Width
;
1794 *h
= dri2_surf
->base
.Height
;
1798 dri2_wl_swrast_get_image(__DRIdrawable
* read
,
1799 int x
, int y
, int w
, int h
,
1800 char *data
, void *loaderPrivate
)
1802 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1803 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1804 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1805 int src_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1806 int dst_stride
= copy_width
;
1809 src
= dri2_wl_swrast_get_frontbuffer_data(dri2_surf
);
1811 memset(data
, 0, copy_width
* h
);
1815 assert(data
!= src
);
1816 assert(copy_width
<= src_stride
);
1819 src
+= y
* src_stride
;
1822 if (copy_width
> src_stride
-x_offset
)
1823 copy_width
= src_stride
-x_offset
;
1824 if (h
> dri2_surf
->base
.Height
-y
)
1825 h
= dri2_surf
->base
.Height
-y
;
1828 memcpy(dst
, src
, copy_width
);
1835 dri2_wl_swrast_put_image2(__DRIdrawable
* draw
, int op
,
1836 int x
, int y
, int w
, int h
, int stride
,
1837 char *data
, void *loaderPrivate
)
1839 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1840 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1841 int dst_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1842 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1845 assert(copy_width
<= stride
);
1847 (void) swrast_update_buffers(dri2_surf
);
1848 dst
= dri2_wl_swrast_get_backbuffer_data(dri2_surf
);
1850 /* partial copy, copy old content */
1851 if (copy_width
< dst_stride
)
1852 dri2_wl_swrast_get_image(draw
, 0, 0,
1853 dri2_surf
->base
.Width
, dri2_surf
->base
.Height
,
1854 dst
, loaderPrivate
);
1857 dst
+= y
* dst_stride
;
1861 /* drivers expect we do these checks (and some rely on it) */
1862 if (copy_width
> dst_stride
-x_offset
)
1863 copy_width
= dst_stride
-x_offset
;
1864 if (h
> dri2_surf
->base
.Height
-y
)
1865 h
= dri2_surf
->base
.Height
-y
;
1868 memcpy(dst
, src
, copy_width
);
1872 dri2_wl_swrast_commit_backbuffer(dri2_surf
);
1876 dri2_wl_swrast_put_image(__DRIdrawable
* draw
, int op
,
1877 int x
, int y
, int w
, int h
,
1878 char *data
, void *loaderPrivate
)
1880 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1883 stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1884 dri2_wl_swrast_put_image2(draw
, op
, x
, y
, w
, h
,
1885 stride
, data
, loaderPrivate
);
1889 dri2_wl_swrast_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1891 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1892 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
1894 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
1899 shm_handle_format(void *data
, struct wl_shm
*shm
, uint32_t format
)
1901 struct dri2_egl_display
*dri2_dpy
= data
;
1902 int visual_idx
= dri2_wl_visual_idx_from_shm_format(format
);
1904 if (visual_idx
== -1)
1907 dri2_dpy
->formats
|= (1u << visual_idx
);
1910 static const struct wl_shm_listener shm_listener
= {
1911 .format
= shm_handle_format
1915 registry_handle_global_swrast(void *data
, struct wl_registry
*registry
,
1916 uint32_t name
, const char *interface
,
1919 struct dri2_egl_display
*dri2_dpy
= data
;
1921 if (strcmp(interface
, "wl_shm") == 0) {
1923 wl_registry_bind(registry
, name
, &wl_shm_interface
, 1);
1924 wl_shm_add_listener(dri2_dpy
->wl_shm
, &shm_listener
, dri2_dpy
);
1928 static const struct wl_registry_listener registry_listener_swrast
= {
1929 .global
= registry_handle_global_swrast
,
1930 .global_remove
= registry_handle_global_remove
1933 static const struct dri2_egl_display_vtbl dri2_wl_swrast_display_vtbl
= {
1934 .authenticate
= NULL
,
1935 .create_window_surface
= dri2_wl_create_window_surface
,
1936 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1937 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1938 .destroy_surface
= dri2_wl_destroy_surface
,
1939 .create_image
= dri2_create_image_khr
,
1940 .swap_buffers
= dri2_wl_swrast_swap_buffers
,
1941 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
1942 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1943 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1944 .copy_buffers
= dri2_fallback_copy_buffers
,
1945 .query_buffer_age
= dri2_fallback_query_buffer_age
,
1946 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
1947 .get_sync_values
= dri2_fallback_get_sync_values
,
1948 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1951 static const __DRIswrastLoaderExtension swrast_loader_extension
= {
1952 .base
= { __DRI_SWRAST_LOADER
, 2 },
1954 .getDrawableInfo
= dri2_wl_swrast_get_drawable_info
,
1955 .putImage
= dri2_wl_swrast_put_image
,
1956 .getImage
= dri2_wl_swrast_get_image
,
1957 .putImage2
= dri2_wl_swrast_put_image2
,
1960 static const __DRIextension
*swrast_loader_extensions
[] = {
1961 &swrast_loader_extension
.base
,
1962 &image_lookup_extension
.base
,
1967 dri2_initialize_wayland_swrast(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1969 struct dri2_egl_display
*dri2_dpy
;
1971 loader_set_logger(_eglLog
);
1973 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1975 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1978 disp
->DriverData
= (void *) dri2_dpy
;
1979 if (disp
->PlatformDisplay
== NULL
) {
1980 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1981 if (dri2_dpy
->wl_dpy
== NULL
)
1983 dri2_dpy
->own_device
= true;
1985 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
1988 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
1990 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
1991 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
1994 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
1995 dri2_dpy
->wl_queue
);
1997 if (dri2_dpy
->own_device
)
1998 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
2000 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
2001 wl_registry_add_listener(dri2_dpy
->wl_registry
,
2002 ®istry_listener_swrast
, dri2_dpy
);
2004 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_shm
== NULL
)
2007 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->formats
== 0)
2010 dri2_dpy
->driver_name
= strdup("swrast");
2011 if (!dri2_load_driver_swrast(disp
))
2014 dri2_dpy
->loader_extensions
= swrast_loader_extensions
;
2016 if (!dri2_create_screen(disp
))
2019 if (!dri2_setup_extensions(disp
))
2022 dri2_setup_screen(disp
);
2024 dri2_wl_setup_swap_interval(disp
);
2026 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
2027 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
2031 /* Fill vtbl last to prevent accidentally calling virtual function during
2034 dri2_dpy
->vtbl
= &dri2_wl_swrast_display_vtbl
;
2039 dri2_display_destroy(disp
);
2044 dri2_initialize_wayland(_EGLDriver
*drv
, _EGLDisplay
*disp
)
2046 EGLBoolean initialized
= EGL_FALSE
;
2048 if (!disp
->Options
.ForceSoftware
)
2049 initialized
= dri2_initialize_wayland_drm(drv
, disp
);
2052 initialized
= dri2_initialize_wayland_swrast(drv
, disp
);
2059 dri2_teardown_wayland(struct dri2_egl_display
*dri2_dpy
)
2061 if (dri2_dpy
->wl_drm
)
2062 wl_drm_destroy(dri2_dpy
->wl_drm
);
2063 if (dri2_dpy
->wl_dmabuf
)
2064 zwp_linux_dmabuf_v1_destroy(dri2_dpy
->wl_dmabuf
);
2065 if (dri2_dpy
->wl_shm
)
2066 wl_shm_destroy(dri2_dpy
->wl_shm
);
2067 if (dri2_dpy
->wl_registry
)
2068 wl_registry_destroy(dri2_dpy
->wl_registry
);
2069 if (dri2_dpy
->wl_queue
)
2070 wl_event_queue_destroy(dri2_dpy
->wl_queue
);
2071 if (dri2_dpy
->wl_dpy_wrapper
)
2072 wl_proxy_wrapper_destroy(dri2_dpy
->wl_dpy_wrapper
);
2074 for (int i
= 0; dri2_dpy
->wl_modifiers
&& i
< ARRAY_SIZE(dri2_wl_visuals
); i
++)
2075 u_vector_finish(&dri2_dpy
->wl_modifiers
[i
]);
2076 free(dri2_dpy
->wl_modifiers
);
2078 if (dri2_dpy
->own_device
)
2079 wl_display_disconnect(dri2_dpy
->wl_dpy
);