gdk: Add GdkMemoryTexture::color-state

This allows setting the color state of textures.
This commit is contained in:
Benjamin Otte 2024-07-14 21:52:00 +02:00
parent 05953a20cc
commit 5e1c3c5d69
3 changed files with 80 additions and 1 deletions

View File

@ -135,7 +135,7 @@ gdk_memory_texture_new_from_builder (GdkMemoryTextureBuilder *builder)
self = g_object_new (GDK_TYPE_MEMORY_TEXTURE, self = g_object_new (GDK_TYPE_MEMORY_TEXTURE,
"width", gdk_memory_texture_builder_get_width (builder), "width", gdk_memory_texture_builder_get_width (builder),
"height", gdk_memory_texture_builder_get_height (builder), "height", gdk_memory_texture_builder_get_height (builder),
"color-state", GDK_COLOR_STATE_SRGB, "color-state", gdk_memory_texture_builder_get_color_state (builder),
NULL); NULL);
texture = GDK_TEXTURE (self); texture = GDK_TEXTURE (self);

View File

@ -21,6 +21,7 @@
#include "gdkmemorytexturebuilder.h" #include "gdkmemorytexturebuilder.h"
#include "gdkcolorstate.h"
#include "gdkenumtypes.h" #include "gdkenumtypes.h"
#include "gdkmemorytextureprivate.h" #include "gdkmemorytextureprivate.h"
@ -35,6 +36,7 @@ struct _GdkMemoryTextureBuilder
int width; int width;
int height; int height;
GdkMemoryFormat format; GdkMemoryFormat format;
GdkColorState *color_state;
GdkTexture *update_texture; GdkTexture *update_texture;
cairo_region_t *update_region; cairo_region_t *update_region;
@ -67,6 +69,7 @@ enum
{ {
PROP_0, PROP_0,
PROP_BYTES, PROP_BYTES,
PROP_COLOR_STATE,
PROP_FORMAT, PROP_FORMAT,
PROP_HEIGHT, PROP_HEIGHT,
PROP_STRIDE, PROP_STRIDE,
@ -87,6 +90,7 @@ gdk_memory_texture_builder_dispose (GObject *object)
GdkMemoryTextureBuilder *self = GDK_MEMORY_TEXTURE_BUILDER (object); GdkMemoryTextureBuilder *self = GDK_MEMORY_TEXTURE_BUILDER (object);
g_clear_pointer (&self->bytes, g_bytes_unref); g_clear_pointer (&self->bytes, g_bytes_unref);
g_clear_pointer (&self->color_state, gdk_color_state_unref);
g_clear_object (&self->update_texture); g_clear_object (&self->update_texture);
g_clear_pointer (&self->update_region, cairo_region_destroy); g_clear_pointer (&self->update_region, cairo_region_destroy);
@ -108,6 +112,10 @@ gdk_memory_texture_builder_get_property (GObject *object,
g_value_set_boxed (value, self->bytes); g_value_set_boxed (value, self->bytes);
break; break;
case PROP_COLOR_STATE:
g_value_set_boxed (value, self->color_state);
break;
case PROP_FORMAT: case PROP_FORMAT:
g_value_set_enum (value, self->format); g_value_set_enum (value, self->format);
break; break;
@ -152,6 +160,10 @@ gdk_memory_texture_builder_set_property (GObject *object,
gdk_memory_texture_builder_set_bytes (self, g_value_get_boxed (value)); gdk_memory_texture_builder_set_bytes (self, g_value_get_boxed (value));
break; break;
case PROP_COLOR_STATE:
gdk_memory_texture_builder_set_color_state (self, g_value_get_boxed (value));
break;
case PROP_FORMAT: case PROP_FORMAT:
gdk_memory_texture_builder_set_format (self, g_value_get_enum (value)); gdk_memory_texture_builder_set_format (self, g_value_get_enum (value));
break; break;
@ -203,6 +215,18 @@ gdk_memory_texture_builder_class_init (GdkMemoryTextureBuilderClass *klass)
G_TYPE_BYTES, G_TYPE_BYTES,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GdkMemoryTextureBuilder:color-state:
*
* The colorstate describing the data.
*
* Since: 4.16
*/
properties[PROP_COLOR_STATE] =
g_param_spec_boxed ("color-state", NULL, NULL,
GDK_TYPE_COLOR_STATE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/** /**
* GdkMemoryTextureBuilder:format: * GdkMemoryTextureBuilder:format:
* *
@ -286,6 +310,7 @@ static void
gdk_memory_texture_builder_init (GdkMemoryTextureBuilder *self) gdk_memory_texture_builder_init (GdkMemoryTextureBuilder *self)
{ {
self->format = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED; self->format = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
self->color_state = gdk_color_state_ref (gdk_color_state_get_srgb ());
} }
/** /**
@ -351,6 +376,54 @@ gdk_memory_texture_builder_set_bytes (GdkMemoryTextureBuilder *self,
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_BYTES]); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_BYTES]);
} }
/**
* gdk_memory_texture_builder_get_color_state: (attributes org.gtk.Method.get_property=color-state)
* @self: a `GdkMemoryTextureBuilder`
*
* Gets the colorstate previously set via gdk_memory_texture_builder_set_color_state().
*
* Returns: (transfer none): The colorstate
*
* Since: 4.16
*/
GdkColorState *
gdk_memory_texture_builder_get_color_state (GdkMemoryTextureBuilder *self)
{
g_return_val_if_fail (GDK_IS_MEMORY_TEXTURE_BUILDER (self), NULL);
return self->color_state;
}
/**
* gdk_memory_texture_builder_set_color_state: (attributes org.gtk.Method.set_property=color-state)
* @self: a `GdkMemoryTextureBuilder`
* @color_state: (nullable): The colorstate describing the data
*
* Sets the colorstate describing the data.
*
* By default, the sRGB colorstate is used. If you don't know
* what colorstates are, this is probably the right thing.
*
* Since: 4.16
*/
void
gdk_memory_texture_builder_set_color_state (GdkMemoryTextureBuilder *self,
GdkColorState *color_state)
{
g_return_if_fail (GDK_IS_MEMORY_TEXTURE_BUILDER (self));
g_return_if_fail (color_state != NULL);
if (self->color_state == color_state)
return;
g_clear_pointer (&self->color_state, gdk_color_state_unref);
self->color_state = color_state;
if (color_state)
gdk_color_state_ref (color_state);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COLOR_STATE]);
}
/** /**
* gdk_memory_texture_builder_get_height: (attributes org.gtk.Method.get_property=height) * gdk_memory_texture_builder_get_height: (attributes org.gtk.Method.get_property=height)
* @self: a `GdkMemoryTextureBuilder` * @self: a `GdkMemoryTextureBuilder`

View File

@ -64,6 +64,12 @@ GDK_AVAILABLE_IN_4_16
void gdk_memory_texture_builder_set_format (GdkMemoryTextureBuilder *self, void gdk_memory_texture_builder_set_format (GdkMemoryTextureBuilder *self,
GdkMemoryFormat format); GdkMemoryFormat format);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_memory_texture_builder_get_color_state (GdkMemoryTextureBuilder *self) G_GNUC_PURE;
GDK_AVAILABLE_IN_4_16
void gdk_memory_texture_builder_set_color_state (GdkMemoryTextureBuilder *self,
GdkColorState *color_state);
GDK_AVAILABLE_IN_4_16 GDK_AVAILABLE_IN_4_16
GdkTexture * gdk_memory_texture_builder_get_update_texture (GdkMemoryTextureBuilder *self) G_GNUC_PURE; GdkTexture * gdk_memory_texture_builder_get_update_texture (GdkMemoryTextureBuilder *self) G_GNUC_PURE;
GDK_AVAILABLE_IN_4_16 GDK_AVAILABLE_IN_4_16