[gtk/matthiasc/color-profile-rebased: 56/66] API: Add a new constructor for GL textures




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

    API: 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        | 54 ++++++++++++++++++++++++++++++++++++++++++++++-
 gdk/gdkgltexture.h        | 23 ++++++++++++++++++++
 gdk/gdkgltextureprivate.h |  1 +
 3 files changed, 77 insertions(+), 1 deletion(-)
---
diff --git a/gdk/gdkgltexture.c b/gdk/gdkgltexture.c
index 7ab0f355e8..8f8f20b4b4 100644
--- a/gdk/gdkgltexture.c
+++ b/gdk/gdkgltexture.c
@@ -39,6 +39,7 @@ struct _GdkGLTexture {
   GdkTexture parent_instance;
 
   GdkGLContext *context;
+  GdkGLTextureFlags flags;
   guint id;
 
   GdkTexture *saved;
@@ -281,6 +282,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
@@ -435,6 +442,10 @@ gdk_gl_texture_determine_format (GdkGLTexture *self)
  * which will happen when the GdkTexture object is finalized, or due to
  * an explicit call of [method@Gdk.GLTexture.release].
  *
+ * The texture data is assumed to be premultiplied, not flipped, and in the
+ * sRGB colorspace, see [ctor@Gdk.GLTexture.new_with_color_profile] to override
+ * this.
+ *
  * Return value: (transfer full) (type GdkGLTexture): A newly-created
  *   `GdkTexture`
  */
@@ -445,6 +456,46 @@ gdk_gl_texture_new (GdkGLContext   *context,
                     int             height,
                     GDestroyNotify  destroy,
                     gpointer        data)
+{
+  return gdk_gl_texture_new_with_color_space (context, id,
+                                              width, height,
+                                              GDK_GL_TEXTURE_PREMULTIPLIED,
+                                              gdk_color_space_get_srgb (),
+                                              destroy, data);
+}
+
+/**
+ * gdk_gl_texture_new_with_color_space:
+ * @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_space: the `GdkColorSpace` 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 space
+ * and flags.
+ *
+ * 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.8
+ */
+GdkTexture *
+gdk_gl_texture_new_with_color_space (GdkGLContext      *context,
+                                     guint              id,
+                                     int                width,
+                                     int                height,
+                                     GdkGLTextureFlags  flags,
+                                     GdkColorSpace     *color_space,
+                                     GDestroyNotify     destroy,
+                                     gpointer           data)
 {
   GdkGLTexture *self;
 
@@ -456,10 +507,12 @@ gdk_gl_texture_new (GdkGLContext   *context,
   self = g_object_new (GDK_TYPE_GL_TEXTURE,
                        "width", width,
                        "height", height,
+                       "color-space", color_space,
                        NULL);
 
   self->context = g_object_ref (context);
   self->id = id;
+  self->flags = flags;
   self->destroy = destroy;
   self->data = data;
 
@@ -467,4 +520,3 @@ gdk_gl_texture_new (GdkGLContext   *context,
 
   return GDK_TEXTURE (self);
 }
-
diff --git a/gdk/gdkgltexture.h b/gdk/gdkgltexture.h
index 54e4fee7e7..634bf2936a 100644
--- a/gdk/gdkgltexture.h
+++ b/gdk/gdkgltexture.h
@@ -49,6 +49,29 @@ GdkTexture *            gdk_gl_texture_new                     (GdkGLContext
                                                                 GDestroyNotify   destroy,
                                                                 gpointer         data);
 
+/**
+ * GdkGLTextureFlags:
+ * @GDK_GL_TEXTURE_FLAGS_PREMULTIPLIED: The alpha in the data is premultiplied
+ * @GDK_GL_TEXTURE_FLAGS_FLIPPED: The data has the origin at the bottom (this is usually
+ *   th case for textures that are produced by GL rendering)
+ *
+ * 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_8
+GdkTexture *            gdk_gl_texture_new_with_color_space (GdkGLContext      *context,
+                                                             guint              id,
+                                                             int                width,
+                                                             int                height,
+                                                             GdkGLTextureFlags  flags,
+                                                             GdkColorSpace     *color_space,
+                                                             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]