[gtk/matthiasc/color-profiles: 31/32] ngl: Use GL texture information




commit 888f242a42b67a6172451f3e48933ddb881d1d42
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Oct 3 16:04:34 2021 -0400

    ngl: 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/ngl/gskngldriver.c | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)
---
diff --git a/gsk/ngl/gskngldriver.c b/gsk/ngl/gskngldriver.c
index e92b5548c2..47c99d9c7e 100644
--- a/gsk/ngl/gskngldriver.c
+++ b/gsk/ngl/gskngldriver.c
@@ -27,6 +27,7 @@
 #include <gdk/gdkdisplayprivate.h>
 #include <gdk/gdktextureprivate.h>
 #include <gdk/gdkprofilerprivate.h>
+#include <gdk/gdkcolorprofileprivate.h>
 #include <gsk/gskdebugprivate.h>
 #include <gsk/gskglshaderprivate.h>
 #include <gsk/gskrendererprivate.h>
@@ -898,27 +899,39 @@ gsk_ngl_driver_load_texture (GskNglDriver *self,
 
       if (gdk_gl_context_is_shared (context, texture_context))
         {
+          GdkColorProfile *profile;
           guint gl_texture_id;
+          GdkGLTextureFlags flags;
 
+          profile = gdk_texture_get_color_profile (texture);
           gl_texture_id = gdk_gl_texture_get_id (gl_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_ngl_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_ngl_texture_destroyed))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]