[gtk/matthiasc/color-profile-rebased: 8/51] API: Add a GdkTexture::color-space property




commit e675b54df75ca09a905f1345c694b58999e7ae57
Author: Benjamin Otte <otte redhat com>
Date:   Mon Sep 20 09:44:32 2021 +0200

    API: Add a GdkTexture::color-space property
    
    Returns the associated color space. For now, this is always sRGB.

 gdk/gdkgltexture.c      |  7 +++---
 gdk/gdkmemorytexture.c  |  1 +
 gdk/gdktexture.c        | 60 +++++++++++++++++++++++++++++++++++++++++--------
 gdk/gdktexture.h        |  2 ++
 gdk/gdktextureprivate.h |  1 +
 5 files changed, 59 insertions(+), 12 deletions(-)
---
diff --git a/gdk/gdkgltexture.c b/gdk/gdkgltexture.c
index 94d877e8a2..4cc070a5c1 100644
--- a/gdk/gdkgltexture.c
+++ b/gdk/gdkgltexture.c
@@ -23,6 +23,7 @@
 #include "gdkdisplayprivate.h"
 #include "gdkglcontextprivate.h"
 #include "gdkmemoryformatprivate.h"
+#include "gdkcolorspace.h"
 #include "gdkmemorytextureprivate.h"
 #include "gdktextureprivate.h"
 
