[gtk+/wip/watson/progress-tracker: 56/60] animatedstyle: don't share styleanimations



commit 867a9bf4aa2f5e47c2b1dfd6a7d70550f1e1fd53
Author: Matt Watson <mattdangerw gmail com>
Date:   Mon Mar 28 01:33:18 2016 -0700

    animatedstyle: don't share styleanimations
    
    Each animated style will have its own unique style animations in
    its animation list. This is necessary to keep the animated styles
    (and all css styles) immutable, now that the style animations
    themselves container mutable state.

 gtk/gtkcssanimatedstyle.c     |   14 ++++++++++--
 gtk/gtkcssanimation.c         |   42 ++++++++++++++++++++++------------------
 gtk/gtkcssanimationprivate.h  |    7 +++--
 gtk/gtkcsstransition.c        |   16 +++++++++++++++
 gtk/gtkcsstransitionprivate.h |    2 +
 5 files changed, 56 insertions(+), 25 deletions(-)
---
diff --git a/gtk/gtkcssanimatedstyle.c b/gtk/gtkcssanimatedstyle.c
index 87e5147..1bee8c0 100644
--- a/gtk/gtkcssanimatedstyle.c
+++ b/gtk/gtkcssanimatedstyle.c
@@ -287,7 +287,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_css_transition_copy (GTK_CSS_TRANSITION (animation));
+                  animations = g_slist_prepend (animations, g_object_ref (animation));
+                }
 
               continue;
             }
