From 492ae6df3571f7e64e715c5b06efd9c0ed76aede Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 19 May 2024 14:18:52 -0400 Subject: [PATCH] css: Less recomputation in animation Only recompute the animated style once all the custom variables have been updated. --- gtk/gtkcssanimatedstyle.c | 35 ++++++++++++++++++-------------- gtk/gtkcssanimatedstyleprivate.h | 1 + gtk/gtkcssanimation.c | 6 ++++++ 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/gtk/gtkcssanimatedstyle.c b/gtk/gtkcssanimatedstyle.c index 8cce441e0b..493b68c1ab 100644 --- a/gtk/gtkcssanimatedstyle.c +++ b/gtk/gtkcssanimatedstyle.c @@ -609,7 +609,6 @@ gtk_css_animated_style_set_animated_custom_value (GtkCssAnimatedStyle *animated, GtkCssVariableValue *value) { GtkCssStyle *style = (GtkCssStyle *)animated; - GtkCssComputeContext context = { NULL, }; gtk_internal_return_if_fail (GTK_IS_CSS_ANIMATED_STYLE (style)); gtk_internal_return_if_fail (value != NULL); @@ -628,22 +627,28 @@ gtk_css_animated_style_set_animated_custom_value (GtkCssAnimatedStyle *animated, } gtk_css_variable_set_add (style->variables, id, value); +} - context.style = animated->style; - context.parent_style = animated->parent_style; - context.provider = animated->provider; +void +gtk_css_animated_style_recompute (GtkCssAnimatedStyle *style) +{ + GtkCssComputeContext context = { NULL, }; - gtk_css_core_values_recompute (animated, &context); - gtk_css_background_values_recompute (animated, &context); - gtk_css_border_values_recompute (animated, &context); - gtk_css_icon_values_recompute (animated, &context); - gtk_css_outline_values_recompute (animated, &context); - gtk_css_font_values_recompute (animated, &context); - gtk_css_font_variant_values_recompute (animated, &context); - gtk_css_animation_values_recompute (animated, &context); - gtk_css_transition_values_recompute (animated, &context); - gtk_css_size_values_recompute (animated, &context); - gtk_css_other_values_recompute (animated, &context); + context.provider = style->provider; + context.style = style->style; + context.parent_style = style->parent_style; + + gtk_css_core_values_recompute (style, &context); + gtk_css_background_values_recompute (style, &context); + gtk_css_border_values_recompute (style, &context); + gtk_css_icon_values_recompute (style, &context); + gtk_css_outline_values_recompute (style, &context); + gtk_css_font_values_recompute (style, &context); + gtk_css_font_variant_values_recompute (style, &context); + gtk_css_animation_values_recompute (style, &context); + gtk_css_transition_values_recompute (style, &context); + gtk_css_size_values_recompute (style, &context); + gtk_css_other_values_recompute (style, &context); } GtkCssVariableValue * diff --git a/gtk/gtkcssanimatedstyleprivate.h b/gtk/gtkcssanimatedstyleprivate.h index d8eab1e458..58a7a2e236 100644 --- a/gtk/gtkcssanimatedstyleprivate.h +++ b/gtk/gtkcssanimatedstyleprivate.h @@ -73,6 +73,7 @@ GtkCssValue * gtk_css_animated_style_get_intrinsic_value (GtkCssAnimat void gtk_css_animated_style_set_animated_custom_value (GtkCssAnimatedStyle *animated, int id, GtkCssVariableValue *value); +void gtk_css_animated_style_recompute (GtkCssAnimatedStyle *style); GtkCssVariableValue * gtk_css_animated_style_get_intrinsic_custom_value (GtkCssAnimatedStyle *style, int id); diff --git a/gtk/gtkcssanimation.c b/gtk/gtkcssanimation.c index a380b704c1..bd5f6b9cd5 100644 --- a/gtk/gtkcssanimation.c +++ b/gtk/gtkcssanimation.c @@ -95,6 +95,7 @@ gtk_css_animation_apply_values (GtkStyleAnimation *style_animation, GtkCssKeyframes *resolved_keyframes; double progress; guint i; + gboolean needs_recompute = FALSE; if (!gtk_css_animation_is_executing (animation)) return; @@ -128,8 +129,13 @@ gtk_css_animation_apply_values (GtkStyleAnimation *style_animation, gtk_css_animated_style_set_animated_custom_value (style, variable_id, value); gtk_css_variable_value_unref (value); + + needs_recompute = TRUE; } + if (needs_recompute) + gtk_css_animated_style_recompute (style); + for (i = 0; i < _gtk_css_keyframes_get_n_properties (resolved_keyframes); i++) { GtkCssValue *value;