[gtk/wip/otte/color-profiles: 55/82] API: Add GdkSurface::color-profile




commit 0df63b028605ca8f99d57f78ef4f5e9da3b9a7b9
Author: Benjamin Otte <otte redhat com>
Date:   Fri Sep 24 20:07:56 2021 +0200

    API: Add GdkSurface::color-profile
    
    Unused so far, but there's a private setter for backends and a public
    readable property for code.

 gdk/gdksurface.c        | 59 +++++++++++++++++++++++++++++++++++++++++++++++--
 gdk/gdksurface.h        | 18 ++++++++-------
 gdk/gdksurfaceprivate.h |  3 +++
 3 files changed, 70 insertions(+), 10 deletions(-)
---
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index 13d779a817..921c037916 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -30,6 +30,7 @@
 #include "gdksurface.h"
 
 #include "gdk-private.h"
+#include "gdkcolorprofile.h"
 #include "gdkcontentprovider.h"
 #include "gdkdeviceprivate.h"
 #include "gdkdisplayprivate.h"
@@ -88,13 +89,14 @@ enum {
 
 enum {
   PROP_0,
+  PROP_COLOR_PROFILE,
   PROP_CURSOR,
   PROP_DISPLAY,
   PROP_FRAME_CLOCK,
-  PROP_MAPPED,
-  PROP_WIDTH,
   PROP_HEIGHT,
+  PROP_MAPPED,
   PROP_SCALE_FACTOR,
+  PROP_WIDTH,
   LAST_PROP
 };
 
@@ -485,6 +487,8 @@ gdk_surface_init (GdkSurface *surface)
 
   surface->alpha = 255;
 
+  surface->color_profile = g_object_ref (gdk_color_profile_get_srgb ());
+
   surface->device_cursor = g_hash_table_new_full (NULL, NULL,
                                                  NULL, g_object_unref);
 }
@@ -500,6 +504,24 @@ gdk_surface_class_init (GdkSurfaceClass *klass)
 
   klass->beep = gdk_surface_real_beep;
 
+  /**
+   * GdkSurface:color-profile: (attributes org.gtk.Property.get=gdk_surface_get_color_profile)
+   *
+   * The preferred color profile for rendering to the surface
+   *
+   * This profile is negotiated between GTK and the compositor.
+   *
+   * The profile may change as the surface gets moved around - for example to different
+   * monitors or when the compositor gets reconfigured. As long as the surface isn't show, the
+   * profile may not represent the actual color profile that is going to be used.
+   */
+  properties[PROP_COLOR_PROFILE] =
+      g_param_spec_object ("color-profile",
+                           P_("Color profile"),
+                           P_("The preferred color profile of the surface"),
+                           GDK_TYPE_COLOR_PROFILE,
+                           G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
   /**
    * GdkSurface:cursor: (attributes org.gtk.Property.get=gdk_surface_get_cursor 
org.gtk.Property.set=gdk_surface_set_cursor)
    *
@@ -729,6 +751,7 @@ gdk_surface_finalize (GObject *object)
   g_clear_object (&surface->cursor);
   g_clear_pointer (&surface->device_cursor, g_hash_table_destroy);
   g_clear_pointer (&surface->devices_inside, g_list_free);
+  g_clear_object (&surface->color_profile);
 
   g_clear_object (&surface->display);
 
@@ -783,6 +806,10 @@ gdk_surface_get_property (GObject    *object,
 
   switch (prop_id)
     {
+    case PROP_COLOR_PROFILE:
+      g_value_set_object (value, gdk_surface_get_color_profile (surface));
+      break;
+
     case PROP_CURSOR:
       g_value_set_object (value, gdk_surface_get_cursor (surface));
       break;
@@ -2049,6 +2076,34 @@ gdk_surface_get_height (GdkSurface *surface)
   return surface->height;
 }
 
+void
+gdk_surface_set_color_profile (GdkSurface      *self,
+                               GdkColorProfile *color_profile)
+{
+  if (gdk_color_profile_equal (self->color_profile, color_profile))
+    return;
+
+  g_set_object (&self->color_profile, color_profile);
+
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COLOR_PROFILE]);
+}
+
+/**
+ * gdk_surface_get_color_profile: (attributes org.gtk.Method.get_property=color-profile)
+ * @self: a `GdkSurface`
+ *
+ * Returns the preferred color profile for rendering to the given @surface.
+ *
+ * Returns: (transfer none): The color profile of @surface
+ */
+GdkColorProfile *
+gdk_surface_get_color_profile (GdkSurface *self)
+{
+  g_return_val_if_fail (GDK_IS_SURFACE (self), gdk_color_profile_get_srgb ());
+
+  return self->color_profile;
+}
+
 /*
  * gdk_surface_get_origin:
  * @surface: a `GdkSurface`
diff --git a/gdk/gdksurface.h b/gdk/gdksurface.h
index 4e083ec07b..7e946f2bcb 100644
--- a/gdk/gdksurface.h
+++ b/gdk/gdksurface.h
@@ -86,17 +86,19 @@ GDK_AVAILABLE_IN_ALL
 GdkCursor    *gdk_surface_get_device_cursor (GdkSurface     *surface,
                                              GdkDevice     *device);
 GDK_AVAILABLE_IN_ALL
-int           gdk_surface_get_width       (GdkSurface       *surface);
+int                     gdk_surface_get_width                   (GdkSurface             *surface);
 GDK_AVAILABLE_IN_ALL
-int           gdk_surface_get_height      (GdkSurface       *surface);
+int                     gdk_surface_get_height                  (GdkSurface             *surface);
 GDK_AVAILABLE_IN_ALL
-gboolean gdk_surface_translate_coordinates (GdkSurface *from,
-                                            GdkSurface *to,
-                                            double     *x,
-                                            double     *y);
-
+int                     gdk_surface_get_scale_factor            (GdkSurface             *surface);
+GDK_AVAILABLE_IN_4_6
+GdkColorProfile *       gdk_surface_get_color_profile           (GdkSurface             *self);
 GDK_AVAILABLE_IN_ALL
-int           gdk_surface_get_scale_factor  (GdkSurface     *surface);
+gboolean                gdk_surface_translate_coordinates       (GdkSurface             *from,
+                                                                 GdkSurface             *to,
+                                                                 double                 *x,
+                                                                 double                 *y);
+
 
 GDK_AVAILABLE_IN_ALL
 gboolean      gdk_surface_get_device_position (GdkSurface      *surface,
diff --git a/gdk/gdksurfaceprivate.h b/gdk/gdksurfaceprivate.h
index c53368574d..30985fa88d 100644
--- a/gdk/gdksurfaceprivate.h
+++ b/gdk/gdksurfaceprivate.h
@@ -52,6 +52,7 @@ struct _GdkSurface
   int y;
 
   GdkGLContext *gl_paint_context;
+  GdkColorProfile *color_profile;
 
   cairo_region_t *update_area;
   guint update_freeze_count;
@@ -171,6 +172,8 @@ void gdk_surface_set_state (GdkSurface      *surface,
 
 void gdk_surface_set_is_mapped (GdkSurface *surface,
                                 gboolean    is_mapped);
+void gdk_surface_set_color_profile (GdkSurface      *self,
+                                    GdkColorProfile *color_profile);
 
 GdkMonitor * gdk_surface_get_layout_monitor (GdkSurface      *surface,
                                              GdkPopupLayout  *layout,


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