1From b727c545a985640aecaf07c3e3e5100e57914bd2 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 30/95] 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         | 5 +++--
12 clients/simple-dmabuf-v4l.c         | 2 +-
13 libweston/backend-drm/drm-gbm.c     | 3 ++-
14 libweston/backend-drm/fb.c          | 6 ++++--
15 libweston/linux-dmabuf.c            | 3 +--
16 libweston/pixel-formats.c           | 2 +-
17 libweston/pixman-renderer.c         | 3 +--
18 libweston/renderer-gl/gl-renderer.c | 6 +++---
19 shared/weston-drm-fourcc.h          | 4 ++++
20 9 files changed, 20 insertions(+), 14 deletions(-)
21
22diff --git a/clients/simple-dmabuf-egl.c b/clients/simple-dmabuf-egl.c
23index 16d47ba..a03058b 100644
24--- a/clients/simple-dmabuf-egl.c
25+++ b/clients/simple-dmabuf-egl.c
26@@ -265,7 +265,8 @@ create_fbo_for_buffer(struct display *display, struct buffer *buffer)
27 	attribs[atti++] = (int) buffer->offsets[plane_idx]; \
28 	attribs[atti++] = EGL_DMA_BUF_PLANE ## plane_idx ## _PITCH_EXT; \
29 	attribs[atti++] = (int) buffer->strides[plane_idx]; \
30-	if (display->egl.has_dma_buf_import_modifiers) { \
31+	if (DRM_MOD_VALID(buffer->modifier) && \
32+	    display->egl.has_dma_buf_import_modifiers) { \
33 		attribs[atti++] = EGL_DMA_BUF_PLANE ## plane_idx ## _MODIFIER_LO_EXT; \
34 		attribs[atti++] = buffer->modifier & 0xFFFFFFFF; \
35 		attribs[atti++] = EGL_DMA_BUF_PLANE ## plane_idx ## _MODIFIER_HI_EXT; \
36@@ -1018,7 +1019,7 @@ dmabuf_modifiers(void *data, struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf,
37
38 	d->format_supported = true;
39
40-	if (modifier != DRM_FORMAT_MOD_INVALID) {
41+	if (DRM_MOD_VALID(modifier)) {
42 		++d->modifiers_count;
43 		d->modifiers = realloc(d->modifiers,
44 				       d->modifiers_count * sizeof(*d->modifiers));
45diff --git a/clients/simple-dmabuf-v4l.c b/clients/simple-dmabuf-v4l.c
46index a19570f..5ac340e 100644
47--- a/clients/simple-dmabuf-v4l.c
48+++ b/clients/simple-dmabuf-v4l.c
49@@ -732,7 +732,7 @@ dmabuf_modifier(void *data, struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf,
50 	struct display *d = data;
51 	uint64_t modifier = ((uint64_t) modifier_hi << 32 ) | modifier_lo;
52
53-	if (format == d->drm_format && modifier == DRM_FORMAT_MOD_LINEAR)
54+	if (format == d->drm_format && !DRM_MOD_VALID(modifier))
55 		d->requested_format_found = true;
56 }
57
58diff --git a/libweston/backend-drm/drm-gbm.c b/libweston/backend-drm/drm-gbm.c
59index d10cc40..f998178 100644
60--- a/libweston/backend-drm/drm-gbm.c
61+++ b/libweston/backend-drm/drm-gbm.c
62@@ -206,7 +206,8 @@ create_gbm_surface(struct gbm_device *gbm, struct drm_output *output)
63 	}
64
65 #ifdef HAVE_GBM_MODIFIERS
66-	if (!weston_drm_format_has_modifier(fmt, DRM_FORMAT_MOD_INVALID)) {
67+	if (!weston_drm_format_has_modifier(fmt, DRM_FORMAT_MOD_INVALID) &&
68+	    !weston_drm_format_has_modifier(fmt, DRM_FORMAT_MOD_LINEAR)) {
69 		modifiers = weston_drm_format_get_modifiers(fmt, &num_modifiers);
70 		output->gbm_surface =
71 			gbm_surface_create_with_modifiers(gbm,
72diff --git a/libweston/backend-drm/fb.c b/libweston/backend-drm/fb.c
73index 05b4988..4cb2cbe 100644
74--- a/libweston/backend-drm/fb.c
75+++ b/libweston/backend-drm/fb.c
76@@ -77,7 +77,7 @@ drm_fb_addfb(struct drm_device *device, struct drm_fb *fb)
77
78 	/* If we have a modifier set, we must only use the WithModifiers
79 	 * entrypoint; we cannot import it through legacy ioctls. */
80-	if (device->fb_modifiers && fb->modifier != DRM_FORMAT_MOD_INVALID) {
81+	if (device->fb_modifiers && DRM_MOD_VALID(fb->modifier)) {
82 		/* KMS demands that if a modifier is set, it must be the same
83 		 * for all planes. */
84 		for (i = 0; i < ARRAY_LENGTH(mods) && fb->handles[i]; i++)
85@@ -238,6 +238,7 @@ drm_fb_get_from_dmabuf(struct linux_dmabuf_buffer *dmabuf,
86 		.modifier = dmabuf->attributes.modifier[0],
87 	};
88
89+#if 0
90 	/* We should not import to KMS a buffer that has been allocated using no
91 	 * modifiers. Usually drivers use linear layouts to allocate with no
92 	 * modifiers, but this is not a rule. The driver could use, for
93@@ -251,6 +252,7 @@ drm_fb_get_from_dmabuf(struct linux_dmabuf_buffer *dmabuf,
94 				FAILURE_REASONS_DMABUF_MODIFIER_INVALID;
95 		return NULL;
96 	}
97+#endif
98
99 	/* XXX: TODO:
100 	 *
101@@ -489,7 +491,7 @@ drm_fb_compatible_with_plane(struct drm_fb *fb, struct drm_plane *plane)
102 		 * wl_drm is being used for scanout. Mesa is the only user we
103 		 * care in this case (even though recent versions are also using
104 		 * dmabufs), and it should know better what works or not. */
105-		if (fb->modifier == DRM_FORMAT_MOD_INVALID)
106+		if (!DRM_MOD_VALID(fb->modifier))
107 			return true;
108
109 		if (weston_drm_format_has_modifier(fmt, fb->modifier))
110diff --git a/libweston/linux-dmabuf.c b/libweston/linux-dmabuf.c
111index b73508e..a4dee8b 100644
112--- a/libweston/linux-dmabuf.c
113+++ b/libweston/linux-dmabuf.c
114@@ -1057,8 +1057,7 @@ bind_linux_dmabuf(struct wl_client *client,
115 								  fmt->format,
116 								  modifier_hi,
117 								  modifier_lo);
118-			} else if (modifiers[i] == DRM_FORMAT_MOD_LINEAR ||
119-				   modifiers[i] == DRM_FORMAT_MOD_INVALID) {
120+			} else if (!DRM_MOD_VALID(modifiers[i])) {
121 				zwp_linux_dmabuf_v1_send_format(resource,
122 								fmt->format);
123 			}
124diff --git a/libweston/pixel-formats.c b/libweston/pixel-formats.c
125index 7590171..10b3ed9 100644
126--- a/libweston/pixel-formats.c
127+++ b/libweston/pixel-formats.c
128@@ -755,7 +755,7 @@ pixel_format_get_modifier(uint64_t modifier)
129 		return mod_str;
130 	}
131
132-	if (modifier == DRM_FORMAT_MOD_LINEAR) {
133+	if (!DRM_MOD_VALID(modifier)) {
134 		str_printf(&mod_str, "%s (0x%llx)", modifier_name,
135 			   (unsigned long long) modifier);
136 		free(modifier_name);
137diff --git a/libweston/pixman-renderer.c b/libweston/pixman-renderer.c
138index 7339541..c8b7b88 100644
139--- a/libweston/pixman-renderer.c
140+++ b/libweston/pixman-renderer.c
141@@ -734,8 +734,7 @@ pixman_renderer_prepare_dmabuf(struct linux_dmabuf_buffer *dmabuf)
142 	total_size = lseek(attributes->fd[0], 0, SEEK_END);
143
144 	for (i = 0; i < attributes->n_planes; i++) {
145-		if (attributes->modifier[i] != DRM_FORMAT_MOD_INVALID &&
146-		    attributes->modifier[i] != DRM_FORMAT_MOD_LINEAR)
147+		if (DRM_MOD_VALID(attributes->modifier[i]))
148 			return false;
149 	}
150
151diff --git a/libweston/renderer-gl/gl-renderer.c b/libweston/renderer-gl/gl-renderer.c
152index bbd1cd4..4eedb94 100644
153--- a/libweston/renderer-gl/gl-renderer.c
154+++ b/libweston/renderer-gl/gl-renderer.c
155@@ -2397,7 +2397,7 @@ import_simple_dmabuf(struct gl_renderer *gr,
156 		attribs[atti++] = EGL_YUV_NARROW_RANGE_EXT;
157 	}
158
159-	if (attributes->modifier[0] != DRM_FORMAT_MOD_INVALID) {
160+	if (DRM_MOD_VALID(attributes->modifier[0])) {
161 		if (!gr->has_dmabuf_import_modifiers)
162 			return NULL;
163 		has_modifier = true;
164@@ -2806,7 +2806,7 @@ gl_renderer_import_dmabuf(struct weston_compositor *ec,
165
166 	for (i = 0; i < dmabuf->attributes.n_planes; i++) {
167 		/* return if EGL doesn't support import modifiers */
168-		if (dmabuf->attributes.modifier[i] != DRM_FORMAT_MOD_INVALID)
169+		if (DRM_MOD_VALID(dmabuf->attributes.modifier[i]))
170 			if (!gr->has_dmabuf_import_modifiers)
171 				return false;
172
173@@ -2970,7 +2970,7 @@ populate_supported_formats(struct weston_compositor *ec,
174
175 		for (j = 0; j < num_modifiers; j++) {
176 			/* Skip MOD_INVALID, as it has already been added. */
177-			if (modifiers[j] == DRM_FORMAT_MOD_INVALID)
178+			if (!DRM_MOD_VALID(modifiers[j]))
179 				continue;
180 			ret = weston_drm_format_add_modifier(fmt, modifiers[j]);
181 			if (ret < 0) {
182diff --git a/shared/weston-drm-fourcc.h b/shared/weston-drm-fourcc.h
183index 0a013f7..31d8039 100644
184--- a/shared/weston-drm-fourcc.h
185+++ b/shared/weston-drm-fourcc.h
186@@ -30,6 +30,10 @@
187
188 #include <drm_fourcc.h>
189
190+/* modifier is not linear or invalid */
191+#define DRM_MOD_VALID(mod) \
192+	((mod) != DRM_FORMAT_MOD_LINEAR && (mod) != DRM_FORMAT_MOD_INVALID)
193+
194 /* The kernel header drm_fourcc.h defines the DRM formats below.  We duplicate
195  * some of the definitions here so that building Weston won't require
196  * bleeding-edge kernel headers.
197--
1982.20.1
199
200