[gtk+/wip/watson/progress-tracker: 5/5] animatedstyle: don't share styleanimations
- From: Matthew Watson <watson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/watson/progress-tracker: 5/5] animatedstyle: don't share styleanimations
- Date: Wed, 6 Apr 2016 22:26:20 +0000 (UTC)
commit b384a523a03cec4fd20a863377feb1082b6895a3
Author: Matt Watson <mattdangerw gmail com>
Date: Tue Mar 22 01:10:21 2016 -0700
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.
gtk/gtkcssanimatedstyle.c | 29 +++++++++++---------
gtk/gtkcssanimation.c | 59 +++++++++++++++++++++------------------
gtk/gtkcssanimationprivate.h | 5 ++-
gtk/gtkcsstransition.c | 37 ++++++++++++++++++-------
gtk/gtkstyleanimation.c | 51 ++++++++++++++++++++++------------
gtk/gtkstyleanimationprivate.h | 22 +++++++--------
6 files changed, 121 insertions(+), 82 deletions(-)
---
diff --git a/gtk/gtkcssanimatedstyle.c b/gtk/gtkcssanimatedstyle.c
index 9847449..3fa005f 100644
--- a/gtk/gtkcssanimatedstyle.c
+++ b/gtk/gtkcssanimatedstyle.c
@@ -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);
}
diff --git a/gtk/gtkcssanimation.c b/gtk/gtkcssanimation.c
index af47934..109ec4c 100644
--- a/gtk/gtkcssanimation.c
+++ b/gtk/gtkcssanimation.c
@@ -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;
}
@@ -198,25 +202,15 @@ _gtk_css_animation_new (const char *name,
return GTK_STYLE_ANIMATION (animation);
}
-const char *
-_gtk_css_animation_get_name (GtkCssAnimation *animation)
-{
- g_return_val_if_fail (GTK_IS_CSS_ANIMATION (animation), NULL);
-
- return animation->name;
-}
-
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 +220,19 @@ _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);
}
+const char *
+_gtk_css_animation_get_name (GtkCssAnimation *animation)
+{
+ g_return_val_if_fail (GTK_IS_CSS_ANIMATION (animation), NULL);
+
+ return animation->name;
+}
diff --git a/gtk/gtkcssanimationprivate.h b/gtk/gtkcssanimationprivate.h
index c0d6fa2..811cddf 100644
--- a/gtk/gtkcssanimationprivate.h
+++ b/gtk/gtkcssanimationprivate.h
@@ -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);
diff --git a/gtk/gtkcsstransition.c b/gtk/gtkcsstransition.c
index c9b3197..5f8e1a4 100644
--- a/gtk/gtkcsstransition.c
+++ b/gtk/gtkcsstransition.c
@@ -26,19 +26,37 @@
G_DEFINE_TYPE (GtkCssTransition, _gtk_css_transition, GTK_TYPE_STYLE_ANIMATION)
+static GtkStyleAnimation *
+gtk_css_transition_advance (GtkStyleAnimation *style_animation,
+ gint64 timestamp)
+{
+ 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_set_values (GtkStyleAnimation *animation,
- gint64 for_time_us,
- GtkCssAnimatedStyle *style)
+gtk_css_transition_apply_values (GtkStyleAnimation *style_animation,
+ GtkCssAnimatedStyle *style)
{
- GtkCssTransition *transition = GTK_CSS_TRANSITION (animation);
+ 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;
}
diff --git a/gtk/gtkstyleanimation.c b/gtk/gtkstyleanimation.c
index 3c1a887..89f8319 100644
--- a/gtk/gtkstyleanimation.c
+++ b/gtk/gtkstyleanimation.c
@@ -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);
}
diff --git a/gtk/gtkstyleanimationprivate.h b/gtk/gtkstyleanimationprivate.h
index 6981004..dacb159 100644
--- a/gtk/gtkstyleanimationprivate.h
+++ b/gtk/gtkstyleanimationprivate.h
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]