diff --git a/gdk/gdkdmabuf.c b/gdk/gdkdmabuf.c index 78d222e112..3a769d7f42 100644 --- a/gdk/gdkdmabuf.c +++ b/gdk/gdkdmabuf.c @@ -440,8 +440,8 @@ gdk_dmabuf_direct_downloader_do_download (GdkTexture *texture, info = get_drm_format_info (dmabuf->fourcc); GDK_DEBUG (DMABUF, - "Using mmap() and memcpy() for downloading a dmabuf (format %.4s:%#lx)", - (char *)&dmabuf->fourcc, dmabuf->modifier); + "Using mmap() and memcpy() for downloading a dmabuf (format %.4s::%016llx)", + (char *)&dmabuf->fourcc, (long long unsigned) dmabuf->modifier); for (i = 0; i < dmabuf->n_planes; i++) { diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c index 91128ca5ff..4ef8c19798 100644 --- a/gdk/gdkglcontext.c +++ b/gdk/gdkglcontext.c @@ -1983,12 +1983,12 @@ gdk_gl_backend_use (GdkGLBackend backend_type) g_assert (the_gl_backend_type == backend_type); } -guint -gdk_gl_context_import_dmabuf (GdkGLContext *self, - int width, - int height, - const GdkDmabuf *dmabuf, - int target) +static guint +gdk_gl_context_import_dmabuf_for_target (GdkGLContext *self, + int width, + int height, + const GdkDmabuf *dmabuf, + int target) { #if defined(HAVE_EGL) && defined(HAVE_DMABUF) GdkDisplay *display = gdk_gl_context_get_display (self); @@ -2076,6 +2076,65 @@ gdk_gl_context_import_dmabuf (GdkGLContext *self, #endif } +guint +gdk_gl_context_import_dmabuf (GdkGLContext *self, + int width, + int height, + const GdkDmabuf *dmabuf, + gboolean *external) +{ + GdkDisplay *display = gdk_gl_context_get_display (self); + guint texture_id; + + gdk_display_init_dmabuf (display); + + if (!gdk_dmabuf_formats_contains (display->egl_external_formats, dmabuf->fourcc, dmabuf->modifier)) + { + texture_id = gdk_gl_context_import_dmabuf_for_target (self, + width, height, + dmabuf, + GL_TEXTURE_2D); + if (texture_id == 0) + { + GDK_DEBUG (DMABUF, "Failed import of %dx%d %.4s::%016llx", + width, height, + (char *) &dmabuf->fourcc, (long long unsigned) dmabuf->modifier); + return 0; + } + + GDK_DEBUG (DMABUF, "Imported %dx%d %.4s::%016llx dmabuf as GL_TEXTURE_2D texture", + width, height, + (char *) &dmabuf->fourcc, (long long unsigned) dmabuf->modifier); + *external = FALSE; + return texture_id; + } + + if (!gdk_gl_context_get_use_es (self)) + { + GDK_DEBUG (DMABUF, "Can't import external_only %.4s::%016llx outside of GLES", + (char *) &dmabuf->fourcc, (long long unsigned) dmabuf->modifier); + return 0; + } + + texture_id = gdk_gl_context_import_dmabuf_for_target (self, + width, height, + dmabuf, + GL_TEXTURE_EXTERNAL_OES); + if (texture_id == 0) + { + GDK_DEBUG (DMABUF, "Failed import of external_only %dx%d %.4s::%016llx dmabuf", + width, height, + (char *) &dmabuf->fourcc, (long long unsigned) dmabuf->modifier); + return 0; + } + + GDK_DEBUG (DMABUF, "Imported %dx%d %.4s::%016llx dmabuf as GL_TEXTURE_EXTERNAL_OES texture", + width, height, + (char *) &dmabuf->fourcc, (long long unsigned) dmabuf->modifier); + *external = TRUE; + return texture_id; +} + gboolean gdk_gl_context_export_dmabuf (GdkGLContext *self, unsigned int texture_id, diff --git a/gdk/gdkglcontextprivate.h b/gdk/gdkglcontextprivate.h index 03d65cc42f..9f3ff82ff8 100644 --- a/gdk/gdkglcontextprivate.h +++ b/gdk/gdkglcontextprivate.h @@ -168,7 +168,7 @@ guint gdk_gl_context_import_dmabuf (GdkGLContext int width, int height, const GdkDmabuf *dmabuf, - int target); + gboolean *external); gboolean gdk_gl_context_export_dmabuf (GdkGLContext *self, unsigned int texture_id, diff --git a/gsk/gl/gskgldriver.c b/gsk/gl/gskgldriver.c index f02fcc2fa3..248bd810fa 100644 --- a/gsk/gl/gskgldriver.c +++ b/gsk/gl/gskgldriver.c @@ -798,7 +798,6 @@ gsk_gl_driver_import_dmabuf_texture (GskGLDriver *self, GdkDmabufTexture *texture) { GdkGLContext *context = self->command_queue->context; - GdkDisplay *display = gdk_gl_context_get_display (context); int max_texture_size = self->command_queue->max_texture_size; const GdkDmabuf *dmabuf; guint texture_id; @@ -806,6 +805,7 @@ gsk_gl_driver_import_dmabuf_texture (GskGLDriver *self, GskGLProgram *program; GskGLRenderTarget *render_target; guint prev_fbo; + gboolean external; gdk_gl_context_make_current (context); @@ -820,33 +820,16 @@ gsk_gl_driver_import_dmabuf_texture (GskGLDriver *self, dmabuf = gdk_dmabuf_texture_get_dmabuf (texture); - GDK_DEBUG (DMABUF, "DMA-buf Format %.4s:%#lx", (char *) &dmabuf->fourcc, dmabuf->modifier); - - gdk_display_init_dmabuf (display); - - if (!gdk_dmabuf_formats_contains (display->egl_external_formats, dmabuf->fourcc, dmabuf->modifier)) - { - GDK_DEBUG (DMABUF, "Import dmabuf as GL_TEXTURE_2D texture"); - return gdk_gl_context_import_dmabuf (context, width, height, - dmabuf, - GL_TEXTURE_2D); - } - - if (!gdk_gl_context_get_use_es (context)) - { - GDK_DEBUG (DMABUF, "Can't import external_only dmabuf outside of GLES"); - return 0; - } - - GDK_DEBUG (DMABUF, "Import dmabuf as GL_TEXTURE_EXTERNAL_OES texture"); - - texture_id = gdk_gl_context_import_dmabuf (context, width, height, + texture_id = gdk_gl_context_import_dmabuf (context, + width, height, dmabuf, - GL_TEXTURE_EXTERNAL_OES); - + &external); if (texture_id == 0) return 0; + if (!external) + return texture_id; + gsk_gl_driver_autorelease_texture (self, texture_id); program = self->external; diff --git a/testsuite/gdk/dmabuftexture.c b/testsuite/gdk/dmabuftexture.c index d56fb29ef0..2851347254 100644 --- a/testsuite/gdk/dmabuftexture.c +++ b/testsuite/gdk/dmabuftexture.c @@ -218,6 +218,7 @@ test_dmabuf_import (void) GdkTexture *texture2; GdkGLTextureBuilder *builder; guchar *data; + gboolean external; display = gdk_display_get_default (); if (!gdk_display_prepare_gl (display, &error)) @@ -256,7 +257,9 @@ test_dmabuf_import (void) g_assert_no_error (error); dmabuf2 = gdk_dmabuf_texture_get_dmabuf (GDK_DMABUF_TEXTURE (texture)); - texture_id2 = gdk_gl_context_import_dmabuf (context2, 64, 64, dmabuf2, GL_TEXTURE_2D); + texture_id2 = gdk_gl_context_import_dmabuf (context2, 64, 64, dmabuf2, &external); + g_assert_cmpint (texture_id2, !=, 0); + g_assert_false (external); builder = gdk_gl_texture_builder_new (); gdk_gl_texture_builder_set_context (builder, context2);