 Chromium Code Reviews
 Chromium Code Reviews Issue 231133002:
  CC::Animations should use TimeTicks & TimeDelta to represent time  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 231133002:
  CC::Animations should use TimeTicks & TimeDelta to represent time  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef CC_ANIMATION_ANIMATION_H_ | 5 #ifndef CC_ANIMATION_ANIMATION_H_ | 
| 6 #define CC_ANIMATION_ANIMATION_H_ | 6 #define CC_ANIMATION_ANIMATION_H_ | 
| 7 | 7 | 
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" | 
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" | 
| 10 #include "base/time/time.h" | |
| 10 #include "cc/base/cc_export.h" | 11 #include "cc/base/cc_export.h" | 
| 11 | 12 | 
| 12 namespace cc { | 13 namespace cc { | 
| 13 | 14 | 
| 14 class AnimationCurve; | 15 class AnimationCurve; | 
| 15 | 16 | 
| 16 // An Animation contains all the state required to play an AnimationCurve. | 17 // An Animation contains all the state required to play an AnimationCurve. | 
| 17 // Specifically, the affected property, the run state (paused, finished, etc.), | 18 // Specifically, the affected property, the run state (paused, finished, etc.), | 
| 18 // loop count, last pause time, and the total time spent paused. | 19 // loop count, last pause time, and the total time spent paused. | 
| 19 class CC_EXPORT Animation { | 20 class CC_EXPORT Animation { | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 int group_id, | 54 int group_id, | 
| 54 TargetProperty target_property); | 55 TargetProperty target_property); | 
| 55 | 56 | 
| 56 virtual ~Animation(); | 57 virtual ~Animation(); | 
| 57 | 58 | 
| 58 int id() const { return id_; } | 59 int id() const { return id_; } | 
| 59 int group() const { return group_; } | 60 int group() const { return group_; } | 
| 60 TargetProperty target_property() const { return target_property_; } | 61 TargetProperty target_property() const { return target_property_; } | 
| 61 | 62 | 
| 62 RunState run_state() const { return run_state_; } | 63 RunState run_state() const { return run_state_; } | 
| 63 void SetRunState(RunState run_state, double monotonic_time); | 64 void SetRunState(RunState run_state, base::TimeTicks monotonic_time); | 
| 64 | 65 | 
| 65 // This is the number of times that the animation will play. If this | 66 // This is the number of times that the animation will play. If this | 
| 66 // value is zero the animation will not play. If it is negative, then | 67 // value is zero the animation will not play. If it is negative, then | 
| 67 // the animation will loop indefinitely. | 68 // the animation will loop indefinitely. | 
| 68 int iterations() const { return iterations_; } | 69 int iterations() const { return iterations_; } | 
| 69 void set_iterations(int n) { iterations_ = n; } | 70 void set_iterations(int n) { iterations_ = n; } | 
| 70 | 71 | 
| 71 double start_time() const { return start_time_; } | 72 base::TimeTicks start_time() const { return start_time_; } | 
| 72 void set_start_time(double monotonic_time) { start_time_ = monotonic_time; } | |
| 73 bool has_set_start_time() const { return !!start_time_; } | |
| 74 | 73 | 
| 75 double time_offset() const { return time_offset_; } | 74 void set_start_time(base::TimeTicks monotonic_time) { | 
| 76 void set_time_offset(double monotonic_time) { time_offset_ = monotonic_time; } | 75 start_time_ = monotonic_time; | 
| 76 } | |
| 77 bool has_set_start_time() const { return (start_time_ != base::TimeTicks()); } | |
| 77 | 78 | 
| 78 void Suspend(double monotonic_time); | 79 base::TimeDelta time_offset() const { return time_offset_; } | 
| 79 void Resume(double monotonic_time); | 80 void set_time_offset(base::TimeDelta monotonic_time) { | 
| 81 time_offset_ = monotonic_time; | |
| 82 } | |
| 83 | |
| 84 void Suspend(base::TimeTicks monotonic_time); | |
| 85 void Resume(base::TimeTicks monotonic_time); | |
| 80 | 86 | 
| 81 // If alternates_direction is true, on odd numbered iterations we reverse the | 87 // If alternates_direction is true, on odd numbered iterations we reverse the | 
| 82 // curve. | 88 // curve. | 
| 83 bool alternates_direction() const { return alternates_direction_; } | 89 bool alternates_direction() const { return alternates_direction_; } | 
| 84 void set_alternates_direction(bool alternates) { | 90 void set_alternates_direction(bool alternates) { | 
| 85 alternates_direction_ = alternates; | 91 alternates_direction_ = alternates; | 
| 86 } | 92 } | 
| 87 | 93 | 
| 88 bool IsFinishedAt(double monotonic_time) const; | 94 bool IsFinishedAt(base::TimeTicks monotonic_time) const; | 
| 89 bool is_finished() const { | 95 bool is_finished() const { | 
| 90 return run_state_ == Finished || | 96 return run_state_ == Finished || | 
| 91 run_state_ == Aborted || | 97 run_state_ == Aborted || | 
| 92 run_state_ == WaitingForDeletion; | 98 run_state_ == WaitingForDeletion; | 
| 93 } | 99 } | 
| 94 | 100 | 
| 95 AnimationCurve* curve() { return curve_.get(); } | 101 AnimationCurve* curve() { return curve_.get(); } | 
| 96 const AnimationCurve* curve() const { return curve_.get(); } | 102 const AnimationCurve* curve() const { return curve_.get(); } | 
| 97 | 103 | 
| 98 // If this is true, even if the animation is running, it will not be tickable | 104 // If this is true, even if the animation is running, it will not be tickable | 
| (...skipping 10 matching lines...) Expand all Loading... | |
| 109 // event sent by the corresponding impl animation has been received. | 115 // event sent by the corresponding impl animation has been received. | 
| 110 bool received_finished_event() const { | 116 bool received_finished_event() const { | 
| 111 return received_finished_event_; | 117 return received_finished_event_; | 
| 112 } | 118 } | 
| 113 void set_received_finished_event(bool received_finished_event) { | 119 void set_received_finished_event(bool received_finished_event) { | 
| 114 received_finished_event_ = received_finished_event; | 120 received_finished_event_ = received_finished_event; | 
| 115 } | 121 } | 
| 116 | 122 | 
| 117 // Takes the given absolute time, and using the start time and the number | 123 // Takes the given absolute time, and using the start time and the number | 
| 118 // of iterations, returns the relative time in the current iteration. | 124 // of iterations, returns the relative time in the current iteration. | 
| 119 double TrimTimeToCurrentIteration(double monotonic_time) const; | 125 double TrimTimeToCurrentIteration(base::TimeTicks monotonic_time) const; | 
| 120 | 126 | 
| 121 scoped_ptr<Animation> CloneAndInitialize(RunState initial_run_state) const; | 127 scoped_ptr<Animation> CloneAndInitialize(RunState initial_run_state) const; | 
| 128 | |
| 122 bool is_controlling_instance() const { return is_controlling_instance_; } | 129 bool is_controlling_instance() const { return is_controlling_instance_; } | 
| 123 | 130 | 
| 124 void PushPropertiesTo(Animation* other) const; | 131 void PushPropertiesTo(Animation* other) const; | 
| 125 | 132 | 
| 126 void set_is_impl_only(bool is_impl_only) { is_impl_only_ = is_impl_only; } | 133 void set_is_impl_only(bool is_impl_only) { is_impl_only_ = is_impl_only; } | 
| 127 bool is_impl_only() const { return is_impl_only_; } | 134 bool is_impl_only() const { return is_impl_only_; } | 
| 128 | 135 | 
| 129 private: | 136 private: | 
| 130 Animation(scoped_ptr<AnimationCurve> curve, | 137 Animation(scoped_ptr<AnimationCurve> curve, | 
| 131 int animation_id, | 138 int animation_id, | 
| 132 int group_id, | 139 int group_id, | 
| 133 TargetProperty target_property); | 140 TargetProperty target_property); | 
| 134 | 141 | 
| 135 scoped_ptr<AnimationCurve> curve_; | 142 scoped_ptr<AnimationCurve> curve_; | 
| 136 | 143 | 
| 137 // IDs are not necessarily unique. | 144 // IDs are not necessarily unique. | 
| 138 int id_; | 145 int id_; | 
| 139 | 146 | 
| 140 // Animations that must be run together are called 'grouped' and have the same | 147 // Animations that must be run together are called 'grouped' and have the same | 
| 141 // group id. Grouped animations are guaranteed to start at the same time and | 148 // group id. Grouped animations are guaranteed to start at the same time and | 
| 142 // no other animations may animate any of the group's target properties until | 149 // no other animations may animate any of the group's target properties until | 
| 143 // all animations in the group have finished animating. Note: an active | 150 // all animations in the group have finished animating. Note: an active | 
| 144 // animation's group id and target property uniquely identify that animation. | 151 // animation's group id and target property uniquely identify that animation. | 
| 145 int group_; | 152 int group_; | 
| 146 | 153 | 
| 147 TargetProperty target_property_; | 154 TargetProperty target_property_; | 
| 148 RunState run_state_; | 155 RunState run_state_; | 
| 149 int iterations_; | 156 int iterations_; | 
| 150 double start_time_; | 157 base::TimeTicks start_time_; | 
| 151 bool alternates_direction_; | 158 bool alternates_direction_; | 
| 152 | 159 | 
| 153 // The time offset effectively pushes the start of the animation back in time. | 160 // The time offset effectively pushes the start of the animation back in time. | 
| 154 // This is used for resuming paused animations -- an animation is added with a | 161 // This is used for resuming paused animations -- an animation is added with a | 
| 155 // non-zero time offset, causing the animation to skip ahead to the desired | 162 // non-zero time offset, causing the animation to skip ahead to the desired | 
| 156 // point in time. | 163 // point in time. | 
| 157 double time_offset_; | 164 base::TimeDelta time_offset_; | 
| 158 | 165 | 
| 159 bool needs_synchronized_start_time_; | 166 bool needs_synchronized_start_time_; | 
| 160 bool received_finished_event_; | 167 bool received_finished_event_; | 
| 161 | 168 | 
| 162 // When an animation is suspended, it behaves as if it is paused and it also | 169 // When an animation is suspended, it behaves as if it is paused and it also | 
| 163 // ignores all run state changes until it is resumed. This is used for testing | 170 // ignores all run state changes until it is resumed. This is used for testing | 
| 164 // purposes. | 171 // purposes. | 
| 165 bool suspended_; | 172 bool suspended_; | 
| 166 | 173 | 
| 167 // These are used in TrimTimeToCurrentIteration to account for time | 174 // These are used in TrimTimeToCurrentIteration to account for time | 
| 168 // spent while paused. This is not included in AnimationState since it | 175 // spent while paused. This is not included in AnimationState since it | 
| 169 // there is absolutely no need for clients of this controller to know | 176 // there is absolutely no need for clients of this controller to know | 
| 170 // about these values. | 177 // about these values. | 
| 171 double pause_time_; | 178 base::TimeTicks pause_time_; | 
| 172 double total_paused_time_; | 179 base::TimeTicks total_paused_time_; | 
| 
ajuma
2014/04/24 20:41:36
These should be TimeDelta (since they're measuring
 
Sikugu_
2014/05/05 07:09:19
Done.
 | |
| 173 | 180 | 
| 174 // Animations lead dual lives. An active animation will be conceptually owned | 181 // Animations lead dual lives. An active animation will be conceptually owned | 
| 175 // by two controllers, one on the impl thread and one on the main. In reality, | 182 // by two controllers, one on the impl thread and one on the main. In reality, | 
| 176 // there will be two separate Animation instances for the same animation. They | 183 // there will be two separate Animation instances for the same animation. They | 
| 177 // will have the same group id and the same target property (these two values | 184 // will have the same group id and the same target property (these two values | 
| 178 // uniquely identify an animation). The instance on the impl thread is the | 185 // uniquely identify an animation). The instance on the impl thread is the | 
| 179 // instance that ultimately controls the values of the animating layer and so | 186 // instance that ultimately controls the values of the animating layer and so | 
| 180 // we will refer to it as the 'controlling instance'. | 187 // we will refer to it as the 'controlling instance'. | 
| 181 bool is_controlling_instance_; | 188 bool is_controlling_instance_; | 
| 182 | 189 | 
| 183 bool is_impl_only_; | 190 bool is_impl_only_; | 
| 184 | 191 | 
| 185 DISALLOW_COPY_AND_ASSIGN(Animation); | 192 DISALLOW_COPY_AND_ASSIGN(Animation); | 
| 186 }; | 193 }; | 
| 187 | 194 | 
| 188 } // namespace cc | 195 } // namespace cc | 
| 189 | 196 | 
| 190 #endif // CC_ANIMATION_ANIMATION_H_ | 197 #endif // CC_ANIMATION_ANIMATION_H_ | 
| OLD | NEW |