[gtk/wip/otte/colorspace: 58/59] API: Add GdkSurface::color-space
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/colorspace: 58/59] API: Add GdkSurface::color-space
- Date: Sat, 23 Oct 2021 00:39:31 +0000 (UTC)
commit 44f1ea42cc379599606a4f05dcb890e8e7966d1a
Author: Benjamin Otte <otte redhat com>
Date: Fri Sep 24 20:07:56 2021 +0200
API: Add GdkSurface::color-space
Unused so far, but there's a private setter for backends and a public
readable property for code.
gdk/gdksurface.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++---
gdk/gdksurface.h | 18 +++++++------
gdk/gdksurfaceprivate.h | 2 ++
3 files changed, 80 insertions(+), 12 deletions(-)
---
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index 5b0c947ed3..4e4e88928e 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -30,6 +30,7 @@
#include "gdksurface.h"
#include "gdk-private.h"
+#include "gdkcolorspace.h"
#include "gdkcontentprovider.h"
#include "gdkdeviceprivate.h"
#include "gdkdisplayprivate.h"
@@ -74,6 +75,8 @@ struct _GdkSurfacePrivate
gboolean egl_surface_high_depth;
#endif
+ GdkColorSpace *color_space;
+
gpointer widget;
};
@@ -88,13 +91,14 @@ enum {
enum {
PROP_0,
+ PROP_COLOR_SPACE,
PROP_CURSOR,
PROP_DISPLAY,
PROP_FRAME_CLOCK,
- PROP_MAPPED,
- PROP_WIDTH,
PROP_HEIGHT,
+ PROP_MAPPED,
PROP_SCALE_FACTOR,
+ PROP_WIDTH,
LAST_PROP
};
@@ -476,7 +480,7 @@ gdk_surface_event_marshallerv (GClosure *closure,
static void
gdk_surface_init (GdkSurface *surface)
{
- /* 0-initialization is good for all other fields. */
+ GdkSurfacePrivate *priv = gdk_surface_get_instance_private (surface);
surface->state = 0;
surface->fullscreen_mode = GDK_FULLSCREEN_ON_CURRENT_MONITOR;
@@ -485,8 +489,10 @@ gdk_surface_init (GdkSurface *surface)
surface->alpha = 255;
+ priv->color_space = g_object_ref (gdk_color_space_get_srgb ());
+
surface->device_cursor = g_hash_table_new_full (NULL, NULL,
- NULL, g_object_unref);
+ NULL, g_object_unref);
}
static void
@@ -500,6 +506,24 @@ gdk_surface_class_init (GdkSurfaceClass *klass)
klass->beep = gdk_surface_real_beep;
+ /**
+ * GdkSurface:color-space: (attributes org.gtk.Property.get=gdk_surface_get_color_space)
+ *
+ * The color space for rendering to the surface
+ *
+ * This space is negotiated between GTK and the compositor.
+ *
+ * The color space 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 shown,
+ * the color space may not represent the actual color space that is going to be used.
+ */
+ properties[PROP_COLOR_SPACE] =
+ g_param_spec_object ("color-space",
+ P_("Color space"),
+ P_("The preferred color space of the surface"),
+ GDK_TYPE_COLOR_SPACE,
+ 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)
*
@@ -713,6 +737,7 @@ static void
gdk_surface_finalize (GObject *object)
{
GdkSurface *surface = GDK_SURFACE (object);
+ GdkSurfacePrivate *priv = gdk_surface_get_instance_private (surface);
g_clear_handle_id (&surface->request_motion_id, g_source_remove);
@@ -729,6 +754,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 (&priv->color_space);
g_clear_object (&surface->display);
@@ -783,6 +809,10 @@ gdk_surface_get_property (GObject *object,
switch (prop_id)
{
+ case PROP_COLOR_SPACE:
+ g_value_set_object (value, gdk_surface_get_color_space (surface));
+ break;
+
case PROP_CURSOR:
g_value_set_object (value, gdk_surface_get_cursor (surface));
break;
@@ -2049,6 +2079,40 @@ gdk_surface_get_height (GdkSurface *surface)
return surface->height;
}
+void
+gdk_surface_set_color_space (GdkSurface *self,
+ GdkColorSpace *color_space)
+{
+ GdkSurfacePrivate *priv = gdk_surface_get_instance_private (self);
+
+ if (gdk_color_space_equal (priv->color_space, color_space))
+ return;
+
+ g_set_object (&priv->color_space, color_space);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COLOR_SPACE]);
+}
+
+/**
+ * gdk_surface_get_color_space: (attributes org.gtk.Method.get_property=color-space)
+ * @self: a `GdkSurface`
+ *
+ * Returns the color space for rendering to the given @surface.
+ *
+ * Renderers will need to provide data in this color space.
+ *
+ * Returns: (transfer none): The color space of @surface
+ */
+GdkColorSpace *
+gdk_surface_get_color_space (GdkSurface *self)
+{
+ GdkSurfacePrivate *priv = gdk_surface_get_instance_private (self);
+
+ g_return_val_if_fail (GDK_IS_SURFACE (self), gdk_color_space_get_srgb ());
+
+ return priv->color_space;
+}
+
/*
* gdk_surface_get_origin:
* @surface: a `GdkSurface`
diff --git a/gdk/gdksurface.h b/gdk/gdksurface.h
index 4e083ec07b..858caa2be5 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
+GdkColorSpace * gdk_surface_get_color_space (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..713c20fb17 100644
--- a/gdk/gdksurfaceprivate.h
+++ b/gdk/gdksurfaceprivate.h
@@ -171,6 +171,8 @@ void gdk_surface_set_state (GdkSurface *surface,
void gdk_surface_set_is_mapped (GdkSurface *surface,
gboolean is_mapped);
+void gdk_surface_set_color_space (GdkSurface *self,
+ GdkColorSpace *color_space);
GdkMonitor * gdk_surface_get_layout_monitor (GdkSurface *surface,
GdkPopupLayout *layout,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]