From 543d0a0bb652894d9825f2a08b0c10118e65334e Mon Sep 17 00:00:00 2001
From: Philipp Zabel
Date: Wed, 17 Jan 2018 17:54:32 +0100
Subject: [PATCH] gl-renderer: return conservative format list if dmabuf import
modifiers unsupported
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
Reviewed-by: Emil Velikov
Reviewed-by: Daniel Stone
---
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 56666ed3..371e06b3 100644
--- a/libweston/gl-renderer.c
+++ b/libweston/gl-renderer.c
@@ -2096,14 +2096,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));
@@ -2111,6 +2120,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);