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 #include "cc/layer_animation_controller.h" | 5 #include "cc/layer_animation_controller.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 |
7 #include "cc/active_animation.h" | 9 #include "cc/active_animation.h" |
8 #include "cc/keyframed_animation_curve.h" | 10 #include "cc/keyframed_animation_curve.h" |
9 #include <public/WebTransformationMatrix.h> | 11 #include <public/WebTransformationMatrix.h> |
10 | 12 |
11 using WebKit::WebTransformationMatrix; | 13 using WebKit::WebTransformationMatrix; |
12 | 14 |
13 namespace cc { | 15 namespace cc { |
14 | 16 |
15 LayerAnimationController::LayerAnimationController(LayerAnimationControllerClien
t* client) | 17 LayerAnimationController::LayerAnimationController(LayerAnimationControllerClien
t* client) |
16 : m_forceSync(false) | 18 : m_forceSync(false) |
(...skipping 11 matching lines...) Expand all Loading... |
28 } | 30 } |
29 | 31 |
30 void LayerAnimationController::pauseAnimation(int animationId, double timeOffset
) | 32 void LayerAnimationController::pauseAnimation(int animationId, double timeOffset
) |
31 { | 33 { |
32 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 34 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
33 if (m_activeAnimations[i]->id() == animationId) | 35 if (m_activeAnimations[i]->id() == animationId) |
34 m_activeAnimations[i]->setRunState(ActiveAnimation::Paused, timeOffs
et + m_activeAnimations[i]->startTime()); | 36 m_activeAnimations[i]->setRunState(ActiveAnimation::Paused, timeOffs
et + m_activeAnimations[i]->startTime()); |
35 } | 37 } |
36 } | 38 } |
37 | 39 |
| 40 struct HasAnimationId { |
| 41 HasAnimationId(int id) : m_id(id) { } |
| 42 bool operator()(ActiveAnimation* animation) const { return animation->id() =
= m_id; } |
| 43 private: |
| 44 int m_id; |
| 45 }; |
| 46 |
38 void LayerAnimationController::removeAnimation(int animationId) | 47 void LayerAnimationController::removeAnimation(int animationId) |
39 { | 48 { |
40 for (size_t i = 0; i < m_activeAnimations.size();) { | 49 ScopedPtrVector<ActiveAnimation>& animations = m_activeAnimations; |
41 if (m_activeAnimations[i]->id() == animationId) | 50 animations.erase(std::remove_if(animations.begin(), animations.end(), HasAni
mationId(animationId)), animations.end()); |
42 m_activeAnimations.remove(i); | |
43 else | |
44 i++; | |
45 } | |
46 } | 51 } |
47 | 52 |
| 53 struct HasAnimationIdAndProperty { |
| 54 HasAnimationIdAndProperty(int id, ActiveAnimation::TargetProperty targetProp
erty) : m_id(id), m_targetProperty(targetProperty) { } |
| 55 bool operator()(ActiveAnimation* animation) const { return animation->id() =
= m_id && animation->targetProperty() == m_targetProperty; } |
| 56 private: |
| 57 int m_id; |
| 58 ActiveAnimation::TargetProperty m_targetProperty; |
| 59 }; |
| 60 |
48 void LayerAnimationController::removeAnimation(int animationId, ActiveAnimation:
:TargetProperty targetProperty) | 61 void LayerAnimationController::removeAnimation(int animationId, ActiveAnimation:
:TargetProperty targetProperty) |
49 { | 62 { |
50 for (size_t i = 0; i < m_activeAnimations.size();) { | 63 ScopedPtrVector<ActiveAnimation>& animations = m_activeAnimations; |
51 if (m_activeAnimations[i]->id() == animationId && m_activeAnimations[i]-
>targetProperty() == targetProperty) | 64 animations.erase(std::remove_if(animations.begin(), animations.end(), HasAni
mationIdAndProperty(animationId, targetProperty)), animations.end()); |
52 m_activeAnimations.remove(i); | |
53 else | |
54 i++; | |
55 } | |
56 } | 65 } |
57 | 66 |
58 // According to render layer backing, these are for testing only. | 67 // According to render layer backing, these are for testing only. |
59 void LayerAnimationController::suspendAnimations(double monotonicTime) | 68 void LayerAnimationController::suspendAnimations(double monotonicTime) |
60 { | 69 { |
61 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 70 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
62 if (!m_activeAnimations[i]->isFinished()) | 71 if (!m_activeAnimations[i]->isFinished()) |
63 m_activeAnimations[i]->setRunState(ActiveAnimation::Paused, monotoni
cTime); | 72 m_activeAnimations[i]->setRunState(ActiveAnimation::Paused, monotoni
cTime); |
64 } | 73 } |
65 } | 74 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 startAnimationsWaitingForStartTime(monotonicTime, events); | 108 startAnimationsWaitingForStartTime(monotonicTime, events); |
100 startAnimationsWaitingForTargetAvailability(monotonicTime, events); | 109 startAnimationsWaitingForTargetAvailability(monotonicTime, events); |
101 resolveConflicts(monotonicTime); | 110 resolveConflicts(monotonicTime); |
102 tickAnimations(monotonicTime); | 111 tickAnimations(monotonicTime); |
103 markAnimationsForDeletion(monotonicTime, events); | 112 markAnimationsForDeletion(monotonicTime, events); |
104 startAnimationsWaitingForTargetAvailability(monotonicTime, events); | 113 startAnimationsWaitingForTargetAvailability(monotonicTime, events); |
105 } | 114 } |
106 | 115 |
107 void LayerAnimationController::addAnimation(scoped_ptr<ActiveAnimation> animatio
n) | 116 void LayerAnimationController::addAnimation(scoped_ptr<ActiveAnimation> animatio
n) |
108 { | 117 { |
109 m_activeAnimations.append(animation.Pass()); | 118 m_activeAnimations.push_back(animation.Pass()); |
110 } | 119 } |
111 | 120 |
112 ActiveAnimation* LayerAnimationController::getActiveAnimation(int groupId, Activ
eAnimation::TargetProperty targetProperty) const | 121 ActiveAnimation* LayerAnimationController::getActiveAnimation(int groupId, Activ
eAnimation::TargetProperty targetProperty) const |
113 { | 122 { |
114 for (size_t i = 0; i < m_activeAnimations.size(); ++i) | 123 for (size_t i = 0; i < m_activeAnimations.size(); ++i) |
115 if (m_activeAnimations[i]->group() == groupId && m_activeAnimations[i]->
targetProperty() == targetProperty) | 124 if (m_activeAnimations[i]->group() == groupId && m_activeAnimations[i]->
targetProperty() == targetProperty) |
116 return m_activeAnimations[i]; | 125 return m_activeAnimations[i]; |
117 return 0; | 126 return 0; |
118 } | 127 } |
119 | 128 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 187 |
179 // The new animation should be set to run as soon as possible. | 188 // The new animation should be set to run as soon as possible. |
180 ActiveAnimation::RunState initialRunState = ActiveAnimation::WaitingForT
argetAvailability; | 189 ActiveAnimation::RunState initialRunState = ActiveAnimation::WaitingForT
argetAvailability; |
181 double startTime = 0; | 190 double startTime = 0; |
182 scoped_ptr<ActiveAnimation> toAdd(m_activeAnimations[i]->cloneAndInitial
ize(ActiveAnimation::ControllingInstance, initialRunState, startTime)); | 191 scoped_ptr<ActiveAnimation> toAdd(m_activeAnimations[i]->cloneAndInitial
ize(ActiveAnimation::ControllingInstance, initialRunState, startTime)); |
183 DCHECK(!toAdd->needsSynchronizedStartTime()); | 192 DCHECK(!toAdd->needsSynchronizedStartTime()); |
184 controllerImpl->addAnimation(toAdd.Pass()); | 193 controllerImpl->addAnimation(toAdd.Pass()); |
185 } | 194 } |
186 } | 195 } |
187 | 196 |
| 197 struct IsCompleted { |
| 198 IsCompleted(const LayerAnimationController& mainThreadController) : m_mainTh
readController(mainThreadController) { } |
| 199 bool operator()(ActiveAnimation* animation) const { return !m_mainThreadCont
roller.getActiveAnimation(animation->group(), animation->targetProperty()); } |
| 200 private: |
| 201 const LayerAnimationController& m_mainThreadController; |
| 202 }; |
| 203 |
188 void LayerAnimationController::removeAnimationsCompletedOnMainThread(LayerAnimat
ionController* controllerImpl) const | 204 void LayerAnimationController::removeAnimationsCompletedOnMainThread(LayerAnimat
ionController* controllerImpl) const |
189 { | 205 { |
190 // Delete all impl thread animations for which there is no corresponding mai
n thread animation. | 206 // Delete all impl thread animations for which there is no corresponding mai
n thread animation. |
191 // Each iteration, controller->m_activeAnimations.size() is decremented or i
is incremented | 207 // Each iteration, controller->m_activeAnimations.size() is decremented or i
is incremented |
192 // guaranteeing progress towards loop termination. | 208 // guaranteeing progress towards loop termination. |
193 for (size_t i = 0; i < controllerImpl->m_activeAnimations.size();) { | 209 ScopedPtrVector<ActiveAnimation>& animations = controllerImpl->m_activeAnima
tions; |
194 ActiveAnimation* current = getActiveAnimation(controllerImpl->m_activeAn
imations[i]->group(), controllerImpl->m_activeAnimations[i]->targetProperty()); | 210 animations.erase(std::remove_if(animations.begin(), animations.end(), IsComp
leted(*this)), animations.end()); |
195 if (!current) | |
196 controllerImpl->m_activeAnimations.remove(i); | |
197 else | |
198 i++; | |
199 } | |
200 } | 211 } |
201 | 212 |
202 void LayerAnimationController::pushPropertiesToImplThread(LayerAnimationControll
er* controllerImpl) const | 213 void LayerAnimationController::pushPropertiesToImplThread(LayerAnimationControll
er* controllerImpl) const |
203 { | 214 { |
204 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 215 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
205 ActiveAnimation* currentImpl = controllerImpl->getActiveAnimation(m_acti
veAnimations[i]->group(), m_activeAnimations[i]->targetProperty()); | 216 ActiveAnimation* currentImpl = controllerImpl->getActiveAnimation(m_acti
veAnimations[i]->group(), m_activeAnimations[i]->targetProperty()); |
206 if (currentImpl) | 217 if (currentImpl) |
207 m_activeAnimations[i]->pushPropertiesTo(currentImpl); | 218 m_activeAnimations[i]->pushPropertiesTo(currentImpl); |
208 } | 219 } |
209 } | 220 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 if (groupId == m_activeAnimations[j]->group()) { | 334 if (groupId == m_activeAnimations[j]->group()) { |
324 if (events) | 335 if (events) |
325 events->push_back(AnimationEvent(AnimationEvent::Finishe
d, m_client->id(), m_activeAnimations[j]->group(), m_activeAnimations[j]->target
Property(), monotonicTime)); | 336 events->push_back(AnimationEvent(AnimationEvent::Finishe
d, m_client->id(), m_activeAnimations[j]->group(), m_activeAnimations[j]->target
Property(), monotonicTime)); |
326 m_activeAnimations[j]->setRunState(ActiveAnimation::WaitingF
orDeletion, monotonicTime); | 337 m_activeAnimations[j]->setRunState(ActiveAnimation::WaitingF
orDeletion, monotonicTime); |
327 } | 338 } |
328 } | 339 } |
329 } | 340 } |
330 } | 341 } |
331 } | 342 } |
332 | 343 |
| 344 static bool isWaitingForDeletion(ActiveAnimation* animation) { return animation-
>runState() == ActiveAnimation::WaitingForDeletion; } |
| 345 |
333 void LayerAnimationController::purgeAnimationsMarkedForDeletion() | 346 void LayerAnimationController::purgeAnimationsMarkedForDeletion() |
334 { | 347 { |
335 for (size_t i = 0; i < m_activeAnimations.size();) { | 348 ScopedPtrVector<ActiveAnimation>& animations = m_activeAnimations; |
336 if (m_activeAnimations[i]->runState() == ActiveAnimation::WaitingForDele
tion) | 349 animations.erase(std::remove_if(animations.begin(), animations.end(), isWait
ingForDeletion), animations.end()); |
337 m_activeAnimations.remove(i); | |
338 else | |
339 i++; | |
340 } | |
341 } | 350 } |
342 | 351 |
343 void LayerAnimationController::replaceImplThreadAnimations(LayerAnimationControl
ler* controllerImpl) const | 352 void LayerAnimationController::replaceImplThreadAnimations(LayerAnimationControl
ler* controllerImpl) const |
344 { | 353 { |
345 controllerImpl->m_activeAnimations.clear(); | 354 controllerImpl->m_activeAnimations.clear(); |
346 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 355 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
347 scoped_ptr<ActiveAnimation> toAdd; | 356 scoped_ptr<ActiveAnimation> toAdd; |
348 if (m_activeAnimations[i]->needsSynchronizedStartTime()) { | 357 if (m_activeAnimations[i]->needsSynchronizedStartTime()) { |
349 // We haven't received an animation started notification yet, so it | 358 // We haven't received an animation started notification yet, so it |
350 // is important that we add it in a 'waiting' and not 'running' stat
e. | 359 // is important that we add it in a 'waiting' and not 'running' stat
e. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 | 402 |
394 // Do nothing for sentinel value. | 403 // Do nothing for sentinel value. |
395 case ActiveAnimation::TargetPropertyEnumSize: | 404 case ActiveAnimation::TargetPropertyEnumSize: |
396 NOTREACHED(); | 405 NOTREACHED(); |
397 } | 406 } |
398 } | 407 } |
399 } | 408 } |
400 } | 409 } |
401 | 410 |
402 } // namespace cc | 411 } // namespace cc |
OLD | NEW |