From bb2b8bf2c34ca3be94ba7d0670cc944b3bbcb31e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 24 Oct 2023 22:24:37 -0400 Subject: [PATCH] dmabuf: Refine the handling of implicit modifiers If all formats with a given fourcc are external, treat the fourcc with implicit modifiers as external too, following a sugestion by Benjamin Otte. --- gdk/gdkdmabufegl.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gdk/gdkdmabufegl.c b/gdk/gdkdmabufegl.c index 79a74531c8..f02e098d30 100644 --- a/gdk/gdkdmabufegl.c +++ b/gdk/gdkdmabufegl.c @@ -72,6 +72,7 @@ gdk_dmabuf_egl_downloader_collect_formats (const GdkDmabufDownloader *downloader for (int i = 0; i < num_fourccs; i++) { int num_modifiers; + gboolean all_external; eglQueryDmaBufModifiersEXT (egl_display, fourccs[i], @@ -94,6 +95,8 @@ gdk_dmabuf_egl_downloader_collect_formats (const GdkDmabufDownloader *downloader external_only, &num_modifiers); + all_external = TRUE; + for (int j = 0; j < num_modifiers; j++) { /* All linear formats we support are already added my the mmap downloader. @@ -112,13 +115,21 @@ gdk_dmabuf_egl_downloader_collect_formats (const GdkDmabufDownloader *downloader } if (external_only[j]) gdk_dmabuf_formats_builder_add_format (external, fourccs[i], modifiers[j]); + else + all_external = FALSE; } /* Accept implicit modifiers as long as we accept the format at all. * This is a bit of a crapshot, but unfortunately needed for a bunch * of drivers. + * + * As an extra wrinkle, treat the implicit modifier as 'external only' + * if all formats with the same fourcc are 'external only'. */ - gdk_dmabuf_formats_builder_add_format (formats, fourccs[i], DRM_FORMAT_MOD_INVALID); + if (!all_external || gdk_gl_context_get_use_es (context)) + gdk_dmabuf_formats_builder_add_format (formats, fourccs[i], DRM_FORMAT_MOD_INVALID); + if (all_external) + gdk_dmabuf_formats_builder_add_format (external, fourccs[i], DRM_FORMAT_MOD_INVALID); } g_free (modifiers);