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



commit 9e881790ffd7ffdd4b805172cb29c0cc52fa540e
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     |   16 ++++++++++++----
 gtk/gtkcssanimation.c         |   33 +++++++++++++++++++--------------
 gtk/gtkcssanimationprivate.h  |    6 ++++--
 gtk/gtkcsstransition.c        |   20 ++++++++++++++++++++
 gtk/gtkcsstransitionprivate.h |    2 ++
 5 files changed, 57 insertions(+), 20 deletions(-)
---
diff --git a/gtk/gtkcssanimatedstyle.c b/gtk/gtkcssanimatedstyle.c
index 87e5147..3b5e749 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,8 +476,12 @@ 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));
+      animations = g_slist_prepend (animations, animation);
     }
   animations = g_slist_reverse (animations);
 
diff --git a/gtk/gtkcssanimation.c b/gtk/gtkcssanimation.c
index ee333cd..a69ca92 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)
 
@@ -191,32 +192,20 @@ _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_copy (GtkCssAnimation *source)
 {
   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);
   animation->keyframes = _gtk_css_keyframes_ref (source->keyframes);
   animation->ease = _gtk_css_value_ref (source->ease);
   animation->direction = source->direction;
-  animation->play_state = play_state;
+  animation->play_state = source->play_state;
   animation->fill_mode = source->fill_mode;
 
   memcpy (&animation->tracker, &source->tracker, sizeof (source->tracker));
@@ -224,3 +213,19 @@ _gtk_css_animation_copy (GtkCssAnimation *source,
   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;
+}
+
+void
+_gtk_css_animation_set_play_state (GtkCssAnimation *animation,
+                                   GtkCssPlayState  play_state)
+{
+  g_return_if_fail (GTK_IS_CSS_ANIMATION (animation));
+
+  animation->play_state = play_state;
+}
diff --git a/gtk/gtkcssanimationprivate.h b/gtk/gtkcssanimationprivate.h
index 68c4dce..e9f6623 100644
--- a/gtk/gtkcssanimationprivate.h
+++ b/gtk/gtkcssanimationprivate.h
@@ -67,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 a542f6e..846e213 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
@@ -132,6 +134,24 @@ _gtk_css_transition_new (guint        property,
   return GTK_STYLE_ANIMATION (transition);
 }
 
+GtkStyleAnimation *
+_gtk_css_transition_copy (GtkCssTransition *source)
+{
+  GtkCssTransition *transition;
+
+  g_return_val_if_fail (GTK_IS_CSS_TRANSITION (source), NULL);
+
+  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]