From 3401150cca54b0cd1b9d9b745b1fe5f22d3b5c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 11 Jan 2020 08:25:52 +0100 Subject: [PATCH] cssimagefallback: Don't compute new image if only a color is set Themes might use e.g. image(red), which is a constant value and will never change. In that case, the fallback image has ->color set, but not ->images. If that's the case and the computed color is the same as the one we already have, just return the already existing image. --- gtk/gtkcssimagefallback.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/gtk/gtkcssimagefallback.c b/gtk/gtkcssimagefallback.c index 8d8ca30b52..879703b0d9 100644 --- a/gtk/gtkcssimagefallback.c +++ b/gtk/gtkcssimagefallback.c @@ -142,6 +142,20 @@ gtk_css_image_fallback_compute (GtkCssImage *image, if (fallback->used < 0) { + GtkCssValue *computed_color = NULL; + + if (fallback->color) + computed_color= _gtk_css_value_compute (fallback->color, + property_id, + provider, + style, + parent_style); + + /* image($color) that didn't change */ + if (computed_color && !fallback->images && + computed_color == fallback->color) + return g_object_ref (image); + copy = g_object_new (_gtk_css_image_fallback_get_type (), NULL); copy->n_images = fallback->n_images; copy->images = g_new (GtkCssImage *, fallback->n_images); @@ -160,14 +174,7 @@ gtk_css_image_fallback_compute (GtkCssImage *image, copy->used = i; } - if (fallback->color) - copy->color = _gtk_css_value_compute (fallback->color, - property_id, - provider, - style, - parent_style); - else - copy->color = NULL; + copy->color = computed_color; return GTK_CSS_IMAGE (copy); }