[gtk/wip/baedert/gl-rework: 3/4] cssimageicontheme: Implement is_computed
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/gl-rework: 3/4] cssimageicontheme: Implement is_computed
- Date: Mon, 20 Jan 2020 09:29:17 +0000 (UTC)
commit 2b669ce94cc564286fe7882064aeebe2035f720c
Author: Timm Bäder <mail baedert org>
Date: Mon Jan 20 10:13:43 2020 +0100
cssimageicontheme: Implement is_computed
Save whether we already compute()d a proper icon theme, etc. and return
that from is_computed.
This way we avoid constantly redrawing the large gear icon in the .devel
styled headerbar.
gtk/gtkcssimageicontheme.c | 26 ++++++++++++++++++++++++--
gtk/gtkcssimageiconthemeprivate.h | 1 +
2 files changed, 25 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkcssimageicontheme.c b/gtk/gtkcssimageicontheme.c
index c2a21c41b9..f74f293afe 100644
--- a/gtk/gtkcssimageicontheme.c
+++ b/gtk/gtkcssimageicontheme.c
@@ -172,11 +172,25 @@ gtk_css_image_icon_theme_compute (GtkCssImage *image,
{
GtkCssImageIconTheme *icon_theme = GTK_CSS_IMAGE_ICON_THEME (image);
GtkCssImageIconTheme *copy;
+ GtkIconTheme *icontheme;
+ int scale;
+
+ if (icon_theme->is_computed)
+ return g_object_ref (image);
+
+ icontheme = gtk_css_icon_theme_value_get_icon_theme (gtk_css_style_get_value (style,
GTK_CSS_PROPERTY_ICON_THEME));
+ scale = gtk_style_provider_get_scale (provider);
+
+ if (icon_theme->scale == scale &&
+ icon_theme->icon_theme == icontheme)
+ return g_object_ref (image);
copy = g_object_new (GTK_TYPE_CSS_IMAGE_ICON_THEME, NULL);
copy->name = g_strdup (icon_theme->name);
- copy->icon_theme = gtk_css_icon_theme_value_get_icon_theme (gtk_css_style_get_value (style,
GTK_CSS_PROPERTY_ICON_THEME));
- copy->scale = gtk_style_provider_get_scale (provider);
+ copy->icon_theme = icontheme;
+ copy->scale = scale;
+ copy->is_computed = TRUE;
+
gtk_icon_theme_lookup_symbolic_colors (style, ©->color, ©->success, ©->warning, ©->error);
return GTK_CSS_IMAGE (copy);
@@ -205,6 +219,13 @@ gtk_css_image_icon_theme_dispose (GObject *object)
G_OBJECT_CLASS (_gtk_css_image_icon_theme_parent_class)->dispose (object);
}
+static gboolean
+gtk_css_image_icon_theme_is_computed (GtkCssImage *image)
+{
+ GtkCssImageIconTheme *icon_theme = (GtkCssImageIconTheme *) image;
+
+ return icon_theme->is_computed;
+}
static void
_gtk_css_image_icon_theme_class_init (GtkCssImageIconThemeClass *klass)
{
@@ -217,6 +238,7 @@ _gtk_css_image_icon_theme_class_init (GtkCssImageIconThemeClass *klass)
image_class->print = gtk_css_image_icon_theme_print;
image_class->compute = gtk_css_image_icon_theme_compute;
image_class->equal = gtk_css_image_icon_theme_equal;
+ image_class->is_computed = gtk_css_image_icon_theme_is_computed;
object_class->dispose = gtk_css_image_icon_theme_dispose;
}
diff --git a/gtk/gtkcssimageiconthemeprivate.h b/gtk/gtkcssimageiconthemeprivate.h
index f583b35230..d4b93accb1 100644
--- a/gtk/gtkcssimageiconthemeprivate.h
+++ b/gtk/gtkcssimageiconthemeprivate.h
@@ -40,6 +40,7 @@ struct _GtkCssImageIconTheme
GtkCssImage parent;
GtkIconTheme *icon_theme;
+ guint is_computed: 1;
GdkRGBA color;
GdkRGBA success;
GdkRGBA warning;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]