gsk: Support dmabuf textures

Defer handling of dmabuf textures to the driver,
and add the necessary code in load_texture.
This commit is contained in:
Matthias Clasen 2023-10-13 08:28:48 -04:00
parent 494154beb6
commit 52254f755f
2 changed files with 22 additions and 12 deletions

View File

@ -44,6 +44,8 @@
#include <gdk/gdktextureprivate.h> #include <gdk/gdktextureprivate.h>
#include <gdk/gdkmemoryformatprivate.h> #include <gdk/gdkmemoryformatprivate.h>
#include <gdk/gdkdmabuftextureprivate.h>
G_DEFINE_TYPE (GskGLDriver, gsk_gl_driver, G_TYPE_OBJECT) G_DEFINE_TYPE (GskGLDriver, gsk_gl_driver, G_TYPE_OBJECT)
@ -758,7 +760,15 @@ gsk_gl_driver_load_texture (GskGLDriver *self,
return t->texture_id; return t->texture_id;
} }
if (GDK_IS_GL_TEXTURE (texture)) if (GDK_IS_DMABUF_TEXTURE (texture))
{
texture_id = gdk_gl_context_import_dmabuf (context,
gdk_texture_get_width (texture),
gdk_texture_get_height (texture),
gdk_dmabuf_texture_get_dmabuf (GDK_DMABUF_TEXTURE (texture)),
GL_TEXTURE_2D);
}
else if (GDK_IS_GL_TEXTURE (texture))
{ {
GdkGLTexture *gl_texture = (GdkGLTexture *) texture; GdkGLTexture *gl_texture = (GdkGLTexture *) texture;
GdkGLContext *texture_context = gdk_gl_texture_get_context (gl_texture); GdkGLContext *texture_context = gdk_gl_texture_get_context (gl_texture);

View File

@ -30,6 +30,7 @@
#include <gsk/gskglshaderprivate.h> #include <gsk/gskglshaderprivate.h>
#include <gdk/gdktextureprivate.h> #include <gdk/gdktextureprivate.h>
#include <gdk/gdkmemorytextureprivate.h> #include <gdk/gdkmemorytextureprivate.h>
#include <gdk/gdkdmabuftexture.h>
#include <gsk/gsktransformprivate.h> #include <gsk/gsktransformprivate.h>
#include <gsk/gskroundedrectprivate.h> #include <gsk/gskroundedrectprivate.h>
#include <gsk/gskrectprivate.h> #include <gsk/gskrectprivate.h>
@ -47,6 +48,7 @@
#include "ninesliceprivate.h" #include "ninesliceprivate.h"
#include "fp16private.h" #include "fp16private.h"
#define ORTHO_NEAR_PLANE -10000 #define ORTHO_NEAR_PLANE -10000
#define ORTHO_FAR_PLANE 10000 #define ORTHO_FAR_PLANE 10000
#define MAX_GRADIENT_STOPS 6 #define MAX_GRADIENT_STOPS 6
@ -3630,16 +3632,12 @@ gsk_gl_render_job_upload_texture (GskGLRenderJob *job,
gboolean ensure_mipmap, gboolean ensure_mipmap,
GskGLRenderOffscreen *offscreen) GskGLRenderOffscreen *offscreen)
{ {
GdkGLTexture *gl_texture = NULL; /* Don't put GL or dmabuf textures into icon caches, they are already on the GPU side */
if (GDK_IS_GL_TEXTURE (texture))
gl_texture = GDK_GL_TEXTURE (texture);
if (!ensure_mipmap && if (!ensure_mipmap &&
gsk_gl_texture_library_can_cache ((GskGLTextureLibrary *)job->driver->icons_library, gsk_gl_texture_library_can_cache ((GskGLTextureLibrary *)job->driver->icons_library,
texture->width, texture->width,
texture->height) && texture->height) &&
!gl_texture) !(GDK_IS_GL_TEXTURE (texture) || GDK_IS_DMABUF_TEXTURE (texture)))
{ {
const GskGLIconData *icon_data; const GskGLIconData *icon_data;
@ -3653,16 +3651,18 @@ gsk_gl_render_job_upload_texture (GskGLRenderJob *job,
/* Only generate a mipmap if it does not make use reupload /* Only generate a mipmap if it does not make use reupload
* a GL texture which we could otherwise use directly. * a GL texture which we could otherwise use directly.
*/ */
if (gl_texture && if (GDK_IS_GL_TEXTURE (texture) &&
gdk_gl_context_is_shared (gdk_gl_texture_get_context (gl_texture), job->command_queue->context)) gdk_gl_context_is_shared (gdk_gl_texture_get_context (GDK_GL_TEXTURE (texture)),
ensure_mipmap = gdk_gl_texture_has_mipmap (gl_texture); job->command_queue->context))
ensure_mipmap = gdk_gl_texture_has_mipmap (GDK_GL_TEXTURE (texture));
offscreen->texture_id = gsk_gl_driver_load_texture (job->driver, texture, ensure_mipmap); offscreen->texture_id = gsk_gl_driver_load_texture (job->driver, texture, ensure_mipmap);
init_full_texture_region (offscreen); init_full_texture_region (offscreen);
offscreen->has_mipmap = ensure_mipmap; offscreen->has_mipmap = ensure_mipmap;
if (gl_texture && offscreen->texture_id == gdk_gl_texture_get_id (gl_texture)) if (GDK_IS_GL_TEXTURE (texture) &&
offscreen->sync = gdk_gl_texture_get_sync (gl_texture); offscreen->texture_id == gdk_gl_texture_get_id (GDK_GL_TEXTURE (texture)))
offscreen->sync = gdk_gl_texture_get_sync (GDK_GL_TEXTURE (texture));
} }
} }