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_ACTIVE_ANIMATION_H_ | 5 #ifndef CC_ANIMATION_H_ |
6 #define CC_ACTIVE_ANIMATION_H_ | 6 #define CC_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 "cc/cc_export.h" | 10 #include "cc/cc_export.h" |
11 | 11 |
12 namespace cc { | 12 namespace cc { |
13 | 13 |
14 class AnimationCurve; | 14 class AnimationCurve; |
15 | 15 |
16 // An ActiveAnimation, contains all the state required to play an AnimationCurve
. | 16 // An Animation, contains all the state required to play an AnimationCurve. |
17 // Specifically, the affected property, the run state (paused, finished, etc.), | 17 // Specifically, the affected property, the run state (paused, finished, etc.), |
18 // loop count, last pause time, and the total time spent paused. | 18 // loop count, last pause time, and the total time spent paused. |
19 class CC_EXPORT ActiveAnimation { | 19 class CC_EXPORT Animation { |
20 public: | 20 public: |
21 // Animations begin in one of the 'waiting' states. Animations waiting for t
he next tick | 21 // Animations begin in one of the 'waiting' states. Animations waiting for t
he next tick |
22 // will start the next time the controller animates. Animations waiting for
target | 22 // will start the next time the controller animates. Animations waiting for
target |
23 // availibility will run as soon as their target property is free (and all t
he animations | 23 // availibility will run as soon as their target property is free (and all t
he animations |
24 // animating with it are also able to run). Animations waiting for their sta
rt time to | 24 // animating with it are also able to run). Animations waiting for their sta
rt time to |
25 // come have be scheduled to run at a particular point in time. When this ti
me arrives, | 25 // come have be scheduled to run at a particular point in time. When this ti
me arrives, |
26 // the controller will move the animations into the Running state. Running a
nimations | 26 // the controller will move the animations into the Running state. Running a
nimations |
27 // may toggle between Running and Paused, and may be stopped by moving into
either the | 27 // may toggle between Running and Paused, and may be stopped by moving into
either the |
28 // Aborted or Finished states. A Finished animation was allowed to run to co
mpletion, but | 28 // Aborted or Finished states. A Finished animation was allowed to run to co
mpletion, but |
29 // an Aborted animation was not. | 29 // an Aborted animation was not. |
(...skipping 10 matching lines...) Expand all Loading... |
40 RunStateEnumSize | 40 RunStateEnumSize |
41 }; | 41 }; |
42 | 42 |
43 enum TargetProperty { | 43 enum TargetProperty { |
44 Transform = 0, | 44 Transform = 0, |
45 Opacity, | 45 Opacity, |
46 // This sentinel must be last. | 46 // This sentinel must be last. |
47 TargetPropertyEnumSize | 47 TargetPropertyEnumSize |
48 }; | 48 }; |
49 | 49 |
50 static scoped_ptr<ActiveAnimation> create(scoped_ptr<AnimationCurve>, int an
imationId, int groupId, TargetProperty); | 50 static scoped_ptr<Animation> create(scoped_ptr<AnimationCurve>, int animatio
nId, int groupId, TargetProperty); |
51 | 51 |
52 virtual ~ActiveAnimation(); | 52 virtual ~Animation(); |
53 | 53 |
54 int id() const { return m_id; } | 54 int id() const { return m_id; } |
55 int group() const { return m_group; } | 55 int group() const { return m_group; } |
56 TargetProperty targetProperty() const { return m_targetProperty; } | 56 TargetProperty targetProperty() const { return m_targetProperty; } |
57 | 57 |
58 RunState runState() const { return m_runState; } | 58 RunState runState() const { return m_runState; } |
59 void setRunState(RunState, double monotonicTime); | 59 void setRunState(RunState, double monotonicTime); |
60 | 60 |
61 // This is the number of times that the animation will play. If this | 61 // This is the number of times that the animation will play. If this |
62 // value is zero the animation will not play. If it is negative, then | 62 // value is zero the animation will not play. If it is negative, then |
(...skipping 30 matching lines...) Expand all Loading... |
93 | 93 |
94 // Takes the given absolute time, and using the start time and the number | 94 // Takes the given absolute time, and using the start time and the number |
95 // of iterations, returns the relative time in the current iteration. | 95 // of iterations, returns the relative time in the current iteration. |
96 double trimTimeToCurrentIteration(double monotonicTime) const; | 96 double trimTimeToCurrentIteration(double monotonicTime) const; |
97 | 97 |
98 enum InstanceType { | 98 enum InstanceType { |
99 ControllingInstance = 0, | 99 ControllingInstance = 0, |
100 NonControllingInstance | 100 NonControllingInstance |
101 }; | 101 }; |
102 | 102 |
103 scoped_ptr<ActiveAnimation> clone(InstanceType) const; | 103 scoped_ptr<Animation> clone(InstanceType) const; |
104 scoped_ptr<ActiveAnimation> cloneAndInitialize(InstanceType, RunState initia
lRunState, double startTime) const; | 104 scoped_ptr<Animation> cloneAndInitialize(InstanceType, RunState initialRunSt
ate, double startTime) const; |
105 bool isControllingInstance() const { return m_isControllingInstance; } | 105 bool isControllingInstance() const { return m_isControllingInstance; } |
106 | 106 |
107 void pushPropertiesTo(ActiveAnimation*) const; | 107 void pushPropertiesTo(Animation*) const; |
108 | 108 |
109 private: | 109 private: |
110 ActiveAnimation(scoped_ptr<AnimationCurve>, int animationId, int groupId, Ta
rgetProperty); | 110 Animation(scoped_ptr<AnimationCurve>, int animationId, int groupId, TargetPr
operty); |
111 | 111 |
112 scoped_ptr<AnimationCurve> m_curve; | 112 scoped_ptr<AnimationCurve> m_curve; |
113 | 113 |
114 // IDs are not necessarily unique. | 114 // IDs are not necessarily unique. |
115 int m_id; | 115 int m_id; |
116 | 116 |
117 // Animations that must be run together are called 'grouped' and have the sa
me group id | 117 // Animations that must be run together are called 'grouped' and have the sa
me group id |
118 // Grouped animations are guaranteed to start at the same time and no other
animations | 118 // Grouped animations are guaranteed to start at the same time and no other
animations |
119 // may animate any of the group's target properties until all animations in
the | 119 // may animate any of the group's target properties until all animations in
the |
120 // group have finished animating. Note: an active animation's group id and t
arget | 120 // group have finished animating. Note: an active animation's group id and t
arget |
(...skipping 19 matching lines...) Expand all Loading... |
140 | 140 |
141 // These are used in trimTimeToCurrentIteration to account for time | 141 // These are used in trimTimeToCurrentIteration to account for time |
142 // spent while paused. This is not included in AnimationState since it | 142 // spent while paused. This is not included in AnimationState since it |
143 // there is absolutely no need for clients of this controller to know | 143 // there is absolutely no need for clients of this controller to know |
144 // about these values. | 144 // about these values. |
145 double m_pauseTime; | 145 double m_pauseTime; |
146 double m_totalPausedTime; | 146 double m_totalPausedTime; |
147 | 147 |
148 // Animations lead dual lives. An active animation will be conceptually owne
d by | 148 // Animations lead dual lives. An active animation will be conceptually owne
d by |
149 // two controllers, one on the impl thread and one on the main. In reality,
there | 149 // two controllers, one on the impl thread and one on the main. In reality,
there |
150 // will be two separate ActiveAnimation instances for the same animation. Th
ey | 150 // will be two separate Animation instances for the same animation. They |
151 // will have the same group id and the same target property (these two value
s | 151 // will have the same group id and the same target property (these two value
s |
152 // uniquely identify an animation). The instance on the impl thread is the i
nstance | 152 // uniquely identify an animation). The instance on the impl thread is the i
nstance |
153 // that ultimately controls the values of the animating layer and so we will
refer | 153 // that ultimately controls the values of the animating layer and so we will
refer |
154 // to it as the 'controlling instance'. | 154 // to it as the 'controlling instance'. |
155 bool m_isControllingInstance; | 155 bool m_isControllingInstance; |
156 | 156 |
157 DISALLOW_COPY_AND_ASSIGN(ActiveAnimation); | 157 DISALLOW_COPY_AND_ASSIGN(Animation); |
158 }; | 158 }; |
159 | 159 |
160 } // namespace cc | 160 } // namespace cc |
161 | 161 |
162 #endif // CC_ACTIVE_ANIMATION_H_ | 162 #endif // CC_ANIMATION_H_ |
OLD | NEW |