1From 9ae9bc0f952538ee7abd79798f608b1bb433f604 Mon Sep 17 00:00:00 2001 2From: Jeffy Chen <jeffy.chen@rock-chips.com> 3Date: Tue, 1 Sep 2020 08:51:17 +0800 4Subject: [PATCH 27/79] HACK: backend-drm: Consider linear and invalid modifier 5 are the same 6 7That is true with Rockchip BSP drivers and packages. 8 9Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> 10--- 11 clients/simple-dmabuf-egl.c | 8 ++++++-- 12 libweston/backend-drm/drm-gbm.c | 3 ++- 13 libweston/backend-drm/drm-virtual.c | 8 +------- 14 libweston/backend-drm/fb.c | 10 ++++++---- 15 libweston/backend-drm/kms.c | 2 +- 16 libweston/linux-dmabuf.h | 4 ++++ 17 libweston/pixman-renderer.c | 4 ++-- 18 libweston/renderer-gl/gl-renderer.c | 8 ++++---- 19 8 files changed, 26 insertions(+), 21 deletions(-) 20 21diff --git a/clients/simple-dmabuf-egl.c b/clients/simple-dmabuf-egl.c 22index ef0d9de..e984503 100644 23--- a/clients/simple-dmabuf-egl.c 24+++ b/clients/simple-dmabuf-egl.c 25@@ -68,6 +68,9 @@ 26 27 #define MAX_BUFFER_PLANES 4 28 29+#define DRM_MOD_VALID(mod) \ 30+ ((mod) != DRM_FORMAT_MOD_LINEAR && (mod) != DRM_FORMAT_MOD_INVALID) 31+ 32 struct display { 33 struct wl_display *display; 34 struct wl_registry *registry; 35@@ -265,7 +268,8 @@ create_fbo_for_buffer(struct display *display, struct buffer *buffer) 36 attribs[atti++] = (int) buffer->offsets[plane_idx]; \ 37 attribs[atti++] = EGL_DMA_BUF_PLANE ## plane_idx ## _PITCH_EXT; \ 38 attribs[atti++] = (int) buffer->strides[plane_idx]; \ 39- if (display->egl.has_dma_buf_import_modifiers) { \ 40+ if (DRM_MOD_VALID(buffer->modifier) && \ 41+ display->egl.has_dma_buf_import_modifiers) { \ 42 attribs[atti++] = EGL_DMA_BUF_PLANE ## plane_idx ## _MODIFIER_LO_EXT; \ 43 attribs[atti++] = buffer->modifier & 0xFFFFFFFF; \ 44 attribs[atti++] = EGL_DMA_BUF_PLANE ## plane_idx ## _MODIFIER_HI_EXT; \ 45@@ -1008,7 +1012,7 @@ dmabuf_modifiers(void *data, struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf, 46 47 d->format_supported = true; 48 49- if (modifier != DRM_FORMAT_MOD_INVALID) { 50+ if (DRM_MOD_VALID(modifier)) { 51 ++d->modifiers_count; 52 d->modifiers = realloc(d->modifiers, 53 d->modifiers_count * sizeof(*d->modifiers)); 54diff --git a/libweston/backend-drm/drm-gbm.c b/libweston/backend-drm/drm-gbm.c 55index d7bd05f..ecc7a5f 100644 56--- a/libweston/backend-drm/drm-gbm.c 57+++ b/libweston/backend-drm/drm-gbm.c 58@@ -196,7 +196,8 @@ create_gbm_surface(struct gbm_device *gbm, struct drm_output *output) 59 } 60 61 #ifdef HAVE_GBM_MODIFIERS 62- if (!weston_drm_format_has_modifier(fmt, DRM_FORMAT_MOD_INVALID)) { 63+ if (!weston_drm_format_has_modifier(fmt, DRM_FORMAT_MOD_INVALID) && 64+ !weston_drm_format_has_modifier(fmt, DRM_FORMAT_MOD_LINEAR)) { 65 modifiers = weston_drm_format_get_modifiers(fmt, &num_modifiers); 66 output->gbm_surface = 67 gbm_surface_create_with_modifiers(gbm, 68diff --git a/libweston/backend-drm/drm-virtual.c b/libweston/backend-drm/drm-virtual.c 69index 597e71c..20f6809 100644 70--- a/libweston/backend-drm/drm-virtual.c 71+++ b/libweston/backend-drm/drm-virtual.c 72@@ -112,13 +112,7 @@ drm_virtual_plane_create(struct drm_backend *b, struct drm_output *output) 73 if (!fmt) 74 goto err; 75 76- /* If output supports linear modifier, we add it to the plane. 77- * Otherwise we add DRM_FORMAT_MOD_INVALID, as explicit modifiers 78- * are not supported. */ 79- if ((output->gbm_bo_flags & GBM_BO_USE_LINEAR) && b->fb_modifiers) 80- mod = DRM_FORMAT_MOD_LINEAR; 81- else 82- mod = DRM_FORMAT_MOD_INVALID; 83+ mod = DRM_FORMAT_MOD_LINEAR; 84 85 if (weston_drm_format_add_modifier(fmt, mod) < 0) 86 goto err; 87diff --git a/libweston/backend-drm/fb.c b/libweston/backend-drm/fb.c 88index ba0c177..af31a8a 100644 89--- a/libweston/backend-drm/fb.c 90+++ b/libweston/backend-drm/fb.c 91@@ -77,7 +77,7 @@ drm_fb_addfb(struct drm_backend *b, struct drm_fb *fb) 92 93 /* If we have a modifier set, we must only use the WithModifiers 94 * entrypoint; we cannot import it through legacy ioctls. */ 95- if (b->fb_modifiers && fb->modifier != DRM_FORMAT_MOD_INVALID) { 96+ if (b->fb_modifiers && DRM_MOD_VALID(fb->modifier)) { 97 /* KMS demands that if a modifier is set, it must be the same 98 * for all planes. */ 99 for (i = 0; i < ARRAY_LENGTH(mods) && fb->handles[i]; i++) 100@@ -150,7 +150,7 @@ drm_fb_create_dumb(struct drm_backend *b, int width, int height, 101 goto err_fb; 102 103 fb->type = BUFFER_PIXMAN_DUMB; 104- fb->modifier = DRM_FORMAT_MOD_INVALID; 105+ fb->modifier = DRM_FORMAT_MOD_LINEAR; 106 fb->handles[0] = create_arg.handle; 107 fb->strides[0] = create_arg.pitch; 108 fb->num_planes = 1; 109@@ -237,6 +237,7 @@ drm_fb_get_from_dmabuf(struct linux_dmabuf_buffer *dmabuf, 110 .modifier = dmabuf->attributes.modifier[0], 111 }; 112 113+#if 0 114 /* We should not import to KMS a buffer that has been allocated using no 115 * modifiers. Usually drivers use linear layouts to allocate with no 116 * modifiers, but this is not a rule. The driver could use, for 117@@ -250,6 +251,7 @@ drm_fb_get_from_dmabuf(struct linux_dmabuf_buffer *dmabuf, 118 FAILURE_REASONS_DMABUF_MODIFIER_INVALID; 119 return NULL; 120 } 121+#endif 122 123 /* XXX: TODO: 124 * 125@@ -375,7 +377,7 @@ drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend, 126 fb->num_planes = 1; 127 fb->strides[0] = gbm_bo_get_stride(bo); 128 fb->handles[0] = gbm_bo_get_handle(bo).u32; 129- fb->modifier = DRM_FORMAT_MOD_INVALID; 130+ fb->modifier = DRM_FORMAT_MOD_LINEAR; 131 #endif 132 133 if (!fb->format) { 134@@ -482,7 +484,7 @@ drm_fb_compatible_with_plane(struct drm_fb *fb, struct drm_plane *plane) 135 * wl_drm is being used for scanout. Mesa is the only user we 136 * care in this case (even though recent versions are also using 137 * dmabufs), and it should know better what works or not. */ 138- if (fb->modifier == DRM_FORMAT_MOD_INVALID) 139+ if (!DRM_MOD_VALID(fb->modifier)) 140 return true; 141 142 if (weston_drm_format_has_modifier(fmt, fb->modifier)) 143diff --git a/libweston/backend-drm/kms.c b/libweston/backend-drm/kms.c 144index 1fcbdeb..4b5ba42 100644 145--- a/libweston/backend-drm/kms.c 146+++ b/libweston/backend-drm/kms.c 147@@ -542,7 +542,7 @@ fallback: 148 kplane->formats[i]); 149 if (!fmt) 150 return -1; 151- ret = weston_drm_format_add_modifier(fmt, DRM_FORMAT_MOD_INVALID); 152+ ret = weston_drm_format_add_modifier(fmt, DRM_FORMAT_MOD_LINEAR); 153 if (ret < 0) 154 return -1; 155 } 156diff --git a/libweston/linux-dmabuf.h b/libweston/linux-dmabuf.h 157index 7cae93c..cfbdc28 100644 158--- a/libweston/linux-dmabuf.h 159+++ b/libweston/linux-dmabuf.h 160@@ -31,6 +31,10 @@ 161 162 #define MAX_DMABUF_PLANES 4 163 164+/* modifier is not linear or invalid */ 165+#define DRM_MOD_VALID(mod) \ 166+ ((mod) != DRM_FORMAT_MOD_LINEAR && (mod) != DRM_FORMAT_MOD_INVALID) 167+ 168 struct linux_dmabuf_buffer; 169 typedef void (*dmabuf_user_data_destroy_func)( 170 struct linux_dmabuf_buffer *buffer); 171diff --git a/libweston/pixman-renderer.c b/libweston/pixman-renderer.c 172index ece4d91..b245fd6 100644 173--- a/libweston/pixman-renderer.c 174+++ b/libweston/pixman-renderer.c 175@@ -701,7 +701,7 @@ pixman_renderer_prepare_dmabuf(struct linux_dmabuf_buffer *dmabuf) 176 total_size = lseek(attributes->fd[0], 0, SEEK_END); 177 178 for (i = 0; i < attributes->n_planes; i++) { 179- if (attributes->modifier[i] != DRM_FORMAT_MOD_INVALID) 180+ if (DRM_MOD_VALID(attributes->modifier[i])) 181 return false; 182 } 183 184@@ -1197,7 +1197,7 @@ populate_supported_formats(struct weston_compositor *ec, 185 186 /* Always add DRM_FORMAT_MOD_INVALID, as EGL implementations 187 * support implicit modifiers. */ 188- ret = weston_drm_format_add_modifier(fmt, DRM_FORMAT_MOD_INVALID); 189+ ret = weston_drm_format_add_modifier(fmt, DRM_FORMAT_MOD_LINEAR); 190 if (ret < 0) 191 goto out; 192 } 193diff --git a/libweston/renderer-gl/gl-renderer.c b/libweston/renderer-gl/gl-renderer.c 194index 3c60f85..f891478 100644 195--- a/libweston/renderer-gl/gl-renderer.c 196+++ b/libweston/renderer-gl/gl-renderer.c 197@@ -2359,7 +2359,7 @@ import_simple_dmabuf(struct gl_renderer *gr, 198 attribs[atti++] = EGL_YUV_NARROW_RANGE_EXT; 199 } 200 201- if (attributes->modifier[0] != DRM_FORMAT_MOD_INVALID) { 202+ if (DRM_MOD_VALID(attributes->modifier[0])) { 203 if (!gr->has_dmabuf_import_modifiers) 204 return NULL; 205 has_modifier = true; 206@@ -2871,7 +2871,7 @@ gl_renderer_import_dmabuf(struct weston_compositor *ec, 207 208 for (i = 0; i < dmabuf->attributes.n_planes; i++) { 209 /* return if EGL doesn't support import modifiers */ 210- if (dmabuf->attributes.modifier[i] != DRM_FORMAT_MOD_INVALID) 211+ if (DRM_MOD_VALID(dmabuf->attributes.modifier[i])) 212 if (!gr->has_dmabuf_import_modifiers) 213 return false; 214 215@@ -3016,7 +3016,7 @@ populate_supported_formats(struct weston_compositor *ec, 216 217 /* Always add DRM_FORMAT_MOD_INVALID, as EGL implementations 218 * support implicit modifiers. */ 219- ret = weston_drm_format_add_modifier(fmt, DRM_FORMAT_MOD_INVALID); 220+ ret = weston_drm_format_add_modifier(fmt, DRM_FORMAT_MOD_LINEAR); 221 if (ret < 0) 222 goto out; 223 224@@ -3027,7 +3027,7 @@ populate_supported_formats(struct weston_compositor *ec, 225 226 for (j = 0; j < num_modifiers; j++) { 227 /* Skip MOD_INVALID, as it has already been added. */ 228- if (modifiers[j] == DRM_FORMAT_MOD_INVALID) 229+ if (!DRM_MOD_VALID(modifiers[j])) 230 continue; 231 ret = weston_drm_format_add_modifier(fmt, modifiers[j]); 232 if (ret < 0) { 233-- 2342.20.1 235 236