@@ -157,7 +158,7 @@ gdk_gl_texture_do_download (gpointer texture_,
   expected_stride = texture->width * gdk_memory_format_bytes_per_pixel (download->format);
 
   if (download->stride == expected_stride &&
-      !gdk_gl_context_get_use_es (self->context) && 
+      !gdk_gl_context_get_use_es (self->context) &&
       gdk_memory_format_gl_format (download->format, TRUE, &gl_internal_format, &gl_format, &gl_type))
     {
       glGetTexImage (GL_TEXTURE_2D,
@@ -193,7 +194,7 @@ gdk_gl_texture_do_download (gpointer texture_,
           (download->stride == expected_stride))
         {
           glReadPixels (0, 0,
-                        texture->width, texture->height, 
+                        texture->width, texture->height,
                         gl_read_format,
                         gl_read_type,
                         download->data);
@@ -204,7 +205,7 @@ gdk_gl_texture_do_download (gpointer texture_,
           guchar *pixels = g_malloc_n (texture->width * actual_bpp, texture->height);
 
           glReadPixels (0, 0,
-                        texture->width, texture->height, 
+                        texture->width, texture->height,
                         gl_read_format,
                         gl_read_type,
                         pixels);
diff --git a/gdk/gdkmemorytexture.c b/gdk/gdkmemorytexture.c
index e241ebd0a3..1ecd2978cd 100644
--- a/gdk/gdkmemorytexture.c
+++ b/gdk/gdkmemorytexture.c
@@ -22,6 +22,7 @@
 #include "gdkmemorytextureprivate.h"
 
 #include "gdkmemoryformatprivate.h"
+#include "gdkcolorspaceprivate.h"
 #include "gsk/gl/fp16private.h"
 
 /**
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index 3c4bf10634..576f30f9ec 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -40,6 +40,7 @@
 #include "gdktextureprivate.h"
 
 #include <glib/gi18n-lib.h>
+#include "gdkcolorspace.h"
 #include "gdkmemorytextureprivate.h"
 #include "gdkpaintable.h"
 #include "gdksnapshot.h"
@@ -61,6 +62,7 @@ enum {
   PROP_0,
   PROP_WIDTH,
   PROP_HEIGHT,
+  PROP_COLOR_SPACE,
 
   N_PROPS
 };
@@ -247,6 +249,12 @@ gdk_texture_set_property (GObject      *gobject,
       self->height = g_value_get_int (value);
       break;
 
+    case PROP_COLOR_SPACE:
+      self->color_space = g_value_dup_object (value);
+      if (self->color_space == NULL)
+        self->color_space = g_object_ref (gdk_color_space_get_srgb ());
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
       break;
@@ -271,6 +279,10 @@ gdk_texture_get_property (GObject    *gobject,
       g_value_set_int (value, self->height);
       break;
 
+    case PROP_COLOR_SPACE:
+      g_value_set_object (value, self->color_space);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
       break;
@@ -283,6 +295,7 @@ gdk_texture_dispose (GObject *object)
   GdkTexture *self = GDK_TEXTURE (object);
 
   gdk_texture_clear_render_data (self);
+  g_clear_object (&self->color_space);
 
   G_OBJECT_CLASS (gdk_texture_parent_class)->dispose (object);
 }
@@ -305,9 +318,7 @@ gdk_texture_class_init (GdkTextureClass *klass)
    */
   properties[PROP_WIDTH] =
     g_param_spec_int ("width", NULL, NULL,
-                      1,
-                      G_MAXINT,
-                      1,
+                      1, G_MAXINT, 1,
                       G_PARAM_READWRITE |
                       G_PARAM_CONSTRUCT_ONLY |
                       G_PARAM_STATIC_STRINGS |
@@ -320,14 +331,27 @@ gdk_texture_class_init (GdkTextureClass *klass)
    */
   properties[PROP_HEIGHT] =
     g_param_spec_int ("height", NULL, NULL,
-                      1,
-                      G_MAXINT,
-                      1,
+                      1, G_MAXINT, 1,
                       G_PARAM_READWRITE |
                       G_PARAM_CONSTRUCT_ONLY |
                       G_PARAM_STATIC_STRINGS |
                       G_PARAM_EXPLICIT_NOTIFY);
 
+  /**
+   * GdkTexture:color-space: (attributes org.gtk.Property.get=gdk_texture_get_color_space)
+   *
+   * The color space associated with texture.
+   *
+   * Since: 4.10
+   */
+  properties[PROP_COLOR_SPACE] =
+    g_param_spec_object ("color-space", NULL, NULL,
+                         GDK_TYPE_COLOR_SPACE,
+                         G_PARAM_READWRITE |
+                         G_PARAM_CONSTRUCT_ONLY |
+                         G_PARAM_STATIC_STRINGS |
+                         G_PARAM_EXPLICIT_NOTIFY);
+
   g_object_class_install_properties (gobject_class, N_PROPS, properties);
 }
 
@@ -361,7 +385,7 @@ gdk_texture_new_for_surface (cairo_surface_t *surface)
                                       * cairo_image_surface_get_stride (surface),
                                       (GDestroyNotify) cairo_surface_destroy,
                                       cairo_surface_reference (surface));
-  
+
   texture = gdk_memory_texture_new (cairo_image_surface_get_width (surface),
                                     cairo_image_surface_get_height (surface),
                                     GDK_MEMORY_DEFAULT,
@@ -665,13 +689,31 @@ gdk_texture_get_height (GdkTexture *texture)
   return texture->height;
 }
 
+/**
+ * gdk_texture_get_color_space: (attributes org.gtk.Method.get_property=color-space)
+ * @texture: a `GdkTexture`
+ *
+ * Returns the color space associsated with @texture.
+ *
+ * Returns: (transfer none): the color space of the `GdkTexture`
+ *
+ * Since: 4.10
+ */
+GdkColorSpace *
+gdk_texture_get_color_space (GdkTexture *texture)
+{
+  g_return_val_if_fail (GDK_IS_TEXTURE (texture), 0);
+
+  return texture->color_space;
+}
+
 void
 gdk_texture_do_download (GdkTexture      *texture,
                          GdkMemoryFormat  format,
                          guchar          *data,
                          gsize            stride)
 {
-  GDK_TEXTURE_GET_CLASS (texture)->download (texture, format, data,stride);
+  GDK_TEXTURE_GET_CLASS (texture)->download (texture, format, data, stride);
 }
 
 cairo_surface_t *
@@ -751,7 +793,7 @@ gdk_texture_set_render_data (GdkTexture     *self,
                              GDestroyNotify  notify)
 {
   g_return_val_if_fail (data != NULL, FALSE);
- 
+
   if (self->render_key != NULL)
     return FALSE;
 
diff --git a/gdk/gdktexture.h b/gdk/gdktexture.h
index 8ce4bae5b2..fb52f66f50 100644
--- a/gdk/gdktexture.h
+++ b/gdk/gdktexture.h
@@ -82,6 +82,8 @@ GDK_AVAILABLE_IN_ALL
 int                     gdk_texture_get_width                  (GdkTexture      *texture) G_GNUC_PURE;
 GDK_AVAILABLE_IN_ALL
 int                     gdk_texture_get_height                 (GdkTexture      *texture) G_GNUC_PURE;
+GDK_AVAILABLE_IN_4_10
+GdkColorSpace *         gdk_texture_get_color_space            (GdkTexture      *texture) G_GNUC_PURE;
 
 GDK_AVAILABLE_IN_ALL
 void                    gdk_texture_download                   (GdkTexture      *texture,
diff --git a/gdk/gdktextureprivate.h b/gdk/gdktextureprivate.h
index fd9f78053e..7102cecac2 100644
--- a/gdk/gdktextureprivate.h
+++ b/gdk/gdktextureprivate.h
@@ -18,6 +18,7 @@ struct _GdkTexture
   GdkMemoryFormat format;
   int width;
   int height;
+  GdkColorSpace *color_space;
 
   gpointer render_key;
   gpointer render_data;


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