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 const char *format_name
;
70 enum wl_drm_format_flags has_format
;
71 unsigned int rgba_masks
[4];
72 } dri2_wl_visuals
[] = {
74 "XRGB2101010", HAS_XRGB2101010
,
75 { 0x3ff00000, 0x000ffc00, 0x000003ff, 0x00000000 }
78 "ARGB2101010", HAS_ARGB2101010
,
79 { 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 }
82 "XRGB8888", HAS_XRGB8888
,
83 { 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 }
86 "ARGB8888", HAS_ARGB8888
,
87 { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }
91 { 0xf800, 0x07e0, 0x001f, 0x0000 }
96 roundtrip(struct dri2_egl_display
*dri2_dpy
)
98 return wl_display_roundtrip_queue(dri2_dpy
->wl_dpy
, dri2_dpy
->wl_queue
);
102 wl_buffer_release(void *data
, struct wl_buffer
*buffer
)
104 struct dri2_egl_surface
*dri2_surf
= data
;
107 for (i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); ++i
)
108 if (dri2_surf
->color_buffers
[i
].wl_buffer
== buffer
)
111 if (i
== ARRAY_SIZE(dri2_surf
->color_buffers
)) {
112 wl_buffer_destroy(buffer
);
116 dri2_surf
->color_buffers
[i
].locked
= false;
119 static const struct wl_buffer_listener wl_buffer_listener
= {
120 .release
= wl_buffer_release
124 resize_callback(struct wl_egl_window
*wl_win
, void *data
)
126 struct dri2_egl_surface
*dri2_surf
= data
;
127 struct dri2_egl_display
*dri2_dpy
=
128 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
130 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
134 destroy_window_callback(void *data
)
136 struct dri2_egl_surface
*dri2_surf
= data
;
137 dri2_surf
->wl_win
= NULL
;
140 static struct wl_surface
*
141 get_wl_surface_proxy(struct wl_egl_window
*window
)
143 /* Version 3 of wl_egl_window introduced a version field at the same
144 * location where a pointer to wl_surface was stored. Thus, if
145 * window->version is dereferencable, we've been given an older version of
146 * wl_egl_window, and window->version points to wl_surface */
147 if (_eglPointerIsDereferencable((void *)(window
->version
))) {
148 return wl_proxy_create_wrapper((void *)(window
->version
));
150 return wl_proxy_create_wrapper(window
->surface
);
154 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
157 dri2_wl_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
158 _EGLConfig
*conf
, void *native_window
,
159 const EGLint
*attrib_list
)
161 __DRIcreateNewDrawableFunc createNewDrawable
;
162 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
163 struct dri2_egl_config
*dri2_conf
= dri2_egl_config(conf
);
164 struct wl_egl_window
*window
= native_window
;
165 struct dri2_egl_surface
*dri2_surf
;
166 const __DRIconfig
*config
;
168 dri2_surf
= calloc(1, sizeof *dri2_surf
);
170 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
174 if (!dri2_init_surface(&dri2_surf
->base
, disp
, EGL_WINDOW_BIT
, conf
, attrib_list
, false))
177 if (dri2_dpy
->wl_dmabuf
|| dri2_dpy
->wl_drm
) {
178 if (conf
->RedSize
== 5)
179 dri2_surf
->format
= WL_DRM_FORMAT_RGB565
;
180 else if (conf
->RedSize
== 8 && conf
->AlphaSize
== 0)
181 dri2_surf
->format
= WL_DRM_FORMAT_XRGB8888
;
182 else if (conf
->RedSize
== 8)
183 dri2_surf
->format
= WL_DRM_FORMAT_ARGB8888
;
184 else if (conf
->RedSize
== 10 && conf
->AlphaSize
== 0)
185 dri2_surf
->format
= WL_DRM_FORMAT_XRGB2101010
;
186 else if (conf
->RedSize
== 10)
187 dri2_surf
->format
= WL_DRM_FORMAT_ARGB2101010
;
189 assert(dri2_dpy
->wl_shm
);
190 if (conf
->RedSize
== 5)
191 dri2_surf
->format
= WL_SHM_FORMAT_RGB565
;
192 else if (conf
->RedSize
== 8 && conf
->AlphaSize
== 0)
193 dri2_surf
->format
= WL_SHM_FORMAT_XRGB8888
;
194 else if (conf
->RedSize
== 8)
195 dri2_surf
->format
= WL_SHM_FORMAT_ARGB8888
;
196 else if (conf
->RedSize
== 10 && conf
->AlphaSize
== 0)
197 dri2_surf
->format
= WL_SHM_FORMAT_XRGB2101010
;
198 else if (conf
->RedSize
== 10)
199 dri2_surf
->format
= WL_SHM_FORMAT_ARGB2101010
;
202 dri2_surf
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
203 if (!dri2_surf
->wl_queue
) {
204 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
208 if (dri2_dpy
->wl_drm
) {
209 dri2_surf
->wl_drm_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_drm
);
210 if (!dri2_surf
->wl_drm_wrapper
) {
211 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
214 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_drm_wrapper
,
215 dri2_surf
->wl_queue
);
218 dri2_surf
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
219 if (!dri2_surf
->wl_dpy_wrapper
) {
220 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
223 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_dpy_wrapper
,
224 dri2_surf
->wl_queue
);
226 dri2_surf
->wl_surface_wrapper
= get_wl_surface_proxy(window
);
227 if (!dri2_surf
->wl_surface_wrapper
) {
228 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
229 goto cleanup_dpy_wrapper
;
231 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_surface_wrapper
,
232 dri2_surf
->wl_queue
);
234 dri2_surf
->wl_win
= window
;
235 dri2_surf
->wl_win
->private = dri2_surf
;
236 dri2_surf
->wl_win
->destroy_window_callback
= destroy_window_callback
;
238 dri2_surf
->wl_win
->resize_callback
= resize_callback
;
240 config
= dri2_get_dri_config(dri2_conf
, EGL_WINDOW_BIT
,
241 dri2_surf
->base
.GLColorspace
);
243 if (dri2_dpy
->image_driver
)
244 createNewDrawable
= dri2_dpy
->image_driver
->createNewDrawable
;
245 else if (dri2_dpy
->dri2
)
246 createNewDrawable
= dri2_dpy
->dri2
->createNewDrawable
;
248 createNewDrawable
= dri2_dpy
->swrast
->createNewDrawable
;
250 dri2_surf
->dri_drawable
= (*createNewDrawable
)(dri2_dpy
->dri_screen
, config
,
252 if (dri2_surf
->dri_drawable
== NULL
) {
253 _eglError(EGL_BAD_ALLOC
, "createNewDrawable");
254 goto cleanup_surf_wrapper
;
257 dri2_surf
->base
.SwapInterval
= dri2_dpy
->default_swap_interval
;
259 return &dri2_surf
->base
;
261 cleanup_surf_wrapper
:
262 wl_proxy_wrapper_destroy(dri2_surf
->wl_surface_wrapper
);
264 wl_proxy_wrapper_destroy(dri2_surf
->wl_dpy_wrapper
);
266 if (dri2_surf
->wl_drm_wrapper
)
267 wl_proxy_wrapper_destroy(dri2_surf
->wl_drm_wrapper
);
269 wl_event_queue_destroy(dri2_surf
->wl_queue
);
277 dri2_wl_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
278 _EGLConfig
*conf
, void *native_window
,
279 const EGLint
*attrib_list
)
281 /* From the EGL_EXT_platform_wayland spec, version 3:
283 * It is not valid to call eglCreatePlatformPixmapSurfaceEXT with a <dpy>
284 * that belongs to Wayland. Any such call fails and generates
287 _eglError(EGL_BAD_PARAMETER
, "cannot create EGL pixmap surfaces on "
293 * Called via eglDestroySurface(), drv->API.DestroySurface().
296 dri2_wl_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
298 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
299 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
303 dri2_dpy
->core
->destroyDrawable(dri2_surf
->dri_drawable
);
305 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
306 if (dri2_surf
->color_buffers
[i
].wl_buffer
)
307 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
308 if (dri2_surf
->color_buffers
[i
].dri_image
)
309 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
310 if (dri2_surf
->color_buffers
[i
].linear_copy
)
311 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
312 if (dri2_surf
->color_buffers
[i
].data
)
313 munmap(dri2_surf
->color_buffers
[i
].data
,
314 dri2_surf
->color_buffers
[i
].data_size
);
318 dri2_egl_surface_free_local_buffers(dri2_surf
);
320 if (dri2_surf
->throttle_callback
)
321 wl_callback_destroy(dri2_surf
->throttle_callback
);
323 if (dri2_surf
->wl_win
) {
324 dri2_surf
->wl_win
->private = NULL
;
325 dri2_surf
->wl_win
->resize_callback
= NULL
;
326 dri2_surf
->wl_win
->destroy_window_callback
= NULL
;
329 wl_proxy_wrapper_destroy(dri2_surf
->wl_surface_wrapper
);
330 wl_proxy_wrapper_destroy(dri2_surf
->wl_dpy_wrapper
);
331 if (dri2_surf
->wl_drm_wrapper
)
332 wl_proxy_wrapper_destroy(dri2_surf
->wl_drm_wrapper
);
333 wl_event_queue_destroy(dri2_surf
->wl_queue
);
335 dri2_fini_surface(surf
);
342 dri2_wl_release_buffers(struct dri2_egl_surface
*dri2_surf
)
344 struct dri2_egl_display
*dri2_dpy
=
345 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
347 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
348 if (dri2_surf
->color_buffers
[i
].wl_buffer
&&
349 !dri2_surf
->color_buffers
[i
].locked
)
350 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
351 if (dri2_surf
->color_buffers
[i
].dri_image
)
352 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
353 if (dri2_surf
->color_buffers
[i
].linear_copy
)
354 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
355 if (dri2_surf
->color_buffers
[i
].data
)
356 munmap(dri2_surf
->color_buffers
[i
].data
,
357 dri2_surf
->color_buffers
[i
].data_size
);
359 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
360 dri2_surf
->color_buffers
[i
].dri_image
= NULL
;
361 dri2_surf
->color_buffers
[i
].linear_copy
= NULL
;
362 dri2_surf
->color_buffers
[i
].data
= NULL
;
363 dri2_surf
->color_buffers
[i
].locked
= false;
367 dri2_egl_surface_free_local_buffers(dri2_surf
);
371 get_back_bo(struct dri2_egl_surface
*dri2_surf
)
373 struct dri2_egl_display
*dri2_dpy
=
374 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
376 unsigned int dri_image_format
;
380 /* currently supports five WL DRM formats,
381 * WL_DRM_FORMAT_ARGB2101010, WL_DRM_FORMAT_XRGB2101010,
382 * WL_DRM_FORMAT_ARGB8888, WL_DRM_FORMAT_XRGB8888,
383 * and WL_DRM_FORMAT_RGB565
385 switch (dri2_surf
->format
) {
386 case WL_DRM_FORMAT_ARGB2101010
:
387 dri_image_format
= __DRI_IMAGE_FORMAT_ARGB2101010
;
388 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.argb2101010
);
389 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.argb2101010
);
391 case WL_DRM_FORMAT_XRGB2101010
:
392 dri_image_format
= __DRI_IMAGE_FORMAT_XRGB2101010
;
393 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.xrgb2101010
);
394 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.xrgb2101010
);
396 case WL_DRM_FORMAT_ARGB8888
:
397 dri_image_format
= __DRI_IMAGE_FORMAT_ARGB8888
;
398 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.argb8888
);
399 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.argb8888
);
401 case WL_DRM_FORMAT_XRGB8888
:
402 dri_image_format
= __DRI_IMAGE_FORMAT_XRGB8888
;
403 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.xrgb8888
);
404 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.xrgb8888
);
406 case WL_DRM_FORMAT_RGB565
:
407 dri_image_format
= __DRI_IMAGE_FORMAT_RGB565
;
408 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.rgb565
);
409 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.rgb565
);
412 /* format is not supported */
416 /* There might be a buffer release already queued that wasn't processed */
417 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
419 while (dri2_surf
->back
== NULL
) {
420 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
421 /* Get an unlocked buffer, preferrably one with a dri_buffer
422 * already allocated. */
423 if (dri2_surf
->color_buffers
[i
].locked
)
425 if (dri2_surf
->back
== NULL
)
426 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
427 else if (dri2_surf
->back
->dri_image
== NULL
)
428 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
434 /* If we don't have a buffer, then block on the server to release one for
435 * us, and try again. wl_display_dispatch_queue will process any pending
436 * events, however not all servers flush on issuing a buffer release
437 * event. So, we spam the server with roundtrips as they always cause a
440 if (wl_display_roundtrip_queue(dri2_dpy
->wl_dpy
,
441 dri2_surf
->wl_queue
) < 0)
445 if (dri2_surf
->back
== NULL
)
448 use_flags
= __DRI_IMAGE_USE_SHARE
| __DRI_IMAGE_USE_BACKBUFFER
;
450 if (dri2_dpy
->is_different_gpu
&&
451 dri2_surf
->back
->linear_copy
== NULL
) {
452 /* The LINEAR modifier should be a perfect alias of the LINEAR use
453 * flag; try the new interface first before the old, then fall back. */
454 if (dri2_dpy
->image
->base
.version
>= 15 &&
455 dri2_dpy
->image
->createImageWithModifiers
) {
456 uint64_t linear_mod
= DRM_FORMAT_MOD_LINEAR
;
458 dri2_surf
->back
->linear_copy
=
459 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
460 dri2_surf
->base
.Width
,
461 dri2_surf
->base
.Height
,
467 dri2_surf
->back
->linear_copy
=
468 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
469 dri2_surf
->base
.Width
,
470 dri2_surf
->base
.Height
,
473 __DRI_IMAGE_USE_LINEAR
,
476 if (dri2_surf
->back
->linear_copy
== NULL
)
480 if (dri2_surf
->back
->dri_image
== NULL
) {
481 /* If our DRIImage implementation does not support
482 * createImageWithModifiers, then fall back to the old createImage,
483 * and hope it allocates an image which is acceptable to the winsys.
485 if (num_modifiers
&& dri2_dpy
->image
->base
.version
>= 15 &&
486 dri2_dpy
->image
->createImageWithModifiers
) {
487 dri2_surf
->back
->dri_image
=
488 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
489 dri2_surf
->base
.Width
,
490 dri2_surf
->base
.Height
,
496 dri2_surf
->back
->dri_image
=
497 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
498 dri2_surf
->base
.Width
,
499 dri2_surf
->base
.Height
,
501 dri2_dpy
->is_different_gpu
?
506 dri2_surf
->back
->age
= 0;
508 if (dri2_surf
->back
->dri_image
== NULL
)
511 dri2_surf
->back
->locked
= true;
518 back_bo_to_dri_buffer(struct dri2_egl_surface
*dri2_surf
, __DRIbuffer
*buffer
)
520 struct dri2_egl_display
*dri2_dpy
=
521 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
525 image
= dri2_surf
->back
->dri_image
;
527 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
528 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &pitch
);
530 buffer
->attachment
= __DRI_BUFFER_BACK_LEFT
;
532 buffer
->pitch
= pitch
;
538 update_buffers(struct dri2_egl_surface
*dri2_surf
)
540 struct dri2_egl_display
*dri2_dpy
=
541 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
543 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->width
||
544 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->height
) {
546 dri2_wl_release_buffers(dri2_surf
);
548 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
549 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
550 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
551 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
554 if (get_back_bo(dri2_surf
) < 0) {
555 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
559 /* If we have an extra unlocked buffer at this point, we had to do triple
560 * buffering for a while, but now can go back to just double buffering.
561 * That means we can free any unlocked buffer now. */
562 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
563 if (!dri2_surf
->color_buffers
[i
].locked
&&
564 dri2_surf
->color_buffers
[i
].wl_buffer
) {
565 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
566 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
567 if (dri2_dpy
->is_different_gpu
)
568 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
569 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
570 dri2_surf
->color_buffers
[i
].dri_image
= NULL
;
571 dri2_surf
->color_buffers
[i
].linear_copy
= NULL
;
579 dri2_wl_get_buffers_with_format(__DRIdrawable
* driDrawable
,
580 int *width
, int *height
,
581 unsigned int *attachments
, int count
,
582 int *out_count
, void *loaderPrivate
)
584 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
587 if (update_buffers(dri2_surf
) < 0)
590 for (i
= 0, j
= 0; i
< 2 * count
; i
+= 2, j
++) {
593 switch (attachments
[i
]) {
594 case __DRI_BUFFER_BACK_LEFT
:
595 back_bo_to_dri_buffer(dri2_surf
, &dri2_surf
->buffers
[j
]);
598 local
= dri2_egl_surface_alloc_local_buffer(dri2_surf
, attachments
[i
],
602 _eglError(EGL_BAD_ALLOC
, "failed to allocate local buffer");
605 dri2_surf
->buffers
[j
] = *local
;
614 *width
= dri2_surf
->base
.Width
;
615 *height
= dri2_surf
->base
.Height
;
617 return dri2_surf
->buffers
;
621 dri2_wl_get_buffers(__DRIdrawable
* driDrawable
,
622 int *width
, int *height
,
623 unsigned int *attachments
, int count
,
624 int *out_count
, void *loaderPrivate
)
626 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
627 unsigned int *attachments_with_format
;
631 switch (dri2_surf
->format
) {
632 case WL_DRM_FORMAT_ARGB2101010
:
633 case WL_DRM_FORMAT_XRGB2101010
:
634 case WL_DRM_FORMAT_ARGB8888
:
635 case WL_DRM_FORMAT_XRGB8888
:
638 case WL_DRM_FORMAT_RGB565
:
642 /* format is not supported */
646 attachments_with_format
= calloc(count
, 2 * sizeof(unsigned int));
647 if (!attachments_with_format
) {
652 for (int i
= 0; i
< count
; ++i
) {
653 attachments_with_format
[2*i
] = attachments
[i
];
654 attachments_with_format
[2*i
+ 1] = bpp
;
658 dri2_wl_get_buffers_with_format(driDrawable
,
660 attachments_with_format
, count
,
661 out_count
, loaderPrivate
);
663 free(attachments_with_format
);
669 image_get_buffers(__DRIdrawable
*driDrawable
,
673 uint32_t buffer_mask
,
674 struct __DRIimageList
*buffers
)
676 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
678 if (update_buffers(dri2_surf
) < 0)
681 buffers
->image_mask
= __DRI_IMAGE_BUFFER_BACK
;
682 buffers
->back
= dri2_surf
->back
->dri_image
;
688 dri2_wl_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
691 (void) loaderPrivate
;
694 static const __DRIdri2LoaderExtension dri2_loader_extension
= {
695 .base
= { __DRI_DRI2_LOADER
, 3 },
697 .getBuffers
= dri2_wl_get_buffers
,
698 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
699 .getBuffersWithFormat
= dri2_wl_get_buffers_with_format
,
702 static const __DRIimageLoaderExtension image_loader_extension
= {
703 .base
= { __DRI_IMAGE_LOADER
, 1 },
705 .getBuffers
= image_get_buffers
,
706 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
710 wayland_throttle_callback(void *data
,
711 struct wl_callback
*callback
,
714 struct dri2_egl_surface
*dri2_surf
= data
;
716 dri2_surf
->throttle_callback
= NULL
;
717 wl_callback_destroy(callback
);
720 static const struct wl_callback_listener throttle_listener
= {
721 .done
= wayland_throttle_callback
725 get_fourcc(struct dri2_egl_display
*dri2_dpy
,
726 __DRIimage
*image
, int *fourcc
)
731 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FOURCC
,
736 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
,
741 switch (dri_format
) {
742 case __DRI_IMAGE_FORMAT_ARGB8888
:
743 *fourcc
= __DRI_IMAGE_FOURCC_ARGB8888
;
745 case __DRI_IMAGE_FORMAT_XRGB8888
:
746 *fourcc
= __DRI_IMAGE_FOURCC_XRGB8888
;
753 static struct wl_buffer
*
754 create_wl_buffer(struct dri2_egl_display
*dri2_dpy
,
755 struct dri2_egl_surface
*dri2_surf
,
758 struct wl_buffer
*ret
;
760 int width
, height
, fourcc
, num_planes
;
761 uint64_t modifier
= DRM_FORMAT_MOD_INVALID
;
763 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_WIDTH
, &width
);
764 query
&= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_HEIGHT
,
766 query
&= get_fourcc(dri2_dpy
, image
, &fourcc
);
770 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NUM_PLANES
,
775 if (dri2_dpy
->image
->base
.version
>= 15) {
778 query
= dri2_dpy
->image
->queryImage(image
,
779 __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
,
781 query
&= dri2_dpy
->image
->queryImage(image
,
782 __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
,
785 modifier
= (uint64_t) mod_hi
<< 32;
786 modifier
|= (uint64_t) (mod_lo
& 0xffffffff);
790 if (dri2_dpy
->wl_dmabuf
&& modifier
!= DRM_FORMAT_MOD_INVALID
) {
791 struct zwp_linux_buffer_params_v1
*params
;
794 /* We don't need a wrapper for wl_dmabuf objects, because we have to
795 * create the intermediate params object; we can set the queue on this,
796 * and the wl_buffer inherits it race-free. */
797 params
= zwp_linux_dmabuf_v1_create_params(dri2_dpy
->wl_dmabuf
);
799 wl_proxy_set_queue((struct wl_proxy
*) params
, dri2_surf
->wl_queue
);
801 for (i
= 0; i
< num_planes
; i
++) {
809 p_image
= dri2_dpy
->image
->fromPlanar(image
, i
, NULL
);
811 zwp_linux_buffer_params_v1_destroy(params
);
815 query
= dri2_dpy
->image
->queryImage(p_image
,
816 __DRI_IMAGE_ATTRIB_FD
,
818 query
&= dri2_dpy
->image
->queryImage(p_image
,
819 __DRI_IMAGE_ATTRIB_STRIDE
,
821 query
&= dri2_dpy
->image
->queryImage(p_image
,
822 __DRI_IMAGE_ATTRIB_OFFSET
,
824 if (image
!= p_image
)
825 dri2_dpy
->image
->destroyImage(p_image
);
830 zwp_linux_buffer_params_v1_destroy(params
);
834 zwp_linux_buffer_params_v1_add(params
, fd
, i
, offset
, stride
,
835 modifier
>> 32, modifier
& 0xffffffff);
839 ret
= zwp_linux_buffer_params_v1_create_immed(params
, width
, height
,
841 zwp_linux_buffer_params_v1_destroy(params
);
842 } else if (dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
) {
843 struct wl_drm
*wl_drm
=
844 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
850 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FD
, &fd
);
851 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
852 ret
= wl_drm_create_prime_buffer(wl_drm
, fd
, width
, height
, fourcc
, 0,
856 struct wl_drm
*wl_drm
=
857 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
863 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
864 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
865 ret
= wl_drm_create_buffer(wl_drm
, name
, width
, height
, stride
, fourcc
);
872 try_damage_buffer(struct dri2_egl_surface
*dri2_surf
,
876 if (wl_proxy_get_version((struct wl_proxy
*) dri2_surf
->wl_surface_wrapper
)
877 < WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION
)
880 for (int i
= 0; i
< n_rects
; i
++) {
881 const int *rect
= &rects
[i
* 4];
883 wl_surface_damage_buffer(dri2_surf
->wl_surface_wrapper
,
885 dri2_surf
->base
.Height
- rect
[1] - rect
[3],
891 * Called via eglSwapBuffers(), drv->API.SwapBuffers().
894 dri2_wl_swap_buffers_with_damage(_EGLDriver
*drv
,
900 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
901 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
903 while (dri2_surf
->throttle_callback
!= NULL
)
904 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
905 dri2_surf
->wl_queue
) == -1)
908 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
909 if (dri2_surf
->color_buffers
[i
].age
> 0)
910 dri2_surf
->color_buffers
[i
].age
++;
912 /* Make sure we have a back buffer in case we're swapping without ever
914 if (get_back_bo(dri2_surf
) < 0)
915 return _eglError(EGL_BAD_ALLOC
, "dri2_swap_buffers");
917 if (draw
->SwapInterval
> 0) {
918 dri2_surf
->throttle_callback
=
919 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
920 wl_callback_add_listener(dri2_surf
->throttle_callback
,
921 &throttle_listener
, dri2_surf
);
924 dri2_surf
->back
->age
= 1;
925 dri2_surf
->current
= dri2_surf
->back
;
926 dri2_surf
->back
= NULL
;
928 if (!dri2_surf
->current
->wl_buffer
) {
931 if (dri2_dpy
->is_different_gpu
)
932 image
= dri2_surf
->current
->linear_copy
;
934 image
= dri2_surf
->current
->dri_image
;
936 dri2_surf
->current
->wl_buffer
=
937 create_wl_buffer(dri2_dpy
, dri2_surf
, image
);
939 wl_buffer_add_listener(dri2_surf
->current
->wl_buffer
,
940 &wl_buffer_listener
, dri2_surf
);
943 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
944 dri2_surf
->current
->wl_buffer
,
945 dri2_surf
->dx
, dri2_surf
->dy
);
947 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
948 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
949 /* reset resize growing parameters */
953 /* If the compositor doesn't support damage_buffer, we deliberately
954 * ignore the damage region and post maximum damage, due to
955 * https://bugs.freedesktop.org/78190 */
956 if (!n_rects
|| !try_damage_buffer(dri2_surf
, rects
, n_rects
))
957 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
958 0, 0, INT32_MAX
, INT32_MAX
);
960 if (dri2_dpy
->is_different_gpu
) {
961 _EGLContext
*ctx
= _eglGetCurrentContext();
962 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
963 dri2_dpy
->image
->blitImage(dri2_ctx
->dri_context
,
964 dri2_surf
->current
->linear_copy
,
965 dri2_surf
->current
->dri_image
,
966 0, 0, dri2_surf
->base
.Width
,
967 dri2_surf
->base
.Height
,
968 0, 0, dri2_surf
->base
.Width
,
969 dri2_surf
->base
.Height
, 0);
972 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
973 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
975 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
977 /* If we're not waiting for a frame callback then we'll at least throttle
978 * to a sync callback so that we always give a chance for the compositor to
979 * handle the commit and send a release event before checking for a free
981 if (dri2_surf
->throttle_callback
== NULL
) {
982 dri2_surf
->throttle_callback
= wl_display_sync(dri2_surf
->wl_dpy_wrapper
);
983 wl_callback_add_listener(dri2_surf
->throttle_callback
,
984 &throttle_listener
, dri2_surf
);
987 wl_display_flush(dri2_dpy
->wl_dpy
);
993 dri2_wl_query_buffer_age(_EGLDriver
*drv
,
994 _EGLDisplay
*disp
, _EGLSurface
*surface
)
996 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
998 if (get_back_bo(dri2_surf
) < 0) {
999 _eglError(EGL_BAD_ALLOC
, "dri2_query_buffer_age");
1003 return dri2_surf
->back
->age
;
1007 dri2_wl_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1009 return dri2_wl_swap_buffers_with_damage(drv
, disp
, draw
, NULL
, 0);
1012 static struct wl_buffer
*
1013 dri2_wl_create_wayland_buffer_from_image(_EGLDriver
*drv
,
1017 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1018 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
1019 __DRIimage
*image
= dri2_img
->dri_image
;
1020 struct wl_buffer
*buffer
;
1023 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
, &format
);
1025 case __DRI_IMAGE_FORMAT_ARGB2101010
:
1026 if (!(dri2_dpy
->formats
& HAS_ARGB2101010
))
1029 case __DRI_IMAGE_FORMAT_XRGB2101010
:
1030 if (!(dri2_dpy
->formats
& HAS_XRGB2101010
))
1033 case __DRI_IMAGE_FORMAT_ARGB8888
:
1034 if (!(dri2_dpy
->formats
& HAS_ARGB8888
))
1037 case __DRI_IMAGE_FORMAT_XRGB8888
:
1038 if (!(dri2_dpy
->formats
& HAS_XRGB8888
))
1045 buffer
= create_wl_buffer(dri2_dpy
, NULL
, image
);
1047 /* The buffer object will have been created with our internal event queue
1048 * because it is using wl_dmabuf/wl_drm as a proxy factory. We want the
1049 * buffer to be used by the application so we'll reset it to the display's
1050 * default event queue. This isn't actually racy, as the only event the
1051 * buffer can get is a buffer release, which doesn't happen with an explicit
1054 wl_proxy_set_queue((struct wl_proxy
*) buffer
, NULL
);
1059 _eglError(EGL_BAD_MATCH
, "unsupported image format");
1064 dri2_wl_authenticate(_EGLDisplay
*disp
, uint32_t id
)
1066 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1069 if (dri2_dpy
->is_render_node
) {
1070 _eglLog(_EGL_WARNING
, "wayland-egl: client asks server to "
1071 "authenticate for render-nodes");
1074 dri2_dpy
->authenticated
= false;
1076 wl_drm_authenticate(dri2_dpy
->wl_drm
, id
);
1077 if (roundtrip(dri2_dpy
) < 0)
1080 if (!dri2_dpy
->authenticated
)
1083 /* reset authenticated */
1084 dri2_dpy
->authenticated
= true;
1090 drm_handle_device(void *data
, struct wl_drm
*drm
, const char *device
)
1092 struct dri2_egl_display
*dri2_dpy
= data
;
1095 dri2_dpy
->device_name
= strdup(device
);
1096 if (!dri2_dpy
->device_name
)
1099 dri2_dpy
->fd
= loader_open_device(dri2_dpy
->device_name
);
1100 if (dri2_dpy
->fd
== -1) {
1101 _eglLog(_EGL_WARNING
, "wayland-egl: could not open %s (%s)",
1102 dri2_dpy
->device_name
, strerror(errno
));
1106 if (drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
) {
1107 dri2_dpy
->authenticated
= true;
1109 drmGetMagic(dri2_dpy
->fd
, &magic
);
1110 wl_drm_authenticate(dri2_dpy
->wl_drm
, magic
);
1115 drm_handle_format(void *data
, struct wl_drm
*drm
, uint32_t format
)
1117 struct dri2_egl_display
*dri2_dpy
= data
;
1120 case WL_DRM_FORMAT_ARGB2101010
:
1121 dri2_dpy
->formats
|= HAS_ARGB2101010
;
1123 case WL_DRM_FORMAT_XRGB2101010
:
1124 dri2_dpy
->formats
|= HAS_XRGB2101010
;
1126 case WL_DRM_FORMAT_ARGB8888
:
1127 dri2_dpy
->formats
|= HAS_ARGB8888
;
1129 case WL_DRM_FORMAT_XRGB8888
:
1130 dri2_dpy
->formats
|= HAS_XRGB8888
;
1132 case WL_DRM_FORMAT_RGB565
:
1133 dri2_dpy
->formats
|= HAS_RGB565
;
1139 drm_handle_capabilities(void *data
, struct wl_drm
*drm
, uint32_t value
)
1141 struct dri2_egl_display
*dri2_dpy
= data
;
1143 dri2_dpy
->capabilities
= value
;
1147 drm_handle_authenticated(void *data
, struct wl_drm
*drm
)
1149 struct dri2_egl_display
*dri2_dpy
= data
;
1151 dri2_dpy
->authenticated
= true;
1154 static const struct wl_drm_listener drm_listener
= {
1155 .device
= drm_handle_device
,
1156 .format
= drm_handle_format
,
1157 .authenticated
= drm_handle_authenticated
,
1158 .capabilities
= drm_handle_capabilities
1162 dmabuf_ignore_format(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1165 /* formats are implicitly advertised by the 'modifier' event, so ignore */
1169 dmabuf_handle_modifier(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1170 uint32_t format
, uint32_t modifier_hi
,
1171 uint32_t modifier_lo
)
1173 struct dri2_egl_display
*dri2_dpy
= data
;
1174 uint64_t *mod
= NULL
;
1176 if (modifier_hi
== (DRM_FORMAT_MOD_INVALID
>> 32) &&
1177 modifier_lo
== (DRM_FORMAT_MOD_INVALID
& 0xffffffff))
1181 case WL_DRM_FORMAT_ARGB2101010
:
1182 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.argb2101010
);
1183 dri2_dpy
->formats
|= HAS_ARGB2101010
;
1185 case WL_DRM_FORMAT_XRGB2101010
:
1186 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.xrgb2101010
);
1187 dri2_dpy
->formats
|= HAS_XRGB2101010
;
1189 case WL_DRM_FORMAT_ARGB8888
:
1190 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.argb8888
);
1191 dri2_dpy
->formats
|= HAS_ARGB8888
;
1193 case WL_DRM_FORMAT_XRGB8888
:
1194 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.xrgb8888
);
1195 dri2_dpy
->formats
|= HAS_XRGB8888
;
1197 case WL_DRM_FORMAT_RGB565
:
1198 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.rgb565
);
1199 dri2_dpy
->formats
|= HAS_RGB565
;
1208 *mod
= (uint64_t) modifier_hi
<< 32;
1209 *mod
|= (uint64_t) (modifier_lo
& 0xffffffff);
1212 static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener
= {
1213 .format
= dmabuf_ignore_format
,
1214 .modifier
= dmabuf_handle_modifier
,
1218 registry_handle_global_drm(void *data
, struct wl_registry
*registry
,
1219 uint32_t name
, const char *interface
,
1222 struct dri2_egl_display
*dri2_dpy
= data
;
1224 if (strcmp(interface
, "wl_drm") == 0) {
1226 wl_registry_bind(registry
, name
, &wl_drm_interface
, MIN2(version
, 2));
1227 wl_drm_add_listener(dri2_dpy
->wl_drm
, &drm_listener
, dri2_dpy
);
1228 } else if (strcmp(interface
, "zwp_linux_dmabuf_v1") == 0 && version
>= 3) {
1229 dri2_dpy
->wl_dmabuf
=
1230 wl_registry_bind(registry
, name
, &zwp_linux_dmabuf_v1_interface
,
1232 zwp_linux_dmabuf_v1_add_listener(dri2_dpy
->wl_dmabuf
, &dmabuf_listener
,
1238 registry_handle_global_remove(void *data
, struct wl_registry
*registry
,
1243 static const struct wl_registry_listener registry_listener_drm
= {
1244 .global
= registry_handle_global_drm
,
1245 .global_remove
= registry_handle_global_remove
1249 dri2_wl_setup_swap_interval(_EGLDisplay
*disp
)
1251 /* We can't use values greater than 1 on Wayland because we are using the
1252 * frame callback to synchronise the frame and the only way we be sure to
1253 * get a frame callback is to attach a new buffer. Therefore we can't just
1254 * sit drawing nothing to wait until the next ‘n’ frame callbacks */
1256 dri2_setup_swap_interval(disp
, 1);
1259 static const struct dri2_egl_display_vtbl dri2_wl_display_vtbl
= {
1260 .authenticate
= dri2_wl_authenticate
,
1261 .create_window_surface
= dri2_wl_create_window_surface
,
1262 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1263 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1264 .destroy_surface
= dri2_wl_destroy_surface
,
1265 .create_image
= dri2_create_image_khr
,
1266 .swap_buffers
= dri2_wl_swap_buffers
,
1267 .swap_buffers_with_damage
= dri2_wl_swap_buffers_with_damage
,
1268 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1269 .set_damage_region
= dri2_fallback_set_damage_region
,
1270 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1271 .copy_buffers
= dri2_fallback_copy_buffers
,
1272 .query_buffer_age
= dri2_wl_query_buffer_age
,
1273 .create_wayland_buffer_from_image
= dri2_wl_create_wayland_buffer_from_image
,
1274 .get_sync_values
= dri2_fallback_get_sync_values
,
1275 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1278 static const __DRIextension
*dri2_loader_extensions
[] = {
1279 &dri2_loader_extension
.base
,
1280 &image_loader_extension
.base
,
1281 &image_lookup_extension
.base
,
1282 &use_invalidate
.base
,
1286 static const __DRIextension
*image_loader_extensions
[] = {
1287 &image_loader_extension
.base
,
1288 &image_lookup_extension
.base
,
1289 &use_invalidate
.base
,
1294 dri2_wl_add_configs_for_visuals(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1296 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1297 unsigned int format_count
[ARRAY_SIZE(dri2_wl_visuals
)] = { 0 };
1298 unsigned int count
= 0;
1300 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
1301 for (unsigned j
= 0; j
< ARRAY_SIZE(dri2_wl_visuals
); j
++) {
1302 struct dri2_egl_config
*dri2_conf
;
1304 if (!(dri2_dpy
->formats
& dri2_wl_visuals
[j
].has_format
))
1307 dri2_conf
= dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
1308 count
+ 1, EGL_WINDOW_BIT
, NULL
, dri2_wl_visuals
[j
].rgba_masks
);
1310 if (dri2_conf
->base
.ConfigID
== count
+ 1)
1317 for (unsigned i
= 0; i
< ARRAY_SIZE(format_count
); i
++) {
1318 if (!format_count
[i
]) {
1319 _eglLog(_EGL_DEBUG
, "No DRI config supports native format %s",
1320 dri2_wl_visuals
[i
].format_name
);
1324 return (count
!= 0);
1328 dri2_initialize_wayland_drm(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1330 struct dri2_egl_display
*dri2_dpy
;
1332 loader_set_logger(_eglLog
);
1334 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1336 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1339 disp
->DriverData
= (void *) dri2_dpy
;
1340 if (disp
->PlatformDisplay
== NULL
) {
1341 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1342 if (dri2_dpy
->wl_dpy
== NULL
)
1344 dri2_dpy
->own_device
= true;
1346 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
1349 if (!u_vector_init(&dri2_dpy
->wl_modifiers
.xrgb2101010
, sizeof(uint64_t), 32) ||
1350 !u_vector_init(&dri2_dpy
->wl_modifiers
.argb2101010
, sizeof(uint64_t), 32) ||
1351 !u_vector_init(&dri2_dpy
->wl_modifiers
.xrgb8888
, sizeof(uint64_t), 32) ||
1352 !u_vector_init(&dri2_dpy
->wl_modifiers
.argb8888
, sizeof(uint64_t), 32) ||
1353 !u_vector_init(&dri2_dpy
->wl_modifiers
.rgb565
, sizeof(uint64_t), 32)) {
1357 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
1359 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
1360 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
1363 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
1364 dri2_dpy
->wl_queue
);
1366 if (dri2_dpy
->own_device
)
1367 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
1369 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
1370 wl_registry_add_listener(dri2_dpy
->wl_registry
,
1371 ®istry_listener_drm
, dri2_dpy
);
1372 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_drm
== NULL
)
1375 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->fd
== -1)
1378 if (roundtrip(dri2_dpy
) < 0 || !dri2_dpy
->authenticated
)
1381 dri2_dpy
->fd
= loader_get_user_preferred_fd(dri2_dpy
->fd
,
1382 &dri2_dpy
->is_different_gpu
);
1383 if (dri2_dpy
->is_different_gpu
) {
1384 free(dri2_dpy
->device_name
);
1385 dri2_dpy
->device_name
= loader_get_device_name_for_fd(dri2_dpy
->fd
);
1386 if (!dri2_dpy
->device_name
) {
1387 _eglError(EGL_BAD_ALLOC
, "wayland-egl: failed to get device name "
1388 "for requested GPU");
1393 /* we have to do the check now, because loader_get_user_preferred_fd
1394 * will return a render-node when the requested gpu is different
1395 * to the server, but also if the client asks for the same gpu than
1396 * the server by requesting its pci-id */
1397 dri2_dpy
->is_render_node
= drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
;
1399 dri2_dpy
->driver_name
= loader_get_driver_for_fd(dri2_dpy
->fd
);
1400 if (dri2_dpy
->driver_name
== NULL
) {
1401 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to get driver name");
1405 /* render nodes cannot use Gem names, and thus do not support
1406 * the __DRI_DRI2_LOADER extension */
1407 if (!dri2_dpy
->is_render_node
) {
1408 dri2_dpy
->loader_extensions
= dri2_loader_extensions
;
1409 if (!dri2_load_driver(disp
)) {
1410 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to load driver");
1414 dri2_dpy
->loader_extensions
= image_loader_extensions
;
1415 if (!dri2_load_driver_dri3(disp
)) {
1416 _eglError(EGL_BAD_ALLOC
, "DRI3: failed to load driver");
1421 if (!dri2_create_screen(disp
))
1424 if (!dri2_setup_extensions(disp
))
1427 dri2_setup_screen(disp
);
1429 dri2_wl_setup_swap_interval(disp
);
1431 /* To use Prime, we must have _DRI_IMAGE v7 at least.
1432 * createImageFromFds support indicates that Prime export/import
1433 * is supported by the driver. Fall back to
1434 * gem names if we don't have Prime support. */
1436 if (dri2_dpy
->image
->base
.version
< 7 ||
1437 dri2_dpy
->image
->createImageFromFds
== NULL
)
1438 dri2_dpy
->capabilities
&= ~WL_DRM_CAPABILITY_PRIME
;
1440 /* We cannot use Gem names with render-nodes, only prime fds (dma-buf).
1441 * The server needs to accept them */
1442 if (dri2_dpy
->is_render_node
&&
1443 !(dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
)) {
1444 _eglLog(_EGL_WARNING
, "wayland-egl: display is not render-node capable");
1448 if (dri2_dpy
->is_different_gpu
&&
1449 (dri2_dpy
->image
->base
.version
< 9 ||
1450 dri2_dpy
->image
->blitImage
== NULL
)) {
1451 _eglLog(_EGL_WARNING
, "wayland-egl: Different GPU selected, but the "
1452 "Image extension in the driver is not "
1453 "compatible. Version 9 or later and blitImage() "
1458 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
1459 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
1463 dri2_set_WL_bind_wayland_display(drv
, disp
);
1464 /* When cannot convert EGLImage to wl_buffer when on a different gpu,
1465 * because the buffer of the EGLImage has likely a tiling mode the server
1466 * gpu won't support. These is no way to check for now. Thus do not support the
1468 if (!dri2_dpy
->is_different_gpu
)
1469 disp
->Extensions
.WL_create_wayland_buffer_from_image
= EGL_TRUE
;
1471 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
1473 disp
->Extensions
.EXT_swap_buffers_with_damage
= EGL_TRUE
;
1475 /* Fill vtbl last to prevent accidentally calling virtual function during
1478 dri2_dpy
->vtbl
= &dri2_wl_display_vtbl
;
1483 dri2_display_destroy(disp
);
1488 dri2_wl_swrast_get_stride_for_format(int format
, int w
)
1490 if (format
== WL_SHM_FORMAT_RGB565
)
1492 else /* ARGB8888 || XRGB8888 || ARGB2101010 || XRGB2101010 */
1497 * Taken from weston shared/os-compatibility.c
1500 #ifndef HAVE_MKOSTEMP
1503 set_cloexec_or_close(int fd
)
1510 flags
= fcntl(fd
, F_GETFD
);
1514 if (fcntl(fd
, F_SETFD
, flags
| FD_CLOEXEC
) == -1)
1527 * Taken from weston shared/os-compatibility.c
1531 create_tmpfile_cloexec(char *tmpname
)
1535 #ifdef HAVE_MKOSTEMP
1536 fd
= mkostemp(tmpname
, O_CLOEXEC
);
1540 fd
= mkstemp(tmpname
);
1542 fd
= set_cloexec_or_close(fd
);
1551 * Taken from weston shared/os-compatibility.c
1553 * Create a new, unique, anonymous file of the given size, and
1554 * return the file descriptor for it. The file descriptor is set
1555 * CLOEXEC. The file is immediately suitable for mmap()'ing
1556 * the given size at offset zero.
1558 * The file should not have a permanent backing store like a disk,
1559 * but may have if XDG_RUNTIME_DIR is not properly implemented in OS.
1561 * The file name is deleted from the file system.
1563 * The file is suitable for buffer sharing between processes by
1564 * transmitting the file descriptor over Unix sockets using the
1565 * SCM_RIGHTS methods.
1567 * If the C library implements posix_fallocate(), it is used to
1568 * guarantee that disk space is available for the file at the
1569 * given size. If disk space is insufficent, errno is set to ENOSPC.
1570 * If posix_fallocate() is not supported, program may receive
1571 * SIGBUS on accessing mmap()'ed file contents instead.
1574 os_create_anonymous_file(off_t size
)
1576 static const char templ
[] = "/mesa-shared-XXXXXX";
1582 path
= getenv("XDG_RUNTIME_DIR");
1588 name
= malloc(strlen(path
) + sizeof(templ
));
1593 strcat(name
, templ
);
1595 fd
= create_tmpfile_cloexec(name
);
1602 ret
= ftruncate(fd
, size
);
1613 dri2_wl_swrast_allocate_buffer(struct dri2_egl_surface
*dri2_surf
,
1614 int format
, int w
, int h
,
1615 void **data
, int *size
,
1616 struct wl_buffer
**buffer
)
1618 struct dri2_egl_display
*dri2_dpy
=
1619 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1620 struct wl_shm_pool
*pool
;
1621 int fd
, stride
, size_map
;
1624 stride
= dri2_wl_swrast_get_stride_for_format(format
, w
);
1625 size_map
= h
* stride
;
1627 /* Create a sharable buffer */
1628 fd
= os_create_anonymous_file(size_map
);
1632 data_map
= mmap(NULL
, size_map
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
1633 if (data_map
== MAP_FAILED
) {
1638 /* Share it in a wl_buffer */
1639 pool
= wl_shm_create_pool(dri2_dpy
->wl_shm
, fd
, size_map
);
1640 wl_proxy_set_queue((struct wl_proxy
*)pool
, dri2_surf
->wl_queue
);
1641 *buffer
= wl_shm_pool_create_buffer(pool
, 0, w
, h
, stride
, format
);
1642 wl_shm_pool_destroy(pool
);
1651 swrast_update_buffers(struct dri2_egl_surface
*dri2_surf
)
1653 struct dri2_egl_display
*dri2_dpy
=
1654 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1656 /* we need to do the following operations only once per frame */
1657 if (dri2_surf
->back
)
1660 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->width
||
1661 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->height
) {
1663 dri2_wl_release_buffers(dri2_surf
);
1665 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
1666 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
1667 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
1668 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
1669 dri2_surf
->current
= NULL
;
1672 /* find back buffer */
1674 /* There might be a buffer release already queued that wasn't processed */
1675 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
1677 /* try get free buffer already created */
1678 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1679 if (!dri2_surf
->color_buffers
[i
].locked
&&
1680 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1681 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1686 /* else choose any another free location */
1687 if (!dri2_surf
->back
) {
1688 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1689 if (!dri2_surf
->color_buffers
[i
].locked
) {
1690 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1691 if (!dri2_wl_swrast_allocate_buffer(dri2_surf
,
1693 dri2_surf
->base
.Width
,
1694 dri2_surf
->base
.Height
,
1695 &dri2_surf
->back
->data
,
1696 &dri2_surf
->back
->data_size
,
1697 &dri2_surf
->back
->wl_buffer
)) {
1698 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
1701 wl_buffer_add_listener(dri2_surf
->back
->wl_buffer
,
1702 &wl_buffer_listener
, dri2_surf
);
1708 if (!dri2_surf
->back
) {
1709 _eglError(EGL_BAD_ALLOC
, "failed to find free buffer");
1713 dri2_surf
->back
->locked
= true;
1715 /* If we have an extra unlocked buffer at this point, we had to do triple
1716 * buffering for a while, but now can go back to just double buffering.
1717 * That means we can free any unlocked buffer now. */
1718 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1719 if (!dri2_surf
->color_buffers
[i
].locked
&&
1720 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1721 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
1722 munmap(dri2_surf
->color_buffers
[i
].data
,
1723 dri2_surf
->color_buffers
[i
].data_size
);
1724 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
1725 dri2_surf
->color_buffers
[i
].data
= NULL
;
1733 dri2_wl_swrast_get_frontbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1735 /* if there has been a resize: */
1736 if (!dri2_surf
->current
)
1739 return dri2_surf
->current
->data
;
1743 dri2_wl_swrast_get_backbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1745 assert(dri2_surf
->back
);
1746 return dri2_surf
->back
->data
;
1750 dri2_wl_swrast_commit_backbuffer(struct dri2_egl_surface
*dri2_surf
)
1752 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1754 while (dri2_surf
->throttle_callback
!= NULL
)
1755 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
1756 dri2_surf
->wl_queue
) == -1)
1759 if (dri2_surf
->base
.SwapInterval
> 0) {
1760 dri2_surf
->throttle_callback
=
1761 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
1762 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1763 &throttle_listener
, dri2_surf
);
1766 dri2_surf
->current
= dri2_surf
->back
;
1767 dri2_surf
->back
= NULL
;
1769 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
1770 dri2_surf
->current
->wl_buffer
,
1771 dri2_surf
->dx
, dri2_surf
->dy
);
1773 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
1774 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
1775 /* reset resize growing parameters */
1779 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
1780 0, 0, INT32_MAX
, INT32_MAX
);
1781 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
1783 /* If we're not waiting for a frame callback then we'll at least throttle
1784 * to a sync callback so that we always give a chance for the compositor to
1785 * handle the commit and send a release event before checking for a free
1787 if (dri2_surf
->throttle_callback
== NULL
) {
1788 dri2_surf
->throttle_callback
= wl_display_sync(dri2_dpy
->wl_dpy_wrapper
);
1789 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1790 &throttle_listener
, dri2_surf
);
1793 wl_display_flush(dri2_dpy
->wl_dpy
);
1797 dri2_wl_swrast_get_drawable_info(__DRIdrawable
* draw
,
1798 int *x
, int *y
, int *w
, int *h
,
1799 void *loaderPrivate
)
1801 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1803 (void) swrast_update_buffers(dri2_surf
);
1806 *w
= dri2_surf
->base
.Width
;
1807 *h
= dri2_surf
->base
.Height
;
1811 dri2_wl_swrast_get_image(__DRIdrawable
* read
,
1812 int x
, int y
, int w
, int h
,
1813 char *data
, void *loaderPrivate
)
1815 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1816 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1817 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1818 int src_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1819 int dst_stride
= copy_width
;
1822 src
= dri2_wl_swrast_get_frontbuffer_data(dri2_surf
);
1824 memset(data
, 0, copy_width
* h
);
1828 assert(data
!= src
);
1829 assert(copy_width
<= src_stride
);
1832 src
+= y
* src_stride
;
1835 if (copy_width
> src_stride
-x_offset
)
1836 copy_width
= src_stride
-x_offset
;
1837 if (h
> dri2_surf
->base
.Height
-y
)
1838 h
= dri2_surf
->base
.Height
-y
;
1841 memcpy(dst
, src
, copy_width
);
1848 dri2_wl_swrast_put_image2(__DRIdrawable
* draw
, int op
,
1849 int x
, int y
, int w
, int h
, int stride
,
1850 char *data
, void *loaderPrivate
)
1852 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1853 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1854 int dst_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1855 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1858 assert(copy_width
<= stride
);
1860 (void) swrast_update_buffers(dri2_surf
);
1861 dst
= dri2_wl_swrast_get_backbuffer_data(dri2_surf
);
1863 /* partial copy, copy old content */
1864 if (copy_width
< dst_stride
)
1865 dri2_wl_swrast_get_image(draw
, 0, 0,
1866 dri2_surf
->base
.Width
, dri2_surf
->base
.Height
,
1867 dst
, loaderPrivate
);
1870 dst
+= y
* dst_stride
;
1874 /* drivers expect we do these checks (and some rely on it) */
1875 if (copy_width
> dst_stride
-x_offset
)
1876 copy_width
= dst_stride
-x_offset
;
1877 if (h
> dri2_surf
->base
.Height
-y
)
1878 h
= dri2_surf
->base
.Height
-y
;
1881 memcpy(dst
, src
, copy_width
);
1885 dri2_wl_swrast_commit_backbuffer(dri2_surf
);
1889 dri2_wl_swrast_put_image(__DRIdrawable
* draw
, int op
,
1890 int x
, int y
, int w
, int h
,
1891 char *data
, void *loaderPrivate
)
1893 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1896 stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1897 dri2_wl_swrast_put_image2(draw
, op
, x
, y
, w
, h
,
1898 stride
, data
, loaderPrivate
);
1902 dri2_wl_swrast_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1904 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1905 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
1907 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
1912 shm_handle_format(void *data
, struct wl_shm
*shm
, uint32_t format
)
1914 struct dri2_egl_display
*dri2_dpy
= data
;
1917 case WL_SHM_FORMAT_ARGB2101010
:
1918 dri2_dpy
->formats
|= HAS_ARGB2101010
;
1920 case WL_SHM_FORMAT_XRGB2101010
:
1921 dri2_dpy
->formats
|= HAS_XRGB2101010
;
1923 case WL_SHM_FORMAT_ARGB8888
:
1924 dri2_dpy
->formats
|= HAS_ARGB8888
;
1926 case WL_SHM_FORMAT_XRGB8888
:
1927 dri2_dpy
->formats
|= HAS_XRGB8888
;
1929 case WL_SHM_FORMAT_RGB565
:
1930 dri2_dpy
->formats
|= HAS_RGB565
;
1935 static const struct wl_shm_listener shm_listener
= {
1936 .format
= shm_handle_format
1940 registry_handle_global_swrast(void *data
, struct wl_registry
*registry
,
1941 uint32_t name
, const char *interface
,
1944 struct dri2_egl_display
*dri2_dpy
= data
;
1946 if (strcmp(interface
, "wl_shm") == 0) {
1948 wl_registry_bind(registry
, name
, &wl_shm_interface
, 1);
1949 wl_shm_add_listener(dri2_dpy
->wl_shm
, &shm_listener
, dri2_dpy
);
1953 static const struct wl_registry_listener registry_listener_swrast
= {
1954 .global
= registry_handle_global_swrast
,
1955 .global_remove
= registry_handle_global_remove
1958 static const struct dri2_egl_display_vtbl dri2_wl_swrast_display_vtbl
= {
1959 .authenticate
= NULL
,
1960 .create_window_surface
= dri2_wl_create_window_surface
,
1961 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1962 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1963 .destroy_surface
= dri2_wl_destroy_surface
,
1964 .create_image
= dri2_create_image_khr
,
1965 .swap_buffers
= dri2_wl_swrast_swap_buffers
,
1966 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
1967 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1968 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1969 .copy_buffers
= dri2_fallback_copy_buffers
,
1970 .query_buffer_age
= dri2_fallback_query_buffer_age
,
1971 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
1972 .get_sync_values
= dri2_fallback_get_sync_values
,
1973 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1976 static const __DRIswrastLoaderExtension swrast_loader_extension
= {
1977 .base
= { __DRI_SWRAST_LOADER
, 2 },
1979 .getDrawableInfo
= dri2_wl_swrast_get_drawable_info
,
1980 .putImage
= dri2_wl_swrast_put_image
,
1981 .getImage
= dri2_wl_swrast_get_image
,
1982 .putImage2
= dri2_wl_swrast_put_image2
,
1985 static const __DRIextension
*swrast_loader_extensions
[] = {
1986 &swrast_loader_extension
.base
,
1987 &image_lookup_extension
.base
,
1992 dri2_initialize_wayland_swrast(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1994 struct dri2_egl_display
*dri2_dpy
;
1996 loader_set_logger(_eglLog
);
1998 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
2000 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
2003 disp
->DriverData
= (void *) dri2_dpy
;
2004 if (disp
->PlatformDisplay
== NULL
) {
2005 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
2006 if (dri2_dpy
->wl_dpy
== NULL
)
2008 dri2_dpy
->own_device
= true;
2010 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
2013 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
2015 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
2016 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
2019 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
2020 dri2_dpy
->wl_queue
);
2022 if (dri2_dpy
->own_device
)
2023 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
2025 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
2026 wl_registry_add_listener(dri2_dpy
->wl_registry
,
2027 ®istry_listener_swrast
, dri2_dpy
);
2029 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_shm
== NULL
)
2032 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->formats
== 0)
2035 dri2_dpy
->driver_name
= strdup("swrast");
2036 if (!dri2_load_driver_swrast(disp
))
2039 dri2_dpy
->loader_extensions
= swrast_loader_extensions
;
2041 if (!dri2_create_screen(disp
))
2044 if (!dri2_setup_extensions(disp
))
2047 dri2_setup_screen(disp
);
2049 dri2_wl_setup_swap_interval(disp
);
2051 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
2052 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
2056 /* Fill vtbl last to prevent accidentally calling virtual function during
2059 dri2_dpy
->vtbl
= &dri2_wl_swrast_display_vtbl
;
2064 dri2_display_destroy(disp
);
2069 dri2_initialize_wayland(_EGLDriver
*drv
, _EGLDisplay
*disp
)
2071 EGLBoolean initialized
= EGL_FALSE
;
2073 if (!disp
->Options
.ForceSoftware
)
2074 initialized
= dri2_initialize_wayland_drm(drv
, disp
);
2077 initialized
= dri2_initialize_wayland_swrast(drv
, disp
);
2084 dri2_teardown_wayland(struct dri2_egl_display
*dri2_dpy
)
2086 if (dri2_dpy
->wl_drm
)
2087 wl_drm_destroy(dri2_dpy
->wl_drm
);
2088 if (dri2_dpy
->wl_dmabuf
)
2089 zwp_linux_dmabuf_v1_destroy(dri2_dpy
->wl_dmabuf
);
2090 if (dri2_dpy
->wl_shm
)
2091 wl_shm_destroy(dri2_dpy
->wl_shm
);
2092 if (dri2_dpy
->wl_registry
)
2093 wl_registry_destroy(dri2_dpy
->wl_registry
);
2094 if (dri2_dpy
->wl_queue
)
2095 wl_event_queue_destroy(dri2_dpy
->wl_queue
);
2096 if (dri2_dpy
->wl_dpy_wrapper
)
2097 wl_proxy_wrapper_destroy(dri2_dpy
->wl_dpy_wrapper
);
2098 u_vector_finish(&dri2_dpy
->wl_modifiers
.argb2101010
);
2099 u_vector_finish(&dri2_dpy
->wl_modifiers
.xrgb2101010
);
2100 u_vector_finish(&dri2_dpy
->wl_modifiers
.argb8888
);
2101 u_vector_finish(&dri2_dpy
->wl_modifiers
.xrgb8888
);
2102 u_vector_finish(&dri2_dpy
->wl_modifiers
.rgb565
);
2103 if (dri2_dpy
->own_device
)
2104 wl_display_disconnect(dri2_dpy
->wl_dpy
);