@@ -365,8 +368,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_copy (GTK_CSS_ANIMATION (animation));
+          _gtk_css_animation_set_play_state (GTK_CSS_ANIMATION (animation),
+                                             _gtk_css_play_state_value_get (_gtk_css_array_value_get_nth 
(play_states, i)));
         }
       else
         {
@@ -472,6 +476,10 @@ gtk_css_animated_style_new_advance (GtkCssAnimatedStyle *source,
       
       if (_gtk_style_animation_is_finished (animation, timestamp))
         continue;
+      if (GTK_IS_CSS_ANIMATION (animation))
+        animation = _gtk_css_animation_copy (GTK_CSS_ANIMATION (animation));
+      if (GTK_IS_CSS_TRANSITION (animation))
+        animation = _gtk_css_transition_copy (GTK_CSS_TRANSITION (animation));
 
       animations = g_slist_prepend (animations, g_object_ref (animation));
     }
diff --git a/gtk/gtkcssanimation.c b/gtk/gtkcssanimation.c
index 9a8f9b5..28a80f3 100644
--- a/gtk/gtkcssanimation.c
+++ b/gtk/gtkcssanimation.c
@@ -25,6 +25,7 @@
 #include "gtkprogresstrackerprivate.h"
 
 #include <math.h>
+#include <string.h>
 
 G_DEFINE_TYPE (GtkCssAnimation, _gtk_css_animation, GTK_TYPE_STYLE_ANIMATION)
 
@@ -181,18 +182,33 @@ _gtk_css_animation_new (const char      *name,
 
   animation->name = g_strdup (name);
   animation->keyframes = _gtk_css_keyframes_ref (keyframes);
-  animation->duration = duration_us;
   animation->ease = _gtk_css_value_ref (ease);
   animation->direction = direction;
   animation->play_state = play_state;
   animation->fill_mode = fill_mode;
-  animation->iteration_count = iteration_count;
 
   gtk_progress_tracker_start (&animation->tracker, duration_us, delay_us, iteration_count);
 
   return GTK_STYLE_ANIMATION (animation);
 }
 
+GtkStyleAnimation *
+_gtk_css_animation_copy (GtkCssAnimation *source)
+{
+  GtkCssAnimation *animation = g_object_new (GTK_TYPE_CSS_ANIMATION, NULL);
+
+  animation->name = g_strdup (source->name);
+  animation->keyframes = _gtk_css_keyframes_ref (source->keyframes);
+  animation->ease = _gtk_css_value_ref (source->ease);
+  animation->direction = source->direction;
+  animation->play_state = source->play_state;
+  animation->fill_mode = source->fill_mode;
+
+  memcpy (&animation->tracker, &source->tracker, sizeof (source->tracker));
+
+  return GTK_STYLE_ANIMATION (animation);
+}
+
 const char *
 _gtk_css_animation_get_name (GtkCssAnimation *animation)
 {
@@ -201,23 +217,11 @@ _gtk_css_animation_get_name (GtkCssAnimation *animation)
   return animation->name;
 }
 
-GtkStyleAnimation *
-_gtk_css_animation_copy (GtkCssAnimation *animation,
-                         GtkCssPlayState  play_state)
+void
+_gtk_css_animation_set_play_state (GtkCssAnimation *animation,
+                                   GtkCssPlayState  play_state)
 {
-  g_return_val_if_fail (GTK_IS_CSS_ANIMATION (animation), NULL);
+  g_return_if_fail (GTK_IS_CSS_ANIMATION (animation));
 
-  if (animation->play_state == play_state)
-    return g_object_ref (animation);
-
-  return _gtk_css_animation_new (animation->name,
-                                 animation->keyframes,
-                                 - gtk_progress_tracker_get_iteration (&animation->tracker) * 
animation->duration,
-                                 animation->duration,
-                                 animation->ease,
-                                 animation->direction,
-                                 play_state,
-                                 animation->fill_mode,
-                                 animation->iteration_count);
+  animation->play_state = play_state;
 }
-
diff --git a/gtk/gtkcssanimationprivate.h b/gtk/gtkcssanimationprivate.h
index 83b0dfb..e9f6623 100644
--- a/gtk/gtkcssanimationprivate.h
+++ b/gtk/gtkcssanimationprivate.h
@@ -44,7 +44,6 @@ struct _GtkCssAnimation
   char            *name;
   GtkCssKeyframes *keyframes;
   GtkCssValue     *ease;
-  gint64           duration;            /* duration of 1 cycle */
   GtkCssDirection  direction;
   GtkCssPlayState  play_state;
   GtkCssFillMode   fill_mode;
@@ -68,11 +67,13 @@ 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_copy            (GtkCssAnimation   *animation);
 
 const char *            _gtk_css_animation_get_name        (GtkCssAnimation   *animation);
 
+void                    _gtk_css_animation_set_play_state  (GtkCssAnimation   *animation,
+                                                            GtkCssPlayState    play_state);
+
 G_END_DECLS
 
 #endif /* __GTK_CSS_ANIMATION_PRIVATE_H__ */
diff --git a/gtk/gtkcsstransition.c b/gtk/gtkcsstransition.c
index 2c7fa83..d4064f4 100644
--- a/gtk/gtkcsstransition.c
+++ b/gtk/gtkcsstransition.c
@@ -24,6 +24,8 @@
 #include "gtkcsseasevalueprivate.h"
 #include "gtkprogresstrackerprivate.h"
 
+#include <string.h>
+
 G_DEFINE_TYPE (GtkCssTransition, _gtk_css_transition, GTK_TYPE_STYLE_ANIMATION)
 
 static void
@@ -124,6 +126,20 @@ _gtk_css_transition_new (guint        property,
   return GTK_STYLE_ANIMATION (transition);
 }
 
+GtkStyleAnimation *
+_gtk_css_transition_copy (GtkCssTransition *source)
+{
+  GtkCssTransition *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);
+
+  memcpy (&transition->tracker, &source->tracker, sizeof (source->tracker));
+
+  return GTK_STYLE_ANIMATION (transition);
+}
+
 guint
 _gtk_css_transition_get_property (GtkCssTransition *transition)
 {
diff --git a/gtk/gtkcsstransitionprivate.h b/gtk/gtkcsstransitionprivate.h
index 919e042..0f81aa5 100644
--- a/gtk/gtkcsstransitionprivate.h
+++ b/gtk/gtkcsstransitionprivate.h
@@ -58,6 +58,8 @@ GtkStyleAnimation *     _gtk_css_transition_new             (guint
                                                              gint64              duration_us,
                                                              gint64              delay_us);
 
+GtkStyleAnimation *     _gtk_css_transition_copy            (GtkCssTransition   *transition);
+
 guint                   _gtk_css_transition_get_property    (GtkCssTransition   *transition);
 
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]