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 assert (i
< ARRAY_SIZE(dri2_surf
->color_buffers
));
187 if (dri2_surf
->color_buffers
[i
].wl_release
) {
188 wl_buffer_destroy(buffer
);
189 dri2_surf
->color_buffers
[i
].wl_release
= false;
190 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
193 dri2_surf
->color_buffers
[i
].locked
= false;
196 static const struct wl_buffer_listener wl_buffer_listener
= {
197 .release
= wl_buffer_release
201 resize_callback(struct wl_egl_window
*wl_win
, void *data
)
203 struct dri2_egl_surface
*dri2_surf
= data
;
204 struct dri2_egl_display
*dri2_dpy
=
205 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
207 /* Update the surface size as soon as native window is resized; from user
208 * pov, this makes the effect that resize is done immediately after native
209 * window resize, without requiring to wait until the first draw.
211 * A more detailed and lengthy explanation can be found at
212 * https://lists.freedesktop.org/archives/mesa-dev/2018-June/196474.html
214 if (!dri2_surf
->back
) {
215 dri2_surf
->base
.Width
= wl_win
->width
;
216 dri2_surf
->base
.Height
= wl_win
->height
;
218 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
222 destroy_window_callback(void *data
)
224 struct dri2_egl_surface
*dri2_surf
= data
;
225 dri2_surf
->wl_win
= NULL
;
228 static struct wl_surface
*
229 get_wl_surface_proxy(struct wl_egl_window
*window
)
231 /* Version 3 of wl_egl_window introduced a version field at the same
232 * location where a pointer to wl_surface was stored. Thus, if
233 * window->version is dereferenceable, we've been given an older version of
234 * wl_egl_window, and window->version points to wl_surface */
235 if (_eglPointerIsDereferencable((void *)(window
->version
))) {
236 return wl_proxy_create_wrapper((void *)(window
->version
));
238 return wl_proxy_create_wrapper(window
->surface
);
242 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
245 dri2_wl_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
246 _EGLConfig
*conf
, void *native_window
,
247 const EGLint
*attrib_list
)
249 __DRIcreateNewDrawableFunc createNewDrawable
;
250 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
251 struct dri2_egl_config
*dri2_conf
= dri2_egl_config(conf
);
252 struct wl_egl_window
*window
= native_window
;
253 struct dri2_egl_surface
*dri2_surf
;
255 const __DRIconfig
*config
;
257 dri2_surf
= calloc(1, sizeof *dri2_surf
);
259 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
263 if (!dri2_init_surface(&dri2_surf
->base
, disp
, EGL_WINDOW_BIT
, conf
,
267 config
= dri2_get_dri_config(dri2_conf
, EGL_WINDOW_BIT
,
268 dri2_surf
->base
.GLColorspace
);
271 _eglError(EGL_BAD_MATCH
, "Unsupported surfacetype/colorspace configuration");
275 dri2_surf
->base
.Width
= window
->width
;
276 dri2_surf
->base
.Height
= window
->height
;
278 visual_idx
= dri2_wl_visual_idx_from_config(dri2_dpy
, config
);
279 assert(visual_idx
!= -1);
281 if (dri2_dpy
->wl_dmabuf
|| dri2_dpy
->wl_drm
) {
282 dri2_surf
->format
= dri2_wl_visuals
[visual_idx
].wl_drm_format
;
284 assert(dri2_dpy
->wl_shm
);
285 dri2_surf
->format
= dri2_wl_visuals
[visual_idx
].wl_shm_format
;
288 dri2_surf
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
289 if (!dri2_surf
->wl_queue
) {
290 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
294 if (dri2_dpy
->wl_drm
) {
295 dri2_surf
->wl_drm_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_drm
);
296 if (!dri2_surf
->wl_drm_wrapper
) {
297 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
300 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_drm_wrapper
,
301 dri2_surf
->wl_queue
);
304 dri2_surf
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
305 if (!dri2_surf
->wl_dpy_wrapper
) {
306 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
309 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_dpy_wrapper
,
310 dri2_surf
->wl_queue
);
312 dri2_surf
->wl_surface_wrapper
= get_wl_surface_proxy(window
);
313 if (!dri2_surf
->wl_surface_wrapper
) {
314 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
315 goto cleanup_dpy_wrapper
;
317 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_surface_wrapper
,
318 dri2_surf
->wl_queue
);
320 dri2_surf
->wl_win
= window
;
321 dri2_surf
->wl_win
->driver_private
= dri2_surf
;
322 dri2_surf
->wl_win
->destroy_window_callback
= destroy_window_callback
;
324 dri2_surf
->wl_win
->resize_callback
= resize_callback
;
326 if (dri2_dpy
->image_driver
)
327 createNewDrawable
= dri2_dpy
->image_driver
->createNewDrawable
;
328 else if (dri2_dpy
->dri2
)
329 createNewDrawable
= dri2_dpy
->dri2
->createNewDrawable
;
331 createNewDrawable
= dri2_dpy
->swrast
->createNewDrawable
;
333 dri2_surf
->dri_drawable
= (*createNewDrawable
)(dri2_dpy
->dri_screen
, config
,
335 if (dri2_surf
->dri_drawable
== NULL
) {
336 _eglError(EGL_BAD_ALLOC
, "createNewDrawable");
337 goto cleanup_surf_wrapper
;
340 dri2_surf
->base
.SwapInterval
= dri2_dpy
->default_swap_interval
;
342 return &dri2_surf
->base
;
344 cleanup_surf_wrapper
:
345 wl_proxy_wrapper_destroy(dri2_surf
->wl_surface_wrapper
);
347 wl_proxy_wrapper_destroy(dri2_surf
->wl_dpy_wrapper
);
349 if (dri2_surf
->wl_drm_wrapper
)
350 wl_proxy_wrapper_destroy(dri2_surf
->wl_drm_wrapper
);
352 wl_event_queue_destroy(dri2_surf
->wl_queue
);
360 dri2_wl_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
361 _EGLConfig
*conf
, void *native_window
,
362 const EGLint
*attrib_list
)
364 /* From the EGL_EXT_platform_wayland spec, version 3:
366 * It is not valid to call eglCreatePlatformPixmapSurfaceEXT with a <dpy>
367 * that belongs to Wayland. Any such call fails and generates
370 _eglError(EGL_BAD_PARAMETER
, "cannot create EGL pixmap surfaces on "
376 * Called via eglDestroySurface(), drv->API.DestroySurface().
379 dri2_wl_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
381 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
382 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
386 dri2_dpy
->core
->destroyDrawable(dri2_surf
->dri_drawable
);
388 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
389 if (dri2_surf
->color_buffers
[i
].wl_buffer
)
390 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
391 if (dri2_surf
->color_buffers
[i
].dri_image
)
392 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
393 if (dri2_surf
->color_buffers
[i
].linear_copy
)
394 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
395 if (dri2_surf
->color_buffers
[i
].data
)
396 munmap(dri2_surf
->color_buffers
[i
].data
,
397 dri2_surf
->color_buffers
[i
].data_size
);
401 dri2_egl_surface_free_local_buffers(dri2_surf
);
403 if (dri2_surf
->throttle_callback
)
404 wl_callback_destroy(dri2_surf
->throttle_callback
);
406 if (dri2_surf
->wl_win
) {
407 dri2_surf
->wl_win
->driver_private
= NULL
;
408 dri2_surf
->wl_win
->resize_callback
= NULL
;
409 dri2_surf
->wl_win
->destroy_window_callback
= NULL
;
412 wl_proxy_wrapper_destroy(dri2_surf
->wl_surface_wrapper
);
413 wl_proxy_wrapper_destroy(dri2_surf
->wl_dpy_wrapper
);
414 if (dri2_surf
->wl_drm_wrapper
)
415 wl_proxy_wrapper_destroy(dri2_surf
->wl_drm_wrapper
);
416 wl_event_queue_destroy(dri2_surf
->wl_queue
);
418 dri2_fini_surface(surf
);
425 dri2_wl_release_buffers(struct dri2_egl_surface
*dri2_surf
)
427 struct dri2_egl_display
*dri2_dpy
=
428 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
430 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
431 if (dri2_surf
->color_buffers
[i
].wl_buffer
) {
432 if (dri2_surf
->color_buffers
[i
].locked
) {
433 dri2_surf
->color_buffers
[i
].wl_release
= true;
435 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
436 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
439 if (dri2_surf
->color_buffers
[i
].dri_image
)
440 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
441 if (dri2_surf
->color_buffers
[i
].linear_copy
)
442 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
443 if (dri2_surf
->color_buffers
[i
].data
)
444 munmap(dri2_surf
->color_buffers
[i
].data
,
445 dri2_surf
->color_buffers
[i
].data_size
);
447 dri2_surf
->color_buffers
[i
].dri_image
= NULL
;
448 dri2_surf
->color_buffers
[i
].linear_copy
= NULL
;
449 dri2_surf
->color_buffers
[i
].data
= NULL
;
453 dri2_egl_surface_free_local_buffers(dri2_surf
);
457 get_back_bo(struct dri2_egl_surface
*dri2_surf
)
459 struct dri2_egl_display
*dri2_dpy
=
460 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
463 unsigned int dri_image_format
;
467 visual_idx
= dri2_wl_visual_idx_from_fourcc(dri2_surf
->format
);
468 assert(visual_idx
!= -1);
469 dri_image_format
= dri2_wl_visuals
[visual_idx
].dri_image_format
;
470 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
[visual_idx
]);
471 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
[visual_idx
]);
473 /* There might be a buffer release already queued that wasn't processed */
474 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
476 while (dri2_surf
->back
== NULL
) {
477 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
478 /* Get an unlocked buffer, preferably one with a dri_buffer
479 * already allocated. */
480 if (dri2_surf
->color_buffers
[i
].locked
)
482 if (dri2_surf
->back
== NULL
)
483 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
484 else if (dri2_surf
->back
->dri_image
== NULL
)
485 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
491 /* If we don't have a buffer, then block on the server to release one for
492 * us, and try again. wl_display_dispatch_queue will process any pending
493 * events, however not all servers flush on issuing a buffer release
494 * event. So, we spam the server with roundtrips as they always cause a
497 if (wl_display_roundtrip_queue(dri2_dpy
->wl_dpy
,
498 dri2_surf
->wl_queue
) < 0)
502 if (dri2_surf
->back
== NULL
)
505 use_flags
= __DRI_IMAGE_USE_SHARE
| __DRI_IMAGE_USE_BACKBUFFER
;
507 if (dri2_dpy
->is_different_gpu
&&
508 dri2_surf
->back
->linear_copy
== NULL
) {
509 /* The LINEAR modifier should be a perfect alias of the LINEAR use
510 * flag; try the new interface first before the old, then fall back. */
511 if (dri2_dpy
->image
->base
.version
>= 15 &&
512 dri2_dpy
->image
->createImageWithModifiers
) {
513 uint64_t linear_mod
= DRM_FORMAT_MOD_LINEAR
;
515 dri2_surf
->back
->linear_copy
=
516 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
517 dri2_surf
->base
.Width
,
518 dri2_surf
->base
.Height
,
524 dri2_surf
->back
->linear_copy
=
525 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
526 dri2_surf
->base
.Width
,
527 dri2_surf
->base
.Height
,
530 __DRI_IMAGE_USE_LINEAR
,
533 if (dri2_surf
->back
->linear_copy
== NULL
)
537 if (dri2_surf
->back
->dri_image
== NULL
) {
538 /* If our DRIImage implementation does not support
539 * createImageWithModifiers, then fall back to the old createImage,
540 * and hope it allocates an image which is acceptable to the winsys.
542 if (num_modifiers
&& dri2_dpy
->image
->base
.version
>= 15 &&
543 dri2_dpy
->image
->createImageWithModifiers
) {
544 dri2_surf
->back
->dri_image
=
545 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
546 dri2_surf
->base
.Width
,
547 dri2_surf
->base
.Height
,
553 dri2_surf
->back
->dri_image
=
554 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
555 dri2_surf
->base
.Width
,
556 dri2_surf
->base
.Height
,
558 dri2_dpy
->is_different_gpu
?
563 dri2_surf
->back
->age
= 0;
565 if (dri2_surf
->back
->dri_image
== NULL
)
568 dri2_surf
->back
->locked
= true;
575 back_bo_to_dri_buffer(struct dri2_egl_surface
*dri2_surf
, __DRIbuffer
*buffer
)
577 struct dri2_egl_display
*dri2_dpy
=
578 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
582 image
= dri2_surf
->back
->dri_image
;
584 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
585 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &pitch
);
587 buffer
->attachment
= __DRI_BUFFER_BACK_LEFT
;
589 buffer
->pitch
= pitch
;
595 update_buffers(struct dri2_egl_surface
*dri2_surf
)
597 struct dri2_egl_display
*dri2_dpy
=
598 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
600 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->attached_width
||
601 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->attached_height
) {
603 dri2_wl_release_buffers(dri2_surf
);
605 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
606 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
607 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
608 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
611 if (get_back_bo(dri2_surf
) < 0) {
612 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
616 /* If we have an extra unlocked buffer at this point, we had to do triple
617 * buffering for a while, but now can go back to just double buffering.
618 * That means we can free any unlocked buffer now. */
619 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
620 if (!dri2_surf
->color_buffers
[i
].locked
&&
621 dri2_surf
->color_buffers
[i
].wl_buffer
) {
622 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
623 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
624 if (dri2_dpy
->is_different_gpu
)
625 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
626 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
627 dri2_surf
->color_buffers
[i
].dri_image
= NULL
;
628 dri2_surf
->color_buffers
[i
].linear_copy
= NULL
;
636 dri2_wl_get_buffers_with_format(__DRIdrawable
* driDrawable
,
637 int *width
, int *height
,
638 unsigned int *attachments
, int count
,
639 int *out_count
, void *loaderPrivate
)
641 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
644 if (update_buffers(dri2_surf
) < 0)
647 for (i
= 0, j
= 0; i
< 2 * count
; i
+= 2, j
++) {
650 switch (attachments
[i
]) {
651 case __DRI_BUFFER_BACK_LEFT
:
652 back_bo_to_dri_buffer(dri2_surf
, &dri2_surf
->buffers
[j
]);
655 local
= dri2_egl_surface_alloc_local_buffer(dri2_surf
, attachments
[i
],
659 _eglError(EGL_BAD_ALLOC
, "failed to allocate local buffer");
662 dri2_surf
->buffers
[j
] = *local
;
671 *width
= dri2_surf
->base
.Width
;
672 *height
= dri2_surf
->base
.Height
;
674 return dri2_surf
->buffers
;
678 dri2_wl_get_buffers(__DRIdrawable
* driDrawable
,
679 int *width
, int *height
,
680 unsigned int *attachments
, int count
,
681 int *out_count
, void *loaderPrivate
)
683 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
684 unsigned int *attachments_with_format
;
686 int visual_idx
= dri2_wl_visual_idx_from_fourcc(dri2_surf
->format
);
688 if (visual_idx
== -1)
691 attachments_with_format
= calloc(count
, 2 * sizeof(unsigned int));
692 if (!attachments_with_format
) {
697 for (int i
= 0; i
< count
; ++i
) {
698 attachments_with_format
[2*i
] = attachments
[i
];
699 attachments_with_format
[2*i
+ 1] = dri2_wl_visuals
[visual_idx
].bpp
;
703 dri2_wl_get_buffers_with_format(driDrawable
,
705 attachments_with_format
, count
,
706 out_count
, loaderPrivate
);
708 free(attachments_with_format
);
714 image_get_buffers(__DRIdrawable
*driDrawable
,
718 uint32_t buffer_mask
,
719 struct __DRIimageList
*buffers
)
721 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
723 if (update_buffers(dri2_surf
) < 0)
726 buffers
->image_mask
= __DRI_IMAGE_BUFFER_BACK
;
727 buffers
->back
= dri2_surf
->back
->dri_image
;
733 dri2_wl_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
736 (void) loaderPrivate
;
739 static const __DRIdri2LoaderExtension dri2_loader_extension
= {
740 .base
= { __DRI_DRI2_LOADER
, 3 },
742 .getBuffers
= dri2_wl_get_buffers
,
743 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
744 .getBuffersWithFormat
= dri2_wl_get_buffers_with_format
,
747 static const __DRIimageLoaderExtension image_loader_extension
= {
748 .base
= { __DRI_IMAGE_LOADER
, 1 },
750 .getBuffers
= image_get_buffers
,
751 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
755 wayland_throttle_callback(void *data
,
756 struct wl_callback
*callback
,
759 struct dri2_egl_surface
*dri2_surf
= data
;
761 dri2_surf
->throttle_callback
= NULL
;
762 wl_callback_destroy(callback
);
765 static const struct wl_callback_listener throttle_listener
= {
766 .done
= wayland_throttle_callback
770 get_fourcc(struct dri2_egl_display
*dri2_dpy
,
771 __DRIimage
*image
, int *fourcc
)
777 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FOURCC
,
782 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
,
787 visual_idx
= dri2_wl_visual_idx_from_dri_image_format(dri_format
);
788 if (visual_idx
== -1)
791 *fourcc
= dri2_wl_visuals
[visual_idx
].wl_drm_format
;
795 static struct wl_buffer
*
796 create_wl_buffer(struct dri2_egl_display
*dri2_dpy
,
797 struct dri2_egl_surface
*dri2_surf
,
800 struct wl_buffer
*ret
;
802 int width
, height
, fourcc
, num_planes
;
803 uint64_t modifier
= DRM_FORMAT_MOD_INVALID
;
805 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_WIDTH
, &width
);
806 query
&= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_HEIGHT
,
808 query
&= get_fourcc(dri2_dpy
, image
, &fourcc
);
812 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NUM_PLANES
,
817 if (dri2_dpy
->image
->base
.version
>= 15) {
820 query
= dri2_dpy
->image
->queryImage(image
,
821 __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
,
823 query
&= dri2_dpy
->image
->queryImage(image
,
824 __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
,
827 modifier
= combine_u32_into_u64(mod_hi
, mod_lo
);
831 if (dri2_dpy
->wl_dmabuf
&& modifier
!= DRM_FORMAT_MOD_INVALID
) {
832 struct zwp_linux_buffer_params_v1
*params
;
835 /* We don't need a wrapper for wl_dmabuf objects, because we have to
836 * create the intermediate params object; we can set the queue on this,
837 * and the wl_buffer inherits it race-free. */
838 params
= zwp_linux_dmabuf_v1_create_params(dri2_dpy
->wl_dmabuf
);
840 wl_proxy_set_queue((struct wl_proxy
*) params
, dri2_surf
->wl_queue
);
842 for (i
= 0; i
< num_planes
; i
++) {
847 p_image
= dri2_dpy
->image
->fromPlanar(image
, i
, NULL
);
853 query
= dri2_dpy
->image
->queryImage(p_image
,
854 __DRI_IMAGE_ATTRIB_FD
,
856 query
&= dri2_dpy
->image
->queryImage(p_image
,
857 __DRI_IMAGE_ATTRIB_STRIDE
,
859 query
&= dri2_dpy
->image
->queryImage(p_image
,
860 __DRI_IMAGE_ATTRIB_OFFSET
,
862 if (image
!= p_image
)
863 dri2_dpy
->image
->destroyImage(p_image
);
868 zwp_linux_buffer_params_v1_destroy(params
);
872 zwp_linux_buffer_params_v1_add(params
, fd
, i
, offset
, stride
,
873 modifier
>> 32, modifier
& 0xffffffff);
877 ret
= zwp_linux_buffer_params_v1_create_immed(params
, width
, height
,
879 zwp_linux_buffer_params_v1_destroy(params
);
880 } else if (dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
) {
881 struct wl_drm
*wl_drm
=
882 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
888 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FD
, &fd
);
889 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
890 ret
= wl_drm_create_prime_buffer(wl_drm
, fd
, width
, height
, fourcc
, 0,
894 struct wl_drm
*wl_drm
=
895 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
901 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
902 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
903 ret
= wl_drm_create_buffer(wl_drm
, name
, width
, height
, stride
, fourcc
);
910 try_damage_buffer(struct dri2_egl_surface
*dri2_surf
,
914 if (wl_proxy_get_version((struct wl_proxy
*) dri2_surf
->wl_surface_wrapper
)
915 < WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION
)
918 for (int i
= 0; i
< n_rects
; i
++) {
919 const int *rect
= &rects
[i
* 4];
921 wl_surface_damage_buffer(dri2_surf
->wl_surface_wrapper
,
923 dri2_surf
->base
.Height
- rect
[1] - rect
[3],
929 * Called via eglSwapBuffers(), drv->API.SwapBuffers().
932 dri2_wl_swap_buffers_with_damage(_EGLDriver
*drv
,
938 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
939 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
941 while (dri2_surf
->throttle_callback
!= NULL
)
942 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
943 dri2_surf
->wl_queue
) == -1)
946 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
947 if (dri2_surf
->color_buffers
[i
].age
> 0)
948 dri2_surf
->color_buffers
[i
].age
++;
950 /* Make sure we have a back buffer in case we're swapping without ever
952 if (get_back_bo(dri2_surf
) < 0)
953 return _eglError(EGL_BAD_ALLOC
, "dri2_swap_buffers");
955 if (draw
->SwapInterval
> 0) {
956 dri2_surf
->throttle_callback
=
957 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
958 wl_callback_add_listener(dri2_surf
->throttle_callback
,
959 &throttle_listener
, dri2_surf
);
962 dri2_surf
->back
->age
= 1;
963 dri2_surf
->current
= dri2_surf
->back
;
964 dri2_surf
->back
= NULL
;
966 if (!dri2_surf
->current
->wl_buffer
) {
969 if (dri2_dpy
->is_different_gpu
)
970 image
= dri2_surf
->current
->linear_copy
;
972 image
= dri2_surf
->current
->dri_image
;
974 dri2_surf
->current
->wl_buffer
=
975 create_wl_buffer(dri2_dpy
, dri2_surf
, image
);
977 dri2_surf
->current
->wl_release
= false;
979 wl_buffer_add_listener(dri2_surf
->current
->wl_buffer
,
980 &wl_buffer_listener
, dri2_surf
);
983 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
984 dri2_surf
->current
->wl_buffer
,
985 dri2_surf
->dx
, dri2_surf
->dy
);
987 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
988 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
989 /* reset resize growing parameters */
993 /* If the compositor doesn't support damage_buffer, we deliberately
994 * ignore the damage region and post maximum damage, due to
995 * https://bugs.freedesktop.org/78190 */
996 if (!n_rects
|| !try_damage_buffer(dri2_surf
, rects
, n_rects
))
997 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
998 0, 0, INT32_MAX
, INT32_MAX
);
1000 if (dri2_dpy
->is_different_gpu
) {
1001 _EGLContext
*ctx
= _eglGetCurrentContext();
1002 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1003 dri2_dpy
->image
->blitImage(dri2_ctx
->dri_context
,
1004 dri2_surf
->current
->linear_copy
,
1005 dri2_surf
->current
->dri_image
,
1006 0, 0, dri2_surf
->base
.Width
,
1007 dri2_surf
->base
.Height
,
1008 0, 0, dri2_surf
->base
.Width
,
1009 dri2_surf
->base
.Height
, 0);
1012 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
1013 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
1015 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
1017 /* If we're not waiting for a frame callback then we'll at least throttle
1018 * to a sync callback so that we always give a chance for the compositor to
1019 * handle the commit and send a release event before checking for a free
1021 if (dri2_surf
->throttle_callback
== NULL
) {
1022 dri2_surf
->throttle_callback
= wl_display_sync(dri2_surf
->wl_dpy_wrapper
);
1023 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1024 &throttle_listener
, dri2_surf
);
1027 wl_display_flush(dri2_dpy
->wl_dpy
);
1033 dri2_wl_query_buffer_age(_EGLDriver
*drv
,
1034 _EGLDisplay
*disp
, _EGLSurface
*surface
)
1036 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
1038 if (get_back_bo(dri2_surf
) < 0) {
1039 _eglError(EGL_BAD_ALLOC
, "dri2_query_buffer_age");
1043 return dri2_surf
->back
->age
;
1047 dri2_wl_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1049 return dri2_wl_swap_buffers_with_damage(drv
, disp
, draw
, NULL
, 0);
1052 static struct wl_buffer
*
1053 dri2_wl_create_wayland_buffer_from_image(_EGLDriver
*drv
,
1057 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1058 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
1059 __DRIimage
*image
= dri2_img
->dri_image
;
1060 struct wl_buffer
*buffer
;
1061 int format
, visual_idx
;
1063 /* Check the upstream display supports this buffer's format. */
1064 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
, &format
);
1065 visual_idx
= dri2_wl_visual_idx_from_dri_image_format(format
);
1066 if (visual_idx
== -1)
1069 if (!(dri2_dpy
->formats
& (1u << visual_idx
)))
1072 buffer
= create_wl_buffer(dri2_dpy
, NULL
, image
);
1074 /* The buffer object will have been created with our internal event queue
1075 * because it is using wl_dmabuf/wl_drm as a proxy factory. We want the
1076 * buffer to be used by the application so we'll reset it to the display's
1077 * default event queue. This isn't actually racy, as the only event the
1078 * buffer can get is a buffer release, which doesn't happen with an explicit
1081 wl_proxy_set_queue((struct wl_proxy
*) buffer
, NULL
);
1086 _eglError(EGL_BAD_MATCH
, "unsupported image format");
1091 dri2_wl_authenticate(_EGLDisplay
*disp
, uint32_t id
)
1093 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1096 if (dri2_dpy
->is_render_node
) {
1097 _eglLog(_EGL_WARNING
, "wayland-egl: client asks server to "
1098 "authenticate for render-nodes");
1101 dri2_dpy
->authenticated
= false;
1103 wl_drm_authenticate(dri2_dpy
->wl_drm
, id
);
1104 if (roundtrip(dri2_dpy
) < 0)
1107 if (!dri2_dpy
->authenticated
)
1110 /* reset authenticated */
1111 dri2_dpy
->authenticated
= true;
1117 drm_handle_device(void *data
, struct wl_drm
*drm
, const char *device
)
1119 struct dri2_egl_display
*dri2_dpy
= data
;
1122 dri2_dpy
->device_name
= strdup(device
);
1123 if (!dri2_dpy
->device_name
)
1126 dri2_dpy
->fd
= loader_open_device(dri2_dpy
->device_name
);
1127 if (dri2_dpy
->fd
== -1) {
1128 _eglLog(_EGL_WARNING
, "wayland-egl: could not open %s (%s)",
1129 dri2_dpy
->device_name
, strerror(errno
));
1133 if (drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
) {
1134 dri2_dpy
->authenticated
= true;
1136 drmGetMagic(dri2_dpy
->fd
, &magic
);
1137 wl_drm_authenticate(dri2_dpy
->wl_drm
, magic
);
1142 drm_handle_format(void *data
, struct wl_drm
*drm
, uint32_t format
)
1144 struct dri2_egl_display
*dri2_dpy
= data
;
1145 int visual_idx
= dri2_wl_visual_idx_from_fourcc(format
);
1147 if (visual_idx
== -1)
1150 dri2_dpy
->formats
|= (1u << visual_idx
);
1154 drm_handle_capabilities(void *data
, struct wl_drm
*drm
, uint32_t value
)
1156 struct dri2_egl_display
*dri2_dpy
= data
;
1158 dri2_dpy
->capabilities
= value
;
1162 drm_handle_authenticated(void *data
, struct wl_drm
*drm
)
1164 struct dri2_egl_display
*dri2_dpy
= data
;
1166 dri2_dpy
->authenticated
= true;
1169 static const struct wl_drm_listener drm_listener
= {
1170 .device
= drm_handle_device
,
1171 .format
= drm_handle_format
,
1172 .authenticated
= drm_handle_authenticated
,
1173 .capabilities
= drm_handle_capabilities
1177 dmabuf_ignore_format(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1180 /* formats are implicitly advertised by the 'modifier' event, so ignore */
1184 dmabuf_handle_modifier(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1185 uint32_t format
, uint32_t modifier_hi
,
1186 uint32_t modifier_lo
)
1188 struct dri2_egl_display
*dri2_dpy
= data
;
1189 int visual_idx
= dri2_wl_visual_idx_from_fourcc(format
);
1192 if (visual_idx
== -1)
1195 if (modifier_hi
== (DRM_FORMAT_MOD_INVALID
>> 32) &&
1196 modifier_lo
== (DRM_FORMAT_MOD_INVALID
& 0xffffffff))
1199 dri2_dpy
->formats
|= (1u << visual_idx
);
1201 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
[visual_idx
]);
1202 *mod
= combine_u32_into_u64(modifier_hi
, modifier_lo
);
1205 static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener
= {
1206 .format
= dmabuf_ignore_format
,
1207 .modifier
= dmabuf_handle_modifier
,
1211 registry_handle_global_drm(void *data
, struct wl_registry
*registry
,
1212 uint32_t name
, const char *interface
,
1215 struct dri2_egl_display
*dri2_dpy
= data
;
1217 if (strcmp(interface
, "wl_drm") == 0) {
1219 wl_registry_bind(registry
, name
, &wl_drm_interface
, MIN2(version
, 2));
1220 wl_drm_add_listener(dri2_dpy
->wl_drm
, &drm_listener
, dri2_dpy
);
1221 } else if (strcmp(interface
, "zwp_linux_dmabuf_v1") == 0 && version
>= 3) {
1222 dri2_dpy
->wl_dmabuf
=
1223 wl_registry_bind(registry
, name
, &zwp_linux_dmabuf_v1_interface
,
1225 zwp_linux_dmabuf_v1_add_listener(dri2_dpy
->wl_dmabuf
, &dmabuf_listener
,
1231 registry_handle_global_remove(void *data
, struct wl_registry
*registry
,
1236 static const struct wl_registry_listener registry_listener_drm
= {
1237 .global
= registry_handle_global_drm
,
1238 .global_remove
= registry_handle_global_remove
1242 dri2_wl_setup_swap_interval(_EGLDisplay
*disp
)
1244 /* We can't use values greater than 1 on Wayland because we are using the
1245 * frame callback to synchronise the frame and the only way we be sure to
1246 * get a frame callback is to attach a new buffer. Therefore we can't just
1247 * sit drawing nothing to wait until the next ‘n’ frame callbacks */
1249 dri2_setup_swap_interval(disp
, 1);
1252 static const struct dri2_egl_display_vtbl dri2_wl_display_vtbl
= {
1253 .authenticate
= dri2_wl_authenticate
,
1254 .create_window_surface
= dri2_wl_create_window_surface
,
1255 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1256 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1257 .destroy_surface
= dri2_wl_destroy_surface
,
1258 .create_image
= dri2_create_image_khr
,
1259 .swap_buffers
= dri2_wl_swap_buffers
,
1260 .swap_buffers_with_damage
= dri2_wl_swap_buffers_with_damage
,
1261 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1262 .set_damage_region
= dri2_fallback_set_damage_region
,
1263 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1264 .copy_buffers
= dri2_fallback_copy_buffers
,
1265 .query_buffer_age
= dri2_wl_query_buffer_age
,
1266 .create_wayland_buffer_from_image
= dri2_wl_create_wayland_buffer_from_image
,
1267 .get_sync_values
= dri2_fallback_get_sync_values
,
1268 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1271 static const __DRIextension
*dri2_loader_extensions
[] = {
1272 &dri2_loader_extension
.base
,
1273 &image_loader_extension
.base
,
1274 &image_lookup_extension
.base
,
1275 &use_invalidate
.base
,
1279 static const __DRIextension
*image_loader_extensions
[] = {
1280 &image_loader_extension
.base
,
1281 &image_lookup_extension
.base
,
1282 &use_invalidate
.base
,
1287 dri2_wl_add_configs_for_visuals(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1289 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1290 unsigned int format_count
[ARRAY_SIZE(dri2_wl_visuals
)] = { 0 };
1291 unsigned int count
= 0;
1293 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
1294 for (unsigned j
= 0; j
< ARRAY_SIZE(dri2_wl_visuals
); j
++) {
1295 struct dri2_egl_config
*dri2_conf
;
1297 if (!(dri2_dpy
->formats
& (1u << j
)))
1300 dri2_conf
= dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
1301 count
+ 1, EGL_WINDOW_BIT
, NULL
, dri2_wl_visuals
[j
].rgba_masks
);
1303 if (dri2_conf
->base
.ConfigID
== count
+ 1)
1310 for (unsigned i
= 0; i
< ARRAY_SIZE(format_count
); i
++) {
1311 if (!format_count
[i
]) {
1312 _eglLog(_EGL_DEBUG
, "No DRI config supports native format %s",
1313 dri2_wl_visuals
[i
].format_name
);
1317 return (count
!= 0);
1321 dri2_initialize_wayland_drm(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1324 struct dri2_egl_display
*dri2_dpy
;
1326 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1328 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1331 disp
->DriverData
= (void *) dri2_dpy
;
1332 if (disp
->PlatformDisplay
== NULL
) {
1333 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1334 if (dri2_dpy
->wl_dpy
== NULL
)
1336 dri2_dpy
->own_device
= true;
1338 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
1341 dri2_dpy
->wl_modifiers
=
1342 calloc(ARRAY_SIZE(dri2_wl_visuals
), sizeof(*dri2_dpy
->wl_modifiers
));
1343 if (!dri2_dpy
->wl_modifiers
)
1345 for (int i
= 0; i
< ARRAY_SIZE(dri2_wl_visuals
); i
++) {
1346 if (!u_vector_init(&dri2_dpy
->wl_modifiers
[i
], sizeof(uint64_t), 32))
1350 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
1352 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
1353 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
1356 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
1357 dri2_dpy
->wl_queue
);
1359 if (dri2_dpy
->own_device
)
1360 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
1362 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
1363 wl_registry_add_listener(dri2_dpy
->wl_registry
,
1364 ®istry_listener_drm
, dri2_dpy
);
1365 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_drm
== NULL
)
1368 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->fd
== -1)
1371 if (roundtrip(dri2_dpy
) < 0 || !dri2_dpy
->authenticated
)
1374 dri2_dpy
->fd
= loader_get_user_preferred_fd(dri2_dpy
->fd
,
1375 &dri2_dpy
->is_different_gpu
);
1376 dev
= _eglAddDevice(dri2_dpy
->fd
, false);
1378 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to find EGLDevice");
1384 if (dri2_dpy
->is_different_gpu
) {
1385 free(dri2_dpy
->device_name
);
1386 dri2_dpy
->device_name
= loader_get_device_name_for_fd(dri2_dpy
->fd
);
1387 if (!dri2_dpy
->device_name
) {
1388 _eglError(EGL_BAD_ALLOC
, "wayland-egl: failed to get device name "
1389 "for requested GPU");
1394 /* we have to do the check now, because loader_get_user_preferred_fd
1395 * will return a render-node when the requested gpu is different
1396 * to the server, but also if the client asks for the same gpu than
1397 * the server by requesting its pci-id */
1398 dri2_dpy
->is_render_node
= drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
;
1400 dri2_dpy
->driver_name
= loader_get_driver_for_fd(dri2_dpy
->fd
);
1401 if (dri2_dpy
->driver_name
== NULL
) {
1402 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to get driver name");
1406 /* render nodes cannot use Gem names, and thus do not support
1407 * the __DRI_DRI2_LOADER extension */
1408 if (!dri2_dpy
->is_render_node
) {
1409 dri2_dpy
->loader_extensions
= dri2_loader_extensions
;
1410 if (!dri2_load_driver(disp
)) {
1411 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to load driver");
1415 dri2_dpy
->loader_extensions
= image_loader_extensions
;
1416 if (!dri2_load_driver_dri3(disp
)) {
1417 _eglError(EGL_BAD_ALLOC
, "DRI3: failed to load driver");
1422 if (!dri2_create_screen(disp
))
1425 if (!dri2_setup_extensions(disp
))
1428 dri2_setup_screen(disp
);
1430 dri2_wl_setup_swap_interval(disp
);
1432 /* To use Prime, we must have _DRI_IMAGE v7 at least.
1433 * createImageFromFds support indicates that Prime export/import
1434 * is supported by the driver. Fall back to
1435 * gem names if we don't have Prime support. */
1437 if (dri2_dpy
->image
->base
.version
< 7 ||
1438 dri2_dpy
->image
->createImageFromFds
== NULL
)
1439 dri2_dpy
->capabilities
&= ~WL_DRM_CAPABILITY_PRIME
;
1441 /* We cannot use Gem names with render-nodes, only prime fds (dma-buf).
1442 * The server needs to accept them */
1443 if (dri2_dpy
->is_render_node
&&
1444 !(dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
)) {
1445 _eglLog(_EGL_WARNING
, "wayland-egl: display is not render-node capable");
1449 if (dri2_dpy
->is_different_gpu
&&
1450 (dri2_dpy
->image
->base
.version
< 9 ||
1451 dri2_dpy
->image
->blitImage
== NULL
)) {
1452 _eglLog(_EGL_WARNING
, "wayland-egl: Different GPU selected, but the "
1453 "Image extension in the driver is not "
1454 "compatible. Version 9 or later and blitImage() "
1459 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
1460 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
1464 dri2_set_WL_bind_wayland_display(drv
, disp
);
1465 /* When cannot convert EGLImage to wl_buffer when on a different gpu,
1466 * because the buffer of the EGLImage has likely a tiling mode the server
1467 * gpu won't support. These is no way to check for now. Thus do not support the
1469 if (!dri2_dpy
->is_different_gpu
)
1470 disp
->Extensions
.WL_create_wayland_buffer_from_image
= EGL_TRUE
;
1472 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
1474 disp
->Extensions
.EXT_swap_buffers_with_damage
= EGL_TRUE
;
1476 /* Fill vtbl last to prevent accidentally calling virtual function during
1479 dri2_dpy
->vtbl
= &dri2_wl_display_vtbl
;
1484 dri2_display_destroy(disp
);
1489 dri2_wl_swrast_get_stride_for_format(int format
, int w
)
1491 int visual_idx
= dri2_wl_visual_idx_from_shm_format(format
);
1493 assume(visual_idx
!= -1);
1495 return w
* (dri2_wl_visuals
[visual_idx
].bpp
/ 8);
1499 * Taken from weston shared/os-compatibility.c
1502 #ifndef HAVE_MKOSTEMP
1505 set_cloexec_or_close(int fd
)
1512 flags
= fcntl(fd
, F_GETFD
);
1516 if (fcntl(fd
, F_SETFD
, flags
| FD_CLOEXEC
) == -1)
1529 * Taken from weston shared/os-compatibility.c
1533 create_tmpfile_cloexec(char *tmpname
)
1537 #ifdef HAVE_MKOSTEMP
1538 fd
= mkostemp(tmpname
, O_CLOEXEC
);
1542 fd
= mkstemp(tmpname
);
1544 fd
= set_cloexec_or_close(fd
);
1553 * Taken from weston shared/os-compatibility.c
1555 * Create a new, unique, anonymous file of the given size, and
1556 * return the file descriptor for it. The file descriptor is set
1557 * CLOEXEC. The file is immediately suitable for mmap()'ing
1558 * the given size at offset zero.
1560 * The file should not have a permanent backing store like a disk,
1561 * but may have if XDG_RUNTIME_DIR is not properly implemented in OS.
1563 * The file name is deleted from the file system.
1565 * The file is suitable for buffer sharing between processes by
1566 * transmitting the file descriptor over Unix sockets using the
1567 * SCM_RIGHTS methods.
1569 * If the C library implements posix_fallocate(), it is used to
1570 * guarantee that disk space is available for the file at the
1571 * given size. If disk space is insufficient, errno is set to ENOSPC.
1572 * If posix_fallocate() is not supported, program may receive
1573 * SIGBUS on accessing mmap()'ed file contents instead.
1576 os_create_anonymous_file(off_t size
)
1578 static const char templ
[] = "/mesa-shared-XXXXXX";
1584 path
= getenv("XDG_RUNTIME_DIR");
1590 name
= malloc(strlen(path
) + sizeof(templ
));
1595 strcat(name
, templ
);
1597 fd
= create_tmpfile_cloexec(name
);
1604 ret
= ftruncate(fd
, size
);
1615 dri2_wl_swrast_allocate_buffer(struct dri2_egl_surface
*dri2_surf
,
1616 int format
, int w
, int h
,
1617 void **data
, int *size
,
1618 struct wl_buffer
**buffer
)
1620 struct dri2_egl_display
*dri2_dpy
=
1621 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1622 struct wl_shm_pool
*pool
;
1623 int fd
, stride
, size_map
;
1626 stride
= dri2_wl_swrast_get_stride_for_format(format
, w
);
1627 size_map
= h
* stride
;
1629 /* Create a shareable buffer */
1630 fd
= os_create_anonymous_file(size_map
);
1634 data_map
= mmap(NULL
, size_map
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
1635 if (data_map
== MAP_FAILED
) {
1640 /* Share it in a wl_buffer */
1641 pool
= wl_shm_create_pool(dri2_dpy
->wl_shm
, fd
, size_map
);
1642 wl_proxy_set_queue((struct wl_proxy
*)pool
, dri2_surf
->wl_queue
);
1643 *buffer
= wl_shm_pool_create_buffer(pool
, 0, w
, h
, stride
, format
);
1644 wl_shm_pool_destroy(pool
);
1653 swrast_update_buffers(struct dri2_egl_surface
*dri2_surf
)
1655 struct dri2_egl_display
*dri2_dpy
=
1656 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1658 /* we need to do the following operations only once per frame */
1659 if (dri2_surf
->back
)
1662 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->width
||
1663 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->height
) {
1665 dri2_wl_release_buffers(dri2_surf
);
1667 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
1668 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
1669 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
1670 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
1671 dri2_surf
->current
= NULL
;
1674 /* find back buffer */
1676 /* There might be a buffer release already queued that wasn't processed */
1677 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
1679 /* try get free buffer already created */
1680 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1681 if (!dri2_surf
->color_buffers
[i
].locked
&&
1682 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1683 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1688 /* else choose any another free location */
1689 if (!dri2_surf
->back
) {
1690 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1691 if (!dri2_surf
->color_buffers
[i
].locked
) {
1692 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1693 if (!dri2_wl_swrast_allocate_buffer(dri2_surf
,
1695 dri2_surf
->base
.Width
,
1696 dri2_surf
->base
.Height
,
1697 &dri2_surf
->back
->data
,
1698 &dri2_surf
->back
->data_size
,
1699 &dri2_surf
->back
->wl_buffer
)) {
1700 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
1703 wl_buffer_add_listener(dri2_surf
->back
->wl_buffer
,
1704 &wl_buffer_listener
, dri2_surf
);
1710 if (!dri2_surf
->back
) {
1711 _eglError(EGL_BAD_ALLOC
, "failed to find free buffer");
1715 dri2_surf
->back
->locked
= true;
1717 /* If we have an extra unlocked buffer at this point, we had to do triple
1718 * buffering for a while, but now can go back to just double buffering.
1719 * That means we can free any unlocked buffer now. */
1720 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1721 if (!dri2_surf
->color_buffers
[i
].locked
&&
1722 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1723 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
1724 munmap(dri2_surf
->color_buffers
[i
].data
,
1725 dri2_surf
->color_buffers
[i
].data_size
);
1726 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
1727 dri2_surf
->color_buffers
[i
].data
= NULL
;
1735 dri2_wl_swrast_get_frontbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1737 /* if there has been a resize: */
1738 if (!dri2_surf
->current
)
1741 return dri2_surf
->current
->data
;
1745 dri2_wl_swrast_get_backbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1747 assert(dri2_surf
->back
);
1748 return dri2_surf
->back
->data
;
1752 dri2_wl_swrast_commit_backbuffer(struct dri2_egl_surface
*dri2_surf
)
1754 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1756 while (dri2_surf
->throttle_callback
!= NULL
)
1757 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
1758 dri2_surf
->wl_queue
) == -1)
1761 if (dri2_surf
->base
.SwapInterval
> 0) {
1762 dri2_surf
->throttle_callback
=
1763 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
1764 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1765 &throttle_listener
, dri2_surf
);
1768 dri2_surf
->current
= dri2_surf
->back
;
1769 dri2_surf
->back
= NULL
;
1771 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
1772 dri2_surf
->current
->wl_buffer
,
1773 dri2_surf
->dx
, dri2_surf
->dy
);
1775 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
1776 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
1777 /* reset resize growing parameters */
1781 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
1782 0, 0, INT32_MAX
, INT32_MAX
);
1783 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
1785 /* If we're not waiting for a frame callback then we'll at least throttle
1786 * to a sync callback so that we always give a chance for the compositor to
1787 * handle the commit and send a release event before checking for a free
1789 if (dri2_surf
->throttle_callback
== NULL
) {
1790 dri2_surf
->throttle_callback
= wl_display_sync(dri2_surf
->wl_dpy_wrapper
);
1791 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1792 &throttle_listener
, dri2_surf
);
1795 wl_display_flush(dri2_dpy
->wl_dpy
);
1799 dri2_wl_swrast_get_drawable_info(__DRIdrawable
* draw
,
1800 int *x
, int *y
, int *w
, int *h
,
1801 void *loaderPrivate
)
1803 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1805 (void) swrast_update_buffers(dri2_surf
);
1808 *w
= dri2_surf
->base
.Width
;
1809 *h
= dri2_surf
->base
.Height
;
1813 dri2_wl_swrast_get_image(__DRIdrawable
* read
,
1814 int x
, int y
, int w
, int h
,
1815 char *data
, void *loaderPrivate
)
1817 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1818 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1819 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1820 int src_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1821 int dst_stride
= copy_width
;
1824 src
= dri2_wl_swrast_get_frontbuffer_data(dri2_surf
);
1826 memset(data
, 0, copy_width
* h
);
1830 assert(data
!= src
);
1831 assert(copy_width
<= src_stride
);
1834 src
+= y
* src_stride
;
1837 if (copy_width
> src_stride
-x_offset
)
1838 copy_width
= src_stride
-x_offset
;
1839 if (h
> dri2_surf
->base
.Height
-y
)
1840 h
= dri2_surf
->base
.Height
-y
;
1843 memcpy(dst
, src
, copy_width
);
1850 dri2_wl_swrast_put_image2(__DRIdrawable
* draw
, int op
,
1851 int x
, int y
, int w
, int h
, int stride
,
1852 char *data
, void *loaderPrivate
)
1854 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1855 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1856 int dst_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1857 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1860 assert(copy_width
<= stride
);
1862 (void) swrast_update_buffers(dri2_surf
);
1863 dst
= dri2_wl_swrast_get_backbuffer_data(dri2_surf
);
1865 /* partial copy, copy old content */
1866 if (copy_width
< dst_stride
)
1867 dri2_wl_swrast_get_image(draw
, 0, 0,
1868 dri2_surf
->base
.Width
, dri2_surf
->base
.Height
,
1869 dst
, loaderPrivate
);
1872 dst
+= y
* dst_stride
;
1876 /* drivers expect we do these checks (and some rely on it) */
1877 if (copy_width
> dst_stride
-x_offset
)
1878 copy_width
= dst_stride
-x_offset
;
1879 if (h
> dri2_surf
->base
.Height
-y
)
1880 h
= dri2_surf
->base
.Height
-y
;
1883 memcpy(dst
, src
, copy_width
);
1887 dri2_wl_swrast_commit_backbuffer(dri2_surf
);
1891 dri2_wl_swrast_put_image(__DRIdrawable
* draw
, int op
,
1892 int x
, int y
, int w
, int h
,
1893 char *data
, void *loaderPrivate
)
1895 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1898 stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1899 dri2_wl_swrast_put_image2(draw
, op
, x
, y
, w
, h
,
1900 stride
, data
, loaderPrivate
);
1904 dri2_wl_swrast_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1906 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1907 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
1909 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
1914 shm_handle_format(void *data
, struct wl_shm
*shm
, uint32_t format
)
1916 struct dri2_egl_display
*dri2_dpy
= data
;
1917 int visual_idx
= dri2_wl_visual_idx_from_shm_format(format
);
1919 if (visual_idx
== -1)
1922 dri2_dpy
->formats
|= (1u << visual_idx
);
1925 static const struct wl_shm_listener shm_listener
= {
1926 .format
= shm_handle_format
1930 registry_handle_global_swrast(void *data
, struct wl_registry
*registry
,
1931 uint32_t name
, const char *interface
,
1934 struct dri2_egl_display
*dri2_dpy
= data
;
1936 if (strcmp(interface
, "wl_shm") == 0) {
1938 wl_registry_bind(registry
, name
, &wl_shm_interface
, 1);
1939 wl_shm_add_listener(dri2_dpy
->wl_shm
, &shm_listener
, dri2_dpy
);
1943 static const struct wl_registry_listener registry_listener_swrast
= {
1944 .global
= registry_handle_global_swrast
,
1945 .global_remove
= registry_handle_global_remove
1948 static const struct dri2_egl_display_vtbl dri2_wl_swrast_display_vtbl
= {
1949 .authenticate
= NULL
,
1950 .create_window_surface
= dri2_wl_create_window_surface
,
1951 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1952 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1953 .destroy_surface
= dri2_wl_destroy_surface
,
1954 .create_image
= dri2_create_image_khr
,
1955 .swap_buffers
= dri2_wl_swrast_swap_buffers
,
1956 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
1957 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1958 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1959 .copy_buffers
= dri2_fallback_copy_buffers
,
1960 .query_buffer_age
= dri2_fallback_query_buffer_age
,
1961 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
1962 .get_sync_values
= dri2_fallback_get_sync_values
,
1963 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1966 static const __DRIswrastLoaderExtension swrast_loader_extension
= {
1967 .base
= { __DRI_SWRAST_LOADER
, 2 },
1969 .getDrawableInfo
= dri2_wl_swrast_get_drawable_info
,
1970 .putImage
= dri2_wl_swrast_put_image
,
1971 .getImage
= dri2_wl_swrast_get_image
,
1972 .putImage2
= dri2_wl_swrast_put_image2
,
1975 static const __DRIextension
*swrast_loader_extensions
[] = {
1976 &swrast_loader_extension
.base
,
1977 &image_lookup_extension
.base
,
1982 dri2_initialize_wayland_swrast(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1985 struct dri2_egl_display
*dri2_dpy
;
1987 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1989 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1992 disp
->DriverData
= (void *) dri2_dpy
;
1993 if (disp
->PlatformDisplay
== NULL
) {
1994 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1995 if (dri2_dpy
->wl_dpy
== NULL
)
1997 dri2_dpy
->own_device
= true;
1999 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
2002 dev
= _eglAddDevice(dri2_dpy
->fd
, true);
2004 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to find EGLDevice");
2010 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
2012 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
2013 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
2016 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
2017 dri2_dpy
->wl_queue
);
2019 if (dri2_dpy
->own_device
)
2020 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
2022 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
2023 wl_registry_add_listener(dri2_dpy
->wl_registry
,
2024 ®istry_listener_swrast
, dri2_dpy
);
2026 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_shm
== NULL
)
2029 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->formats
== 0)
2032 dri2_dpy
->driver_name
= strdup("swrast");
2033 if (!dri2_load_driver_swrast(disp
))
2036 dri2_dpy
->loader_extensions
= swrast_loader_extensions
;
2038 if (!dri2_create_screen(disp
))
2041 if (!dri2_setup_extensions(disp
))
2044 dri2_setup_screen(disp
);
2046 dri2_wl_setup_swap_interval(disp
);
2048 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
2049 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
2053 /* Fill vtbl last to prevent accidentally calling virtual function during
2056 dri2_dpy
->vtbl
= &dri2_wl_swrast_display_vtbl
;
2061 dri2_display_destroy(disp
);
2066 dri2_initialize_wayland(_EGLDriver
*drv
, _EGLDisplay
*disp
)
2068 EGLBoolean initialized
= EGL_FALSE
;
2070 if (!disp
->Options
.ForceSoftware
)
2071 initialized
= dri2_initialize_wayland_drm(drv
, disp
);
2074 initialized
= dri2_initialize_wayland_swrast(drv
, disp
);
2081 dri2_teardown_wayland(struct dri2_egl_display
*dri2_dpy
)
2083 if (dri2_dpy
->wl_drm
)
2084 wl_drm_destroy(dri2_dpy
->wl_drm
);
2085 if (dri2_dpy
->wl_dmabuf
)
2086 zwp_linux_dmabuf_v1_destroy(dri2_dpy
->wl_dmabuf
);
2087 if (dri2_dpy
->wl_shm
)
2088 wl_shm_destroy(dri2_dpy
->wl_shm
);
2089 if (dri2_dpy
->wl_registry
)
2090 wl_registry_destroy(dri2_dpy
->wl_registry
);
2091 if (dri2_dpy
->wl_queue
)
2092 wl_event_queue_destroy(dri2_dpy
->wl_queue
);
2093 if (dri2_dpy
->wl_dpy_wrapper
)
2094 wl_proxy_wrapper_destroy(dri2_dpy
->wl_dpy_wrapper
);
2096 for (int i
= 0; dri2_dpy
->wl_modifiers
&& i
< ARRAY_SIZE(dri2_wl_visuals
); i
++)
2097 u_vector_finish(&dri2_dpy
->wl_modifiers
[i
]);
2098 free(dri2_dpy
->wl_modifiers
);
2100 if (dri2_dpy
->own_device
)
2101 wl_display_disconnect(dri2_dpy
->wl_dpy
);