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 uint32_t wl_drm_format
;
72 uint32_t wl_shm_format
;
74 unsigned int rgba_masks
[4];
75 } dri2_wl_visuals
[] = {
77 "XRGB2101010", HAS_XRGB2101010
,
78 WL_DRM_FORMAT_XRGB2101010
, WL_SHM_FORMAT_XRGB2101010
,
79 __DRI_IMAGE_FORMAT_XRGB2101010
,
80 { 0x3ff00000, 0x000ffc00, 0x000003ff, 0x00000000 }
83 "ARGB2101010", HAS_ARGB2101010
,
84 WL_DRM_FORMAT_ARGB2101010
, WL_SHM_FORMAT_ARGB2101010
,
85 __DRI_IMAGE_FORMAT_ARGB2101010
,
86 { 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 }
89 "XRGB8888", HAS_XRGB8888
,
90 WL_DRM_FORMAT_XRGB8888
, WL_SHM_FORMAT_XRGB8888
,
91 __DRI_IMAGE_FORMAT_XRGB8888
,
92 { 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 }
95 "ARGB8888", HAS_ARGB8888
,
96 WL_DRM_FORMAT_ARGB8888
, WL_SHM_FORMAT_ARGB8888
,
97 __DRI_IMAGE_FORMAT_ARGB8888
,
98 { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }
101 "RGB565", HAS_RGB565
,
102 WL_DRM_FORMAT_RGB565
, WL_SHM_FORMAT_RGB565
,
103 __DRI_IMAGE_FORMAT_RGB565
,
104 { 0xf800, 0x07e0, 0x001f, 0x0000 }
109 roundtrip(struct dri2_egl_display
*dri2_dpy
)
111 return wl_display_roundtrip_queue(dri2_dpy
->wl_dpy
, dri2_dpy
->wl_queue
);
115 wl_buffer_release(void *data
, struct wl_buffer
*buffer
)
117 struct dri2_egl_surface
*dri2_surf
= data
;
120 for (i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); ++i
)
121 if (dri2_surf
->color_buffers
[i
].wl_buffer
== buffer
)
124 if (i
== ARRAY_SIZE(dri2_surf
->color_buffers
)) {
125 wl_buffer_destroy(buffer
);
129 dri2_surf
->color_buffers
[i
].locked
= false;
132 static const struct wl_buffer_listener wl_buffer_listener
= {
133 .release
= wl_buffer_release
137 resize_callback(struct wl_egl_window
*wl_win
, void *data
)
139 struct dri2_egl_surface
*dri2_surf
= data
;
140 struct dri2_egl_display
*dri2_dpy
=
141 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
143 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
147 destroy_window_callback(void *data
)
149 struct dri2_egl_surface
*dri2_surf
= data
;
150 dri2_surf
->wl_win
= NULL
;
153 static struct wl_surface
*
154 get_wl_surface_proxy(struct wl_egl_window
*window
)
156 /* Version 3 of wl_egl_window introduced a version field at the same
157 * location where a pointer to wl_surface was stored. Thus, if
158 * window->version is dereferencable, we've been given an older version of
159 * wl_egl_window, and window->version points to wl_surface */
160 if (_eglPointerIsDereferencable((void *)(window
->version
))) {
161 return wl_proxy_create_wrapper((void *)(window
->version
));
163 return wl_proxy_create_wrapper(window
->surface
);
167 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
170 dri2_wl_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
171 _EGLConfig
*conf
, void *native_window
,
172 const EGLint
*attrib_list
)
174 __DRIcreateNewDrawableFunc createNewDrawable
;
175 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
176 struct dri2_egl_config
*dri2_conf
= dri2_egl_config(conf
);
177 struct wl_egl_window
*window
= native_window
;
178 struct dri2_egl_surface
*dri2_surf
;
179 const __DRIconfig
*config
;
181 dri2_surf
= calloc(1, sizeof *dri2_surf
);
183 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
187 if (!dri2_init_surface(&dri2_surf
->base
, disp
, EGL_WINDOW_BIT
, conf
, attrib_list
, false))
190 if (dri2_dpy
->wl_dmabuf
|| dri2_dpy
->wl_drm
) {
191 if (conf
->RedSize
== 5)
192 dri2_surf
->format
= WL_DRM_FORMAT_RGB565
;
193 else if (conf
->RedSize
== 8 && conf
->AlphaSize
== 0)
194 dri2_surf
->format
= WL_DRM_FORMAT_XRGB8888
;
195 else if (conf
->RedSize
== 8)
196 dri2_surf
->format
= WL_DRM_FORMAT_ARGB8888
;
197 else if (conf
->RedSize
== 10 && conf
->AlphaSize
== 0)
198 dri2_surf
->format
= WL_DRM_FORMAT_XRGB2101010
;
199 else if (conf
->RedSize
== 10)
200 dri2_surf
->format
= WL_DRM_FORMAT_ARGB2101010
;
202 assert(dri2_dpy
->wl_shm
);
203 if (conf
->RedSize
== 5)
204 dri2_surf
->format
= WL_SHM_FORMAT_RGB565
;
205 else if (conf
->RedSize
== 8 && conf
->AlphaSize
== 0)
206 dri2_surf
->format
= WL_SHM_FORMAT_XRGB8888
;
207 else if (conf
->RedSize
== 8)
208 dri2_surf
->format
= WL_SHM_FORMAT_ARGB8888
;
209 else if (conf
->RedSize
== 10 && conf
->AlphaSize
== 0)
210 dri2_surf
->format
= WL_SHM_FORMAT_XRGB2101010
;
211 else if (conf
->RedSize
== 10)
212 dri2_surf
->format
= WL_SHM_FORMAT_ARGB2101010
;
215 dri2_surf
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
216 if (!dri2_surf
->wl_queue
) {
217 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
221 if (dri2_dpy
->wl_drm
) {
222 dri2_surf
->wl_drm_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_drm
);
223 if (!dri2_surf
->wl_drm_wrapper
) {
224 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
227 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_drm_wrapper
,
228 dri2_surf
->wl_queue
);
231 dri2_surf
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
232 if (!dri2_surf
->wl_dpy_wrapper
) {
233 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
236 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_dpy_wrapper
,
237 dri2_surf
->wl_queue
);
239 dri2_surf
->wl_surface_wrapper
= get_wl_surface_proxy(window
);
240 if (!dri2_surf
->wl_surface_wrapper
) {
241 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
242 goto cleanup_dpy_wrapper
;
244 wl_proxy_set_queue((struct wl_proxy
*)dri2_surf
->wl_surface_wrapper
,
245 dri2_surf
->wl_queue
);
247 dri2_surf
->wl_win
= window
;
248 dri2_surf
->wl_win
->private = dri2_surf
;
249 dri2_surf
->wl_win
->destroy_window_callback
= destroy_window_callback
;
251 dri2_surf
->wl_win
->resize_callback
= resize_callback
;
253 config
= dri2_get_dri_config(dri2_conf
, EGL_WINDOW_BIT
,
254 dri2_surf
->base
.GLColorspace
);
256 if (dri2_dpy
->image_driver
)
257 createNewDrawable
= dri2_dpy
->image_driver
->createNewDrawable
;
258 else if (dri2_dpy
->dri2
)
259 createNewDrawable
= dri2_dpy
->dri2
->createNewDrawable
;
261 createNewDrawable
= dri2_dpy
->swrast
->createNewDrawable
;
263 dri2_surf
->dri_drawable
= (*createNewDrawable
)(dri2_dpy
->dri_screen
, config
,
265 if (dri2_surf
->dri_drawable
== NULL
) {
266 _eglError(EGL_BAD_ALLOC
, "createNewDrawable");
267 goto cleanup_surf_wrapper
;
270 dri2_surf
->base
.SwapInterval
= dri2_dpy
->default_swap_interval
;
272 return &dri2_surf
->base
;
274 cleanup_surf_wrapper
:
275 wl_proxy_wrapper_destroy(dri2_surf
->wl_surface_wrapper
);
277 wl_proxy_wrapper_destroy(dri2_surf
->wl_dpy_wrapper
);
279 if (dri2_surf
->wl_drm_wrapper
)
280 wl_proxy_wrapper_destroy(dri2_surf
->wl_drm_wrapper
);
282 wl_event_queue_destroy(dri2_surf
->wl_queue
);
290 dri2_wl_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
291 _EGLConfig
*conf
, void *native_window
,
292 const EGLint
*attrib_list
)
294 /* From the EGL_EXT_platform_wayland spec, version 3:
296 * It is not valid to call eglCreatePlatformPixmapSurfaceEXT with a <dpy>
297 * that belongs to Wayland. Any such call fails and generates
300 _eglError(EGL_BAD_PARAMETER
, "cannot create EGL pixmap surfaces on "
306 * Called via eglDestroySurface(), drv->API.DestroySurface().
309 dri2_wl_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
311 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
312 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
316 dri2_dpy
->core
->destroyDrawable(dri2_surf
->dri_drawable
);
318 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
319 if (dri2_surf
->color_buffers
[i
].wl_buffer
)
320 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
321 if (dri2_surf
->color_buffers
[i
].dri_image
)
322 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
323 if (dri2_surf
->color_buffers
[i
].linear_copy
)
324 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
325 if (dri2_surf
->color_buffers
[i
].data
)
326 munmap(dri2_surf
->color_buffers
[i
].data
,
327 dri2_surf
->color_buffers
[i
].data_size
);
331 dri2_egl_surface_free_local_buffers(dri2_surf
);
333 if (dri2_surf
->throttle_callback
)
334 wl_callback_destroy(dri2_surf
->throttle_callback
);
336 if (dri2_surf
->wl_win
) {
337 dri2_surf
->wl_win
->private = NULL
;
338 dri2_surf
->wl_win
->resize_callback
= NULL
;
339 dri2_surf
->wl_win
->destroy_window_callback
= NULL
;
342 wl_proxy_wrapper_destroy(dri2_surf
->wl_surface_wrapper
);
343 wl_proxy_wrapper_destroy(dri2_surf
->wl_dpy_wrapper
);
344 if (dri2_surf
->wl_drm_wrapper
)
345 wl_proxy_wrapper_destroy(dri2_surf
->wl_drm_wrapper
);
346 wl_event_queue_destroy(dri2_surf
->wl_queue
);
348 dri2_fini_surface(surf
);
355 dri2_wl_release_buffers(struct dri2_egl_surface
*dri2_surf
)
357 struct dri2_egl_display
*dri2_dpy
=
358 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
360 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
361 if (dri2_surf
->color_buffers
[i
].wl_buffer
&&
362 !dri2_surf
->color_buffers
[i
].locked
)
363 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
364 if (dri2_surf
->color_buffers
[i
].dri_image
)
365 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
366 if (dri2_surf
->color_buffers
[i
].linear_copy
)
367 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
368 if (dri2_surf
->color_buffers
[i
].data
)
369 munmap(dri2_surf
->color_buffers
[i
].data
,
370 dri2_surf
->color_buffers
[i
].data_size
);
372 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
373 dri2_surf
->color_buffers
[i
].dri_image
= NULL
;
374 dri2_surf
->color_buffers
[i
].linear_copy
= NULL
;
375 dri2_surf
->color_buffers
[i
].data
= NULL
;
376 dri2_surf
->color_buffers
[i
].locked
= false;
380 dri2_egl_surface_free_local_buffers(dri2_surf
);
384 get_back_bo(struct dri2_egl_surface
*dri2_surf
)
386 struct dri2_egl_display
*dri2_dpy
=
387 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
389 unsigned int dri_image_format
;
393 /* currently supports five WL DRM formats,
394 * WL_DRM_FORMAT_ARGB2101010, WL_DRM_FORMAT_XRGB2101010,
395 * WL_DRM_FORMAT_ARGB8888, WL_DRM_FORMAT_XRGB8888,
396 * and WL_DRM_FORMAT_RGB565
398 switch (dri2_surf
->format
) {
399 case WL_DRM_FORMAT_ARGB2101010
:
400 dri_image_format
= __DRI_IMAGE_FORMAT_ARGB2101010
;
401 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.argb2101010
);
402 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.argb2101010
);
404 case WL_DRM_FORMAT_XRGB2101010
:
405 dri_image_format
= __DRI_IMAGE_FORMAT_XRGB2101010
;
406 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.xrgb2101010
);
407 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.xrgb2101010
);
409 case WL_DRM_FORMAT_ARGB8888
:
410 dri_image_format
= __DRI_IMAGE_FORMAT_ARGB8888
;
411 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.argb8888
);
412 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.argb8888
);
414 case WL_DRM_FORMAT_XRGB8888
:
415 dri_image_format
= __DRI_IMAGE_FORMAT_XRGB8888
;
416 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.xrgb8888
);
417 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.xrgb8888
);
419 case WL_DRM_FORMAT_RGB565
:
420 dri_image_format
= __DRI_IMAGE_FORMAT_RGB565
;
421 modifiers
= u_vector_tail(&dri2_dpy
->wl_modifiers
.rgb565
);
422 num_modifiers
= u_vector_length(&dri2_dpy
->wl_modifiers
.rgb565
);
425 /* format is not supported */
429 /* There might be a buffer release already queued that wasn't processed */
430 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
432 while (dri2_surf
->back
== NULL
) {
433 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
434 /* Get an unlocked buffer, preferrably one with a dri_buffer
435 * already allocated. */
436 if (dri2_surf
->color_buffers
[i
].locked
)
438 if (dri2_surf
->back
== NULL
)
439 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
440 else if (dri2_surf
->back
->dri_image
== NULL
)
441 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
447 /* If we don't have a buffer, then block on the server to release one for
448 * us, and try again. wl_display_dispatch_queue will process any pending
449 * events, however not all servers flush on issuing a buffer release
450 * event. So, we spam the server with roundtrips as they always cause a
453 if (wl_display_roundtrip_queue(dri2_dpy
->wl_dpy
,
454 dri2_surf
->wl_queue
) < 0)
458 if (dri2_surf
->back
== NULL
)
461 use_flags
= __DRI_IMAGE_USE_SHARE
| __DRI_IMAGE_USE_BACKBUFFER
;
463 if (dri2_dpy
->is_different_gpu
&&
464 dri2_surf
->back
->linear_copy
== NULL
) {
465 /* The LINEAR modifier should be a perfect alias of the LINEAR use
466 * flag; try the new interface first before the old, then fall back. */
467 if (dri2_dpy
->image
->base
.version
>= 15 &&
468 dri2_dpy
->image
->createImageWithModifiers
) {
469 uint64_t linear_mod
= DRM_FORMAT_MOD_LINEAR
;
471 dri2_surf
->back
->linear_copy
=
472 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
473 dri2_surf
->base
.Width
,
474 dri2_surf
->base
.Height
,
480 dri2_surf
->back
->linear_copy
=
481 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
482 dri2_surf
->base
.Width
,
483 dri2_surf
->base
.Height
,
486 __DRI_IMAGE_USE_LINEAR
,
489 if (dri2_surf
->back
->linear_copy
== NULL
)
493 if (dri2_surf
->back
->dri_image
== NULL
) {
494 /* If our DRIImage implementation does not support
495 * createImageWithModifiers, then fall back to the old createImage,
496 * and hope it allocates an image which is acceptable to the winsys.
498 if (num_modifiers
&& dri2_dpy
->image
->base
.version
>= 15 &&
499 dri2_dpy
->image
->createImageWithModifiers
) {
500 dri2_surf
->back
->dri_image
=
501 dri2_dpy
->image
->createImageWithModifiers(dri2_dpy
->dri_screen
,
502 dri2_surf
->base
.Width
,
503 dri2_surf
->base
.Height
,
509 dri2_surf
->back
->dri_image
=
510 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
511 dri2_surf
->base
.Width
,
512 dri2_surf
->base
.Height
,
514 dri2_dpy
->is_different_gpu
?
519 dri2_surf
->back
->age
= 0;
521 if (dri2_surf
->back
->dri_image
== NULL
)
524 dri2_surf
->back
->locked
= true;
531 back_bo_to_dri_buffer(struct dri2_egl_surface
*dri2_surf
, __DRIbuffer
*buffer
)
533 struct dri2_egl_display
*dri2_dpy
=
534 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
538 image
= dri2_surf
->back
->dri_image
;
540 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
541 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &pitch
);
543 buffer
->attachment
= __DRI_BUFFER_BACK_LEFT
;
545 buffer
->pitch
= pitch
;
551 update_buffers(struct dri2_egl_surface
*dri2_surf
)
553 struct dri2_egl_display
*dri2_dpy
=
554 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
556 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->width
||
557 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->height
) {
559 dri2_wl_release_buffers(dri2_surf
);
561 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
562 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
563 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
564 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
567 if (get_back_bo(dri2_surf
) < 0) {
568 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
572 /* If we have an extra unlocked buffer at this point, we had to do triple
573 * buffering for a while, but now can go back to just double buffering.
574 * That means we can free any unlocked buffer now. */
575 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
576 if (!dri2_surf
->color_buffers
[i
].locked
&&
577 dri2_surf
->color_buffers
[i
].wl_buffer
) {
578 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
579 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].dri_image
);
580 if (dri2_dpy
->is_different_gpu
)
581 dri2_dpy
->image
->destroyImage(dri2_surf
->color_buffers
[i
].linear_copy
);
582 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
583 dri2_surf
->color_buffers
[i
].dri_image
= NULL
;
584 dri2_surf
->color_buffers
[i
].linear_copy
= NULL
;
592 dri2_wl_get_buffers_with_format(__DRIdrawable
* driDrawable
,
593 int *width
, int *height
,
594 unsigned int *attachments
, int count
,
595 int *out_count
, void *loaderPrivate
)
597 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
600 if (update_buffers(dri2_surf
) < 0)
603 for (i
= 0, j
= 0; i
< 2 * count
; i
+= 2, j
++) {
606 switch (attachments
[i
]) {
607 case __DRI_BUFFER_BACK_LEFT
:
608 back_bo_to_dri_buffer(dri2_surf
, &dri2_surf
->buffers
[j
]);
611 local
= dri2_egl_surface_alloc_local_buffer(dri2_surf
, attachments
[i
],
615 _eglError(EGL_BAD_ALLOC
, "failed to allocate local buffer");
618 dri2_surf
->buffers
[j
] = *local
;
627 *width
= dri2_surf
->base
.Width
;
628 *height
= dri2_surf
->base
.Height
;
630 return dri2_surf
->buffers
;
634 dri2_wl_get_buffers(__DRIdrawable
* driDrawable
,
635 int *width
, int *height
,
636 unsigned int *attachments
, int count
,
637 int *out_count
, void *loaderPrivate
)
639 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
640 unsigned int *attachments_with_format
;
644 switch (dri2_surf
->format
) {
645 case WL_DRM_FORMAT_ARGB2101010
:
646 case WL_DRM_FORMAT_XRGB2101010
:
647 case WL_DRM_FORMAT_ARGB8888
:
648 case WL_DRM_FORMAT_XRGB8888
:
651 case WL_DRM_FORMAT_RGB565
:
655 /* format is not supported */
659 attachments_with_format
= calloc(count
, 2 * sizeof(unsigned int));
660 if (!attachments_with_format
) {
665 for (int i
= 0; i
< count
; ++i
) {
666 attachments_with_format
[2*i
] = attachments
[i
];
667 attachments_with_format
[2*i
+ 1] = bpp
;
671 dri2_wl_get_buffers_with_format(driDrawable
,
673 attachments_with_format
, count
,
674 out_count
, loaderPrivate
);
676 free(attachments_with_format
);
682 image_get_buffers(__DRIdrawable
*driDrawable
,
686 uint32_t buffer_mask
,
687 struct __DRIimageList
*buffers
)
689 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
691 if (update_buffers(dri2_surf
) < 0)
694 buffers
->image_mask
= __DRI_IMAGE_BUFFER_BACK
;
695 buffers
->back
= dri2_surf
->back
->dri_image
;
701 dri2_wl_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
704 (void) loaderPrivate
;
707 static const __DRIdri2LoaderExtension dri2_loader_extension
= {
708 .base
= { __DRI_DRI2_LOADER
, 3 },
710 .getBuffers
= dri2_wl_get_buffers
,
711 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
712 .getBuffersWithFormat
= dri2_wl_get_buffers_with_format
,
715 static const __DRIimageLoaderExtension image_loader_extension
= {
716 .base
= { __DRI_IMAGE_LOADER
, 1 },
718 .getBuffers
= image_get_buffers
,
719 .flushFrontBuffer
= dri2_wl_flush_front_buffer
,
723 wayland_throttle_callback(void *data
,
724 struct wl_callback
*callback
,
727 struct dri2_egl_surface
*dri2_surf
= data
;
729 dri2_surf
->throttle_callback
= NULL
;
730 wl_callback_destroy(callback
);
733 static const struct wl_callback_listener throttle_listener
= {
734 .done
= wayland_throttle_callback
738 get_fourcc(struct dri2_egl_display
*dri2_dpy
,
739 __DRIimage
*image
, int *fourcc
)
744 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FOURCC
,
749 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
,
754 switch (dri_format
) {
755 case __DRI_IMAGE_FORMAT_ARGB8888
:
756 *fourcc
= __DRI_IMAGE_FOURCC_ARGB8888
;
758 case __DRI_IMAGE_FORMAT_XRGB8888
:
759 *fourcc
= __DRI_IMAGE_FOURCC_XRGB8888
;
766 static struct wl_buffer
*
767 create_wl_buffer(struct dri2_egl_display
*dri2_dpy
,
768 struct dri2_egl_surface
*dri2_surf
,
771 struct wl_buffer
*ret
;
773 int width
, height
, fourcc
, num_planes
;
774 uint64_t modifier
= DRM_FORMAT_MOD_INVALID
;
776 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_WIDTH
, &width
);
777 query
&= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_HEIGHT
,
779 query
&= get_fourcc(dri2_dpy
, image
, &fourcc
);
783 query
= dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NUM_PLANES
,
788 if (dri2_dpy
->image
->base
.version
>= 15) {
791 query
= dri2_dpy
->image
->queryImage(image
,
792 __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
,
794 query
&= dri2_dpy
->image
->queryImage(image
,
795 __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
,
798 modifier
= (uint64_t) mod_hi
<< 32;
799 modifier
|= (uint64_t) (mod_lo
& 0xffffffff);
803 if (dri2_dpy
->wl_dmabuf
&& modifier
!= DRM_FORMAT_MOD_INVALID
) {
804 struct zwp_linux_buffer_params_v1
*params
;
807 /* We don't need a wrapper for wl_dmabuf objects, because we have to
808 * create the intermediate params object; we can set the queue on this,
809 * and the wl_buffer inherits it race-free. */
810 params
= zwp_linux_dmabuf_v1_create_params(dri2_dpy
->wl_dmabuf
);
812 wl_proxy_set_queue((struct wl_proxy
*) params
, dri2_surf
->wl_queue
);
814 for (i
= 0; i
< num_planes
; i
++) {
822 p_image
= dri2_dpy
->image
->fromPlanar(image
, i
, NULL
);
824 zwp_linux_buffer_params_v1_destroy(params
);
828 query
= dri2_dpy
->image
->queryImage(p_image
,
829 __DRI_IMAGE_ATTRIB_FD
,
831 query
&= dri2_dpy
->image
->queryImage(p_image
,
832 __DRI_IMAGE_ATTRIB_STRIDE
,
834 query
&= dri2_dpy
->image
->queryImage(p_image
,
835 __DRI_IMAGE_ATTRIB_OFFSET
,
837 if (image
!= p_image
)
838 dri2_dpy
->image
->destroyImage(p_image
);
843 zwp_linux_buffer_params_v1_destroy(params
);
847 zwp_linux_buffer_params_v1_add(params
, fd
, i
, offset
, stride
,
848 modifier
>> 32, modifier
& 0xffffffff);
852 ret
= zwp_linux_buffer_params_v1_create_immed(params
, width
, height
,
854 zwp_linux_buffer_params_v1_destroy(params
);
855 } else if (dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
) {
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_FD
, &fd
);
864 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
865 ret
= wl_drm_create_prime_buffer(wl_drm
, fd
, width
, height
, fourcc
, 0,
869 struct wl_drm
*wl_drm
=
870 dri2_surf
? dri2_surf
->wl_drm_wrapper
: dri2_dpy
->wl_drm
;
876 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
877 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_STRIDE
, &stride
);
878 ret
= wl_drm_create_buffer(wl_drm
, name
, width
, height
, stride
, fourcc
);
885 try_damage_buffer(struct dri2_egl_surface
*dri2_surf
,
889 if (wl_proxy_get_version((struct wl_proxy
*) dri2_surf
->wl_surface_wrapper
)
890 < WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION
)
893 for (int i
= 0; i
< n_rects
; i
++) {
894 const int *rect
= &rects
[i
* 4];
896 wl_surface_damage_buffer(dri2_surf
->wl_surface_wrapper
,
898 dri2_surf
->base
.Height
- rect
[1] - rect
[3],
904 * Called via eglSwapBuffers(), drv->API.SwapBuffers().
907 dri2_wl_swap_buffers_with_damage(_EGLDriver
*drv
,
913 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
914 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
916 while (dri2_surf
->throttle_callback
!= NULL
)
917 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
918 dri2_surf
->wl_queue
) == -1)
921 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
922 if (dri2_surf
->color_buffers
[i
].age
> 0)
923 dri2_surf
->color_buffers
[i
].age
++;
925 /* Make sure we have a back buffer in case we're swapping without ever
927 if (get_back_bo(dri2_surf
) < 0)
928 return _eglError(EGL_BAD_ALLOC
, "dri2_swap_buffers");
930 if (draw
->SwapInterval
> 0) {
931 dri2_surf
->throttle_callback
=
932 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
933 wl_callback_add_listener(dri2_surf
->throttle_callback
,
934 &throttle_listener
, dri2_surf
);
937 dri2_surf
->back
->age
= 1;
938 dri2_surf
->current
= dri2_surf
->back
;
939 dri2_surf
->back
= NULL
;
941 if (!dri2_surf
->current
->wl_buffer
) {
944 if (dri2_dpy
->is_different_gpu
)
945 image
= dri2_surf
->current
->linear_copy
;
947 image
= dri2_surf
->current
->dri_image
;
949 dri2_surf
->current
->wl_buffer
=
950 create_wl_buffer(dri2_dpy
, dri2_surf
, image
);
952 wl_buffer_add_listener(dri2_surf
->current
->wl_buffer
,
953 &wl_buffer_listener
, dri2_surf
);
956 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
957 dri2_surf
->current
->wl_buffer
,
958 dri2_surf
->dx
, dri2_surf
->dy
);
960 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
961 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
962 /* reset resize growing parameters */
966 /* If the compositor doesn't support damage_buffer, we deliberately
967 * ignore the damage region and post maximum damage, due to
968 * https://bugs.freedesktop.org/78190 */
969 if (!n_rects
|| !try_damage_buffer(dri2_surf
, rects
, n_rects
))
970 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
971 0, 0, INT32_MAX
, INT32_MAX
);
973 if (dri2_dpy
->is_different_gpu
) {
974 _EGLContext
*ctx
= _eglGetCurrentContext();
975 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
976 dri2_dpy
->image
->blitImage(dri2_ctx
->dri_context
,
977 dri2_surf
->current
->linear_copy
,
978 dri2_surf
->current
->dri_image
,
979 0, 0, dri2_surf
->base
.Width
,
980 dri2_surf
->base
.Height
,
981 0, 0, dri2_surf
->base
.Width
,
982 dri2_surf
->base
.Height
, 0);
985 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
986 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
988 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
990 /* If we're not waiting for a frame callback then we'll at least throttle
991 * to a sync callback so that we always give a chance for the compositor to
992 * handle the commit and send a release event before checking for a free
994 if (dri2_surf
->throttle_callback
== NULL
) {
995 dri2_surf
->throttle_callback
= wl_display_sync(dri2_surf
->wl_dpy_wrapper
);
996 wl_callback_add_listener(dri2_surf
->throttle_callback
,
997 &throttle_listener
, dri2_surf
);
1000 wl_display_flush(dri2_dpy
->wl_dpy
);
1006 dri2_wl_query_buffer_age(_EGLDriver
*drv
,
1007 _EGLDisplay
*disp
, _EGLSurface
*surface
)
1009 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
1011 if (get_back_bo(dri2_surf
) < 0) {
1012 _eglError(EGL_BAD_ALLOC
, "dri2_query_buffer_age");
1016 return dri2_surf
->back
->age
;
1020 dri2_wl_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1022 return dri2_wl_swap_buffers_with_damage(drv
, disp
, draw
, NULL
, 0);
1025 static struct wl_buffer
*
1026 dri2_wl_create_wayland_buffer_from_image(_EGLDriver
*drv
,
1030 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1031 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
1032 __DRIimage
*image
= dri2_img
->dri_image
;
1033 struct wl_buffer
*buffer
;
1036 dri2_dpy
->image
->queryImage(image
, __DRI_IMAGE_ATTRIB_FORMAT
, &format
);
1038 case __DRI_IMAGE_FORMAT_ARGB2101010
:
1039 if (!(dri2_dpy
->formats
& HAS_ARGB2101010
))
1042 case __DRI_IMAGE_FORMAT_XRGB2101010
:
1043 if (!(dri2_dpy
->formats
& HAS_XRGB2101010
))
1046 case __DRI_IMAGE_FORMAT_ARGB8888
:
1047 if (!(dri2_dpy
->formats
& HAS_ARGB8888
))
1050 case __DRI_IMAGE_FORMAT_XRGB8888
:
1051 if (!(dri2_dpy
->formats
& HAS_XRGB8888
))
1058 buffer
= create_wl_buffer(dri2_dpy
, NULL
, image
);
1060 /* The buffer object will have been created with our internal event queue
1061 * because it is using wl_dmabuf/wl_drm as a proxy factory. We want the
1062 * buffer to be used by the application so we'll reset it to the display's
1063 * default event queue. This isn't actually racy, as the only event the
1064 * buffer can get is a buffer release, which doesn't happen with an explicit
1067 wl_proxy_set_queue((struct wl_proxy
*) buffer
, NULL
);
1072 _eglError(EGL_BAD_MATCH
, "unsupported image format");
1077 dri2_wl_authenticate(_EGLDisplay
*disp
, uint32_t id
)
1079 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1082 if (dri2_dpy
->is_render_node
) {
1083 _eglLog(_EGL_WARNING
, "wayland-egl: client asks server to "
1084 "authenticate for render-nodes");
1087 dri2_dpy
->authenticated
= false;
1089 wl_drm_authenticate(dri2_dpy
->wl_drm
, id
);
1090 if (roundtrip(dri2_dpy
) < 0)
1093 if (!dri2_dpy
->authenticated
)
1096 /* reset authenticated */
1097 dri2_dpy
->authenticated
= true;
1103 drm_handle_device(void *data
, struct wl_drm
*drm
, const char *device
)
1105 struct dri2_egl_display
*dri2_dpy
= data
;
1108 dri2_dpy
->device_name
= strdup(device
);
1109 if (!dri2_dpy
->device_name
)
1112 dri2_dpy
->fd
= loader_open_device(dri2_dpy
->device_name
);
1113 if (dri2_dpy
->fd
== -1) {
1114 _eglLog(_EGL_WARNING
, "wayland-egl: could not open %s (%s)",
1115 dri2_dpy
->device_name
, strerror(errno
));
1119 if (drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
) {
1120 dri2_dpy
->authenticated
= true;
1122 drmGetMagic(dri2_dpy
->fd
, &magic
);
1123 wl_drm_authenticate(dri2_dpy
->wl_drm
, magic
);
1128 drm_handle_format(void *data
, struct wl_drm
*drm
, uint32_t format
)
1130 struct dri2_egl_display
*dri2_dpy
= data
;
1133 case WL_DRM_FORMAT_ARGB2101010
:
1134 dri2_dpy
->formats
|= HAS_ARGB2101010
;
1136 case WL_DRM_FORMAT_XRGB2101010
:
1137 dri2_dpy
->formats
|= HAS_XRGB2101010
;
1139 case WL_DRM_FORMAT_ARGB8888
:
1140 dri2_dpy
->formats
|= HAS_ARGB8888
;
1142 case WL_DRM_FORMAT_XRGB8888
:
1143 dri2_dpy
->formats
|= HAS_XRGB8888
;
1145 case WL_DRM_FORMAT_RGB565
:
1146 dri2_dpy
->formats
|= HAS_RGB565
;
1152 drm_handle_capabilities(void *data
, struct wl_drm
*drm
, uint32_t value
)
1154 struct dri2_egl_display
*dri2_dpy
= data
;
1156 dri2_dpy
->capabilities
= value
;
1160 drm_handle_authenticated(void *data
, struct wl_drm
*drm
)
1162 struct dri2_egl_display
*dri2_dpy
= data
;
1164 dri2_dpy
->authenticated
= true;
1167 static const struct wl_drm_listener drm_listener
= {
1168 .device
= drm_handle_device
,
1169 .format
= drm_handle_format
,
1170 .authenticated
= drm_handle_authenticated
,
1171 .capabilities
= drm_handle_capabilities
1175 dmabuf_ignore_format(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1178 /* formats are implicitly advertised by the 'modifier' event, so ignore */
1182 dmabuf_handle_modifier(void *data
, struct zwp_linux_dmabuf_v1
*dmabuf
,
1183 uint32_t format
, uint32_t modifier_hi
,
1184 uint32_t modifier_lo
)
1186 struct dri2_egl_display
*dri2_dpy
= data
;
1187 uint64_t *mod
= NULL
;
1189 if (modifier_hi
== (DRM_FORMAT_MOD_INVALID
>> 32) &&
1190 modifier_lo
== (DRM_FORMAT_MOD_INVALID
& 0xffffffff))
1194 case WL_DRM_FORMAT_ARGB2101010
:
1195 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.argb2101010
);
1196 dri2_dpy
->formats
|= HAS_ARGB2101010
;
1198 case WL_DRM_FORMAT_XRGB2101010
:
1199 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.xrgb2101010
);
1200 dri2_dpy
->formats
|= HAS_XRGB2101010
;
1202 case WL_DRM_FORMAT_ARGB8888
:
1203 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.argb8888
);
1204 dri2_dpy
->formats
|= HAS_ARGB8888
;
1206 case WL_DRM_FORMAT_XRGB8888
:
1207 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.xrgb8888
);
1208 dri2_dpy
->formats
|= HAS_XRGB8888
;
1210 case WL_DRM_FORMAT_RGB565
:
1211 mod
= u_vector_add(&dri2_dpy
->wl_modifiers
.rgb565
);
1212 dri2_dpy
->formats
|= HAS_RGB565
;
1221 *mod
= (uint64_t) modifier_hi
<< 32;
1222 *mod
|= (uint64_t) (modifier_lo
& 0xffffffff);
1225 static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener
= {
1226 .format
= dmabuf_ignore_format
,
1227 .modifier
= dmabuf_handle_modifier
,
1231 registry_handle_global_drm(void *data
, struct wl_registry
*registry
,
1232 uint32_t name
, const char *interface
,
1235 struct dri2_egl_display
*dri2_dpy
= data
;
1237 if (strcmp(interface
, "wl_drm") == 0) {
1239 wl_registry_bind(registry
, name
, &wl_drm_interface
, MIN2(version
, 2));
1240 wl_drm_add_listener(dri2_dpy
->wl_drm
, &drm_listener
, dri2_dpy
);
1241 } else if (strcmp(interface
, "zwp_linux_dmabuf_v1") == 0 && version
>= 3) {
1242 dri2_dpy
->wl_dmabuf
=
1243 wl_registry_bind(registry
, name
, &zwp_linux_dmabuf_v1_interface
,
1245 zwp_linux_dmabuf_v1_add_listener(dri2_dpy
->wl_dmabuf
, &dmabuf_listener
,
1251 registry_handle_global_remove(void *data
, struct wl_registry
*registry
,
1256 static const struct wl_registry_listener registry_listener_drm
= {
1257 .global
= registry_handle_global_drm
,
1258 .global_remove
= registry_handle_global_remove
1262 dri2_wl_setup_swap_interval(_EGLDisplay
*disp
)
1264 /* We can't use values greater than 1 on Wayland because we are using the
1265 * frame callback to synchronise the frame and the only way we be sure to
1266 * get a frame callback is to attach a new buffer. Therefore we can't just
1267 * sit drawing nothing to wait until the next ‘n’ frame callbacks */
1269 dri2_setup_swap_interval(disp
, 1);
1272 static const struct dri2_egl_display_vtbl dri2_wl_display_vtbl
= {
1273 .authenticate
= dri2_wl_authenticate
,
1274 .create_window_surface
= dri2_wl_create_window_surface
,
1275 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1276 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1277 .destroy_surface
= dri2_wl_destroy_surface
,
1278 .create_image
= dri2_create_image_khr
,
1279 .swap_buffers
= dri2_wl_swap_buffers
,
1280 .swap_buffers_with_damage
= dri2_wl_swap_buffers_with_damage
,
1281 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1282 .set_damage_region
= dri2_fallback_set_damage_region
,
1283 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1284 .copy_buffers
= dri2_fallback_copy_buffers
,
1285 .query_buffer_age
= dri2_wl_query_buffer_age
,
1286 .create_wayland_buffer_from_image
= dri2_wl_create_wayland_buffer_from_image
,
1287 .get_sync_values
= dri2_fallback_get_sync_values
,
1288 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1291 static const __DRIextension
*dri2_loader_extensions
[] = {
1292 &dri2_loader_extension
.base
,
1293 &image_loader_extension
.base
,
1294 &image_lookup_extension
.base
,
1295 &use_invalidate
.base
,
1299 static const __DRIextension
*image_loader_extensions
[] = {
1300 &image_loader_extension
.base
,
1301 &image_lookup_extension
.base
,
1302 &use_invalidate
.base
,
1307 dri2_wl_add_configs_for_visuals(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1309 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1310 unsigned int format_count
[ARRAY_SIZE(dri2_wl_visuals
)] = { 0 };
1311 unsigned int count
= 0;
1313 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
1314 for (unsigned j
= 0; j
< ARRAY_SIZE(dri2_wl_visuals
); j
++) {
1315 struct dri2_egl_config
*dri2_conf
;
1317 if (!(dri2_dpy
->formats
& dri2_wl_visuals
[j
].has_format
))
1320 dri2_conf
= dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
1321 count
+ 1, EGL_WINDOW_BIT
, NULL
, dri2_wl_visuals
[j
].rgba_masks
);
1323 if (dri2_conf
->base
.ConfigID
== count
+ 1)
1330 for (unsigned i
= 0; i
< ARRAY_SIZE(format_count
); i
++) {
1331 if (!format_count
[i
]) {
1332 _eglLog(_EGL_DEBUG
, "No DRI config supports native format %s",
1333 dri2_wl_visuals
[i
].format_name
);
1337 return (count
!= 0);
1341 dri2_initialize_wayland_drm(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1343 struct dri2_egl_display
*dri2_dpy
;
1345 loader_set_logger(_eglLog
);
1347 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
1349 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
1352 disp
->DriverData
= (void *) dri2_dpy
;
1353 if (disp
->PlatformDisplay
== NULL
) {
1354 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
1355 if (dri2_dpy
->wl_dpy
== NULL
)
1357 dri2_dpy
->own_device
= true;
1359 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
1362 if (!u_vector_init(&dri2_dpy
->wl_modifiers
.xrgb2101010
, sizeof(uint64_t), 32) ||
1363 !u_vector_init(&dri2_dpy
->wl_modifiers
.argb2101010
, sizeof(uint64_t), 32) ||
1364 !u_vector_init(&dri2_dpy
->wl_modifiers
.xrgb8888
, sizeof(uint64_t), 32) ||
1365 !u_vector_init(&dri2_dpy
->wl_modifiers
.argb8888
, sizeof(uint64_t), 32) ||
1366 !u_vector_init(&dri2_dpy
->wl_modifiers
.rgb565
, sizeof(uint64_t), 32)) {
1370 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
1372 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
1373 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
1376 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
1377 dri2_dpy
->wl_queue
);
1379 if (dri2_dpy
->own_device
)
1380 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
1382 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
1383 wl_registry_add_listener(dri2_dpy
->wl_registry
,
1384 ®istry_listener_drm
, dri2_dpy
);
1385 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_drm
== NULL
)
1388 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->fd
== -1)
1391 if (roundtrip(dri2_dpy
) < 0 || !dri2_dpy
->authenticated
)
1394 dri2_dpy
->fd
= loader_get_user_preferred_fd(dri2_dpy
->fd
,
1395 &dri2_dpy
->is_different_gpu
);
1396 if (dri2_dpy
->is_different_gpu
) {
1397 free(dri2_dpy
->device_name
);
1398 dri2_dpy
->device_name
= loader_get_device_name_for_fd(dri2_dpy
->fd
);
1399 if (!dri2_dpy
->device_name
) {
1400 _eglError(EGL_BAD_ALLOC
, "wayland-egl: failed to get device name "
1401 "for requested GPU");
1406 /* we have to do the check now, because loader_get_user_preferred_fd
1407 * will return a render-node when the requested gpu is different
1408 * to the server, but also if the client asks for the same gpu than
1409 * the server by requesting its pci-id */
1410 dri2_dpy
->is_render_node
= drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
;
1412 dri2_dpy
->driver_name
= loader_get_driver_for_fd(dri2_dpy
->fd
);
1413 if (dri2_dpy
->driver_name
== NULL
) {
1414 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to get driver name");
1418 /* render nodes cannot use Gem names, and thus do not support
1419 * the __DRI_DRI2_LOADER extension */
1420 if (!dri2_dpy
->is_render_node
) {
1421 dri2_dpy
->loader_extensions
= dri2_loader_extensions
;
1422 if (!dri2_load_driver(disp
)) {
1423 _eglError(EGL_BAD_ALLOC
, "DRI2: failed to load driver");
1427 dri2_dpy
->loader_extensions
= image_loader_extensions
;
1428 if (!dri2_load_driver_dri3(disp
)) {
1429 _eglError(EGL_BAD_ALLOC
, "DRI3: failed to load driver");
1434 if (!dri2_create_screen(disp
))
1437 if (!dri2_setup_extensions(disp
))
1440 dri2_setup_screen(disp
);
1442 dri2_wl_setup_swap_interval(disp
);
1444 /* To use Prime, we must have _DRI_IMAGE v7 at least.
1445 * createImageFromFds support indicates that Prime export/import
1446 * is supported by the driver. Fall back to
1447 * gem names if we don't have Prime support. */
1449 if (dri2_dpy
->image
->base
.version
< 7 ||
1450 dri2_dpy
->image
->createImageFromFds
== NULL
)
1451 dri2_dpy
->capabilities
&= ~WL_DRM_CAPABILITY_PRIME
;
1453 /* We cannot use Gem names with render-nodes, only prime fds (dma-buf).
1454 * The server needs to accept them */
1455 if (dri2_dpy
->is_render_node
&&
1456 !(dri2_dpy
->capabilities
& WL_DRM_CAPABILITY_PRIME
)) {
1457 _eglLog(_EGL_WARNING
, "wayland-egl: display is not render-node capable");
1461 if (dri2_dpy
->is_different_gpu
&&
1462 (dri2_dpy
->image
->base
.version
< 9 ||
1463 dri2_dpy
->image
->blitImage
== NULL
)) {
1464 _eglLog(_EGL_WARNING
, "wayland-egl: Different GPU selected, but the "
1465 "Image extension in the driver is not "
1466 "compatible. Version 9 or later and blitImage() "
1471 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
1472 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
1476 dri2_set_WL_bind_wayland_display(drv
, disp
);
1477 /* When cannot convert EGLImage to wl_buffer when on a different gpu,
1478 * because the buffer of the EGLImage has likely a tiling mode the server
1479 * gpu won't support. These is no way to check for now. Thus do not support the
1481 if (!dri2_dpy
->is_different_gpu
)
1482 disp
->Extensions
.WL_create_wayland_buffer_from_image
= EGL_TRUE
;
1484 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
1486 disp
->Extensions
.EXT_swap_buffers_with_damage
= EGL_TRUE
;
1488 /* Fill vtbl last to prevent accidentally calling virtual function during
1491 dri2_dpy
->vtbl
= &dri2_wl_display_vtbl
;
1496 dri2_display_destroy(disp
);
1501 dri2_wl_swrast_get_stride_for_format(int format
, int w
)
1503 if (format
== WL_SHM_FORMAT_RGB565
)
1505 else /* ARGB8888 || XRGB8888 || ARGB2101010 || XRGB2101010 */
1510 * Taken from weston shared/os-compatibility.c
1513 #ifndef HAVE_MKOSTEMP
1516 set_cloexec_or_close(int fd
)
1523 flags
= fcntl(fd
, F_GETFD
);
1527 if (fcntl(fd
, F_SETFD
, flags
| FD_CLOEXEC
) == -1)
1540 * Taken from weston shared/os-compatibility.c
1544 create_tmpfile_cloexec(char *tmpname
)
1548 #ifdef HAVE_MKOSTEMP
1549 fd
= mkostemp(tmpname
, O_CLOEXEC
);
1553 fd
= mkstemp(tmpname
);
1555 fd
= set_cloexec_or_close(fd
);
1564 * Taken from weston shared/os-compatibility.c
1566 * Create a new, unique, anonymous file of the given size, and
1567 * return the file descriptor for it. The file descriptor is set
1568 * CLOEXEC. The file is immediately suitable for mmap()'ing
1569 * the given size at offset zero.
1571 * The file should not have a permanent backing store like a disk,
1572 * but may have if XDG_RUNTIME_DIR is not properly implemented in OS.
1574 * The file name is deleted from the file system.
1576 * The file is suitable for buffer sharing between processes by
1577 * transmitting the file descriptor over Unix sockets using the
1578 * SCM_RIGHTS methods.
1580 * If the C library implements posix_fallocate(), it is used to
1581 * guarantee that disk space is available for the file at the
1582 * given size. If disk space is insufficent, errno is set to ENOSPC.
1583 * If posix_fallocate() is not supported, program may receive
1584 * SIGBUS on accessing mmap()'ed file contents instead.
1587 os_create_anonymous_file(off_t size
)
1589 static const char templ
[] = "/mesa-shared-XXXXXX";
1595 path
= getenv("XDG_RUNTIME_DIR");
1601 name
= malloc(strlen(path
) + sizeof(templ
));
1606 strcat(name
, templ
);
1608 fd
= create_tmpfile_cloexec(name
);
1615 ret
= ftruncate(fd
, size
);
1626 dri2_wl_swrast_allocate_buffer(struct dri2_egl_surface
*dri2_surf
,
1627 int format
, int w
, int h
,
1628 void **data
, int *size
,
1629 struct wl_buffer
**buffer
)
1631 struct dri2_egl_display
*dri2_dpy
=
1632 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1633 struct wl_shm_pool
*pool
;
1634 int fd
, stride
, size_map
;
1637 stride
= dri2_wl_swrast_get_stride_for_format(format
, w
);
1638 size_map
= h
* stride
;
1640 /* Create a sharable buffer */
1641 fd
= os_create_anonymous_file(size_map
);
1645 data_map
= mmap(NULL
, size_map
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
1646 if (data_map
== MAP_FAILED
) {
1651 /* Share it in a wl_buffer */
1652 pool
= wl_shm_create_pool(dri2_dpy
->wl_shm
, fd
, size_map
);
1653 wl_proxy_set_queue((struct wl_proxy
*)pool
, dri2_surf
->wl_queue
);
1654 *buffer
= wl_shm_pool_create_buffer(pool
, 0, w
, h
, stride
, format
);
1655 wl_shm_pool_destroy(pool
);
1664 swrast_update_buffers(struct dri2_egl_surface
*dri2_surf
)
1666 struct dri2_egl_display
*dri2_dpy
=
1667 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1669 /* we need to do the following operations only once per frame */
1670 if (dri2_surf
->back
)
1673 if (dri2_surf
->base
.Width
!= dri2_surf
->wl_win
->width
||
1674 dri2_surf
->base
.Height
!= dri2_surf
->wl_win
->height
) {
1676 dri2_wl_release_buffers(dri2_surf
);
1678 dri2_surf
->base
.Width
= dri2_surf
->wl_win
->width
;
1679 dri2_surf
->base
.Height
= dri2_surf
->wl_win
->height
;
1680 dri2_surf
->dx
= dri2_surf
->wl_win
->dx
;
1681 dri2_surf
->dy
= dri2_surf
->wl_win
->dy
;
1682 dri2_surf
->current
= NULL
;
1685 /* find back buffer */
1687 /* There might be a buffer release already queued that wasn't processed */
1688 wl_display_dispatch_queue_pending(dri2_dpy
->wl_dpy
, dri2_surf
->wl_queue
);
1690 /* try get free buffer already created */
1691 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1692 if (!dri2_surf
->color_buffers
[i
].locked
&&
1693 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1694 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1699 /* else choose any another free location */
1700 if (!dri2_surf
->back
) {
1701 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1702 if (!dri2_surf
->color_buffers
[i
].locked
) {
1703 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
1704 if (!dri2_wl_swrast_allocate_buffer(dri2_surf
,
1706 dri2_surf
->base
.Width
,
1707 dri2_surf
->base
.Height
,
1708 &dri2_surf
->back
->data
,
1709 &dri2_surf
->back
->data_size
,
1710 &dri2_surf
->back
->wl_buffer
)) {
1711 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
1714 wl_buffer_add_listener(dri2_surf
->back
->wl_buffer
,
1715 &wl_buffer_listener
, dri2_surf
);
1721 if (!dri2_surf
->back
) {
1722 _eglError(EGL_BAD_ALLOC
, "failed to find free buffer");
1726 dri2_surf
->back
->locked
= true;
1728 /* If we have an extra unlocked buffer at this point, we had to do triple
1729 * buffering for a while, but now can go back to just double buffering.
1730 * That means we can free any unlocked buffer now. */
1731 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
1732 if (!dri2_surf
->color_buffers
[i
].locked
&&
1733 dri2_surf
->color_buffers
[i
].wl_buffer
) {
1734 wl_buffer_destroy(dri2_surf
->color_buffers
[i
].wl_buffer
);
1735 munmap(dri2_surf
->color_buffers
[i
].data
,
1736 dri2_surf
->color_buffers
[i
].data_size
);
1737 dri2_surf
->color_buffers
[i
].wl_buffer
= NULL
;
1738 dri2_surf
->color_buffers
[i
].data
= NULL
;
1746 dri2_wl_swrast_get_frontbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1748 /* if there has been a resize: */
1749 if (!dri2_surf
->current
)
1752 return dri2_surf
->current
->data
;
1756 dri2_wl_swrast_get_backbuffer_data(struct dri2_egl_surface
*dri2_surf
)
1758 assert(dri2_surf
->back
);
1759 return dri2_surf
->back
->data
;
1763 dri2_wl_swrast_commit_backbuffer(struct dri2_egl_surface
*dri2_surf
)
1765 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1767 while (dri2_surf
->throttle_callback
!= NULL
)
1768 if (wl_display_dispatch_queue(dri2_dpy
->wl_dpy
,
1769 dri2_surf
->wl_queue
) == -1)
1772 if (dri2_surf
->base
.SwapInterval
> 0) {
1773 dri2_surf
->throttle_callback
=
1774 wl_surface_frame(dri2_surf
->wl_surface_wrapper
);
1775 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1776 &throttle_listener
, dri2_surf
);
1779 dri2_surf
->current
= dri2_surf
->back
;
1780 dri2_surf
->back
= NULL
;
1782 wl_surface_attach(dri2_surf
->wl_surface_wrapper
,
1783 dri2_surf
->current
->wl_buffer
,
1784 dri2_surf
->dx
, dri2_surf
->dy
);
1786 dri2_surf
->wl_win
->attached_width
= dri2_surf
->base
.Width
;
1787 dri2_surf
->wl_win
->attached_height
= dri2_surf
->base
.Height
;
1788 /* reset resize growing parameters */
1792 wl_surface_damage(dri2_surf
->wl_surface_wrapper
,
1793 0, 0, INT32_MAX
, INT32_MAX
);
1794 wl_surface_commit(dri2_surf
->wl_surface_wrapper
);
1796 /* If we're not waiting for a frame callback then we'll at least throttle
1797 * to a sync callback so that we always give a chance for the compositor to
1798 * handle the commit and send a release event before checking for a free
1800 if (dri2_surf
->throttle_callback
== NULL
) {
1801 dri2_surf
->throttle_callback
= wl_display_sync(dri2_dpy
->wl_dpy_wrapper
);
1802 wl_callback_add_listener(dri2_surf
->throttle_callback
,
1803 &throttle_listener
, dri2_surf
);
1806 wl_display_flush(dri2_dpy
->wl_dpy
);
1810 dri2_wl_swrast_get_drawable_info(__DRIdrawable
* draw
,
1811 int *x
, int *y
, int *w
, int *h
,
1812 void *loaderPrivate
)
1814 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1816 (void) swrast_update_buffers(dri2_surf
);
1819 *w
= dri2_surf
->base
.Width
;
1820 *h
= dri2_surf
->base
.Height
;
1824 dri2_wl_swrast_get_image(__DRIdrawable
* read
,
1825 int x
, int y
, int w
, int h
,
1826 char *data
, void *loaderPrivate
)
1828 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1829 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1830 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1831 int src_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1832 int dst_stride
= copy_width
;
1835 src
= dri2_wl_swrast_get_frontbuffer_data(dri2_surf
);
1837 memset(data
, 0, copy_width
* h
);
1841 assert(data
!= src
);
1842 assert(copy_width
<= src_stride
);
1845 src
+= y
* src_stride
;
1848 if (copy_width
> src_stride
-x_offset
)
1849 copy_width
= src_stride
-x_offset
;
1850 if (h
> dri2_surf
->base
.Height
-y
)
1851 h
= dri2_surf
->base
.Height
-y
;
1854 memcpy(dst
, src
, copy_width
);
1861 dri2_wl_swrast_put_image2(__DRIdrawable
* draw
, int op
,
1862 int x
, int y
, int w
, int h
, int stride
,
1863 char *data
, void *loaderPrivate
)
1865 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1866 int copy_width
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1867 int dst_stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, dri2_surf
->base
.Width
);
1868 int x_offset
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, x
);
1871 assert(copy_width
<= stride
);
1873 (void) swrast_update_buffers(dri2_surf
);
1874 dst
= dri2_wl_swrast_get_backbuffer_data(dri2_surf
);
1876 /* partial copy, copy old content */
1877 if (copy_width
< dst_stride
)
1878 dri2_wl_swrast_get_image(draw
, 0, 0,
1879 dri2_surf
->base
.Width
, dri2_surf
->base
.Height
,
1880 dst
, loaderPrivate
);
1883 dst
+= y
* dst_stride
;
1887 /* drivers expect we do these checks (and some rely on it) */
1888 if (copy_width
> dst_stride
-x_offset
)
1889 copy_width
= dst_stride
-x_offset
;
1890 if (h
> dri2_surf
->base
.Height
-y
)
1891 h
= dri2_surf
->base
.Height
-y
;
1894 memcpy(dst
, src
, copy_width
);
1898 dri2_wl_swrast_commit_backbuffer(dri2_surf
);
1902 dri2_wl_swrast_put_image(__DRIdrawable
* draw
, int op
,
1903 int x
, int y
, int w
, int h
,
1904 char *data
, void *loaderPrivate
)
1906 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
1909 stride
= dri2_wl_swrast_get_stride_for_format(dri2_surf
->format
, w
);
1910 dri2_wl_swrast_put_image2(draw
, op
, x
, y
, w
, h
,
1911 stride
, data
, loaderPrivate
);
1915 dri2_wl_swrast_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1917 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1918 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
1920 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
1925 shm_handle_format(void *data
, struct wl_shm
*shm
, uint32_t format
)
1927 struct dri2_egl_display
*dri2_dpy
= data
;
1930 case WL_SHM_FORMAT_ARGB2101010
:
1931 dri2_dpy
->formats
|= HAS_ARGB2101010
;
1933 case WL_SHM_FORMAT_XRGB2101010
:
1934 dri2_dpy
->formats
|= HAS_XRGB2101010
;
1936 case WL_SHM_FORMAT_ARGB8888
:
1937 dri2_dpy
->formats
|= HAS_ARGB8888
;
1939 case WL_SHM_FORMAT_XRGB8888
:
1940 dri2_dpy
->formats
|= HAS_XRGB8888
;
1942 case WL_SHM_FORMAT_RGB565
:
1943 dri2_dpy
->formats
|= HAS_RGB565
;
1948 static const struct wl_shm_listener shm_listener
= {
1949 .format
= shm_handle_format
1953 registry_handle_global_swrast(void *data
, struct wl_registry
*registry
,
1954 uint32_t name
, const char *interface
,
1957 struct dri2_egl_display
*dri2_dpy
= data
;
1959 if (strcmp(interface
, "wl_shm") == 0) {
1961 wl_registry_bind(registry
, name
, &wl_shm_interface
, 1);
1962 wl_shm_add_listener(dri2_dpy
->wl_shm
, &shm_listener
, dri2_dpy
);
1966 static const struct wl_registry_listener registry_listener_swrast
= {
1967 .global
= registry_handle_global_swrast
,
1968 .global_remove
= registry_handle_global_remove
1971 static const struct dri2_egl_display_vtbl dri2_wl_swrast_display_vtbl
= {
1972 .authenticate
= NULL
,
1973 .create_window_surface
= dri2_wl_create_window_surface
,
1974 .create_pixmap_surface
= dri2_wl_create_pixmap_surface
,
1975 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
1976 .destroy_surface
= dri2_wl_destroy_surface
,
1977 .create_image
= dri2_create_image_khr
,
1978 .swap_buffers
= dri2_wl_swrast_swap_buffers
,
1979 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
1980 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
1981 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
1982 .copy_buffers
= dri2_fallback_copy_buffers
,
1983 .query_buffer_age
= dri2_fallback_query_buffer_age
,
1984 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
1985 .get_sync_values
= dri2_fallback_get_sync_values
,
1986 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
1989 static const __DRIswrastLoaderExtension swrast_loader_extension
= {
1990 .base
= { __DRI_SWRAST_LOADER
, 2 },
1992 .getDrawableInfo
= dri2_wl_swrast_get_drawable_info
,
1993 .putImage
= dri2_wl_swrast_put_image
,
1994 .getImage
= dri2_wl_swrast_get_image
,
1995 .putImage2
= dri2_wl_swrast_put_image2
,
1998 static const __DRIextension
*swrast_loader_extensions
[] = {
1999 &swrast_loader_extension
.base
,
2000 &image_lookup_extension
.base
,
2005 dri2_initialize_wayland_swrast(_EGLDriver
*drv
, _EGLDisplay
*disp
)
2007 struct dri2_egl_display
*dri2_dpy
;
2009 loader_set_logger(_eglLog
);
2011 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
2013 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
2016 disp
->DriverData
= (void *) dri2_dpy
;
2017 if (disp
->PlatformDisplay
== NULL
) {
2018 dri2_dpy
->wl_dpy
= wl_display_connect(NULL
);
2019 if (dri2_dpy
->wl_dpy
== NULL
)
2021 dri2_dpy
->own_device
= true;
2023 dri2_dpy
->wl_dpy
= disp
->PlatformDisplay
;
2026 dri2_dpy
->wl_queue
= wl_display_create_queue(dri2_dpy
->wl_dpy
);
2028 dri2_dpy
->wl_dpy_wrapper
= wl_proxy_create_wrapper(dri2_dpy
->wl_dpy
);
2029 if (dri2_dpy
->wl_dpy_wrapper
== NULL
)
2032 wl_proxy_set_queue((struct wl_proxy
*) dri2_dpy
->wl_dpy_wrapper
,
2033 dri2_dpy
->wl_queue
);
2035 if (dri2_dpy
->own_device
)
2036 wl_display_dispatch_pending(dri2_dpy
->wl_dpy
);
2038 dri2_dpy
->wl_registry
= wl_display_get_registry(dri2_dpy
->wl_dpy_wrapper
);
2039 wl_registry_add_listener(dri2_dpy
->wl_registry
,
2040 ®istry_listener_swrast
, dri2_dpy
);
2042 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->wl_shm
== NULL
)
2045 if (roundtrip(dri2_dpy
) < 0 || dri2_dpy
->formats
== 0)
2048 dri2_dpy
->driver_name
= strdup("swrast");
2049 if (!dri2_load_driver_swrast(disp
))
2052 dri2_dpy
->loader_extensions
= swrast_loader_extensions
;
2054 if (!dri2_create_screen(disp
))
2057 if (!dri2_setup_extensions(disp
))
2060 dri2_setup_screen(disp
);
2062 dri2_wl_setup_swap_interval(disp
);
2064 if (!dri2_wl_add_configs_for_visuals(drv
, disp
)) {
2065 _eglError(EGL_NOT_INITIALIZED
, "DRI2: failed to add configs");
2069 /* Fill vtbl last to prevent accidentally calling virtual function during
2072 dri2_dpy
->vtbl
= &dri2_wl_swrast_display_vtbl
;
2077 dri2_display_destroy(disp
);
2082 dri2_initialize_wayland(_EGLDriver
*drv
, _EGLDisplay
*disp
)
2084 EGLBoolean initialized
= EGL_FALSE
;
2086 if (!disp
->Options
.ForceSoftware
)
2087 initialized
= dri2_initialize_wayland_drm(drv
, disp
);
2090 initialized
= dri2_initialize_wayland_swrast(drv
, disp
);
2097 dri2_teardown_wayland(struct dri2_egl_display
*dri2_dpy
)
2099 if (dri2_dpy
->wl_drm
)
2100 wl_drm_destroy(dri2_dpy
->wl_drm
);
2101 if (dri2_dpy
->wl_dmabuf
)
2102 zwp_linux_dmabuf_v1_destroy(dri2_dpy
->wl_dmabuf
);
2103 if (dri2_dpy
->wl_shm
)
2104 wl_shm_destroy(dri2_dpy
->wl_shm
);
2105 if (dri2_dpy
->wl_registry
)
2106 wl_registry_destroy(dri2_dpy
->wl_registry
);
2107 if (dri2_dpy
->wl_queue
)
2108 wl_event_queue_destroy(dri2_dpy
->wl_queue
);
2109 if (dri2_dpy
->wl_dpy_wrapper
)
2110 wl_proxy_wrapper_destroy(dri2_dpy
->wl_dpy_wrapper
);
2111 u_vector_finish(&dri2_dpy
->wl_modifiers
.argb2101010
);
2112 u_vector_finish(&dri2_dpy
->wl_modifiers
.xrgb2101010
);
2113 u_vector_finish(&dri2_dpy
->wl_modifiers
.argb8888
);
2114 u_vector_finish(&dri2_dpy
->wl_modifiers
.xrgb8888
);
2115 u_vector_finish(&dri2_dpy
->wl_modifiers
.rgb565
);
2116 if (dri2_dpy
->own_device
)
2117 wl_display_disconnect(dri2_dpy
->wl_dpy
);