Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(530)

Side by Side Diff: cc/animation.h

Issue 12517003: cc: Chromify the Animation and LayerAnimationController classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | cc/animation.cc » ('j') | cc/animation.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_H_ 5 #ifndef CC_ANIMATION_H_
6 #define CC_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 Animation, 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 Animation { 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 the
22 // will start the next time the controller animates. Animations waiting for target 22 // next tick will start the next time the controller animates. Animations
23 // availibility will run as soon as their target property is free (and all t he animations 23 // waiting for target availibility will run as soon as their target property
24 // animating with it are also able to run). Animations waiting for their sta rt time to 24 // is free (and all the animations animating with it are also able to run).
25 // come have be scheduled to run at a particular point in time. When this ti me arrives, 25 // Animations waiting for their start time to come have be scheduled to run at
26 // the controller will move the animations into the Starting state, and then into the 26 // a particular point in time. When this time arrives, the controller will
27 // Running state. Running animations may toggle between Running and Paused, and may be 27 // move the animations into the Starting state, and then into the Running
28 // stopped by moving into either the Aborted or Finished states. A Finished animation 28 // state. Running animations may toggle between Running and Paused, and may be
29 // was allowed to run to completion, but an Aborted animation was not. 29 // stopped by moving into either the Aborted or Finished states. A Finished
30 enum RunState { 30 // animation was allowed to run to completion, but an Aborted animation was
31 WaitingForNextTick = 0, 31 // not.
32 WaitingForTargetAvailability, 32 enum RunState {
33 WaitingForStartTime, 33 WaitingForNextTick = 0,
34 WaitingForDeletion, 34 WaitingForTargetAvailability,
35 Starting, 35 WaitingForStartTime,
36 Running, 36 WaitingForDeletion,
37 Paused, 37 Starting,
38 Finished, 38 Running,
39 Aborted, 39 Paused,
40 // This sentinel must be last. 40 Finished,
41 RunStateEnumSize 41 Aborted,
42 }; 42 // This sentinel must be last.
43 RunStateEnumSize
44 };
43 45
44 enum TargetProperty { 46 enum TargetProperty {
45 Transform = 0, 47 Transform = 0,
46 Opacity, 48 Opacity,
47 // This sentinel must be last. 49 // This sentinel must be last.
48 TargetPropertyEnumSize 50 TargetPropertyEnumSize
49 }; 51 };
50 52
51 static scoped_ptr<Animation> create(scoped_ptr<AnimationCurve>, int animatio nId, int groupId, TargetProperty); 53 static scoped_ptr<Animation> Create(scoped_ptr<AnimationCurve> curve,
54 int animation_id,
55 int group_id,
56 TargetProperty target_property);
52 57
53 virtual ~Animation(); 58 virtual ~Animation();
54 59
55 int id() const { return m_id; } 60 int id() const { return id_; }
56 int group() const { return m_group; } 61 int group() const { return group_; }
57 TargetProperty targetProperty() const { return m_targetProperty; } 62 TargetProperty target_property() const { return target_property_; }
58 63
59 RunState runState() const { return m_runState; } 64 RunState run_state() const { return run_state_; }
60 void setRunState(RunState, double monotonicTime); 65 void SetRunState(RunState run_state, double monotonic_time);
61 66
62 // This is the number of times that the animation will play. If this 67 // This is the number of times that the animation will play. If this
63 // value is zero the animation will not play. If it is negative, then 68 // value is zero the animation will not play. If it is negative, then
64 // the animation will loop indefinitely. 69 // the animation will loop indefinitely.
65 int iterations() const { return m_iterations; } 70 int iterations() const { return iterations_; }
66 void setIterations(int n) { m_iterations = n; } 71 void set_iterations(int n) { iterations_ = n; }
67 72
68 double startTime() const { return m_startTime; } 73 double start_time() const { return start_time_; }
69 void setStartTime(double monotonicTime) { m_startTime = monotonicTime; } 74 void set_start_time(double monotonic_time) { start_time_ = monotonic_time; }
70 bool hasSetStartTime() const { return !!m_startTime; } 75 bool has_set_start_time() const { return !!start_time_; }
71 76
72 double timeOffset() const { return m_timeOffset; } 77 double time_offset() const { return time_offset_; }
73 void setTimeOffset(double monotonicTime) { m_timeOffset = monotonicTime; } 78 void set_time_offset(double monotonic_time) { time_offset_ = monotonic_time; }
74 79
75 void suspend(double monotonicTime); 80 void Suspend(double monotonic_time);
76 void resume(double monotonicTime); 81 void Resume(double monotonic_time);
77 82
78 // If alternatesDirection is true, on odd numbered iterations we reverse the curve. 83 // If alternatesDirection is true, on odd numbered iterations we reverse the
79 bool alternatesDirection() const { return m_alternatesDirection; } 84 // curve.
80 void setAlternatesDirection(bool alternates) { m_alternatesDirection = alter nates; } 85 bool alternates_direction() const { return alternates_direction_; }
86 void set_alternates_direction(bool alternates) {
87 alternates_direction_ = alternates;
88 }
81 89
82 bool isFinishedAt(double monotonicTime) const; 90 bool IsFinishedAt(double monotonic_time) const;
83 bool isFinished() const { return m_runState == Finished 91 bool is_finished() const {
84 || m_runState == Aborted 92 return run_state_ == Finished ||
85 || m_runState == WaitingForDeletion; } 93 run_state_ == Aborted ||
94 run_state_ == WaitingForDeletion;
95 }
86 96
87 AnimationCurve* curve() { return m_curve.get(); } 97 AnimationCurve* curve() { return curve_.get(); }
88 const AnimationCurve* curve() const { return m_curve.get(); } 98 const AnimationCurve* curve() const { return curve_.get(); }
89 99
90 // If this is true, even if the animation is running, it will not be tickabl e until 100 // If this is true, even if the animation is running, it will not be tickable
91 // it is given a start time. This is true for animations running on the main thread. 101 // until it is given a start time. This is true for animations running on the
92 bool needsSynchronizedStartTime() const { return m_needsSynchronizedStartTim e; } 102 // main thread.
93 void setNeedsSynchronizedStartTime(bool needsSynchronizedStartTime) { m_need sSynchronizedStartTime = needsSynchronizedStartTime; } 103 bool needs_synchronized_start_time() const {
104 return needs_synchronized_start_time_;
105 }
106 void set_needs_synchronized_start_time(bool needs_synchronized_start_time) {
107 needs_synchronized_start_time_ = needs_synchronized_start_time;
108 }
94 109
95 // Takes the given absolute time, and using the start time and the number 110 // Takes the given absolute time, and using the start time and the number
96 // of iterations, returns the relative time in the current iteration. 111 // of iterations, returns the relative time in the current iteration.
97 double trimTimeToCurrentIteration(double monotonicTime) const; 112 double TrimTimeToCurrentIteration(double monotonic_time) const;
98 113
99 enum InstanceType { 114 enum InstanceType {
100 ControllingInstance = 0, 115 ControllingInstance = 0,
101 NonControllingInstance 116 NonControllingInstance
102 }; 117 };
103 118
104 scoped_ptr<Animation> clone(InstanceType) const; 119 scoped_ptr<Animation> Clone(InstanceType instance_type) const;
105 scoped_ptr<Animation> cloneAndInitialize(InstanceType, RunState initialRunSt ate, double startTime) const; 120 scoped_ptr<Animation> CloneAndInitialize(InstanceType instance_type,
106 bool isControllingInstance() const { return m_isControllingInstance; } 121 RunState initial_run_state,
122 double start_time) const;
123 bool is_controlling_instance() const { return is_controlling_instance_; }
107 124
108 void pushPropertiesTo(Animation*) const; 125 void PushPropertiesTo(Animation* other) const;
109 126
110 void setIsImplOnly(bool isImplOnly) { m_isImplOnly = isImplOnly; } 127 void set_is_impl_only(bool is_impl_only) { is_impl_only_ = is_impl_only; }
111 bool isImplOnly() { return m_isImplOnly; } 128 bool is_impl_only() const { return is_impl_only_; }
112 129
113 private: 130 private:
114 Animation(scoped_ptr<AnimationCurve>, int animationId, int groupId, TargetPr operty); 131 Animation(scoped_ptr<AnimationCurve> curve,
132 int animation_id,
133 int group_id,
134 TargetProperty target_property);
115 135
116 scoped_ptr<AnimationCurve> m_curve; 136 scoped_ptr<AnimationCurve> curve_;
117 137
118 // IDs are not necessarily unique. 138 // IDs are not necessarily unique.
119 int m_id; 139 int id_;
120 140
121 // Animations that must be run together are called 'grouped' and have the sa me group id 141 // Animations that must be run together are called 'grouped' and have the same
122 // Grouped animations are guaranteed to start at the same time and no other animations 142 // group id. Grouped animations are guaranteed to start at the same time and
123 // may animate any of the group's target properties until all animations in the 143 // no other animations may animate any of the group's target properties until
124 // group have finished animating. Note: an active animation's group id and t arget 144 // all animations in the group have finished animating. Note: an active
125 // property uniquely identify that animation. 145 // animation's group id and target property uniquely identify that animation.
126 int m_group; 146 int group_;
127 147
128 TargetProperty m_targetProperty; 148 TargetProperty target_property_;
129 RunState m_runState; 149 RunState run_state_;
130 int m_iterations; 150 int iterations_;
131 double m_startTime; 151 double start_time_;
132 bool m_alternatesDirection; 152 bool alternates_direction_;
133 153
134 // The time offset effectively pushes the start of the animation back in tim e. This is 154 // The time offset effectively pushes the start of the animation back in time.
135 // used for resuming paused animations -- an animation is added with a non-z ero time 155 // This is used for resuming paused animations -- an animation is added with a
136 // offset, causing the animation to skip ahead to the desired point in time. 156 // non-zero time offset, causing the animation to skip ahead to the desired
137 double m_timeOffset; 157 // point in time.
158 double time_offset_;
138 159
139 bool m_needsSynchronizedStartTime; 160 bool needs_synchronized_start_time_;
140 161
141 // When an animation is suspended, it behaves as if it is paused and it also ignores 162 // When an animation is suspended, it behaves as if it is paused and it also
142 // all run state changes until it is resumed. This is used for testing purpo ses. 163 // ignores all run state changes until it is resumed. This is used for testing
143 bool m_suspended; 164 // purposes.
165 bool suspended_;
144 166
145 // These are used in trimTimeToCurrentIteration to account for time 167 // These are used in trimTimeToCurrentIteration to account for time
146 // spent while paused. This is not included in AnimationState since it 168 // spent while paused. This is not included in AnimationState since it
147 // there is absolutely no need for clients of this controller to know 169 // there is absolutely no need for clients of this controller to know
148 // about these values. 170 // about these values.
149 double m_pauseTime; 171 double pause_time_;
150 double m_totalPausedTime; 172 double total_paused_time_;
151 173
152 // Animations lead dual lives. An active animation will be conceptually owne d by 174 // Animations lead dual lives. An active animation will be conceptually owned
153 // two controllers, one on the impl thread and one on the main. In reality, there 175 // by two controllers, one on the impl thread and one on the main. In reality,
154 // will be two separate Animation instances for the same animation. They 176 // there will be two separate Animation instances for the same animation. They
155 // will have the same group id and the same target property (these two value s 177 // will have the same group id and the same target property (these two values
156 // uniquely identify an animation). The instance on the impl thread is the i nstance 178 // uniquely identify an animation). The instance on the impl thread is the
157 // that ultimately controls the values of the animating layer and so we will refer 179 // instance that ultimately controls the values of the animating layer and so
158 // to it as the 'controlling instance'. 180 // we will refer to it as the 'controlling instance'.
159 bool m_isControllingInstance; 181 bool is_controlling_instance_;
160 182
161 bool m_isImplOnly; 183 bool is_impl_only_;
162 184
163 DISALLOW_COPY_AND_ASSIGN(Animation); 185 DISALLOW_COPY_AND_ASSIGN(Animation);
164 }; 186 };
165 187
166 } // namespace cc 188 } // namespace cc
167 189
168 #endif // CC_ANIMATION_H_ 190 #endif // CC_ANIMATION_H_
OLDNEW
« no previous file with comments | « no previous file | cc/animation.cc » ('j') | cc/animation.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698