| 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 "cc/active_animation.h" | 7 #include "cc/animation.h" |
| 8 #include "cc/animation_registrar.h" | 8 #include "cc/animation_registrar.h" |
| 9 #include "cc/keyframed_animation_curve.h" | 9 #include "cc/keyframed_animation_curve.h" |
| 10 #include "cc/layer_animation_value_observer.h" | 10 #include "cc/layer_animation_value_observer.h" |
| 11 #include "ui/gfx/transform.h" | 11 #include "ui/gfx/transform.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 gfx::Transform convertWebTransformationMatrixToTransform(const WebKit::WebTransf
ormationMatrix& matrix) | 14 gfx::Transform convertWebTransformationMatrixToTransform(const WebKit::WebTransf
ormationMatrix& matrix) |
| 15 { | 15 { |
| 16 gfx::Transform transform; | 16 gfx::Transform transform; |
| 17 transform.matrix().setDouble(0, 0, matrix.m11()); | 17 transform.matrix().setDouble(0, 0, matrix.m11()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 scoped_refptr<LayerAnimationController> LayerAnimationController::create(int id) | 53 scoped_refptr<LayerAnimationController> LayerAnimationController::create(int id) |
| 54 { | 54 { |
| 55 return make_scoped_refptr(new LayerAnimationController(id)); | 55 return make_scoped_refptr(new LayerAnimationController(id)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void LayerAnimationController::pauseAnimation(int animationId, double timeOffset
) | 58 void LayerAnimationController::pauseAnimation(int animationId, double timeOffset
) |
| 59 { | 59 { |
| 60 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 60 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
| 61 if (m_activeAnimations[i]->id() == animationId) | 61 if (m_activeAnimations[i]->id() == animationId) |
| 62 m_activeAnimations[i]->setRunState(ActiveAnimation::Paused, timeOffs
et + m_activeAnimations[i]->startTime()); | 62 m_activeAnimations[i]->setRunState(Animation::Paused, timeOffset + m
_activeAnimations[i]->startTime()); |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 void LayerAnimationController::removeAnimation(int animationId) | 66 void LayerAnimationController::removeAnimation(int animationId) |
| 67 { | 67 { |
| 68 for (size_t i = 0; i < m_activeAnimations.size();) { | 68 for (size_t i = 0; i < m_activeAnimations.size();) { |
| 69 if (m_activeAnimations[i]->id() == animationId) | 69 if (m_activeAnimations[i]->id() == animationId) |
| 70 m_activeAnimations.remove(i); | 70 m_activeAnimations.remove(i); |
| 71 else | 71 else |
| 72 i++; | 72 i++; |
| 73 } | 73 } |
| 74 updateActivation(); | 74 updateActivation(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void LayerAnimationController::removeAnimation(int animationId, ActiveAnimation:
:TargetProperty targetProperty) | 77 void LayerAnimationController::removeAnimation(int animationId, Animation::Targe
tProperty targetProperty) |
| 78 { | 78 { |
| 79 for (size_t i = 0; i < m_activeAnimations.size();) { | 79 for (size_t i = 0; i < m_activeAnimations.size();) { |
| 80 if (m_activeAnimations[i]->id() == animationId && m_activeAnimations[i]-
>targetProperty() == targetProperty) | 80 if (m_activeAnimations[i]->id() == animationId && m_activeAnimations[i]-
>targetProperty() == targetProperty) |
| 81 m_activeAnimations.remove(i); | 81 m_activeAnimations.remove(i); |
| 82 else | 82 else |
| 83 i++; | 83 i++; |
| 84 } | 84 } |
| 85 updateActivation(); | 85 updateActivation(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 // According to render layer backing, these are for testing only. | 88 // According to render layer backing, these are for testing only. |
| 89 void LayerAnimationController::suspendAnimations(double monotonicTime) | 89 void LayerAnimationController::suspendAnimations(double monotonicTime) |
| 90 { | 90 { |
| 91 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 91 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
| 92 if (!m_activeAnimations[i]->isFinished()) | 92 if (!m_activeAnimations[i]->isFinished()) |
| 93 m_activeAnimations[i]->setRunState(ActiveAnimation::Paused, monotoni
cTime); | 93 m_activeAnimations[i]->setRunState(Animation::Paused, monotonicTime)
; |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 // Looking at GraphicsLayerCA, this appears to be the analog to suspendAnimation
s, which is for testing. | 97 // Looking at GraphicsLayerCA, this appears to be the analog to suspendAnimation
s, which is for testing. |
| 98 void LayerAnimationController::resumeAnimations(double monotonicTime) | 98 void LayerAnimationController::resumeAnimations(double monotonicTime) |
| 99 { | 99 { |
| 100 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 100 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
| 101 if (m_activeAnimations[i]->runState() == ActiveAnimation::Paused) | 101 if (m_activeAnimations[i]->runState() == Animation::Paused) |
| 102 m_activeAnimations[i]->setRunState(ActiveAnimation::Running, monoton
icTime); | 102 m_activeAnimations[i]->setRunState(Animation::Running, monotonicTime
); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 // Ensures that the list of active animations on the main thread and the impl th
read | 106 // Ensures that the list of active animations on the main thread and the impl th
read |
| 107 // are kept in sync. | 107 // are kept in sync. |
| 108 void LayerAnimationController::pushAnimationUpdatesTo(LayerAnimationController*
controllerImpl) | 108 void LayerAnimationController::pushAnimationUpdatesTo(LayerAnimationController*
controllerImpl) |
| 109 { | 109 { |
| 110 if (m_forceSync) { | 110 if (m_forceSync) { |
| 111 replaceImplThreadAnimations(controllerImpl); | 111 replaceImplThreadAnimations(controllerImpl); |
| 112 m_forceSync = false; | 112 m_forceSync = false; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 131 startAnimationsWaitingForStartTime(monotonicTime, events); | 131 startAnimationsWaitingForStartTime(monotonicTime, events); |
| 132 startAnimationsWaitingForTargetAvailability(monotonicTime, events); | 132 startAnimationsWaitingForTargetAvailability(monotonicTime, events); |
| 133 resolveConflicts(monotonicTime); | 133 resolveConflicts(monotonicTime); |
| 134 tickAnimations(monotonicTime); | 134 tickAnimations(monotonicTime); |
| 135 markAnimationsForDeletion(monotonicTime, events); | 135 markAnimationsForDeletion(monotonicTime, events); |
| 136 startAnimationsWaitingForTargetAvailability(monotonicTime, events); | 136 startAnimationsWaitingForTargetAvailability(monotonicTime, events); |
| 137 | 137 |
| 138 updateActivation(); | 138 updateActivation(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void LayerAnimationController::addAnimation(scoped_ptr<ActiveAnimation> animatio
n) | 141 void LayerAnimationController::addAnimation(scoped_ptr<Animation> animation) |
| 142 { | 142 { |
| 143 m_activeAnimations.append(animation.Pass()); | 143 m_activeAnimations.append(animation.Pass()); |
| 144 updateActivation(); | 144 updateActivation(); |
| 145 } | 145 } |
| 146 | 146 |
| 147 ActiveAnimation* LayerAnimationController::getActiveAnimation(int groupId, Activ
eAnimation::TargetProperty targetProperty) const | 147 Animation* LayerAnimationController::getAnimation(int groupId, Animation::Target
Property targetProperty) const |
| 148 { | 148 { |
| 149 for (size_t i = 0; i < m_activeAnimations.size(); ++i) | 149 for (size_t i = 0; i < m_activeAnimations.size(); ++i) |
| 150 if (m_activeAnimations[i]->group() == groupId && m_activeAnimations[i]->
targetProperty() == targetProperty) | 150 if (m_activeAnimations[i]->group() == groupId && m_activeAnimations[i]->
targetProperty() == targetProperty) |
| 151 return m_activeAnimations[i]; | 151 return m_activeAnimations[i]; |
| 152 return 0; | 152 return 0; |
| 153 } | 153 } |
| 154 | 154 |
| 155 ActiveAnimation* LayerAnimationController::getActiveAnimation(ActiveAnimation::T
argetProperty targetProperty) const | 155 Animation* LayerAnimationController::getAnimation(Animation::TargetProperty targ
etProperty) const |
| 156 { | 156 { |
| 157 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 157 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
| 158 size_t index = m_activeAnimations.size() - i - 1; | 158 size_t index = m_activeAnimations.size() - i - 1; |
| 159 if (m_activeAnimations[index]->targetProperty() == targetProperty) | 159 if (m_activeAnimations[index]->targetProperty() == targetProperty) |
| 160 return m_activeAnimations[index]; | 160 return m_activeAnimations[index]; |
| 161 } | 161 } |
| 162 return 0; | 162 return 0; |
| 163 } | 163 } |
| 164 | 164 |
| 165 bool LayerAnimationController::hasActiveAnimation() const | 165 bool LayerAnimationController::hasActiveAnimation() const |
| 166 { | 166 { |
| 167 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 167 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
| 168 if (!m_activeAnimations[i]->isFinished()) | 168 if (!m_activeAnimations[i]->isFinished()) |
| 169 return true; | 169 return true; |
| 170 } | 170 } |
| 171 return false; | 171 return false; |
| 172 } | 172 } |
| 173 | 173 |
| 174 bool LayerAnimationController::isAnimatingProperty(ActiveAnimation::TargetProper
ty targetProperty) const | 174 bool LayerAnimationController::isAnimatingProperty(Animation::TargetProperty tar
getProperty) const |
| 175 { | 175 { |
| 176 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 176 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
| 177 if (m_activeAnimations[i]->runState() != ActiveAnimation::Finished && m_
activeAnimations[i]->runState() != ActiveAnimation::Aborted && m_activeAnimation
s[i]->targetProperty() == targetProperty) | 177 if (m_activeAnimations[i]->runState() != Animation::Finished && m_active
Animations[i]->runState() != Animation::Aborted && m_activeAnimations[i]->target
Property() == targetProperty) |
| 178 return true; | 178 return true; |
| 179 } | 179 } |
| 180 return false; | 180 return false; |
| 181 } | 181 } |
| 182 | 182 |
| 183 void LayerAnimationController::OnAnimationStarted(const AnimationEvent& event) | 183 void LayerAnimationController::OnAnimationStarted(const AnimationEvent& event) |
| 184 { | 184 { |
| 185 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 185 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
| 186 if (m_activeAnimations[i]->group() == event.groupId && m_activeAnimation
s[i]->targetProperty() == event.targetProperty && m_activeAnimations[i]->needsSy
nchronizedStartTime()) { | 186 if (m_activeAnimations[i]->group() == event.groupId && m_activeAnimation
s[i]->targetProperty() == event.targetProperty && m_activeAnimations[i]->needsSy
nchronizedStartTime()) { |
| 187 m_activeAnimations[i]->setNeedsSynchronizedStartTime(false); | 187 m_activeAnimations[i]->setNeedsSynchronizedStartTime(false); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 216 void LayerAnimationController::removeObserver(LayerAnimationValueObserver* obser
ver) | 216 void LayerAnimationController::removeObserver(LayerAnimationValueObserver* obser
ver) |
| 217 { | 217 { |
| 218 m_observers.RemoveObserver(observer); | 218 m_observers.RemoveObserver(observer); |
| 219 } | 219 } |
| 220 | 220 |
| 221 void LayerAnimationController::pushNewAnimationsToImplThread(LayerAnimationContr
oller* controllerImpl) const | 221 void LayerAnimationController::pushNewAnimationsToImplThread(LayerAnimationContr
oller* controllerImpl) const |
| 222 { | 222 { |
| 223 // Any new animations owned by the main thread's controller are cloned and a
dde to the impl thread's controller. | 223 // Any new animations owned by the main thread's controller are cloned and a
dde to the impl thread's controller. |
| 224 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 224 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
| 225 // If the animation is already running on the impl thread, there is no n
eed to copy it over. | 225 // If the animation is already running on the impl thread, there is no n
eed to copy it over. |
| 226 if (controllerImpl->getActiveAnimation(m_activeAnimations[i]->group(), m
_activeAnimations[i]->targetProperty())) | 226 if (controllerImpl->getAnimation(m_activeAnimations[i]->group(), m_activ
eAnimations[i]->targetProperty())) |
| 227 continue; | 227 continue; |
| 228 | 228 |
| 229 // If the animation is not running on the impl thread, it does not neces
sarily mean that it needs | 229 // If the animation is not running on the impl thread, it does not neces
sarily mean that it needs |
| 230 // to be copied over and started; it may have already finished. In this
case, the impl thread animation | 230 // to be copied over and started; it may have already finished. In this
case, the impl thread animation |
| 231 // will have already notified that it has started and the main thread an
imation will no longer need | 231 // will have already notified that it has started and the main thread an
imation will no longer need |
| 232 // a synchronized start time. | 232 // a synchronized start time. |
| 233 if (!m_activeAnimations[i]->needsSynchronizedStartTime()) | 233 if (!m_activeAnimations[i]->needsSynchronizedStartTime()) |
| 234 continue; | 234 continue; |
| 235 | 235 |
| 236 // The new animation should be set to run as soon as possible. | 236 // The new animation should be set to run as soon as possible. |
| 237 ActiveAnimation::RunState initialRunState = ActiveAnimation::WaitingForT
argetAvailability; | 237 Animation::RunState initialRunState = Animation::WaitingForTargetAvailab
ility; |
| 238 double startTime = 0; | 238 double startTime = 0; |
| 239 scoped_ptr<ActiveAnimation> toAdd(m_activeAnimations[i]->cloneAndInitial
ize(ActiveAnimation::ControllingInstance, initialRunState, startTime)); | 239 scoped_ptr<Animation> toAdd(m_activeAnimations[i]->cloneAndInitialize(An
imation::ControllingInstance, initialRunState, startTime)); |
| 240 DCHECK(!toAdd->needsSynchronizedStartTime()); | 240 DCHECK(!toAdd->needsSynchronizedStartTime()); |
| 241 controllerImpl->addAnimation(toAdd.Pass()); | 241 controllerImpl->addAnimation(toAdd.Pass()); |
| 242 } | 242 } |
| 243 } | 243 } |
| 244 | 244 |
| 245 void LayerAnimationController::removeAnimationsCompletedOnMainThread(LayerAnimat
ionController* controllerImpl) const | 245 void LayerAnimationController::removeAnimationsCompletedOnMainThread(LayerAnimat
ionController* controllerImpl) const |
| 246 { | 246 { |
| 247 // Delete all impl thread animations for which there is no corresponding mai
n thread animation. | 247 // Delete all impl thread animations for which there is no corresponding mai
n thread animation. |
| 248 // Each iteration, controller->m_activeAnimations.size() is decremented or i
is incremented | 248 // Each iteration, controller->m_activeAnimations.size() is decremented or i
is incremented |
| 249 // guaranteeing progress towards loop termination. | 249 // guaranteeing progress towards loop termination. |
| 250 for (size_t i = 0; i < controllerImpl->m_activeAnimations.size();) { | 250 for (size_t i = 0; i < controllerImpl->m_activeAnimations.size();) { |
| 251 ActiveAnimation* current = getActiveAnimation(controllerImpl->m_activeAn
imations[i]->group(), controllerImpl->m_activeAnimations[i]->targetProperty()); | 251 Animation* current = getAnimation(controllerImpl->m_activeAnimations[i]-
>group(), controllerImpl->m_activeAnimations[i]->targetProperty()); |
| 252 if (!current) | 252 if (!current) |
| 253 controllerImpl->m_activeAnimations.remove(i); | 253 controllerImpl->m_activeAnimations.remove(i); |
| 254 else | 254 else |
| 255 i++; | 255 i++; |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 | 258 |
| 259 void LayerAnimationController::pushPropertiesToImplThread(LayerAnimationControll
er* controllerImpl) const | 259 void LayerAnimationController::pushPropertiesToImplThread(LayerAnimationControll
er* controllerImpl) const |
| 260 { | 260 { |
| 261 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 261 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
| 262 ActiveAnimation* currentImpl = controllerImpl->getActiveAnimation(m_acti
veAnimations[i]->group(), m_activeAnimations[i]->targetProperty()); | 262 Animation* currentImpl = controllerImpl->getAnimation(m_activeAnimations
[i]->group(), m_activeAnimations[i]->targetProperty()); |
| 263 if (currentImpl) | 263 if (currentImpl) |
| 264 m_activeAnimations[i]->pushPropertiesTo(currentImpl); | 264 m_activeAnimations[i]->pushPropertiesTo(currentImpl); |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 | 267 |
| 268 void LayerAnimationController::startAnimationsWaitingForNextTick(double monotoni
cTime, AnimationEventsVector* events) | 268 void LayerAnimationController::startAnimationsWaitingForNextTick(double monotoni
cTime, AnimationEventsVector* events) |
| 269 { | 269 { |
| 270 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 270 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
| 271 if (m_activeAnimations[i]->runState() == ActiveAnimation::WaitingForNext
Tick) { | 271 if (m_activeAnimations[i]->runState() == Animation::WaitingForNextTick)
{ |
| 272 m_activeAnimations[i]->setRunState(ActiveAnimation::Running, monoton
icTime); | 272 m_activeAnimations[i]->setRunState(Animation::Running, monotonicTime
); |
| 273 if (!m_activeAnimations[i]->hasSetStartTime()) | 273 if (!m_activeAnimations[i]->hasSetStartTime()) |
| 274 m_activeAnimations[i]->setStartTime(monotonicTime); | 274 m_activeAnimations[i]->setStartTime(monotonicTime); |
| 275 if (events) | 275 if (events) |
| 276 events->push_back(AnimationEvent(AnimationEvent::Started, m_id,
m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty(), monoton
icTime)); | 276 events->push_back(AnimationEvent(AnimationEvent::Started, m_id,
m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty(), monoton
icTime)); |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 } | 279 } |
| 280 | 280 |
| 281 void LayerAnimationController::startAnimationsWaitingForStartTime(double monoton
icTime, AnimationEventsVector* events) | 281 void LayerAnimationController::startAnimationsWaitingForStartTime(double monoton
icTime, AnimationEventsVector* events) |
| 282 { | 282 { |
| 283 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 283 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
| 284 if (m_activeAnimations[i]->runState() == ActiveAnimation::WaitingForStar
tTime && m_activeAnimations[i]->startTime() <= monotonicTime) { | 284 if (m_activeAnimations[i]->runState() == Animation::WaitingForStartTime
&& m_activeAnimations[i]->startTime() <= monotonicTime) { |
| 285 m_activeAnimations[i]->setRunState(ActiveAnimation::Running, monoton
icTime); | 285 m_activeAnimations[i]->setRunState(Animation::Running, monotonicTime
); |
| 286 if (events) | 286 if (events) |
| 287 events->push_back(AnimationEvent(AnimationEvent::Started, m_id,
m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty(), monoton
icTime)); | 287 events->push_back(AnimationEvent(AnimationEvent::Started, m_id,
m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty(), monoton
icTime)); |
| 288 } | 288 } |
| 289 } | 289 } |
| 290 } | 290 } |
| 291 | 291 |
| 292 void LayerAnimationController::startAnimationsWaitingForTargetAvailability(doubl
e monotonicTime, AnimationEventsVector* events) | 292 void LayerAnimationController::startAnimationsWaitingForTargetAvailability(doubl
e monotonicTime, AnimationEventsVector* events) |
| 293 { | 293 { |
| 294 // First collect running properties. | 294 // First collect running properties. |
| 295 TargetProperties blockedProperties; | 295 TargetProperties blockedProperties; |
| 296 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 296 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
| 297 if (m_activeAnimations[i]->runState() == ActiveAnimation::Running || m_a
ctiveAnimations[i]->runState() == ActiveAnimation::Finished) | 297 if (m_activeAnimations[i]->runState() == Animation::Running || m_activeA
nimations[i]->runState() == Animation::Finished) |
| 298 blockedProperties.insert(m_activeAnimations[i]->targetProperty()); | 298 blockedProperties.insert(m_activeAnimations[i]->targetProperty()); |
| 299 } | 299 } |
| 300 | 300 |
| 301 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 301 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
| 302 if (m_activeAnimations[i]->runState() == ActiveAnimation::WaitingForTarg
etAvailability) { | 302 if (m_activeAnimations[i]->runState() == Animation::WaitingForTargetAvai
lability) { |
| 303 // Collect all properties for animations with the same group id (the
y should all also be in the list of animations). | 303 // Collect all properties for animations with the same group id (the
y should all also be in the list of animations). |
| 304 TargetProperties enqueuedProperties; | 304 TargetProperties enqueuedProperties; |
| 305 enqueuedProperties.insert(m_activeAnimations[i]->targetProperty()); | 305 enqueuedProperties.insert(m_activeAnimations[i]->targetProperty()); |
| 306 for (size_t j = i + 1; j < m_activeAnimations.size(); ++j) { | 306 for (size_t j = i + 1; j < m_activeAnimations.size(); ++j) { |
| 307 if (m_activeAnimations[i]->group() == m_activeAnimations[j]->gro
up()) | 307 if (m_activeAnimations[i]->group() == m_activeAnimations[j]->gro
up()) |
| 308 enqueuedProperties.insert(m_activeAnimations[j]->targetPrope
rty()); | 308 enqueuedProperties.insert(m_activeAnimations[j]->targetPrope
rty()); |
| 309 } | 309 } |
| 310 | 310 |
| 311 // Check to see if intersection of the list of properties affected b
y the group and the list of currently | 311 // Check to see if intersection of the list of properties affected b
y the group and the list of currently |
| 312 // blocked properties is null. In any case, the group's target prope
rties need to be added to the list | 312 // blocked properties is null. In any case, the group's target prope
rties need to be added to the list |
| 313 // of blocked properties. | 313 // of blocked properties. |
| 314 bool nullIntersection = true; | 314 bool nullIntersection = true; |
| 315 for (TargetProperties::iterator pIter = enqueuedProperties.begin();
pIter != enqueuedProperties.end(); ++pIter) { | 315 for (TargetProperties::iterator pIter = enqueuedProperties.begin();
pIter != enqueuedProperties.end(); ++pIter) { |
| 316 if (!blockedProperties.insert(*pIter).second) | 316 if (!blockedProperties.insert(*pIter).second) |
| 317 nullIntersection = false; | 317 nullIntersection = false; |
| 318 } | 318 } |
| 319 | 319 |
| 320 // If the intersection is null, then we are free to start the animat
ions in the group. | 320 // If the intersection is null, then we are free to start the animat
ions in the group. |
| 321 if (nullIntersection) { | 321 if (nullIntersection) { |
| 322 m_activeAnimations[i]->setRunState(ActiveAnimation::Running, mon
otonicTime); | 322 m_activeAnimations[i]->setRunState(Animation::Running, monotonic
Time); |
| 323 if (!m_activeAnimations[i]->hasSetStartTime()) | 323 if (!m_activeAnimations[i]->hasSetStartTime()) |
| 324 m_activeAnimations[i]->setStartTime(monotonicTime); | 324 m_activeAnimations[i]->setStartTime(monotonicTime); |
| 325 if (events) | 325 if (events) |
| 326 events->push_back(AnimationEvent(AnimationEvent::Started, m_
id, m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty(), mon
otonicTime)); | 326 events->push_back(AnimationEvent(AnimationEvent::Started, m_
id, m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty(), mon
otonicTime)); |
| 327 for (size_t j = i + 1; j < m_activeAnimations.size(); ++j) { | 327 for (size_t j = i + 1; j < m_activeAnimations.size(); ++j) { |
| 328 if (m_activeAnimations[i]->group() == m_activeAnimations[j]-
>group()) { | 328 if (m_activeAnimations[i]->group() == m_activeAnimations[j]-
>group()) { |
| 329 m_activeAnimations[j]->setRunState(ActiveAnimation::Runn
ing, monotonicTime); | 329 m_activeAnimations[j]->setRunState(Animation::Running, m
onotonicTime); |
| 330 if (!m_activeAnimations[j]->hasSetStartTime()) | 330 if (!m_activeAnimations[j]->hasSetStartTime()) |
| 331 m_activeAnimations[j]->setStartTime(monotonicTime); | 331 m_activeAnimations[j]->setStartTime(monotonicTime); |
| 332 } | 332 } |
| 333 } | 333 } |
| 334 } | 334 } |
| 335 } | 335 } |
| 336 } | 336 } |
| 337 } | 337 } |
| 338 | 338 |
| 339 void LayerAnimationController::resolveConflicts(double monotonicTime) | 339 void LayerAnimationController::resolveConflicts(double monotonicTime) |
| 340 { | 340 { |
| 341 // Find any animations that are animating the same property and resolve the | 341 // Find any animations that are animating the same property and resolve the |
| 342 // confict. We could eventually blend, but for now we'll just abort the | 342 // confict. We could eventually blend, but for now we'll just abort the |
| 343 // previous animation (where 'previous' means: (1) has a prior start time or | 343 // previous animation (where 'previous' means: (1) has a prior start time or |
| 344 // (2) has an equal start time, but was added to the queue earlier, i.e., | 344 // (2) has an equal start time, but was added to the queue earlier, i.e., |
| 345 // has a lower index in m_activeAnimations). | 345 // has a lower index in m_activeAnimations). |
| 346 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 346 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
| 347 if (m_activeAnimations[i]->runState() == ActiveAnimation::Running) { | 347 if (m_activeAnimations[i]->runState() == Animation::Running) { |
| 348 for (size_t j = i + 1; j < m_activeAnimations.size(); ++j) { | 348 for (size_t j = i + 1; j < m_activeAnimations.size(); ++j) { |
| 349 if (m_activeAnimations[j]->runState() == ActiveAnimation::Runnin
g && m_activeAnimations[i]->targetProperty() == m_activeAnimations[j]->targetPro
perty()) { | 349 if (m_activeAnimations[j]->runState() == Animation::Running && m
_activeAnimations[i]->targetProperty() == m_activeAnimations[j]->targetProperty(
)) { |
| 350 if (m_activeAnimations[i]->startTime() > m_activeAnimations[
j]->startTime()) | 350 if (m_activeAnimations[i]->startTime() > m_activeAnimations[
j]->startTime()) |
| 351 m_activeAnimations[j]->setRunState(ActiveAnimation::Abor
ted, monotonicTime); | 351 m_activeAnimations[j]->setRunState(Animation::Aborted, m
onotonicTime); |
| 352 else | 352 else |
| 353 m_activeAnimations[i]->setRunState(ActiveAnimation::Abor
ted, monotonicTime); | 353 m_activeAnimations[i]->setRunState(Animation::Aborted, m
onotonicTime); |
| 354 } | 354 } |
| 355 } | 355 } |
| 356 } | 356 } |
| 357 } | 357 } |
| 358 } | 358 } |
| 359 | 359 |
| 360 void LayerAnimationController::markAnimationsForDeletion(double monotonicTime, A
nimationEventsVector* events) | 360 void LayerAnimationController::markAnimationsForDeletion(double monotonicTime, A
nimationEventsVector* events) |
| 361 { | 361 { |
| 362 for (size_t i = 0; i < m_activeAnimations.size(); i++) { | 362 for (size_t i = 0; i < m_activeAnimations.size(); i++) { |
| 363 int groupId = m_activeAnimations[i]->group(); | 363 int groupId = m_activeAnimations[i]->group(); |
| 364 bool allAnimsWithSameIdAreFinished = false; | 364 bool allAnimsWithSameIdAreFinished = false; |
| 365 // If an animation is finished, and not already marked for deletion, | 365 // If an animation is finished, and not already marked for deletion, |
| 366 // Find out if all other animations in the same group are also finished. | 366 // Find out if all other animations in the same group are also finished. |
| 367 if (m_activeAnimations[i]->isFinished()) { | 367 if (m_activeAnimations[i]->isFinished()) { |
| 368 allAnimsWithSameIdAreFinished = true; | 368 allAnimsWithSameIdAreFinished = true; |
| 369 for (size_t j = 0; j < m_activeAnimations.size(); ++j) { | 369 for (size_t j = 0; j < m_activeAnimations.size(); ++j) { |
| 370 if (groupId == m_activeAnimations[j]->group() && !m_activeAnimat
ions[j]->isFinished()) { | 370 if (groupId == m_activeAnimations[j]->group() && !m_activeAnimat
ions[j]->isFinished()) { |
| 371 allAnimsWithSameIdAreFinished = false; | 371 allAnimsWithSameIdAreFinished = false; |
| 372 break; | 372 break; |
| 373 } | 373 } |
| 374 } | 374 } |
| 375 } | 375 } |
| 376 if (allAnimsWithSameIdAreFinished) { | 376 if (allAnimsWithSameIdAreFinished) { |
| 377 // We now need to remove all animations with the same group id as gr
oupId | 377 // We now need to remove all animations with the same group id as gr
oupId |
| 378 // (and send along animation finished notifications, if necessary). | 378 // (and send along animation finished notifications, if necessary). |
| 379 for (size_t j = i; j < m_activeAnimations.size(); j++) { | 379 for (size_t j = i; j < m_activeAnimations.size(); j++) { |
| 380 if (groupId == m_activeAnimations[j]->group()) { | 380 if (groupId == m_activeAnimations[j]->group()) { |
| 381 if (events) | 381 if (events) |
| 382 events->push_back(AnimationEvent(AnimationEvent::Finishe
d, m_id, m_activeAnimations[j]->group(), m_activeAnimations[j]->targetProperty()
, monotonicTime)); | 382 events->push_back(AnimationEvent(AnimationEvent::Finishe
d, m_id, m_activeAnimations[j]->group(), m_activeAnimations[j]->targetProperty()
, monotonicTime)); |
| 383 m_activeAnimations[j]->setRunState(ActiveAnimation::WaitingF
orDeletion, monotonicTime); | 383 m_activeAnimations[j]->setRunState(Animation::WaitingForDele
tion, monotonicTime); |
| 384 } | 384 } |
| 385 } | 385 } |
| 386 } | 386 } |
| 387 } | 387 } |
| 388 } | 388 } |
| 389 | 389 |
| 390 void LayerAnimationController::purgeAnimationsMarkedForDeletion() | 390 void LayerAnimationController::purgeAnimationsMarkedForDeletion() |
| 391 { | 391 { |
| 392 for (size_t i = 0; i < m_activeAnimations.size();) { | 392 for (size_t i = 0; i < m_activeAnimations.size();) { |
| 393 if (m_activeAnimations[i]->runState() == ActiveAnimation::WaitingForDele
tion) | 393 if (m_activeAnimations[i]->runState() == Animation::WaitingForDeletion) |
| 394 m_activeAnimations.remove(i); | 394 m_activeAnimations.remove(i); |
| 395 else | 395 else |
| 396 i++; | 396 i++; |
| 397 } | 397 } |
| 398 } | 398 } |
| 399 | 399 |
| 400 void LayerAnimationController::replaceImplThreadAnimations(LayerAnimationControl
ler* controllerImpl) const | 400 void LayerAnimationController::replaceImplThreadAnimations(LayerAnimationControl
ler* controllerImpl) const |
| 401 { | 401 { |
| 402 controllerImpl->m_activeAnimations.clear(); | 402 controllerImpl->m_activeAnimations.clear(); |
| 403 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 403 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
| 404 scoped_ptr<ActiveAnimation> toAdd; | 404 scoped_ptr<Animation> toAdd; |
| 405 if (m_activeAnimations[i]->needsSynchronizedStartTime()) { | 405 if (m_activeAnimations[i]->needsSynchronizedStartTime()) { |
| 406 // We haven't received an animation started notification yet, so it | 406 // We haven't received an animation started notification yet, so it |
| 407 // is important that we add it in a 'waiting' and not 'running' stat
e. | 407 // is important that we add it in a 'waiting' and not 'running' stat
e. |
| 408 ActiveAnimation::RunState initialRunState = ActiveAnimation::Waiting
ForTargetAvailability; | 408 Animation::RunState initialRunState = Animation::WaitingForTargetAva
ilability; |
| 409 double startTime = 0; | 409 double startTime = 0; |
| 410 toAdd = m_activeAnimations[i]->cloneAndInitialize(ActiveAnimation::C
ontrollingInstance, initialRunState, startTime).Pass(); | 410 toAdd = m_activeAnimations[i]->cloneAndInitialize(Animation::Control
lingInstance, initialRunState, startTime).Pass(); |
| 411 } else | 411 } else |
| 412 toAdd = m_activeAnimations[i]->clone(ActiveAnimation::ControllingIns
tance).Pass(); | 412 toAdd = m_activeAnimations[i]->clone(Animation::ControllingInstance)
.Pass(); |
| 413 | 413 |
| 414 controllerImpl->addAnimation(toAdd.Pass()); | 414 controllerImpl->addAnimation(toAdd.Pass()); |
| 415 } | 415 } |
| 416 } | 416 } |
| 417 | 417 |
| 418 void LayerAnimationController::tickAnimations(double monotonicTime) | 418 void LayerAnimationController::tickAnimations(double monotonicTime) |
| 419 { | 419 { |
| 420 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 420 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
| 421 if (m_activeAnimations[i]->runState() == ActiveAnimation::Running || m_a
ctiveAnimations[i]->runState() == ActiveAnimation::Paused) { | 421 if (m_activeAnimations[i]->runState() == Animation::Running || m_activeA
nimations[i]->runState() == Animation::Paused) { |
| 422 double trimmed = m_activeAnimations[i]->trimTimeToCurrentIteration(m
onotonicTime); | 422 double trimmed = m_activeAnimations[i]->trimTimeToCurrentIteration(m
onotonicTime); |
| 423 | 423 |
| 424 // Animation assumes its initial value until it gets the synchronize
d start time | 424 // Animation assumes its initial value until it gets the synchronize
d start time |
| 425 // from the impl thread and can start ticking. | 425 // from the impl thread and can start ticking. |
| 426 if (m_activeAnimations[i]->needsSynchronizedStartTime()) | 426 if (m_activeAnimations[i]->needsSynchronizedStartTime()) |
| 427 trimmed = 0; | 427 trimmed = 0; |
| 428 | 428 |
| 429 switch (m_activeAnimations[i]->targetProperty()) { | 429 switch (m_activeAnimations[i]->targetProperty()) { |
| 430 | 430 |
| 431 case ActiveAnimation::Transform: { | 431 case Animation::Transform: { |
| 432 const TransformAnimationCurve* transformAnimationCurve = m_activ
eAnimations[i]->curve()->toTransformAnimationCurve(); | 432 const TransformAnimationCurve* transformAnimationCurve = m_activ
eAnimations[i]->curve()->toTransformAnimationCurve(); |
| 433 const gfx::Transform transform = convertWebTransformationMatrixT
oTransform(transformAnimationCurve->getValue(trimmed)); | 433 const gfx::Transform transform = convertWebTransformationMatrixT
oTransform(transformAnimationCurve->getValue(trimmed)); |
| 434 if (m_activeAnimations[i]->isFinishedAt(monotonicTime)) | 434 if (m_activeAnimations[i]->isFinishedAt(monotonicTime)) |
| 435 m_activeAnimations[i]->setRunState(ActiveAnimation::Finished
, monotonicTime); | 435 m_activeAnimations[i]->setRunState(Animation::Finished, mono
tonicTime); |
| 436 | 436 |
| 437 notifyObserversTransformAnimated(transform); | 437 notifyObserversTransformAnimated(transform); |
| 438 break; | 438 break; |
| 439 } | 439 } |
| 440 | 440 |
| 441 case ActiveAnimation::Opacity: { | 441 case Animation::Opacity: { |
| 442 const FloatAnimationCurve* floatAnimationCurve = m_activeAnimati
ons[i]->curve()->toFloatAnimationCurve(); | 442 const FloatAnimationCurve* floatAnimationCurve = m_activeAnimati
ons[i]->curve()->toFloatAnimationCurve(); |
| 443 const float opacity = floatAnimationCurve->getValue(trimmed); | 443 const float opacity = floatAnimationCurve->getValue(trimmed); |
| 444 if (m_activeAnimations[i]->isFinishedAt(monotonicTime)) | 444 if (m_activeAnimations[i]->isFinishedAt(monotonicTime)) |
| 445 m_activeAnimations[i]->setRunState(ActiveAnimation::Finished
, monotonicTime); | 445 m_activeAnimations[i]->setRunState(Animation::Finished, mono
tonicTime); |
| 446 | 446 |
| 447 notifyObserversOpacityAnimated(opacity); | 447 notifyObserversOpacityAnimated(opacity); |
| 448 break; | 448 break; |
| 449 } | 449 } |
| 450 | 450 |
| 451 // Do nothing for sentinel value. | 451 // Do nothing for sentinel value. |
| 452 case ActiveAnimation::TargetPropertyEnumSize: | 452 case Animation::TargetPropertyEnumSize: |
| 453 NOTREACHED(); | 453 NOTREACHED(); |
| 454 } | 454 } |
| 455 } | 455 } |
| 456 } | 456 } |
| 457 } | 457 } |
| 458 | 458 |
| 459 void LayerAnimationController::updateActivation(bool force) | 459 void LayerAnimationController::updateActivation(bool force) |
| 460 { | 460 { |
| 461 if (m_registrar) { | 461 if (m_registrar) { |
| 462 if (!m_activeAnimations.isEmpty() && (!m_isActive || force)) | 462 if (!m_activeAnimations.isEmpty() && (!m_isActive || force)) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 475 } | 475 } |
| 476 | 476 |
| 477 void LayerAnimationController::notifyObserversTransformAnimated(const gfx::Trans
form& transform) | 477 void LayerAnimationController::notifyObserversTransformAnimated(const gfx::Trans
form& transform) |
| 478 { | 478 { |
| 479 FOR_EACH_OBSERVER(LayerAnimationValueObserver, | 479 FOR_EACH_OBSERVER(LayerAnimationValueObserver, |
| 480 m_observers, | 480 m_observers, |
| 481 OnTransformAnimated(transform)); | 481 OnTransformAnimated(transform)); |
| 482 } | 482 } |
| 483 | 483 |
| 484 } // namespace cc | 484 } // namespace cc |
| OLD | NEW |