2 * Copyright © 2011-2012 Intel Corporation
3 * Copyright © 2012 Collabora, Ltd.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
26 * Kristian Høgsberg <krh@bitplanet.net>
27 * Benjamin Franzke <benjaminfranzke@googlemail.com>
39 #include <drm_fourcc.h>
43 #include "egl_dri2_fallbacks.h"
45 #include "util/u_vector.h"
46 #include "eglglobals.h"
48 #include <wayland-client.h>
49 #include "wayland-drm-client-protocol.h"
50 #include "linux-dmabuf-unstable-v1-client-protocol.h"
52 #ifndef DRM_FORMAT_MOD_INVALID
53 #define DRM_FORMAT_MOD_INVALID ((1ULL << 56) - 1)
56 #ifndef DRM_FORMAT_MOD_LINEAR
57 #define DRM_FORMAT_MOD_LINEAR 0
60 enum wl_drm_format_flags
{
69 roundtrip(struct dri2_egl_display
*dri2_dpy
)
71 return wl_display_roundtrip_queue(dri2_dpy
->wl_dpy
, dri2_dpy
->wl_queue
);
75 wl_buffer_release(void *data
, struct wl_buffer
*buffer
)
77 struct dri2_egl_surface
*dri2_surf
= data
;
80 for (i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); ++i
)
81 if (dri2_surf
->color_buffers
[i
].wl_buffer
== buffer
)
84 if (i
== ARRAY_SIZE(dri2_surf
->color_buffers
)) {
85 wl_buffer_destroy(buffer
);
89 dri2_surf
->color_buffers
[i
].locked
= false;
92 static const struct wl_buffer_listener wl_buffer_listener
= {
93 .release
= wl_buffer_release
97 resize_callback(struct wl_egl_window
*wl_win
, void *data
)
99 struct dri2_egl_surface
*dri2_surf
= data
;
100 struct dri2_egl_display
*dri2_dpy
=
101 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
103 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
107 destroy_window_callback(void *data
)
109 struct dri2_egl_surface
*dri2_surf
= data
;
110 dri2_surf
->wl_win
= NULL
;
113 static struct wl_surface
*
114 get_wl_surface_proxy(struct wl_egl_window
*window
)
116 /* Version 3 of wl_egl_window introduced a version field at the same
117 * location where a pointer to wl_surface was stored. Thus, if
118 * window->version is dereferencable, we've been given an older version of
119 * wl_egl_window, and window->version points to wl_surface */
120 if (_eglPointerIsDereferencable((void *)(window
->version
))) {
121 return wl_proxy_create_wrapper((void *)(window
->version
));
123 return wl_proxy_create_wrapper(window
->surface
);
127 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
130 dri2_wl_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
131 _EGLConfig
*conf
, void *native_window
,
132 const EGLint
*attrib_list
)
134 __DRIcreateNewDrawableFunc createNewDrawable
;
135 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
136 struct dri2_egl_config
*dri2_conf
= dri2_egl_config(conf
);
137 struct wl_egl_window
*window
= native_window
;
138 struct dri2_egl_surface
*dri2_surf
;
139 const __DRIconfig
*config
;
141 dri2_surf
= calloc(1, sizeof *dri2_surf
);
143 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
147 if (!dri2_init_surface(&dri2_surf
->base
, disp
, EGL_WINDOW_BIT
, conf
, attrib_list
, false))
150 if (dri2_dpy
->wl_dmabuf
|| dri2_dpy
->wl_drm
) {
151 if (conf
->RedSize
== 5)
152 dri2_surf
->format
= WL_DRM_FORMAT_RGB565
;
153 else if (conf
->RedSize
== 8 && conf
->AlphaSize
== 0)
154 dri2_surf
->format
= WL_DRM_FORMAT_XRGB8888
;
155 else if (conf
->RedSize
== 8)
156 dri2_surf
->format
= WL_DRM_FORMAT_ARGB8888
;
157 else if (conf
->RedSize
== 10 && conf
->AlphaSize
== 0)
158 dri2_surf
->format
= WL_DRM_FORMAT_XRGB2101010
;
159 else if (conf
->RedSize
== 10)
160 dri2_surf
->format
= WL_DRM_FORMAT_ARGB2101010
;
162 assert(dri2_dpy
->wl_shm
);
163 if (conf
->RedSize
== 5)
164 dri2_surf
->format
= WL_SHM_FORMAT_RGB565
;
165 else if (conf
->AlphaSize
== 0)
166 dri2_surf
->format
= WL_SHM_FORMAT_XRGB8888
;
168 dri2_surf
->format
= WL_SHM_FORMAT_ARGB8888
;
171 dri2_surf
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
172 if (!dri2_surf
->wl_queue
) {
173 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
177 if (dri2_dpy
->wl_drm
) {
178 dri2_surf
->wl_drm_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_drm
);
179 if (!dri2_surf
->wl_drm_wrapper
) {
180 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
183 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_drm_wrapper
,
184 dri2_surf
->wl_queue
);
187 dri2_surf
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
188 if (!dri2_surf
->wl_dpy_wrapper
) {
189 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
192 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_dpy_wrapper
,
193 dri2_surf
->wl_queue
);
195 dri2_surf
->wl_surface_wrapper
= get_wl_surface_proxy(window
);
196 if (!dri2_surf
->wl_surface_wrapper
) {
197 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
198 goto cleanup_dpy_wrapper
;
200 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_surface_wrapper
,
201 dri2_surf
->wl_queue
);
203 dri2_surf
->wl_win
= window
;
204 dri2_surf
->wl_win
->private = dri2_surf
;
205 dri2_surf
->wl_win
->destroy_window_callback
= destroy_window_callback
;
207 dri2_surf
->wl_win
->resize_callback
= resize_callback
;
209 config
= dri2_get_dri_config(dri2_conf
, EGL_WINDOW_BIT
,
210 dri2_surf
->base
.GLColorspace
);
212 if (dri2_dpy
->image_driver
)
213 createNewDrawable
= dri2_dpy
->image_driver
->createNewDrawable
;
214 else if (dri2_dpy
->dri2
)
215 createNewDrawable
= dri2_dpy
->dri2
->createNewDrawable
;
217 createNewDrawable
= dri2_dpy
->swrast
->createNewDrawable
;
219 dri2_surf
->dri_drawable
= (*createNewDrawable
)(dri2_dpy
->dri_screen
, config
,
221 if (dri2_surf
->dri_drawable
== NULL
) {
222 _eglError(EGL_BAD_ALLOC
, "createNewDrawable");
223 goto cleanup_surf_wrapper
;
226 dri2_surf
->base
.SwapInterval
= dri2_dpy
->default_swap_interval
;
228 return &dri2_surf
->base
;
230 cleanup_surf_wrapper
:
231 wl_proxy_wrapper_destroy(dri2_surf
->wl_surface_wrapper
);
233 wl_proxy_wrapper_destroy(dri2_surf
->wl_dpy_wrapper
);
235 if (dri2_surf
->wl_drm_wrapper
)
236 wl_proxy_wrapper_destroy(dri2_surf
->wl_drm_wrapper
);
238 wl_event_queue_destroy(dri2_surf
->wl_queue
);
246 dri2_wl_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
247 _EGLConfig
*conf
, void *native_window
,
248 const EGLint
*attrib_list
)
250 /* From the EGL_EXT_platform_wayland spec, version 3:
252 * It is not valid to call eglCreatePlatformPixmapSurfaceEXT with a <dpy>
253 * that belongs to Wayland. Any such call fails and generates
256 _eglError(EGL_BAD_PARAMETER
, "cannot create EGL pixmap surfaces on "
262 * Called via eglDestroySurface(), drv->API.DestroySurface().
265 dri2_wl_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
267 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
268 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
272 dri2_dpy
->core
->destroyDrawable(dri2_surf
->dri_drawable
);
274 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
275 if (dri2_surf
->color_buffers
[i
].wl_buffer
)
276 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
277 if (dri2_surf
->color_buffers
[i
].dri_image
)
278 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
279 if (dri2_surf
->color_buffers
[i
].linear_copy
)
280 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
281 if (dri2_surf
->color_buffers
[i
].data
)
282 munmap(dri2_surf
->color_buffers
[i
].data
,
283 dri2_surf
->color_buffers
[i
].data_size
);
287 dri2_egl_surface_free_local_buffers(dri2_surf
);
289 if (dri2_surf
->throttle_callback
)
290 wl_callback_destroy(dri2_surf
->throttle_callback
);
292 if (dri2_surf
->wl_win
) {
293 dri2_surf
->wl_win
->private = NULL
;
294 dri2_surf
->wl_win
->resize_callback
= NULL
;
295 dri2_surf
->wl_win
->destroy_window_callback
= NULL
;
298 wl_proxy_wrapper_destroy(dri2_surf
->wl_surface_wrapper
);
299 wl_proxy_wrapper_destroy(dri2_surf
->wl_dpy_wrapper
);
300 if (dri2_surf
->wl_drm_wrapper
)
301 wl_proxy_wrapper_destroy(dri2_surf
->wl_drm_wrapper
);
302 wl_event_queue_destroy(dri2_surf
->wl_queue
);
304 dri2_fini_surface(surf
);
311 dri2_wl_release_buffers(struct dri2_egl_surface
*dri2_surf
)
313 struct dri2_egl_display
*dri2_dpy
=
314 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
316 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
317 if (dri2_surf
->color_buffers
[i
].wl_buffer
&&
318 !dri2_surf
->color_buffers
[i
].locked
)
319 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
320 if (dri2_surf
->color_buffers
[i
].dri_image
)
321 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
322 if (dri2_surf
->color_buffers
[i
].linear_copy
)
323 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
324 if (dri2_surf
->color_buffers
[i
].data
)
325 munmap(dri2_surf
->color_buffers
[i
].data
,
326 dri2_surf
->color_buffers
[i
].data_size
);
328 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
329 dri2_surf
->color_buffers
[i
].dri_image
= NULL
;
330 dri2_surf
->color_buffers
[i
].linear_copy
= NULL
;
331 dri2_surf
->color_buffers
[i
].data
= NULL
;
332 dri2_surf
->color_buffers
[i
].locked
= false;
336 dri2_egl_surface_free_local_buffers(dri2_surf
);
340 get_back_bo(struct dri2_egl_surface
*dri2_surf
)
342 struct dri2_egl_display
*dri2_dpy
=
343 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
345 unsigned int dri_image_format
;
349 /* currently supports five WL DRM formats,
350 * WL_DRM_FORMAT_ARGB2101010, WL_DRM_FORMAT_XRGB2101010,
351 * WL_DRM_FORMAT_ARGB8888, WL_DRM_FORMAT_XRGB8888,
352 * and WL_DRM_FORMAT_RGB565
354 switch (dri2_surf
->format
) {
355 case WL_DRM_FORMAT_ARGB2101010
:
356 dri_image_format
= __DRI_IMAGE_FORMAT_ARGB2101010
;
358 case WL_DRM_FORMAT_XRGB2101010
:
359 dri_image_format
= __DRI_IMAGE_FORMAT_XRGB2101010
;
361 case WL_DRM_FORMAT_ARGB8888
:
362 dri_image_format
= __DRI_IMAGE_FORMAT_ARGB8888
;
363 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.argb8888
);
364 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.argb8888
);
366 case WL_DRM_FORMAT_XRGB8888
:
367 dri_image_format
= __DRI_IMAGE_FORMAT_XRGB8888
;
368 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.xrgb8888
);
369 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.xrgb8888
);
371 case WL_DRM_FORMAT_RGB565
:
372 dri_image_format
= __DRI_IMAGE_FORMAT_RGB565
;
373 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.rgb565
);
374 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.rgb565
);
377 /* format is not supported */
381 /* There might be a buffer release already queued that wasn't processed */
382 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
384 while (dri2_surf
->back
== NULL
) {
385 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
386 /* Get an unlocked buffer, preferrably one with a dri_buffer
387 * already allocated. */
388 if (dri2_surf
->color_buffers
[i
].locked
)
390 if (dri2_surf
->back
== NULL
)
391 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
392 else if (dri2_surf
->back
->dri_image
== NULL
)
393 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
399 /* If we don't have a buffer, then block on the server to release one for
400 * us, and try again. wl_display_dispatch_queue will process any pending
401 * events, however not all servers flush on issuing a buffer release
402 * event. So, we spam the server with roundtrips as they always cause a
405 if (wl_display_roundtrip_queue(dri2_dpy
->wl_dpy
,
406 dri2_surf
->wl_queue
) < 0)
410 if (dri2_surf
->back
== NULL
)
413 use_flags
= __DRI_IMAGE_USE_SHARE
| __DRI_IMAGE_USE_BACKBUFFER
;
415 if (dri2_dpy
->is_different_gpu
&&
416 dri2_surf
->back
->linear_copy
== NULL
) {
417 /* The LINEAR modifier should be a perfect alias of the LINEAR use
418 * flag; try the new interface first before the old, then fall back. */
419 if (dri2_dpy
->image
->base
.version
>= 15 &&
420 dri2_dpy
->image
->createImageWithModifiers
) {
421 uint64_t linear_mod
= DRM_FORMAT_MOD_LINEAR
;
423 dri2_surf
->back
->linear_copy
=
424 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
425 dri2_surf
->base
.Width
,
426 dri2_surf
->base
.Height
,
432 dri2_surf
->back
->linear_copy
=
433 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
434 dri2_surf
->base
.Width
,
435 dri2_surf
->base
.Height
,
438 __DRI_IMAGE_USE_LINEAR
,
441 if (dri2_surf
->back
->linear_copy
== NULL
)
445 if (dri2_surf
->back
->dri_image
== NULL
) {
446 /* If our DRIImage implementation does not support
447 * createImageWithModifiers, then fall back to the old createImage,
448 * and hope it allocates an image which is acceptable to the winsys.
450 if (num_modifiers
&& dri2_dpy
->image
->base
.version
>= 15 &&
451 dri2_dpy
->image
->createImageWithModifiers
) {
452 dri2_surf
->back
->dri_image
=
453 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
454 dri2_surf
->base
.Width
,
455 dri2_surf
->base
.Height
,
461 dri2_surf
->back
->dri_image
=
462 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
463 dri2_surf
->base
.Width
,
464 dri2_surf
->base
.Height
,
466 dri2_dpy
->is_different_gpu
?
471 dri2_surf
->back
->age
= 0;
473 if (dri2_surf
->back
->dri_image
== NULL
)
476 dri2_surf
->back
->locked
= true;
483 back_bo_to_dri_buffer(struct dri2_egl_surface
*dri2_surf
, __DRIbuffer
*buffer
)
485 struct dri2_egl_display
*dri2_dpy
=
486 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
490 image
= dri2_surf
->back
->dri_image
;
492 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
493 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &pitch
);
495 buffer
->attachment
= __DRI_BUFFER_BACK_LEFT
;
497 buffer
->pitch
= pitch
;
503 update_buffers(struct dri2_egl_surface
*dri2_surf
)
505 struct dri2_egl_display
*dri2_dpy
=
506 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
508 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->width
||
509 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->height
) {
511 dri2_wl_release_buffers(dri2_surf
);
513 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
514 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
515 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
516 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
519 if (get_back_bo(dri2_surf
) < 0) {
520 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
524 /* If we have an extra unlocked buffer at this point, we had to do triple
525 * buffering for a while, but now can go back to just double buffering.
526 * That means we can free any unlocked buffer now. */
527 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
528 if (!dri2_surf
->color_buffers
[i
].locked
&&
529 dri2_surf
->color_buffers
[i
].wl_buffer
) {
530 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
531 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
532 if (dri2_dpy
->is_different_gpu
)
533 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
534 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
535 dri2_surf
->color_buffers
[i
].dri_image
= NULL
;
536 dri2_surf
->color_buffers
[i
].linear_copy
= NULL
;
544 dri2_wl_get_buffers_with_format(__DRIdrawable
* driDrawable
,
545 int *width
, int *height
,
546 unsigned int *attachments
, int count
,
547 int *out_count
, void *loaderPrivate
)
549 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
552 if (update_buffers(dri2_surf
) < 0)
555 for (i
= 0, j
= 0; i
< 2 * count
; i
+= 2, j
++) {
558 switch (attachments
[i
]) {
559 case __DRI_BUFFER_BACK_LEFT
:
560 back_bo_to_dri_buffer(dri2_surf
, &dri2_surf
->buffers
[j
]);
563 local
= dri2_egl_surface_alloc_local_buffer(dri2_surf
, attachments
[i
],
567 _eglError(EGL_BAD_ALLOC
, "failed to allocate local buffer");
570 dri2_surf
->buffers
[j
] = *local
;
579 *width
= dri2_surf
->base
.Width
;
580 *height
= dri2_surf
->base
.Height
;
582 return dri2_surf
->buffers
;
586 dri2_wl_get_buffers(__DRIdrawable
* driDrawable
,
587 int *width
, int *height
,
588 unsigned int *attachments
, int count
,
589 int *out_count
, void *loaderPrivate
)
591 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
592 unsigned int *attachments_with_format
;
596 switch (dri2_surf
->format
) {
597 case WL_DRM_FORMAT_ARGB2101010
:
598 case WL_DRM_FORMAT_XRGB2101010
:
599 case WL_DRM_FORMAT_ARGB8888
:
600 case WL_DRM_FORMAT_XRGB8888
:
603 case WL_DRM_FORMAT_RGB565
:
607 /* format is not supported */
611 attachments_with_format
= calloc(count
, 2 * sizeof(unsigned int));
612 if (!attachments_with_format
) {
617 for (int i
= 0; i
< count
; ++i
) {
618 attachments_with_format
[2*i
] = attachments
[i
];
619 attachments_with_format
[2*i
+ 1] = bpp
;
623 dri2_wl_get_buffers_with_format(driDrawable
,
625 attachments_with_format
, count
,
626 out_count
, loaderPrivate
);
628 free(attachments_with_format
);
634 image_get_buffers(__DRIdrawable
*driDrawable
,
638 uint32_t buffer_mask
,
639 struct __DRIimageList
*buffers
)
641 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
643 if (update_buffers(dri2_surf
) < 0)
646 buffers
->image_mask
= __DRI_IMAGE_BUFFER_BACK
;
647 buffers
->back
= dri2_surf
->back
->dri_image
;
653 dri2_wl_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
656 (void) loaderPrivate
;
659 static const __DRIdri2LoaderExtension dri2_loader_extension
= {
660 .base
= { __DRI_DRI2_LOADER
, 3 },
662 .getBuffers
= dri2_wl_get_buffers
,
663 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
664 .getBuffersWithFormat
= dri2_wl_get_buffers_with_format
,
667 static const __DRIimageLoaderExtension image_loader_extension
= {
668 .base
= { __DRI_IMAGE_LOADER
, 1 },
670 .getBuffers
= image_get_buffers
,
671 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
675 wayland_throttle_callback(void *data
,
676 struct wl_callback
*callback
,
679 struct dri2_egl_surface
*dri2_surf
= data
;
681 dri2_surf
->throttle_callback
= NULL
;
682 wl_callback_destroy(callback
);
685 static const struct wl_callback_listener throttle_listener
= {
686 .done
= wayland_throttle_callback
690 get_fourcc(struct dri2_egl_display
*dri2_dpy
,
691 __DRIimage
*image
, int *fourcc
)
696 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FOURCC
,
701 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
,
706 switch (dri_format
) {
707 case __DRI_IMAGE_FORMAT_ARGB8888
:
708 *fourcc
= __DRI_IMAGE_FOURCC_ARGB8888
;
710 case __DRI_IMAGE_FORMAT_XRGB8888
:
711 *fourcc
= __DRI_IMAGE_FOURCC_XRGB8888
;
718 static struct wl_buffer
*
719 create_wl_buffer(struct dri2_egl_display
*dri2_dpy
,
720 struct dri2_egl_surface
*dri2_surf
,
723 struct wl_buffer
*ret
;
725 int width
, height
, fourcc
, num_planes
;
726 uint64_t modifier
= DRM_FORMAT_MOD_INVALID
;
728 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_WIDTH
, &width
);
729 query
&= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_HEIGHT
,
731 query
&= get_fourcc(dri2_dpy
, image
, &fourcc
);
735 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NUM_PLANES
,
740 if (dri2_dpy
->image
->base
.version
>= 15) {
743 query
= dri2_dpy
->image
->queryImage(image
,
744 __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
,
746 query
&= dri2_dpy
->image
->queryImage(image
,
747 __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
,
750 modifier
= (uint64_t) mod_hi
<< 32;
751 modifier
|= (uint64_t) (mod_lo
& 0xffffffff);
755 if (dri2_dpy
->wl_dmabuf
&& modifier
!= DRM_FORMAT_MOD_INVALID
) {
756 struct zwp_linux_buffer_params_v1
*params
;
759 /* We don't need a wrapper for wl_dmabuf objects, because we have to
760 * create the intermediate params object; we can set the queue on this,
761 * and the wl_buffer inherits it race-free. */
762 params
= zwp_linux_dmabuf_v1_create_params(dri2_dpy
->wl_dmabuf
);
764 wl_proxy_set_queue((struct wl_proxy
*) params
, dri2_surf
->wl_queue
);
766 for (i
= 0; i
< num_planes
; i
++) {
774 p_image
= dri2_dpy
->image
->fromPlanar(image
, i
, NULL
);
776 zwp_linux_buffer_params_v1_destroy(params
);
780 query
= dri2_dpy
->image
->queryImage(p_image
,
781 __DRI_IMAGE_ATTRIB_FD
,
783 query
&= dri2_dpy
->image
->queryImage(p_image
,
784 __DRI_IMAGE_ATTRIB_STRIDE
,
786 query
&= dri2_dpy
->image
->queryImage(p_image
,
787 __DRI_IMAGE_ATTRIB_OFFSET
,
789 if (image
!= p_image
)
790 dri2_dpy
->image
->destroyImage(p_image
);
795 zwp_linux_buffer_params_v1_destroy(params
);
799 zwp_linux_buffer_params_v1_add(params
, fd
, i
, offset
, stride
,
800 modifier
>> 32, modifier
& 0xffffffff);
804 ret
= zwp_linux_buffer_params_v1_create_immed(params
, width
, height
,
806 zwp_linux_buffer_params_v1_destroy(params
);
807 } else if (dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
) {
808 struct wl_drm
*wl_drm
=
809 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
815 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FD
, &fd
);
816 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
817 ret
= wl_drm_create_prime_buffer(wl_drm
, fd
, width
, height
, fourcc
, 0,
821 struct wl_drm
*wl_drm
=
822 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
828 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
829 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
830 ret
= wl_drm_create_buffer(wl_drm
, name
, width
, height
, stride
, fourcc
);
837 try_damage_buffer(struct dri2_egl_surface
*dri2_surf
,
841 if (wl_proxy_get_version((struct wl_proxy
*) dri2_surf
->wl_surface_wrapper
)
842 < WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION
)
845 for (int i
= 0; i
< n_rects
; i
++) {
846 const int *rect
= &rects
[i
* 4];
848 wl_surface_damage_buffer(dri2_surf
->wl_surface_wrapper
,
850 dri2_surf
->base
.Height
- rect
[1] - rect
[3],
856 * Called via eglSwapBuffers(), drv->API.SwapBuffers().
859 dri2_wl_swap_buffers_with_damage(_EGLDriver
*drv
,
865 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
866 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
868 while (dri2_surf
->throttle_callback
!= NULL
)
869 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
870 dri2_surf
->wl_queue
) == -1)
873 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
874 if (dri2_surf
->color_buffers
[i
].age
> 0)
875 dri2_surf
->color_buffers
[i
].age
++;
877 /* Make sure we have a back buffer in case we're swapping without ever
879 if (get_back_bo(dri2_surf
) < 0)
880 return _eglError(EGL_BAD_ALLOC
, "dri2_swap_buffers");
882 if (draw
->SwapInterval
> 0) {
883 dri2_surf
->throttle_callback
=
884 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
885 wl_callback_add_listener(dri2_surf
->throttle_callback
,
886 &throttle_listener
, dri2_surf
);
889 dri2_surf
->back
->age
= 1;
890 dri2_surf
->current
= dri2_surf
->back
;
891 dri2_surf
->back
= NULL
;
893 if (!dri2_surf
->current
->wl_buffer
) {
896 if (dri2_dpy
->is_different_gpu
)
897 image
= dri2_surf
->current
->linear_copy
;
899 image
= dri2_surf
->current
->dri_image
;
901 dri2_surf
->current
->wl_buffer
=
902 create_wl_buffer(dri2_dpy
, dri2_surf
, image
);
904 wl_buffer_add_listener(dri2_surf
->current
->wl_buffer
,
905 &wl_buffer_listener
, dri2_surf
);
908 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
909 dri2_surf
->current
->wl_buffer
,
910 dri2_surf
->dx
, dri2_surf
->dy
);
912 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
913 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
914 /* reset resize growing parameters */
918 /* If the compositor doesn't support damage_buffer, we deliberately
919 * ignore the damage region and post maximum damage, due to
920 * https://bugs.freedesktop.org/78190 */
921 if (!n_rects
|| !try_damage_buffer(dri2_surf
, rects
, n_rects
))
922 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
923 0, 0, INT32_MAX
, INT32_MAX
);
925 if (dri2_dpy
->is_different_gpu
) {
926 _EGLContext
*ctx
= _eglGetCurrentContext();
927 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
928 dri2_dpy
->image
->blitImage(dri2_ctx
->dri_context
,
929 dri2_surf
->current
->linear_copy
,
930 dri2_surf
->current
->dri_image
,
931 0, 0, dri2_surf
->base
.Width
,
932 dri2_surf
->base
.Height
,
933 0, 0, dri2_surf
->base
.Width
,
934 dri2_surf
->base
.Height
, 0);
937 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
938 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
940 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
942 /* If we're not waiting for a frame callback then we'll at least throttle
943 * to a sync callback so that we always give a chance for the compositor to
944 * handle the commit and send a release event before checking for a free
946 if (dri2_surf
->throttle_callback
== NULL
) {
947 dri2_surf
->throttle_callback
= wl_display_sync(dri2_surf
->wl_dpy_wrapper
);
948 wl_callback_add_listener(dri2_surf
->throttle_callback
,
949 &throttle_listener
, dri2_surf
);
952 wl_display_flush(dri2_dpy
->wl_dpy
);
958 dri2_wl_query_buffer_age(_EGLDriver
*drv
,
959 _EGLDisplay
*disp
, _EGLSurface
*surface
)
961 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
963 if (get_back_bo(dri2_surf
) < 0) {
964 _eglError(EGL_BAD_ALLOC
, "dri2_query_buffer_age");
968 return dri2_surf
->back
->age
;
972 dri2_wl_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
974 return dri2_wl_swap_buffers_with_damage(drv
, disp
, draw
, NULL
, 0);
977 static struct wl_buffer
*
978 dri2_wl_create_wayland_buffer_from_image(_EGLDriver
*drv
,
982 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
983 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
984 __DRIimage
*image
= dri2_img
->dri_image
;
985 struct wl_buffer
*buffer
;
988 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
, &format
);
990 case __DRI_IMAGE_FORMAT_ARGB2101010
:
991 if (!(dri2_dpy
->formats
& HAS_ARGB2101010
))
994 case __DRI_IMAGE_FORMAT_XRGB2101010
:
995 if (!(dri2_dpy
->formats
& HAS_XRGB2101010
))
998 case __DRI_IMAGE_FORMAT_ARGB8888
:
999 if (!(dri2_dpy
->formats
& HAS_ARGB8888
))
1002 case __DRI_IMAGE_FORMAT_XRGB8888
:
1003 if (!(dri2_dpy
->formats
& HAS_XRGB8888
))
1010 buffer
= create_wl_buffer(dri2_dpy
, NULL
, image
);
1012 /* The buffer object will have been created with our internal event queue
1013 * because it is using wl_dmabuf/wl_drm as a proxy factory. We want the
1014 * buffer to be used by the application so we'll reset it to the display's
1015 * default event queue. This isn't actually racy, as the only event the
1016 * buffer can get is a buffer release, which doesn't happen with an explicit
1019 wl_proxy_set_queue((struct wl_proxy
*) buffer
, NULL
);
1024 _eglError(EGL_BAD_MATCH
, "unsupported image format");
1029 dri2_wl_authenticate(_EGLDisplay
*disp
, uint32_t id
)
1031 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1034 if (dri2_dpy
->is_render_node
) {
1035 _eglLog(_EGL_WARNING
, "wayland-egl: client asks server to "
1036 "authenticate for render-nodes");
1039 dri2_dpy
->authenticated
= false;
1041 wl_drm_authenticate(dri2_dpy
->wl_drm
, id
);
1042 if (roundtrip(dri2_dpy
) < 0)
1045 if (!dri2_dpy
->authenticated
)
1048 /* reset authenticated */
1049 dri2_dpy
->authenticated
= true;
1055 drm_handle_device(void *data
, struct wl_drm
*drm
, const char *device
)
1057 struct dri2_egl_display
*dri2_dpy
= data
;
1060 dri2_dpy
->device_name
= strdup(device
);
1061 if (!dri2_dpy
->device_name
)
1064 dri2_dpy
->fd
= loader_open_device(dri2_dpy
->device_name
);
1065 if (dri2_dpy
->fd
== -1) {
1066 _eglLog(_EGL_WARNING
, "wayland-egl: could not open %s (%s)",
1067 dri2_dpy
->device_name
, strerror(errno
));
1071 if (drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
) {
1072 dri2_dpy
->authenticated
= true;
1074 drmGetMagic(dri2_dpy
->fd
, &magic
);
1075 wl_drm_authenticate(dri2_dpy
->wl_drm
, magic
);
1080 drm_handle_format(void *data
, struct wl_drm
*drm
, uint32_t format
)
1082 struct dri2_egl_display
*dri2_dpy
= data
;
1085 case WL_DRM_FORMAT_ARGB2101010
:
1086 dri2_dpy
->formats
|= HAS_ARGB2101010
;
1088 case WL_DRM_FORMAT_XRGB2101010
:
1089 dri2_dpy
->formats
|= HAS_XRGB2101010
;
1091 case WL_DRM_FORMAT_ARGB8888
:
1092 dri2_dpy
->formats
|= HAS_ARGB8888
;
1094 case WL_DRM_FORMAT_XRGB8888
:
1095 dri2_dpy
->formats
|= HAS_XRGB8888
;
1097 case WL_DRM_FORMAT_RGB565
:
1098 dri2_dpy
->formats
|= HAS_RGB565
;
1104 drm_handle_capabilities(void *data
, struct wl_drm
*drm
, uint32_t value
)
1106 struct dri2_egl_display
*dri2_dpy
= data
;
1108 dri2_dpy
->capabilities
= value
;
1112 drm_handle_authenticated(void *data
, struct wl_drm
*drm
)
1114 struct dri2_egl_display
*dri2_dpy
= data
;
1116 dri2_dpy
->authenticated
= true;
1119 static const struct wl_drm_listener drm_listener
= {
1120 .device
= drm_handle_device
,
1121 .format
= drm_handle_format
,
1122 .authenticated
= drm_handle_authenticated
,
1123 .capabilities
= drm_handle_capabilities
1127 dmabuf_ignore_format(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1130 /* formats are implicitly advertised by the 'modifier' event, so ignore */
1134 dmabuf_handle_modifier(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1135 uint32_t format
, uint32_t modifier_hi
,
1136 uint32_t modifier_lo
)
1138 struct dri2_egl_display
*dri2_dpy
= data
;
1139 uint64_t *mod
= NULL
;
1141 if (modifier_hi
== (DRM_FORMAT_MOD_INVALID
>> 32) &&
1142 modifier_lo
== (DRM_FORMAT_MOD_INVALID
& 0xffffffff))
1146 case WL_DRM_FORMAT_ARGB8888
:
1147 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.argb8888
);
1148 dri2_dpy
->formats
|= HAS_ARGB8888
;
1150 case WL_DRM_FORMAT_XRGB8888
:
1151 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.xrgb8888
);
1152 dri2_dpy
->formats
|= HAS_XRGB8888
;
1154 case WL_DRM_FORMAT_RGB565
:
1155 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.rgb565
);
1156 dri2_dpy
->formats
|= HAS_RGB565
;
1165 *mod
= (uint64_t) modifier_hi
<< 32;
1166 *mod
|= (uint64_t) (modifier_lo
& 0xffffffff);
1169 static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener
= {
1170 .format
= dmabuf_ignore_format
,
1171 .modifier
= dmabuf_handle_modifier
,
1175 registry_handle_global_drm(void *data
, struct wl_registry
*registry
,
1176 uint32_t name
, const char *interface
,
1179 struct dri2_egl_display
*dri2_dpy
= data
;
1181 if (strcmp(interface
, "wl_drm") == 0) {
1183 wl_registry_bind(registry
, name
, &wl_drm_interface
, MIN2(version
, 2));
1184 wl_drm_add_listener(dri2_dpy
->wl_drm
, &drm_listener
, dri2_dpy
);
1185 } else if (strcmp(interface
, "zwp_linux_dmabuf_v1") == 0 && version
>= 3) {
1186 dri2_dpy
->wl_dmabuf
=
1187 wl_registry_bind(registry
, name
, &zwp_linux_dmabuf_v1_interface
,
1189 zwp_linux_dmabuf_v1_add_listener(dri2_dpy
->wl_dmabuf
, &dmabuf_listener
,
1195 registry_handle_global_remove(void *data
, struct wl_registry
*registry
,
1200 static const struct wl_registry_listener registry_listener_drm
= {
1201 .global
= registry_handle_global_drm
,
1202 .global_remove
= registry_handle_global_remove
1206 dri2_wl_setup_swap_interval(_EGLDisplay
*disp
)
1208 /* We can't use values greater than 1 on Wayland because we are using the
1209 * frame callback to synchronise the frame and the only way we be sure to
1210 * get a frame callback is to attach a new buffer. Therefore we can't just
1211 * sit drawing nothing to wait until the next ‘n’ frame callbacks */
1213 dri2_setup_swap_interval(disp
, 1);
1216 static const struct dri2_egl_display_vtbl dri2_wl_display_vtbl
= {
1217 .authenticate
= dri2_wl_authenticate
,
1218 .create_window_surface
= dri2_wl_create_window_surface
,
1219 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1220 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1221 .destroy_surface
= dri2_wl_destroy_surface
,
1222 .create_image
= dri2_create_image_khr
,
1223 .swap_buffers
= dri2_wl_swap_buffers
,
1224 .swap_buffers_with_damage
= dri2_wl_swap_buffers_with_damage
,
1225 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1226 .set_damage_region
= dri2_fallback_set_damage_region
,
1227 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1228 .copy_buffers
= dri2_fallback_copy_buffers
,
1229 .query_buffer_age
= dri2_wl_query_buffer_age
,
1230 .create_wayland_buffer_from_image
= dri2_wl_create_wayland_buffer_from_image
,
1231 .get_sync_values
= dri2_fallback_get_sync_values
,
1232 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1235 static const __DRIextension
*dri2_loader_extensions
[] = {
1236 &dri2_loader_extension
.base
,
1237 &image_loader_extension
.base
,
1238 &image_lookup_extension
.base
,
1239 &use_invalidate
.base
,
1243 static const __DRIextension
*image_loader_extensions
[] = {
1244 &image_loader_extension
.base
,
1245 &image_lookup_extension
.base
,
1246 &use_invalidate
.base
,
1251 dri2_wl_add_configs_for_visuals(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1253 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1254 static const struct {
1255 const char *format_name
;
1257 unsigned int rgba_masks
[4];
1259 { "XRGB2101010", HAS_XRGB2101010
, { 0x3ff00000, 0xffc00, 0x3ff, 0 } },
1260 { "ARGB2101010", HAS_ARGB2101010
, { 0x3ff00000, 0xffc00, 0x3ff, 0xc0000000 } },
1261 { "XRGB8888", HAS_XRGB8888
, { 0xff0000, 0xff00, 0x00ff, 0xff000000 } },
1262 { "ARGB8888", HAS_ARGB8888
, { 0xff0000, 0xff00, 0x00ff, 0 } },
1263 { "RGB565", HAS_RGB565
, { 0x00f800, 0x07e0, 0x001f, 0 } },
1265 unsigned int format_count
[ARRAY_SIZE(visuals
)] = { 0 };
1266 unsigned int count
= 0;
1268 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
1269 for (unsigned j
= 0; j
< ARRAY_SIZE(visuals
); j
++) {
1270 struct dri2_egl_config
*dri2_conf
;
1272 if (!(dri2_dpy
->formats
& visuals
[j
].has_format
))
1275 dri2_conf
= dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
1276 count
+ 1, EGL_WINDOW_BIT
, NULL
, visuals
[j
].rgba_masks
);
1278 if (dri2_conf
->base
.ConfigID
== count
+ 1)
1285 for (unsigned i
= 0; i
< ARRAY_SIZE(format_count
); i
++) {
1286 if (!format_count
[i
]) {
1287 _eglLog(_EGL_DEBUG
, "No DRI config supports native format %s",
1288 visuals
[i
].format_name
);
1292 return (count
!= 0);
1296 dri2_initialize_wayland_drm(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1298 struct dri2_egl_display
*dri2_dpy
;
1300 loader_set_logger(_eglLog
);
1302 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1304 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1307 disp
->DriverData
= (void *) dri2_dpy
;
1308 if (disp
->PlatformDisplay
== NULL
) {
1309 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1310 if (dri2_dpy
->wl_dpy
== NULL
)
1312 dri2_dpy
->own_device
= true;
1314 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
1317 if (!u_vector_init(&dri2_dpy
->wl_modifiers
.xrgb8888
, sizeof(uint64_t), 32) ||
1318 !u_vector_init(&dri2_dpy
->wl_modifiers
.argb8888
, sizeof(uint64_t), 32) ||
1319 !u_vector_init(&dri2_dpy
->wl_modifiers
.rgb565
, sizeof(uint64_t), 32)) {
1323 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
1325 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
1326 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
1329 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
1330 dri2_dpy
->wl_queue
);
1332 if (dri2_dpy
->own_device
)
1333 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
1335 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
1336 wl_registry_add_listener(dri2_dpy
->wl_registry
,
1337 ®istry_listener_drm
, dri2_dpy
);
1338 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_drm
== NULL
)
1341 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->fd
== -1)
1344 if (roundtrip(dri2_dpy
) < 0 || !dri2_dpy
->authenticated
)
1347 dri2_dpy
->fd
= loader_get_user_preferred_fd(dri2_dpy
->fd
,
1348 &dri2_dpy
->is_different_gpu
);
1349 if (dri2_dpy
->is_different_gpu
) {
1350 free(dri2_dpy
->device_name
);
1351 dri2_dpy
->device_name
= loader_get_device_name_for_fd(dri2_dpy
->fd
);
1352 if (!dri2_dpy
->device_name
) {
1353 _eglError(EGL_BAD_ALLOC
, "wayland-egl: failed to get device name "
1354 "for requested GPU");
1359 /* we have to do the check now, because loader_get_user_preferred_fd
1360 * will return a render-node when the requested gpu is different
1361 * to the server, but also if the client asks for the same gpu than
1362 * the server by requesting its pci-id */
1363 dri2_dpy
->is_render_node
= drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
;
1365 dri2_dpy
->driver_name
= loader_get_driver_for_fd(dri2_dpy
->fd
);
1366 if (dri2_dpy
->driver_name
== NULL
) {
1367 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to get driver name");
1371 /* render nodes cannot use Gem names, and thus do not support
1372 * the __DRI_DRI2_LOADER extension */
1373 if (!dri2_dpy
->is_render_node
) {
1374 dri2_dpy
->loader_extensions
= dri2_loader_extensions
;
1375 if (!dri2_load_driver(disp
)) {
1376 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to load driver");
1380 dri2_dpy
->loader_extensions
= image_loader_extensions
;
1381 if (!dri2_load_driver_dri3(disp
)) {
1382 _eglError(EGL_BAD_ALLOC
, "DRI3: failed to load driver");
1387 if (!dri2_create_screen(disp
))
1390 if (!dri2_setup_extensions(disp
))
1393 dri2_setup_screen(disp
);
1395 dri2_wl_setup_swap_interval(disp
);
1397 /* To use Prime, we must have _DRI_IMAGE v7 at least.
1398 * createImageFromFds support indicates that Prime export/import
1399 * is supported by the driver. Fall back to
1400 * gem names if we don't have Prime support. */
1402 if (dri2_dpy
->image
->base
.version
< 7 ||
1403 dri2_dpy
->image
->createImageFromFds
== NULL
)
1404 dri2_dpy
->capabilities
&= ~WL_DRM_CAPABILITY_PRIME
;
1406 /* We cannot use Gem names with render-nodes, only prime fds (dma-buf).
1407 * The server needs to accept them */
1408 if (dri2_dpy
->is_render_node
&&
1409 !(dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
)) {
1410 _eglLog(_EGL_WARNING
, "wayland-egl: display is not render-node capable");
1414 if (dri2_dpy
->is_different_gpu
&&
1415 (dri2_dpy
->image
->base
.version
< 9 ||
1416 dri2_dpy
->image
->blitImage
== NULL
)) {
1417 _eglLog(_EGL_WARNING
, "wayland-egl: Different GPU selected, but the "
1418 "Image extension in the driver is not "
1419 "compatible. Version 9 or later and blitImage() "
1424 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
1425 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
1429 dri2_set_WL_bind_wayland_display(drv
, disp
);
1430 /* When cannot convert EGLImage to wl_buffer when on a different gpu,
1431 * because the buffer of the EGLImage has likely a tiling mode the server
1432 * gpu won't support. These is no way to check for now. Thus do not support the
1434 if (!dri2_dpy
->is_different_gpu
)
1435 disp
->Extensions
.WL_create_wayland_buffer_from_image
= EGL_TRUE
;
1437 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
1439 disp
->Extensions
.EXT_swap_buffers_with_damage
= EGL_TRUE
;
1441 /* Fill vtbl last to prevent accidentally calling virtual function during
1444 dri2_dpy
->vtbl
= &dri2_wl_display_vtbl
;
1449 dri2_display_destroy(disp
);
1454 dri2_wl_swrast_get_stride_for_format(int format
, int w
)
1456 if (format
== WL_SHM_FORMAT_RGB565
)
1458 else /* ARGB8888 || XRGB8888 */
1463 * Taken from weston shared/os-compatibility.c
1466 #ifndef HAVE_MKOSTEMP
1469 set_cloexec_or_close(int fd
)
1476 flags
= fcntl(fd
, F_GETFD
);
1480 if (fcntl(fd
, F_SETFD
, flags
| FD_CLOEXEC
) == -1)
1493 * Taken from weston shared/os-compatibility.c
1497 create_tmpfile_cloexec(char *tmpname
)
1501 #ifdef HAVE_MKOSTEMP
1502 fd
= mkostemp(tmpname
, O_CLOEXEC
);
1506 fd
= mkstemp(tmpname
);
1508 fd
= set_cloexec_or_close(fd
);
1517 * Taken from weston shared/os-compatibility.c
1519 * Create a new, unique, anonymous file of the given size, and
1520 * return the file descriptor for it. The file descriptor is set
1521 * CLOEXEC. The file is immediately suitable for mmap()'ing
1522 * the given size at offset zero.
1524 * The file should not have a permanent backing store like a disk,
1525 * but may have if XDG_RUNTIME_DIR is not properly implemented in OS.
1527 * The file name is deleted from the file system.
1529 * The file is suitable for buffer sharing between processes by
1530 * transmitting the file descriptor over Unix sockets using the
1531 * SCM_RIGHTS methods.
1533 * If the C library implements posix_fallocate(), it is used to
1534 * guarantee that disk space is available for the file at the
1535 * given size. If disk space is insufficent, errno is set to ENOSPC.
1536 * If posix_fallocate() is not supported, program may receive
1537 * SIGBUS on accessing mmap()'ed file contents instead.
1540 os_create_anonymous_file(off_t size
)
1542 static const char templ
[] = "/mesa-shared-XXXXXX";
1548 path
= getenv("XDG_RUNTIME_DIR");
1554 name
= malloc(strlen(path
) + sizeof(templ
));
1559 strcat(name
, templ
);
1561 fd
= create_tmpfile_cloexec(name
);
1568 ret
= ftruncate(fd
, size
);
1579 dri2_wl_swrast_allocate_buffer(struct dri2_egl_surface
*dri2_surf
,
1580 int format
, int w
, int h
,
1581 void **data
, int *size
,
1582 struct wl_buffer
**buffer
)
1584 struct dri2_egl_display
*dri2_dpy
=
1585 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1586 struct wl_shm_pool
*pool
;
1587 int fd
, stride
, size_map
;
1590 stride
= dri2_wl_swrast_get_stride_for_format(format
, w
);
1591 size_map
= h
* stride
;
1593 /* Create a sharable buffer */
1594 fd
= os_create_anonymous_file(size_map
);
1598 data_map
= mmap(NULL
, size_map
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
1599 if (data_map
== MAP_FAILED
) {
1604 /* Share it in a wl_buffer */
1605 pool
= wl_shm_create_pool(dri2_dpy
->wl_shm
, fd
, size_map
);
1606 wl_proxy_set_queue((struct wl_proxy
*)pool
, dri2_surf
->wl_queue
);
1607 *buffer
= wl_shm_pool_create_buffer(pool
, 0, w
, h
, stride
, format
);
1608 wl_shm_pool_destroy(pool
);
1617 swrast_update_buffers(struct dri2_egl_surface
*dri2_surf
)
1619 struct dri2_egl_display
*dri2_dpy
=
1620 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1622 /* we need to do the following operations only once per frame */
1623 if (dri2_surf
->back
)
1626 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->width
||
1627 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->height
) {
1629 dri2_wl_release_buffers(dri2_surf
);
1631 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
1632 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
1633 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
1634 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
1635 dri2_surf
->current
= NULL
;
1638 /* find back buffer */
1640 /* There might be a buffer release already queued that wasn't processed */
1641 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
1643 /* try get free buffer already created */
1644 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1645 if (!dri2_surf
->color_buffers
[i
].locked
&&
1646 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1647 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1652 /* else choose any another free location */
1653 if (!dri2_surf
->back
) {
1654 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1655 if (!dri2_surf
->color_buffers
[i
].locked
) {
1656 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1657 if (!dri2_wl_swrast_allocate_buffer(dri2_surf
,
1659 dri2_surf
->base
.Width
,
1660 dri2_surf
->base
.Height
,
1661 &dri2_surf
->back
->data
,
1662 &dri2_surf
->back
->data_size
,
1663 &dri2_surf
->back
->wl_buffer
)) {
1664 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
1667 wl_buffer_add_listener(dri2_surf
->back
->wl_buffer
,
1668 &wl_buffer_listener
, dri2_surf
);
1674 if (!dri2_surf
->back
) {
1675 _eglError(EGL_BAD_ALLOC
, "failed to find free buffer");
1679 dri2_surf
->back
->locked
= true;
1681 /* If we have an extra unlocked buffer at this point, we had to do triple
1682 * buffering for a while, but now can go back to just double buffering.
1683 * That means we can free any unlocked buffer now. */
1684 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1685 if (!dri2_surf
->color_buffers
[i
].locked
&&
1686 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1687 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
1688 munmap(dri2_surf
->color_buffers
[i
].data
,
1689 dri2_surf
->color_buffers
[i
].data_size
);
1690 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
1691 dri2_surf
->color_buffers
[i
].data
= NULL
;
1699 dri2_wl_swrast_get_frontbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1701 /* if there has been a resize: */
1702 if (!dri2_surf
->current
)
1705 return dri2_surf
->current
->data
;
1709 dri2_wl_swrast_get_backbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1711 assert(dri2_surf
->back
);
1712 return dri2_surf
->back
->data
;
1716 dri2_wl_swrast_commit_backbuffer(struct dri2_egl_surface
*dri2_surf
)
1718 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1720 while (dri2_surf
->throttle_callback
!= NULL
)
1721 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
1722 dri2_surf
->wl_queue
) == -1)
1725 if (dri2_surf
->base
.SwapInterval
> 0) {
1726 dri2_surf
->throttle_callback
=
1727 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
1728 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1729 &throttle_listener
, dri2_surf
);
1732 dri2_surf
->current
= dri2_surf
->back
;
1733 dri2_surf
->back
= NULL
;
1735 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
1736 dri2_surf
->current
->wl_buffer
,
1737 dri2_surf
->dx
, dri2_surf
->dy
);
1739 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
1740 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
1741 /* reset resize growing parameters */
1745 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
1746 0, 0, INT32_MAX
, INT32_MAX
);
1747 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
1749 /* If we're not waiting for a frame callback then we'll at least throttle
1750 * to a sync callback so that we always give a chance for the compositor to
1751 * handle the commit and send a release event before checking for a free
1753 if (dri2_surf
->throttle_callback
== NULL
) {
1754 dri2_surf
->throttle_callback
= wl_display_sync(dri2_dpy
->wl_dpy_wrapper
);
1755 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1756 &throttle_listener
, dri2_surf
);
1759 wl_display_flush(dri2_dpy
->wl_dpy
);
1763 dri2_wl_swrast_get_drawable_info(__DRIdrawable
* draw
,
1764 int *x
, int *y
, int *w
, int *h
,
1765 void *loaderPrivate
)
1767 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1769 (void) swrast_update_buffers(dri2_surf
);
1772 *w
= dri2_surf
->base
.Width
;
1773 *h
= dri2_surf
->base
.Height
;
1777 dri2_wl_swrast_get_image(__DRIdrawable
* read
,
1778 int x
, int y
, int w
, int h
,
1779 char *data
, void *loaderPrivate
)
1781 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1782 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1783 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1784 int src_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1785 int dst_stride
= copy_width
;
1788 src
= dri2_wl_swrast_get_frontbuffer_data(dri2_surf
);
1790 memset(data
, 0, copy_width
* h
);
1794 assert(data
!= src
);
1795 assert(copy_width
<= src_stride
);
1798 src
+= y
* src_stride
;
1801 if (copy_width
> src_stride
-x_offset
)
1802 copy_width
= src_stride
-x_offset
;
1803 if (h
> dri2_surf
->base
.Height
-y
)
1804 h
= dri2_surf
->base
.Height
-y
;
1807 memcpy(dst
, src
, copy_width
);
1814 dri2_wl_swrast_put_image2(__DRIdrawable
* draw
, int op
,
1815 int x
, int y
, int w
, int h
, int stride
,
1816 char *data
, void *loaderPrivate
)
1818 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1819 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1820 int dst_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1821 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1824 assert(copy_width
<= stride
);
1826 (void) swrast_update_buffers(dri2_surf
);
1827 dst
= dri2_wl_swrast_get_backbuffer_data(dri2_surf
);
1829 /* partial copy, copy old content */
1830 if (copy_width
< dst_stride
)
1831 dri2_wl_swrast_get_image(draw
, 0, 0,
1832 dri2_surf
->base
.Width
, dri2_surf
->base
.Height
,
1833 dst
, loaderPrivate
);
1836 dst
+= y
* dst_stride
;
1840 /* drivers expect we do these checks (and some rely on it) */
1841 if (copy_width
> dst_stride
-x_offset
)
1842 copy_width
= dst_stride
-x_offset
;
1843 if (h
> dri2_surf
->base
.Height
-y
)
1844 h
= dri2_surf
->base
.Height
-y
;
1847 memcpy(dst
, src
, copy_width
);
1851 dri2_wl_swrast_commit_backbuffer(dri2_surf
);
1855 dri2_wl_swrast_put_image(__DRIdrawable
* draw
, int op
,
1856 int x
, int y
, int w
, int h
,
1857 char *data
, void *loaderPrivate
)
1859 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1862 stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1863 dri2_wl_swrast_put_image2(draw
, op
, x
, y
, w
, h
,
1864 stride
, data
, loaderPrivate
);
1868 dri2_wl_swrast_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1870 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1871 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
1873 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
1878 shm_handle_format(void *data
, struct wl_shm
*shm
, uint32_t format
)
1880 struct dri2_egl_display
*dri2_dpy
= data
;
1883 case WL_SHM_FORMAT_ARGB8888
:
1884 dri2_dpy
->formats
|= HAS_ARGB8888
;
1886 case WL_SHM_FORMAT_XRGB8888
:
1887 dri2_dpy
->formats
|= HAS_XRGB8888
;
1889 case WL_SHM_FORMAT_RGB565
:
1890 dri2_dpy
->formats
|= HAS_RGB565
;
1895 static const struct wl_shm_listener shm_listener
= {
1896 .format
= shm_handle_format
1900 registry_handle_global_swrast(void *data
, struct wl_registry
*registry
,
1901 uint32_t name
, const char *interface
,
1904 struct dri2_egl_display
*dri2_dpy
= data
;
1906 if (strcmp(interface
, "wl_shm") == 0) {
1908 wl_registry_bind(registry
, name
, &wl_shm_interface
, 1);
1909 wl_shm_add_listener(dri2_dpy
->wl_shm
, &shm_listener
, dri2_dpy
);
1913 static const struct wl_registry_listener registry_listener_swrast
= {
1914 .global
= registry_handle_global_swrast
,
1915 .global_remove
= registry_handle_global_remove
1918 static const struct dri2_egl_display_vtbl dri2_wl_swrast_display_vtbl
= {
1919 .authenticate
= NULL
,
1920 .create_window_surface
= dri2_wl_create_window_surface
,
1921 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1922 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1923 .destroy_surface
= dri2_wl_destroy_surface
,
1924 .create_image
= dri2_create_image_khr
,
1925 .swap_buffers
= dri2_wl_swrast_swap_buffers
,
1926 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
1927 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1928 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1929 .copy_buffers
= dri2_fallback_copy_buffers
,
1930 .query_buffer_age
= dri2_fallback_query_buffer_age
,
1931 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
1932 .get_sync_values
= dri2_fallback_get_sync_values
,
1933 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1936 static const __DRIswrastLoaderExtension swrast_loader_extension
= {
1937 .base
= { __DRI_SWRAST_LOADER
, 2 },
1939 .getDrawableInfo
= dri2_wl_swrast_get_drawable_info
,
1940 .putImage
= dri2_wl_swrast_put_image
,
1941 .getImage
= dri2_wl_swrast_get_image
,
1942 .putImage2
= dri2_wl_swrast_put_image2
,
1945 static const __DRIextension
*swrast_loader_extensions
[] = {
1946 &swrast_loader_extension
.base
,
1947 &image_lookup_extension
.base
,
1952 dri2_initialize_wayland_swrast(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1954 struct dri2_egl_display
*dri2_dpy
;
1956 loader_set_logger(_eglLog
);
1958 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1960 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1963 disp
->DriverData
= (void *) dri2_dpy
;
1964 if (disp
->PlatformDisplay
== NULL
) {
1965 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1966 if (dri2_dpy
->wl_dpy
== NULL
)
1968 dri2_dpy
->own_device
= true;
1970 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
1973 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
1975 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
1976 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
1979 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
1980 dri2_dpy
->wl_queue
);
1982 if (dri2_dpy
->own_device
)
1983 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
1985 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
1986 wl_registry_add_listener(dri2_dpy
->wl_registry
,
1987 ®istry_listener_swrast
, dri2_dpy
);
1989 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_shm
== NULL
)
1992 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->formats
== 0)
1995 dri2_dpy
->driver_name
= strdup("swrast");
1996 if (!dri2_load_driver_swrast(disp
))
1999 dri2_dpy
->loader_extensions
= swrast_loader_extensions
;
2001 if (!dri2_create_screen(disp
))
2004 if (!dri2_setup_extensions(disp
))
2007 dri2_setup_screen(disp
);
2009 dri2_wl_setup_swap_interval(disp
);
2011 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
2012 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
2016 /* Fill vtbl last to prevent accidentally calling virtual function during
2019 dri2_dpy
->vtbl
= &dri2_wl_swrast_display_vtbl
;
2024 dri2_display_destroy(disp
);
2029 dri2_initialize_wayland(_EGLDriver
*drv
, _EGLDisplay
*disp
)
2031 EGLBoolean initialized
= EGL_FALSE
;
2033 if (!disp
->Options
.ForceSoftware
)
2034 initialized
= dri2_initialize_wayland_drm(drv
, disp
);
2037 initialized
= dri2_initialize_wayland_swrast(drv
, disp
);
2044 dri2_teardown_wayland(struct dri2_egl_display
*dri2_dpy
)
2046 if (dri2_dpy
->wl_drm
)
2047 wl_drm_destroy(dri2_dpy
->wl_drm
);
2048 if (dri2_dpy
->wl_dmabuf
)
2049 zwp_linux_dmabuf_v1_destroy(dri2_dpy
->wl_dmabuf
);
2050 if (dri2_dpy
->wl_shm
)
2051 wl_shm_destroy(dri2_dpy
->wl_shm
);
2052 if (dri2_dpy
->wl_registry
)
2053 wl_registry_destroy(dri2_dpy
->wl_registry
);
2054 if (dri2_dpy
->wl_queue
)
2055 wl_event_queue_destroy(dri2_dpy
->wl_queue
);
2056 if (dri2_dpy
->wl_dpy_wrapper
)
2057 wl_proxy_wrapper_destroy(dri2_dpy
->wl_dpy_wrapper
);
2058 u_vector_finish(&dri2_dpy
->wl_modifiers
.argb8888
);
2059 u_vector_finish(&dri2_dpy
->wl_modifiers
.xrgb8888
);
2060 u_vector_finish(&dri2_dpy
->wl_modifiers
.rgb565
);
2061 if (dri2_dpy
->own_device
)
2062 wl_display_disconnect(dri2_dpy
->wl_dpy
);