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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "CCLayerAnimationController.h" | 7 #include "CCLayerAnimationController.h" |
8 | 8 |
9 #include "CCActiveAnimation.h" | 9 #include "CCActiveAnimation.h" |
10 #include "CCKeyframedAnimationCurve.h" | 10 #include "CCKeyframedAnimationCurve.h" |
11 #include <public/WebTransformationMatrix.h> | 11 #include <public/WebTransformationMatrix.h> |
12 #include <wtf/CurrentTime.h> | 12 #include <wtf/CurrentTime.h> |
13 #include <wtf/HashMap.h> | 13 #include <wtf/HashMap.h> |
14 | 14 |
15 using WebKit::WebTransformationMatrix; | 15 using WebKit::WebTransformationMatrix; |
16 | 16 |
17 namespace cc { | 17 namespace cc { |
18 | 18 |
19 CCLayerAnimationController::CCLayerAnimationController(CCLayerAnimationControlle
rClient* client) | 19 CCLayerAnimationController::CCLayerAnimationController(CCLayerAnimationControlle
rClient* client) |
20 : m_forceSync(false) | 20 : m_forceSync(false) |
21 , m_client(client) | 21 , m_client(client) |
22 { | 22 { |
23 } | 23 } |
24 | 24 |
25 CCLayerAnimationController::~CCLayerAnimationController() | 25 CCLayerAnimationController::~CCLayerAnimationController() |
26 { | 26 { |
27 } | 27 } |
28 | 28 |
29 PassOwnPtr<CCLayerAnimationController> CCLayerAnimationController::create(CCLaye
rAnimationControllerClient* client) | 29 scoped_ptr<CCLayerAnimationController> CCLayerAnimationController::create(CCLaye
rAnimationControllerClient* client) |
30 { | 30 { |
31 return adoptPtr(new CCLayerAnimationController(client)); | 31 return make_scoped_ptr(new CCLayerAnimationController(client)); |
32 } | 32 } |
33 | 33 |
34 void CCLayerAnimationController::pauseAnimation(int animationId, double timeOffs
et) | 34 void CCLayerAnimationController::pauseAnimation(int animationId, double timeOffs
et) |
35 { | 35 { |
36 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 36 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
37 if (m_activeAnimations[i]->id() == animationId) | 37 if (m_activeAnimations[i]->id() == animationId) |
38 m_activeAnimations[i]->setRunState(CCActiveAnimation::Paused, timeOf
fset + m_activeAnimations[i]->startTime()); | 38 m_activeAnimations[i]->setRunState(CCActiveAnimation::Paused, timeOf
fset + m_activeAnimations[i]->startTime()); |
39 } | 39 } |
40 } | 40 } |
41 | 41 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 { | 101 { |
102 startAnimationsWaitingForNextTick(monotonicTime, events); | 102 startAnimationsWaitingForNextTick(monotonicTime, events); |
103 startAnimationsWaitingForStartTime(monotonicTime, events); | 103 startAnimationsWaitingForStartTime(monotonicTime, events); |
104 startAnimationsWaitingForTargetAvailability(monotonicTime, events); | 104 startAnimationsWaitingForTargetAvailability(monotonicTime, events); |
105 resolveConflicts(monotonicTime); | 105 resolveConflicts(monotonicTime); |
106 tickAnimations(monotonicTime); | 106 tickAnimations(monotonicTime); |
107 markAnimationsForDeletion(monotonicTime, events); | 107 markAnimationsForDeletion(monotonicTime, events); |
108 startAnimationsWaitingForTargetAvailability(monotonicTime, events); | 108 startAnimationsWaitingForTargetAvailability(monotonicTime, events); |
109 } | 109 } |
110 | 110 |
111 void CCLayerAnimationController::addAnimation(PassOwnPtr<CCActiveAnimation> anim
ation) | 111 void CCLayerAnimationController::addAnimation(scoped_ptr<CCActiveAnimation> anim
ation) |
112 { | 112 { |
113 m_activeAnimations.append(animation); | 113 m_activeAnimations.append(animation.Pass()); |
114 } | 114 } |
115 | 115 |
116 CCActiveAnimation* CCLayerAnimationController::getActiveAnimation(int groupId, C
CActiveAnimation::TargetProperty targetProperty) const | 116 CCActiveAnimation* CCLayerAnimationController::getActiveAnimation(int groupId, C
CActiveAnimation::TargetProperty targetProperty) const |
117 { | 117 { |
118 for (size_t i = 0; i < m_activeAnimations.size(); ++i) | 118 for (size_t i = 0; i < m_activeAnimations.size(); ++i) |
119 if (m_activeAnimations[i]->group() == groupId && m_activeAnimations[i]->
targetProperty() == targetProperty) | 119 if (m_activeAnimations[i]->group() == groupId && m_activeAnimations[i]->
targetProperty() == targetProperty) |
120 return m_activeAnimations[i]; | 120 return m_activeAnimations[i]; |
121 return 0; | 121 return 0; |
122 } | 122 } |
123 | 123 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 // If the animation is not running on the impl thread, it does not neces
sarily mean that it needs | 176 // If the animation is not running on the impl thread, it does not neces
sarily mean that it needs |
177 // to be copied over and started; it may have already finished. In this
case, the impl thread animation | 177 // to be copied over and started; it may have already finished. In this
case, the impl thread animation |
178 // will have already notified that it has started and the main thread an
imation will no longer need | 178 // will have already notified that it has started and the main thread an
imation will no longer need |
179 // a synchronized start time. | 179 // a synchronized start time. |
180 if (!m_activeAnimations[i]->needsSynchronizedStartTime()) | 180 if (!m_activeAnimations[i]->needsSynchronizedStartTime()) |
181 continue; | 181 continue; |
182 | 182 |
183 // The new animation should be set to run as soon as possible. | 183 // The new animation should be set to run as soon as possible. |
184 CCActiveAnimation::RunState initialRunState = CCActiveAnimation::Waiting
ForTargetAvailability; | 184 CCActiveAnimation::RunState initialRunState = CCActiveAnimation::Waiting
ForTargetAvailability; |
185 double startTime = 0; | 185 double startTime = 0; |
186 OwnPtr<CCActiveAnimation> toAdd(m_activeAnimations[i]->cloneAndInitializ
e(CCActiveAnimation::ControllingInstance, initialRunState, startTime)); | 186 scoped_ptr<CCActiveAnimation> toAdd(m_activeAnimations[i]->cloneAndIniti
alize(CCActiveAnimation::ControllingInstance, initialRunState, startTime)); |
187 ASSERT(!toAdd->needsSynchronizedStartTime()); | 187 ASSERT(!toAdd->needsSynchronizedStartTime()); |
188 controllerImpl->addAnimation(toAdd.release()); | 188 controllerImpl->addAnimation(toAdd.Pass()); |
189 } | 189 } |
190 } | 190 } |
191 | 191 |
192 void CCLayerAnimationController::removeAnimationsCompletedOnMainThread(CCLayerAn
imationController* controllerImpl) const | 192 void CCLayerAnimationController::removeAnimationsCompletedOnMainThread(CCLayerAn
imationController* controllerImpl) const |
193 { | 193 { |
194 // Delete all impl thread animations for which there is no corresponding mai
n thread animation. | 194 // Delete all impl thread animations for which there is no corresponding mai
n thread animation. |
195 // Each iteration, controller->m_activeAnimations.size() is decremented or i
is incremented | 195 // Each iteration, controller->m_activeAnimations.size() is decremented or i
is incremented |
196 // guaranteeing progress towards loop termination. | 196 // guaranteeing progress towards loop termination. |
197 for (size_t i = 0; i < controllerImpl->m_activeAnimations.size();) { | 197 for (size_t i = 0; i < controllerImpl->m_activeAnimations.size();) { |
198 CCActiveAnimation* current = getActiveAnimation(controllerImpl->m_active
Animations[i]->group(), controllerImpl->m_activeAnimations[i]->targetProperty())
; | 198 CCActiveAnimation* current = getActiveAnimation(controllerImpl->m_active
Animations[i]->group(), controllerImpl->m_activeAnimations[i]->targetProperty())
; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 m_activeAnimations.remove(i); | 341 m_activeAnimations.remove(i); |
342 else | 342 else |
343 i++; | 343 i++; |
344 } | 344 } |
345 } | 345 } |
346 | 346 |
347 void CCLayerAnimationController::replaceImplThreadAnimations(CCLayerAnimationCon
troller* controllerImpl) const | 347 void CCLayerAnimationController::replaceImplThreadAnimations(CCLayerAnimationCon
troller* controllerImpl) const |
348 { | 348 { |
349 controllerImpl->m_activeAnimations.clear(); | 349 controllerImpl->m_activeAnimations.clear(); |
350 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 350 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
351 OwnPtr<CCActiveAnimation> toAdd; | 351 scoped_ptr<CCActiveAnimation> toAdd; |
352 if (m_activeAnimations[i]->needsSynchronizedStartTime()) { | 352 if (m_activeAnimations[i]->needsSynchronizedStartTime()) { |
353 // We haven't received an animation started notification yet, so it | 353 // We haven't received an animation started notification yet, so it |
354 // is important that we add it in a 'waiting' and not 'running' stat
e. | 354 // is important that we add it in a 'waiting' and not 'running' stat
e. |
355 CCActiveAnimation::RunState initialRunState = CCActiveAnimation::Wai
tingForTargetAvailability; | 355 CCActiveAnimation::RunState initialRunState = CCActiveAnimation::Wai
tingForTargetAvailability; |
356 double startTime = 0; | 356 double startTime = 0; |
357 toAdd = m_activeAnimations[i]->cloneAndInitialize(CCActiveAnimation:
:ControllingInstance, initialRunState, startTime); | 357 toAdd = m_activeAnimations[i]->cloneAndInitialize(CCActiveAnimation:
:ControllingInstance, initialRunState, startTime).Pass(); |
358 } else | 358 } else |
359 toAdd = m_activeAnimations[i]->clone(CCActiveAnimation::ControllingI
nstance); | 359 toAdd = m_activeAnimations[i]->clone(CCActiveAnimation::ControllingI
nstance).Pass(); |
360 | 360 |
361 controllerImpl->addAnimation(toAdd.release()); | 361 controllerImpl->addAnimation(toAdd.Pass()); |
362 } | 362 } |
363 } | 363 } |
364 | 364 |
365 void CCLayerAnimationController::tickAnimations(double monotonicTime) | 365 void CCLayerAnimationController::tickAnimations(double monotonicTime) |
366 { | 366 { |
367 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 367 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
368 if (m_activeAnimations[i]->runState() == CCActiveAnimation::Running || m
_activeAnimations[i]->runState() == CCActiveAnimation::Paused) { | 368 if (m_activeAnimations[i]->runState() == CCActiveAnimation::Running || m
_activeAnimations[i]->runState() == CCActiveAnimation::Paused) { |
369 double trimmed = m_activeAnimations[i]->trimTimeToCurrentIteration(m
onotonicTime); | 369 double trimmed = m_activeAnimations[i]->trimTimeToCurrentIteration(m
onotonicTime); |
370 | 370 |
371 // Animation assumes its initial value until it gets the synchronize
d start time | 371 // Animation assumes its initial value until it gets the synchronize
d start time |
(...skipping 26 matching lines...) Expand all Loading... |
398 // Do nothing for sentinel value. | 398 // Do nothing for sentinel value. |
399 case CCActiveAnimation::TargetPropertyEnumSize: | 399 case CCActiveAnimation::TargetPropertyEnumSize: |
400 ASSERT_NOT_REACHED(); | 400 ASSERT_NOT_REACHED(); |
401 | 401 |
402 } | 402 } |
403 } | 403 } |
404 } | 404 } |
405 } | 405 } |
406 | 406 |
407 } // namespace cc | 407 } // namespace cc |
OLD | NEW |