[gtk/matthiasc/color-profiles: 106/111] gdk: Add a new constructor for GL textures




commit 2dc0c6b3801b74520f9f3fa4c68bf36f32762356
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Oct 3 16:03:14 2021 -0400

    gdk: Add a new constructor for GL textures
    
    Add a constructor that lets us provide more information
    about the content of a GL texture, such as the color
    profile, and whether it is premultiplied or flipped.

 gdk/gdkgltexture.c        | 49 +++++++++++++++++++++++++++++++++++++++++++++++
 gdk/gdkgltexture.h        | 22 +++++++++++++++++++++
 gdk/gdkgltextureprivate.h |  1 +
 3 files changed, 72 insertions(+)
---
diff --git a/gdk/gdkgltexture.c b/gdk/gdkgltexture.c
index a89ed388b7..21582bb31a 100644
--- a/gdk/gdkgltexture.c
+++ b/gdk/gdkgltexture.c
@@ -24,6 +24,7 @@
 #include "gdkmemoryformatprivate.h"
 #include "gdkmemorytextureprivate.h"
 #include "gdktextureprivate.h"
+#include "gdkcolorprofile.h"
 
 #include <epoxy/gl.h>
 
@@ -37,6 +38,7 @@ struct _GdkGLTexture {
   GdkTexture parent_instance;
 
   GdkGLContext *context;
+  GdkGLTextureFlags flags;
   guint id;
 
   GdkTexture *saved;
@@ -382,6 +384,12 @@ gdk_gl_texture_get_id (GdkGLTexture *self)
   return self->id;
 }
 
+GdkGLTextureFlags
+gdk_gl_texture_get_flags (GdkGLTexture *self)
+{
+  return self->flags;
+}
+
 /**
  * gdk_gl_texture_release:
  * @self: a `GdkTexture` wrapping a GL texture
@@ -436,6 +444,45 @@ gdk_gl_texture_new (GdkGLContext   *context,
                     int             height,
                     GDestroyNotify  destroy,
                     gpointer        data)
+{
+  return gdk_gl_texture_new_with_color_profile (context, id,
+                                                width, height,
+                                                GDK_GL_TEXTURE_PREMULTIPLIED,
+                                                gdk_color_profile_get_srgb (),
+                                                destroy, data);
+}
+
+/**
+ * gdk_gl_texture_new_with_color_profile:
+ * @context: a `GdkGLContext`
+ * @id: the ID of a texture that was created with @context
+ * @width: the nominal width of the texture
+ * @height: the nominal height of the texture
+ * @flags: flags that describe the content of the texture
+ * @color_profile: the `GdkColorProfile` for the content of the texture
+ * @destroy: a destroy notify that will be called when the GL resources
+ *   are released
+ * @data: data that gets passed to @destroy
+ *
+ * Creates a new texture for an existing GL texture with a given color profile.
+ *
+ * Note that the GL texture must not be modified until @destroy is called,
+ * which will happen when the GdkTexture object is finalized, or due to
+ * an explicit call of [method@Gdk.GLTexture.release].
+ *
+ * Return value: (transfer full): A newly-created `GdkTexture`
+ *
+ * Since: 4.6
+ */
+GdkTexture *
+gdk_gl_texture_new_with_color_profile (GdkGLContext      *context,
+                                       guint              id,
+                                       int                width,
+                                       int                height,
+                                       GdkGLTextureFlags  flags,
+                                       GdkColorProfile   *color_profile,
+                                       GDestroyNotify     destroy,
+                                       gpointer           data)
 {
   GdkGLTexture *self;
 
@@ -447,10 +494,12 @@ gdk_gl_texture_new (GdkGLContext   *context,
   self = g_object_new (GDK_TYPE_GL_TEXTURE,
                        "width", width,
                        "height", height,
+                       "color-profile", color_profile,
                        NULL);
 
   self->context = g_object_ref (context);
   self->id = id;
+  self->flags = flags;
   self->destroy = destroy;
   self->data = data;
 
diff --git a/gdk/gdkgltexture.h b/gdk/gdkgltexture.h
index 54e4fee7e7..ffdfc596f3 100644
--- a/gdk/gdkgltexture.h
+++ b/gdk/gdkgltexture.h
@@ -49,6 +49,28 @@ GdkTexture *            gdk_gl_texture_new                     (GdkGLContext
                                                                 GDestroyNotify   destroy,
                                                                 gpointer         data);
 
+/**
+ * GdkGLTextureFlags:
+ * @GDK_GL_TEXTURE_FLAGS_PREMULTIPLIED: The alpha in the data is not premultiplied
+ * @GDK_GL_TEXTURE_FLAGS_FLIPPED: The data has the origin at the bottom
+ *
+ * Flags that describe the content of a GL texture.
+ */
+typedef enum {
+  GDK_GL_TEXTURE_PREMULTIPLIED = 1 << 0,
+  GDK_GL_TEXTURE_FLIPPED       = 1 << 1,
+} GdkGLTextureFlags;
+
+GDK_AVAILABLE_IN_4_6
+GdkTexture *            gdk_gl_texture_new_with_color_profile  (GdkGLContext      *context,
+                                                                guint              id,
+                                                                int                width,
+                                                                int                height,
+                                                                GdkGLTextureFlags  flags,
+                                                                GdkColorProfile   *color_profile,
+                                                                GDestroyNotify     destroy,
+                                                                gpointer           data);
+
 GDK_AVAILABLE_IN_ALL
 void                    gdk_gl_texture_release                 (GdkGLTexture    *self);
 
diff --git a/gdk/gdkgltextureprivate.h b/gdk/gdkgltextureprivate.h
index 06035eea07..9906d878df 100644
--- a/gdk/gdkgltextureprivate.h
+++ b/gdk/gdkgltextureprivate.h
@@ -9,6 +9,7 @@ G_BEGIN_DECLS
 
 GdkGLContext *          gdk_gl_texture_get_context      (GdkGLTexture           *self);
 guint                   gdk_gl_texture_get_id           (GdkGLTexture           *self);
+GdkGLTextureFlags       gdk_gl_texture_get_flags        (GdkGLTexture           *self);
 
 G_END_DECLS
 


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