Andrew Geissler | 615f2f1 | 2022-07-15 14:00:58 -0500 | [diff] [blame^] | 1 | From 7796c2c56c960ac55e49246f0349ac52539ada55 Mon Sep 17 00:00:00 2001 |
| 2 | From: Leandro Ribeiro <leandro.ribeiro@collabora.com> |
| 3 | Date: Sun, 10 Apr 2022 22:54:36 -0300 |
| 4 | Subject: [PATCH] Revert "egl/wayland: deprecate drm_handle_format() and |
| 5 | drm_handle_capabilities()" |
| 6 | |
| 7 | Commit af1ee8e010441f8f2ed8c77065b159652a4ac9fe dropped support to |
| 8 | wl_drm, as we thought that most compositors from active projects were |
| 9 | already supporting zwp_linux_dmabuf_v1. |
| 10 | |
| 11 | But that's not true, so revert this commit in order to give these |
| 12 | projects a longer transition period. |
| 13 | |
| 14 | Note that we didn't add back the support to GEM name API, and that was |
| 15 | on purpose. |
| 16 | |
| 17 | Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com> |
| 18 | Reviewed-by: Simon Ser <contact@emersion.fr> |
| 19 | Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15822> |
| 20 | |
| 21 | Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com> |
| 22 | Upstream-Status: Backport [https://gitlab.freedesktop.org/mesa/mesa/-/commit/c60fea8c228ae3f32e20d6b65c473d9f04871d20] |
| 23 | --- |
| 24 | src/egl/drivers/dri2/egl_dri2.h | 1 + |
| 25 | src/egl/drivers/dri2/platform_wayland.c | 59 +++++++++++++++++++------ |
| 26 | 2 files changed, 47 insertions(+), 13 deletions(-) |
| 27 | |
| 28 | diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h |
| 29 | index c466ff83c53..eecb32a53fd 100644 |
| 30 | --- a/src/egl/drivers/dri2/egl_dri2.h |
| 31 | +++ b/src/egl/drivers/dri2/egl_dri2.h |
| 32 | @@ -283,6 +283,7 @@ struct dri2_egl_display |
| 33 | struct zwp_linux_dmabuf_feedback_v1 *wl_dmabuf_feedback; |
| 34 | struct dmabuf_feedback_format_table format_table; |
| 35 | bool authenticated; |
| 36 | + uint32_t capabilities; |
| 37 | char *device_name; |
| 38 | #endif |
| 39 | |
| 40 | diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c |
| 41 | index 5ff83cce08a..843434376a7 100644 |
| 42 | --- a/src/egl/drivers/dri2/platform_wayland.c |
| 43 | +++ b/src/egl/drivers/dri2/platform_wayland.c |
| 44 | @@ -1343,7 +1343,7 @@ create_wl_buffer(struct dri2_egl_display *dri2_dpy, |
| 45 | struct dri2_egl_surface *dri2_surf, |
| 46 | __DRIimage *image) |
| 47 | { |
| 48 | - struct wl_buffer *ret; |
| 49 | + struct wl_buffer *ret = NULL; |
| 50 | EGLBoolean query; |
| 51 | int width, height, fourcc, num_planes; |
| 52 | uint64_t modifier = DRM_FORMAT_MOD_INVALID; |
| 53 | @@ -1447,11 +1447,28 @@ create_wl_buffer(struct dri2_egl_display *dri2_dpy, |
| 54 | ret = zwp_linux_buffer_params_v1_create_immed(params, width, height, |
| 55 | fourcc, 0); |
| 56 | zwp_linux_buffer_params_v1_destroy(params); |
| 57 | + } else { |
| 58 | + struct wl_drm *wl_drm = |
| 59 | + dri2_surf ? dri2_surf->wl_drm_wrapper : dri2_dpy->wl_drm; |
| 60 | + int fd = -1, stride; |
| 61 | + |
| 62 | + if (num_planes > 1) |
| 63 | + return NULL; |
| 64 | + |
| 65 | + query = dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_FD, &fd); |
| 66 | + query &= dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_STRIDE, &stride); |
| 67 | + if (!query) { |
| 68 | + if (fd >= 0) |
| 69 | + close(fd); |
| 70 | + return NULL; |
| 71 | + } |
| 72 | |
| 73 | - return ret; |
| 74 | + ret = wl_drm_create_prime_buffer(wl_drm, fd, width, height, fourcc, 0, |
| 75 | + stride, 0, 0, 0, 0); |
| 76 | + close(fd); |
| 77 | } |
| 78 | |
| 79 | - return NULL; |
| 80 | + return ret; |
| 81 | } |
| 82 | |
| 83 | static EGLBoolean |
| 84 | @@ -1698,16 +1715,21 @@ drm_handle_device(void *data, struct wl_drm *drm, const char *device) |
| 85 | static void |
| 86 | drm_handle_format(void *data, struct wl_drm *drm, uint32_t format) |
| 87 | { |
| 88 | - /* deprecated, as compositors already support the dma-buf protocol extension |
| 89 | - * and so we can rely on dmabuf_handle_modifier() to receive formats and |
| 90 | - * modifiers */ |
| 91 | + struct dri2_egl_display *dri2_dpy = data; |
| 92 | + int visual_idx = dri2_wl_visual_idx_from_fourcc(format); |
| 93 | + |
| 94 | + if (visual_idx == -1) |
| 95 | + return; |
| 96 | + |
| 97 | + BITSET_SET(dri2_dpy->formats.formats_bitmap, visual_idx); |
| 98 | } |
| 99 | |
| 100 | static void |
| 101 | drm_handle_capabilities(void *data, struct wl_drm *drm, uint32_t value) |
| 102 | { |
| 103 | - /* deprecated, as compositors already support the dma-buf protocol extension |
| 104 | - * and so we can rely on it to create wl_buffer's */ |
| 105 | + struct dri2_egl_display *dri2_dpy = data; |
| 106 | + |
| 107 | + dri2_dpy->capabilities = value; |
| 108 | } |
| 109 | |
| 110 | static void |
| 111 | @@ -2075,13 +2097,12 @@ dri2_initialize_wayland_drm(_EGLDisplay *disp) |
| 112 | wl_registry_add_listener(dri2_dpy->wl_registry, |
| 113 | ®istry_listener_drm, dri2_dpy); |
| 114 | |
| 115 | - /* The compositor must expose the dma-buf interface. */ |
| 116 | - if (roundtrip(dri2_dpy) < 0 || dri2_dpy->wl_dmabuf == NULL) |
| 117 | + if (roundtrip(dri2_dpy) < 0) |
| 118 | goto cleanup; |
| 119 | |
| 120 | /* Get default dma-buf feedback */ |
| 121 | - if (zwp_linux_dmabuf_v1_get_version(dri2_dpy->wl_dmabuf) >= |
| 122 | - ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK_SINCE_VERSION) { |
| 123 | + if (dri2_dpy->wl_dmabuf && zwp_linux_dmabuf_v1_get_version(dri2_dpy->wl_dmabuf) >= |
| 124 | + ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK_SINCE_VERSION) { |
| 125 | dmabuf_feedback_format_table_init(&dri2_dpy->format_table); |
| 126 | dri2_dpy->wl_dmabuf_feedback = |
| 127 | zwp_linux_dmabuf_v1_get_default_feedback(dri2_dpy->wl_dmabuf); |
| 128 | @@ -2089,7 +2110,6 @@ dri2_initialize_wayland_drm(_EGLDisplay *disp) |
| 129 | &dmabuf_feedback_listener, dri2_dpy); |
| 130 | } |
| 131 | |
| 132 | - /* Receive events from the interfaces */ |
| 133 | if (roundtrip(dri2_dpy) < 0) |
| 134 | goto cleanup; |
| 135 | |
| 136 | @@ -2176,6 +2196,19 @@ dri2_initialize_wayland_drm(_EGLDisplay *disp) |
| 137 | |
| 138 | dri2_wl_setup_swap_interval(disp); |
| 139 | |
| 140 | + if (dri2_dpy->wl_drm) { |
| 141 | + /* To use Prime, we must have _DRI_IMAGE v7 at least. createImageFromFds |
| 142 | + * support indicates that Prime export/import is supported by the driver. |
| 143 | + * We deprecated the support to GEM names API, so we bail out if the |
| 144 | + * driver does not suport Prime. */ |
| 145 | + if (!(dri2_dpy->capabilities & WL_DRM_CAPABILITY_PRIME) || |
| 146 | + (dri2_dpy->image->base.version < 7) || |
| 147 | + (dri2_dpy->image->createImageFromFds == NULL)) { |
| 148 | + _eglLog(_EGL_WARNING, "wayland-egl: display does not support prime"); |
| 149 | + goto cleanup; |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | if (dri2_dpy->is_different_gpu && |
| 154 | (dri2_dpy->image->base.version < 9 || |
| 155 | dri2_dpy->image->blitImage == NULL)) { |
| 156 | -- |
| 157 | 2.35.1 |
| 158 | |