diff --git a/gdk/gdkdmabuftexture.c b/gdk/gdkdmabuftexture.c index 62fea85f25..fb5450532b 100644 --- a/gdk/gdkdmabuftexture.c +++ b/gdk/gdkdmabuftexture.c @@ -204,7 +204,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, + "color-state", gdk_dmabuf_texture_builder_get_color_state (builder), NULL); g_set_object (&self->display, display); diff --git a/gdk/gdkdmabuftexturebuilder.c b/gdk/gdkdmabuftexturebuilder.c index 6508d9c2cf..055ed6f9ea 100644 --- a/gdk/gdkdmabuftexturebuilder.c +++ b/gdk/gdkdmabuftexturebuilder.c @@ -24,6 +24,7 @@ #include "gdkdebugprivate.h" #include "gdkdisplay.h" #include "gdkenumtypes.h" +#include "gdkcolorstate.h" #include "gdkdmabuftextureprivate.h" #include "gdkdmabuftexturebuilderprivate.h" @@ -41,6 +42,8 @@ struct _GdkDmabufTextureBuilder GdkDmabuf dmabuf; + GdkColorState *color_state; + GdkTexture *update_texture; cairo_region_t *update_region; }; @@ -124,6 +127,7 @@ enum PROP_MODIFIER, PROP_PREMULTIPLIED, PROP_N_PLANES, + PROP_COLOR_STATE, PROP_UPDATE_REGION, PROP_UPDATE_TEXTURE, @@ -141,6 +145,7 @@ gdk_dmabuf_texture_builder_dispose (GObject *object) g_clear_object (&self->update_texture); g_clear_pointer (&self->update_region, cairo_region_destroy); + g_clear_pointer (&self->color_state, gdk_color_state_unref); G_OBJECT_CLASS (gdk_dmabuf_texture_builder_parent_class)->dispose (object); } @@ -183,6 +188,10 @@ gdk_dmabuf_texture_builder_get_property (GObject *object, g_value_set_uint (value, self->dmabuf.n_planes); break; + case PROP_COLOR_STATE: + g_value_set_boxed (value, self->color_state); + break; + case PROP_UPDATE_REGION: g_value_set_boxed (value, self->update_region); break; @@ -235,6 +244,10 @@ gdk_dmabuf_texture_builder_set_property (GObject *object, gdk_dmabuf_texture_builder_set_n_planes (self, g_value_get_uint (value)); break; + case PROP_COLOR_STATE: + gdk_dmabuf_texture_builder_set_color_state (self, g_value_get_boxed (value)); + break; + case PROP_UPDATE_REGION: gdk_dmabuf_texture_builder_set_update_region (self, g_value_get_boxed (value)); break; @@ -347,6 +360,18 @@ gdk_dmabuf_texture_builder_class_init (GdkDmabufTextureBuilderClass *klass) 1, GDK_DMABUF_MAX_PLANES, 1, G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + /** + * GdkDmabufTextureBuilder: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_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + /** * GdkDmabufTextureBuilder:update-region: (attributes org.gtk.Property.get=gdk_dmabuf_texture_builder_get_update_region org.gtk.Property.set=gdk_dmabuf_texture_builder_set_update_region) * @@ -383,6 +408,8 @@ gdk_dmabuf_texture_builder_init (GdkDmabufTextureBuilder *self) for (int i = 0; i < GDK_DMABUF_MAX_PLANES; i++) self->dmabuf.planes[i].fd = -1; + + self->color_state = gdk_color_state_ref (gdk_color_state_get_srgb ()); } /** @@ -843,6 +870,51 @@ gdk_dmabuf_texture_builder_set_offset (GdkDmabufTextureBuilder *self, self->dmabuf.planes[plane].offset = offset; } +/** + * gdk_dmabuf_texture_builder_get_color_state: (attributes org.gtk.Method.get_property=color-state) + * @self: a `GdkDmabufTextureBuilder` + * + * Gets the color state previously set via gdk_dmabuf_texture_builder_set_color_state(). + * + * Returns: the color state + * + * Since: 4.16 + */ +GdkColorState * +gdk_dmabuf_texture_builder_get_color_state (GdkDmabufTextureBuilder *self) +{ + g_return_val_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self), NULL); + + return self->color_state; +} + +/** + * gdk_dmabuf_texture_builder_set_color_state: (attributes org.gtk.Method.set_property=color-state) + * @self: a `GdkDmabufTextureBuilder` + * @color_state: a `GdkColorState` + * + * Sets the color state for the texture. + * + * 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_dmabuf_texture_builder_set_color_state (GdkDmabufTextureBuilder *self, + GdkColorState *color_state) +{ + g_return_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self)); + g_return_if_fail (color_state != NULL); + + if (gdk_color_state_equal (self->color_state, color_state)) + return; + + g_clear_pointer (&self->color_state, gdk_color_state_unref); + self->color_state = gdk_color_state_ref (color_state); + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COLOR_STATE]); +} + /** * gdk_dmabuf_texture_builder_get_update_texture: (attributes org.gtk.Method.get_property=update-texture) * @self: a `GdkDmabufTextureBuilder` diff --git a/gdk/gdkdmabuftexturebuilder.h b/gdk/gdkdmabuftexturebuilder.h index 88ecfea5cf..28a0f45d6e 100644 --- a/gdk/gdkdmabuftexturebuilder.h +++ b/gdk/gdkdmabuftexturebuilder.h @@ -100,6 +100,12 @@ void gdk_dmabuf_texture_builder_set_offset (GdkDmabufT unsigned int plane, unsigned int offset); +GDK_AVAILABLE_IN_4_16 +GdkColorState * gdk_dmabuf_texture_builder_get_color_state (GdkDmabufTextureBuilder *self); +GDK_AVAILABLE_IN_4_16 +void gdk_dmabuf_texture_builder_set_color_state (GdkDmabufTextureBuilder *self, + GdkColorState *color_state); + GDK_AVAILABLE_IN_4_14 GdkTexture * gdk_dmabuf_texture_builder_get_update_texture (GdkDmabufTextureBuilder *self) G_GNUC_PURE; GDK_AVAILABLE_IN_4_14 diff --git a/testsuite/gtk/defaultvalue.c b/testsuite/gtk/defaultvalue.c index 4734f80120..4f1988699d 100644 --- a/testsuite/gtk/defaultvalue.c +++ b/testsuite/gtk/defaultvalue.c @@ -22,8 +22,8 @@ static void check_property (const char *output, - GParamSpec *pspec, - GValue *value) + GParamSpec *pspec, + GValue *value) { GValue default_value = G_VALUE_INIT; char *v, *dv, *msg; @@ -42,12 +42,12 @@ check_property (const char *output, dv = g_strdup_value_contents (&default_value); msg = g_strdup_printf ("%s %s.%s: %s != %s\n", - output, - g_type_name (pspec->owner_type), - pspec->name, - dv, v); + output, + g_type_name (pspec->owner_type), + pspec->name, + dv, v); g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, - G_STRFUNC, msg); + G_STRFUNC, msg); g_free (msg); g_free (v); @@ -159,16 +159,16 @@ G_GNUC_END_IGNORE_DEPRECATIONS gboolean check = TRUE; if (pspec->owner_type != type) - continue; + continue; if ((pspec->flags & G_PARAM_READABLE) == 0) - continue; + continue; /* This is set by the treelistmodel, plain * g_object_new() will crash here */ if (g_type_is_a (type, GTK_TYPE_TREE_LIST_ROW) && - (strcmp (pspec->name, "item") == 0)) - continue; + (strcmp (pspec->name, "item") == 0)) + continue; /* This is set via class_init, and we have a11y tests to verify it */ if (g_type_is_a (type, GTK_TYPE_ACCESSIBLE) && @@ -181,121 +181,121 @@ G_GNUC_END_IGNORE_DEPRECATIONS check = FALSE; if (g_type_is_a (type, GDK_TYPE_CLIPBOARD) && - strcmp (pspec->name, "display") == 0) - check = FALSE; + strcmp (pspec->name, "display") == 0) + check = FALSE; /* These are set in init() */ if ((g_type_is_a (type, GDK_TYPE_CLIPBOARD) || g_type_is_a (type, GDK_TYPE_CONTENT_PROVIDER) || g_type_is_a (type, GTK_TYPE_DROP_TARGET)) && - strcmp (pspec->name, "formats") == 0) - check = FALSE; + strcmp (pspec->name, "formats") == 0) + check = FALSE; if (g_type_is_a (type, GDK_TYPE_CONTENT_PROVIDER) && - strcmp (pspec->name, "storable-formats") == 0) - check = FALSE; + strcmp (pspec->name, "storable-formats") == 0) + check = FALSE; if (g_type_is_a (type, GDK_TYPE_DMABUF_TEXTURE_BUILDER) && - strcmp (pspec->name, "display") == 0) - check = FALSE; + strcmp (pspec->name, "display") == 0) + check = FALSE; G_GNUC_BEGIN_IGNORE_DEPRECATIONS /* set in the constructor */ if (g_type_is_a (type, GSK_TYPE_GL_SHADER) && - strcmp (pspec->name, "source") == 0) - check = FALSE; + strcmp (pspec->name, "source") == 0) + check = FALSE; G_GNUC_END_IGNORE_DEPRECATIONS /* This one has a special-purpose default value */ if (g_type_is_a (type, GTK_TYPE_DIALOG) && - (strcmp (pspec->name, "use-header-bar") == 0)) - check = FALSE; + (strcmp (pspec->name, "use-header-bar") == 0)) + check = FALSE; if (g_type_is_a (type, GTK_TYPE_ASSISTANT) && - (strcmp (pspec->name, "use-header-bar") == 0 || + (strcmp (pspec->name, "use-header-bar") == 0 || strcmp (pspec->name, "pages") == 0)) /* pages always gets a non-NULL value */ - check = FALSE; + check = FALSE; if (g_type_is_a (type, GTK_TYPE_STACK) && - (strcmp (pspec->name, "pages") == 0)) /* pages always gets a non-NULL value */ - check = FALSE; + (strcmp (pspec->name, "pages") == 0)) /* pages always gets a non-NULL value */ + check = FALSE; if (g_type_is_a (type, GTK_TYPE_NOTEBOOK) && - (strcmp (pspec->name, "pages") == 0)) /* pages always gets a non-NULL value */ - check = FALSE; + (strcmp (pspec->name, "pages") == 0)) /* pages always gets a non-NULL value */ + check = FALSE; if (g_type_is_a (type, GTK_TYPE_COMBO_BOX) && (strcmp (pspec->name, "child") == 0)) check = FALSE; if (g_type_is_a (type, GTK_TYPE_POPOVER) && - (strcmp (pspec->name, "pointing-to") == 0)) - check = FALSE; + (strcmp (pspec->name, "pointing-to") == 0)) + check = FALSE; if (g_type_is_a (type, GDK_TYPE_DISPLAY_MANAGER) && - (strcmp (pspec->name, "default-display") == 0)) - check = FALSE; + (strcmp (pspec->name, "default-display") == 0)) + check = FALSE; if (g_type_is_a (type, GDK_TYPE_DISPLAY) && - (strcmp (pspec->name, "dmabuf-formats") == 0)) - check = FALSE; + (strcmp (pspec->name, "dmabuf-formats") == 0)) + check = FALSE; if (g_type_is_a (type, GDK_TYPE_MONITOR) && (strcmp (pspec->name, "geometry") == 0)) check = FALSE; if (g_type_is_a (type, GTK_TYPE_ABOUT_DIALOG) && - (strcmp (pspec->name, "program-name") == 0)) - check = FALSE; + (strcmp (pspec->name, "program-name") == 0)) + check = FALSE; /* These are set to the current date */ if (g_type_is_a (type, GTK_TYPE_CALENDAR) && - (strcmp (pspec->name, "year") == 0 || - strcmp (pspec->name, "month") == 0 || - strcmp (pspec->name, "day") == 0)) - check = FALSE; + (strcmp (pspec->name, "year") == 0 || + strcmp (pspec->name, "month") == 0 || + strcmp (pspec->name, "day") == 0)) + check = FALSE; if (g_type_is_a (type, GTK_TYPE_CELL_AREA_CONTEXT) && - (strcmp (pspec->name, "minimum-width") == 0 || - strcmp (pspec->name, "minimum-height") == 0 || - strcmp (pspec->name, "natural-width") == 0 || - strcmp (pspec->name, "natural-height") == 0)) - check = FALSE; + (strcmp (pspec->name, "minimum-width") == 0 || + strcmp (pspec->name, "minimum-height") == 0 || + strcmp (pspec->name, "natural-width") == 0 || + strcmp (pspec->name, "natural-height") == 0)) + check = FALSE; if (g_type_is_a (type, GTK_TYPE_CELL_RENDERER_TEXT) && - (strcmp (pspec->name, "background-gdk") == 0 || - strcmp (pspec->name, "foreground-gdk") == 0 || - strcmp (pspec->name, "background-rgba") == 0 || - strcmp (pspec->name, "foreground-rgba") == 0 || - strcmp (pspec->name, "font") == 0 || - strcmp (pspec->name, "font-desc") == 0)) - check = FALSE; + (strcmp (pspec->name, "background-gdk") == 0 || + strcmp (pspec->name, "foreground-gdk") == 0 || + strcmp (pspec->name, "background-rgba") == 0 || + strcmp (pspec->name, "foreground-rgba") == 0 || + strcmp (pspec->name, "font") == 0 || + strcmp (pspec->name, "font-desc") == 0)) + check = FALSE; if (g_type_is_a (type, GTK_TYPE_CELL_VIEW) && - (strcmp (pspec->name, "background-gdk") == 0 || - strcmp (pspec->name, "foreground-gdk") == 0 || - strcmp (pspec->name, "foreground-rgba") == 0 || - strcmp (pspec->name, "background-rgba") == 0 || + (strcmp (pspec->name, "background-gdk") == 0 || + strcmp (pspec->name, "foreground-gdk") == 0 || + strcmp (pspec->name, "foreground-rgba") == 0 || + strcmp (pspec->name, "background-rgba") == 0 || strcmp (pspec->name, "cell-area") == 0 || strcmp (pspec->name, "cell-area-context") == 0)) - check = FALSE; + check = FALSE; if (g_type_is_a (type, GTK_TYPE_COLOR_BUTTON) && - (strcmp (pspec->name, "color") == 0 || - strcmp (pspec->name, "rgba") == 0)) - check = FALSE; + (strcmp (pspec->name, "color") == 0 || + strcmp (pspec->name, "rgba") == 0)) + check = FALSE; if (g_type_is_a (type, GTK_TYPE_COLUMN_VIEW) && (strcmp (pspec->name, "columns") == 0 || - strcmp (pspec->name, "sorter") == 0)) - check = FALSE; + strcmp (pspec->name, "sorter") == 0)) + check = FALSE; G_GNUC_BEGIN_IGNORE_DEPRECATIONS if (g_type_is_a (type, GTK_TYPE_COMBO_BOX) && - (strcmp (pspec->name, "cell-area") == 0 || + (strcmp (pspec->name, "cell-area") == 0 || strcmp (pspec->name, "cell-area-context") == 0)) - check = FALSE; + check = FALSE; G_GNUC_END_IGNORE_DEPRECATIONS @@ -303,21 +303,21 @@ G_GNUC_END_IGNORE_DEPRECATIONS * and buffer gets created on-demand */ if (g_type_is_a (type, GTK_TYPE_ENTRY) && - (strcmp (pspec->name, "invisible-char") == 0 || + (strcmp (pspec->name, "invisible-char") == 0 || strcmp (pspec->name, "buffer") == 0)) - check = FALSE; + check = FALSE; if (g_type_is_a (type, GTK_TYPE_TEXT) && - (strcmp (pspec->name, "invisible-char") == 0 || + (strcmp (pspec->name, "invisible-char") == 0 || strcmp (pspec->name, "buffer") == 0)) - check = FALSE; + check = FALSE; G_GNUC_BEGIN_IGNORE_DEPRECATIONS if (g_type_is_a (type, GTK_TYPE_ENTRY_COMPLETION) && - (strcmp (pspec->name, "cell-area") == 0 || + (strcmp (pspec->name, "cell-area") == 0 || strcmp (pspec->name, "cell-area-context") == 0)) - check = FALSE; + check = FALSE; G_GNUC_END_IGNORE_DEPRECATIONS @@ -329,8 +329,8 @@ G_GNUC_END_IGNORE_DEPRECATIONS check = FALSE; if (g_type_is_a (type, GTK_TYPE_TREE_LIST_MODEL) && - (strcmp (pspec->name, "item-type") == 0)) /* might be a treelistrow */ - check = FALSE; + (strcmp (pspec->name, "item-type") == 0)) /* might be a treelistrow */ + check = FALSE; /* This is set in init() */ if (g_type_is_a (type, GTK_TYPE_FONT_CHOOSER_WIDGET) && @@ -340,30 +340,30 @@ G_GNUC_END_IGNORE_DEPRECATIONS G_GNUC_BEGIN_IGNORE_DEPRECATIONS if (g_type_is_a (type, GTK_TYPE_ICON_VIEW) && - (strcmp (pspec->name, "cell-area") == 0 || + (strcmp (pspec->name, "cell-area") == 0 || strcmp (pspec->name, "cell-area-context") == 0)) - check = FALSE; + check = FALSE; G_GNUC_END_IGNORE_DEPRECATIONS if (g_type_is_a (type, GTK_TYPE_MESSAGE_DIALOG) && (strcmp (pspec->name, "image") == 0 || strcmp (pspec->name, "message-area") == 0)) - check = FALSE; + check = FALSE; if (g_type_is_a (type, GTK_TYPE_PANED) && - strcmp (pspec->name, "max-position") == 0) - check = FALSE; + strcmp (pspec->name, "max-position") == 0) + check = FALSE; if (g_type_is_a (type, GTK_TYPE_PRINT_OPERATION) && - strcmp (pspec->name, "job-name") == 0) - check = FALSE; + strcmp (pspec->name, "job-name") == 0) + check = FALSE; #ifdef G_OS_UNIX if (g_type_is_a (type, GTK_TYPE_PRINT_UNIX_DIALOG) && - (strcmp (pspec->name, "page-setup") == 0 || - strcmp (pspec->name, "print-settings") == 0)) - check = FALSE; + (strcmp (pspec->name, "page-setup") == 0 || + strcmp (pspec->name, "print-settings") == 0)) + check = FALSE; #endif if (g_type_is_a (type, GTK_TYPE_PROGRESS_BAR) && @@ -373,7 +373,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS /* filename value depends on $HOME */ if (g_type_is_a (type, GTK_TYPE_RECENT_MANAGER) && (strcmp (pspec->name, "filename") == 0 || - strcmp (pspec->name, "size") == 0)) + strcmp (pspec->name, "size") == 0)) check = FALSE; if (g_type_is_a (type, GTK_TYPE_SCALE_BUTTON) && @@ -381,15 +381,15 @@ G_GNUC_END_IGNORE_DEPRECATIONS check = FALSE; if (g_type_is_a (type, GTK_TYPE_SCROLLED_WINDOW) && - (strcmp (pspec->name, "hadjustment") == 0 || + (strcmp (pspec->name, "hadjustment") == 0 || strcmp (pspec->name, "vadjustment") == 0)) - check = FALSE; + check = FALSE; if (g_type_is_a (type, GTK_TYPE_SETTINGS)) check = FALSE; if (g_type_is_a (type, GTK_TYPE_SHORTCUT) && - (strcmp (pspec->name, "action") == 0 || + (strcmp (pspec->name, "action") == 0 || strcmp (pspec->name, "trigger") == 0)) check = FALSE; @@ -411,9 +411,9 @@ G_GNUC_END_IGNORE_DEPRECATIONS if (g_type_is_a (type, GTK_TYPE_TEXT_TAG) && (strcmp (pspec->name, "background-gdk") == 0 || strcmp (pspec->name, "foreground-gdk") == 0 || - strcmp (pspec->name, "language") == 0 || - strcmp (pspec->name, "font") == 0 || - strcmp (pspec->name, "font-desc") == 0)) + strcmp (pspec->name, "language") == 0 || + strcmp (pspec->name, "font") == 0 || + strcmp (pspec->name, "font-desc") == 0)) check = FALSE; if (g_type_is_a (type, GTK_TYPE_TEXT_VIEW) && @@ -421,25 +421,25 @@ G_GNUC_END_IGNORE_DEPRECATIONS check = FALSE; if (g_type_is_a (type, GTK_TYPE_TREE_VIEW) && - (strcmp (pspec->name, "hadjustment") == 0 || + (strcmp (pspec->name, "hadjustment") == 0 || strcmp (pspec->name, "vadjustment") == 0)) - check = FALSE; + check = FALSE; if (g_type_is_a (type, GTK_TYPE_TREE_VIEW_COLUMN) && - (strcmp (pspec->name, "cell-area") == 0 || + (strcmp (pspec->name, "cell-area") == 0 || strcmp (pspec->name, "cell-area-context") == 0)) - check = FALSE; + check = FALSE; if (g_type_is_a (type, GTK_TYPE_VIEWPORT) && - (strcmp (pspec->name, "hadjustment") == 0 || + (strcmp (pspec->name, "hadjustment") == 0 || strcmp (pspec->name, "vadjustment") == 0)) - check = FALSE; + check = FALSE; if (g_type_is_a (type, GTK_TYPE_WIDGET) && (strcmp (pspec->name, "name") == 0 || - strcmp (pspec->name, "display") == 0 || - strcmp (pspec->name, "style") == 0)) - check = FALSE; + strcmp (pspec->name, "display") == 0 || + strcmp (pspec->name, "style") == 0)) + check = FALSE; /* resize-grip-visible is determined at runtime */ if (g_type_is_a (type, GTK_TYPE_WINDOW) && @@ -559,10 +559,10 @@ main (int argc, char **argv) continue; testname = g_strdup_printf ("/Default Values/%s", - g_type_name (otypes[i])); + g_type_name (otypes[i])); g_test_add_data_func (testname, &otypes[i], - test_type); + test_type); g_free (testname); }