animatedstyle: don't share styleanimations

Because of our port of css animation and css transition to
progress tracker, we should not think of animated styles as
immutable objects that can map any timestamp to css values.
Rather, timestamps can correspond to different values depending
on the value of GTK_SLOWDOWN over the course of the animation.

To keep animated styles and style animations totally immutable,
we will not share styleanimations between animatedstyles, and
make a new copy of a styleanimation for each timestamp.
This commit is contained in:
Matt Watson 2016-03-22 01:10:21 -07:00
parent 7b68bdb831
commit a970ba5ef6
6 changed files with 115 additions and 76 deletions

View File

@ -71,7 +71,7 @@ gtk_css_animated_style_is_static (GtkCssStyle *style)
for (list = animated->animations; list; list = list->next)
{
if (!_gtk_style_animation_is_static (list->data, animated->current_time))
if (!_gtk_style_animation_is_static (list->data))
return FALSE;
}
@ -288,7 +288,10 @@ gtk_css_animated_style_create_css_transitions (GSList *animations,
{
animation = gtk_css_animated_style_find_transition (GTK_CSS_ANIMATED_STYLE (source), i);
if (animation)
animations = g_slist_prepend (animations, g_object_ref (animation));
{
animation = _gtk_style_animation_advance (animation, timestamp);
animations = g_slist_prepend (animations, animation);
}
continue;
}
@ -368,8 +371,9 @@ gtk_css_animated_style_create_css_animations (GSList *animation
if (animation)
{
animation = _gtk_css_animation_copy (GTK_CSS_ANIMATION (animation),
_gtk_css_play_state_value_get (_gtk_css_array_value_get_nth (play_states, i)));
animation = _gtk_css_animation_advance_with_play_state (GTK_CSS_ANIMATION (animation),
timestamp,
_gtk_css_play_state_value_get (_gtk_css_array_value_get_nth (play_states, i)));
}
else
{
@ -400,8 +404,7 @@ gtk_css_animated_style_create_css_animations (GSList *animation
/* PUBLIC API */
static void
gtk_css_animated_style_apply_animations (GtkCssAnimatedStyle *style,
gint64 timestamp)
gtk_css_animated_style_apply_animations (GtkCssAnimatedStyle *style)
{
GSList *l;
@ -409,9 +412,8 @@ gtk_css_animated_style_apply_animations (GtkCssAnimatedStyle *style,
{
GtkStyleAnimation *animation = l->data;
_gtk_style_animation_set_values (animation,
timestamp,
GTK_CSS_ANIMATED_STYLE (style));
_gtk_style_animation_apply_values (animation,
GTK_CSS_ANIMATED_STYLE (style));
}
}
@ -448,7 +450,7 @@ gtk_css_animated_style_new (GtkCssStyle *base_style,
result->current_time = timestamp;
result->animations = animations;
gtk_css_animated_style_apply_animations (result, timestamp);
gtk_css_animated_style_apply_animations (result);
return GTK_CSS_STYLE (result);
}
@ -474,10 +476,11 @@ gtk_css_animated_style_new_advance (GtkCssAnimatedStyle *source,
{
GtkStyleAnimation *animation = l->data;
if (_gtk_style_animation_is_finished (animation, timestamp))
if (_gtk_style_animation_is_finished (animation))
continue;
animations = g_slist_prepend (animations, g_object_ref (animation));
animation = _gtk_style_animation_advance (animation, timestamp);
animations = g_slist_prepend (animations, animation);
}
animations = g_slist_reverse (animations);
@ -490,7 +493,7 @@ gtk_css_animated_style_new_advance (GtkCssAnimatedStyle *source,
result->current_time = timestamp;
result->animations = animations;
gtk_css_animated_style_apply_animations (result, timestamp);
gtk_css_animated_style_apply_animations (result);
return GTK_CSS_STYLE (result);
}

View File

@ -76,20 +76,25 @@ gtk_css_animation_get_progress (GtkCssAnimation *animation)
return gtk_progress_tracker_get_progress (&animation->tracker, reverse);
}
GtkStyleAnimation *
gtk_css_animation_advance (GtkStyleAnimation *style_animation,
gint64 timestamp)
{
GtkCssAnimation *animation = GTK_CSS_ANIMATION (style_animation);
return _gtk_css_animation_advance_with_play_state (animation,
timestamp,
animation->play_state);
}
static void
gtk_css_animation_set_values (GtkStyleAnimation *style_animation,
gint64 for_time_us,
GtkCssAnimatedStyle *style)
gtk_css_animation_apply_values (GtkStyleAnimation *style_animation,
GtkCssAnimatedStyle *style)
{
GtkCssAnimation *animation = GTK_CSS_ANIMATION (style_animation);
double progress;
guint i;
if (animation->play_state != GTK_CSS_PLAY_STATE_PAUSED)
gtk_progress_tracker_advance_frame (&animation->tracker, for_time_us);
else
gtk_progress_tracker_skip_frame (&animation->tracker, for_time_us);
if (!gtk_css_animation_is_executing (animation))
return;
@ -113,15 +118,13 @@ gtk_css_animation_set_values (GtkStyleAnimation *style_animation,
}
static gboolean
gtk_css_animation_is_finished (GtkStyleAnimation *style_animation,
gint64 at_time_us)
gtk_css_animation_is_finished (GtkStyleAnimation *style_animation)
{
return FALSE;
}
static gboolean
gtk_css_animation_is_static (GtkStyleAnimation *style_animation,
gint64 at_time_us)
gtk_css_animation_is_static (GtkStyleAnimation *style_animation)
{
GtkCssAnimation *animation = GTK_CSS_ANIMATION (style_animation);
@ -151,7 +154,8 @@ _gtk_css_animation_class_init (GtkCssAnimationClass *klass)
object_class->finalize = gtk_css_animation_finalize;
animation_class->set_values = gtk_css_animation_set_values;
animation_class->advance = gtk_css_animation_advance;
animation_class->apply_values = gtk_css_animation_apply_values;
animation_class->is_finished = gtk_css_animation_is_finished;
animation_class->is_static = gtk_css_animation_is_static;
}
@ -207,16 +211,14 @@ _gtk_css_animation_get_name (GtkCssAnimation *animation)
}
GtkStyleAnimation *
_gtk_css_animation_copy (GtkCssAnimation *source,
GtkCssPlayState play_state)
_gtk_css_animation_advance_with_play_state (GtkCssAnimation *source,
gint64 timestamp,
GtkCssPlayState play_state)
{
GtkCssAnimation *animation;
g_return_val_if_fail (GTK_IS_CSS_ANIMATION (source), NULL);
if (source->play_state == play_state)
return g_object_ref (source);
animation = g_object_new (GTK_TYPE_CSS_ANIMATION, NULL);
animation->name = g_strdup (source->name);
@ -226,8 +228,11 @@ _gtk_css_animation_copy (GtkCssAnimation *source,
animation->play_state = play_state;
animation->fill_mode = source->fill_mode;
memcpy (&animation->tracker, &source->tracker, sizeof (source->tracker));
gtk_progress_tracker_init_copy (&source->tracker, &animation->tracker);
if (animation->play_state == GTK_CSS_PLAY_STATE_PAUSED)
gtk_progress_tracker_skip_frame (&animation->tracker, timestamp);
else
gtk_progress_tracker_advance_frame (&animation->tracker, timestamp);
return GTK_STYLE_ANIMATION (animation);
}

View File

@ -68,8 +68,9 @@ GtkStyleAnimation * _gtk_css_animation_new (const char *
GtkCssFillMode fill_mode,
double iteration_count);
GtkStyleAnimation * _gtk_css_animation_copy (GtkCssAnimation *animation,
GtkCssPlayState play_state);
GtkStyleAnimation * _gtk_css_animation_advance_with_play_state (GtkCssAnimation *animation,
gint64 timestamp,
GtkCssPlayState play_state);
const char * _gtk_css_animation_get_name (GtkCssAnimation *animation);

View File

@ -26,19 +26,37 @@
G_DEFINE_TYPE (GtkCssTransition, _gtk_css_transition, GTK_TYPE_STYLE_ANIMATION)
static void
gtk_css_transition_set_values (GtkStyleAnimation *animation,
gint64 for_time_us,
GtkCssAnimatedStyle *style)
static GtkStyleAnimation *
gtk_css_transition_advance (GtkStyleAnimation *style_animation,
gint64 timestamp)
{
GtkCssTransition *transition = GTK_CSS_TRANSITION (animation);
GtkCssTransition *source = GTK_CSS_TRANSITION (style_animation);
GtkCssTransition *transition;
transition = g_object_new (GTK_TYPE_CSS_TRANSITION, NULL);
transition->property = source->property;
transition->start = _gtk_css_value_ref (source->start);
transition->ease = _gtk_css_value_ref (source->ease);
gtk_progress_tracker_init_copy (&source->tracker, &transition->tracker);
gtk_progress_tracker_advance_frame (&transition->tracker, timestamp);
return GTK_STYLE_ANIMATION (transition);
}
static void
gtk_css_transition_apply_values (GtkStyleAnimation *style_animation,
GtkCssAnimatedStyle *style)
{
GtkCssTransition *transition = GTK_CSS_TRANSITION (style_animation);
GtkCssValue *value, *end;
double progress;
GtkProgressState state;
end = gtk_css_animated_style_get_intrinsic_value (style, transition->property);
gtk_progress_tracker_advance_frame (&transition->tracker, for_time_us);
state = gtk_progress_tracker_get_state (&transition->tracker);
if (state == GTK_PROGRESS_STATE_BEFORE)
@ -64,8 +82,7 @@ gtk_css_transition_set_values (GtkStyleAnimation *animation,
}
static gboolean
gtk_css_transition_is_finished (GtkStyleAnimation *animation,
gint64 at_time_us)
gtk_css_transition_is_finished (GtkStyleAnimation *animation)
{
GtkCssTransition *transition = GTK_CSS_TRANSITION (animation);
@ -73,8 +90,7 @@ gtk_css_transition_is_finished (GtkStyleAnimation *animation,
}
static gboolean
gtk_css_transition_is_static (GtkStyleAnimation *animation,
gint64 at_time_us)
gtk_css_transition_is_static (GtkStyleAnimation *animation)
{
GtkCssTransition *transition = GTK_CSS_TRANSITION (animation);
@ -100,7 +116,8 @@ _gtk_css_transition_class_init (GtkCssTransitionClass *klass)
object_class->finalize = gtk_css_transition_finalize;
animation_class->set_values = gtk_css_transition_set_values;
animation_class->advance = gtk_css_transition_advance;
animation_class->apply_values = gtk_css_transition_apply_values;
animation_class->is_finished = gtk_css_transition_is_finished;
animation_class->is_static = gtk_css_transition_is_static;
}

View File

@ -23,23 +23,27 @@
G_DEFINE_ABSTRACT_TYPE (GtkStyleAnimation, _gtk_style_animation, G_TYPE_OBJECT)
static GtkStyleAnimation *
gtk_style_animation_real_advance (GtkStyleAnimation *animation,
gint64 timestamp)
{
return NULL;
}
static void
gtk_style_animation_real_set_values (GtkStyleAnimation *animation,
gint64 for_time_us,
GtkCssAnimatedStyle *style)
gtk_style_animation_real_apply_values (GtkStyleAnimation *animation,
GtkCssAnimatedStyle *style)
{
}
static gboolean
gtk_style_animation_real_is_finished (GtkStyleAnimation *animation,
gint64 at_time_us)
gtk_style_animation_real_is_finished (GtkStyleAnimation *animation)
{
return TRUE;
}
static gboolean
gtk_style_animation_real_is_static (GtkStyleAnimation *animation,
gint64 at_time_us)
gtk_style_animation_real_is_static (GtkStyleAnimation *animation)
{
return FALSE;
}
@ -47,7 +51,8 @@ gtk_style_animation_real_is_static (GtkStyleAnimation *animation,
static void
_gtk_style_animation_class_init (GtkStyleAnimationClass *klass)
{
klass->set_values = gtk_style_animation_real_set_values;
klass->advance = gtk_style_animation_real_advance;
klass->apply_values = gtk_style_animation_real_apply_values;
klass->is_finished = gtk_style_animation_real_is_finished;
klass->is_static = gtk_style_animation_real_is_static;
}
@ -57,10 +62,22 @@ _gtk_style_animation_init (GtkStyleAnimation *animation)
{
}
GtkStyleAnimation *
_gtk_style_animation_advance (GtkStyleAnimation *animation,
gint64 timestamp)
{
GtkStyleAnimationClass *klass;
g_return_val_if_fail (GTK_IS_STYLE_ANIMATION (animation), NULL);
klass = GTK_STYLE_ANIMATION_GET_CLASS (animation);
return klass->advance (animation, timestamp);
}
void
_gtk_style_animation_set_values (GtkStyleAnimation *animation,
gint64 for_time_us,
GtkCssAnimatedStyle *style)
_gtk_style_animation_apply_values (GtkStyleAnimation *animation,
GtkCssAnimatedStyle *style)
{
GtkStyleAnimationClass *klass;
@ -69,12 +86,11 @@ _gtk_style_animation_set_values (GtkStyleAnimation *animation,
klass = GTK_STYLE_ANIMATION_GET_CLASS (animation);
klass->set_values (animation, for_time_us, style);
klass->apply_values (animation, style);
}
gboolean
_gtk_style_animation_is_finished (GtkStyleAnimation *animation,
gint64 at_time_us)
_gtk_style_animation_is_finished (GtkStyleAnimation *animation)
{
GtkStyleAnimationClass *klass;
@ -82,7 +98,7 @@ _gtk_style_animation_is_finished (GtkStyleAnimation *animation,
klass = GTK_STYLE_ANIMATION_GET_CLASS (animation);
return klass->is_finished (animation, at_time_us);
return klass->is_finished (animation);
}
/**
@ -97,8 +113,7 @@ _gtk_style_animation_is_finished (GtkStyleAnimation *animation,
* Returns: %TRUE if @animation will not change anymore after @at_time_us
**/
gboolean
_gtk_style_animation_is_static (GtkStyleAnimation *animation,
gint64 at_time_us)
_gtk_style_animation_is_static (GtkStyleAnimation *animation)
{
GtkStyleAnimationClass *klass;
@ -106,5 +121,5 @@ _gtk_style_animation_is_static (GtkStyleAnimation *animation,
klass = GTK_STYLE_ANIMATION_GET_CLASS (animation);
return klass->is_static (animation, at_time_us);
return klass->is_static (animation);
}

View File

@ -43,24 +43,22 @@ struct _GtkStyleAnimationClass
{
GObjectClass parent_class;
gboolean (* is_finished) (GtkStyleAnimation *animation,
gint64 at_time_us);
gboolean (* is_static) (GtkStyleAnimation *animation,
gint64 at_time_us);
void (* set_values) (GtkStyleAnimation *animation,
gint64 for_time_us,
gboolean (* is_finished) (GtkStyleAnimation *animation);
gboolean (* is_static) (GtkStyleAnimation *animation);
void (* apply_values) (GtkStyleAnimation *animation,
GtkCssAnimatedStyle *style);
GtkStyleAnimation * (* advance) (GtkStyleAnimation *animation,
gint64 timestamp);
};
GType _gtk_style_animation_get_type (void) G_GNUC_CONST;
void _gtk_style_animation_set_values (GtkStyleAnimation *animation,
gint64 for_time_us,
GtkStyleAnimation * _gtk_style_animation_advance (GtkStyleAnimation *animation,
gint64 timestamp);
void _gtk_style_animation_apply_values (GtkStyleAnimation *animation,
GtkCssAnimatedStyle *style);
gboolean _gtk_style_animation_is_finished (GtkStyleAnimation *animation,
gint64 at_time_us);
gboolean _gtk_style_animation_is_static (GtkStyleAnimation *animation,
gint64 at_time_us);
gboolean _gtk_style_animation_is_finished (GtkStyleAnimation *animation);
gboolean _gtk_style_animation_is_static (GtkStyleAnimation *animation);
G_END_DECLS