From ff0045b8c90ae1adba10d7c453ae1fbbef744eae Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 17 Sep 2024 08:34:54 +0200 Subject: [PATCH] dmabuftexture: Stop having a fixed downloader Change things from picking a download method at creation time to trying all methods at download time until one succeeds. --- gdk/gdkdmabuftexture.c | 90 +++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 41 deletions(-) diff --git a/gdk/gdkdmabuftexture.c b/gdk/gdkdmabuftexture.c index e68341db71..9858f25ce5 100644 --- a/gdk/gdkdmabuftexture.c +++ b/gdk/gdkdmabuftexture.c @@ -50,7 +50,6 @@ struct _GdkDmabufTexture GdkTexture parent_instance; GdkDisplay *display; - GdkDmabufDownloader *downloader; GdkDmabuf dmabuf; @@ -85,7 +84,6 @@ gdk_dmabuf_texture_dispose (GObject *object) self->destroy = NULL; } - g_clear_object (&self->downloader); g_clear_object (&self->display); G_OBJECT_CLASS (gdk_dmabuf_texture_parent_class)->dispose (object); @@ -107,16 +105,49 @@ static gboolean gdk_dmabuf_texture_invoke_callback (gpointer data) { Download *download = data; + GdkDisplay *display = download->texture->display; - gdk_dmabuf_downloader_download (download->texture->downloader, - download->texture, - download->format, - download->color_state, - download->data, - download->stride); + if (display->egl_downloader && + gdk_dmabuf_downloader_download (display->egl_downloader, + download->texture, + download->format, + download->color_state, + download->data, + download->stride)) + { + /* Successfully downloaded using EGL */ + } + else if (display->vk_downloader && + gdk_dmabuf_downloader_download (display->vk_downloader, + download->texture, + download->format, + download->color_state, + download->data, + download->stride)) + { + /* Successfully downloaded using Vulkan */ + } +#ifdef HAVE_DMABUF + else if (gdk_dmabuf_download_mmap (GDK_TEXTURE (download->texture), + download->format, + download->color_state, + download->data, + download->stride)) + { + /* Successfully downloaded using mmap */ + } +#endif + else + { + const GdkDmabuf *dmabuf = gdk_dmabuf_texture_get_dmabuf (download->texture); + + g_critical ("Failed to download %dx%d dmabuf texture (format %.4s:%#" G_GINT64_MODIFIER "x)", + gdk_texture_get_width (GDK_TEXTURE (download->texture)), + gdk_texture_get_height (GDK_TEXTURE (download->texture)), + (char *)&(dmabuf->fourcc), dmabuf->modifier); + } g_atomic_int_set (&download->spinlock, 1); - return FALSE; } @@ -130,14 +161,6 @@ gdk_dmabuf_texture_download (GdkTexture *texture, GdkDmabufTexture *self = GDK_DMABUF_TEXTURE (texture); Download download = { self, format, color_state, data, stride, 0 }; - if (self->downloader == NULL) - { -#ifdef HAVE_DMABUF - gdk_dmabuf_download_mmap (texture, format, color_state, data, stride); -#endif - return; - } - g_main_context_invoke (NULL, gdk_dmabuf_texture_invoke_callback, &download); while (g_atomic_int_get (&download.spinlock) == 0); @@ -232,37 +255,22 @@ gdk_dmabuf_texture_new_from_builder (GdkDmabufTextureBuilder *builder, : GDK_MEMORY_R8G8B8A8; } - if (display->egl_downloader) + if (!gdk_dmabuf_formats_contains (display->dmabuf_formats, dmabuf.fourcc, dmabuf.modifier)) { - if (gdk_dmabuf_downloader_supports (display->egl_downloader, self, error)) - self->downloader = g_object_ref (display->egl_downloader); - } - - if (!self->downloader && display->vk_downloader) - { - g_clear_error (error); - if (gdk_dmabuf_downloader_supports (display->vk_downloader, self, error)) - self->downloader = g_object_ref (display->vk_downloader); - } - - if (!self->downloader) - { - if (!gdk_dmabuf_formats_contains (gdk_dmabuf_get_mmap_formats (), dmabuf.fourcc, dmabuf.modifier)) - { - g_object_unref (self); - return NULL; - } - - g_clear_error (error); + g_set_error (error, + GDK_DMABUF_ERROR, GDK_DMABUF_ERROR_UNSUPPORTED_FORMAT, + "Unsupported dmabuf format: %.4s:%#" G_GINT64_MODIFIER "x", + (char *) &dmabuf.fourcc, dmabuf.modifier); + g_object_unref (self); + return NULL; } GDK_DISPLAY_DEBUG (display, DMABUF, - "Creating dmabuf texture, format %.4s:%#" G_GINT64_MODIFIER "x, %s%u planes, memory format %u, downloader %s", + "Creating dmabuf texture, format %.4s:%#" G_GINT64_MODIFIER "x, %s%u planes, memory format %u", (char *) &dmabuf.fourcc, dmabuf.modifier, gdk_dmabuf_texture_builder_get_premultiplied (builder) ? " premultiplied, " : "", dmabuf.n_planes, - GDK_TEXTURE (self)->format, - self->downloader ? G_OBJECT_TYPE_NAME (self->downloader) : "none"); + GDK_TEXTURE (self)->format); /* Set this only once we know that the texture will be created. * Otherwise dispose() will run the callback */