From 1d9af571a54774a5281e9c8bd3b7cf76288ee988 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 8 May 2022 14:55:24 -0400 Subject: [PATCH] gsk: Use GL texture information Use the flags and color profile information from GL textures to figure out what conversions we need to do on them. --- gsk/gl/gskgldriver.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/gsk/gl/gskgldriver.c b/gsk/gl/gskgldriver.c index 98f93ad3d4..f820bdd9f3 100644 --- a/gsk/gl/gskgldriver.c +++ b/gsk/gl/gskgldriver.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -883,28 +884,40 @@ gsk_gl_driver_load_texture (GskGLDriver *self, if (gdk_gl_context_is_shared (context, texture_context)) { + GdkColorProfile *profile; guint gl_texture_id; + GdkGLTextureFlags flags; gl_texture_id = gdk_gl_texture_get_id (gl_texture); + profile = gdk_texture_get_color_profile (texture); + flags = gdk_gl_texture_get_flags (gl_texture); /* A GL texture from the same GL context is a simple task... */ - if (gdk_color_profile_is_linear (gdk_texture_get_color_profile (texture))) + if (profile == gdk_color_profile_get_srgb_linear () && + flags == GDK_GL_TEXTURE_PREMULTIPLIED) { return gl_texture_id; } - else + else if (profile == gdk_color_profile_get_srgb () || + profile == gdk_color_profile_get_srgb_linear ()) { - /* The GL texture isn't linear sRGB, so we need to convert - * it before we can use it. For now, we just assume that it - * is nonlinear sRGB. Eventually, we should figure out how - * to convert from other color spaces to linear sRGB - */ + conversion = 0; + + if (profile == gdk_color_profile_get_srgb ()) + conversion |= GSK_CONVERSION_LINEARIZE; + + if ((flags & GDK_GL_TEXTURE_PREMULTIPLIED) == 0) + conversion |= GSK_CONVERSION_PREMULTIPLY; + + if ((flags & GDK_GL_TEXTURE_FLIPPED) != 0) + conversion |= GSK_CONVERSION_FLIP; + t = gsk_gl_driver_convert_texture (self, gl_texture_id, width, height, format, min_filter, mag_filter, - GSK_CONVERSION_LINEARIZE); + conversion); if (gdk_texture_set_render_data (texture, self, t, gsk_gl_texture_destroyed)) t->user = texture;