blob: c72df0454a79eb3736fc46bd54bd0deffbed9f4a [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// Copyright 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]d50c6862012-10-23 02:08:315#include "cc/layer_animation_controller.h"
[email protected]94f206c12012-08-25 00:09:146
[email protected]aa0a9d32012-10-24 01:58:107#include "cc/active_animation.h"
[email protected]de4afb5e2012-12-20 00:11:348#include "cc/animation_registrar.h"
[email protected]d50c6862012-10-23 02:08:319#include "cc/keyframed_animation_curve.h"
[email protected]de4afb5e2012-12-20 00:11:3410#include "cc/layer_animation_value_observer.h"
[email protected]c8686a02012-11-27 08:29:0011#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1412
[email protected]9c88e562012-09-14 22:21:3013namespace cc {
[email protected]94f206c12012-08-25 00:09:1414
[email protected]de4afb5e2012-12-20 00:11:3415LayerAnimationController::LayerAnimationController(int id)
[email protected]94f206c12012-08-25 00:09:1416 : m_forceSync(false)
[email protected]de4afb5e2012-12-20 00:11:3417 , m_id(id)
18 , m_registrar(0)
19 , m_isActive(false)
[email protected]94f206c12012-08-25 00:09:1420{
21}
22
[email protected]96baf3e2012-10-22 23:09:5523LayerAnimationController::~LayerAnimationController()
[email protected]94f206c12012-08-25 00:09:1424{
[email protected]de4afb5e2012-12-20 00:11:3425 if (m_registrar)
26 m_registrar->UnregisterAnimationController(this);
[email protected]94f206c12012-08-25 00:09:1427}
28
[email protected]de4afb5e2012-12-20 00:11:3429scoped_refptr<LayerAnimationController> LayerAnimationController::create(int id)
[email protected]94f206c12012-08-25 00:09:1430{
[email protected]de4afb5e2012-12-20 00:11:3431 return make_scoped_refptr(new LayerAnimationController(id));
[email protected]94f206c12012-08-25 00:09:1432}
33
[email protected]96baf3e2012-10-22 23:09:5534void LayerAnimationController::pauseAnimation(int animationId, double timeOffset)
[email protected]94f206c12012-08-25 00:09:1435{
36 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
37 if (m_activeAnimations[i]->id() == animationId)
[email protected]96baf3e2012-10-22 23:09:5538 m_activeAnimations[i]->setRunState(ActiveAnimation::Paused, timeOffset + m_activeAnimations[i]->startTime());
[email protected]94f206c12012-08-25 00:09:1439 }
40}
41
[email protected]96baf3e2012-10-22 23:09:5542void LayerAnimationController::removeAnimation(int animationId)
[email protected]94f206c12012-08-25 00:09:1443{
44 for (size_t i = 0; i < m_activeAnimations.size();) {
45 if (m_activeAnimations[i]->id() == animationId)
46 m_activeAnimations.remove(i);
47 else
48 i++;
49 }
[email protected]de4afb5e2012-12-20 00:11:3450 updateActivation();
[email protected]94f206c12012-08-25 00:09:1451}
52
[email protected]96baf3e2012-10-22 23:09:5553void LayerAnimationController::removeAnimation(int animationId, ActiveAnimation::TargetProperty targetProperty)
[email protected]94f206c12012-08-25 00:09:1454{
55 for (size_t i = 0; i < m_activeAnimations.size();) {
56 if (m_activeAnimations[i]->id() == animationId && m_activeAnimations[i]->targetProperty() == targetProperty)
57 m_activeAnimations.remove(i);
58 else
59 i++;
60 }
[email protected]de4afb5e2012-12-20 00:11:3461 updateActivation();
[email protected]94f206c12012-08-25 00:09:1462}
63
64// According to render layer backing, these are for testing only.
[email protected]96baf3e2012-10-22 23:09:5565void LayerAnimationController::suspendAnimations(double monotonicTime)
[email protected]94f206c12012-08-25 00:09:1466{
67 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
68 if (!m_activeAnimations[i]->isFinished())
[email protected]96baf3e2012-10-22 23:09:5569 m_activeAnimations[i]->setRunState(ActiveAnimation::Paused, monotonicTime);
[email protected]94f206c12012-08-25 00:09:1470 }
71}
72
73// Looking at GraphicsLayerCA, this appears to be the analog to suspendAnimations, which is for testing.
[email protected]96baf3e2012-10-22 23:09:5574void LayerAnimationController::resumeAnimations(double monotonicTime)
[email protected]94f206c12012-08-25 00:09:1475{
76 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
[email protected]96baf3e2012-10-22 23:09:5577 if (m_activeAnimations[i]->runState() == ActiveAnimation::Paused)
78 m_activeAnimations[i]->setRunState(ActiveAnimation::Running, monotonicTime);
[email protected]94f206c12012-08-25 00:09:1479 }
80}
81
82// Ensures that the list of active animations on the main thread and the impl thread
83// are kept in sync.
[email protected]96baf3e2012-10-22 23:09:5584void LayerAnimationController::pushAnimationUpdatesTo(LayerAnimationController* controllerImpl)
[email protected]94f206c12012-08-25 00:09:1485{
86 if (m_forceSync) {
87 replaceImplThreadAnimations(controllerImpl);
88 m_forceSync = false;
89 } else {
90 purgeAnimationsMarkedForDeletion();
91 pushNewAnimationsToImplThread(controllerImpl);
92
93 // Remove finished impl side animations only after pushing,
94 // and only after the animations are deleted on the main thread
95 // this insures we will never push an animation twice.
96 removeAnimationsCompletedOnMainThread(controllerImpl);
97
98 pushPropertiesToImplThread(controllerImpl);
99 }
[email protected]de4afb5e2012-12-20 00:11:34100 controllerImpl->updateActivation();
101 updateActivation();
[email protected]94f206c12012-08-25 00:09:14102}
103
[email protected]96baf3e2012-10-22 23:09:55104void LayerAnimationController::animate(double monotonicTime, AnimationEventsVector* events)
[email protected]94f206c12012-08-25 00:09:14105{
106 startAnimationsWaitingForNextTick(monotonicTime, events);
107 startAnimationsWaitingForStartTime(monotonicTime, events);
108 startAnimationsWaitingForTargetAvailability(monotonicTime, events);
109 resolveConflicts(monotonicTime);
110 tickAnimations(monotonicTime);
111 markAnimationsForDeletion(monotonicTime, events);
112 startAnimationsWaitingForTargetAvailability(monotonicTime, events);
[email protected]de4afb5e2012-12-20 00:11:34113
114 updateActivation();
[email protected]94f206c12012-08-25 00:09:14115}
116
[email protected]96baf3e2012-10-22 23:09:55117void LayerAnimationController::addAnimation(scoped_ptr<ActiveAnimation> animation)
[email protected]94f206c12012-08-25 00:09:14118{
[email protected]9aca3592012-10-12 15:57:09119 m_activeAnimations.append(animation.Pass());
[email protected]de4afb5e2012-12-20 00:11:34120 updateActivation();
[email protected]94f206c12012-08-25 00:09:14121}
122
[email protected]96baf3e2012-10-22 23:09:55123ActiveAnimation* LayerAnimationController::getActiveAnimation(int groupId, ActiveAnimation::TargetProperty targetProperty) const
[email protected]94f206c12012-08-25 00:09:14124{
125 for (size_t i = 0; i < m_activeAnimations.size(); ++i)
126 if (m_activeAnimations[i]->group() == groupId && m_activeAnimations[i]->targetProperty() == targetProperty)
[email protected]0920e24f2012-09-20 03:34:03127 return m_activeAnimations[i];
[email protected]94f206c12012-08-25 00:09:14128 return 0;
129}
130
[email protected]96baf3e2012-10-22 23:09:55131ActiveAnimation* LayerAnimationController::getActiveAnimation(ActiveAnimation::TargetProperty targetProperty) const
[email protected]94f206c12012-08-25 00:09:14132{
133 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
134 size_t index = m_activeAnimations.size() - i - 1;
135 if (m_activeAnimations[index]->targetProperty() == targetProperty)
[email protected]0920e24f2012-09-20 03:34:03136 return m_activeAnimations[index];
[email protected]94f206c12012-08-25 00:09:14137 }
138 return 0;
139}
140
[email protected]96baf3e2012-10-22 23:09:55141bool LayerAnimationController::hasActiveAnimation() const
[email protected]94f206c12012-08-25 00:09:14142{
143 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
144 if (!m_activeAnimations[i]->isFinished())
145 return true;
146 }
147 return false;
148}
149
[email protected]96baf3e2012-10-22 23:09:55150bool LayerAnimationController::isAnimatingProperty(ActiveAnimation::TargetProperty targetProperty) const
[email protected]94f206c12012-08-25 00:09:14151{
152 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
[email protected]96baf3e2012-10-22 23:09:55153 if (m_activeAnimations[i]->runState() != ActiveAnimation::Finished && m_activeAnimations[i]->runState() != ActiveAnimation::Aborted && m_activeAnimations[i]->targetProperty() == targetProperty)
[email protected]94f206c12012-08-25 00:09:14154 return true;
155 }
156 return false;
157}
158
[email protected]e10cd022012-12-18 00:32:26159void LayerAnimationController::OnAnimationStarted(const AnimationEvent& event)
[email protected]94f206c12012-08-25 00:09:14160{
161 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
162 if (m_activeAnimations[i]->group() == event.groupId && m_activeAnimations[i]->targetProperty() == event.targetProperty && m_activeAnimations[i]->needsSynchronizedStartTime()) {
163 m_activeAnimations[i]->setNeedsSynchronizedStartTime(false);
164 m_activeAnimations[i]->setStartTime(event.monotonicTime);
165 return;
166 }
167 }
168}
169
[email protected]de4afb5e2012-12-20 00:11:34170void LayerAnimationController::setAnimationRegistrar(AnimationRegistrar* registrar)
[email protected]94f206c12012-08-25 00:09:14171{
[email protected]de4afb5e2012-12-20 00:11:34172 if (m_registrar == registrar)
173 return;
174
175 if (m_registrar)
176 m_registrar->UnregisterAnimationController(this);
177
178 m_registrar = registrar;
179 if (m_registrar)
180 m_registrar->RegisterAnimationController(this);
181
182 bool force = true;
183 updateActivation(force);
184}
185
186void LayerAnimationController::addObserver(LayerAnimationValueObserver* observer)
187{
188 if (!m_observers.HasObserver(observer))
189 m_observers.AddObserver(observer);
190}
191
192void LayerAnimationController::removeObserver(LayerAnimationValueObserver* observer)
193{
194 m_observers.RemoveObserver(observer);
[email protected]94f206c12012-08-25 00:09:14195}
196
[email protected]96baf3e2012-10-22 23:09:55197void LayerAnimationController::pushNewAnimationsToImplThread(LayerAnimationController* controllerImpl) const
[email protected]94f206c12012-08-25 00:09:14198{
199 // Any new animations owned by the main thread's controller are cloned and adde to the impl thread's controller.
200 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
201 // If the animation is already running on the impl thread, there is no need to copy it over.
202 if (controllerImpl->getActiveAnimation(m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty()))
203 continue;
204
205 // If the animation is not running on the impl thread, it does not necessarily mean that it needs
206 // to be copied over and started; it may have already finished. In this case, the impl thread animation
207 // will have already notified that it has started and the main thread animation will no longer need
208 // a synchronized start time.
209 if (!m_activeAnimations[i]->needsSynchronizedStartTime())
210 continue;
211
212 // The new animation should be set to run as soon as possible.
[email protected]96baf3e2012-10-22 23:09:55213 ActiveAnimation::RunState initialRunState = ActiveAnimation::WaitingForTargetAvailability;
[email protected]94f206c12012-08-25 00:09:14214 double startTime = 0;
[email protected]96baf3e2012-10-22 23:09:55215 scoped_ptr<ActiveAnimation> toAdd(m_activeAnimations[i]->cloneAndInitialize(ActiveAnimation::ControllingInstance, initialRunState, startTime));
[email protected]1d993172012-10-18 18:15:04216 DCHECK(!toAdd->needsSynchronizedStartTime());
[email protected]9aca3592012-10-12 15:57:09217 controllerImpl->addAnimation(toAdd.Pass());
[email protected]94f206c12012-08-25 00:09:14218 }
219}
220
[email protected]96baf3e2012-10-22 23:09:55221void LayerAnimationController::removeAnimationsCompletedOnMainThread(LayerAnimationController* controllerImpl) const
[email protected]94f206c12012-08-25 00:09:14222{
223 // Delete all impl thread animations for which there is no corresponding main thread animation.
224 // Each iteration, controller->m_activeAnimations.size() is decremented or i is incremented
225 // guaranteeing progress towards loop termination.
226 for (size_t i = 0; i < controllerImpl->m_activeAnimations.size();) {
[email protected]96baf3e2012-10-22 23:09:55227 ActiveAnimation* current = getActiveAnimation(controllerImpl->m_activeAnimations[i]->group(), controllerImpl->m_activeAnimations[i]->targetProperty());
[email protected]94f206c12012-08-25 00:09:14228 if (!current)
229 controllerImpl->m_activeAnimations.remove(i);
230 else
231 i++;
232 }
233}
234
[email protected]96baf3e2012-10-22 23:09:55235void LayerAnimationController::pushPropertiesToImplThread(LayerAnimationController* controllerImpl) const
[email protected]94f206c12012-08-25 00:09:14236{
237 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
[email protected]96baf3e2012-10-22 23:09:55238 ActiveAnimation* currentImpl = controllerImpl->getActiveAnimation(m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty());
[email protected]94f206c12012-08-25 00:09:14239 if (currentImpl)
240 m_activeAnimations[i]->pushPropertiesTo(currentImpl);
241 }
242}
243
[email protected]96baf3e2012-10-22 23:09:55244void LayerAnimationController::startAnimationsWaitingForNextTick(double monotonicTime, AnimationEventsVector* events)
[email protected]94f206c12012-08-25 00:09:14245{
246 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
[email protected]96baf3e2012-10-22 23:09:55247 if (m_activeAnimations[i]->runState() == ActiveAnimation::WaitingForNextTick) {
248 m_activeAnimations[i]->setRunState(ActiveAnimation::Running, monotonicTime);
[email protected]94f206c12012-08-25 00:09:14249 if (!m_activeAnimations[i]->hasSetStartTime())
250 m_activeAnimations[i]->setStartTime(monotonicTime);
251 if (events)
[email protected]de4afb5e2012-12-20 00:11:34252 events->push_back(AnimationEvent(AnimationEvent::Started, m_id, m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty(), monotonicTime));
[email protected]94f206c12012-08-25 00:09:14253 }
254 }
255}
256
[email protected]96baf3e2012-10-22 23:09:55257void LayerAnimationController::startAnimationsWaitingForStartTime(double monotonicTime, AnimationEventsVector* events)
[email protected]94f206c12012-08-25 00:09:14258{
259 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
[email protected]96baf3e2012-10-22 23:09:55260 if (m_activeAnimations[i]->runState() == ActiveAnimation::WaitingForStartTime && m_activeAnimations[i]->startTime() <= monotonicTime) {
261 m_activeAnimations[i]->setRunState(ActiveAnimation::Running, monotonicTime);
[email protected]94f206c12012-08-25 00:09:14262 if (events)
[email protected]de4afb5e2012-12-20 00:11:34263 events->push_back(AnimationEvent(AnimationEvent::Started, m_id, m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty(), monotonicTime));
[email protected]94f206c12012-08-25 00:09:14264 }
265 }
266}
267
[email protected]96baf3e2012-10-22 23:09:55268void LayerAnimationController::startAnimationsWaitingForTargetAvailability(double monotonicTime, AnimationEventsVector* events)
[email protected]94f206c12012-08-25 00:09:14269{
270 // First collect running properties.
271 TargetProperties blockedProperties;
272 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
[email protected]96baf3e2012-10-22 23:09:55273 if (m_activeAnimations[i]->runState() == ActiveAnimation::Running || m_activeAnimations[i]->runState() == ActiveAnimation::Finished)
[email protected]c7278e5b2012-10-11 02:35:46274 blockedProperties.insert(m_activeAnimations[i]->targetProperty());
[email protected]94f206c12012-08-25 00:09:14275 }
276
277 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
[email protected]96baf3e2012-10-22 23:09:55278 if (m_activeAnimations[i]->runState() == ActiveAnimation::WaitingForTargetAvailability) {
[email protected]94f206c12012-08-25 00:09:14279 // Collect all properties for animations with the same group id (they should all also be in the list of animations).
280 TargetProperties enqueuedProperties;
[email protected]c7278e5b2012-10-11 02:35:46281 enqueuedProperties.insert(m_activeAnimations[i]->targetProperty());
[email protected]94f206c12012-08-25 00:09:14282 for (size_t j = i + 1; j < m_activeAnimations.size(); ++j) {
283 if (m_activeAnimations[i]->group() == m_activeAnimations[j]->group())
[email protected]c7278e5b2012-10-11 02:35:46284 enqueuedProperties.insert(m_activeAnimations[j]->targetProperty());
[email protected]94f206c12012-08-25 00:09:14285 }
286
287 // Check to see if intersection of the list of properties affected by the group and the list of currently
288 // blocked properties is null. In any case, the group's target properties need to be added to the list
289 // of blocked properties.
290 bool nullIntersection = true;
291 for (TargetProperties::iterator pIter = enqueuedProperties.begin(); pIter != enqueuedProperties.end(); ++pIter) {
[email protected]c7278e5b2012-10-11 02:35:46292 if (!blockedProperties.insert(*pIter).second)
[email protected]94f206c12012-08-25 00:09:14293 nullIntersection = false;
294 }
295
296 // If the intersection is null, then we are free to start the animations in the group.
297 if (nullIntersection) {
[email protected]96baf3e2012-10-22 23:09:55298 m_activeAnimations[i]->setRunState(ActiveAnimation::Running, monotonicTime);
[email protected]94f206c12012-08-25 00:09:14299 if (!m_activeAnimations[i]->hasSetStartTime())
300 m_activeAnimations[i]->setStartTime(monotonicTime);
301 if (events)
[email protected]de4afb5e2012-12-20 00:11:34302 events->push_back(AnimationEvent(AnimationEvent::Started, m_id, m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty(), monotonicTime));
[email protected]94f206c12012-08-25 00:09:14303 for (size_t j = i + 1; j < m_activeAnimations.size(); ++j) {
304 if (m_activeAnimations[i]->group() == m_activeAnimations[j]->group()) {
[email protected]96baf3e2012-10-22 23:09:55305 m_activeAnimations[j]->setRunState(ActiveAnimation::Running, monotonicTime);
[email protected]94f206c12012-08-25 00:09:14306 if (!m_activeAnimations[j]->hasSetStartTime())
307 m_activeAnimations[j]->setStartTime(monotonicTime);
308 }
309 }
310 }
311 }
312 }
313}
314
[email protected]96baf3e2012-10-22 23:09:55315void LayerAnimationController::resolveConflicts(double monotonicTime)
[email protected]94f206c12012-08-25 00:09:14316{
317 // Find any animations that are animating the same property and resolve the
318 // confict. We could eventually blend, but for now we'll just abort the
319 // previous animation (where 'previous' means: (1) has a prior start time or
320 // (2) has an equal start time, but was added to the queue earlier, i.e.,
321 // has a lower index in m_activeAnimations).
322 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
[email protected]96baf3e2012-10-22 23:09:55323 if (m_activeAnimations[i]->runState() == ActiveAnimation::Running) {
[email protected]94f206c12012-08-25 00:09:14324 for (size_t j = i + 1; j < m_activeAnimations.size(); ++j) {
[email protected]96baf3e2012-10-22 23:09:55325 if (m_activeAnimations[j]->runState() == ActiveAnimation::Running && m_activeAnimations[i]->targetProperty() == m_activeAnimations[j]->targetProperty()) {
[email protected]94f206c12012-08-25 00:09:14326 if (m_activeAnimations[i]->startTime() > m_activeAnimations[j]->startTime())
[email protected]96baf3e2012-10-22 23:09:55327 m_activeAnimations[j]->setRunState(ActiveAnimation::Aborted, monotonicTime);
[email protected]94f206c12012-08-25 00:09:14328 else
[email protected]96baf3e2012-10-22 23:09:55329 m_activeAnimations[i]->setRunState(ActiveAnimation::Aborted, monotonicTime);
[email protected]94f206c12012-08-25 00:09:14330 }
331 }
332 }
333 }
334}
335
[email protected]96baf3e2012-10-22 23:09:55336void LayerAnimationController::markAnimationsForDeletion(double monotonicTime, AnimationEventsVector* events)
[email protected]94f206c12012-08-25 00:09:14337{
338 for (size_t i = 0; i < m_activeAnimations.size(); i++) {
339 int groupId = m_activeAnimations[i]->group();
340 bool allAnimsWithSameIdAreFinished = false;
341 // If an animation is finished, and not already marked for deletion,
342 // Find out if all other animations in the same group are also finished.
343 if (m_activeAnimations[i]->isFinished()) {
344 allAnimsWithSameIdAreFinished = true;
345 for (size_t j = 0; j < m_activeAnimations.size(); ++j) {
346 if (groupId == m_activeAnimations[j]->group() && !m_activeAnimations[j]->isFinished()) {
347 allAnimsWithSameIdAreFinished = false;
348 break;
349 }
350 }
351 }
352 if (allAnimsWithSameIdAreFinished) {
353 // We now need to remove all animations with the same group id as groupId
354 // (and send along animation finished notifications, if necessary).
355 for (size_t j = i; j < m_activeAnimations.size(); j++) {
356 if (groupId == m_activeAnimations[j]->group()) {
357 if (events)
[email protected]de4afb5e2012-12-20 00:11:34358 events->push_back(AnimationEvent(AnimationEvent::Finished, m_id, m_activeAnimations[j]->group(), m_activeAnimations[j]->targetProperty(), monotonicTime));
[email protected]96baf3e2012-10-22 23:09:55359 m_activeAnimations[j]->setRunState(ActiveAnimation::WaitingForDeletion, monotonicTime);
[email protected]94f206c12012-08-25 00:09:14360 }
361 }
362 }
363 }
364}
365
[email protected]96baf3e2012-10-22 23:09:55366void LayerAnimationController::purgeAnimationsMarkedForDeletion()
[email protected]94f206c12012-08-25 00:09:14367{
368 for (size_t i = 0; i < m_activeAnimations.size();) {
[email protected]96baf3e2012-10-22 23:09:55369 if (m_activeAnimations[i]->runState() == ActiveAnimation::WaitingForDeletion)
[email protected]94f206c12012-08-25 00:09:14370 m_activeAnimations.remove(i);
371 else
372 i++;
373 }
374}
375
[email protected]96baf3e2012-10-22 23:09:55376void LayerAnimationController::replaceImplThreadAnimations(LayerAnimationController* controllerImpl) const
[email protected]94f206c12012-08-25 00:09:14377{
378 controllerImpl->m_activeAnimations.clear();
379 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
[email protected]96baf3e2012-10-22 23:09:55380 scoped_ptr<ActiveAnimation> toAdd;
[email protected]94f206c12012-08-25 00:09:14381 if (m_activeAnimations[i]->needsSynchronizedStartTime()) {
382 // We haven't received an animation started notification yet, so it
383 // is important that we add it in a 'waiting' and not 'running' state.
[email protected]96baf3e2012-10-22 23:09:55384 ActiveAnimation::RunState initialRunState = ActiveAnimation::WaitingForTargetAvailability;
[email protected]94f206c12012-08-25 00:09:14385 double startTime = 0;
[email protected]96baf3e2012-10-22 23:09:55386 toAdd = m_activeAnimations[i]->cloneAndInitialize(ActiveAnimation::ControllingInstance, initialRunState, startTime).Pass();
[email protected]94f206c12012-08-25 00:09:14387 } else
[email protected]96baf3e2012-10-22 23:09:55388 toAdd = m_activeAnimations[i]->clone(ActiveAnimation::ControllingInstance).Pass();
[email protected]94f206c12012-08-25 00:09:14389
[email protected]9aca3592012-10-12 15:57:09390 controllerImpl->addAnimation(toAdd.Pass());
[email protected]94f206c12012-08-25 00:09:14391 }
392}
393
[email protected]96baf3e2012-10-22 23:09:55394void LayerAnimationController::tickAnimations(double monotonicTime)
[email protected]94f206c12012-08-25 00:09:14395{
[email protected]df1ec1a2012-12-08 17:01:18396 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
[email protected]96baf3e2012-10-22 23:09:55397 if (m_activeAnimations[i]->runState() == ActiveAnimation::Running || m_activeAnimations[i]->runState() == ActiveAnimation::Paused) {
[email protected]94f206c12012-08-25 00:09:14398 double trimmed = m_activeAnimations[i]->trimTimeToCurrentIteration(monotonicTime);
399
400 // Animation assumes its initial value until it gets the synchronized start time
401 // from the impl thread and can start ticking.
402 if (m_activeAnimations[i]->needsSynchronizedStartTime())
403 trimmed = 0;
404
405 switch (m_activeAnimations[i]->targetProperty()) {
406
[email protected]96baf3e2012-10-22 23:09:55407 case ActiveAnimation::Transform: {
408 const TransformAnimationCurve* transformAnimationCurve = m_activeAnimations[i]->curve()->toTransformAnimationCurve();
[email protected]de4afb5e2012-12-20 00:11:34409 const gfx::Transform transform = transformAnimationCurve->getValue(trimmed).toTransform();
[email protected]94f206c12012-08-25 00:09:14410 if (m_activeAnimations[i]->isFinishedAt(monotonicTime))
[email protected]96baf3e2012-10-22 23:09:55411 m_activeAnimations[i]->setRunState(ActiveAnimation::Finished, monotonicTime);
[email protected]df1ec1a2012-12-08 17:01:18412
[email protected]de4afb5e2012-12-20 00:11:34413 notifyObserversTransformAnimated(transform);
[email protected]94f206c12012-08-25 00:09:14414 break;
415 }
416
[email protected]96baf3e2012-10-22 23:09:55417 case ActiveAnimation::Opacity: {
418 const FloatAnimationCurve* floatAnimationCurve = m_activeAnimations[i]->curve()->toFloatAnimationCurve();
[email protected]df1ec1a2012-12-08 17:01:18419 const float opacity = floatAnimationCurve->getValue(trimmed);
[email protected]94f206c12012-08-25 00:09:14420 if (m_activeAnimations[i]->isFinishedAt(monotonicTime))
[email protected]96baf3e2012-10-22 23:09:55421 m_activeAnimations[i]->setRunState(ActiveAnimation::Finished, monotonicTime);
[email protected]df1ec1a2012-12-08 17:01:18422
[email protected]de4afb5e2012-12-20 00:11:34423 notifyObserversOpacityAnimated(opacity);
[email protected]94f206c12012-08-25 00:09:14424 break;
425 }
426
427 // Do nothing for sentinel value.
[email protected]96baf3e2012-10-22 23:09:55428 case ActiveAnimation::TargetPropertyEnumSize:
[email protected]1d993172012-10-18 18:15:04429 NOTREACHED();
[email protected]94f206c12012-08-25 00:09:14430 }
431 }
432 }
433}
434
[email protected]de4afb5e2012-12-20 00:11:34435void LayerAnimationController::updateActivation(bool force)
436{
437 if (m_registrar) {
438 if (!m_activeAnimations.isEmpty() && (!m_isActive || force))
439 m_registrar->DidActivateAnimationController(this);
440 else if (m_activeAnimations.isEmpty() && (m_isActive || force))
441 m_registrar->DidDeactivateAnimationController(this);
442 m_isActive = !m_activeAnimations.isEmpty();
443 }
444}
445
446void LayerAnimationController::notifyObserversOpacityAnimated(float opacity)
447{
448 FOR_EACH_OBSERVER(LayerAnimationValueObserver,
449 m_observers,
450 OnOpacityAnimated(opacity));
451}
452
453void LayerAnimationController::notifyObserversTransformAnimated(const gfx::Transform& transform)
454{
455 FOR_EACH_OBSERVER(LayerAnimationValueObserver,
456 m_observers,
457 OnTransformAnimated(transform));
458}
459
[email protected]d3143c732012-10-05 19:17:59460} // namespace cc