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
;
357 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.argb2101010
);
358 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.argb2101010
);
360 case WL_DRM_FORMAT_XRGB2101010
:
361 dri_image_format
= __DRI_IMAGE_FORMAT_XRGB2101010
;
362 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.xrgb2101010
);
363 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.xrgb2101010
);
365 case WL_DRM_FORMAT_ARGB8888
:
366 dri_image_format
= __DRI_IMAGE_FORMAT_ARGB8888
;
367 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.argb8888
);
368 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.argb8888
);
370 case WL_DRM_FORMAT_XRGB8888
:
371 dri_image_format
= __DRI_IMAGE_FORMAT_XRGB8888
;
372 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.xrgb8888
);
373 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.xrgb8888
);
375 case WL_DRM_FORMAT_RGB565
:
376 dri_image_format
= __DRI_IMAGE_FORMAT_RGB565
;
377 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.rgb565
);
378 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.rgb565
);
381 /* format is not supported */
385 /* There might be a buffer release already queued that wasn't processed */
386 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
388 while (dri2_surf
->back
== NULL
) {
389 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
390 /* Get an unlocked buffer, preferrably one with a dri_buffer
391 * already allocated. */
392 if (dri2_surf
->color_buffers
[i
].locked
)
394 if (dri2_surf
->back
== NULL
)
395 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
396 else if (dri2_surf
->back
->dri_image
== NULL
)
397 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
403 /* If we don't have a buffer, then block on the server to release one for
404 * us, and try again. wl_display_dispatch_queue will process any pending
405 * events, however not all servers flush on issuing a buffer release
406 * event. So, we spam the server with roundtrips as they always cause a
409 if (wl_display_roundtrip_queue(dri2_dpy
->wl_dpy
,
410 dri2_surf
->wl_queue
) < 0)
414 if (dri2_surf
->back
== NULL
)
417 use_flags
= __DRI_IMAGE_USE_SHARE
| __DRI_IMAGE_USE_BACKBUFFER
;
419 if (dri2_dpy
->is_different_gpu
&&
420 dri2_surf
->back
->linear_copy
== NULL
) {
421 /* The LINEAR modifier should be a perfect alias of the LINEAR use
422 * flag; try the new interface first before the old, then fall back. */
423 if (dri2_dpy
->image
->base
.version
>= 15 &&
424 dri2_dpy
->image
->createImageWithModifiers
) {
425 uint64_t linear_mod
= DRM_FORMAT_MOD_LINEAR
;
427 dri2_surf
->back
->linear_copy
=
428 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
429 dri2_surf
->base
.Width
,
430 dri2_surf
->base
.Height
,
436 dri2_surf
->back
->linear_copy
=
437 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
438 dri2_surf
->base
.Width
,
439 dri2_surf
->base
.Height
,
442 __DRI_IMAGE_USE_LINEAR
,
445 if (dri2_surf
->back
->linear_copy
== NULL
)
449 if (dri2_surf
->back
->dri_image
== NULL
) {
450 /* If our DRIImage implementation does not support
451 * createImageWithModifiers, then fall back to the old createImage,
452 * and hope it allocates an image which is acceptable to the winsys.
454 if (num_modifiers
&& dri2_dpy
->image
->base
.version
>= 15 &&
455 dri2_dpy
->image
->createImageWithModifiers
) {
456 dri2_surf
->back
->dri_image
=
457 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
458 dri2_surf
->base
.Width
,
459 dri2_surf
->base
.Height
,
465 dri2_surf
->back
->dri_image
=
466 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
467 dri2_surf
->base
.Width
,
468 dri2_surf
->base
.Height
,
470 dri2_dpy
->is_different_gpu
?
475 dri2_surf
->back
->age
= 0;
477 if (dri2_surf
->back
->dri_image
== NULL
)
480 dri2_surf
->back
->locked
= true;
487 back_bo_to_dri_buffer(struct dri2_egl_surface
*dri2_surf
, __DRIbuffer
*buffer
)
489 struct dri2_egl_display
*dri2_dpy
=
490 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
494 image
= dri2_surf
->back
->dri_image
;
496 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
497 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &pitch
);
499 buffer
->attachment
= __DRI_BUFFER_BACK_LEFT
;
501 buffer
->pitch
= pitch
;
507 update_buffers(struct dri2_egl_surface
*dri2_surf
)
509 struct dri2_egl_display
*dri2_dpy
=
510 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
512 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->width
||
513 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->height
) {
515 dri2_wl_release_buffers(dri2_surf
);
517 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
518 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
519 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
520 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
523 if (get_back_bo(dri2_surf
) < 0) {
524 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
528 /* If we have an extra unlocked buffer at this point, we had to do triple
529 * buffering for a while, but now can go back to just double buffering.
530 * That means we can free any unlocked buffer now. */
531 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
532 if (!dri2_surf
->color_buffers
[i
].locked
&&
533 dri2_surf
->color_buffers
[i
].wl_buffer
) {
534 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
535 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
536 if (dri2_dpy
->is_different_gpu
)
537 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
538 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
539 dri2_surf
->color_buffers
[i
].dri_image
= NULL
;
540 dri2_surf
->color_buffers
[i
].linear_copy
= NULL
;
548 dri2_wl_get_buffers_with_format(__DRIdrawable
* driDrawable
,
549 int *width
, int *height
,
550 unsigned int *attachments
, int count
,
551 int *out_count
, void *loaderPrivate
)
553 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
556 if (update_buffers(dri2_surf
) < 0)
559 for (i
= 0, j
= 0; i
< 2 * count
; i
+= 2, j
++) {
562 switch (attachments
[i
]) {
563 case __DRI_BUFFER_BACK_LEFT
:
564 back_bo_to_dri_buffer(dri2_surf
, &dri2_surf
->buffers
[j
]);
567 local
= dri2_egl_surface_alloc_local_buffer(dri2_surf
, attachments
[i
],
571 _eglError(EGL_BAD_ALLOC
, "failed to allocate local buffer");
574 dri2_surf
->buffers
[j
] = *local
;
583 *width
= dri2_surf
->base
.Width
;
584 *height
= dri2_surf
->base
.Height
;
586 return dri2_surf
->buffers
;
590 dri2_wl_get_buffers(__DRIdrawable
* driDrawable
,
591 int *width
, int *height
,
592 unsigned int *attachments
, int count
,
593 int *out_count
, void *loaderPrivate
)
595 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
596 unsigned int *attachments_with_format
;
600 switch (dri2_surf
->format
) {
601 case WL_DRM_FORMAT_ARGB2101010
:
602 case WL_DRM_FORMAT_XRGB2101010
:
603 case WL_DRM_FORMAT_ARGB8888
:
604 case WL_DRM_FORMAT_XRGB8888
:
607 case WL_DRM_FORMAT_RGB565
:
611 /* format is not supported */
615 attachments_with_format
= calloc(count
, 2 * sizeof(unsigned int));
616 if (!attachments_with_format
) {
621 for (int i
= 0; i
< count
; ++i
) {
622 attachments_with_format
[2*i
] = attachments
[i
];
623 attachments_with_format
[2*i
+ 1] = bpp
;
627 dri2_wl_get_buffers_with_format(driDrawable
,
629 attachments_with_format
, count
,
630 out_count
, loaderPrivate
);
632 free(attachments_with_format
);
638 image_get_buffers(__DRIdrawable
*driDrawable
,
642 uint32_t buffer_mask
,
643 struct __DRIimageList
*buffers
)
645 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
647 if (update_buffers(dri2_surf
) < 0)
650 buffers
->image_mask
= __DRI_IMAGE_BUFFER_BACK
;
651 buffers
->back
= dri2_surf
->back
->dri_image
;
657 dri2_wl_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
660 (void) loaderPrivate
;
663 static const __DRIdri2LoaderExtension dri2_loader_extension
= {
664 .base
= { __DRI_DRI2_LOADER
, 3 },
666 .getBuffers
= dri2_wl_get_buffers
,
667 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
668 .getBuffersWithFormat
= dri2_wl_get_buffers_with_format
,
671 static const __DRIimageLoaderExtension image_loader_extension
= {
672 .base
= { __DRI_IMAGE_LOADER
, 1 },
674 .getBuffers
= image_get_buffers
,
675 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
679 wayland_throttle_callback(void *data
,
680 struct wl_callback
*callback
,
683 struct dri2_egl_surface
*dri2_surf
= data
;
685 dri2_surf
->throttle_callback
= NULL
;
686 wl_callback_destroy(callback
);
689 static const struct wl_callback_listener throttle_listener
= {
690 .done
= wayland_throttle_callback
694 get_fourcc(struct dri2_egl_display
*dri2_dpy
,
695 __DRIimage
*image
, int *fourcc
)
700 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FOURCC
,
705 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
,
710 switch (dri_format
) {
711 case __DRI_IMAGE_FORMAT_ARGB8888
:
712 *fourcc
= __DRI_IMAGE_FOURCC_ARGB8888
;
714 case __DRI_IMAGE_FORMAT_XRGB8888
:
715 *fourcc
= __DRI_IMAGE_FOURCC_XRGB8888
;
722 static struct wl_buffer
*
723 create_wl_buffer(struct dri2_egl_display
*dri2_dpy
,
724 struct dri2_egl_surface
*dri2_surf
,
727 struct wl_buffer
*ret
;
729 int width
, height
, fourcc
, num_planes
;
730 uint64_t modifier
= DRM_FORMAT_MOD_INVALID
;
732 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_WIDTH
, &width
);
733 query
&= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_HEIGHT
,
735 query
&= get_fourcc(dri2_dpy
, image
, &fourcc
);
739 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NUM_PLANES
,
744 if (dri2_dpy
->image
->base
.version
>= 15) {
747 query
= dri2_dpy
->image
->queryImage(image
,
748 __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
,
750 query
&= dri2_dpy
->image
->queryImage(image
,
751 __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
,
754 modifier
= (uint64_t) mod_hi
<< 32;
755 modifier
|= (uint64_t) (mod_lo
& 0xffffffff);
759 if (dri2_dpy
->wl_dmabuf
&& modifier
!= DRM_FORMAT_MOD_INVALID
) {
760 struct zwp_linux_buffer_params_v1
*params
;
763 /* We don't need a wrapper for wl_dmabuf objects, because we have to
764 * create the intermediate params object; we can set the queue on this,
765 * and the wl_buffer inherits it race-free. */
766 params
= zwp_linux_dmabuf_v1_create_params(dri2_dpy
->wl_dmabuf
);
768 wl_proxy_set_queue((struct wl_proxy
*) params
, dri2_surf
->wl_queue
);
770 for (i
= 0; i
< num_planes
; i
++) {
778 p_image
= dri2_dpy
->image
->fromPlanar(image
, i
, NULL
);
780 zwp_linux_buffer_params_v1_destroy(params
);
784 query
= dri2_dpy
->image
->queryImage(p_image
,
785 __DRI_IMAGE_ATTRIB_FD
,
787 query
&= dri2_dpy
->image
->queryImage(p_image
,
788 __DRI_IMAGE_ATTRIB_STRIDE
,
790 query
&= dri2_dpy
->image
->queryImage(p_image
,
791 __DRI_IMAGE_ATTRIB_OFFSET
,
793 if (image
!= p_image
)
794 dri2_dpy
->image
->destroyImage(p_image
);
799 zwp_linux_buffer_params_v1_destroy(params
);
803 zwp_linux_buffer_params_v1_add(params
, fd
, i
, offset
, stride
,
804 modifier
>> 32, modifier
& 0xffffffff);
808 ret
= zwp_linux_buffer_params_v1_create_immed(params
, width
, height
,
810 zwp_linux_buffer_params_v1_destroy(params
);
811 } else if (dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
) {
812 struct wl_drm
*wl_drm
=
813 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
819 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FD
, &fd
);
820 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
821 ret
= wl_drm_create_prime_buffer(wl_drm
, fd
, width
, height
, fourcc
, 0,
825 struct wl_drm
*wl_drm
=
826 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
832 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
833 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
834 ret
= wl_drm_create_buffer(wl_drm
, name
, width
, height
, stride
, fourcc
);
841 try_damage_buffer(struct dri2_egl_surface
*dri2_surf
,
845 if (wl_proxy_get_version((struct wl_proxy
*) dri2_surf
->wl_surface_wrapper
)
846 < WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION
)
849 for (int i
= 0; i
< n_rects
; i
++) {
850 const int *rect
= &rects
[i
* 4];
852 wl_surface_damage_buffer(dri2_surf
->wl_surface_wrapper
,
854 dri2_surf
->base
.Height
- rect
[1] - rect
[3],
860 * Called via eglSwapBuffers(), drv->API.SwapBuffers().
863 dri2_wl_swap_buffers_with_damage(_EGLDriver
*drv
,
869 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
870 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
872 while (dri2_surf
->throttle_callback
!= NULL
)
873 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
874 dri2_surf
->wl_queue
) == -1)
877 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
878 if (dri2_surf
->color_buffers
[i
].age
> 0)
879 dri2_surf
->color_buffers
[i
].age
++;
881 /* Make sure we have a back buffer in case we're swapping without ever
883 if (get_back_bo(dri2_surf
) < 0)
884 return _eglError(EGL_BAD_ALLOC
, "dri2_swap_buffers");
886 if (draw
->SwapInterval
> 0) {
887 dri2_surf
->throttle_callback
=
888 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
889 wl_callback_add_listener(dri2_surf
->throttle_callback
,
890 &throttle_listener
, dri2_surf
);
893 dri2_surf
->back
->age
= 1;
894 dri2_surf
->current
= dri2_surf
->back
;
895 dri2_surf
->back
= NULL
;
897 if (!dri2_surf
->current
->wl_buffer
) {
900 if (dri2_dpy
->is_different_gpu
)
901 image
= dri2_surf
->current
->linear_copy
;
903 image
= dri2_surf
->current
->dri_image
;
905 dri2_surf
->current
->wl_buffer
=
906 create_wl_buffer(dri2_dpy
, dri2_surf
, image
);
908 wl_buffer_add_listener(dri2_surf
->current
->wl_buffer
,
909 &wl_buffer_listener
, dri2_surf
);
912 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
913 dri2_surf
->current
->wl_buffer
,
914 dri2_surf
->dx
, dri2_surf
->dy
);
916 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
917 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
918 /* reset resize growing parameters */
922 /* If the compositor doesn't support damage_buffer, we deliberately
923 * ignore the damage region and post maximum damage, due to
924 * https://bugs.freedesktop.org/78190 */
925 if (!n_rects
|| !try_damage_buffer(dri2_surf
, rects
, n_rects
))
926 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
927 0, 0, INT32_MAX
, INT32_MAX
);
929 if (dri2_dpy
->is_different_gpu
) {
930 _EGLContext
*ctx
= _eglGetCurrentContext();
931 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
932 dri2_dpy
->image
->blitImage(dri2_ctx
->dri_context
,
933 dri2_surf
->current
->linear_copy
,
934 dri2_surf
->current
->dri_image
,
935 0, 0, dri2_surf
->base
.Width
,
936 dri2_surf
->base
.Height
,
937 0, 0, dri2_surf
->base
.Width
,
938 dri2_surf
->base
.Height
, 0);
941 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
942 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
944 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
946 /* If we're not waiting for a frame callback then we'll at least throttle
947 * to a sync callback so that we always give a chance for the compositor to
948 * handle the commit and send a release event before checking for a free
950 if (dri2_surf
->throttle_callback
== NULL
) {
951 dri2_surf
->throttle_callback
= wl_display_sync(dri2_surf
->wl_dpy_wrapper
);
952 wl_callback_add_listener(dri2_surf
->throttle_callback
,
953 &throttle_listener
, dri2_surf
);
956 wl_display_flush(dri2_dpy
->wl_dpy
);
962 dri2_wl_query_buffer_age(_EGLDriver
*drv
,
963 _EGLDisplay
*disp
, _EGLSurface
*surface
)
965 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
967 if (get_back_bo(dri2_surf
) < 0) {
968 _eglError(EGL_BAD_ALLOC
, "dri2_query_buffer_age");
972 return dri2_surf
->back
->age
;
976 dri2_wl_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
978 return dri2_wl_swap_buffers_with_damage(drv
, disp
, draw
, NULL
, 0);
981 static struct wl_buffer
*
982 dri2_wl_create_wayland_buffer_from_image(_EGLDriver
*drv
,
986 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
987 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
988 __DRIimage
*image
= dri2_img
->dri_image
;
989 struct wl_buffer
*buffer
;
992 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
, &format
);
994 case __DRI_IMAGE_FORMAT_ARGB2101010
:
995 if (!(dri2_dpy
->formats
& HAS_ARGB2101010
))
998 case __DRI_IMAGE_FORMAT_XRGB2101010
:
999 if (!(dri2_dpy
->formats
& HAS_XRGB2101010
))
1002 case __DRI_IMAGE_FORMAT_ARGB8888
:
1003 if (!(dri2_dpy
->formats
& HAS_ARGB8888
))
1006 case __DRI_IMAGE_FORMAT_XRGB8888
:
1007 if (!(dri2_dpy
->formats
& HAS_XRGB8888
))
1014 buffer
= create_wl_buffer(dri2_dpy
, NULL
, image
);
1016 /* The buffer object will have been created with our internal event queue
1017 * because it is using wl_dmabuf/wl_drm as a proxy factory. We want the
1018 * buffer to be used by the application so we'll reset it to the display's
1019 * default event queue. This isn't actually racy, as the only event the
1020 * buffer can get is a buffer release, which doesn't happen with an explicit
1023 wl_proxy_set_queue((struct wl_proxy
*) buffer
, NULL
);
1028 _eglError(EGL_BAD_MATCH
, "unsupported image format");
1033 dri2_wl_authenticate(_EGLDisplay
*disp
, uint32_t id
)
1035 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1038 if (dri2_dpy
->is_render_node
) {
1039 _eglLog(_EGL_WARNING
, "wayland-egl: client asks server to "
1040 "authenticate for render-nodes");
1043 dri2_dpy
->authenticated
= false;
1045 wl_drm_authenticate(dri2_dpy
->wl_drm
, id
);
1046 if (roundtrip(dri2_dpy
) < 0)
1049 if (!dri2_dpy
->authenticated
)
1052 /* reset authenticated */
1053 dri2_dpy
->authenticated
= true;
1059 drm_handle_device(void *data
, struct wl_drm
*drm
, const char *device
)
1061 struct dri2_egl_display
*dri2_dpy
= data
;
1064 dri2_dpy
->device_name
= strdup(device
);
1065 if (!dri2_dpy
->device_name
)
1068 dri2_dpy
->fd
= loader_open_device(dri2_dpy
->device_name
);
1069 if (dri2_dpy
->fd
== -1) {
1070 _eglLog(_EGL_WARNING
, "wayland-egl: could not open %s (%s)",
1071 dri2_dpy
->device_name
, strerror(errno
));
1075 if (drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
) {
1076 dri2_dpy
->authenticated
= true;
1078 drmGetMagic(dri2_dpy
->fd
, &magic
);
1079 wl_drm_authenticate(dri2_dpy
->wl_drm
, magic
);
1084 drm_handle_format(void *data
, struct wl_drm
*drm
, uint32_t format
)
1086 struct dri2_egl_display
*dri2_dpy
= data
;
1089 case WL_DRM_FORMAT_ARGB2101010
:
1090 dri2_dpy
->formats
|= HAS_ARGB2101010
;
1092 case WL_DRM_FORMAT_XRGB2101010
:
1093 dri2_dpy
->formats
|= HAS_XRGB2101010
;
1095 case WL_DRM_FORMAT_ARGB8888
:
1096 dri2_dpy
->formats
|= HAS_ARGB8888
;
1098 case WL_DRM_FORMAT_XRGB8888
:
1099 dri2_dpy
->formats
|= HAS_XRGB8888
;
1101 case WL_DRM_FORMAT_RGB565
:
1102 dri2_dpy
->formats
|= HAS_RGB565
;
1108 drm_handle_capabilities(void *data
, struct wl_drm
*drm
, uint32_t value
)
1110 struct dri2_egl_display
*dri2_dpy
= data
;
1112 dri2_dpy
->capabilities
= value
;
1116 drm_handle_authenticated(void *data
, struct wl_drm
*drm
)
1118 struct dri2_egl_display
*dri2_dpy
= data
;
1120 dri2_dpy
->authenticated
= true;
1123 static const struct wl_drm_listener drm_listener
= {
1124 .device
= drm_handle_device
,
1125 .format
= drm_handle_format
,
1126 .authenticated
= drm_handle_authenticated
,
1127 .capabilities
= drm_handle_capabilities
1131 dmabuf_ignore_format(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1134 /* formats are implicitly advertised by the 'modifier' event, so ignore */
1138 dmabuf_handle_modifier(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1139 uint32_t format
, uint32_t modifier_hi
,
1140 uint32_t modifier_lo
)
1142 struct dri2_egl_display
*dri2_dpy
= data
;
1143 uint64_t *mod
= NULL
;
1145 if (modifier_hi
== (DRM_FORMAT_MOD_INVALID
>> 32) &&
1146 modifier_lo
== (DRM_FORMAT_MOD_INVALID
& 0xffffffff))
1150 case WL_DRM_FORMAT_ARGB2101010
:
1151 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.argb2101010
);
1152 dri2_dpy
->formats
|= HAS_ARGB2101010
;
1154 case WL_DRM_FORMAT_XRGB2101010
:
1155 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.xrgb2101010
);
1156 dri2_dpy
->formats
|= HAS_XRGB2101010
;
1158 case WL_DRM_FORMAT_ARGB8888
:
1159 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.argb8888
);
1160 dri2_dpy
->formats
|= HAS_ARGB8888
;
1162 case WL_DRM_FORMAT_XRGB8888
:
1163 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.xrgb8888
);
1164 dri2_dpy
->formats
|= HAS_XRGB8888
;
1166 case WL_DRM_FORMAT_RGB565
:
1167 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.rgb565
);
1168 dri2_dpy
->formats
|= HAS_RGB565
;
1177 *mod
= (uint64_t) modifier_hi
<< 32;
1178 *mod
|= (uint64_t) (modifier_lo
& 0xffffffff);
1181 static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener
= {
1182 .format
= dmabuf_ignore_format
,
1183 .modifier
= dmabuf_handle_modifier
,
1187 registry_handle_global_drm(void *data
, struct wl_registry
*registry
,
1188 uint32_t name
, const char *interface
,
1191 struct dri2_egl_display
*dri2_dpy
= data
;
1193 if (strcmp(interface
, "wl_drm") == 0) {
1195 wl_registry_bind(registry
, name
, &wl_drm_interface
, MIN2(version
, 2));
1196 wl_drm_add_listener(dri2_dpy
->wl_drm
, &drm_listener
, dri2_dpy
);
1197 } else if (strcmp(interface
, "zwp_linux_dmabuf_v1") == 0 && version
>= 3) {
1198 dri2_dpy
->wl_dmabuf
=
1199 wl_registry_bind(registry
, name
, &zwp_linux_dmabuf_v1_interface
,
1201 zwp_linux_dmabuf_v1_add_listener(dri2_dpy
->wl_dmabuf
, &dmabuf_listener
,
1207 registry_handle_global_remove(void *data
, struct wl_registry
*registry
,
1212 static const struct wl_registry_listener registry_listener_drm
= {
1213 .global
= registry_handle_global_drm
,
1214 .global_remove
= registry_handle_global_remove
1218 dri2_wl_setup_swap_interval(_EGLDisplay
*disp
)
1220 /* We can't use values greater than 1 on Wayland because we are using the
1221 * frame callback to synchronise the frame and the only way we be sure to
1222 * get a frame callback is to attach a new buffer. Therefore we can't just
1223 * sit drawing nothing to wait until the next ‘n’ frame callbacks */
1225 dri2_setup_swap_interval(disp
, 1);
1228 static const struct dri2_egl_display_vtbl dri2_wl_display_vtbl
= {
1229 .authenticate
= dri2_wl_authenticate
,
1230 .create_window_surface
= dri2_wl_create_window_surface
,
1231 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1232 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1233 .destroy_surface
= dri2_wl_destroy_surface
,
1234 .create_image
= dri2_create_image_khr
,
1235 .swap_buffers
= dri2_wl_swap_buffers
,
1236 .swap_buffers_with_damage
= dri2_wl_swap_buffers_with_damage
,
1237 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1238 .set_damage_region
= dri2_fallback_set_damage_region
,
1239 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1240 .copy_buffers
= dri2_fallback_copy_buffers
,
1241 .query_buffer_age
= dri2_wl_query_buffer_age
,
1242 .create_wayland_buffer_from_image
= dri2_wl_create_wayland_buffer_from_image
,
1243 .get_sync_values
= dri2_fallback_get_sync_values
,
1244 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1247 static const __DRIextension
*dri2_loader_extensions
[] = {
1248 &dri2_loader_extension
.base
,
1249 &image_loader_extension
.base
,
1250 &image_lookup_extension
.base
,
1251 &use_invalidate
.base
,
1255 static const __DRIextension
*image_loader_extensions
[] = {
1256 &image_loader_extension
.base
,
1257 &image_lookup_extension
.base
,
1258 &use_invalidate
.base
,
1263 dri2_wl_add_configs_for_visuals(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1265 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1266 static const struct {
1267 const char *format_name
;
1269 unsigned int rgba_masks
[4];
1271 { "XRGB2101010", HAS_XRGB2101010
, { 0x3ff00000, 0xffc00, 0x3ff, 0 } },
1272 { "ARGB2101010", HAS_ARGB2101010
, { 0x3ff00000, 0xffc00, 0x3ff, 0xc0000000 } },
1273 { "XRGB8888", HAS_XRGB8888
, { 0xff0000, 0xff00, 0x00ff, 0xff000000 } },
1274 { "ARGB8888", HAS_ARGB8888
, { 0xff0000, 0xff00, 0x00ff, 0 } },
1275 { "RGB565", HAS_RGB565
, { 0x00f800, 0x07e0, 0x001f, 0 } },
1277 unsigned int format_count
[ARRAY_SIZE(visuals
)] = { 0 };
1278 unsigned int count
= 0;
1280 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
1281 for (unsigned j
= 0; j
< ARRAY_SIZE(visuals
); j
++) {
1282 struct dri2_egl_config
*dri2_conf
;
1284 if (!(dri2_dpy
->formats
& visuals
[j
].has_format
))
1287 dri2_conf
= dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
1288 count
+ 1, EGL_WINDOW_BIT
, NULL
, visuals
[j
].rgba_masks
);
1290 if (dri2_conf
->base
.ConfigID
== count
+ 1)
1297 for (unsigned i
= 0; i
< ARRAY_SIZE(format_count
); i
++) {
1298 if (!format_count
[i
]) {
1299 _eglLog(_EGL_DEBUG
, "No DRI config supports native format %s",
1300 visuals
[i
].format_name
);
1304 return (count
!= 0);
1308 dri2_initialize_wayland_drm(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1310 struct dri2_egl_display
*dri2_dpy
;
1312 loader_set_logger(_eglLog
);
1314 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1316 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1319 disp
->DriverData
= (void *) dri2_dpy
;
1320 if (disp
->PlatformDisplay
== NULL
) {
1321 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1322 if (dri2_dpy
->wl_dpy
== NULL
)
1324 dri2_dpy
->own_device
= true;
1326 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
1329 if (!u_vector_init(&dri2_dpy
->wl_modifiers
.xrgb2101010
, sizeof(uint64_t), 32) ||
1330 !u_vector_init(&dri2_dpy
->wl_modifiers
.argb2101010
, sizeof(uint64_t), 32) ||
1331 !u_vector_init(&dri2_dpy
->wl_modifiers
.xrgb8888
, sizeof(uint64_t), 32) ||
1332 !u_vector_init(&dri2_dpy
->wl_modifiers
.argb8888
, sizeof(uint64_t), 32) ||
1333 !u_vector_init(&dri2_dpy
->wl_modifiers
.rgb565
, sizeof(uint64_t), 32)) {
1337 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
1339 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
1340 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
1343 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
1344 dri2_dpy
->wl_queue
);
1346 if (dri2_dpy
->own_device
)
1347 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
1349 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
1350 wl_registry_add_listener(dri2_dpy
->wl_registry
,
1351 ®istry_listener_drm
, dri2_dpy
);
1352 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_drm
== NULL
)
1355 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->fd
== -1)
1358 if (roundtrip(dri2_dpy
) < 0 || !dri2_dpy
->authenticated
)
1361 dri2_dpy
->fd
= loader_get_user_preferred_fd(dri2_dpy
->fd
,
1362 &dri2_dpy
->is_different_gpu
);
1363 if (dri2_dpy
->is_different_gpu
) {
1364 free(dri2_dpy
->device_name
);
1365 dri2_dpy
->device_name
= loader_get_device_name_for_fd(dri2_dpy
->fd
);
1366 if (!dri2_dpy
->device_name
) {
1367 _eglError(EGL_BAD_ALLOC
, "wayland-egl: failed to get device name "
1368 "for requested GPU");
1373 /* we have to do the check now, because loader_get_user_preferred_fd
1374 * will return a render-node when the requested gpu is different
1375 * to the server, but also if the client asks for the same gpu than
1376 * the server by requesting its pci-id */
1377 dri2_dpy
->is_render_node
= drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
;
1379 dri2_dpy
->driver_name
= loader_get_driver_for_fd(dri2_dpy
->fd
);
1380 if (dri2_dpy
->driver_name
== NULL
) {
1381 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to get driver name");
1385 /* render nodes cannot use Gem names, and thus do not support
1386 * the __DRI_DRI2_LOADER extension */
1387 if (!dri2_dpy
->is_render_node
) {
1388 dri2_dpy
->loader_extensions
= dri2_loader_extensions
;
1389 if (!dri2_load_driver(disp
)) {
1390 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to load driver");
1394 dri2_dpy
->loader_extensions
= image_loader_extensions
;
1395 if (!dri2_load_driver_dri3(disp
)) {
1396 _eglError(EGL_BAD_ALLOC
, "DRI3: failed to load driver");
1401 if (!dri2_create_screen(disp
))
1404 if (!dri2_setup_extensions(disp
))
1407 dri2_setup_screen(disp
);
1409 dri2_wl_setup_swap_interval(disp
);
1411 /* To use Prime, we must have _DRI_IMAGE v7 at least.
1412 * createImageFromFds support indicates that Prime export/import
1413 * is supported by the driver. Fall back to
1414 * gem names if we don't have Prime support. */
1416 if (dri2_dpy
->image
->base
.version
< 7 ||
1417 dri2_dpy
->image
->createImageFromFds
== NULL
)
1418 dri2_dpy
->capabilities
&= ~WL_DRM_CAPABILITY_PRIME
;
1420 /* We cannot use Gem names with render-nodes, only prime fds (dma-buf).
1421 * The server needs to accept them */
1422 if (dri2_dpy
->is_render_node
&&
1423 !(dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
)) {
1424 _eglLog(_EGL_WARNING
, "wayland-egl: display is not render-node capable");
1428 if (dri2_dpy
->is_different_gpu
&&
1429 (dri2_dpy
->image
->base
.version
< 9 ||
1430 dri2_dpy
->image
->blitImage
== NULL
)) {
1431 _eglLog(_EGL_WARNING
, "wayland-egl: Different GPU selected, but the "
1432 "Image extension in the driver is not "
1433 "compatible. Version 9 or later and blitImage() "
1438 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
1439 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
1443 dri2_set_WL_bind_wayland_display(drv
, disp
);
1444 /* When cannot convert EGLImage to wl_buffer when on a different gpu,
1445 * because the buffer of the EGLImage has likely a tiling mode the server
1446 * gpu won't support. These is no way to check for now. Thus do not support the
1448 if (!dri2_dpy
->is_different_gpu
)
1449 disp
->Extensions
.WL_create_wayland_buffer_from_image
= EGL_TRUE
;
1451 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
1453 disp
->Extensions
.EXT_swap_buffers_with_damage
= EGL_TRUE
;
1455 /* Fill vtbl last to prevent accidentally calling virtual function during
1458 dri2_dpy
->vtbl
= &dri2_wl_display_vtbl
;
1463 dri2_display_destroy(disp
);
1468 dri2_wl_swrast_get_stride_for_format(int format
, int w
)
1470 if (format
== WL_SHM_FORMAT_RGB565
)
1472 else /* ARGB8888 || XRGB8888 */
1477 * Taken from weston shared/os-compatibility.c
1480 #ifndef HAVE_MKOSTEMP
1483 set_cloexec_or_close(int fd
)
1490 flags
= fcntl(fd
, F_GETFD
);
1494 if (fcntl(fd
, F_SETFD
, flags
| FD_CLOEXEC
) == -1)
1507 * Taken from weston shared/os-compatibility.c
1511 create_tmpfile_cloexec(char *tmpname
)
1515 #ifdef HAVE_MKOSTEMP
1516 fd
= mkostemp(tmpname
, O_CLOEXEC
);
1520 fd
= mkstemp(tmpname
);
1522 fd
= set_cloexec_or_close(fd
);
1531 * Taken from weston shared/os-compatibility.c
1533 * Create a new, unique, anonymous file of the given size, and
1534 * return the file descriptor for it. The file descriptor is set
1535 * CLOEXEC. The file is immediately suitable for mmap()'ing
1536 * the given size at offset zero.
1538 * The file should not have a permanent backing store like a disk,
1539 * but may have if XDG_RUNTIME_DIR is not properly implemented in OS.
1541 * The file name is deleted from the file system.
1543 * The file is suitable for buffer sharing between processes by
1544 * transmitting the file descriptor over Unix sockets using the
1545 * SCM_RIGHTS methods.
1547 * If the C library implements posix_fallocate(), it is used to
1548 * guarantee that disk space is available for the file at the
1549 * given size. If disk space is insufficent, errno is set to ENOSPC.
1550 * If posix_fallocate() is not supported, program may receive
1551 * SIGBUS on accessing mmap()'ed file contents instead.
1554 os_create_anonymous_file(off_t size
)
1556 static const char templ
[] = "/mesa-shared-XXXXXX";
1562 path
= getenv("XDG_RUNTIME_DIR");
1568 name
= malloc(strlen(path
) + sizeof(templ
));
1573 strcat(name
, templ
);
1575 fd
= create_tmpfile_cloexec(name
);
1582 ret
= ftruncate(fd
, size
);
1593 dri2_wl_swrast_allocate_buffer(struct dri2_egl_surface
*dri2_surf
,
1594 int format
, int w
, int h
,
1595 void **data
, int *size
,
1596 struct wl_buffer
**buffer
)
1598 struct dri2_egl_display
*dri2_dpy
=
1599 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1600 struct wl_shm_pool
*pool
;
1601 int fd
, stride
, size_map
;
1604 stride
= dri2_wl_swrast_get_stride_for_format(format
, w
);
1605 size_map
= h
* stride
;
1607 /* Create a sharable buffer */
1608 fd
= os_create_anonymous_file(size_map
);
1612 data_map
= mmap(NULL
, size_map
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
1613 if (data_map
== MAP_FAILED
) {
1618 /* Share it in a wl_buffer */
1619 pool
= wl_shm_create_pool(dri2_dpy
->wl_shm
, fd
, size_map
);
1620 wl_proxy_set_queue((struct wl_proxy
*)pool
, dri2_surf
->wl_queue
);
1621 *buffer
= wl_shm_pool_create_buffer(pool
, 0, w
, h
, stride
, format
);
1622 wl_shm_pool_destroy(pool
);
1631 swrast_update_buffers(struct dri2_egl_surface
*dri2_surf
)
1633 struct dri2_egl_display
*dri2_dpy
=
1634 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1636 /* we need to do the following operations only once per frame */
1637 if (dri2_surf
->back
)
1640 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->width
||
1641 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->height
) {
1643 dri2_wl_release_buffers(dri2_surf
);
1645 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
1646 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
1647 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
1648 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
1649 dri2_surf
->current
= NULL
;
1652 /* find back buffer */
1654 /* There might be a buffer release already queued that wasn't processed */
1655 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
1657 /* try get free buffer already created */
1658 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1659 if (!dri2_surf
->color_buffers
[i
].locked
&&
1660 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1661 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1666 /* else choose any another free location */
1667 if (!dri2_surf
->back
) {
1668 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1669 if (!dri2_surf
->color_buffers
[i
].locked
) {
1670 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1671 if (!dri2_wl_swrast_allocate_buffer(dri2_surf
,
1673 dri2_surf
->base
.Width
,
1674 dri2_surf
->base
.Height
,
1675 &dri2_surf
->back
->data
,
1676 &dri2_surf
->back
->data_size
,
1677 &dri2_surf
->back
->wl_buffer
)) {
1678 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
1681 wl_buffer_add_listener(dri2_surf
->back
->wl_buffer
,
1682 &wl_buffer_listener
, dri2_surf
);
1688 if (!dri2_surf
->back
) {
1689 _eglError(EGL_BAD_ALLOC
, "failed to find free buffer");
1693 dri2_surf
->back
->locked
= true;
1695 /* If we have an extra unlocked buffer at this point, we had to do triple
1696 * buffering for a while, but now can go back to just double buffering.
1697 * That means we can free any unlocked buffer now. */
1698 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1699 if (!dri2_surf
->color_buffers
[i
].locked
&&
1700 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1701 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
1702 munmap(dri2_surf
->color_buffers
[i
].data
,
1703 dri2_surf
->color_buffers
[i
].data_size
);
1704 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
1705 dri2_surf
->color_buffers
[i
].data
= NULL
;
1713 dri2_wl_swrast_get_frontbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1715 /* if there has been a resize: */
1716 if (!dri2_surf
->current
)
1719 return dri2_surf
->current
->data
;
1723 dri2_wl_swrast_get_backbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1725 assert(dri2_surf
->back
);
1726 return dri2_surf
->back
->data
;
1730 dri2_wl_swrast_commit_backbuffer(struct dri2_egl_surface
*dri2_surf
)
1732 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1734 while (dri2_surf
->throttle_callback
!= NULL
)
1735 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
1736 dri2_surf
->wl_queue
) == -1)
1739 if (dri2_surf
->base
.SwapInterval
> 0) {
1740 dri2_surf
->throttle_callback
=
1741 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
1742 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1743 &throttle_listener
, dri2_surf
);
1746 dri2_surf
->current
= dri2_surf
->back
;
1747 dri2_surf
->back
= NULL
;
1749 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
1750 dri2_surf
->current
->wl_buffer
,
1751 dri2_surf
->dx
, dri2_surf
->dy
);
1753 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
1754 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
1755 /* reset resize growing parameters */
1759 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
1760 0, 0, INT32_MAX
, INT32_MAX
);
1761 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
1763 /* If we're not waiting for a frame callback then we'll at least throttle
1764 * to a sync callback so that we always give a chance for the compositor to
1765 * handle the commit and send a release event before checking for a free
1767 if (dri2_surf
->throttle_callback
== NULL
) {
1768 dri2_surf
->throttle_callback
= wl_display_sync(dri2_dpy
->wl_dpy_wrapper
);
1769 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1770 &throttle_listener
, dri2_surf
);
1773 wl_display_flush(dri2_dpy
->wl_dpy
);
1777 dri2_wl_swrast_get_drawable_info(__DRIdrawable
* draw
,
1778 int *x
, int *y
, int *w
, int *h
,
1779 void *loaderPrivate
)
1781 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1783 (void) swrast_update_buffers(dri2_surf
);
1786 *w
= dri2_surf
->base
.Width
;
1787 *h
= dri2_surf
->base
.Height
;
1791 dri2_wl_swrast_get_image(__DRIdrawable
* read
,
1792 int x
, int y
, int w
, int h
,
1793 char *data
, void *loaderPrivate
)
1795 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1796 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1797 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1798 int src_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1799 int dst_stride
= copy_width
;
1802 src
= dri2_wl_swrast_get_frontbuffer_data(dri2_surf
);
1804 memset(data
, 0, copy_width
* h
);
1808 assert(data
!= src
);
1809 assert(copy_width
<= src_stride
);
1812 src
+= y
* src_stride
;
1815 if (copy_width
> src_stride
-x_offset
)
1816 copy_width
= src_stride
-x_offset
;
1817 if (h
> dri2_surf
->base
.Height
-y
)
1818 h
= dri2_surf
->base
.Height
-y
;
1821 memcpy(dst
, src
, copy_width
);
1828 dri2_wl_swrast_put_image2(__DRIdrawable
* draw
, int op
,
1829 int x
, int y
, int w
, int h
, int stride
,
1830 char *data
, void *loaderPrivate
)
1832 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1833 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1834 int dst_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1835 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1838 assert(copy_width
<= stride
);
1840 (void) swrast_update_buffers(dri2_surf
);
1841 dst
= dri2_wl_swrast_get_backbuffer_data(dri2_surf
);
1843 /* partial copy, copy old content */
1844 if (copy_width
< dst_stride
)
1845 dri2_wl_swrast_get_image(draw
, 0, 0,
1846 dri2_surf
->base
.Width
, dri2_surf
->base
.Height
,
1847 dst
, loaderPrivate
);
1850 dst
+= y
* dst_stride
;
1854 /* drivers expect we do these checks (and some rely on it) */
1855 if (copy_width
> dst_stride
-x_offset
)
1856 copy_width
= dst_stride
-x_offset
;
1857 if (h
> dri2_surf
->base
.Height
-y
)
1858 h
= dri2_surf
->base
.Height
-y
;
1861 memcpy(dst
, src
, copy_width
);
1865 dri2_wl_swrast_commit_backbuffer(dri2_surf
);
1869 dri2_wl_swrast_put_image(__DRIdrawable
* draw
, int op
,
1870 int x
, int y
, int w
, int h
,
1871 char *data
, void *loaderPrivate
)
1873 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1876 stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1877 dri2_wl_swrast_put_image2(draw
, op
, x
, y
, w
, h
,
1878 stride
, data
, loaderPrivate
);
1882 dri2_wl_swrast_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1884 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1885 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
1887 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
1892 shm_handle_format(void *data
, struct wl_shm
*shm
, uint32_t format
)
1894 struct dri2_egl_display
*dri2_dpy
= data
;
1897 case WL_SHM_FORMAT_ARGB8888
:
1898 dri2_dpy
->formats
|= HAS_ARGB8888
;
1900 case WL_SHM_FORMAT_XRGB8888
:
1901 dri2_dpy
->formats
|= HAS_XRGB8888
;
1903 case WL_SHM_FORMAT_RGB565
:
1904 dri2_dpy
->formats
|= HAS_RGB565
;
1909 static const struct wl_shm_listener shm_listener
= {
1910 .format
= shm_handle_format
1914 registry_handle_global_swrast(void *data
, struct wl_registry
*registry
,
1915 uint32_t name
, const char *interface
,
1918 struct dri2_egl_display
*dri2_dpy
= data
;
1920 if (strcmp(interface
, "wl_shm") == 0) {
1922 wl_registry_bind(registry
, name
, &wl_shm_interface
, 1);
1923 wl_shm_add_listener(dri2_dpy
->wl_shm
, &shm_listener
, dri2_dpy
);
1927 static const struct wl_registry_listener registry_listener_swrast
= {
1928 .global
= registry_handle_global_swrast
,
1929 .global_remove
= registry_handle_global_remove
1932 static const struct dri2_egl_display_vtbl dri2_wl_swrast_display_vtbl
= {
1933 .authenticate
= NULL
,
1934 .create_window_surface
= dri2_wl_create_window_surface
,
1935 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1936 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1937 .destroy_surface
= dri2_wl_destroy_surface
,
1938 .create_image
= dri2_create_image_khr
,
1939 .swap_buffers
= dri2_wl_swrast_swap_buffers
,
1940 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
1941 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1942 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1943 .copy_buffers
= dri2_fallback_copy_buffers
,
1944 .query_buffer_age
= dri2_fallback_query_buffer_age
,
1945 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
1946 .get_sync_values
= dri2_fallback_get_sync_values
,
1947 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1950 static const __DRIswrastLoaderExtension swrast_loader_extension
= {
1951 .base
= { __DRI_SWRAST_LOADER
, 2 },
1953 .getDrawableInfo
= dri2_wl_swrast_get_drawable_info
,
1954 .putImage
= dri2_wl_swrast_put_image
,
1955 .getImage
= dri2_wl_swrast_get_image
,
1956 .putImage2
= dri2_wl_swrast_put_image2
,
1959 static const __DRIextension
*swrast_loader_extensions
[] = {
1960 &swrast_loader_extension
.base
,
1961 &image_lookup_extension
.base
,
1966 dri2_initialize_wayland_swrast(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1968 struct dri2_egl_display
*dri2_dpy
;
1970 loader_set_logger(_eglLog
);
1972 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1974 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1977 disp
->DriverData
= (void *) dri2_dpy
;
1978 if (disp
->PlatformDisplay
== NULL
) {
1979 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1980 if (dri2_dpy
->wl_dpy
== NULL
)
1982 dri2_dpy
->own_device
= true;
1984 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
1987 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
1989 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
1990 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
1993 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
1994 dri2_dpy
->wl_queue
);
1996 if (dri2_dpy
->own_device
)
1997 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
1999 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
2000 wl_registry_add_listener(dri2_dpy
->wl_registry
,
2001 ®istry_listener_swrast
, dri2_dpy
);
2003 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_shm
== NULL
)
2006 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->formats
== 0)
2009 dri2_dpy
->driver_name
= strdup("swrast");
2010 if (!dri2_load_driver_swrast(disp
))
2013 dri2_dpy
->loader_extensions
= swrast_loader_extensions
;
2015 if (!dri2_create_screen(disp
))
2018 if (!dri2_setup_extensions(disp
))
2021 dri2_setup_screen(disp
);
2023 dri2_wl_setup_swap_interval(disp
);
2025 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
2026 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
2030 /* Fill vtbl last to prevent accidentally calling virtual function during
2033 dri2_dpy
->vtbl
= &dri2_wl_swrast_display_vtbl
;
2038 dri2_display_destroy(disp
);
2043 dri2_initialize_wayland(_EGLDriver
*drv
, _EGLDisplay
*disp
)
2045 EGLBoolean initialized
= EGL_FALSE
;
2047 if (!disp
->Options
.ForceSoftware
)
2048 initialized
= dri2_initialize_wayland_drm(drv
, disp
);
2051 initialized
= dri2_initialize_wayland_swrast(drv
, disp
);
2058 dri2_teardown_wayland(struct dri2_egl_display
*dri2_dpy
)
2060 if (dri2_dpy
->wl_drm
)
2061 wl_drm_destroy(dri2_dpy
->wl_drm
);
2062 if (dri2_dpy
->wl_dmabuf
)
2063 zwp_linux_dmabuf_v1_destroy(dri2_dpy
->wl_dmabuf
);
2064 if (dri2_dpy
->wl_shm
)
2065 wl_shm_destroy(dri2_dpy
->wl_shm
);
2066 if (dri2_dpy
->wl_registry
)
2067 wl_registry_destroy(dri2_dpy
->wl_registry
);
2068 if (dri2_dpy
->wl_queue
)
2069 wl_event_queue_destroy(dri2_dpy
->wl_queue
);
2070 if (dri2_dpy
->wl_dpy_wrapper
)
2071 wl_proxy_wrapper_destroy(dri2_dpy
->wl_dpy_wrapper
);
2072 u_vector_finish(&dri2_dpy
->wl_modifiers
.argb2101010
);
2073 u_vector_finish(&dri2_dpy
->wl_modifiers
.xrgb2101010
);
2074 u_vector_finish(&dri2_dpy
->wl_modifiers
.argb8888
);
2075 u_vector_finish(&dri2_dpy
->wl_modifiers
.xrgb8888
);
2076 u_vector_finish(&dri2_dpy
->wl_modifiers
.rgb565
);
2077 if (dri2_dpy
->own_device
)
2078 wl_display_disconnect(dri2_dpy
->wl_dpy
);