From 2c96391bd237459a6b41752704cee66d10603748 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Fri, 24 Sep 2021 20:07:56 +0200 Subject: [PATCH] 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 | 63 +++++++++++++++++++++++++++++++++++++++-- gdk/gdksurface.h | 18 ++++++------ gdk/gdksurfaceprivate.h | 3 ++ 3 files changed, 74 insertions(+), 10 deletions(-) diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c index 16d668a931..f9733bc97b 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,26 @@ 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. + * + * Since: 4.8 + */ + 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) * @@ -732,6 +756,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); @@ -786,6 +811,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; @@ -2054,6 +2083,36 @@ 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 + * + * Since: 4.8 + */ +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..bbf3a648f6 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_8 +GdkColorProfile * gdk_surface_get_color_profile (GdkSurface *self); +GDK_AVAILABLE_IN_ALL +gboolean gdk_surface_translate_coordinates (GdkSurface *from, + GdkSurface *to, + double *x, + double *y); -GDK_AVAILABLE_IN_ALL -int gdk_surface_get_scale_factor (GdkSurface *surface); 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,