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/active_animation.h" |
8 #include "cc/animation_registrar.h" | |
8 #include "cc/keyframed_animation_curve.h" | 9 #include "cc/keyframed_animation_curve.h" |
9 #include "ui/gfx/transform.h" | 10 #include "ui/gfx/transform.h" |
10 | 11 |
11 namespace cc { | 12 namespace cc { |
12 | 13 |
13 LayerAnimationController::LayerAnimationController(LayerAnimationControllerClien t* client) | 14 LayerAnimationController::LayerAnimationController() |
14 : m_forceSync(false) | 15 : m_forceSync(false) |
15 , m_client(client) | 16 , m_id(-1) |
17 , m_registrar(0) | |
16 { | 18 { |
17 } | 19 } |
18 | 20 |
19 LayerAnimationController::~LayerAnimationController() | 21 LayerAnimationController::~LayerAnimationController() |
20 { | 22 { |
23 if (m_registrar) | |
24 m_registrar->Unregister(this); | |
21 } | 25 } |
22 | 26 |
23 scoped_ptr<LayerAnimationController> LayerAnimationController::create(LayerAnima tionControllerClient* client) | 27 scoped_refptr<LayerAnimationController> LayerAnimationController::create() |
24 { | 28 { |
25 return make_scoped_ptr(new LayerAnimationController(client)); | 29 return make_scoped_refptr(new LayerAnimationController()); |
26 } | 30 } |
27 | 31 |
28 void LayerAnimationController::pauseAnimation(int animationId, double timeOffset ) | 32 void LayerAnimationController::pauseAnimation(int animationId, double timeOffset ) |
29 { | 33 { |
30 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 34 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
31 if (m_activeAnimations[i]->id() == animationId) | 35 if (m_activeAnimations[i]->id() == animationId) |
32 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()); |
33 } | 37 } |
34 } | 38 } |
35 | 39 |
36 void LayerAnimationController::removeAnimation(int animationId) | 40 void LayerAnimationController::removeAnimation(int animationId) |
37 { | 41 { |
38 for (size_t i = 0; i < m_activeAnimations.size();) { | 42 for (size_t i = 0; i < m_activeAnimations.size();) { |
39 if (m_activeAnimations[i]->id() == animationId) | 43 if (m_activeAnimations[i]->id() == animationId) |
40 m_activeAnimations.remove(i); | 44 m_activeAnimations.remove(i); |
41 else | 45 else |
42 i++; | 46 i++; |
43 } | 47 } |
48 updateRegistration(); | |
44 } | 49 } |
45 | 50 |
46 void LayerAnimationController::removeAnimation(int animationId, ActiveAnimation: :TargetProperty targetProperty) | 51 void LayerAnimationController::removeAnimation(int animationId, ActiveAnimation: :TargetProperty targetProperty) |
47 { | 52 { |
48 for (size_t i = 0; i < m_activeAnimations.size();) { | 53 for (size_t i = 0; i < m_activeAnimations.size();) { |
49 if (m_activeAnimations[i]->id() == animationId && m_activeAnimations[i]- >targetProperty() == targetProperty) | 54 if (m_activeAnimations[i]->id() == animationId && m_activeAnimations[i]- >targetProperty() == targetProperty) |
50 m_activeAnimations.remove(i); | 55 m_activeAnimations.remove(i); |
51 else | 56 else |
52 i++; | 57 i++; |
53 } | 58 } |
59 updateRegistration(); | |
54 } | 60 } |
55 | 61 |
56 // According to render layer backing, these are for testing only. | 62 // According to render layer backing, these are for testing only. |
57 void LayerAnimationController::suspendAnimations(double monotonicTime) | 63 void LayerAnimationController::suspendAnimations(double monotonicTime) |
58 { | 64 { |
59 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 65 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
60 if (!m_activeAnimations[i]->isFinished()) | 66 if (!m_activeAnimations[i]->isFinished()) |
61 m_activeAnimations[i]->setRunState(ActiveAnimation::Paused, monotoni cTime); | 67 m_activeAnimations[i]->setRunState(ActiveAnimation::Paused, monotoni cTime); |
62 } | 68 } |
63 } | 69 } |
(...skipping 29 matching lines...) Expand all Loading... | |
93 | 99 |
94 void LayerAnimationController::animate(double monotonicTime, AnimationEventsVect or* events) | 100 void LayerAnimationController::animate(double monotonicTime, AnimationEventsVect or* events) |
95 { | 101 { |
96 startAnimationsWaitingForNextTick(monotonicTime, events); | 102 startAnimationsWaitingForNextTick(monotonicTime, events); |
97 startAnimationsWaitingForStartTime(monotonicTime, events); | 103 startAnimationsWaitingForStartTime(monotonicTime, events); |
98 startAnimationsWaitingForTargetAvailability(monotonicTime, events); | 104 startAnimationsWaitingForTargetAvailability(monotonicTime, events); |
99 resolveConflicts(monotonicTime); | 105 resolveConflicts(monotonicTime); |
100 tickAnimations(monotonicTime); | 106 tickAnimations(monotonicTime); |
101 markAnimationsForDeletion(monotonicTime, events); | 107 markAnimationsForDeletion(monotonicTime, events); |
102 startAnimationsWaitingForTargetAvailability(monotonicTime, events); | 108 startAnimationsWaitingForTargetAvailability(monotonicTime, events); |
109 | |
110 updateRegistration(); | |
103 } | 111 } |
104 | 112 |
105 void LayerAnimationController::addAnimation(scoped_ptr<ActiveAnimation> animatio n) | 113 void LayerAnimationController::addAnimation(scoped_ptr<ActiveAnimation> animatio n) |
106 { | 114 { |
107 m_activeAnimations.append(animation.Pass()); | 115 m_activeAnimations.append(animation.Pass()); |
116 updateRegistration(); | |
108 } | 117 } |
109 | 118 |
110 ActiveAnimation* LayerAnimationController::getActiveAnimation(int groupId, Activ eAnimation::TargetProperty targetProperty) const | 119 ActiveAnimation* LayerAnimationController::getActiveAnimation(int groupId, Activ eAnimation::TargetProperty targetProperty) const |
111 { | 120 { |
112 for (size_t i = 0; i < m_activeAnimations.size(); ++i) | 121 for (size_t i = 0; i < m_activeAnimations.size(); ++i) |
113 if (m_activeAnimations[i]->group() == groupId && m_activeAnimations[i]-> targetProperty() == targetProperty) | 122 if (m_activeAnimations[i]->group() == groupId && m_activeAnimations[i]-> targetProperty() == targetProperty) |
114 return m_activeAnimations[i]; | 123 return m_activeAnimations[i]; |
115 return 0; | 124 return 0; |
116 } | 125 } |
117 | 126 |
(...skipping 29 matching lines...) Expand all Loading... | |
147 { | 156 { |
148 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 157 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
149 if (m_activeAnimations[i]->group() == event.groupId && m_activeAnimation s[i]->targetProperty() == event.targetProperty && m_activeAnimations[i]->needsSy nchronizedStartTime()) { | 158 if (m_activeAnimations[i]->group() == event.groupId && m_activeAnimation s[i]->targetProperty() == event.targetProperty && m_activeAnimations[i]->needsSy nchronizedStartTime()) { |
150 m_activeAnimations[i]->setNeedsSynchronizedStartTime(false); | 159 m_activeAnimations[i]->setNeedsSynchronizedStartTime(false); |
151 m_activeAnimations[i]->setStartTime(event.monotonicTime); | 160 m_activeAnimations[i]->setStartTime(event.monotonicTime); |
152 return; | 161 return; |
153 } | 162 } |
154 } | 163 } |
155 } | 164 } |
156 | 165 |
157 void LayerAnimationController::setClient(LayerAnimationControllerClient* client) | 166 void LayerAnimationController::setAnimationRegistrar(AnimationRegistrar* registr ar) |
158 { | 167 { |
159 m_client = client; | 168 if (m_registrar == registrar) |
169 return; | |
nduca
2012/12/04 05:51:13
Oh i get it nao. Thanks.
Can we split out registr
Ian Vollick
2012/12/04 19:49:06
Naming is hard. Perhaps registration is the wrong
| |
170 | |
171 if (m_registrar && registrar) | |
172 m_registrar->Unregister(this); | |
173 | |
174 m_registrar = registrar; | |
175 | |
176 updateRegistration(); | |
177 } | |
178 | |
179 void LayerAnimationController::setId(int id) | |
180 { | |
181 m_id = id; | |
160 } | 182 } |
161 | 183 |
162 void LayerAnimationController::pushNewAnimationsToImplThread(LayerAnimationContr oller* controllerImpl) const | 184 void LayerAnimationController::pushNewAnimationsToImplThread(LayerAnimationContr oller* controllerImpl) const |
163 { | 185 { |
164 // Any new animations owned by the main thread's controller are cloned and a dde to the impl thread's controller. | 186 // Any new animations owned by the main thread's controller are cloned and a dde to the impl thread's controller. |
165 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 187 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
166 // If the animation is already running on the impl thread, there is no n eed to copy it over. | 188 // If the animation is already running on the impl thread, there is no n eed to copy it over. |
167 if (controllerImpl->getActiveAnimation(m_activeAnimations[i]->group(), m _activeAnimations[i]->targetProperty())) | 189 if (controllerImpl->getActiveAnimation(m_activeAnimations[i]->group(), m _activeAnimations[i]->targetProperty())) |
168 continue; | 190 continue; |
169 | 191 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 } | 229 } |
208 | 230 |
209 void LayerAnimationController::startAnimationsWaitingForNextTick(double monotoni cTime, AnimationEventsVector* events) | 231 void LayerAnimationController::startAnimationsWaitingForNextTick(double monotoni cTime, AnimationEventsVector* events) |
210 { | 232 { |
211 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 233 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
212 if (m_activeAnimations[i]->runState() == ActiveAnimation::WaitingForNext Tick) { | 234 if (m_activeAnimations[i]->runState() == ActiveAnimation::WaitingForNext Tick) { |
213 m_activeAnimations[i]->setRunState(ActiveAnimation::Running, monoton icTime); | 235 m_activeAnimations[i]->setRunState(ActiveAnimation::Running, monoton icTime); |
214 if (!m_activeAnimations[i]->hasSetStartTime()) | 236 if (!m_activeAnimations[i]->hasSetStartTime()) |
215 m_activeAnimations[i]->setStartTime(monotonicTime); | 237 m_activeAnimations[i]->setStartTime(monotonicTime); |
216 if (events) | 238 if (events) |
217 events->push_back(AnimationEvent(AnimationEvent::Started, m_clie nt->id(), m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty( ), monotonicTime)); | 239 events->push_back(AnimationEvent(AnimationEvent::Started, m_id, m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty(), monoton icTime)); |
218 } | 240 } |
219 } | 241 } |
220 } | 242 } |
221 | 243 |
222 void LayerAnimationController::startAnimationsWaitingForStartTime(double monoton icTime, AnimationEventsVector* events) | 244 void LayerAnimationController::startAnimationsWaitingForStartTime(double monoton icTime, AnimationEventsVector* events) |
223 { | 245 { |
224 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 246 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
225 if (m_activeAnimations[i]->runState() == ActiveAnimation::WaitingForStar tTime && m_activeAnimations[i]->startTime() <= monotonicTime) { | 247 if (m_activeAnimations[i]->runState() == ActiveAnimation::WaitingForStar tTime && m_activeAnimations[i]->startTime() <= monotonicTime) { |
226 m_activeAnimations[i]->setRunState(ActiveAnimation::Running, monoton icTime); | 248 m_activeAnimations[i]->setRunState(ActiveAnimation::Running, monoton icTime); |
227 if (events) | 249 if (events) |
228 events->push_back(AnimationEvent(AnimationEvent::Started, m_clie nt->id(), m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty( ), monotonicTime)); | 250 events->push_back(AnimationEvent(AnimationEvent::Started, m_id, m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty(), monoton icTime)); |
229 } | 251 } |
230 } | 252 } |
231 } | 253 } |
232 | 254 |
233 void LayerAnimationController::startAnimationsWaitingForTargetAvailability(doubl e monotonicTime, AnimationEventsVector* events) | 255 void LayerAnimationController::startAnimationsWaitingForTargetAvailability(doubl e monotonicTime, AnimationEventsVector* events) |
234 { | 256 { |
235 // First collect running properties. | 257 // First collect running properties. |
236 TargetProperties blockedProperties; | 258 TargetProperties blockedProperties; |
237 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 259 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
238 if (m_activeAnimations[i]->runState() == ActiveAnimation::Running || m_a ctiveAnimations[i]->runState() == ActiveAnimation::Finished) | 260 if (m_activeAnimations[i]->runState() == ActiveAnimation::Running || m_a ctiveAnimations[i]->runState() == ActiveAnimation::Finished) |
(...skipping 18 matching lines...) Expand all Loading... | |
257 if (!blockedProperties.insert(*pIter).second) | 279 if (!blockedProperties.insert(*pIter).second) |
258 nullIntersection = false; | 280 nullIntersection = false; |
259 } | 281 } |
260 | 282 |
261 // If the intersection is null, then we are free to start the animat ions in the group. | 283 // If the intersection is null, then we are free to start the animat ions in the group. |
262 if (nullIntersection) { | 284 if (nullIntersection) { |
263 m_activeAnimations[i]->setRunState(ActiveAnimation::Running, mon otonicTime); | 285 m_activeAnimations[i]->setRunState(ActiveAnimation::Running, mon otonicTime); |
264 if (!m_activeAnimations[i]->hasSetStartTime()) | 286 if (!m_activeAnimations[i]->hasSetStartTime()) |
265 m_activeAnimations[i]->setStartTime(monotonicTime); | 287 m_activeAnimations[i]->setStartTime(monotonicTime); |
266 if (events) | 288 if (events) |
267 events->push_back(AnimationEvent(AnimationEvent::Started, m_ client->id(), m_activeAnimations[i]->group(), m_activeAnimations[i]->targetPrope rty(), monotonicTime)); | 289 events->push_back(AnimationEvent(AnimationEvent::Started, m_ id, m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty(), mon otonicTime)); |
268 for (size_t j = i + 1; j < m_activeAnimations.size(); ++j) { | 290 for (size_t j = i + 1; j < m_activeAnimations.size(); ++j) { |
269 if (m_activeAnimations[i]->group() == m_activeAnimations[j]- >group()) { | 291 if (m_activeAnimations[i]->group() == m_activeAnimations[j]- >group()) { |
270 m_activeAnimations[j]->setRunState(ActiveAnimation::Runn ing, monotonicTime); | 292 m_activeAnimations[j]->setRunState(ActiveAnimation::Runn ing, monotonicTime); |
271 if (!m_activeAnimations[j]->hasSetStartTime()) | 293 if (!m_activeAnimations[j]->hasSetStartTime()) |
272 m_activeAnimations[j]->setStartTime(monotonicTime); | 294 m_activeAnimations[j]->setStartTime(monotonicTime); |
273 } | 295 } |
274 } | 296 } |
275 } | 297 } |
276 } | 298 } |
277 } | 299 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 break; | 335 break; |
314 } | 336 } |
315 } | 337 } |
316 } | 338 } |
317 if (allAnimsWithSameIdAreFinished) { | 339 if (allAnimsWithSameIdAreFinished) { |
318 // We now need to remove all animations with the same group id as gr oupId | 340 // We now need to remove all animations with the same group id as gr oupId |
319 // (and send along animation finished notifications, if necessary). | 341 // (and send along animation finished notifications, if necessary). |
320 for (size_t j = i; j < m_activeAnimations.size(); j++) { | 342 for (size_t j = i; j < m_activeAnimations.size(); j++) { |
321 if (groupId == m_activeAnimations[j]->group()) { | 343 if (groupId == m_activeAnimations[j]->group()) { |
322 if (events) | 344 if (events) |
323 events->push_back(AnimationEvent(AnimationEvent::Finishe d, m_client->id(), m_activeAnimations[j]->group(), m_activeAnimations[j]->target Property(), monotonicTime)); | 345 events->push_back(AnimationEvent(AnimationEvent::Finishe d, m_id, m_activeAnimations[j]->group(), m_activeAnimations[j]->targetProperty() , monotonicTime)); |
324 m_activeAnimations[j]->setRunState(ActiveAnimation::WaitingF orDeletion, monotonicTime); | 346 m_activeAnimations[j]->setRunState(ActiveAnimation::WaitingF orDeletion, monotonicTime); |
325 } | 347 } |
326 } | 348 } |
327 } | 349 } |
328 } | 350 } |
329 } | 351 } |
330 | 352 |
331 void LayerAnimationController::purgeAnimationsMarkedForDeletion() | 353 void LayerAnimationController::purgeAnimationsMarkedForDeletion() |
332 { | 354 { |
333 for (size_t i = 0; i < m_activeAnimations.size();) { | 355 for (size_t i = 0; i < m_activeAnimations.size();) { |
(...skipping 17 matching lines...) Expand all Loading... | |
351 toAdd = m_activeAnimations[i]->cloneAndInitialize(ActiveAnimation::C ontrollingInstance, initialRunState, startTime).Pass(); | 373 toAdd = m_activeAnimations[i]->cloneAndInitialize(ActiveAnimation::C ontrollingInstance, initialRunState, startTime).Pass(); |
352 } else | 374 } else |
353 toAdd = m_activeAnimations[i]->clone(ActiveAnimation::ControllingIns tance).Pass(); | 375 toAdd = m_activeAnimations[i]->clone(ActiveAnimation::ControllingIns tance).Pass(); |
354 | 376 |
355 controllerImpl->addAnimation(toAdd.Pass()); | 377 controllerImpl->addAnimation(toAdd.Pass()); |
356 } | 378 } |
357 } | 379 } |
358 | 380 |
359 void LayerAnimationController::tickAnimations(double monotonicTime) | 381 void LayerAnimationController::tickAnimations(double monotonicTime) |
360 { | 382 { |
383 // FIXME(vollick) we should really be using base::TimeTicks instead of | |
384 // doubles throughout this class. For now, we need to recalculate now so | |
385 // that we can express the last update times for opacity and floats as | |
386 // base::TimeTicks. | |
387 base::TimeTicks now = base::TimeTicks::Now(); | |
388 | |
361 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 389 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
362 if (m_activeAnimations[i]->runState() == ActiveAnimation::Running || m_a ctiveAnimations[i]->runState() == ActiveAnimation::Paused) { | 390 if (m_activeAnimations[i]->runState() == ActiveAnimation::Running || m_a ctiveAnimations[i]->runState() == ActiveAnimation::Paused) { |
363 double trimmed = m_activeAnimations[i]->trimTimeToCurrentIteration(m onotonicTime); | 391 double trimmed = m_activeAnimations[i]->trimTimeToCurrentIteration(m onotonicTime); |
364 | 392 |
365 // Animation assumes its initial value until it gets the synchronize d start time | 393 // Animation assumes its initial value until it gets the synchronize d start time |
366 // from the impl thread and can start ticking. | 394 // from the impl thread and can start ticking. |
367 if (m_activeAnimations[i]->needsSynchronizedStartTime()) | 395 if (m_activeAnimations[i]->needsSynchronizedStartTime()) |
368 trimmed = 0; | 396 trimmed = 0; |
369 | 397 |
370 switch (m_activeAnimations[i]->targetProperty()) { | 398 switch (m_activeAnimations[i]->targetProperty()) { |
371 | 399 |
372 case ActiveAnimation::Transform: { | 400 case ActiveAnimation::Transform: { |
373 const TransformAnimationCurve* transformAnimationCurve = m_activ eAnimations[i]->curve()->toTransformAnimationCurve(); | 401 const TransformAnimationCurve* transformAnimationCurve = m_activ eAnimations[i]->curve()->toTransformAnimationCurve(); |
374 const gfx::Transform matrix = transformAnimationCurve->getValue( trimmed).toTransform(); | 402 m_transform = transformAnimationCurve->getValue(trimmed).toTrans form(); |
403 m_transformLastUpdateTime = now; | |
375 if (m_activeAnimations[i]->isFinishedAt(monotonicTime)) | 404 if (m_activeAnimations[i]->isFinishedAt(monotonicTime)) |
376 m_activeAnimations[i]->setRunState(ActiveAnimation::Finished , monotonicTime); | 405 m_activeAnimations[i]->setRunState(ActiveAnimation::Finished , monotonicTime); |
377 | |
378 m_client->setTransformFromAnimation(matrix); | |
379 break; | 406 break; |
380 } | 407 } |
381 | 408 |
382 case ActiveAnimation::Opacity: { | 409 case ActiveAnimation::Opacity: { |
383 const FloatAnimationCurve* floatAnimationCurve = m_activeAnimati ons[i]->curve()->toFloatAnimationCurve(); | 410 const FloatAnimationCurve* floatAnimationCurve = m_activeAnimati ons[i]->curve()->toFloatAnimationCurve(); |
384 const float opacity = floatAnimationCurve->getValue(trimmed); | 411 m_opacity = floatAnimationCurve->getValue(trimmed); |
412 m_opacityLastUpdateTime = now; | |
385 if (m_activeAnimations[i]->isFinishedAt(monotonicTime)) | 413 if (m_activeAnimations[i]->isFinishedAt(monotonicTime)) |
386 m_activeAnimations[i]->setRunState(ActiveAnimation::Finished , monotonicTime); | 414 m_activeAnimations[i]->setRunState(ActiveAnimation::Finished , monotonicTime); |
387 | |
388 m_client->setOpacityFromAnimation(opacity); | |
389 break; | 415 break; |
390 } | 416 } |
391 | 417 |
392 // Do nothing for sentinel value. | 418 // Do nothing for sentinel value. |
393 case ActiveAnimation::TargetPropertyEnumSize: | 419 case ActiveAnimation::TargetPropertyEnumSize: |
394 NOTREACHED(); | 420 NOTREACHED(); |
395 } | 421 } |
396 } | 422 } |
397 } | 423 } |
398 } | 424 } |
399 | 425 |
426 void LayerAnimationController::updateRegistration() | |
427 { | |
428 if (m_registrar) { | |
429 if (hasActiveAnimation()) | |
430 m_registrar->Register(this); | |
431 else | |
432 m_registrar->Unregister(this); | |
433 } | |
434 } | |
435 | |
400 } // namespace cc | 436 } // namespace cc |
OLD | NEW |