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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 int group_id, | 56 int group_id, |
56 TargetProperty target_property); | 57 TargetProperty target_property); |
57 | 58 |
58 virtual ~Animation(); | 59 virtual ~Animation(); |
59 | 60 |
60 int id() const { return id_; } | 61 int id() const { return id_; } |
61 int group() const { return group_; } | 62 int group() const { return group_; } |
62 TargetProperty target_property() const { return target_property_; } | 63 TargetProperty target_property() const { return target_property_; } |
63 | 64 |
64 RunState run_state() const { return run_state_; } | 65 RunState run_state() const { return run_state_; } |
65 void SetRunState(RunState run_state, double monotonic_time); | 66 void SetRunState(RunState run_state, base::TimeTicks monotonic_time); |
66 | 67 |
67 // This is the number of times that the animation will play. If this | 68 // This is the number of times that the animation will play. If this |
68 // value is zero the animation will not play. If it is negative, then | 69 // value is zero the animation will not play. If it is negative, then |
69 // the animation will loop indefinitely. | 70 // the animation will loop indefinitely. |
70 int iterations() const { return iterations_; } | 71 int iterations() const { return iterations_; } |
71 void set_iterations(int n) { iterations_ = n; } | 72 void set_iterations(int n) { iterations_ = n; } |
72 | 73 |
73 double start_time() const { return start_time_; } | 74 base::TimeTicks start_time() const { return start_time_; } |
74 void set_start_time(double monotonic_time) { start_time_ = monotonic_time; } | |
75 bool has_set_start_time() const { return !!start_time_; } | |
76 | 75 |
77 double time_offset() const { return time_offset_; } | 76 void set_start_time(base::TimeTicks monotonic_time) { |
78 void set_time_offset(double monotonic_time) { time_offset_ = monotonic_time; } | 77 start_time_ = monotonic_time; |
| 78 } |
| 79 bool has_set_start_time() const { return (start_time_ != base::TimeTicks()); } |
79 | 80 |
80 void Suspend(double monotonic_time); | 81 base::TimeDelta time_offset() const { return time_offset_; } |
81 void Resume(double monotonic_time); | 82 void set_time_offset(base::TimeDelta monotonic_time) { |
| 83 time_offset_ = monotonic_time; |
| 84 } |
| 85 |
| 86 void Suspend(base::TimeTicks monotonic_time); |
| 87 void Resume(base::TimeTicks monotonic_time); |
82 | 88 |
83 Direction direction() { return direction_; } | 89 Direction direction() { return direction_; } |
84 void set_direction(Direction direction) { direction_ = direction; } | 90 void set_direction(Direction direction) { direction_ = direction; } |
85 | 91 |
86 bool IsFinishedAt(double monotonic_time) const; | 92 bool IsFinishedAt(base::TimeTicks monotonic_time) const; |
87 bool is_finished() const { | 93 bool is_finished() const { |
88 return run_state_ == Finished || | 94 return run_state_ == Finished || |
89 run_state_ == Aborted || | 95 run_state_ == Aborted || |
90 run_state_ == WaitingForDeletion; | 96 run_state_ == WaitingForDeletion; |
91 } | 97 } |
92 | 98 |
93 AnimationCurve* curve() { return curve_.get(); } | 99 AnimationCurve* curve() { return curve_.get(); } |
94 const AnimationCurve* curve() const { return curve_.get(); } | 100 const AnimationCurve* curve() const { return curve_.get(); } |
95 | 101 |
96 // If this is true, even if the animation is running, it will not be tickable | 102 // If this is true, even if the animation is running, it will not be tickable |
(...skipping 10 matching lines...) Expand all Loading... |
107 // event sent by the corresponding impl animation has been received. | 113 // event sent by the corresponding impl animation has been received. |
108 bool received_finished_event() const { | 114 bool received_finished_event() const { |
109 return received_finished_event_; | 115 return received_finished_event_; |
110 } | 116 } |
111 void set_received_finished_event(bool received_finished_event) { | 117 void set_received_finished_event(bool received_finished_event) { |
112 received_finished_event_ = received_finished_event; | 118 received_finished_event_ = received_finished_event; |
113 } | 119 } |
114 | 120 |
115 // Takes the given absolute time, and using the start time and the number | 121 // Takes the given absolute time, and using the start time and the number |
116 // of iterations, returns the relative time in the current iteration. | 122 // of iterations, returns the relative time in the current iteration. |
117 double TrimTimeToCurrentIteration(double monotonic_time) const; | 123 double TrimTimeToCurrentIteration(base::TimeTicks monotonic_time) const; |
118 | 124 |
119 scoped_ptr<Animation> CloneAndInitialize(RunState initial_run_state) const; | 125 scoped_ptr<Animation> CloneAndInitialize(RunState initial_run_state) const; |
| 126 |
120 bool is_controlling_instance() const { return is_controlling_instance_; } | 127 bool is_controlling_instance() const { return is_controlling_instance_; } |
121 | 128 |
122 void PushPropertiesTo(Animation* other) const; | 129 void PushPropertiesTo(Animation* other) const; |
123 | 130 |
124 void set_is_impl_only(bool is_impl_only) { is_impl_only_ = is_impl_only; } | 131 void set_is_impl_only(bool is_impl_only) { is_impl_only_ = is_impl_only; } |
125 bool is_impl_only() const { return is_impl_only_; } | 132 bool is_impl_only() const { return is_impl_only_; } |
126 | 133 |
127 void set_affects_active_observers(bool affects_active_observers) { | 134 void set_affects_active_observers(bool affects_active_observers) { |
128 affects_active_observers_ = affects_active_observers; | 135 affects_active_observers_ = affects_active_observers; |
129 } | 136 } |
(...skipping 18 matching lines...) Expand all Loading... |
148 // Animations that must be run together are called 'grouped' and have the same | 155 // Animations that must be run together are called 'grouped' and have the same |
149 // group id. Grouped animations are guaranteed to start at the same time and | 156 // group id. Grouped animations are guaranteed to start at the same time and |
150 // no other animations may animate any of the group's target properties until | 157 // no other animations may animate any of the group's target properties until |
151 // all animations in the group have finished animating. Note: an active | 158 // all animations in the group have finished animating. Note: an active |
152 // animation's group id and target property uniquely identify that animation. | 159 // animation's group id and target property uniquely identify that animation. |
153 int group_; | 160 int group_; |
154 | 161 |
155 TargetProperty target_property_; | 162 TargetProperty target_property_; |
156 RunState run_state_; | 163 RunState run_state_; |
157 int iterations_; | 164 int iterations_; |
158 double start_time_; | 165 base::TimeTicks start_time_; |
159 Direction direction_; | 166 Direction direction_; |
160 | 167 |
161 // The time offset effectively pushes the start of the animation back in time. | 168 // The time offset effectively pushes the start of the animation back in time. |
162 // This is used for resuming paused animations -- an animation is added with a | 169 // This is used for resuming paused animations -- an animation is added with a |
163 // non-zero time offset, causing the animation to skip ahead to the desired | 170 // non-zero time offset, causing the animation to skip ahead to the desired |
164 // point in time. | 171 // point in time. |
165 double time_offset_; | 172 base::TimeDelta time_offset_; |
166 | 173 |
167 bool needs_synchronized_start_time_; | 174 bool needs_synchronized_start_time_; |
168 bool received_finished_event_; | 175 bool received_finished_event_; |
169 | 176 |
170 // When an animation is suspended, it behaves as if it is paused and it also | 177 // When an animation is suspended, it behaves as if it is paused and it also |
171 // ignores all run state changes until it is resumed. This is used for testing | 178 // ignores all run state changes until it is resumed. This is used for testing |
172 // purposes. | 179 // purposes. |
173 bool suspended_; | 180 bool suspended_; |
174 | 181 |
175 // These are used in TrimTimeToCurrentIteration to account for time | 182 // These are used in TrimTimeToCurrentIteration to account for time |
176 // spent while paused. This is not included in AnimationState since it | 183 // spent while paused. This is not included in AnimationState since it |
177 // there is absolutely no need for clients of this controller to know | 184 // there is absolutely no need for clients of this controller to know |
178 // about these values. | 185 // about these values. |
179 double pause_time_; | 186 base::TimeTicks pause_time_; |
180 double total_paused_time_; | 187 base::TimeDelta total_paused_time_; |
181 | 188 |
182 // Animations lead dual lives. An active animation will be conceptually owned | 189 // Animations lead dual lives. An active animation will be conceptually owned |
183 // by two controllers, one on the impl thread and one on the main. In reality, | 190 // by two controllers, one on the impl thread and one on the main. In reality, |
184 // there will be two separate Animation instances for the same animation. They | 191 // there will be two separate Animation instances for the same animation. They |
185 // will have the same group id and the same target property (these two values | 192 // will have the same group id and the same target property (these two values |
186 // uniquely identify an animation). The instance on the impl thread is the | 193 // uniquely identify an animation). The instance on the impl thread is the |
187 // instance that ultimately controls the values of the animating layer and so | 194 // instance that ultimately controls the values of the animating layer and so |
188 // we will refer to it as the 'controlling instance'. | 195 // we will refer to it as the 'controlling instance'. |
189 bool is_controlling_instance_; | 196 bool is_controlling_instance_; |
190 | 197 |
(...skipping 12 matching lines...) Expand all Loading... |
203 // longer affect any observers, and are deleted. | 210 // longer affect any observers, and are deleted. |
204 bool affects_active_observers_; | 211 bool affects_active_observers_; |
205 bool affects_pending_observers_; | 212 bool affects_pending_observers_; |
206 | 213 |
207 DISALLOW_COPY_AND_ASSIGN(Animation); | 214 DISALLOW_COPY_AND_ASSIGN(Animation); |
208 }; | 215 }; |
209 | 216 |
210 } // namespace cc | 217 } // namespace cc |
211 | 218 |
212 #endif // CC_ANIMATION_ANIMATION_H_ | 219 #endif // CC_ANIMATION_ANIMATION_H_ |
OLD | NEW |