OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 109 |
110 // If timeOffset > 0, then the animation has started in the past. | 110 // If timeOffset > 0, then the animation has started in the past. |
111 anim->setTimeOffset(timeOffset); | 111 anim->setTimeOffset(timeOffset); |
112 | 112 |
113 return anim.release(); | 113 return anim.release(); |
114 } | 114 } |
115 | 115 |
116 } // namepace | 116 } // namepace |
117 | 117 |
118 CCLayerAnimationController::CCLayerAnimationController(CCLayerAnimationControlle
rClient* client) | 118 CCLayerAnimationController::CCLayerAnimationController(CCLayerAnimationControlle
rClient* client) |
119 : m_client(client) | 119 : m_forceSync(false) |
| 120 , m_client(client) |
120 { | 121 { |
121 } | 122 } |
122 | 123 |
123 CCLayerAnimationController::~CCLayerAnimationController() | 124 CCLayerAnimationController::~CCLayerAnimationController() |
124 { | 125 { |
125 } | 126 } |
126 | 127 |
127 PassOwnPtr<CCLayerAnimationController> CCLayerAnimationController::create(CCLaye
rAnimationControllerClient* client) | 128 PassOwnPtr<CCLayerAnimationController> CCLayerAnimationController::create(CCLaye
rAnimationControllerClient* client) |
128 { | 129 { |
129 return adoptPtr(new CCLayerAnimationController(client)); | 130 return adoptPtr(new CCLayerAnimationController(client)); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 189 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
189 if (m_activeAnimations[i]->runState() == CCActiveAnimation::Paused) | 190 if (m_activeAnimations[i]->runState() == CCActiveAnimation::Paused) |
190 m_activeAnimations[i]->setRunState(CCActiveAnimation::Running, monot
onicTime); | 191 m_activeAnimations[i]->setRunState(CCActiveAnimation::Running, monot
onicTime); |
191 } | 192 } |
192 } | 193 } |
193 | 194 |
194 // Ensures that the list of active animations on the main thread and the impl th
read | 195 // Ensures that the list of active animations on the main thread and the impl th
read |
195 // are kept in sync. | 196 // are kept in sync. |
196 void CCLayerAnimationController::pushAnimationUpdatesTo(CCLayerAnimationControll
er* controllerImpl) | 197 void CCLayerAnimationController::pushAnimationUpdatesTo(CCLayerAnimationControll
er* controllerImpl) |
197 { | 198 { |
198 pushNewAnimationsToImplThread(controllerImpl); | 199 if (m_forceSync) { |
199 removeAnimationsCompletedOnMainThread(controllerImpl); | 200 replaceImplThreadAnimations(controllerImpl); |
200 pushPropertiesToImplThread(controllerImpl); | 201 m_forceSync = false; |
| 202 } else { |
| 203 pushNewAnimationsToImplThread(controllerImpl); |
| 204 removeAnimationsCompletedOnMainThread(controllerImpl); |
| 205 pushPropertiesToImplThread(controllerImpl); |
| 206 } |
201 } | 207 } |
202 | 208 |
203 void CCLayerAnimationController::animate(double monotonicTime, CCAnimationEvents
Vector* events) | 209 void CCLayerAnimationController::animate(double monotonicTime, CCAnimationEvents
Vector* events) |
204 { | 210 { |
205 startAnimationsWaitingForNextTick(monotonicTime, events); | 211 startAnimationsWaitingForNextTick(monotonicTime, events); |
206 startAnimationsWaitingForStartTime(monotonicTime, events); | 212 startAnimationsWaitingForStartTime(monotonicTime, events); |
207 startAnimationsWaitingForTargetAvailability(monotonicTime, events); | 213 startAnimationsWaitingForTargetAvailability(monotonicTime, events); |
208 resolveConflicts(monotonicTime); | 214 resolveConflicts(monotonicTime); |
209 tickAnimations(monotonicTime); | 215 tickAnimations(monotonicTime); |
210 purgeFinishedAnimations(monotonicTime, events); | 216 purgeFinishedAnimations(monotonicTime, events); |
(...skipping 27 matching lines...) Expand all Loading... |
238 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 244 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
239 if (m_activeAnimations[i]->runState() != CCActiveAnimation::Finished &&
m_activeAnimations[i]->runState() != CCActiveAnimation::Aborted && m_activeAnima
tions[i]->targetProperty() == targetProperty) | 245 if (m_activeAnimations[i]->runState() != CCActiveAnimation::Finished &&
m_activeAnimations[i]->runState() != CCActiveAnimation::Aborted && m_activeAnima
tions[i]->targetProperty() == targetProperty) |
240 return true; | 246 return true; |
241 } | 247 } |
242 return false; | 248 return false; |
243 } | 249 } |
244 | 250 |
245 void CCLayerAnimationController::notifyAnimationStarted(const CCAnimationEvent&
event) | 251 void CCLayerAnimationController::notifyAnimationStarted(const CCAnimationEvent&
event) |
246 { | 252 { |
247 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 253 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
248 if (m_activeAnimations[i]->group() == event.groupId && m_activeAnimation
s[i]->targetProperty() == event.targetProperty) { | 254 if (m_activeAnimations[i]->group() == event.groupId && m_activeAnimation
s[i]->targetProperty() == event.targetProperty && m_activeAnimations[i]->needsSy
nchronizedStartTime()) { |
249 ASSERT(m_activeAnimations[i]->needsSynchronizedStartTime()); | |
250 m_activeAnimations[i]->setNeedsSynchronizedStartTime(false); | 255 m_activeAnimations[i]->setNeedsSynchronizedStartTime(false); |
251 m_activeAnimations[i]->setStartTime(event.monotonicTime); | 256 m_activeAnimations[i]->setStartTime(event.monotonicTime); |
252 return; | 257 return; |
253 } | 258 } |
254 } | 259 } |
255 } | 260 } |
256 | 261 |
| 262 void CCLayerAnimationController::setClient(CCLayerAnimationControllerClient* cli
ent) |
| 263 { |
| 264 m_client = client; |
| 265 } |
| 266 |
257 void CCLayerAnimationController::pushNewAnimationsToImplThread(CCLayerAnimationC
ontroller* controllerImpl) const | 267 void CCLayerAnimationController::pushNewAnimationsToImplThread(CCLayerAnimationC
ontroller* controllerImpl) const |
258 { | 268 { |
259 // Any new animations owned by the main thread's controller are cloned and a
dde to the impl thread's controller. | 269 // Any new animations owned by the main thread's controller are cloned and a
dde to the impl thread's controller. |
260 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 270 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
261 // If the animation is already running on the impl thread, there is no n
eed to copy it over. | 271 // If the animation is already running on the impl thread, there is no n
eed to copy it over. |
262 if (controllerImpl->getActiveAnimation(m_activeAnimations[i]->group(), m
_activeAnimations[i]->targetProperty())) | 272 if (controllerImpl->getActiveAnimation(m_activeAnimations[i]->group(), m
_activeAnimations[i]->targetProperty())) |
263 continue; | 273 continue; |
264 | 274 |
265 // If the animation is not running on the impl thread, it does not neces
sarily mean that it needs | 275 // If the animation is not running on the impl thread, it does not neces
sarily mean that it needs |
266 // to be copied over and started; it may have already finished. In this
case, the impl thread animation | 276 // to be copied over and started; it may have already finished. In this
case, the impl thread animation |
267 // will have already notified that it has started and the main thread an
imation will no longer need | 277 // will have already notified that it has started and the main thread an
imation will no longer need |
268 // a synchronized start time. | 278 // a synchronized start time. |
269 if (!m_activeAnimations[i]->needsSynchronizedStartTime()) | 279 if (!m_activeAnimations[i]->needsSynchronizedStartTime()) |
270 continue; | 280 continue; |
271 | 281 |
272 OwnPtr<CCActiveAnimation> toAdd(m_activeAnimations[i]->cloneForImplThrea
d()); | 282 OwnPtr<CCActiveAnimation> toAdd(m_activeAnimations[i]->cloneForImplThrea
d()); |
273 ASSERT(!toAdd->needsSynchronizedStartTime()); | 283 ASSERT(!toAdd->needsSynchronizedStartTime()); |
274 // The new animation should be set to run as soon as possible. | 284 // The new animation should be set to run as soon as possible. |
275 toAdd->setRunState(CCActiveAnimation::WaitingForTargetAvailability, 0); | 285 toAdd->setRunState(CCActiveAnimation::WaitingForTargetAvailability, 0); |
| 286 toAdd->setStartTime(0); |
276 controllerImpl->add(toAdd.release()); | 287 controllerImpl->add(toAdd.release()); |
277 } | 288 } |
278 } | 289 } |
279 | 290 |
280 void CCLayerAnimationController::removeAnimationsCompletedOnMainThread(CCLayerAn
imationController* controllerImpl) const | 291 void CCLayerAnimationController::removeAnimationsCompletedOnMainThread(CCLayerAn
imationController* controllerImpl) const |
281 { | 292 { |
282 // Delete all impl thread animations for which there is no corresponding mai
n thread animation. | 293 // Delete all impl thread animations for which there is no corresponding mai
n thread animation. |
283 // Each iteration, controller->m_activeAnimations.size() is decremented or i
is incremented | 294 // Each iteration, controller->m_activeAnimations.size() is decremented or i
is incremented |
284 // guaranteeing progress towards loop termination. | 295 // guaranteeing progress towards loop termination. |
285 for (size_t i = 0; i < controllerImpl->m_activeAnimations.size();) { | 296 for (size_t i = 0; i < controllerImpl->m_activeAnimations.size();) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 if (events) | 433 if (events) |
423 events->append(CCAnimationEvent(CCAnimationEvent::Finish
ed, m_client->id(), m_activeAnimations[j]->group(), m_activeAnimations[j]->targe
tProperty(), monotonicTime)); | 434 events->append(CCAnimationEvent(CCAnimationEvent::Finish
ed, m_client->id(), m_activeAnimations[j]->group(), m_activeAnimations[j]->targe
tProperty(), monotonicTime)); |
424 m_activeAnimations.remove(j); | 435 m_activeAnimations.remove(j); |
425 } | 436 } |
426 } | 437 } |
427 } else | 438 } else |
428 i++; | 439 i++; |
429 } | 440 } |
430 } | 441 } |
431 | 442 |
| 443 void CCLayerAnimationController::replaceImplThreadAnimations(CCLayerAnimationCon
troller* controllerImpl) const |
| 444 { |
| 445 controllerImpl->m_activeAnimations.clear(); |
| 446 for (size_t i = 0; i < m_activeAnimations.size(); ++i) |
| 447 controllerImpl->add(m_activeAnimations[i]->cloneForImplThread()); |
| 448 } |
| 449 |
432 void CCLayerAnimationController::tickAnimations(double monotonicTime) | 450 void CCLayerAnimationController::tickAnimations(double monotonicTime) |
433 { | 451 { |
434 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { | 452 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
435 if (m_activeAnimations[i]->runState() == CCActiveAnimation::Running || m
_activeAnimations[i]->runState() == CCActiveAnimation::Paused) { | 453 if (m_activeAnimations[i]->runState() == CCActiveAnimation::Running || m
_activeAnimations[i]->runState() == CCActiveAnimation::Paused) { |
436 double trimmed = m_activeAnimations[i]->trimTimeToCurrentIteration(m
onotonicTime); | 454 double trimmed = m_activeAnimations[i]->trimTimeToCurrentIteration(m
onotonicTime); |
437 | 455 |
438 // Animation assumes its initial value until it gets the synchronize
d start time | 456 // Animation assumes its initial value until it gets the synchronize
d start time |
439 // from the impl thread and can start ticking. | 457 // from the impl thread and can start ticking. |
440 if (m_activeAnimations[i]->needsSynchronizedStartTime()) | 458 if (m_activeAnimations[i]->needsSynchronizedStartTime()) |
441 trimmed = 0; | 459 trimmed = 0; |
(...skipping 19 matching lines...) Expand all Loading... |
461 m_client->setOpacityFromAnimation(opacity); | 479 m_client->setOpacityFromAnimation(opacity); |
462 break; | 480 break; |
463 } | 481 } |
464 | 482 |
465 } | 483 } |
466 } | 484 } |
467 } | 485 } |
468 } | 486 } |
469 | 487 |
470 } // namespace WebCore | 488 } // namespace WebCore |
OLD | NEW |