cssimagefallback: Don't compute new image if only a color is set
authorTimm Bäder <mail@baedert.org>
Sat, 11 Jan 2020 07:25:52 +0000 (08:25 +0100)
committerTimm Bäder <mail@baedert.org>
Sat, 18 Jan 2020 07:49:51 +0000 (08:49 +0100)
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

index 8d8ca30b5265fd63e858f0be7011fef43d6cbd10..879703b0d976ceb46e3d1cedd2a3933ff7a82d8f 100644 (file)
@@ -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);
     }