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 "base/time/time.h" |
11 #include "cc/base/cc_export.h" | 11 #include "cc/base/cc_export.h" |
12 | 12 |
13 namespace cc { | 13 namespace cc { |
14 | 14 |
15 class AnimationCurve; | 15 class AnimationCurve; |
16 | 16 |
17 // An Animation contains all the state required to play an AnimationCurve. | 17 // An Animation contains all the state required to play an AnimationCurve. |
18 // Specifically, the affected property, the run state (paused, finished, etc.), | 18 // Specifically, the affected property, the run state (paused, finished, etc.), |
19 // loop count, last pause time, and the total time spent paused. | 19 // loop count, last pause time, and the total time spent paused. |
20 class CC_EXPORT Animation { | 20 class CC_EXPORT Animation { |
21 public: | 21 public: |
22 // Animations begin in the 'WAITING_FOR_TARGET_AVAILABILITY' state. An | 22 // Animations begin in the 'WaitingForTargetAvailability' state. An Animation |
23 // Animation waiting for target availibility will run as soon as its target | 23 // waiting for target availibility will run as soon as its target property |
24 // property is free (and all the animations animating with it are also able to | 24 // is free (and all the animations animating with it are also able to run). |
25 // run). When this time arrives, the controller will move the animation into | 25 // When this time arrives, the controller will move the animation into the |
26 // the STARTING state, and then into the RUNNING state. RUNNING animations may | 26 // Starting state, and then into the Running state. Running animations may |
27 // toggle between RUNNING and PAUSED, and may be stopped by moving into either | 27 // toggle between Running and Paused, and may be stopped by moving into either |
28 // the ABORTED or FINISHED states. A FINISHED animation was allowed to run to | 28 // the Aborted or Finished states. A Finished animation was allowed to run to |
29 // completion, but an ABORTED animation was not. | 29 // completion, but an Aborted animation was not. |
30 enum RunState { | 30 enum RunState { |
31 WAITING_FOR_TARGET_AVAILABILITY = 0, | 31 WaitingForTargetAvailability = 0, |
32 WAITING_FOR_DELETION, | 32 WaitingForDeletion, |
33 STARTING, | 33 Starting, |
34 RUNNING, | 34 Running, |
35 PAUSED, | 35 Paused, |
36 FINISHED, | 36 Finished, |
37 ABORTED, | 37 Aborted, |
38 // This sentinel must be last. | 38 // This sentinel must be last. |
39 LAST_RUN_STATE = ABORTED | 39 RunStateEnumSize |
40 }; | 40 }; |
41 | 41 |
42 enum TargetProperty { | 42 enum TargetProperty { |
43 TRANSFORM = 0, | 43 Transform = 0, |
44 OPACITY, | 44 Opacity, |
45 FILTER, | 45 Filter, |
46 SCROLL_OFFSET, | 46 ScrollOffset, |
47 BACKGROUND_COLOR, | 47 BackgroundColor, |
48 // This sentinel must be last. | 48 // This sentinel must be last. |
49 LAST_TARGET_PROPERTY = BACKGROUND_COLOR | 49 TargetPropertyEnumSize |
50 }; | 50 }; |
51 | 51 |
52 enum Direction { | 52 enum Direction { Normal, Reverse, Alternate, AlternateReverse }; |
53 DIRECTION_NORMAL, | |
54 DIRECTION_REVERSE, | |
55 DIRECTION_ALTERNATE, | |
56 DIRECTION_ALTERNATE_REVERSE | |
57 }; | |
58 | 53 |
59 enum FillMode { | 54 enum FillMode { |
60 FILL_MODE_NONE, | 55 FillModeNone, |
61 FILL_MODE_FORWARDS, | 56 FillModeForwards, |
62 FILL_MODE_BACKWARDS, | 57 FillModeBackwards, |
63 FILL_MODE_BOTH | 58 FillModeBoth |
64 }; | 59 }; |
65 | 60 |
66 static scoped_ptr<Animation> Create(scoped_ptr<AnimationCurve> curve, | 61 static scoped_ptr<Animation> Create(scoped_ptr<AnimationCurve> curve, |
67 int animation_id, | 62 int animation_id, |
68 int group_id, | 63 int group_id, |
69 TargetProperty target_property); | 64 TargetProperty target_property); |
70 | 65 |
71 virtual ~Animation(); | 66 virtual ~Animation(); |
72 | 67 |
73 int id() const { return id_; } | 68 int id() const { return id_; } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 FillMode fill_mode() { return fill_mode_; } | 104 FillMode fill_mode() { return fill_mode_; } |
110 void set_fill_mode(FillMode fill_mode) { fill_mode_ = fill_mode; } | 105 void set_fill_mode(FillMode fill_mode) { fill_mode_ = fill_mode; } |
111 | 106 |
112 double playback_rate() { return playback_rate_; } | 107 double playback_rate() { return playback_rate_; } |
113 void set_playback_rate(double playback_rate) { | 108 void set_playback_rate(double playback_rate) { |
114 playback_rate_ = playback_rate; | 109 playback_rate_ = playback_rate; |
115 } | 110 } |
116 | 111 |
117 bool IsFinishedAt(base::TimeTicks monotonic_time) const; | 112 bool IsFinishedAt(base::TimeTicks monotonic_time) const; |
118 bool is_finished() const { | 113 bool is_finished() const { |
119 return run_state_ == FINISHED || run_state_ == ABORTED || | 114 return run_state_ == Finished || |
120 run_state_ == WAITING_FOR_DELETION; | 115 run_state_ == Aborted || |
| 116 run_state_ == WaitingForDeletion; |
121 } | 117 } |
122 | 118 |
123 bool InEffect(base::TimeTicks monotonic_time) const; | 119 bool InEffect(base::TimeTicks monotonic_time) const; |
124 | 120 |
125 AnimationCurve* curve() { return curve_.get(); } | 121 AnimationCurve* curve() { return curve_.get(); } |
126 const AnimationCurve* curve() const { return curve_.get(); } | 122 const AnimationCurve* curve() const { return curve_.get(); } |
127 | 123 |
128 // If this is true, even if the animation is running, it will not be tickable | 124 // If this is true, even if the animation is running, it will not be tickable |
129 // until it is given a start time. This is true for animations running on the | 125 // until it is given a start time. This is true for animations running on the |
130 // main thread. | 126 // main thread. |
131 bool needs_synchronized_start_time() const { | 127 bool needs_synchronized_start_time() const { |
132 return needs_synchronized_start_time_; | 128 return needs_synchronized_start_time_; |
133 } | 129 } |
134 void set_needs_synchronized_start_time(bool needs_synchronized_start_time) { | 130 void set_needs_synchronized_start_time(bool needs_synchronized_start_time) { |
135 needs_synchronized_start_time_ = needs_synchronized_start_time; | 131 needs_synchronized_start_time_ = needs_synchronized_start_time; |
136 } | 132 } |
137 | 133 |
138 // This is true for animations running on the main thread when the FINISHED | 134 // This is true for animations running on the main thread when the Finished |
139 // event sent by the corresponding impl animation has been received. | 135 // event sent by the corresponding impl animation has been received. |
140 bool received_finished_event() const { | 136 bool received_finished_event() const { |
141 return received_finished_event_; | 137 return received_finished_event_; |
142 } | 138 } |
143 void set_received_finished_event(bool received_finished_event) { | 139 void set_received_finished_event(bool received_finished_event) { |
144 received_finished_event_ = received_finished_event; | 140 received_finished_event_ = received_finished_event; |
145 } | 141 } |
146 | 142 |
147 // Takes the given absolute time, and using the start time and the number | 143 // Takes the given absolute time, and using the start time and the number |
148 // of iterations, returns the relative time in the current iteration. | 144 // of iterations, returns the relative time in the current iteration. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 // uniquely identify an animation). The instance on the impl thread is the | 220 // uniquely identify an animation). The instance on the impl thread is the |
225 // instance that ultimately controls the values of the animating layer and so | 221 // instance that ultimately controls the values of the animating layer and so |
226 // we will refer to it as the 'controlling instance'. | 222 // we will refer to it as the 'controlling instance'. |
227 bool is_controlling_instance_; | 223 bool is_controlling_instance_; |
228 | 224 |
229 bool is_impl_only_; | 225 bool is_impl_only_; |
230 | 226 |
231 // When pushed from a main-thread controller to a compositor-thread | 227 // When pushed from a main-thread controller to a compositor-thread |
232 // controller, an animation will initially only affect pending observers | 228 // controller, an animation will initially only affect pending observers |
233 // (corresponding to layers in the pending tree). Animations that only | 229 // (corresponding to layers in the pending tree). Animations that only |
234 // affect pending observers are able to reach the STARTING state and tick | 230 // affect pending observers are able to reach the Starting state and tick |
235 // pending observers, but cannot proceed any further and do not tick active | 231 // pending observers, but cannot proceed any further and do not tick active |
236 // observers. After activation, such animations affect both kinds of observers | 232 // observers. After activation, such animations affect both kinds of observers |
237 // and are able to proceed past the STARTING state. When the removal of | 233 // and are able to proceed past the Starting state. When the removal of |
238 // an animation is pushed from a main-thread controller to a | 234 // an animation is pushed from a main-thread controller to a |
239 // compositor-thread controller, this initially only makes the animation | 235 // compositor-thread controller, this initially only makes the animation |
240 // stop affecting pending observers. After activation, such animations no | 236 // stop affecting pending observers. After activation, such animations no |
241 // longer affect any observers, and are deleted. | 237 // longer affect any observers, and are deleted. |
242 bool affects_active_observers_; | 238 bool affects_active_observers_; |
243 bool affects_pending_observers_; | 239 bool affects_pending_observers_; |
244 | 240 |
245 DISALLOW_COPY_AND_ASSIGN(Animation); | 241 DISALLOW_COPY_AND_ASSIGN(Animation); |
246 }; | 242 }; |
247 | 243 |
248 } // namespace cc | 244 } // namespace cc |
249 | 245 |
250 #endif // CC_ANIMATION_ANIMATION_H_ | 246 #endif // CC_ANIMATION_ANIMATION_H_ |
OLD | NEW |