linuxOS_AP06/buildroot/package/weston/0035-HACK-backend-drm-Consider-linear-and-invalid-modifie.patch
2025-06-03 12:28:32 +08:00

200 lines
7.8 KiB
Diff

From 14a2985b3f6a937e5f6108034c697a2add745fd8 Mon Sep 17 00:00:00 2001
From: Jeffy Chen <jeffy.chen@rock-chips.com>
Date: Tue, 1 Sep 2020 08:51:17 +0800
Subject: [PATCH 35/95] HACK: backend-drm: Consider linear and invalid modifier
are the same
That is true with Rockchip BSP drivers and packages.
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
clients/simple-dmabuf-egl.c | 5 +++--
clients/simple-dmabuf-v4l.c | 2 +-
libweston/backend-drm/drm-gbm.c | 3 ++-
libweston/backend-drm/fb.c | 6 ++++--
libweston/linux-dmabuf.c | 3 +--
libweston/pixel-formats.c | 2 +-
libweston/pixman-renderer.c | 3 +--
libweston/renderer-gl/gl-renderer.c | 6 +++---
shared/weston-drm-fourcc.h | 4 ++++
9 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/clients/simple-dmabuf-egl.c b/clients/simple-dmabuf-egl.c
index 9989497..8a2d6b0 100644
--- a/clients/simple-dmabuf-egl.c
+++ b/clients/simple-dmabuf-egl.c
@@ -265,7 +265,8 @@ create_fbo_for_buffer(struct display *display, struct buffer *buffer)
attribs[atti++] = (int) buffer->offsets[plane_idx]; \
attribs[atti++] = EGL_DMA_BUF_PLANE ## plane_idx ## _PITCH_EXT; \
attribs[atti++] = (int) buffer->strides[plane_idx]; \
- if (display->egl.has_dma_buf_import_modifiers) { \
+ if (DRM_MOD_VALID(buffer->modifier) && \
+ display->egl.has_dma_buf_import_modifiers) { \
attribs[atti++] = EGL_DMA_BUF_PLANE ## plane_idx ## _MODIFIER_LO_EXT; \
attribs[atti++] = buffer->modifier & 0xFFFFFFFF; \
attribs[atti++] = EGL_DMA_BUF_PLANE ## plane_idx ## _MODIFIER_HI_EXT; \
@@ -1023,7 +1024,7 @@ dmabuf_modifiers(void *data, struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf,
d->format_supported = true;
- if (modifier != DRM_FORMAT_MOD_INVALID) {
+ if (DRM_MOD_VALID(modifier)) {
++d->modifiers_count;
d->modifiers = realloc(d->modifiers,
d->modifiers_count * sizeof(*d->modifiers));
diff --git a/clients/simple-dmabuf-v4l.c b/clients/simple-dmabuf-v4l.c
index 8ed3a0b..7a4aa9c 100644
--- a/clients/simple-dmabuf-v4l.c
+++ b/clients/simple-dmabuf-v4l.c
@@ -912,7 +912,7 @@ dmabuf_modifier(void *data, struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf,
struct display *d = data;
uint64_t modifier = u64_from_u32s(modifier_hi, modifier_lo);
- if (format == d->drm_format && modifier == DRM_FORMAT_MOD_LINEAR)
+ if (format == d->drm_format && !DRM_MOD_VALID(modifier))
d->requested_format_found = true;
}
diff --git a/libweston/backend-drm/drm-gbm.c b/libweston/backend-drm/drm-gbm.c
index 98e0cae..70924cf 100644
--- a/libweston/backend-drm/drm-gbm.c
+++ b/libweston/backend-drm/drm-gbm.c
@@ -197,7 +197,8 @@ create_gbm_surface(struct gbm_device *gbm, struct drm_output *output)
return;
}
- if (!weston_drm_format_has_modifier(fmt, DRM_FORMAT_MOD_INVALID)) {
+ if (!weston_drm_format_has_modifier(fmt, DRM_FORMAT_MOD_INVALID) &&
+ !weston_drm_format_has_modifier(fmt, DRM_FORMAT_MOD_LINEAR)) {
modifiers = weston_drm_format_get_modifiers(fmt, &num_modifiers);
output->gbm_surface =
gbm_surface_create_with_modifiers(gbm,
diff --git a/libweston/backend-drm/fb.c b/libweston/backend-drm/fb.c
index 05fba0c..769a6bb 100644
--- a/libweston/backend-drm/fb.c
+++ b/libweston/backend-drm/fb.c
@@ -219,7 +219,7 @@ drm_fb_addfb(struct drm_device *device, struct drm_fb *fb)
/* If we have a modifier set, we must only use the WithModifiers
* entrypoint; we cannot import it through legacy ioctls. */
- if (device->fb_modifiers && fb->modifier != DRM_FORMAT_MOD_INVALID) {
+ if (device->fb_modifiers && DRM_MOD_VALID(fb->modifier)) {
/* KMS demands that if a modifier is set, it must be the same
* for all planes. */
for (i = 0; i < ARRAY_LENGTH(mods) && fb->handles[i]; i++)
@@ -387,6 +387,7 @@ drm_fb_get_from_dmabuf(struct linux_dmabuf_buffer *dmabuf,
.modifier = dmabuf->attributes.modifier,
};
+#if 0
/* We should not import to KMS a buffer that has been allocated using no
* modifiers. Usually drivers use linear layouts to allocate with no
* modifiers, but this is not a rule. The driver could use, for
@@ -400,6 +401,7 @@ drm_fb_get_from_dmabuf(struct linux_dmabuf_buffer *dmabuf,
FAILURE_REASONS_DMABUF_MODIFIER_INVALID;
return NULL;
}
+#endif
/* XXX: TODO:
*
@@ -631,7 +633,7 @@ drm_fb_compatible_with_plane(struct drm_fb *fb, struct drm_plane *plane,
* wl_drm is being used for scanout. Mesa is the only user we
* care in this case (even though recent versions are also using
* dmabufs), and it should know better what works or not. */
- if (fb->modifier == DRM_FORMAT_MOD_INVALID)
+ if (!DRM_MOD_VALID(fb->modifier))
return true;
if (weston_drm_format_has_modifier(fmt, fb->modifier))
diff --git a/libweston/linux-dmabuf.c b/libweston/linux-dmabuf.c
index d37121d..7ce8a88 100644
--- a/libweston/linux-dmabuf.c
+++ b/libweston/linux-dmabuf.c
@@ -1071,8 +1071,7 @@ bind_linux_dmabuf(struct wl_client *client,
fmt->format,
modifier_hi,
modifier_lo);
- } else if (modifiers[i] == DRM_FORMAT_MOD_LINEAR ||
- modifiers[i] == DRM_FORMAT_MOD_INVALID) {
+ } else if (!DRM_MOD_VALID(modifiers[i])) {
zwp_linux_dmabuf_v1_send_format(resource,
fmt->format);
}
diff --git a/libweston/pixel-formats.c b/libweston/pixel-formats.c
index 3e8be0a..b350638 100644
--- a/libweston/pixel-formats.c
+++ b/libweston/pixel-formats.c
@@ -801,7 +801,7 @@ pixel_format_get_modifier(uint64_t modifier)
return mod_str;
}
- if (modifier == DRM_FORMAT_MOD_LINEAR) {
+ if (!DRM_MOD_VALID(modifier)) {
str_printf(&mod_str, "%s (0x%llx)", modifier_name,
(unsigned long long) modifier);
free(modifier_name);
diff --git a/libweston/pixman-renderer.c b/libweston/pixman-renderer.c
index 914fbb6..f654819 100644
--- a/libweston/pixman-renderer.c
+++ b/libweston/pixman-renderer.c
@@ -848,8 +848,7 @@ pixman_renderer_prepare_dmabuf(struct linux_dmabuf_buffer *dmabuf)
total_size = lseek(attributes->fd[0], 0, SEEK_END);
- if (attributes->modifier != DRM_FORMAT_MOD_INVALID &&
- attributes->modifier != DRM_FORMAT_MOD_LINEAR)
+ if (DRM_MOD_VALID(attributes->modifier))
return false;
/* reject all flags we do not recognize or handle */
diff --git a/libweston/renderer-gl/gl-renderer.c b/libweston/renderer-gl/gl-renderer.c
index a27aa84..49b3f7a 100644
--- a/libweston/renderer-gl/gl-renderer.c
+++ b/libweston/renderer-gl/gl-renderer.c
@@ -2991,7 +2991,7 @@ import_simple_dmabuf(struct gl_renderer *gr,
attribs[atti++] = EGL_IMAGE_PRESERVED_KHR;
attribs[atti++] = EGL_TRUE;
- if (attributes->modifier != DRM_FORMAT_MOD_INVALID) {
+ if (DRM_MOD_VALID(attributes->modifier)) {
if (!gr->has_dmabuf_import_modifiers)
return NULL;
has_modifier = true;
@@ -3318,7 +3318,7 @@ gl_renderer_import_dmabuf(struct weston_compositor *ec,
assert(gr->has_dmabuf_import);
/* return if EGL doesn't support import modifiers */
- if (dmabuf->attributes.modifier != DRM_FORMAT_MOD_INVALID)
+ if (DRM_MOD_VALID(dmabuf->attributes.modifier))
if (!gr->has_dmabuf_import_modifiers)
return false;
@@ -3455,7 +3455,7 @@ populate_supported_formats(struct weston_compositor *ec,
for (j = 0; j < num_modifiers; j++) {
/* Skip MOD_INVALID, as it has already been added. */
- if (modifiers[j] == DRM_FORMAT_MOD_INVALID)
+ if (!DRM_MOD_VALID(modifiers[j]))
continue;
ret = weston_drm_format_add_modifier(fmt, modifiers[j]);
if (ret < 0) {
diff --git a/shared/weston-drm-fourcc.h b/shared/weston-drm-fourcc.h
index 0a013f7..31d8039 100644
--- a/shared/weston-drm-fourcc.h
+++ b/shared/weston-drm-fourcc.h
@@ -30,6 +30,10 @@
#include <drm_fourcc.h>
+/* modifier is not linear or invalid */
+#define DRM_MOD_VALID(mod) \
+ ((mod) != DRM_FORMAT_MOD_LINEAR && (mod) != DRM_FORMAT_MOD_INVALID)
+
/* The kernel header drm_fourcc.h defines the DRM formats below. We duplicate
* some of the definitions here so that building Weston won't require
* bleeding-edge kernel headers.
--
2.20.1