cssnode: Only recreate styles when needed
authorBenjamin Otte <otte@redhat.com>
Thu, 5 Feb 2015 05:49:59 +0000 (06:49 +0100)
committerBenjamin Otte <otte@redhat.com>
Wed, 18 Mar 2015 14:23:30 +0000 (15:23 +0100)
gtk/gtkcssnode.c

index b331f26b73670947cb7f6df7f81038660e03ddec..db68349c0dbd5f43208dbd7b336bdac5cacd1950 100644 (file)
 
 #include "gtkcssnodeprivate.h"
 
+#include "gtkcssanimatedstyleprivate.h"
 #include "gtkcsstransientnodeprivate.h"
 #include "gtkdebug.h"
 #include "gtksettingsprivate.h"
 
+/* When these change we do a full restyling. Otherwise we try to figure out
+ * if we need to change things. */
+#define GTK_CSS_RADICAL_CHANGE (GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_CLASS | GTK_CSS_CHANGE_SOURCE)
+
 G_DEFINE_TYPE (GtkCssNode, gtk_css_node, G_TYPE_OBJECT)
 
 void
@@ -222,11 +227,31 @@ gtk_css_node_create_style (GtkCssNode *cssnode)
   return style;
 }
 
+static gboolean
+gtk_css_style_needs_recreation (GtkCssStyle  *style,
+                                GtkCssChange  change)
+{
+  /* Try to avoid invalidating if we can */
+  if (change & GTK_CSS_RADICAL_CHANGE)
+    return TRUE;
+
+  if (GTK_IS_CSS_ANIMATED_STYLE (style))
+    style = GTK_CSS_ANIMATED_STYLE (style)->style;
+
+  if (gtk_css_static_style_get_change (GTK_CSS_STATIC_STYLE (style)) & change)
+    return TRUE;
+  else
+    return FALSE;
+}
+
 static GtkCssStyle *
 gtk_css_node_real_update_style (GtkCssNode   *cssnode,
                                 GtkCssChange  pending_change,
                                 GtkCssStyle  *old_style)
 {
+  if (!gtk_css_style_needs_recreation (old_style, pending_change))
+    return g_object_ref (old_style);
+
   return gtk_css_node_create_style (cssnode);
 }