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
= (uint64_t) mod_hi
<< 32;
822 modifier
|= (uint64_t) (mod_lo
& 0xffffffff);
826 if (dri2_dpy
->wl_dmabuf
&& modifier
!= DRM_FORMAT_MOD_INVALID
) {
827 struct zwp_linux_buffer_params_v1
*params
;
830 /* We don't need a wrapper for wl_dmabuf objects, because we have to
831 * create the intermediate params object; we can set the queue on this,
832 * and the wl_buffer inherits it race-free. */
833 params
= zwp_linux_dmabuf_v1_create_params(dri2_dpy
->wl_dmabuf
);
835 wl_proxy_set_queue((struct wl_proxy
*) params
, dri2_surf
->wl_queue
);
837 for (i
= 0; i
< num_planes
; i
++) {
842 p_image
= dri2_dpy
->image
->fromPlanar(image
, i
, NULL
);
848 query
= dri2_dpy
->image
->queryImage(p_image
,
849 __DRI_IMAGE_ATTRIB_FD
,
851 query
&= dri2_dpy
->image
->queryImage(p_image
,
852 __DRI_IMAGE_ATTRIB_STRIDE
,
854 query
&= dri2_dpy
->image
->queryImage(p_image
,
855 __DRI_IMAGE_ATTRIB_OFFSET
,
857 if (image
!= p_image
)
858 dri2_dpy
->image
->destroyImage(p_image
);
863 zwp_linux_buffer_params_v1_destroy(params
);
867 zwp_linux_buffer_params_v1_add(params
, fd
, i
, offset
, stride
,
868 modifier
>> 32, modifier
& 0xffffffff);
872 ret
= zwp_linux_buffer_params_v1_create_immed(params
, width
, height
,
874 zwp_linux_buffer_params_v1_destroy(params
);
875 } else if (dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
) {
876 struct wl_drm
*wl_drm
=
877 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
883 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FD
, &fd
);
884 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
885 ret
= wl_drm_create_prime_buffer(wl_drm
, fd
, width
, height
, fourcc
, 0,
889 struct wl_drm
*wl_drm
=
890 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
896 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
897 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
898 ret
= wl_drm_create_buffer(wl_drm
, name
, width
, height
, stride
, fourcc
);
905 try_damage_buffer(struct dri2_egl_surface
*dri2_surf
,
909 if (wl_proxy_get_version((struct wl_proxy
*) dri2_surf
->wl_surface_wrapper
)
910 < WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION
)
913 for (int i
= 0; i
< n_rects
; i
++) {
914 const int *rect
= &rects
[i
* 4];
916 wl_surface_damage_buffer(dri2_surf
->wl_surface_wrapper
,
918 dri2_surf
->base
.Height
- rect
[1] - rect
[3],
924 * Called via eglSwapBuffers(), drv->API.SwapBuffers().
927 dri2_wl_swap_buffers_with_damage(_EGLDriver
*drv
,
933 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
934 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
936 while (dri2_surf
->throttle_callback
!= NULL
)
937 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
938 dri2_surf
->wl_queue
) == -1)
941 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
942 if (dri2_surf
->color_buffers
[i
].age
> 0)
943 dri2_surf
->color_buffers
[i
].age
++;
945 /* Make sure we have a back buffer in case we're swapping without ever
947 if (get_back_bo(dri2_surf
) < 0)
948 return _eglError(EGL_BAD_ALLOC
, "dri2_swap_buffers");
950 if (draw
->SwapInterval
> 0) {
951 dri2_surf
->throttle_callback
=
952 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
953 wl_callback_add_listener(dri2_surf
->throttle_callback
,
954 &throttle_listener
, dri2_surf
);
957 dri2_surf
->back
->age
= 1;
958 dri2_surf
->current
= dri2_surf
->back
;
959 dri2_surf
->back
= NULL
;
961 if (!dri2_surf
->current
->wl_buffer
) {
964 if (dri2_dpy
->is_different_gpu
)
965 image
= dri2_surf
->current
->linear_copy
;
967 image
= dri2_surf
->current
->dri_image
;
969 dri2_surf
->current
->wl_buffer
=
970 create_wl_buffer(dri2_dpy
, dri2_surf
, image
);
972 wl_buffer_add_listener(dri2_surf
->current
->wl_buffer
,
973 &wl_buffer_listener
, dri2_surf
);
976 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
977 dri2_surf
->current
->wl_buffer
,
978 dri2_surf
->dx
, dri2_surf
->dy
);
980 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
981 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
982 /* reset resize growing parameters */
986 /* If the compositor doesn't support damage_buffer, we deliberately
987 * ignore the damage region and post maximum damage, due to
988 * https://bugs.freedesktop.org/78190 */
989 if (!n_rects
|| !try_damage_buffer(dri2_surf
, rects
, n_rects
))
990 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
991 0, 0, INT32_MAX
, INT32_MAX
);
993 if (dri2_dpy
->is_different_gpu
) {
994 _EGLContext
*ctx
= _eglGetCurrentContext();
995 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
996 dri2_dpy
->image
->blitImage(dri2_ctx
->dri_context
,
997 dri2_surf
->current
->linear_copy
,
998 dri2_surf
->current
->dri_image
,
999 0, 0, dri2_surf
->base
.Width
,
1000 dri2_surf
->base
.Height
,
1001 0, 0, dri2_surf
->base
.Width
,
1002 dri2_surf
->base
.Height
, 0);
1005 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
1006 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
1008 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
1010 /* If we're not waiting for a frame callback then we'll at least throttle
1011 * to a sync callback so that we always give a chance for the compositor to
1012 * handle the commit and send a release event before checking for a free
1014 if (dri2_surf
->throttle_callback
== NULL
) {
1015 dri2_surf
->throttle_callback
= wl_display_sync(dri2_surf
->wl_dpy_wrapper
);
1016 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1017 &throttle_listener
, dri2_surf
);
1020 wl_display_flush(dri2_dpy
->wl_dpy
);
1026 dri2_wl_query_buffer_age(_EGLDriver
*drv
,
1027 _EGLDisplay
*disp
, _EGLSurface
*surface
)
1029 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
1031 if (get_back_bo(dri2_surf
) < 0) {
1032 _eglError(EGL_BAD_ALLOC
, "dri2_query_buffer_age");
1036 return dri2_surf
->back
->age
;
1040 dri2_wl_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1042 return dri2_wl_swap_buffers_with_damage(drv
, disp
, draw
, NULL
, 0);
1045 static struct wl_buffer
*
1046 dri2_wl_create_wayland_buffer_from_image(_EGLDriver
*drv
,
1050 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1051 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
1052 __DRIimage
*image
= dri2_img
->dri_image
;
1053 struct wl_buffer
*buffer
;
1054 int format
, visual_idx
;
1056 /* Check the upstream display supports this buffer's format. */
1057 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
, &format
);
1058 visual_idx
= dri2_wl_visual_idx_from_dri_image_format(format
);
1059 if (visual_idx
== -1)
1062 if (!(dri2_dpy
->formats
& (1u << visual_idx
)))
1065 buffer
= create_wl_buffer(dri2_dpy
, NULL
, image
);
1067 /* The buffer object will have been created with our internal event queue
1068 * because it is using wl_dmabuf/wl_drm as a proxy factory. We want the
1069 * buffer to be used by the application so we'll reset it to the display's
1070 * default event queue. This isn't actually racy, as the only event the
1071 * buffer can get is a buffer release, which doesn't happen with an explicit
1074 wl_proxy_set_queue((struct wl_proxy
*) buffer
, NULL
);
1079 _eglError(EGL_BAD_MATCH
, "unsupported image format");
1084 dri2_wl_authenticate(_EGLDisplay
*disp
, uint32_t id
)
1086 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1089 if (dri2_dpy
->is_render_node
) {
1090 _eglLog(_EGL_WARNING
, "wayland-egl: client asks server to "
1091 "authenticate for render-nodes");
1094 dri2_dpy
->authenticated
= false;
1096 wl_drm_authenticate(dri2_dpy
->wl_drm
, id
);
1097 if (roundtrip(dri2_dpy
) < 0)
1100 if (!dri2_dpy
->authenticated
)
1103 /* reset authenticated */
1104 dri2_dpy
->authenticated
= true;
1110 drm_handle_device(void *data
, struct wl_drm
*drm
, const char *device
)
1112 struct dri2_egl_display
*dri2_dpy
= data
;
1115 dri2_dpy
->device_name
= strdup(device
);
1116 if (!dri2_dpy
->device_name
)
1119 dri2_dpy
->fd
= loader_open_device(dri2_dpy
->device_name
);
1120 if (dri2_dpy
->fd
== -1) {
1121 _eglLog(_EGL_WARNING
, "wayland-egl: could not open %s (%s)",
1122 dri2_dpy
->device_name
, strerror(errno
));
1126 if (drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
) {
1127 dri2_dpy
->authenticated
= true;
1129 drmGetMagic(dri2_dpy
->fd
, &magic
);
1130 wl_drm_authenticate(dri2_dpy
->wl_drm
, magic
);
1135 drm_handle_format(void *data
, struct wl_drm
*drm
, uint32_t format
)
1137 struct dri2_egl_display
*dri2_dpy
= data
;
1138 int visual_idx
= dri2_wl_visual_idx_from_fourcc(format
);
1140 if (visual_idx
== -1)
1143 dri2_dpy
->formats
|= (1u << visual_idx
);
1147 drm_handle_capabilities(void *data
, struct wl_drm
*drm
, uint32_t value
)
1149 struct dri2_egl_display
*dri2_dpy
= data
;
1151 dri2_dpy
->capabilities
= value
;
1155 drm_handle_authenticated(void *data
, struct wl_drm
*drm
)
1157 struct dri2_egl_display
*dri2_dpy
= data
;
1159 dri2_dpy
->authenticated
= true;
1162 static const struct wl_drm_listener drm_listener
= {
1163 .device
= drm_handle_device
,
1164 .format
= drm_handle_format
,
1165 .authenticated
= drm_handle_authenticated
,
1166 .capabilities
= drm_handle_capabilities
1170 dmabuf_ignore_format(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1173 /* formats are implicitly advertised by the 'modifier' event, so ignore */
1177 dmabuf_handle_modifier(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1178 uint32_t format
, uint32_t modifier_hi
,
1179 uint32_t modifier_lo
)
1181 struct dri2_egl_display
*dri2_dpy
= data
;
1182 int visual_idx
= dri2_wl_visual_idx_from_fourcc(format
);
1185 if (visual_idx
== -1)
1188 if (modifier_hi
== (DRM_FORMAT_MOD_INVALID
>> 32) &&
1189 modifier_lo
== (DRM_FORMAT_MOD_INVALID
& 0xffffffff))
1192 dri2_dpy
->formats
|= (1u << visual_idx
);
1194 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
[visual_idx
]);
1195 *mod
= (uint64_t) modifier_hi
<< 32;
1196 *mod
|= (uint64_t) (modifier_lo
& 0xffffffff);
1199 static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener
= {
1200 .format
= dmabuf_ignore_format
,
1201 .modifier
= dmabuf_handle_modifier
,
1205 registry_handle_global_drm(void *data
, struct wl_registry
*registry
,
1206 uint32_t name
, const char *interface
,
1209 struct dri2_egl_display
*dri2_dpy
= data
;
1211 if (strcmp(interface
, "wl_drm") == 0) {
1213 wl_registry_bind(registry
, name
, &wl_drm_interface
, MIN2(version
, 2));
1214 wl_drm_add_listener(dri2_dpy
->wl_drm
, &drm_listener
, dri2_dpy
);
1215 } else if (strcmp(interface
, "zwp_linux_dmabuf_v1") == 0 && version
>= 3) {
1216 dri2_dpy
->wl_dmabuf
=
1217 wl_registry_bind(registry
, name
, &zwp_linux_dmabuf_v1_interface
,
1219 zwp_linux_dmabuf_v1_add_listener(dri2_dpy
->wl_dmabuf
, &dmabuf_listener
,
1225 registry_handle_global_remove(void *data
, struct wl_registry
*registry
,
1230 static const struct wl_registry_listener registry_listener_drm
= {
1231 .global
= registry_handle_global_drm
,
1232 .global_remove
= registry_handle_global_remove
1236 dri2_wl_setup_swap_interval(_EGLDisplay
*disp
)
1238 /* We can't use values greater than 1 on Wayland because we are using the
1239 * frame callback to synchronise the frame and the only way we be sure to
1240 * get a frame callback is to attach a new buffer. Therefore we can't just
1241 * sit drawing nothing to wait until the next ‘n’ frame callbacks */
1243 dri2_setup_swap_interval(disp
, 1);
1246 static const struct dri2_egl_display_vtbl dri2_wl_display_vtbl
= {
1247 .authenticate
= dri2_wl_authenticate
,
1248 .create_window_surface
= dri2_wl_create_window_surface
,
1249 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1250 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1251 .destroy_surface
= dri2_wl_destroy_surface
,
1252 .create_image
= dri2_create_image_khr
,
1253 .swap_buffers
= dri2_wl_swap_buffers
,
1254 .swap_buffers_with_damage
= dri2_wl_swap_buffers_with_damage
,
1255 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1256 .set_damage_region
= dri2_fallback_set_damage_region
,
1257 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1258 .copy_buffers
= dri2_fallback_copy_buffers
,
1259 .query_buffer_age
= dri2_wl_query_buffer_age
,
1260 .create_wayland_buffer_from_image
= dri2_wl_create_wayland_buffer_from_image
,
1261 .get_sync_values
= dri2_fallback_get_sync_values
,
1262 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1265 static const __DRIextension
*dri2_loader_extensions
[] = {
1266 &dri2_loader_extension
.base
,
1267 &image_loader_extension
.base
,
1268 &image_lookup_extension
.base
,
1269 &use_invalidate
.base
,
1273 static const __DRIextension
*image_loader_extensions
[] = {
1274 &image_loader_extension
.base
,
1275 &image_lookup_extension
.base
,
1276 &use_invalidate
.base
,
1281 dri2_wl_add_configs_for_visuals(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1283 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1284 unsigned int format_count
[ARRAY_SIZE(dri2_wl_visuals
)] = { 0 };
1285 unsigned int count
= 0;
1287 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
1288 for (unsigned j
= 0; j
< ARRAY_SIZE(dri2_wl_visuals
); j
++) {
1289 struct dri2_egl_config
*dri2_conf
;
1291 if (!(dri2_dpy
->formats
& (1u << j
)))
1294 dri2_conf
= dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
1295 count
+ 1, EGL_WINDOW_BIT
, NULL
, dri2_wl_visuals
[j
].rgba_masks
);
1297 if (dri2_conf
->base
.ConfigID
== count
+ 1)
1304 for (unsigned i
= 0; i
< ARRAY_SIZE(format_count
); i
++) {
1305 if (!format_count
[i
]) {
1306 _eglLog(_EGL_DEBUG
, "No DRI config supports native format %s",
1307 dri2_wl_visuals
[i
].format_name
);
1311 return (count
!= 0);
1315 dri2_initialize_wayland_drm(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1317 struct dri2_egl_display
*dri2_dpy
;
1319 loader_set_logger(_eglLog
);
1321 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1323 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1326 disp
->DriverData
= (void *) dri2_dpy
;
1327 if (disp
->PlatformDisplay
== NULL
) {
1328 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1329 if (dri2_dpy
->wl_dpy
== NULL
)
1331 dri2_dpy
->own_device
= true;
1333 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
1336 dri2_dpy
->wl_modifiers
=
1337 calloc(ARRAY_SIZE(dri2_wl_visuals
), sizeof(*dri2_dpy
->wl_modifiers
));
1338 if (!dri2_dpy
->wl_modifiers
)
1340 for (int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
1341 if (!u_vector_init(&dri2_dpy
->wl_modifiers
[i
], sizeof(uint64_t), 32))
1345 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
1347 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
1348 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
1351 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
1352 dri2_dpy
->wl_queue
);
1354 if (dri2_dpy
->own_device
)
1355 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
1357 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
1358 wl_registry_add_listener(dri2_dpy
->wl_registry
,
1359 ®istry_listener_drm
, dri2_dpy
);
1360 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_drm
== NULL
)
1363 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->fd
== -1)
1366 if (roundtrip(dri2_dpy
) < 0 || !dri2_dpy
->authenticated
)
1369 dri2_dpy
->fd
= loader_get_user_preferred_fd(dri2_dpy
->fd
,
1370 &dri2_dpy
->is_different_gpu
);
1371 if (dri2_dpy
->is_different_gpu
) {
1372 free(dri2_dpy
->device_name
);
1373 dri2_dpy
->device_name
= loader_get_device_name_for_fd(dri2_dpy
->fd
);
1374 if (!dri2_dpy
->device_name
) {
1375 _eglError(EGL_BAD_ALLOC
, "wayland-egl: failed to get device name "
1376 "for requested GPU");
1381 /* we have to do the check now, because loader_get_user_preferred_fd
1382 * will return a render-node when the requested gpu is different
1383 * to the server, but also if the client asks for the same gpu than
1384 * the server by requesting its pci-id */
1385 dri2_dpy
->is_render_node
= drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
;
1387 dri2_dpy
->driver_name
= loader_get_driver_for_fd(dri2_dpy
->fd
);
1388 if (dri2_dpy
->driver_name
== NULL
) {
1389 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to get driver name");
1393 /* render nodes cannot use Gem names, and thus do not support
1394 * the __DRI_DRI2_LOADER extension */
1395 if (!dri2_dpy
->is_render_node
) {
1396 dri2_dpy
->loader_extensions
= dri2_loader_extensions
;
1397 if (!dri2_load_driver(disp
)) {
1398 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to load driver");
1402 dri2_dpy
->loader_extensions
= image_loader_extensions
;
1403 if (!dri2_load_driver_dri3(disp
)) {
1404 _eglError(EGL_BAD_ALLOC
, "DRI3: failed to load driver");
1409 if (!dri2_create_screen(disp
))
1412 if (!dri2_setup_extensions(disp
))
1415 dri2_setup_screen(disp
);
1417 dri2_wl_setup_swap_interval(disp
);
1419 /* To use Prime, we must have _DRI_IMAGE v7 at least.
1420 * createImageFromFds support indicates that Prime export/import
1421 * is supported by the driver. Fall back to
1422 * gem names if we don't have Prime support. */
1424 if (dri2_dpy
->image
->base
.version
< 7 ||
1425 dri2_dpy
->image
->createImageFromFds
== NULL
)
1426 dri2_dpy
->capabilities
&= ~WL_DRM_CAPABILITY_PRIME
;
1428 /* We cannot use Gem names with render-nodes, only prime fds (dma-buf).
1429 * The server needs to accept them */
1430 if (dri2_dpy
->is_render_node
&&
1431 !(dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
)) {
1432 _eglLog(_EGL_WARNING
, "wayland-egl: display is not render-node capable");
1436 if (dri2_dpy
->is_different_gpu
&&
1437 (dri2_dpy
->image
->base
.version
< 9 ||
1438 dri2_dpy
->image
->blitImage
== NULL
)) {
1439 _eglLog(_EGL_WARNING
, "wayland-egl: Different GPU selected, but the "
1440 "Image extension in the driver is not "
1441 "compatible. Version 9 or later and blitImage() "
1446 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
1447 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
1451 dri2_set_WL_bind_wayland_display(drv
, disp
);
1452 /* When cannot convert EGLImage to wl_buffer when on a different gpu,
1453 * because the buffer of the EGLImage has likely a tiling mode the server
1454 * gpu won't support. These is no way to check for now. Thus do not support the
1456 if (!dri2_dpy
->is_different_gpu
)
1457 disp
->Extensions
.WL_create_wayland_buffer_from_image
= EGL_TRUE
;
1459 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
1461 disp
->Extensions
.EXT_swap_buffers_with_damage
= EGL_TRUE
;
1463 /* Fill vtbl last to prevent accidentally calling virtual function during
1466 dri2_dpy
->vtbl
= &dri2_wl_display_vtbl
;
1471 dri2_display_destroy(disp
);
1476 dri2_wl_swrast_get_stride_for_format(int format
, int w
)
1478 int visual_idx
= dri2_wl_visual_idx_from_shm_format(format
);
1480 assume(visual_idx
!= -1);
1482 return w
* (dri2_wl_visuals
[visual_idx
].bpp
/ 8);
1486 * Taken from weston shared/os-compatibility.c
1489 #ifndef HAVE_MKOSTEMP
1492 set_cloexec_or_close(int fd
)
1499 flags
= fcntl(fd
, F_GETFD
);
1503 if (fcntl(fd
, F_SETFD
, flags
| FD_CLOEXEC
) == -1)
1516 * Taken from weston shared/os-compatibility.c
1520 create_tmpfile_cloexec(char *tmpname
)
1524 #ifdef HAVE_MKOSTEMP
1525 fd
= mkostemp(tmpname
, O_CLOEXEC
);
1529 fd
= mkstemp(tmpname
);
1531 fd
= set_cloexec_or_close(fd
);
1540 * Taken from weston shared/os-compatibility.c
1542 * Create a new, unique, anonymous file of the given size, and
1543 * return the file descriptor for it. The file descriptor is set
1544 * CLOEXEC. The file is immediately suitable for mmap()'ing
1545 * the given size at offset zero.
1547 * The file should not have a permanent backing store like a disk,
1548 * but may have if XDG_RUNTIME_DIR is not properly implemented in OS.
1550 * The file name is deleted from the file system.
1552 * The file is suitable for buffer sharing between processes by
1553 * transmitting the file descriptor over Unix sockets using the
1554 * SCM_RIGHTS methods.
1556 * If the C library implements posix_fallocate(), it is used to
1557 * guarantee that disk space is available for the file at the
1558 * given size. If disk space is insufficient, errno is set to ENOSPC.
1559 * If posix_fallocate() is not supported, program may receive
1560 * SIGBUS on accessing mmap()'ed file contents instead.
1563 os_create_anonymous_file(off_t size
)
1565 static const char templ
[] = "/mesa-shared-XXXXXX";
1571 path
= getenv("XDG_RUNTIME_DIR");
1577 name
= malloc(strlen(path
) + sizeof(templ
));
1582 strcat(name
, templ
);
1584 fd
= create_tmpfile_cloexec(name
);
1591 ret
= ftruncate(fd
, size
);
1602 dri2_wl_swrast_allocate_buffer(struct dri2_egl_surface
*dri2_surf
,
1603 int format
, int w
, int h
,
1604 void **data
, int *size
,
1605 struct wl_buffer
**buffer
)
1607 struct dri2_egl_display
*dri2_dpy
=
1608 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1609 struct wl_shm_pool
*pool
;
1610 int fd
, stride
, size_map
;
1613 stride
= dri2_wl_swrast_get_stride_for_format(format
, w
);
1614 size_map
= h
* stride
;
1616 /* Create a shareable buffer */
1617 fd
= os_create_anonymous_file(size_map
);
1621 data_map
= mmap(NULL
, size_map
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
1622 if (data_map
== MAP_FAILED
) {
1627 /* Share it in a wl_buffer */
1628 pool
= wl_shm_create_pool(dri2_dpy
->wl_shm
, fd
, size_map
);
1629 wl_proxy_set_queue((struct wl_proxy
*)pool
, dri2_surf
->wl_queue
);
1630 *buffer
= wl_shm_pool_create_buffer(pool
, 0, w
, h
, stride
, format
);
1631 wl_shm_pool_destroy(pool
);
1640 swrast_update_buffers(struct dri2_egl_surface
*dri2_surf
)
1642 struct dri2_egl_display
*dri2_dpy
=
1643 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1645 /* we need to do the following operations only once per frame */
1646 if (dri2_surf
->back
)
1649 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->attached_width
||
1650 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->attached_height
) {
1652 dri2_wl_release_buffers(dri2_surf
);
1654 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
1655 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
1656 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
1657 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
1658 dri2_surf
->current
= NULL
;
1661 /* find back buffer */
1663 /* There might be a buffer release already queued that wasn't processed */
1664 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
1666 /* try get free buffer already created */
1667 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1668 if (!dri2_surf
->color_buffers
[i
].locked
&&
1669 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1670 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1675 /* else choose any another free location */
1676 if (!dri2_surf
->back
) {
1677 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1678 if (!dri2_surf
->color_buffers
[i
].locked
) {
1679 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1680 if (!dri2_wl_swrast_allocate_buffer(dri2_surf
,
1682 dri2_surf
->base
.Width
,
1683 dri2_surf
->base
.Height
,
1684 &dri2_surf
->back
->data
,
1685 &dri2_surf
->back
->data_size
,
1686 &dri2_surf
->back
->wl_buffer
)) {
1687 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
1690 wl_buffer_add_listener(dri2_surf
->back
->wl_buffer
,
1691 &wl_buffer_listener
, dri2_surf
);
1697 if (!dri2_surf
->back
) {
1698 _eglError(EGL_BAD_ALLOC
, "failed to find free buffer");
1702 dri2_surf
->back
->locked
= true;
1704 /* If we have an extra unlocked buffer at this point, we had to do triple
1705 * buffering for a while, but now can go back to just double buffering.
1706 * That means we can free any unlocked buffer now. */
1707 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1708 if (!dri2_surf
->color_buffers
[i
].locked
&&
1709 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1710 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
1711 munmap(dri2_surf
->color_buffers
[i
].data
,
1712 dri2_surf
->color_buffers
[i
].data_size
);
1713 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
1714 dri2_surf
->color_buffers
[i
].data
= NULL
;
1722 dri2_wl_swrast_get_frontbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1724 /* if there has been a resize: */
1725 if (!dri2_surf
->current
)
1728 return dri2_surf
->current
->data
;
1732 dri2_wl_swrast_get_backbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1734 assert(dri2_surf
->back
);
1735 return dri2_surf
->back
->data
;
1739 dri2_wl_swrast_commit_backbuffer(struct dri2_egl_surface
*dri2_surf
)
1741 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1743 while (dri2_surf
->throttle_callback
!= NULL
)
1744 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
1745 dri2_surf
->wl_queue
) == -1)
1748 if (dri2_surf
->base
.SwapInterval
> 0) {
1749 dri2_surf
->throttle_callback
=
1750 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
1751 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1752 &throttle_listener
, dri2_surf
);
1755 dri2_surf
->current
= dri2_surf
->back
;
1756 dri2_surf
->back
= NULL
;
1758 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
1759 dri2_surf
->current
->wl_buffer
,
1760 dri2_surf
->dx
, dri2_surf
->dy
);
1762 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
1763 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
1764 /* reset resize growing parameters */
1768 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
1769 0, 0, INT32_MAX
, INT32_MAX
);
1770 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
1772 /* If we're not waiting for a frame callback then we'll at least throttle
1773 * to a sync callback so that we always give a chance for the compositor to
1774 * handle the commit and send a release event before checking for a free
1776 if (dri2_surf
->throttle_callback
== NULL
) {
1777 dri2_surf
->throttle_callback
= wl_display_sync(dri2_surf
->wl_dpy_wrapper
);
1778 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1779 &throttle_listener
, dri2_surf
);
1782 wl_display_flush(dri2_dpy
->wl_dpy
);
1786 dri2_wl_swrast_get_drawable_info(__DRIdrawable
* draw
,
1787 int *x
, int *y
, int *w
, int *h
,
1788 void *loaderPrivate
)
1790 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1792 (void) swrast_update_buffers(dri2_surf
);
1795 *w
= dri2_surf
->base
.Width
;
1796 *h
= dri2_surf
->base
.Height
;
1800 dri2_wl_swrast_get_image(__DRIdrawable
* read
,
1801 int x
, int y
, int w
, int h
,
1802 char *data
, void *loaderPrivate
)
1804 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1805 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1806 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1807 int src_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1808 int dst_stride
= copy_width
;
1811 src
= dri2_wl_swrast_get_frontbuffer_data(dri2_surf
);
1813 memset(data
, 0, copy_width
* h
);
1817 assert(data
!= src
);
1818 assert(copy_width
<= src_stride
);
1821 src
+= y
* src_stride
;
1824 if (copy_width
> src_stride
-x_offset
)
1825 copy_width
= src_stride
-x_offset
;
1826 if (h
> dri2_surf
->base
.Height
-y
)
1827 h
= dri2_surf
->base
.Height
-y
;
1830 memcpy(dst
, src
, copy_width
);
1837 dri2_wl_swrast_put_image2(__DRIdrawable
* draw
, int op
,
1838 int x
, int y
, int w
, int h
, int stride
,
1839 char *data
, void *loaderPrivate
)
1841 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1842 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1843 int dst_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1844 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1847 assert(copy_width
<= stride
);
1849 (void) swrast_update_buffers(dri2_surf
);
1850 dst
= dri2_wl_swrast_get_backbuffer_data(dri2_surf
);
1852 /* partial copy, copy old content */
1853 if (copy_width
< dst_stride
)
1854 dri2_wl_swrast_get_image(draw
, 0, 0,
1855 dri2_surf
->base
.Width
, dri2_surf
->base
.Height
,
1856 dst
, loaderPrivate
);
1859 dst
+= y
* dst_stride
;
1863 /* drivers expect we do these checks (and some rely on it) */
1864 if (copy_width
> dst_stride
-x_offset
)
1865 copy_width
= dst_stride
-x_offset
;
1866 if (h
> dri2_surf
->base
.Height
-y
)
1867 h
= dri2_surf
->base
.Height
-y
;
1870 memcpy(dst
, src
, copy_width
);
1874 dri2_wl_swrast_commit_backbuffer(dri2_surf
);
1878 dri2_wl_swrast_put_image(__DRIdrawable
* draw
, int op
,
1879 int x
, int y
, int w
, int h
,
1880 char *data
, void *loaderPrivate
)
1882 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1885 stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1886 dri2_wl_swrast_put_image2(draw
, op
, x
, y
, w
, h
,
1887 stride
, data
, loaderPrivate
);
1891 dri2_wl_swrast_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1893 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1894 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
1896 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
1901 shm_handle_format(void *data
, struct wl_shm
*shm
, uint32_t format
)
1903 struct dri2_egl_display
*dri2_dpy
= data
;
1904 int visual_idx
= dri2_wl_visual_idx_from_shm_format(format
);
1906 if (visual_idx
== -1)
1909 dri2_dpy
->formats
|= (1u << visual_idx
);
1912 static const struct wl_shm_listener shm_listener
= {
1913 .format
= shm_handle_format
1917 registry_handle_global_swrast(void *data
, struct wl_registry
*registry
,
1918 uint32_t name
, const char *interface
,
1921 struct dri2_egl_display
*dri2_dpy
= data
;
1923 if (strcmp(interface
, "wl_shm") == 0) {
1925 wl_registry_bind(registry
, name
, &wl_shm_interface
, 1);
1926 wl_shm_add_listener(dri2_dpy
->wl_shm
, &shm_listener
, dri2_dpy
);
1930 static const struct wl_registry_listener registry_listener_swrast
= {
1931 .global
= registry_handle_global_swrast
,
1932 .global_remove
= registry_handle_global_remove
1935 static const struct dri2_egl_display_vtbl dri2_wl_swrast_display_vtbl
= {
1936 .authenticate
= NULL
,
1937 .create_window_surface
= dri2_wl_create_window_surface
,
1938 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1939 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1940 .destroy_surface
= dri2_wl_destroy_surface
,
1941 .create_image
= dri2_create_image_khr
,
1942 .swap_buffers
= dri2_wl_swrast_swap_buffers
,
1943 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
1944 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1945 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1946 .copy_buffers
= dri2_fallback_copy_buffers
,
1947 .query_buffer_age
= dri2_fallback_query_buffer_age
,
1948 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
1949 .get_sync_values
= dri2_fallback_get_sync_values
,
1950 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1953 static const __DRIswrastLoaderExtension swrast_loader_extension
= {
1954 .base
= { __DRI_SWRAST_LOADER
, 2 },
1956 .getDrawableInfo
= dri2_wl_swrast_get_drawable_info
,
1957 .putImage
= dri2_wl_swrast_put_image
,
1958 .getImage
= dri2_wl_swrast_get_image
,
1959 .putImage2
= dri2_wl_swrast_put_image2
,
1962 static const __DRIextension
*swrast_loader_extensions
[] = {
1963 &swrast_loader_extension
.base
,
1964 &image_lookup_extension
.base
,
1969 dri2_initialize_wayland_swrast(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1971 struct dri2_egl_display
*dri2_dpy
;
1973 loader_set_logger(_eglLog
);
1975 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1977 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1980 disp
->DriverData
= (void *) dri2_dpy
;
1981 if (disp
->PlatformDisplay
== NULL
) {
1982 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1983 if (dri2_dpy
->wl_dpy
== NULL
)
1985 dri2_dpy
->own_device
= true;
1987 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
1990 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
1992 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
1993 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
1996 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
1997 dri2_dpy
->wl_queue
);
1999 if (dri2_dpy
->own_device
)
2000 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
2002 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
2003 wl_registry_add_listener(dri2_dpy
->wl_registry
,
2004 ®istry_listener_swrast
, dri2_dpy
);
2006 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_shm
== NULL
)
2009 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->formats
== 0)
2012 dri2_dpy
->driver_name
= strdup("swrast");
2013 if (!dri2_load_driver_swrast(disp
))
2016 dri2_dpy
->loader_extensions
= swrast_loader_extensions
;
2018 if (!dri2_create_screen(disp
))
2021 if (!dri2_setup_extensions(disp
))
2024 dri2_setup_screen(disp
);
2026 dri2_wl_setup_swap_interval(disp
);
2028 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
2029 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
2033 /* Fill vtbl last to prevent accidentally calling virtual function during
2036 dri2_dpy
->vtbl
= &dri2_wl_swrast_display_vtbl
;
2041 dri2_display_destroy(disp
);
2046 dri2_initialize_wayland(_EGLDriver
*drv
, _EGLDisplay
*disp
)
2048 EGLBoolean initialized
= EGL_FALSE
;
2050 if (!disp
->Options
.ForceSoftware
)
2051 initialized
= dri2_initialize_wayland_drm(drv
, disp
);
2054 initialized
= dri2_initialize_wayland_swrast(drv
, disp
);
2061 dri2_teardown_wayland(struct dri2_egl_display
*dri2_dpy
)
2063 if (dri2_dpy
->wl_drm
)
2064 wl_drm_destroy(dri2_dpy
->wl_drm
);
2065 if (dri2_dpy
->wl_dmabuf
)
2066 zwp_linux_dmabuf_v1_destroy(dri2_dpy
->wl_dmabuf
);
2067 if (dri2_dpy
->wl_shm
)
2068 wl_shm_destroy(dri2_dpy
->wl_shm
);
2069 if (dri2_dpy
->wl_registry
)
2070 wl_registry_destroy(dri2_dpy
->wl_registry
);
2071 if (dri2_dpy
->wl_queue
)
2072 wl_event_queue_destroy(dri2_dpy
->wl_queue
);
2073 if (dri2_dpy
->wl_dpy_wrapper
)
2074 wl_proxy_wrapper_destroy(dri2_dpy
->wl_dpy_wrapper
);
2076 for (int i
= 0; dri2_dpy
->wl_modifiers
&& i
< ARRAY_SIZE(dri2_wl_visuals
); i
++)
2077 u_vector_finish(&dri2_dpy
->wl_modifiers
[i
]);
2078 free(dri2_dpy
->wl_modifiers
);
2080 if (dri2_dpy
->own_device
)
2081 wl_display_disconnect(dri2_dpy
->wl_dpy
);