Keep similar theme nodes so we don't have to recompute CSS so often
Because we calculate and cache CSS properties once per StThemeNode, and only a certain set of attributes can affect the CSS properties, it's advantageous for as many widgets as possible to share a single StThemeNode. Similarly, if a widget changes state and then changes back (e.g. gaining and losing the :hover pseudo-class), it should ideally get its original StThemeNode back again when it returns to the old state. Here, I'm using the StThemeContext as the location for a cache. StThemeNodes are currently never freed: this seems OK for Shell's usage (a finite number of IDs, classes, pseudo-classes and types). Bug: https://bugzilla.gnome.org/show_bug.cgi?id=687465 Reviewed-by: Jasper St. Pierre <jstpierre@mecheye.net>
This commit is contained in:
@ -589,6 +589,8 @@ st_widget_get_theme_node (StWidget *widget)
|
||||
|
||||
if (priv->theme_node == NULL)
|
||||
{
|
||||
StThemeContext *context;
|
||||
StThemeNode *tmp_node;
|
||||
StThemeNode *parent_node = NULL;
|
||||
ClutterStage *stage = NULL;
|
||||
ClutterActor *parent;
|
||||
@ -629,16 +631,20 @@ st_widget_get_theme_node (StWidget *widget)
|
||||
else
|
||||
pseudo_class = direction_pseudo_class;
|
||||
|
||||
priv->theme_node = st_theme_node_new (st_theme_context_get_for_stage (stage),
|
||||
parent_node, priv->theme,
|
||||
G_OBJECT_TYPE (widget),
|
||||
clutter_actor_get_name (CLUTTER_ACTOR (widget)),
|
||||
priv->style_class,
|
||||
pseudo_class,
|
||||
priv->inline_style);
|
||||
context = st_theme_context_get_for_stage (stage);
|
||||
tmp_node = st_theme_node_new (context, parent_node, priv->theme,
|
||||
G_OBJECT_TYPE (widget),
|
||||
clutter_actor_get_name (CLUTTER_ACTOR (widget)),
|
||||
priv->style_class,
|
||||
pseudo_class,
|
||||
priv->inline_style);
|
||||
|
||||
if (pseudo_class != direction_pseudo_class)
|
||||
g_free (pseudo_class);
|
||||
|
||||
priv->theme_node = g_object_ref (st_theme_context_intern_node (context,
|
||||
tmp_node));
|
||||
g_object_unref (tmp_node);
|
||||
}
|
||||
|
||||
return priv->theme_node;
|
||||
|
Reference in New Issue
Block a user