mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-09 10:20:07 +00:00
gdk: Give textures a color state
Adds gdk_texture_get_color_state() and GdkTexture::color-state property. All texture implementations initialize the property to SRGB for now.
This commit is contained in:
parent
bdb6b10be8
commit
5297c5f2ee
@ -20,6 +20,7 @@
|
||||
|
||||
#include "gdkdmabuftextureprivate.h"
|
||||
|
||||
#include "gdkcolorstateprivate.h"
|
||||
#include "gdkdisplayprivate.h"
|
||||
#include "gdkdmabufdownloaderprivate.h"
|
||||
#include "gdkdmabufformatsbuilderprivate.h"
|
||||
@ -200,6 +201,7 @@ gdk_dmabuf_texture_new_from_builder (GdkDmabufTextureBuilder *builder,
|
||||
self = g_object_new (GDK_TYPE_DMABUF_TEXTURE,
|
||||
"width", width,
|
||||
"height", height,
|
||||
"color-state", GDK_COLOR_STATE_SRGB,
|
||||
NULL);
|
||||
|
||||
g_set_object (&self->display, display);
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "gdkgltextureprivate.h"
|
||||
|
||||
#include "gdkcolorstateprivate.h"
|
||||
#include "gdkdisplayprivate.h"
|
||||
#include "gdkglcontextprivate.h"
|
||||
#include "gdkmemoryformatprivate.h"
|
||||
@ -488,6 +489,7 @@ gdk_gl_texture_new_from_builder (GdkGLTextureBuilder *builder,
|
||||
self = g_object_new (GDK_TYPE_GL_TEXTURE,
|
||||
"width", gdk_gl_texture_builder_get_width (builder),
|
||||
"height", gdk_gl_texture_builder_get_height (builder),
|
||||
"color-state", GDK_COLOR_STATE_SRGB,
|
||||
NULL);
|
||||
|
||||
self->context = g_object_ref (gdk_gl_texture_builder_get_context (builder));
|
||||
@ -682,6 +684,7 @@ gdk_gl_texture_new (GdkGLContext *context,
|
||||
self = g_object_new (GDK_TYPE_GL_TEXTURE,
|
||||
"width", width,
|
||||
"height", height,
|
||||
"color-state", GDK_COLOR_STATE_SRGB,
|
||||
NULL);
|
||||
|
||||
self->context = g_object_ref (context);
|
||||
|
@ -21,8 +21,8 @@
|
||||
|
||||
#include "gdkmemorytextureprivate.h"
|
||||
|
||||
#include "gdkcolorstateprivate.h"
|
||||
#include "gdkmemoryformatprivate.h"
|
||||
#include "gsk/gl/fp16private.h"
|
||||
|
||||
/**
|
||||
* GdkMemoryTexture:
|
||||
@ -159,6 +159,7 @@ gdk_memory_texture_new (int width,
|
||||
self = g_object_new (GDK_TYPE_MEMORY_TEXTURE,
|
||||
"width", width,
|
||||
"height", height,
|
||||
"color-state", GDK_COLOR_STATE_SRGB,
|
||||
NULL);
|
||||
|
||||
GDK_TEXTURE (self)->format = format;
|
||||
|
@ -40,11 +40,12 @@
|
||||
|
||||
#include "gdktextureprivate.h"
|
||||
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include "gdkcolorstateprivate.h"
|
||||
#include "gdkmemorytextureprivate.h"
|
||||
#include "gdkpaintable.h"
|
||||
#include "gdksnapshot.h"
|
||||
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include <graphene.h>
|
||||
#include "loaders/gdkpngprivate.h"
|
||||
#include "loaders/gdktiffprivate.h"
|
||||
@ -69,6 +70,7 @@ enum {
|
||||
PROP_0,
|
||||
PROP_WIDTH,
|
||||
PROP_HEIGHT,
|
||||
PROP_COLOR_STATE,
|
||||
|
||||
N_PROPS
|
||||
};
|
||||
@ -282,6 +284,11 @@ gdk_texture_set_property (GObject *gobject,
|
||||
self->height = g_value_get_int (value);
|
||||
break;
|
||||
|
||||
case PROP_COLOR_STATE:
|
||||
self->color_state = g_value_dup_boxed (value);
|
||||
g_assert (self->color_state);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
||||
break;
|
||||
@ -306,6 +313,10 @@ gdk_texture_get_property (GObject *gobject,
|
||||
g_value_set_int (value, self->height);
|
||||
break;
|
||||
|
||||
case PROP_COLOR_STATE:
|
||||
g_value_set_boxed (value, self->color_state);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
||||
break;
|
||||
@ -347,6 +358,16 @@ gdk_texture_dispose (GObject *object)
|
||||
G_OBJECT_CLASS (gdk_texture_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_texture_finalize (GObject *object)
|
||||
{
|
||||
GdkTexture *self = GDK_TEXTURE (object);
|
||||
|
||||
gdk_color_state_unref (self->color_state);
|
||||
|
||||
G_OBJECT_CLASS (gdk_texture_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_texture_class_init (GdkTextureClass *klass)
|
||||
{
|
||||
@ -357,6 +378,7 @@ gdk_texture_class_init (GdkTextureClass *klass)
|
||||
gobject_class->set_property = gdk_texture_set_property;
|
||||
gobject_class->get_property = gdk_texture_get_property;
|
||||
gobject_class->dispose = gdk_texture_dispose;
|
||||
gobject_class->finalize = gdk_texture_finalize;
|
||||
|
||||
/**
|
||||
* GdkTexture:width: (attributes org.gtk.Property.get=gdk_texture_get_width)
|
||||
@ -388,12 +410,28 @@ gdk_texture_class_init (GdkTextureClass *klass)
|
||||
G_PARAM_STATIC_STRINGS |
|
||||
G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
/**
|
||||
* GdkTexture:color-state: (attributes org.gtk.Property.get=gdk_texture_get_color_state)
|
||||
*
|
||||
* The color state of the texture.
|
||||
*
|
||||
* Since: 4.16
|
||||
*/
|
||||
properties[PROP_COLOR_STATE] =
|
||||
g_param_spec_boxed ("color-state", NULL, NULL,
|
||||
GDK_TYPE_COLOR_STATE,
|
||||
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);
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_texture_init (GdkTexture *self)
|
||||
{
|
||||
self->color_state = gdk_color_state_get_srgb ();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -727,6 +765,24 @@ gdk_texture_get_height (GdkTexture *texture)
|
||||
return texture->height;
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_texture_get_color_state: (attributes org.gtk.Method.get_property=color-state)
|
||||
* @self: a `GdkTexture`
|
||||
*
|
||||
* Returns the color state associated with the texture.
|
||||
*
|
||||
* Returns: (transfer none): the color state of the `GdkTexture`
|
||||
*
|
||||
* Since: 4.16
|
||||
*/
|
||||
GdkColorState *
|
||||
gdk_texture_get_color_state (GdkTexture *self)
|
||||
{
|
||||
g_return_val_if_fail (GDK_IS_TEXTURE (self), NULL);
|
||||
|
||||
return self->color_state;
|
||||
}
|
||||
|
||||
void
|
||||
gdk_texture_do_download (GdkTexture *texture,
|
||||
GdkMemoryFormat format,
|
||||
@ -1086,3 +1142,4 @@ gdk_texture_save_to_tiff_bytes (GdkTexture *texture)
|
||||
|
||||
return gdk_save_tiff (texture);
|
||||
}
|
||||
|
||||
|
@ -83,6 +83,9 @@ int gdk_texture_get_height (GdkTexture
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
GdkMemoryFormat gdk_texture_get_format (GdkTexture *self) G_GNUC_PURE;
|
||||
|
||||
GDK_AVAILABLE_IN_4_16
|
||||
GdkColorState * gdk_texture_get_color_state (GdkTexture *self);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gdk_texture_download (GdkTexture *texture,
|
||||
guchar *data,
|
||||
|
@ -25,6 +25,7 @@ struct _GdkTexture
|
||||
GdkMemoryFormat format;
|
||||
int width;
|
||||
int height;
|
||||
GdkColorState *color_state;
|
||||
|
||||
gpointer render_key;
|
||||
gpointer render_data;
|
||||
|
@ -73,6 +73,7 @@ compare_textures (GdkTexture *texture1,
|
||||
|
||||
g_assert_true (gdk_texture_get_width (texture1) == gdk_texture_get_width (texture2));
|
||||
g_assert_true (gdk_texture_get_height (texture1) == gdk_texture_get_height (texture2));
|
||||
g_assert_true (gdk_texture_get_color_state (texture1) == gdk_texture_get_color_state (texture2));
|
||||
|
||||
width = gdk_texture_get_width (texture1);
|
||||
height = gdk_texture_get_height (texture1);
|
||||
@ -144,6 +145,7 @@ static void
|
||||
test_texture_from_resource (void)
|
||||
{
|
||||
GdkTexture *texture;
|
||||
GdkColorState *color_state;
|
||||
int width, height;
|
||||
|
||||
texture = gdk_texture_new_from_resource ("/org/gtk/libgtk/icons/16x16/places/user-trash.png");
|
||||
@ -152,10 +154,13 @@ test_texture_from_resource (void)
|
||||
g_object_get (texture,
|
||||
"width", &width,
|
||||
"height", &height,
|
||||
"color-state", &color_state,
|
||||
NULL);
|
||||
g_assert_cmpint (width, ==, 16);
|
||||
g_assert_cmpint (height, ==, 16);
|
||||
g_assert_true (gdk_color_state_equal (color_state, gdk_color_state_get_srgb ()));
|
||||
|
||||
gdk_color_state_unref (color_state);
|
||||
g_object_unref (texture);
|
||||
}
|
||||
|
||||
@ -237,6 +242,8 @@ test_texture_subtexture (void)
|
||||
|
||||
g_assert_cmpint (gdk_texture_get_width (subtexture), ==, 32);
|
||||
g_assert_cmpint (gdk_texture_get_height (subtexture), ==, 32);
|
||||
g_assert_true (gdk_color_state_equal (gdk_texture_get_color_state (subtexture),
|
||||
gdk_texture_get_color_state (texture)));
|
||||
|
||||
data = g_new0 (guchar, 64 * 64 * 4);
|
||||
stride = 64 * 4;
|
||||
|
Loading…
Reference in New Issue
Block a user