css: Less recomputation in animation

Only recompute the animated style once all the custom variables
have been updated.
This commit is contained in:
Matthias Clasen
2024-05-19 14:18:52 -04:00
parent a19d0471e9
commit 492ae6df35
3 changed files with 27 additions and 15 deletions

View File

@@ -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 *

View File

@@ -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);

View File

@@ -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;