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




commit d1b3cd9e7a6817f77942e7e64abc84730e8490a3
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 b1c2211763..31db07130b 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 ef7123c94a..2641655fb9 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -39,6 +39,7 @@
 
 #include "gdktextureprivate.h"
 
+#include "gdkcolorspace.h"
 #include "gdkintl.h"
 #include "gdkmemorytextureprivate.h"
 #include "gdkpaintable.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.8
+   */
+  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.8
+ */
+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 531ae3bbde..00fe6810f0 100644
--- a/gdk/gdktexture.h
+++ b/gdk/gdktexture.h
@@ -84,6 +84,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_8
+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]