cssanimatedstyle: Avoid creating animation

... when no animation exists.

This makes the function name kinda wrong, but I'm not sure what else to
call it.
This commit is contained in:
Benjamin Otte
2014-12-15 04:17:42 +01:00
parent 682abc345f
commit f3f021106d
2 changed files with 49 additions and 34 deletions

View File

@ -244,8 +244,9 @@ gtk_css_animated_style_find_transition (GtkCssAnimatedStyle *style,
return NULL; return NULL;
} }
static void static GSList *
gtk_css_animated_style_create_css_transitions (GtkCssAnimatedStyle *style, gtk_css_animated_style_create_css_transitions (GSList *animations,
GtkCssStyle *base_style,
gint64 timestamp, gint64 timestamp,
GtkCssStyle *source) GtkCssStyle *source)
{ {
@ -253,11 +254,11 @@ gtk_css_animated_style_create_css_transitions (GtkCssAnimatedStyle *style,
GtkCssValue *durations, *delays, *timing_functions; GtkCssValue *durations, *delays, *timing_functions;
guint i; guint i;
transition_infos_set (transitions, gtk_css_style_get_value (GTK_CSS_STYLE (style), GTK_CSS_PROPERTY_TRANSITION_PROPERTY)); transition_infos_set (transitions, gtk_css_style_get_value (base_style, GTK_CSS_PROPERTY_TRANSITION_PROPERTY));
durations = gtk_css_style_get_value (GTK_CSS_STYLE (style), GTK_CSS_PROPERTY_TRANSITION_DURATION); durations = gtk_css_style_get_value (base_style, GTK_CSS_PROPERTY_TRANSITION_DURATION);
delays = gtk_css_style_get_value (GTK_CSS_STYLE (style), GTK_CSS_PROPERTY_TRANSITION_DELAY); delays = gtk_css_style_get_value (base_style, GTK_CSS_PROPERTY_TRANSITION_DELAY);
timing_functions = gtk_css_style_get_value (GTK_CSS_STYLE (style), GTK_CSS_PROPERTY_TRANSITION_TIMING_FUNCTION); timing_functions = gtk_css_style_get_value (base_style, GTK_CSS_PROPERTY_TRANSITION_TIMING_FUNCTION);
for (i = 0; i < GTK_CSS_PROPERTY_N_PROPERTIES; i++) for (i = 0; i < GTK_CSS_PROPERTY_N_PROPERTIES; i++)
{ {
@ -276,12 +277,13 @@ gtk_css_animated_style_create_css_transitions (GtkCssAnimatedStyle *style,
if (GTK_IS_CSS_ANIMATED_STYLE (source)) if (GTK_IS_CSS_ANIMATED_STYLE (source))
{ {
start = gtk_css_animated_style_get_intrinsic_value (GTK_CSS_ANIMATED_STYLE (source), i); start = gtk_css_animated_style_get_intrinsic_value (GTK_CSS_ANIMATED_STYLE (source), i);
end = gtk_css_animated_style_get_intrinsic_value (style, i); end = gtk_css_style_get_value (base_style, i);
if (_gtk_css_value_equal (start, end)) if (_gtk_css_value_equal (start, end))
{ {
animation = gtk_css_animated_style_find_transition (GTK_CSS_ANIMATED_STYLE (source), i); animation = gtk_css_animated_style_find_transition (GTK_CSS_ANIMATED_STYLE (source), i);
if (animation) if (animation)
style->animations = g_slist_prepend (style->animations, g_object_ref (animation)); animations = g_slist_prepend (animations, g_object_ref (animation));
continue; continue;
} }
@ -292,17 +294,19 @@ gtk_css_animated_style_create_css_transitions (GtkCssAnimatedStyle *style,
_gtk_css_array_value_get_nth (timing_functions, i), _gtk_css_array_value_get_nth (timing_functions, i),
timestamp + delay * G_USEC_PER_SEC, timestamp + delay * G_USEC_PER_SEC,
timestamp + (delay + duration) * G_USEC_PER_SEC); timestamp + (delay + duration) * G_USEC_PER_SEC);
style->animations = g_slist_prepend (style->animations, animation); animations = g_slist_prepend (animations, animation);
} }
return animations;
} }
static GtkStyleAnimation * static GtkStyleAnimation *
gtk_css_animated_style_find_animation (GtkCssAnimatedStyle *style, gtk_css_animated_style_find_animation (GSList *animations,
const char *name) const char *name)
{ {
GSList *list; GSList *list;
for (list = style->animations; list; list = list->next) for (list = animations; list; list = list->next)
{ {
if (!GTK_IS_CSS_ANIMATION (list->data)) if (!GTK_IS_CSS_ANIMATION (list->data))
continue; continue;
@ -314,43 +318,44 @@ gtk_css_animated_style_find_animation (GtkCssAnimatedStyle *style,
return NULL; return NULL;
} }
static void static GSList *
gtk_css_animated_style_create_css_animations (GtkCssAnimatedStyle *style, gtk_css_animated_style_create_css_animations (GSList *animations,
GtkCssStyle *base_style,
GtkCssStyle *parent_style, GtkCssStyle *parent_style,
gint64 timestamp, gint64 timestamp,
GtkStyleProviderPrivate *provider, GtkStyleProviderPrivate *provider,
int scale, int scale,
GtkCssStyle *source) GtkCssStyle *source)
{ {
GtkCssValue *durations, *delays, *timing_functions, *animations; GtkCssValue *durations, *delays, *timing_functions, *animation_names;
GtkCssValue *iteration_counts, *directions, *play_states, *fill_modes; GtkCssValue *iteration_counts, *directions, *play_states, *fill_modes;
guint i; guint i;
animations = gtk_css_style_get_value (GTK_CSS_STYLE (style), GTK_CSS_PROPERTY_ANIMATION_NAME); animation_names = gtk_css_style_get_value (base_style, GTK_CSS_PROPERTY_ANIMATION_NAME);
durations = gtk_css_style_get_value (GTK_CSS_STYLE (style), GTK_CSS_PROPERTY_ANIMATION_DURATION); durations = gtk_css_style_get_value (base_style, GTK_CSS_PROPERTY_ANIMATION_DURATION);
delays = gtk_css_style_get_value (GTK_CSS_STYLE (style), GTK_CSS_PROPERTY_ANIMATION_DELAY); delays = gtk_css_style_get_value (base_style, GTK_CSS_PROPERTY_ANIMATION_DELAY);
timing_functions = gtk_css_style_get_value (GTK_CSS_STYLE (style), GTK_CSS_PROPERTY_ANIMATION_TIMING_FUNCTION); timing_functions = gtk_css_style_get_value (base_style, GTK_CSS_PROPERTY_ANIMATION_TIMING_FUNCTION);
iteration_counts = gtk_css_style_get_value (GTK_CSS_STYLE (style), GTK_CSS_PROPERTY_ANIMATION_ITERATION_COUNT); iteration_counts = gtk_css_style_get_value (base_style, GTK_CSS_PROPERTY_ANIMATION_ITERATION_COUNT);
directions = gtk_css_style_get_value (GTK_CSS_STYLE (style), GTK_CSS_PROPERTY_ANIMATION_DIRECTION); directions = gtk_css_style_get_value (base_style, GTK_CSS_PROPERTY_ANIMATION_DIRECTION);
play_states = gtk_css_style_get_value (GTK_CSS_STYLE (style), GTK_CSS_PROPERTY_ANIMATION_PLAY_STATE); play_states = gtk_css_style_get_value (base_style, GTK_CSS_PROPERTY_ANIMATION_PLAY_STATE);
fill_modes = gtk_css_style_get_value (GTK_CSS_STYLE (style), GTK_CSS_PROPERTY_ANIMATION_FILL_MODE); fill_modes = gtk_css_style_get_value (base_style, GTK_CSS_PROPERTY_ANIMATION_FILL_MODE);
for (i = 0; i < _gtk_css_array_value_get_n_values (animations); i++) for (i = 0; i < _gtk_css_array_value_get_n_values (animation_names); i++)
{ {
GtkStyleAnimation *animation; GtkStyleAnimation *animation;
GtkCssKeyframes *keyframes; GtkCssKeyframes *keyframes;
const char *name; const char *name;
name = _gtk_css_ident_value_get (_gtk_css_array_value_get_nth (animations, i)); name = _gtk_css_ident_value_get (_gtk_css_array_value_get_nth (animation_names, i));
if (g_ascii_strcasecmp (name, "none") == 0) if (g_ascii_strcasecmp (name, "none") == 0)
continue; continue;
animation = gtk_css_animated_style_find_animation (style, name); animation = gtk_css_animated_style_find_animation (animations, name);
if (animation) if (animation)
continue; continue;
if (GTK_IS_CSS_ANIMATED_STYLE (source)) if (GTK_IS_CSS_ANIMATED_STYLE (source))
animation = gtk_css_animated_style_find_animation (GTK_CSS_ANIMATED_STYLE (source), name); animation = gtk_css_animated_style_find_animation (GTK_CSS_ANIMATED_STYLE (source)->animations, name);
if (animation) if (animation)
{ {
@ -364,7 +369,7 @@ gtk_css_animated_style_create_css_animations (GtkCssAnimatedStyle *style,
if (keyframes == NULL) if (keyframes == NULL)
continue; continue;
keyframes = _gtk_css_keyframes_compute (keyframes, provider, scale, GTK_CSS_STYLE (style), parent_style); keyframes = _gtk_css_keyframes_compute (keyframes, provider, scale, base_style, parent_style);
animation = _gtk_css_animation_new (name, animation = _gtk_css_animation_new (name,
keyframes, keyframes,
@ -378,8 +383,10 @@ gtk_css_animated_style_create_css_animations (GtkCssAnimatedStyle *style,
_gtk_css_number_value_get (_gtk_css_array_value_get_nth (iteration_counts, i), 100)); _gtk_css_number_value_get (_gtk_css_array_value_get_nth (iteration_counts, i), 100));
_gtk_css_keyframes_unref (keyframes); _gtk_css_keyframes_unref (keyframes);
} }
style->animations = g_slist_prepend (style->animations, animation); animations = g_slist_prepend (animations, animation);
} }
return animations;
} }
/* PUBLIC API */ /* PUBLIC API */
@ -393,19 +400,26 @@ gtk_css_animated_style_new (GtkCssStyle *base_style,
GtkCssStyle *previous_style) GtkCssStyle *previous_style)
{ {
GtkCssAnimatedStyle *result; GtkCssAnimatedStyle *result;
GSList *animations;
gtk_internal_return_val_if_fail (GTK_IS_CSS_STYLE (base_style), NULL); gtk_internal_return_val_if_fail (GTK_IS_CSS_STYLE (base_style), NULL);
gtk_internal_return_val_if_fail (parent_style == NULL || GTK_IS_CSS_STYLE (parent_style), NULL); gtk_internal_return_val_if_fail (parent_style == NULL || GTK_IS_CSS_STYLE (parent_style), NULL);
gtk_internal_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), NULL); gtk_internal_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), NULL);
gtk_internal_return_val_if_fail (previous_style == NULL || GTK_IS_CSS_STYLE (previous_style), NULL); gtk_internal_return_val_if_fail (previous_style == NULL || GTK_IS_CSS_STYLE (previous_style), NULL);
animations = NULL;
if (previous_style != NULL)
animations = gtk_css_animated_style_create_css_transitions (animations, base_style, timestamp, previous_style);
animations = gtk_css_animated_style_create_css_animations (animations, base_style, parent_style, timestamp, provider, scale, previous_style);
if (animations == NULL)
return g_object_ref (base_style);
result = g_object_new (GTK_TYPE_CSS_ANIMATED_STYLE, NULL); result = g_object_new (GTK_TYPE_CSS_ANIMATED_STYLE, NULL);
result->style = g_object_ref (base_style); result->style = g_object_ref (base_style);
result->animations = animations;
if (previous_style != NULL)
gtk_css_animated_style_create_css_transitions (result, timestamp, previous_style);
gtk_css_animated_style_create_css_animations (result, parent_style, timestamp, provider, scale, previous_style);
return GTK_CSS_STYLE (result); return GTK_CSS_STYLE (result);
} }

View File

@ -2846,7 +2846,8 @@ _gtk_style_context_validate (GtkStyleContext *context,
priv->scale, priv->scale,
gtk_style_context_should_create_transitions (context) ? current : NULL); gtk_style_context_should_create_transitions (context) ? current : NULL);
if (gtk_css_animated_style_is_static (GTK_CSS_ANIMATED_STYLE (values))) if (!GTK_IS_CSS_ANIMATED_STYLE (values) ||
gtk_css_animated_style_is_static (GTK_CSS_ANIMATED_STYLE (values)))
{ {
change &= ~GTK_CSS_CHANGE_ANIMATE; change &= ~GTK_CSS_CHANGE_ANIMATE;
} }