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
;
71 unsigned int rgba_masks
[4];
72 } dri2_wl_visuals
[] = {
73 { "XRGB2101010", HAS_XRGB2101010
, { 0x3ff00000, 0xffc00, 0x3ff, 0 } },
74 { "ARGB2101010", HAS_ARGB2101010
, { 0x3ff00000, 0xffc00, 0x3ff, 0xc0000000 } },
75 { "XRGB8888", HAS_XRGB8888
, { 0xff0000, 0xff00, 0x00ff, 0 } },
76 { "ARGB8888", HAS_ARGB8888
, { 0xff0000, 0xff00, 0x00ff, 0xff000000 } },
77 { "RGB565", HAS_RGB565
, { 0x00f800, 0x07e0, 0x001f, 0 } },
81 roundtrip(struct dri2_egl_display
*dri2_dpy
)
83 return wl_display_roundtrip_queue(dri2_dpy
->wl_dpy
, dri2_dpy
->wl_queue
);
87 wl_buffer_release(void *data
, struct wl_buffer
*buffer
)
89 struct dri2_egl_surface
*dri2_surf
= data
;
92 for (i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); ++i
)
93 if (dri2_surf
->color_buffers
[i
].wl_buffer
== buffer
)
96 if (i
== ARRAY_SIZE(dri2_surf
->color_buffers
)) {
97 wl_buffer_destroy(buffer
);
101 dri2_surf
->color_buffers
[i
].locked
= false;
104 static const struct wl_buffer_listener wl_buffer_listener
= {
105 .release
= wl_buffer_release
109 resize_callback(struct wl_egl_window
*wl_win
, void *data
)
111 struct dri2_egl_surface
*dri2_surf
= data
;
112 struct dri2_egl_display
*dri2_dpy
=
113 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
115 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
119 destroy_window_callback(void *data
)
121 struct dri2_egl_surface
*dri2_surf
= data
;
122 dri2_surf
->wl_win
= NULL
;
125 static struct wl_surface
*
126 get_wl_surface_proxy(struct wl_egl_window
*window
)
128 /* Version 3 of wl_egl_window introduced a version field at the same
129 * location where a pointer to wl_surface was stored. Thus, if
130 * window->version is dereferencable, we've been given an older version of
131 * wl_egl_window, and window->version points to wl_surface */
132 if (_eglPointerIsDereferencable((void *)(window
->version
))) {
133 return wl_proxy_create_wrapper((void *)(window
->version
));
135 return wl_proxy_create_wrapper(window
->surface
);
139 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
142 dri2_wl_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
143 _EGLConfig
*conf
, void *native_window
,
144 const EGLint
*attrib_list
)
146 __DRIcreateNewDrawableFunc createNewDrawable
;
147 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
148 struct dri2_egl_config
*dri2_conf
= dri2_egl_config(conf
);
149 struct wl_egl_window
*window
= native_window
;
150 struct dri2_egl_surface
*dri2_surf
;
151 const __DRIconfig
*config
;
153 dri2_surf
= calloc(1, sizeof *dri2_surf
);
155 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
159 if (!dri2_init_surface(&dri2_surf
->base
, disp
, EGL_WINDOW_BIT
, conf
, attrib_list
, false))
162 if (dri2_dpy
->wl_dmabuf
|| dri2_dpy
->wl_drm
) {
163 if (conf
->RedSize
== 5)
164 dri2_surf
->format
= WL_DRM_FORMAT_RGB565
;
165 else if (conf
->RedSize
== 8 && conf
->AlphaSize
== 0)
166 dri2_surf
->format
= WL_DRM_FORMAT_XRGB8888
;
167 else if (conf
->RedSize
== 8)
168 dri2_surf
->format
= WL_DRM_FORMAT_ARGB8888
;
169 else if (conf
->RedSize
== 10 && conf
->AlphaSize
== 0)
170 dri2_surf
->format
= WL_DRM_FORMAT_XRGB2101010
;
171 else if (conf
->RedSize
== 10)
172 dri2_surf
->format
= WL_DRM_FORMAT_ARGB2101010
;
174 assert(dri2_dpy
->wl_shm
);
175 if (conf
->RedSize
== 5)
176 dri2_surf
->format
= WL_SHM_FORMAT_RGB565
;
177 else if (conf
->RedSize
== 8 && conf
->AlphaSize
== 0)
178 dri2_surf
->format
= WL_SHM_FORMAT_XRGB8888
;
179 else if (conf
->RedSize
== 8)
180 dri2_surf
->format
= WL_SHM_FORMAT_ARGB8888
;
181 else if (conf
->RedSize
== 10 && conf
->AlphaSize
== 0)
182 dri2_surf
->format
= WL_SHM_FORMAT_XRGB2101010
;
183 else if (conf
->RedSize
== 10)
184 dri2_surf
->format
= WL_SHM_FORMAT_ARGB2101010
;
187 dri2_surf
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
188 if (!dri2_surf
->wl_queue
) {
189 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
193 if (dri2_dpy
->wl_drm
) {
194 dri2_surf
->wl_drm_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_drm
);
195 if (!dri2_surf
->wl_drm_wrapper
) {
196 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
199 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_drm_wrapper
,
200 dri2_surf
->wl_queue
);
203 dri2_surf
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
204 if (!dri2_surf
->wl_dpy_wrapper
) {
205 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
208 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_dpy_wrapper
,
209 dri2_surf
->wl_queue
);
211 dri2_surf
->wl_surface_wrapper
= get_wl_surface_proxy(window
);
212 if (!dri2_surf
->wl_surface_wrapper
) {
213 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
214 goto cleanup_dpy_wrapper
;
216 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_surface_wrapper
,
217 dri2_surf
->wl_queue
);
219 dri2_surf
->wl_win
= window
;
220 dri2_surf
->wl_win
->private = dri2_surf
;
221 dri2_surf
->wl_win
->destroy_window_callback
= destroy_window_callback
;
223 dri2_surf
->wl_win
->resize_callback
= resize_callback
;
225 config
= dri2_get_dri_config(dri2_conf
, EGL_WINDOW_BIT
,
226 dri2_surf
->base
.GLColorspace
);
228 if (dri2_dpy
->image_driver
)
229 createNewDrawable
= dri2_dpy
->image_driver
->createNewDrawable
;
230 else if (dri2_dpy
->dri2
)
231 createNewDrawable
= dri2_dpy
->dri2
->createNewDrawable
;
233 createNewDrawable
= dri2_dpy
->swrast
->createNewDrawable
;
235 dri2_surf
->dri_drawable
= (*createNewDrawable
)(dri2_dpy
->dri_screen
, config
,
237 if (dri2_surf
->dri_drawable
== NULL
) {
238 _eglError(EGL_BAD_ALLOC
, "createNewDrawable");
239 goto cleanup_surf_wrapper
;
242 dri2_surf
->base
.SwapInterval
= dri2_dpy
->default_swap_interval
;
244 return &dri2_surf
->base
;
246 cleanup_surf_wrapper
:
247 wl_proxy_wrapper_destroy(dri2_surf
->wl_surface_wrapper
);
249 wl_proxy_wrapper_destroy(dri2_surf
->wl_dpy_wrapper
);
251 if (dri2_surf
->wl_drm_wrapper
)
252 wl_proxy_wrapper_destroy(dri2_surf
->wl_drm_wrapper
);
254 wl_event_queue_destroy(dri2_surf
->wl_queue
);
262 dri2_wl_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
263 _EGLConfig
*conf
, void *native_window
,
264 const EGLint
*attrib_list
)
266 /* From the EGL_EXT_platform_wayland spec, version 3:
268 * It is not valid to call eglCreatePlatformPixmapSurfaceEXT with a <dpy>
269 * that belongs to Wayland. Any such call fails and generates
272 _eglError(EGL_BAD_PARAMETER
, "cannot create EGL pixmap surfaces on "
278 * Called via eglDestroySurface(), drv->API.DestroySurface().
281 dri2_wl_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
283 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
284 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
288 dri2_dpy
->core
->destroyDrawable(dri2_surf
->dri_drawable
);
290 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
291 if (dri2_surf
->color_buffers
[i
].wl_buffer
)
292 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
293 if (dri2_surf
->color_buffers
[i
].dri_image
)
294 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
295 if (dri2_surf
->color_buffers
[i
].linear_copy
)
296 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
297 if (dri2_surf
->color_buffers
[i
].data
)
298 munmap(dri2_surf
->color_buffers
[i
].data
,
299 dri2_surf
->color_buffers
[i
].data_size
);
303 dri2_egl_surface_free_local_buffers(dri2_surf
);
305 if (dri2_surf
->throttle_callback
)
306 wl_callback_destroy(dri2_surf
->throttle_callback
);
308 if (dri2_surf
->wl_win
) {
309 dri2_surf
->wl_win
->private = NULL
;
310 dri2_surf
->wl_win
->resize_callback
= NULL
;
311 dri2_surf
->wl_win
->destroy_window_callback
= NULL
;
314 wl_proxy_wrapper_destroy(dri2_surf
->wl_surface_wrapper
);
315 wl_proxy_wrapper_destroy(dri2_surf
->wl_dpy_wrapper
);
316 if (dri2_surf
->wl_drm_wrapper
)
317 wl_proxy_wrapper_destroy(dri2_surf
->wl_drm_wrapper
);
318 wl_event_queue_destroy(dri2_surf
->wl_queue
);
320 dri2_fini_surface(surf
);
327 dri2_wl_release_buffers(struct dri2_egl_surface
*dri2_surf
)
329 struct dri2_egl_display
*dri2_dpy
=
330 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
332 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
333 if (dri2_surf
->color_buffers
[i
].wl_buffer
&&
334 !dri2_surf
->color_buffers
[i
].locked
)
335 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
336 if (dri2_surf
->color_buffers
[i
].dri_image
)
337 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
338 if (dri2_surf
->color_buffers
[i
].linear_copy
)
339 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
340 if (dri2_surf
->color_buffers
[i
].data
)
341 munmap(dri2_surf
->color_buffers
[i
].data
,
342 dri2_surf
->color_buffers
[i
].data_size
);
344 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
345 dri2_surf
->color_buffers
[i
].dri_image
= NULL
;
346 dri2_surf
->color_buffers
[i
].linear_copy
= NULL
;
347 dri2_surf
->color_buffers
[i
].data
= NULL
;
348 dri2_surf
->color_buffers
[i
].locked
= false;
352 dri2_egl_surface_free_local_buffers(dri2_surf
);
356 get_back_bo(struct dri2_egl_surface
*dri2_surf
)
358 struct dri2_egl_display
*dri2_dpy
=
359 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
361 unsigned int dri_image_format
;
365 /* currently supports five WL DRM formats,
366 * WL_DRM_FORMAT_ARGB2101010, WL_DRM_FORMAT_XRGB2101010,
367 * WL_DRM_FORMAT_ARGB8888, WL_DRM_FORMAT_XRGB8888,
368 * and WL_DRM_FORMAT_RGB565
370 switch (dri2_surf
->format
) {
371 case WL_DRM_FORMAT_ARGB2101010
:
372 dri_image_format
= __DRI_IMAGE_FORMAT_ARGB2101010
;
373 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.argb2101010
);
374 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.argb2101010
);
376 case WL_DRM_FORMAT_XRGB2101010
:
377 dri_image_format
= __DRI_IMAGE_FORMAT_XRGB2101010
;
378 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.xrgb2101010
);
379 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.xrgb2101010
);
381 case WL_DRM_FORMAT_ARGB8888
:
382 dri_image_format
= __DRI_IMAGE_FORMAT_ARGB8888
;
383 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.argb8888
);
384 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.argb8888
);
386 case WL_DRM_FORMAT_XRGB8888
:
387 dri_image_format
= __DRI_IMAGE_FORMAT_XRGB8888
;
388 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.xrgb8888
);
389 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.xrgb8888
);
391 case WL_DRM_FORMAT_RGB565
:
392 dri_image_format
= __DRI_IMAGE_FORMAT_RGB565
;
393 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.rgb565
);
394 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.rgb565
);
397 /* format is not supported */
401 /* There might be a buffer release already queued that wasn't processed */
402 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
404 while (dri2_surf
->back
== NULL
) {
405 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
406 /* Get an unlocked buffer, preferrably one with a dri_buffer
407 * already allocated. */
408 if (dri2_surf
->color_buffers
[i
].locked
)
410 if (dri2_surf
->back
== NULL
)
411 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
412 else if (dri2_surf
->back
->dri_image
== NULL
)
413 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
419 /* If we don't have a buffer, then block on the server to release one for
420 * us, and try again. wl_display_dispatch_queue will process any pending
421 * events, however not all servers flush on issuing a buffer release
422 * event. So, we spam the server with roundtrips as they always cause a
425 if (wl_display_roundtrip_queue(dri2_dpy
->wl_dpy
,
426 dri2_surf
->wl_queue
) < 0)
430 if (dri2_surf
->back
== NULL
)
433 use_flags
= __DRI_IMAGE_USE_SHARE
| __DRI_IMAGE_USE_BACKBUFFER
;
435 if (dri2_dpy
->is_different_gpu
&&
436 dri2_surf
->back
->linear_copy
== NULL
) {
437 /* The LINEAR modifier should be a perfect alias of the LINEAR use
438 * flag; try the new interface first before the old, then fall back. */
439 if (dri2_dpy
->image
->base
.version
>= 15 &&
440 dri2_dpy
->image
->createImageWithModifiers
) {
441 uint64_t linear_mod
= DRM_FORMAT_MOD_LINEAR
;
443 dri2_surf
->back
->linear_copy
=
444 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
445 dri2_surf
->base
.Width
,
446 dri2_surf
->base
.Height
,
452 dri2_surf
->back
->linear_copy
=
453 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
454 dri2_surf
->base
.Width
,
455 dri2_surf
->base
.Height
,
458 __DRI_IMAGE_USE_LINEAR
,
461 if (dri2_surf
->back
->linear_copy
== NULL
)
465 if (dri2_surf
->back
->dri_image
== NULL
) {
466 /* If our DRIImage implementation does not support
467 * createImageWithModifiers, then fall back to the old createImage,
468 * and hope it allocates an image which is acceptable to the winsys.
470 if (num_modifiers
&& dri2_dpy
->image
->base
.version
>= 15 &&
471 dri2_dpy
->image
->createImageWithModifiers
) {
472 dri2_surf
->back
->dri_image
=
473 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
474 dri2_surf
->base
.Width
,
475 dri2_surf
->base
.Height
,
481 dri2_surf
->back
->dri_image
=
482 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
483 dri2_surf
->base
.Width
,
484 dri2_surf
->base
.Height
,
486 dri2_dpy
->is_different_gpu
?
491 dri2_surf
->back
->age
= 0;
493 if (dri2_surf
->back
->dri_image
== NULL
)
496 dri2_surf
->back
->locked
= true;
503 back_bo_to_dri_buffer(struct dri2_egl_surface
*dri2_surf
, __DRIbuffer
*buffer
)
505 struct dri2_egl_display
*dri2_dpy
=
506 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
510 image
= dri2_surf
->back
->dri_image
;
512 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
513 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &pitch
);
515 buffer
->attachment
= __DRI_BUFFER_BACK_LEFT
;
517 buffer
->pitch
= pitch
;
523 update_buffers(struct dri2_egl_surface
*dri2_surf
)
525 struct dri2_egl_display
*dri2_dpy
=
526 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
528 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->width
||
529 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->height
) {
531 dri2_wl_release_buffers(dri2_surf
);
533 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
534 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
535 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
536 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
539 if (get_back_bo(dri2_surf
) < 0) {
540 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
544 /* If we have an extra unlocked buffer at this point, we had to do triple
545 * buffering for a while, but now can go back to just double buffering.
546 * That means we can free any unlocked buffer now. */
547 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
548 if (!dri2_surf
->color_buffers
[i
].locked
&&
549 dri2_surf
->color_buffers
[i
].wl_buffer
) {
550 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
551 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
552 if (dri2_dpy
->is_different_gpu
)
553 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
554 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
555 dri2_surf
->color_buffers
[i
].dri_image
= NULL
;
556 dri2_surf
->color_buffers
[i
].linear_copy
= NULL
;
564 dri2_wl_get_buffers_with_format(__DRIdrawable
* driDrawable
,
565 int *width
, int *height
,
566 unsigned int *attachments
, int count
,
567 int *out_count
, void *loaderPrivate
)
569 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
572 if (update_buffers(dri2_surf
) < 0)
575 for (i
= 0, j
= 0; i
< 2 * count
; i
+= 2, j
++) {
578 switch (attachments
[i
]) {
579 case __DRI_BUFFER_BACK_LEFT
:
580 back_bo_to_dri_buffer(dri2_surf
, &dri2_surf
->buffers
[j
]);
583 local
= dri2_egl_surface_alloc_local_buffer(dri2_surf
, attachments
[i
],
587 _eglError(EGL_BAD_ALLOC
, "failed to allocate local buffer");
590 dri2_surf
->buffers
[j
] = *local
;
599 *width
= dri2_surf
->base
.Width
;
600 *height
= dri2_surf
->base
.Height
;
602 return dri2_surf
->buffers
;
606 dri2_wl_get_buffers(__DRIdrawable
* driDrawable
,
607 int *width
, int *height
,
608 unsigned int *attachments
, int count
,
609 int *out_count
, void *loaderPrivate
)
611 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
612 unsigned int *attachments_with_format
;
616 switch (dri2_surf
->format
) {
617 case WL_DRM_FORMAT_ARGB2101010
:
618 case WL_DRM_FORMAT_XRGB2101010
:
619 case WL_DRM_FORMAT_ARGB8888
:
620 case WL_DRM_FORMAT_XRGB8888
:
623 case WL_DRM_FORMAT_RGB565
:
627 /* format is not supported */
631 attachments_with_format
= calloc(count
, 2 * sizeof(unsigned int));
632 if (!attachments_with_format
) {
637 for (int i
= 0; i
< count
; ++i
) {
638 attachments_with_format
[2*i
] = attachments
[i
];
639 attachments_with_format
[2*i
+ 1] = bpp
;
643 dri2_wl_get_buffers_with_format(driDrawable
,
645 attachments_with_format
, count
,
646 out_count
, loaderPrivate
);
648 free(attachments_with_format
);
654 image_get_buffers(__DRIdrawable
*driDrawable
,
658 uint32_t buffer_mask
,
659 struct __DRIimageList
*buffers
)
661 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
663 if (update_buffers(dri2_surf
) < 0)
666 buffers
->image_mask
= __DRI_IMAGE_BUFFER_BACK
;
667 buffers
->back
= dri2_surf
->back
->dri_image
;
673 dri2_wl_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
676 (void) loaderPrivate
;
679 static const __DRIdri2LoaderExtension dri2_loader_extension
= {
680 .base
= { __DRI_DRI2_LOADER
, 3 },
682 .getBuffers
= dri2_wl_get_buffers
,
683 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
684 .getBuffersWithFormat
= dri2_wl_get_buffers_with_format
,
687 static const __DRIimageLoaderExtension image_loader_extension
= {
688 .base
= { __DRI_IMAGE_LOADER
, 1 },
690 .getBuffers
= image_get_buffers
,
691 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
695 wayland_throttle_callback(void *data
,
696 struct wl_callback
*callback
,
699 struct dri2_egl_surface
*dri2_surf
= data
;
701 dri2_surf
->throttle_callback
= NULL
;
702 wl_callback_destroy(callback
);
705 static const struct wl_callback_listener throttle_listener
= {
706 .done
= wayland_throttle_callback
710 get_fourcc(struct dri2_egl_display
*dri2_dpy
,
711 __DRIimage
*image
, int *fourcc
)
716 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FOURCC
,
721 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
,
726 switch (dri_format
) {
727 case __DRI_IMAGE_FORMAT_ARGB8888
:
728 *fourcc
= __DRI_IMAGE_FOURCC_ARGB8888
;
730 case __DRI_IMAGE_FORMAT_XRGB8888
:
731 *fourcc
= __DRI_IMAGE_FOURCC_XRGB8888
;
738 static struct wl_buffer
*
739 create_wl_buffer(struct dri2_egl_display
*dri2_dpy
,
740 struct dri2_egl_surface
*dri2_surf
,
743 struct wl_buffer
*ret
;
745 int width
, height
, fourcc
, num_planes
;
746 uint64_t modifier
= DRM_FORMAT_MOD_INVALID
;
748 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_WIDTH
, &width
);
749 query
&= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_HEIGHT
,
751 query
&= get_fourcc(dri2_dpy
, image
, &fourcc
);
755 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NUM_PLANES
,
760 if (dri2_dpy
->image
->base
.version
>= 15) {
763 query
= dri2_dpy
->image
->queryImage(image
,
764 __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
,
766 query
&= dri2_dpy
->image
->queryImage(image
,
767 __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
,
770 modifier
= (uint64_t) mod_hi
<< 32;
771 modifier
|= (uint64_t) (mod_lo
& 0xffffffff);
775 if (dri2_dpy
->wl_dmabuf
&& modifier
!= DRM_FORMAT_MOD_INVALID
) {
776 struct zwp_linux_buffer_params_v1
*params
;
779 /* We don't need a wrapper for wl_dmabuf objects, because we have to
780 * create the intermediate params object; we can set the queue on this,
781 * and the wl_buffer inherits it race-free. */
782 params
= zwp_linux_dmabuf_v1_create_params(dri2_dpy
->wl_dmabuf
);
784 wl_proxy_set_queue((struct wl_proxy
*) params
, dri2_surf
->wl_queue
);
786 for (i
= 0; i
< num_planes
; i
++) {
794 p_image
= dri2_dpy
->image
->fromPlanar(image
, i
, NULL
);
796 zwp_linux_buffer_params_v1_destroy(params
);
800 query
= dri2_dpy
->image
->queryImage(p_image
,
801 __DRI_IMAGE_ATTRIB_FD
,
803 query
&= dri2_dpy
->image
->queryImage(p_image
,
804 __DRI_IMAGE_ATTRIB_STRIDE
,
806 query
&= dri2_dpy
->image
->queryImage(p_image
,
807 __DRI_IMAGE_ATTRIB_OFFSET
,
809 if (image
!= p_image
)
810 dri2_dpy
->image
->destroyImage(p_image
);
815 zwp_linux_buffer_params_v1_destroy(params
);
819 zwp_linux_buffer_params_v1_add(params
, fd
, i
, offset
, stride
,
820 modifier
>> 32, modifier
& 0xffffffff);
824 ret
= zwp_linux_buffer_params_v1_create_immed(params
, width
, height
,
826 zwp_linux_buffer_params_v1_destroy(params
);
827 } else if (dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
) {
828 struct wl_drm
*wl_drm
=
829 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
835 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FD
, &fd
);
836 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
837 ret
= wl_drm_create_prime_buffer(wl_drm
, fd
, width
, height
, fourcc
, 0,
841 struct wl_drm
*wl_drm
=
842 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
848 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
849 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
850 ret
= wl_drm_create_buffer(wl_drm
, name
, width
, height
, stride
, fourcc
);
857 try_damage_buffer(struct dri2_egl_surface
*dri2_surf
,
861 if (wl_proxy_get_version((struct wl_proxy
*) dri2_surf
->wl_surface_wrapper
)
862 < WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION
)
865 for (int i
= 0; i
< n_rects
; i
++) {
866 const int *rect
= &rects
[i
* 4];
868 wl_surface_damage_buffer(dri2_surf
->wl_surface_wrapper
,
870 dri2_surf
->base
.Height
- rect
[1] - rect
[3],
876 * Called via eglSwapBuffers(), drv->API.SwapBuffers().
879 dri2_wl_swap_buffers_with_damage(_EGLDriver
*drv
,
885 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
886 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
888 while (dri2_surf
->throttle_callback
!= NULL
)
889 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
890 dri2_surf
->wl_queue
) == -1)
893 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
894 if (dri2_surf
->color_buffers
[i
].age
> 0)
895 dri2_surf
->color_buffers
[i
].age
++;
897 /* Make sure we have a back buffer in case we're swapping without ever
899 if (get_back_bo(dri2_surf
) < 0)
900 return _eglError(EGL_BAD_ALLOC
, "dri2_swap_buffers");
902 if (draw
->SwapInterval
> 0) {
903 dri2_surf
->throttle_callback
=
904 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
905 wl_callback_add_listener(dri2_surf
->throttle_callback
,
906 &throttle_listener
, dri2_surf
);
909 dri2_surf
->back
->age
= 1;
910 dri2_surf
->current
= dri2_surf
->back
;
911 dri2_surf
->back
= NULL
;
913 if (!dri2_surf
->current
->wl_buffer
) {
916 if (dri2_dpy
->is_different_gpu
)
917 image
= dri2_surf
->current
->linear_copy
;
919 image
= dri2_surf
->current
->dri_image
;
921 dri2_surf
->current
->wl_buffer
=
922 create_wl_buffer(dri2_dpy
, dri2_surf
, image
);
924 wl_buffer_add_listener(dri2_surf
->current
->wl_buffer
,
925 &wl_buffer_listener
, dri2_surf
);
928 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
929 dri2_surf
->current
->wl_buffer
,
930 dri2_surf
->dx
, dri2_surf
->dy
);
932 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
933 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
934 /* reset resize growing parameters */
938 /* If the compositor doesn't support damage_buffer, we deliberately
939 * ignore the damage region and post maximum damage, due to
940 * https://bugs.freedesktop.org/78190 */
941 if (!n_rects
|| !try_damage_buffer(dri2_surf
, rects
, n_rects
))
942 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
943 0, 0, INT32_MAX
, INT32_MAX
);
945 if (dri2_dpy
->is_different_gpu
) {
946 _EGLContext
*ctx
= _eglGetCurrentContext();
947 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
948 dri2_dpy
->image
->blitImage(dri2_ctx
->dri_context
,
949 dri2_surf
->current
->linear_copy
,
950 dri2_surf
->current
->dri_image
,
951 0, 0, dri2_surf
->base
.Width
,
952 dri2_surf
->base
.Height
,
953 0, 0, dri2_surf
->base
.Width
,
954 dri2_surf
->base
.Height
, 0);
957 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
958 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
960 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
962 /* If we're not waiting for a frame callback then we'll at least throttle
963 * to a sync callback so that we always give a chance for the compositor to
964 * handle the commit and send a release event before checking for a free
966 if (dri2_surf
->throttle_callback
== NULL
) {
967 dri2_surf
->throttle_callback
= wl_display_sync(dri2_surf
->wl_dpy_wrapper
);
968 wl_callback_add_listener(dri2_surf
->throttle_callback
,
969 &throttle_listener
, dri2_surf
);
972 wl_display_flush(dri2_dpy
->wl_dpy
);
978 dri2_wl_query_buffer_age(_EGLDriver
*drv
,
979 _EGLDisplay
*disp
, _EGLSurface
*surface
)
981 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
983 if (get_back_bo(dri2_surf
) < 0) {
984 _eglError(EGL_BAD_ALLOC
, "dri2_query_buffer_age");
988 return dri2_surf
->back
->age
;
992 dri2_wl_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
994 return dri2_wl_swap_buffers_with_damage(drv
, disp
, draw
, NULL
, 0);
997 static struct wl_buffer
*
998 dri2_wl_create_wayland_buffer_from_image(_EGLDriver
*drv
,
1002 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1003 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
1004 __DRIimage
*image
= dri2_img
->dri_image
;
1005 struct wl_buffer
*buffer
;
1008 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
, &format
);
1010 case __DRI_IMAGE_FORMAT_ARGB2101010
:
1011 if (!(dri2_dpy
->formats
& HAS_ARGB2101010
))
1014 case __DRI_IMAGE_FORMAT_XRGB2101010
:
1015 if (!(dri2_dpy
->formats
& HAS_XRGB2101010
))
1018 case __DRI_IMAGE_FORMAT_ARGB8888
:
1019 if (!(dri2_dpy
->formats
& HAS_ARGB8888
))
1022 case __DRI_IMAGE_FORMAT_XRGB8888
:
1023 if (!(dri2_dpy
->formats
& HAS_XRGB8888
))
1030 buffer
= create_wl_buffer(dri2_dpy
, NULL
, image
);
1032 /* The buffer object will have been created with our internal event queue
1033 * because it is using wl_dmabuf/wl_drm as a proxy factory. We want the
1034 * buffer to be used by the application so we'll reset it to the display's
1035 * default event queue. This isn't actually racy, as the only event the
1036 * buffer can get is a buffer release, which doesn't happen with an explicit
1039 wl_proxy_set_queue((struct wl_proxy
*) buffer
, NULL
);
1044 _eglError(EGL_BAD_MATCH
, "unsupported image format");
1049 dri2_wl_authenticate(_EGLDisplay
*disp
, uint32_t id
)
1051 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1054 if (dri2_dpy
->is_render_node
) {
1055 _eglLog(_EGL_WARNING
, "wayland-egl: client asks server to "
1056 "authenticate for render-nodes");
1059 dri2_dpy
->authenticated
= false;
1061 wl_drm_authenticate(dri2_dpy
->wl_drm
, id
);
1062 if (roundtrip(dri2_dpy
) < 0)
1065 if (!dri2_dpy
->authenticated
)
1068 /* reset authenticated */
1069 dri2_dpy
->authenticated
= true;
1075 drm_handle_device(void *data
, struct wl_drm
*drm
, const char *device
)
1077 struct dri2_egl_display
*dri2_dpy
= data
;
1080 dri2_dpy
->device_name
= strdup(device
);
1081 if (!dri2_dpy
->device_name
)
1084 dri2_dpy
->fd
= loader_open_device(dri2_dpy
->device_name
);
1085 if (dri2_dpy
->fd
== -1) {
1086 _eglLog(_EGL_WARNING
, "wayland-egl: could not open %s (%s)",
1087 dri2_dpy
->device_name
, strerror(errno
));
1091 if (drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
) {
1092 dri2_dpy
->authenticated
= true;
1094 drmGetMagic(dri2_dpy
->fd
, &magic
);
1095 wl_drm_authenticate(dri2_dpy
->wl_drm
, magic
);
1100 drm_handle_format(void *data
, struct wl_drm
*drm
, uint32_t format
)
1102 struct dri2_egl_display
*dri2_dpy
= data
;
1105 case WL_DRM_FORMAT_ARGB2101010
:
1106 dri2_dpy
->formats
|= HAS_ARGB2101010
;
1108 case WL_DRM_FORMAT_XRGB2101010
:
1109 dri2_dpy
->formats
|= HAS_XRGB2101010
;
1111 case WL_DRM_FORMAT_ARGB8888
:
1112 dri2_dpy
->formats
|= HAS_ARGB8888
;
1114 case WL_DRM_FORMAT_XRGB8888
:
1115 dri2_dpy
->formats
|= HAS_XRGB8888
;
1117 case WL_DRM_FORMAT_RGB565
:
1118 dri2_dpy
->formats
|= HAS_RGB565
;
1124 drm_handle_capabilities(void *data
, struct wl_drm
*drm
, uint32_t value
)
1126 struct dri2_egl_display
*dri2_dpy
= data
;
1128 dri2_dpy
->capabilities
= value
;
1132 drm_handle_authenticated(void *data
, struct wl_drm
*drm
)
1134 struct dri2_egl_display
*dri2_dpy
= data
;
1136 dri2_dpy
->authenticated
= true;
1139 static const struct wl_drm_listener drm_listener
= {
1140 .device
= drm_handle_device
,
1141 .format
= drm_handle_format
,
1142 .authenticated
= drm_handle_authenticated
,
1143 .capabilities
= drm_handle_capabilities
1147 dmabuf_ignore_format(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1150 /* formats are implicitly advertised by the 'modifier' event, so ignore */
1154 dmabuf_handle_modifier(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1155 uint32_t format
, uint32_t modifier_hi
,
1156 uint32_t modifier_lo
)
1158 struct dri2_egl_display
*dri2_dpy
= data
;
1159 uint64_t *mod
= NULL
;
1161 if (modifier_hi
== (DRM_FORMAT_MOD_INVALID
>> 32) &&
1162 modifier_lo
== (DRM_FORMAT_MOD_INVALID
& 0xffffffff))
1166 case WL_DRM_FORMAT_ARGB2101010
:
1167 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.argb2101010
);
1168 dri2_dpy
->formats
|= HAS_ARGB2101010
;
1170 case WL_DRM_FORMAT_XRGB2101010
:
1171 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.xrgb2101010
);
1172 dri2_dpy
->formats
|= HAS_XRGB2101010
;
1174 case WL_DRM_FORMAT_ARGB8888
:
1175 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.argb8888
);
1176 dri2_dpy
->formats
|= HAS_ARGB8888
;
1178 case WL_DRM_FORMAT_XRGB8888
:
1179 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.xrgb8888
);
1180 dri2_dpy
->formats
|= HAS_XRGB8888
;
1182 case WL_DRM_FORMAT_RGB565
:
1183 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.rgb565
);
1184 dri2_dpy
->formats
|= HAS_RGB565
;
1193 *mod
= (uint64_t) modifier_hi
<< 32;
1194 *mod
|= (uint64_t) (modifier_lo
& 0xffffffff);
1197 static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener
= {
1198 .format
= dmabuf_ignore_format
,
1199 .modifier
= dmabuf_handle_modifier
,
1203 registry_handle_global_drm(void *data
, struct wl_registry
*registry
,
1204 uint32_t name
, const char *interface
,
1207 struct dri2_egl_display
*dri2_dpy
= data
;
1209 if (strcmp(interface
, "wl_drm") == 0) {
1211 wl_registry_bind(registry
, name
, &wl_drm_interface
, MIN2(version
, 2));
1212 wl_drm_add_listener(dri2_dpy
->wl_drm
, &drm_listener
, dri2_dpy
);
1213 } else if (strcmp(interface
, "zwp_linux_dmabuf_v1") == 0 && version
>= 3) {
1214 dri2_dpy
->wl_dmabuf
=
1215 wl_registry_bind(registry
, name
, &zwp_linux_dmabuf_v1_interface
,
1217 zwp_linux_dmabuf_v1_add_listener(dri2_dpy
->wl_dmabuf
, &dmabuf_listener
,
1223 registry_handle_global_remove(void *data
, struct wl_registry
*registry
,
1228 static const struct wl_registry_listener registry_listener_drm
= {
1229 .global
= registry_handle_global_drm
,
1230 .global_remove
= registry_handle_global_remove
1234 dri2_wl_setup_swap_interval(_EGLDisplay
*disp
)
1236 /* We can't use values greater than 1 on Wayland because we are using the
1237 * frame callback to synchronise the frame and the only way we be sure to
1238 * get a frame callback is to attach a new buffer. Therefore we can't just
1239 * sit drawing nothing to wait until the next ‘n’ frame callbacks */
1241 dri2_setup_swap_interval(disp
, 1);
1244 static const struct dri2_egl_display_vtbl dri2_wl_display_vtbl
= {
1245 .authenticate
= dri2_wl_authenticate
,
1246 .create_window_surface
= dri2_wl_create_window_surface
,
1247 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1248 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1249 .destroy_surface
= dri2_wl_destroy_surface
,
1250 .create_image
= dri2_create_image_khr
,
1251 .swap_buffers
= dri2_wl_swap_buffers
,
1252 .swap_buffers_with_damage
= dri2_wl_swap_buffers_with_damage
,
1253 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1254 .set_damage_region
= dri2_fallback_set_damage_region
,
1255 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1256 .copy_buffers
= dri2_fallback_copy_buffers
,
1257 .query_buffer_age
= dri2_wl_query_buffer_age
,
1258 .create_wayland_buffer_from_image
= dri2_wl_create_wayland_buffer_from_image
,
1259 .get_sync_values
= dri2_fallback_get_sync_values
,
1260 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1263 static const __DRIextension
*dri2_loader_extensions
[] = {
1264 &dri2_loader_extension
.base
,
1265 &image_loader_extension
.base
,
1266 &image_lookup_extension
.base
,
1267 &use_invalidate
.base
,
1271 static const __DRIextension
*image_loader_extensions
[] = {
1272 &image_loader_extension
.base
,
1273 &image_lookup_extension
.base
,
1274 &use_invalidate
.base
,
1279 dri2_wl_add_configs_for_visuals(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1281 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1282 unsigned int format_count
[ARRAY_SIZE(dri2_wl_visuals
)] = { 0 };
1283 unsigned int count
= 0;
1285 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
1286 for (unsigned j
= 0; j
< ARRAY_SIZE(dri2_wl_visuals
); j
++) {
1287 struct dri2_egl_config
*dri2_conf
;
1289 if (!(dri2_dpy
->formats
& dri2_wl_visuals
[j
].has_format
))
1292 dri2_conf
= dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
1293 count
+ 1, EGL_WINDOW_BIT
, NULL
, dri2_wl_visuals
[j
].rgba_masks
);
1295 if (dri2_conf
->base
.ConfigID
== count
+ 1)
1302 for (unsigned i
= 0; i
< ARRAY_SIZE(format_count
); i
++) {
1303 if (!format_count
[i
]) {
1304 _eglLog(_EGL_DEBUG
, "No DRI config supports native format %s",
1305 dri2_wl_visuals
[i
].format_name
);
1309 return (count
!= 0);
1313 dri2_initialize_wayland_drm(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1315 struct dri2_egl_display
*dri2_dpy
;
1317 loader_set_logger(_eglLog
);
1319 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1321 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1324 disp
->DriverData
= (void *) dri2_dpy
;
1325 if (disp
->PlatformDisplay
== NULL
) {
1326 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1327 if (dri2_dpy
->wl_dpy
== NULL
)
1329 dri2_dpy
->own_device
= true;
1331 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
1334 if (!u_vector_init(&dri2_dpy
->wl_modifiers
.xrgb2101010
, sizeof(uint64_t), 32) ||
1335 !u_vector_init(&dri2_dpy
->wl_modifiers
.argb2101010
, sizeof(uint64_t), 32) ||
1336 !u_vector_init(&dri2_dpy
->wl_modifiers
.xrgb8888
, sizeof(uint64_t), 32) ||
1337 !u_vector_init(&dri2_dpy
->wl_modifiers
.argb8888
, sizeof(uint64_t), 32) ||
1338 !u_vector_init(&dri2_dpy
->wl_modifiers
.rgb565
, sizeof(uint64_t), 32)) {
1342 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
1344 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
1345 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
1348 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
1349 dri2_dpy
->wl_queue
);
1351 if (dri2_dpy
->own_device
)
1352 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
1354 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
1355 wl_registry_add_listener(dri2_dpy
->wl_registry
,
1356 ®istry_listener_drm
, dri2_dpy
);
1357 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_drm
== NULL
)
1360 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->fd
== -1)
1363 if (roundtrip(dri2_dpy
) < 0 || !dri2_dpy
->authenticated
)
1366 dri2_dpy
->fd
= loader_get_user_preferred_fd(dri2_dpy
->fd
,
1367 &dri2_dpy
->is_different_gpu
);
1368 if (dri2_dpy
->is_different_gpu
) {
1369 free(dri2_dpy
->device_name
);
1370 dri2_dpy
->device_name
= loader_get_device_name_for_fd(dri2_dpy
->fd
);
1371 if (!dri2_dpy
->device_name
) {
1372 _eglError(EGL_BAD_ALLOC
, "wayland-egl: failed to get device name "
1373 "for requested GPU");
1378 /* we have to do the check now, because loader_get_user_preferred_fd
1379 * will return a render-node when the requested gpu is different
1380 * to the server, but also if the client asks for the same gpu than
1381 * the server by requesting its pci-id */
1382 dri2_dpy
->is_render_node
= drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
;
1384 dri2_dpy
->driver_name
= loader_get_driver_for_fd(dri2_dpy
->fd
);
1385 if (dri2_dpy
->driver_name
== NULL
) {
1386 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to get driver name");
1390 /* render nodes cannot use Gem names, and thus do not support
1391 * the __DRI_DRI2_LOADER extension */
1392 if (!dri2_dpy
->is_render_node
) {
1393 dri2_dpy
->loader_extensions
= dri2_loader_extensions
;
1394 if (!dri2_load_driver(disp
)) {
1395 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to load driver");
1399 dri2_dpy
->loader_extensions
= image_loader_extensions
;
1400 if (!dri2_load_driver_dri3(disp
)) {
1401 _eglError(EGL_BAD_ALLOC
, "DRI3: failed to load driver");
1406 if (!dri2_create_screen(disp
))
1409 if (!dri2_setup_extensions(disp
))
1412 dri2_setup_screen(disp
);
1414 dri2_wl_setup_swap_interval(disp
);
1416 /* To use Prime, we must have _DRI_IMAGE v7 at least.
1417 * createImageFromFds support indicates that Prime export/import
1418 * is supported by the driver. Fall back to
1419 * gem names if we don't have Prime support. */
1421 if (dri2_dpy
->image
->base
.version
< 7 ||
1422 dri2_dpy
->image
->createImageFromFds
== NULL
)
1423 dri2_dpy
->capabilities
&= ~WL_DRM_CAPABILITY_PRIME
;
1425 /* We cannot use Gem names with render-nodes, only prime fds (dma-buf).
1426 * The server needs to accept them */
1427 if (dri2_dpy
->is_render_node
&&
1428 !(dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
)) {
1429 _eglLog(_EGL_WARNING
, "wayland-egl: display is not render-node capable");
1433 if (dri2_dpy
->is_different_gpu
&&
1434 (dri2_dpy
->image
->base
.version
< 9 ||
1435 dri2_dpy
->image
->blitImage
== NULL
)) {
1436 _eglLog(_EGL_WARNING
, "wayland-egl: Different GPU selected, but the "
1437 "Image extension in the driver is not "
1438 "compatible. Version 9 or later and blitImage() "
1443 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
1444 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
1448 dri2_set_WL_bind_wayland_display(drv
, disp
);
1449 /* When cannot convert EGLImage to wl_buffer when on a different gpu,
1450 * because the buffer of the EGLImage has likely a tiling mode the server
1451 * gpu won't support. These is no way to check for now. Thus do not support the
1453 if (!dri2_dpy
->is_different_gpu
)
1454 disp
->Extensions
.WL_create_wayland_buffer_from_image
= EGL_TRUE
;
1456 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
1458 disp
->Extensions
.EXT_swap_buffers_with_damage
= EGL_TRUE
;
1460 /* Fill vtbl last to prevent accidentally calling virtual function during
1463 dri2_dpy
->vtbl
= &dri2_wl_display_vtbl
;
1468 dri2_display_destroy(disp
);
1473 dri2_wl_swrast_get_stride_for_format(int format
, int w
)
1475 if (format
== WL_SHM_FORMAT_RGB565
)
1477 else /* ARGB8888 || XRGB8888 || ARGB2101010 || XRGB2101010 */
1482 * Taken from weston shared/os-compatibility.c
1485 #ifndef HAVE_MKOSTEMP
1488 set_cloexec_or_close(int fd
)
1495 flags
= fcntl(fd
, F_GETFD
);
1499 if (fcntl(fd
, F_SETFD
, flags
| FD_CLOEXEC
) == -1)
1512 * Taken from weston shared/os-compatibility.c
1516 create_tmpfile_cloexec(char *tmpname
)
1520 #ifdef HAVE_MKOSTEMP
1521 fd
= mkostemp(tmpname
, O_CLOEXEC
);
1525 fd
= mkstemp(tmpname
);
1527 fd
= set_cloexec_or_close(fd
);
1536 * Taken from weston shared/os-compatibility.c
1538 * Create a new, unique, anonymous file of the given size, and
1539 * return the file descriptor for it. The file descriptor is set
1540 * CLOEXEC. The file is immediately suitable for mmap()'ing
1541 * the given size at offset zero.
1543 * The file should not have a permanent backing store like a disk,
1544 * but may have if XDG_RUNTIME_DIR is not properly implemented in OS.
1546 * The file name is deleted from the file system.
1548 * The file is suitable for buffer sharing between processes by
1549 * transmitting the file descriptor over Unix sockets using the
1550 * SCM_RIGHTS methods.
1552 * If the C library implements posix_fallocate(), it is used to
1553 * guarantee that disk space is available for the file at the
1554 * given size. If disk space is insufficent, errno is set to ENOSPC.
1555 * If posix_fallocate() is not supported, program may receive
1556 * SIGBUS on accessing mmap()'ed file contents instead.
1559 os_create_anonymous_file(off_t size
)
1561 static const char templ
[] = "/mesa-shared-XXXXXX";
1567 path
= getenv("XDG_RUNTIME_DIR");
1573 name
= malloc(strlen(path
) + sizeof(templ
));
1578 strcat(name
, templ
);
1580 fd
= create_tmpfile_cloexec(name
);
1587 ret
= ftruncate(fd
, size
);
1598 dri2_wl_swrast_allocate_buffer(struct dri2_egl_surface
*dri2_surf
,
1599 int format
, int w
, int h
,
1600 void **data
, int *size
,
1601 struct wl_buffer
**buffer
)
1603 struct dri2_egl_display
*dri2_dpy
=
1604 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1605 struct wl_shm_pool
*pool
;
1606 int fd
, stride
, size_map
;
1609 stride
= dri2_wl_swrast_get_stride_for_format(format
, w
);
1610 size_map
= h
* stride
;
1612 /* Create a sharable buffer */
1613 fd
= os_create_anonymous_file(size_map
);
1617 data_map
= mmap(NULL
, size_map
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
1618 if (data_map
== MAP_FAILED
) {
1623 /* Share it in a wl_buffer */
1624 pool
= wl_shm_create_pool(dri2_dpy
->wl_shm
, fd
, size_map
);
1625 wl_proxy_set_queue((struct wl_proxy
*)pool
, dri2_surf
->wl_queue
);
1626 *buffer
= wl_shm_pool_create_buffer(pool
, 0, w
, h
, stride
, format
);
1627 wl_shm_pool_destroy(pool
);
1636 swrast_update_buffers(struct dri2_egl_surface
*dri2_surf
)
1638 struct dri2_egl_display
*dri2_dpy
=
1639 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1641 /* we need to do the following operations only once per frame */
1642 if (dri2_surf
->back
)
1645 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->width
||
1646 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->height
) {
1648 dri2_wl_release_buffers(dri2_surf
);
1650 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
1651 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
1652 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
1653 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
1654 dri2_surf
->current
= NULL
;
1657 /* find back buffer */
1659 /* There might be a buffer release already queued that wasn't processed */
1660 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
1662 /* try get free buffer already created */
1663 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1664 if (!dri2_surf
->color_buffers
[i
].locked
&&
1665 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1666 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1671 /* else choose any another free location */
1672 if (!dri2_surf
->back
) {
1673 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1674 if (!dri2_surf
->color_buffers
[i
].locked
) {
1675 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1676 if (!dri2_wl_swrast_allocate_buffer(dri2_surf
,
1678 dri2_surf
->base
.Width
,
1679 dri2_surf
->base
.Height
,
1680 &dri2_surf
->back
->data
,
1681 &dri2_surf
->back
->data_size
,
1682 &dri2_surf
->back
->wl_buffer
)) {
1683 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
1686 wl_buffer_add_listener(dri2_surf
->back
->wl_buffer
,
1687 &wl_buffer_listener
, dri2_surf
);
1693 if (!dri2_surf
->back
) {
1694 _eglError(EGL_BAD_ALLOC
, "failed to find free buffer");
1698 dri2_surf
->back
->locked
= true;
1700 /* If we have an extra unlocked buffer at this point, we had to do triple
1701 * buffering for a while, but now can go back to just double buffering.
1702 * That means we can free any unlocked buffer now. */
1703 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1704 if (!dri2_surf
->color_buffers
[i
].locked
&&
1705 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1706 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
1707 munmap(dri2_surf
->color_buffers
[i
].data
,
1708 dri2_surf
->color_buffers
[i
].data_size
);
1709 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
1710 dri2_surf
->color_buffers
[i
].data
= NULL
;
1718 dri2_wl_swrast_get_frontbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1720 /* if there has been a resize: */
1721 if (!dri2_surf
->current
)
1724 return dri2_surf
->current
->data
;
1728 dri2_wl_swrast_get_backbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1730 assert(dri2_surf
->back
);
1731 return dri2_surf
->back
->data
;
1735 dri2_wl_swrast_commit_backbuffer(struct dri2_egl_surface
*dri2_surf
)
1737 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1739 while (dri2_surf
->throttle_callback
!= NULL
)
1740 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
1741 dri2_surf
->wl_queue
) == -1)
1744 if (dri2_surf
->base
.SwapInterval
> 0) {
1745 dri2_surf
->throttle_callback
=
1746 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
1747 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1748 &throttle_listener
, dri2_surf
);
1751 dri2_surf
->current
= dri2_surf
->back
;
1752 dri2_surf
->back
= NULL
;
1754 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
1755 dri2_surf
->current
->wl_buffer
,
1756 dri2_surf
->dx
, dri2_surf
->dy
);
1758 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
1759 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
1760 /* reset resize growing parameters */
1764 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
1765 0, 0, INT32_MAX
, INT32_MAX
);
1766 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
1768 /* If we're not waiting for a frame callback then we'll at least throttle
1769 * to a sync callback so that we always give a chance for the compositor to
1770 * handle the commit and send a release event before checking for a free
1772 if (dri2_surf
->throttle_callback
== NULL
) {
1773 dri2_surf
->throttle_callback
= wl_display_sync(dri2_dpy
->wl_dpy_wrapper
);
1774 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1775 &throttle_listener
, dri2_surf
);
1778 wl_display_flush(dri2_dpy
->wl_dpy
);
1782 dri2_wl_swrast_get_drawable_info(__DRIdrawable
* draw
,
1783 int *x
, int *y
, int *w
, int *h
,
1784 void *loaderPrivate
)
1786 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1788 (void) swrast_update_buffers(dri2_surf
);
1791 *w
= dri2_surf
->base
.Width
;
1792 *h
= dri2_surf
->base
.Height
;
1796 dri2_wl_swrast_get_image(__DRIdrawable
* read
,
1797 int x
, int y
, int w
, int h
,
1798 char *data
, void *loaderPrivate
)
1800 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1801 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1802 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1803 int src_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1804 int dst_stride
= copy_width
;
1807 src
= dri2_wl_swrast_get_frontbuffer_data(dri2_surf
);
1809 memset(data
, 0, copy_width
* h
);
1813 assert(data
!= src
);
1814 assert(copy_width
<= src_stride
);
1817 src
+= y
* src_stride
;
1820 if (copy_width
> src_stride
-x_offset
)
1821 copy_width
= src_stride
-x_offset
;
1822 if (h
> dri2_surf
->base
.Height
-y
)
1823 h
= dri2_surf
->base
.Height
-y
;
1826 memcpy(dst
, src
, copy_width
);
1833 dri2_wl_swrast_put_image2(__DRIdrawable
* draw
, int op
,
1834 int x
, int y
, int w
, int h
, int stride
,
1835 char *data
, void *loaderPrivate
)
1837 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1838 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1839 int dst_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1840 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1843 assert(copy_width
<= stride
);
1845 (void) swrast_update_buffers(dri2_surf
);
1846 dst
= dri2_wl_swrast_get_backbuffer_data(dri2_surf
);
1848 /* partial copy, copy old content */
1849 if (copy_width
< dst_stride
)
1850 dri2_wl_swrast_get_image(draw
, 0, 0,
1851 dri2_surf
->base
.Width
, dri2_surf
->base
.Height
,
1852 dst
, loaderPrivate
);
1855 dst
+= y
* dst_stride
;
1859 /* drivers expect we do these checks (and some rely on it) */
1860 if (copy_width
> dst_stride
-x_offset
)
1861 copy_width
= dst_stride
-x_offset
;
1862 if (h
> dri2_surf
->base
.Height
-y
)
1863 h
= dri2_surf
->base
.Height
-y
;
1866 memcpy(dst
, src
, copy_width
);
1870 dri2_wl_swrast_commit_backbuffer(dri2_surf
);
1874 dri2_wl_swrast_put_image(__DRIdrawable
* draw
, int op
,
1875 int x
, int y
, int w
, int h
,
1876 char *data
, void *loaderPrivate
)
1878 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1881 stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1882 dri2_wl_swrast_put_image2(draw
, op
, x
, y
, w
, h
,
1883 stride
, data
, loaderPrivate
);
1887 dri2_wl_swrast_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1889 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1890 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
1892 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
1897 shm_handle_format(void *data
, struct wl_shm
*shm
, uint32_t format
)
1899 struct dri2_egl_display
*dri2_dpy
= data
;
1902 case WL_SHM_FORMAT_ARGB2101010
:
1903 dri2_dpy
->formats
|= HAS_ARGB2101010
;
1905 case WL_SHM_FORMAT_XRGB2101010
:
1906 dri2_dpy
->formats
|= HAS_XRGB2101010
;
1908 case WL_SHM_FORMAT_ARGB8888
:
1909 dri2_dpy
->formats
|= HAS_ARGB8888
;
1911 case WL_SHM_FORMAT_XRGB8888
:
1912 dri2_dpy
->formats
|= HAS_XRGB8888
;
1914 case WL_SHM_FORMAT_RGB565
:
1915 dri2_dpy
->formats
|= HAS_RGB565
;
1920 static const struct wl_shm_listener shm_listener
= {
1921 .format
= shm_handle_format
1925 registry_handle_global_swrast(void *data
, struct wl_registry
*registry
,
1926 uint32_t name
, const char *interface
,
1929 struct dri2_egl_display
*dri2_dpy
= data
;
1931 if (strcmp(interface
, "wl_shm") == 0) {
1933 wl_registry_bind(registry
, name
, &wl_shm_interface
, 1);
1934 wl_shm_add_listener(dri2_dpy
->wl_shm
, &shm_listener
, dri2_dpy
);
1938 static const struct wl_registry_listener registry_listener_swrast
= {
1939 .global
= registry_handle_global_swrast
,
1940 .global_remove
= registry_handle_global_remove
1943 static const struct dri2_egl_display_vtbl dri2_wl_swrast_display_vtbl
= {
1944 .authenticate
= NULL
,
1945 .create_window_surface
= dri2_wl_create_window_surface
,
1946 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1947 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1948 .destroy_surface
= dri2_wl_destroy_surface
,
1949 .create_image
= dri2_create_image_khr
,
1950 .swap_buffers
= dri2_wl_swrast_swap_buffers
,
1951 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
1952 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1953 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1954 .copy_buffers
= dri2_fallback_copy_buffers
,
1955 .query_buffer_age
= dri2_fallback_query_buffer_age
,
1956 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
1957 .get_sync_values
= dri2_fallback_get_sync_values
,
1958 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1961 static const __DRIswrastLoaderExtension swrast_loader_extension
= {
1962 .base
= { __DRI_SWRAST_LOADER
, 2 },
1964 .getDrawableInfo
= dri2_wl_swrast_get_drawable_info
,
1965 .putImage
= dri2_wl_swrast_put_image
,
1966 .getImage
= dri2_wl_swrast_get_image
,
1967 .putImage2
= dri2_wl_swrast_put_image2
,
1970 static const __DRIextension
*swrast_loader_extensions
[] = {
1971 &swrast_loader_extension
.base
,
1972 &image_lookup_extension
.base
,
1977 dri2_initialize_wayland_swrast(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1979 struct dri2_egl_display
*dri2_dpy
;
1981 loader_set_logger(_eglLog
);
1983 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1985 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1988 disp
->DriverData
= (void *) dri2_dpy
;
1989 if (disp
->PlatformDisplay
== NULL
) {
1990 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1991 if (dri2_dpy
->wl_dpy
== NULL
)
1993 dri2_dpy
->own_device
= true;
1995 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
1998 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
2000 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
2001 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
2004 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
2005 dri2_dpy
->wl_queue
);
2007 if (dri2_dpy
->own_device
)
2008 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
2010 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
2011 wl_registry_add_listener(dri2_dpy
->wl_registry
,
2012 ®istry_listener_swrast
, dri2_dpy
);
2014 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_shm
== NULL
)
2017 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->formats
== 0)
2020 dri2_dpy
->driver_name
= strdup("swrast");
2021 if (!dri2_load_driver_swrast(disp
))
2024 dri2_dpy
->loader_extensions
= swrast_loader_extensions
;
2026 if (!dri2_create_screen(disp
))
2029 if (!dri2_setup_extensions(disp
))
2032 dri2_setup_screen(disp
);
2034 dri2_wl_setup_swap_interval(disp
);
2036 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
2037 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
2041 /* Fill vtbl last to prevent accidentally calling virtual function during
2044 dri2_dpy
->vtbl
= &dri2_wl_swrast_display_vtbl
;
2049 dri2_display_destroy(disp
);
2054 dri2_initialize_wayland(_EGLDriver
*drv
, _EGLDisplay
*disp
)
2056 EGLBoolean initialized
= EGL_FALSE
;
2058 if (!disp
->Options
.ForceSoftware
)
2059 initialized
= dri2_initialize_wayland_drm(drv
, disp
);
2062 initialized
= dri2_initialize_wayland_swrast(drv
, disp
);
2069 dri2_teardown_wayland(struct dri2_egl_display
*dri2_dpy
)
2071 if (dri2_dpy
->wl_drm
)
2072 wl_drm_destroy(dri2_dpy
->wl_drm
);
2073 if (dri2_dpy
->wl_dmabuf
)
2074 zwp_linux_dmabuf_v1_destroy(dri2_dpy
->wl_dmabuf
);
2075 if (dri2_dpy
->wl_shm
)
2076 wl_shm_destroy(dri2_dpy
->wl_shm
);
2077 if (dri2_dpy
->wl_registry
)
2078 wl_registry_destroy(dri2_dpy
->wl_registry
);
2079 if (dri2_dpy
->wl_queue
)
2080 wl_event_queue_destroy(dri2_dpy
->wl_queue
);
2081 if (dri2_dpy
->wl_dpy_wrapper
)
2082 wl_proxy_wrapper_destroy(dri2_dpy
->wl_dpy_wrapper
);
2083 u_vector_finish(&dri2_dpy
->wl_modifiers
.argb2101010
);
2084 u_vector_finish(&dri2_dpy
->wl_modifiers
.xrgb2101010
);
2085 u_vector_finish(&dri2_dpy
->wl_modifiers
.argb8888
);
2086 u_vector_finish(&dri2_dpy
->wl_modifiers
.xrgb8888
);
2087 u_vector_finish(&dri2_dpy
->wl_modifiers
.rgb565
);
2088 if (dri2_dpy
->own_device
)
2089 wl_display_disconnect(dri2_dpy
->wl_dpy
);