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

Side by Side Diff: cc/active_animation.cc

Issue 11189043: cc: Rename cc classes and members to match filenames (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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
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 #include "config.h" 5 #include "config.h"
6 6
7 #include "CCActiveAnimation.h" 7 #include "CCActiveAnimation.h"
8 8
9 #include "CCAnimationCurve.h" 9 #include "CCAnimationCurve.h"
10 #include "TraceEvent.h" 10 #include "TraceEvent.h"
(...skipping 10 matching lines...) Expand all
21 "WaitingForNextTick", 21 "WaitingForNextTick",
22 "WaitingForTargetAvailability", 22 "WaitingForTargetAvailability",
23 "WaitingForStartTime", 23 "WaitingForStartTime",
24 "WaitingForDeletion", 24 "WaitingForDeletion",
25 "Running", 25 "Running",
26 "Paused", 26 "Paused",
27 "Finished", 27 "Finished",
28 "Aborted" 28 "Aborted"
29 }; 29 };
30 30
31 COMPILE_ASSERT(static_cast<int>(cc::CCActiveAnimation::RunStateEnumSize) == arra ysize(s_runStateNames), RunState_names_match_enum); 31 COMPILE_ASSERT(static_cast<int>(cc::ActiveAnimation::RunStateEnumSize) == arrays ize(s_runStateNames), RunState_names_match_enum);
32 32
33 // This should match the TargetProperty enum. 33 // This should match the TargetProperty enum.
34 static const char* const s_targetPropertyNames[] = { 34 static const char* const s_targetPropertyNames[] = {
35 "Transform", 35 "Transform",
36 "Opacity" 36 "Opacity"
37 }; 37 };
38 38
39 COMPILE_ASSERT(static_cast<int>(cc::CCActiveAnimation::TargetPropertyEnumSize) = = arraysize(s_targetPropertyNames), TargetProperty_names_match_enum); 39 COMPILE_ASSERT(static_cast<int>(cc::ActiveAnimation::TargetPropertyEnumSize) == arraysize(s_targetPropertyNames), TargetProperty_names_match_enum);
40 40
41 } // namespace 41 } // namespace
42 42
43 namespace cc { 43 namespace cc {
44 44
45 scoped_ptr<CCActiveAnimation> CCActiveAnimation::create(scoped_ptr<CCAnimationCu rve> curve, int animationId, int groupId, TargetProperty targetProperty) 45 scoped_ptr<ActiveAnimation> ActiveAnimation::create(scoped_ptr<AnimationCurve> c urve, int animationId, int groupId, TargetProperty targetProperty)
46 { 46 {
47 return make_scoped_ptr(new CCActiveAnimation(curve.Pass(), animationId, grou pId, targetProperty)); 47 return make_scoped_ptr(new ActiveAnimation(curve.Pass(), animationId, groupI d, targetProperty));
48 } 48 }
49 49
50 CCActiveAnimation::CCActiveAnimation(scoped_ptr<CCAnimationCurve> curve, int ani mationId, int groupId, TargetProperty targetProperty) 50 ActiveAnimation::ActiveAnimation(scoped_ptr<AnimationCurve> curve, int animation Id, int groupId, TargetProperty targetProperty)
51 : m_curve(curve.Pass()) 51 : m_curve(curve.Pass())
52 , m_id(animationId) 52 , m_id(animationId)
53 , m_group(groupId) 53 , m_group(groupId)
54 , m_targetProperty(targetProperty) 54 , m_targetProperty(targetProperty)
55 , m_runState(WaitingForTargetAvailability) 55 , m_runState(WaitingForTargetAvailability)
56 , m_iterations(1) 56 , m_iterations(1)
57 , m_startTime(0) 57 , m_startTime(0)
58 , m_alternatesDirection(false) 58 , m_alternatesDirection(false)
59 , m_timeOffset(0) 59 , m_timeOffset(0)
60 , m_needsSynchronizedStartTime(false) 60 , m_needsSynchronizedStartTime(false)
61 , m_suspended(false) 61 , m_suspended(false)
62 , m_pauseTime(0) 62 , m_pauseTime(0)
63 , m_totalPausedTime(0) 63 , m_totalPausedTime(0)
64 , m_isControllingInstance(false) 64 , m_isControllingInstance(false)
65 { 65 {
66 } 66 }
67 67
68 CCActiveAnimation::~CCActiveAnimation() 68 ActiveAnimation::~ActiveAnimation()
69 { 69 {
70 if (m_runState == Running || m_runState == Paused) 70 if (m_runState == Running || m_runState == Paused)
71 setRunState(Aborted, 0); 71 setRunState(Aborted, 0);
72 } 72 }
73 73
74 void CCActiveAnimation::setRunState(RunState runState, double monotonicTime) 74 void ActiveAnimation::setRunState(RunState runState, double monotonicTime)
75 { 75 {
76 if (m_suspended) 76 if (m_suspended)
77 return; 77 return;
78 78
79 char nameBuffer[256]; 79 char nameBuffer[256];
80 base::snprintf(nameBuffer, sizeof(nameBuffer), "%s-%d%s", s_targetPropertyNa mes[m_targetProperty], m_group, m_isControllingInstance ? "(impl)" : ""); 80 base::snprintf(nameBuffer, sizeof(nameBuffer), "%s-%d%s", s_targetPropertyNa mes[m_targetProperty], m_group, m_isControllingInstance ? "(impl)" : "");
81 81
82 bool isWaitingToStart = m_runState == WaitingForNextTick 82 bool isWaitingToStart = m_runState == WaitingForNextTick
83 || m_runState == WaitingForTargetAvailability 83 || m_runState == WaitingForTargetAvailability
84 || m_runState == WaitingForStartTime; 84 || m_runState == WaitingForStartTime;
85 85
86 if (isWaitingToStart && runState == Running) 86 if (isWaitingToStart && runState == Running)
87 TRACE_EVENT_ASYNC_BEGIN1("cc", "CCActiveAnimation", this, "Name", TRACE_ STR_COPY(nameBuffer)); 87 TRACE_EVENT_ASYNC_BEGIN1("cc", "ActiveAnimation", this, "Name", TRACE_ST R_COPY(nameBuffer));
88 88
89 bool wasFinished = isFinished(); 89 bool wasFinished = isFinished();
90 90
91 const char* oldRunStateName = s_runStateNames[m_runState]; 91 const char* oldRunStateName = s_runStateNames[m_runState];
92 92
93 if (runState == Running && m_runState == Paused) 93 if (runState == Running && m_runState == Paused)
94 m_totalPausedTime += monotonicTime - m_pauseTime; 94 m_totalPausedTime += monotonicTime - m_pauseTime;
95 else if (runState == Paused) 95 else if (runState == Paused)
96 m_pauseTime = monotonicTime; 96 m_pauseTime = monotonicTime;
97 m_runState = runState; 97 m_runState = runState;
98 98
99 const char* newRunStateName = s_runStateNames[runState]; 99 const char* newRunStateName = s_runStateNames[runState];
100 100
101 if (!wasFinished && isFinished()) 101 if (!wasFinished && isFinished())
102 TRACE_EVENT_ASYNC_END0("cc", "CCActiveAnimation", this); 102 TRACE_EVENT_ASYNC_END0("cc", "ActiveAnimation", this);
103 103
104 char stateBuffer[256]; 104 char stateBuffer[256];
105 base::snprintf(stateBuffer, sizeof(stateBuffer), "%s->%s", oldRunStateName, newRunStateName); 105 base::snprintf(stateBuffer, sizeof(stateBuffer), "%s->%s", oldRunStateName, newRunStateName);
106 106
107 TRACE_EVENT_INSTANT2("cc", "CCLayerAnimationController::setRunState", "Name" , TRACE_STR_COPY(nameBuffer), "State", TRACE_STR_COPY(stateBuffer)); 107 TRACE_EVENT_INSTANT2("cc", "LayerAnimationController::setRunState", "Name", TRACE_STR_COPY(nameBuffer), "State", TRACE_STR_COPY(stateBuffer));
108 } 108 }
109 109
110 void CCActiveAnimation::suspend(double monotonicTime) 110 void ActiveAnimation::suspend(double monotonicTime)
111 { 111 {
112 setRunState(Paused, monotonicTime); 112 setRunState(Paused, monotonicTime);
113 m_suspended = true; 113 m_suspended = true;
114 } 114 }
115 115
116 void CCActiveAnimation::resume(double monotonicTime) 116 void ActiveAnimation::resume(double monotonicTime)
117 { 117 {
118 m_suspended = false; 118 m_suspended = false;
119 setRunState(Running, monotonicTime); 119 setRunState(Running, monotonicTime);
120 } 120 }
121 121
122 bool CCActiveAnimation::isFinishedAt(double monotonicTime) const 122 bool ActiveAnimation::isFinishedAt(double monotonicTime) const
123 { 123 {
124 if (isFinished()) 124 if (isFinished())
125 return true; 125 return true;
126 126
127 if (m_needsSynchronizedStartTime) 127 if (m_needsSynchronizedStartTime)
128 return false; 128 return false;
129 129
130 return m_runState == Running 130 return m_runState == Running
131 && m_iterations >= 0 131 && m_iterations >= 0
132 && m_iterations * m_curve->duration() <= monotonicTime - startTime() - m _totalPausedTime; 132 && m_iterations * m_curve->duration() <= monotonicTime - startTime() - m _totalPausedTime;
133 } 133 }
134 134
135 double CCActiveAnimation::trimTimeToCurrentIteration(double monotonicTime) const 135 double ActiveAnimation::trimTimeToCurrentIteration(double monotonicTime) const
136 { 136 {
137 double trimmed = monotonicTime + m_timeOffset; 137 double trimmed = monotonicTime + m_timeOffset;
138 138
139 // If we're paused, time is 'stuck' at the pause time. 139 // If we're paused, time is 'stuck' at the pause time.
140 if (m_runState == Paused) 140 if (m_runState == Paused)
141 trimmed = m_pauseTime; 141 trimmed = m_pauseTime;
142 142
143 // Returned time should always be relative to the start time and should subt ract 143 // Returned time should always be relative to the start time and should subt ract
144 // all time spent paused. 144 // all time spent paused.
145 trimmed -= m_startTime + m_totalPausedTime; 145 trimmed -= m_startTime + m_totalPausedTime;
(...skipping 27 matching lines...) Expand all
173 // Calculate x where trimmed = x + n * m_curve->duration() for some positive integer n. 173 // Calculate x where trimmed = x + n * m_curve->duration() for some positive integer n.
174 trimmed = fmod(trimmed, m_curve->duration()); 174 trimmed = fmod(trimmed, m_curve->duration());
175 175
176 // If we're alternating and on an odd iteration, reverse the direction. 176 // If we're alternating and on an odd iteration, reverse the direction.
177 if (m_alternatesDirection && iteration % 2 == 1) 177 if (m_alternatesDirection && iteration % 2 == 1)
178 return m_curve->duration() - trimmed; 178 return m_curve->duration() - trimmed;
179 179
180 return trimmed; 180 return trimmed;
181 } 181 }
182 182
183 scoped_ptr<CCActiveAnimation> CCActiveAnimation::clone(InstanceType instanceType ) const 183 scoped_ptr<ActiveAnimation> ActiveAnimation::clone(InstanceType instanceType) co nst
184 { 184 {
185 return cloneAndInitialize(instanceType, m_runState, m_startTime); 185 return cloneAndInitialize(instanceType, m_runState, m_startTime);
186 } 186 }
187 187
188 scoped_ptr<CCActiveAnimation> CCActiveAnimation::cloneAndInitialize(InstanceType instanceType, RunState initialRunState, double startTime) const 188 scoped_ptr<ActiveAnimation> ActiveAnimation::cloneAndInitialize(InstanceType ins tanceType, RunState initialRunState, double startTime) const
189 { 189 {
190 scoped_ptr<CCActiveAnimation> toReturn(new CCActiveAnimation(m_curve->clone( ), m_id, m_group, m_targetProperty)); 190 scoped_ptr<ActiveAnimation> toReturn(new ActiveAnimation(m_curve->clone(), m _id, m_group, m_targetProperty));
191 toReturn->m_runState = initialRunState; 191 toReturn->m_runState = initialRunState;
192 toReturn->m_iterations = m_iterations; 192 toReturn->m_iterations = m_iterations;
193 toReturn->m_startTime = startTime; 193 toReturn->m_startTime = startTime;
194 toReturn->m_pauseTime = m_pauseTime; 194 toReturn->m_pauseTime = m_pauseTime;
195 toReturn->m_totalPausedTime = m_totalPausedTime; 195 toReturn->m_totalPausedTime = m_totalPausedTime;
196 toReturn->m_timeOffset = m_timeOffset; 196 toReturn->m_timeOffset = m_timeOffset;
197 toReturn->m_alternatesDirection = m_alternatesDirection; 197 toReturn->m_alternatesDirection = m_alternatesDirection;
198 toReturn->m_isControllingInstance = instanceType == ControllingInstance; 198 toReturn->m_isControllingInstance = instanceType == ControllingInstance;
199 return toReturn.Pass(); 199 return toReturn.Pass();
200 } 200 }
201 201
202 void CCActiveAnimation::pushPropertiesTo(CCActiveAnimation* other) const 202 void ActiveAnimation::pushPropertiesTo(ActiveAnimation* other) const
203 { 203 {
204 // Currently, we only push changes due to pausing and resuming animations on the main thread. 204 // Currently, we only push changes due to pausing and resuming animations on the main thread.
205 if (m_runState == CCActiveAnimation::Paused || other->m_runState == CCActive Animation::Paused) { 205 if (m_runState == ActiveAnimation::Paused || other->m_runState == ActiveAnim ation::Paused) {
206 other->m_runState = m_runState; 206 other->m_runState = m_runState;
207 other->m_pauseTime = m_pauseTime; 207 other->m_pauseTime = m_pauseTime;
208 other->m_totalPausedTime = m_totalPausedTime; 208 other->m_totalPausedTime = m_totalPausedTime;
209 } 209 }
210 } 210 }
211 211
212 } // namespace cc 212 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698