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 double start_time() const { |
ajuma
2014/04/08 15:44:16
We should make this return a TimeTicks instead of
| |
72 void set_start_time(double monotonic_time) { start_time_ = monotonic_time; } | 73 return (start_time_ - base::TimeTicks()).InSecondsF(); |
73 bool has_set_start_time() const { return !!start_time_; } | 74 } |
75 void set_start_time(base::TimeTicks monotonic_time) { | |
76 start_time_ = monotonic_time; | |
77 } | |
78 bool has_set_start_time() const { | |
79 return !!(start_time_ - base::TimeTicks()).InSecondsF(); | |
ajuma
2014/04/08 15:44:16
return start_time_ != base::TimeTicks()
| |
80 } | |
74 | 81 |
75 double time_offset() const { return time_offset_; } | 82 double time_offset() const { |
76 void set_time_offset(double monotonic_time) { time_offset_ = monotonic_time; } | 83 return (time_offset_ - base::TimeTicks()).InSecondsF(); |
ajuma
2014/04/08 15:44:16
It seems like time_offset_ should be a TimeDelta,
| |
84 } | |
85 void set_time_offset(base::TimeTicks monotonic_time) { | |
ajuma
2014/04/08 15:44:16
TimeDelta?
| |
86 time_offset_ = monotonic_time; | |
87 } | |
77 | 88 |
78 void Suspend(double monotonic_time); | 89 void Suspend(base::TimeTicks monotonic_time); |
79 void Resume(double monotonic_time); | 90 void Resume(base::TimeTicks monotonic_time); |
80 | 91 |
81 // If alternates_direction is true, on odd numbered iterations we reverse the | 92 // If alternates_direction is true, on odd numbered iterations we reverse the |
82 // curve. | 93 // curve. |
83 bool alternates_direction() const { return alternates_direction_; } | 94 bool alternates_direction() const { return alternates_direction_; } |
84 void set_alternates_direction(bool alternates) { | 95 void set_alternates_direction(bool alternates) { |
85 alternates_direction_ = alternates; | 96 alternates_direction_ = alternates; |
86 } | 97 } |
87 | 98 |
88 bool IsFinishedAt(double monotonic_time) const; | 99 bool IsFinishedAt(base::TimeTicks monotonic_time) const; |
89 bool is_finished() const { | 100 bool is_finished() const { |
90 return run_state_ == Finished || | 101 return run_state_ == Finished || |
91 run_state_ == Aborted || | 102 run_state_ == Aborted || |
92 run_state_ == WaitingForDeletion; | 103 run_state_ == WaitingForDeletion; |
93 } | 104 } |
94 | 105 |
95 AnimationCurve* curve() { return curve_.get(); } | 106 AnimationCurve* curve() { return curve_.get(); } |
96 const AnimationCurve* curve() const { return curve_.get(); } | 107 const AnimationCurve* curve() const { return curve_.get(); } |
97 | 108 |
98 // If this is true, even if the animation is running, it will not be tickable | 109 // 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. | 120 // event sent by the corresponding impl animation has been received. |
110 bool received_finished_event() const { | 121 bool received_finished_event() const { |
111 return received_finished_event_; | 122 return received_finished_event_; |
112 } | 123 } |
113 void set_received_finished_event(bool received_finished_event) { | 124 void set_received_finished_event(bool received_finished_event) { |
114 received_finished_event_ = received_finished_event; | 125 received_finished_event_ = received_finished_event; |
115 } | 126 } |
116 | 127 |
117 // Takes the given absolute time, and using the start time and the number | 128 // Takes the given absolute time, and using the start time and the number |
118 // of iterations, returns the relative time in the current iteration. | 129 // of iterations, returns the relative time in the current iteration. |
119 double TrimTimeToCurrentIteration(double monotonic_time) const; | 130 double TrimTimeToCurrentIteration(base::TimeTicks monotonic_time) const; |
120 | 131 |
121 scoped_ptr<Animation> Clone() const; | 132 scoped_ptr<Animation> Clone() const; |
122 scoped_ptr<Animation> CloneAndInitialize(RunState initial_run_state, | 133 scoped_ptr<Animation> CloneAndInitialize(RunState initial_run_state, |
123 double start_time) const; | 134 base::TimeTicks start_time) const; |
124 bool is_controlling_instance() const { return is_controlling_instance_; } | 135 bool is_controlling_instance() const { return is_controlling_instance_; } |
125 | 136 |
126 void PushPropertiesTo(Animation* other) const; | 137 void PushPropertiesTo(Animation* other) const; |
127 | 138 |
128 void set_is_impl_only(bool is_impl_only) { is_impl_only_ = is_impl_only; } | 139 void set_is_impl_only(bool is_impl_only) { is_impl_only_ = is_impl_only; } |
129 bool is_impl_only() const { return is_impl_only_; } | 140 bool is_impl_only() const { return is_impl_only_; } |
130 | 141 |
131 private: | 142 private: |
132 Animation(scoped_ptr<AnimationCurve> curve, | 143 Animation(scoped_ptr<AnimationCurve> curve, |
133 int animation_id, | 144 int animation_id, |
134 int group_id, | 145 int group_id, |
135 TargetProperty target_property); | 146 TargetProperty target_property); |
136 | 147 |
137 scoped_ptr<AnimationCurve> curve_; | 148 scoped_ptr<AnimationCurve> curve_; |
138 | 149 |
139 // IDs are not necessarily unique. | 150 // IDs are not necessarily unique. |
140 int id_; | 151 int id_; |
141 | 152 |
142 // Animations that must be run together are called 'grouped' and have the same | 153 // Animations that must be run together are called 'grouped' and have the same |
143 // group id. Grouped animations are guaranteed to start at the same time and | 154 // group id. Grouped animations are guaranteed to start at the same time and |
144 // no other animations may animate any of the group's target properties until | 155 // no other animations may animate any of the group's target properties until |
145 // all animations in the group have finished animating. Note: an active | 156 // all animations in the group have finished animating. Note: an active |
146 // animation's group id and target property uniquely identify that animation. | 157 // animation's group id and target property uniquely identify that animation. |
147 int group_; | 158 int group_; |
148 | 159 |
149 TargetProperty target_property_; | 160 TargetProperty target_property_; |
150 RunState run_state_; | 161 RunState run_state_; |
151 int iterations_; | 162 int iterations_; |
152 double start_time_; | 163 base::TimeTicks start_time_; |
153 bool alternates_direction_; | 164 bool alternates_direction_; |
154 | 165 |
155 // The time offset effectively pushes the start of the animation back in time. | 166 // The time offset effectively pushes the start of the animation back in time. |
156 // This is used for resuming paused animations -- an animation is added with a | 167 // This is used for resuming paused animations -- an animation is added with a |
157 // non-zero time offset, causing the animation to skip ahead to the desired | 168 // non-zero time offset, causing the animation to skip ahead to the desired |
158 // point in time. | 169 // point in time. |
159 double time_offset_; | 170 base::TimeTicks time_offset_; |
ajuma
2014/04/08 15:44:16
TimeDelta seems more appropriate for an offset.
| |
160 | 171 |
161 bool needs_synchronized_start_time_; | 172 bool needs_synchronized_start_time_; |
162 bool received_finished_event_; | 173 bool received_finished_event_; |
163 | 174 |
164 // When an animation is suspended, it behaves as if it is paused and it also | 175 // When an animation is suspended, it behaves as if it is paused and it also |
165 // ignores all run state changes until it is resumed. This is used for testing | 176 // ignores all run state changes until it is resumed. This is used for testing |
166 // purposes. | 177 // purposes. |
167 bool suspended_; | 178 bool suspended_; |
168 | 179 |
169 // These are used in TrimTimeToCurrentIteration to account for time | 180 // These are used in TrimTimeToCurrentIteration to account for time |
(...skipping 13 matching lines...) Expand all Loading... | |
183 bool is_controlling_instance_; | 194 bool is_controlling_instance_; |
184 | 195 |
185 bool is_impl_only_; | 196 bool is_impl_only_; |
186 | 197 |
187 DISALLOW_COPY_AND_ASSIGN(Animation); | 198 DISALLOW_COPY_AND_ASSIGN(Animation); |
188 }; | 199 }; |
189 | 200 |
190 } // namespace cc | 201 } // namespace cc |
191 | 202 |
192 #endif // CC_ANIMATION_ANIMATION_H_ | 203 #endif // CC_ANIMATION_ANIMATION_H_ |
OLD | NEW |