[PATCH v2 2/2] gl-renderer: return conservative format list if dmabuf import modifiers unsupported

Philipp Zabel p.zabel at pengutronix.de
Wed Jan 17 16:54:32 UTC 2018


If the EGL_EXT_image_dma_buf_import_modifiers extension is not
supported, let gl_renderer_query_dmabuf_formats return a hardcoded
fallback list. That list contains ARGB8888, XRGB8888, and if the
GL_EXT_texture_rg extension is supported, YUYV, NV12, YUV420, and
YUV444.

Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
Reviewed-by: Emil Velikov <emil.velikov at collabora.com>
---
v2: change fallback_formats[] array to static const
---
 libweston/gl-renderer.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/libweston/gl-renderer.c b/libweston/gl-renderer.c
index abf556f0..7cd76cce 100644
--- a/libweston/gl-renderer.c
+++ b/libweston/gl-renderer.c
@@ -2088,14 +2088,23 @@ gl_renderer_query_dmabuf_formats(struct weston_compositor *wc,
 				int **formats, int *num_formats)
 {
 	struct gl_renderer *gr = get_renderer(wc);
+	static const int fallback_formats[] = {
+		DRM_FORMAT_ARGB8888,
+		DRM_FORMAT_XRGB8888,
+		DRM_FORMAT_YUYV,
+		DRM_FORMAT_NV12,
+		DRM_FORMAT_YUV420,
+		DRM_FORMAT_YUV444,
+	};
+	bool fallback = false;
 	EGLint num;
 
 	assert(gr->has_dmabuf_import);
 
 	if (!gr->has_dmabuf_import_modifiers ||
 	    !gr->query_dmabuf_formats(gr->egl_display, 0, NULL, &num)) {
-		*num_formats = 0;
-		return;
+		num = gr->has_gl_texture_rg ? ARRAY_LENGTH(fallback_formats) : 2;
+		fallback = true;
 	}
 
 	*formats = calloc(num, sizeof(int));
@@ -2103,6 +2112,13 @@ gl_renderer_query_dmabuf_formats(struct weston_compositor *wc,
 		*num_formats = 0;
 		return;
 	}
+
+	if (fallback) {
+		memcpy(formats, fallback_formats, num * sizeof(int));
+		*num_formats = num;
+		return;
+	}
+
 	if (!gr->query_dmabuf_formats(gr->egl_display, num, *formats, &num)) {
 		*num_formats = 0;
 		free(*formats);
-- 
2.11.0



More information about the wayland-devel mailing list