From b5e26aec7b26742b46ebe0162637f10b57f32037 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 25 Oct 2023 17:09:59 -0400 Subject: [PATCH] Reshuffle dmabuf format collection Arrange for the following tranches to be collected With GL: - Regular EGL formats - Mmap formats (that aren't included already And with GLES: - Regular EGL formats - External EGL formats - Mmap formats (that aren't included already Also, move the debug spew for formats from the downloaders to the display, so we can print them properlty sorted, and in their tranches. The only thing we don't have anymore here is the downloader name. --- gdk/gdkdisplay.c | 34 +++++++++++++++++++++++++++++----- gdk/gdkdmabuf.c | 4 ---- gdk/gdkdmabufegl.c | 30 ++++++++++++++---------------- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c index f914f7c6fc..d4577cbbf7 100644 --- a/gdk/gdkdisplay.c +++ b/gdk/gdkdisplay.c @@ -1891,14 +1891,15 @@ gdk_display_init_dmabuf (GdkDisplay *self) #ifdef HAVE_DMABUF if (!GDK_DEBUG_CHECK (DMABUF_DISABLE)) { - gdk_display_prepare_gl (self, NULL); - - gdk_display_add_dmabuf_downloader (self, gdk_dmabuf_get_direct_downloader (), builder); - #ifdef HAVE_EGL if (gdk_display_prepare_gl (self, NULL)) - gdk_display_add_dmabuf_downloader (self, gdk_dmabuf_get_egl_downloader (), builder); + { + gdk_display_add_dmabuf_downloader (self, gdk_dmabuf_get_egl_downloader (), builder); + gdk_dmabuf_formats_builder_next_priority (builder); + } #endif + + gdk_display_add_dmabuf_downloader (self, gdk_dmabuf_get_direct_downloader (), builder); } #endif @@ -1907,6 +1908,29 @@ gdk_display_init_dmabuf (GdkDisplay *self) GDK_DISPLAY_DEBUG (self, DMABUF, "Initialized support for %zu dmabuf formats", gdk_dmabuf_formats_get_n_formats (self->dmabuf_formats)); + +#ifdef G_ENABLE_DEBUG + if (GDK_DISPLAY_DEBUG_CHECK (self, DMABUF)) + { + for (gsize i = 0; i < gdk_dmabuf_formats_get_n_formats (self->dmabuf_formats); i++) + { + guint32 fourcc; + guint64 modifier; + + gdk_dmabuf_formats_get_format (self->dmabuf_formats, i, &fourcc, &modifier); + + gdk_debug_message ("dmabuf format %.4s:%#" G_GINT64_MODIFIER "x%s", + (char *) &fourcc, + modifier, + gdk_dmabuf_formats_contains (self->egl_external_formats, fourcc, modifier) ? " (external)" : ""); + + if (i + 1 < gdk_dmabuf_formats_get_n_formats (self->dmabuf_formats) && + gdk_dmabuf_formats_next_priority (self->dmabuf_formats, i) == i + 1) + gdk_debug_message ("------"); + + } + } +#endif } /** diff --git a/gdk/gdkdmabuf.c b/gdk/gdkdmabuf.c index 78d222e112..13f12c1855 100644 --- a/gdk/gdkdmabuf.c +++ b/gdk/gdkdmabuf.c @@ -376,10 +376,6 @@ gdk_dmabuf_direct_downloader_add_formats (const GdkDmabufDownloader *downloader, for (i = 0; i < G_N_ELEMENTS (supported_formats); i++) { - GDK_DEBUG (DMABUF, "%s dmabuf format %.4s:%#" G_GINT64_MODIFIER "x", - downloader->name, - (char *) &supported_formats[i].fourcc, (guint64) DRM_FORMAT_MOD_LINEAR); - gdk_dmabuf_formats_builder_add_format (builder, supported_formats[i].fourcc, DRM_FORMAT_MOD_LINEAR); diff --git a/gdk/gdkdmabufegl.c b/gdk/gdkdmabufegl.c index f02e098d30..f4a67421c2 100644 --- a/gdk/gdkdmabufegl.c +++ b/gdk/gdkdmabufegl.c @@ -99,24 +99,16 @@ gdk_dmabuf_egl_downloader_collect_formats (const GdkDmabufDownloader *downloader for (int j = 0; j < num_modifiers; j++) { - /* All linear formats we support are already added my the mmap downloader. - * We don't add external formats, unless we can use them (via GLES) - */ - if (modifiers[j] != DRM_FORMAT_MOD_LINEAR && - (!external_only[j] || gdk_gl_context_get_use_es (context))) + if (!external_only[j]) { - GDK_DEBUG (DMABUF, "%s%s dmabuf format %.4s:%#" G_GINT64_MODIFIER "x", - external_only[j] ? "external " : "", - downloader->name, - (char *) &fourccs[i], - modifiers[j]); - gdk_dmabuf_formats_builder_add_format (formats, fourccs[i], modifiers[j]); + all_external = FALSE; } - if (external_only[j]) - gdk_dmabuf_formats_builder_add_format (external, fourccs[i], modifiers[j]); else - all_external = FALSE; + { + if (gdk_gl_context_get_use_es (context)) + gdk_dmabuf_formats_builder_add_format (external, fourccs[i], modifiers[j]); + } } /* Accept implicit modifiers as long as we accept the format at all. @@ -126,9 +118,9 @@ gdk_dmabuf_egl_downloader_collect_formats (const GdkDmabufDownloader *downloader * As an extra wrinkle, treat the implicit modifier as 'external only' * if all formats with the same fourcc are 'external only'. */ - if (!all_external || gdk_gl_context_get_use_es (context)) + if (!all_external) gdk_dmabuf_formats_builder_add_format (formats, fourccs[i], DRM_FORMAT_MOD_INVALID); - if (all_external) + else if (gdk_gl_context_get_use_es (context)) gdk_dmabuf_formats_builder_add_format (external, fourccs[i], DRM_FORMAT_MOD_INVALID); } @@ -144,6 +136,7 @@ gdk_dmabuf_egl_downloader_add_formats (const GdkDmabufDownloader *downloader, GdkDisplay *display, GdkDmabufFormatsBuilder *builder) { + GdkGLContext *context = gdk_display_get_gl_context (display); GdkDmabufFormatsBuilder *formats; GdkDmabufFormatsBuilder *external; gboolean retval = FALSE; @@ -160,6 +153,11 @@ gdk_dmabuf_egl_downloader_add_formats (const GdkDmabufDownloader *downloader, display->egl_external_formats = gdk_dmabuf_formats_builder_free_to_formats (external); gdk_dmabuf_formats_builder_add_formats (builder, display->egl_dmabuf_formats); + if (gdk_gl_context_get_use_es (context)) + { + gdk_dmabuf_formats_builder_next_priority (builder); + gdk_dmabuf_formats_builder_add_formats (builder, display->egl_external_formats); + } return retval; }