[gtk/css-lookup-caching] Try to make the style computation clearer



commit 064dc80d3eaf551ce25e3df4a9397a8aeb5b8602
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Feb 13 19:05:02 2020 -0500

    Try to make the style computation clearer

 gtk/gtkcssnode.c | 58 +++++++++++++++++++++++++++++++-------------------------
 1 file changed, 32 insertions(+), 26 deletions(-)
---
diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c
index c4c9c79909..d9bcac4489 100644
--- a/gtk/gtkcssnode.c
+++ b/gtk/gtkcssnode.c
@@ -356,21 +356,14 @@ store_in_global_parent_cache (GtkCssNode                  *node,
 }
 
 static GtkCssStyle *
-gtk_css_node_create_style (GtkCssNode                   *cssnode,
-                           GtkCssStyle                  *static_style,
-                           const GtkCountingBloomFilter *filter,
-                           GtkCssChange                  change)
+compute_style (GtkStyleProvider             *provider,
+               const GtkCountingBloomFilter *filter,
+               GtkCssNode                   *cssnode,
+               GtkCssLookup                 *lookup,
+               GtkCssChange                  change)
 {
   const GtkCssNodeDeclaration *decl;
   GtkCssStyle *style;
-  GtkCssChange style_change;
-  GtkCssLookup *lookup;
-
-  style_change = gtk_css_static_style_get_change (GTK_CSS_STATIC_STYLE (static_style));
-
-  if ((change & GTK_CSS_RADICAL_CHANGE) == 0 &&
-      (change & style_change) == 0)
-    return g_object_ref (static_style);
 
   decl = gtk_css_node_get_declaration (cssnode);
   style = lookup_in_global_parent_cache (cssnode, decl);
@@ -379,24 +372,37 @@ gtk_css_node_create_style (GtkCssNode                   *cssnode,
 
   created_styles++;
 
-  if ((change & GTK_CSS_CHANGE_SOURCE) == 0 &&
-      (change & style_change) == 0)
-    lookup = gtk_css_static_style_get_lookup (GTK_CSS_STATIC_STYLE (static_style));
-  else
-    lookup = NULL;
+  style = gtk_css_static_style_new_compute (provider, filter, cssnode, lookup, change);
+  store_in_global_parent_cache (cssnode, decl, style);
+
+  return style;
+}
 
-  if ((change & GTK_CSS_CHANGE_NEEDS_RECOMPUTE) != 0)
-    style_change = 0;
+static GtkCssStyle *
+gtk_css_node_create_style (GtkCssNode                   *cssnode,
+                           GtkCssStyle                  *style,
+                           const GtkCountingBloomFilter *filter,
+                           GtkCssChange                  change)
+{
+  GtkCssStyle *new_style;
+  GtkCssChange style_change;
+  GtkCssLookup *lookup;
+  GtkStyleProvider *provider;
 
-  style = gtk_css_static_style_new_compute (gtk_css_node_get_style_provider (cssnode),
-                                            filter,
-                                            cssnode,
-                                            lookup,
-                                            style_change);
+  provider = gtk_css_node_get_style_provider (cssnode);
+  style_change = gtk_css_static_style_get_change (GTK_CSS_STATIC_STYLE (style));
+  lookup = gtk_css_static_style_get_lookup (GTK_CSS_STATIC_STYLE (style));
 
-  store_in_global_parent_cache (cssnode, decl, style);
+  if (change & (GTK_CSS_RADICAL_CHANGE & ~GTK_CSS_CHANGE_PARENT_STYLE))
+    new_style = compute_style (provider, filter, cssnode, NULL, 0);
+  else if (change & style_change)
+    new_style = compute_style (provider, filter, cssnode, NULL, style_change);
+  else if (change & GTK_CSS_CHANGE_PARENT_STYLE)
+    new_style = compute_style (provider, filter, cssnode, lookup, style_change);
+  else
+    new_style = g_object_ref (style);
 
-  return style;
+  return new_style;
 }
 
 static gboolean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]