Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: cc/layer_animation_controller.cc

Issue 11418108: cc: Make the ScopedPtrVector and ScopedPtrDeque containers act like STL vector and deque. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: android!! Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layer_animation_controller.h ('k') | cc/layer_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm>
8
7 #include "cc/animation.h" 9 #include "cc/animation.h"
8 #include "cc/animation_registrar.h" 10 #include "cc/animation_registrar.h"
9 #include "cc/keyframed_animation_curve.h" 11 #include "cc/keyframed_animation_curve.h"
10 #include "cc/layer_animation_value_observer.h" 12 #include "cc/layer_animation_value_observer.h"
13 #include "cc/scoped_ptr_algorithm.h"
11 #include "ui/gfx/transform.h" 14 #include "ui/gfx/transform.h"
12 15
13 namespace { 16 namespace {
14 gfx::Transform convertWebTransformationMatrixToTransform(const WebKit::WebTransf ormationMatrix& matrix) 17 gfx::Transform convertWebTransformationMatrixToTransform(const WebKit::WebTransf ormationMatrix& matrix)
15 { 18 {
16 gfx::Transform transform; 19 gfx::Transform transform;
17 transform.matrix().setDouble(0, 0, matrix.m11()); 20 transform.matrix().setDouble(0, 0, matrix.m11());
18 transform.matrix().setDouble(0, 1, matrix.m21()); 21 transform.matrix().setDouble(0, 1, matrix.m21());
19 transform.matrix().setDouble(0, 2, matrix.m31()); 22 transform.matrix().setDouble(0, 2, matrix.m31());
20 transform.matrix().setDouble(0, 3, matrix.m41()); 23 transform.matrix().setDouble(0, 3, matrix.m41());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } 59 }
57 60
58 void LayerAnimationController::pauseAnimation(int animationId, double timeOffset ) 61 void LayerAnimationController::pauseAnimation(int animationId, double timeOffset )
59 { 62 {
60 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { 63 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
61 if (m_activeAnimations[i]->id() == animationId) 64 if (m_activeAnimations[i]->id() == animationId)
62 m_activeAnimations[i]->setRunState(Animation::Paused, timeOffset + m _activeAnimations[i]->startTime()); 65 m_activeAnimations[i]->setRunState(Animation::Paused, timeOffset + m _activeAnimations[i]->startTime());
63 } 66 }
64 } 67 }
65 68
69 struct HasAnimationId {
70 HasAnimationId(int id) : m_id(id) { }
71 bool operator()(Animation* animation) const { return animation->id() == m_id ; }
72 private:
73 int m_id;
74 };
75
66 void LayerAnimationController::removeAnimation(int animationId) 76 void LayerAnimationController::removeAnimation(int animationId)
67 { 77 {
68 for (size_t i = 0; i < m_activeAnimations.size();) { 78 ScopedPtrVector<Animation>& animations = m_activeAnimations;
69 if (m_activeAnimations[i]->id() == animationId) 79 animations.erase(cc::remove_if(animations, animations.begin(), animations.en d(), HasAnimationId(animationId)), animations.end());
70 m_activeAnimations.remove(i);
71 else
72 i++;
73 }
74 updateActivation(); 80 updateActivation();
75 } 81 }
76 82
83 struct HasAnimationIdAndProperty {
84 HasAnimationIdAndProperty(int id, Animation::TargetProperty targetProperty) : m_id(id), m_targetProperty(targetProperty) { }
85 bool operator()(Animation* animation) const { return animation->id() == m_id && animation->targetProperty() == m_targetProperty; }
86 private:
87 int m_id;
88 Animation::TargetProperty m_targetProperty;
89 };
90
77 void LayerAnimationController::removeAnimation(int animationId, Animation::Targe tProperty targetProperty) 91 void LayerAnimationController::removeAnimation(int animationId, Animation::Targe tProperty targetProperty)
78 { 92 {
79 for (size_t i = 0; i < m_activeAnimations.size();) { 93 ScopedPtrVector<Animation>& animations = m_activeAnimations;
80 if (m_activeAnimations[i]->id() == animationId && m_activeAnimations[i]- >targetProperty() == targetProperty) 94 animations.erase(cc::remove_if(animations, animations.begin(), animations.en d(), HasAnimationIdAndProperty(animationId, targetProperty)), animations.end());
81 m_activeAnimations.remove(i);
82 else
83 i++;
84 }
85 updateActivation(); 95 updateActivation();
86 } 96 }
87 97
88 // According to render layer backing, these are for testing only. 98 // According to render layer backing, these are for testing only.
89 void LayerAnimationController::suspendAnimations(double monotonicTime) 99 void LayerAnimationController::suspendAnimations(double monotonicTime)
90 { 100 {
91 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { 101 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
92 if (!m_activeAnimations[i]->isFinished()) 102 if (!m_activeAnimations[i]->isFinished())
93 m_activeAnimations[i]->setRunState(Animation::Paused, monotonicTime) ; 103 m_activeAnimations[i]->setRunState(Animation::Paused, monotonicTime) ;
94 } 104 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 resolveConflicts(monotonicTime); 146 resolveConflicts(monotonicTime);
137 tickAnimations(monotonicTime); 147 tickAnimations(monotonicTime);
138 markAnimationsForDeletion(monotonicTime, events); 148 markAnimationsForDeletion(monotonicTime, events);
139 startAnimationsWaitingForTargetAvailability(monotonicTime, events); 149 startAnimationsWaitingForTargetAvailability(monotonicTime, events);
140 150
141 updateActivation(); 151 updateActivation();
142 } 152 }
143 153
144 void LayerAnimationController::addAnimation(scoped_ptr<Animation> animation) 154 void LayerAnimationController::addAnimation(scoped_ptr<Animation> animation)
145 { 155 {
146 m_activeAnimations.append(animation.Pass()); 156 m_activeAnimations.push_back(animation.Pass());
147 updateActivation(); 157 updateActivation();
148 } 158 }
149 159
150 Animation* LayerAnimationController::getAnimation(int groupId, Animation::Target Property targetProperty) const 160 Animation* LayerAnimationController::getAnimation(int groupId, Animation::Target Property targetProperty) const
151 { 161 {
152 for (size_t i = 0; i < m_activeAnimations.size(); ++i) 162 for (size_t i = 0; i < m_activeAnimations.size(); ++i)
153 if (m_activeAnimations[i]->group() == groupId && m_activeAnimations[i]-> targetProperty() == targetProperty) 163 if (m_activeAnimations[i]->group() == groupId && m_activeAnimations[i]-> targetProperty() == targetProperty)
154 return m_activeAnimations[i]; 164 return m_activeAnimations[i];
155 return 0; 165 return 0;
156 } 166 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 248
239 // The new animation should be set to run as soon as possible. 249 // The new animation should be set to run as soon as possible.
240 Animation::RunState initialRunState = Animation::WaitingForTargetAvailab ility; 250 Animation::RunState initialRunState = Animation::WaitingForTargetAvailab ility;
241 double startTime = 0; 251 double startTime = 0;
242 scoped_ptr<Animation> toAdd(m_activeAnimations[i]->cloneAndInitialize(An imation::ControllingInstance, initialRunState, startTime)); 252 scoped_ptr<Animation> toAdd(m_activeAnimations[i]->cloneAndInitialize(An imation::ControllingInstance, initialRunState, startTime));
243 DCHECK(!toAdd->needsSynchronizedStartTime()); 253 DCHECK(!toAdd->needsSynchronizedStartTime());
244 controllerImpl->addAnimation(toAdd.Pass()); 254 controllerImpl->addAnimation(toAdd.Pass());
245 } 255 }
246 } 256 }
247 257
258 struct IsCompleted {
259 IsCompleted(const LayerAnimationController& mainThreadController) : m_mainTh readController(mainThreadController) { }
260 bool operator()(Animation* animation) const { return !m_mainThreadController .getAnimation(animation->group(), animation->targetProperty()); }
261 private:
262 const LayerAnimationController& m_mainThreadController;
263 };
264
248 void LayerAnimationController::removeAnimationsCompletedOnMainThread(LayerAnimat ionController* controllerImpl) const 265 void LayerAnimationController::removeAnimationsCompletedOnMainThread(LayerAnimat ionController* controllerImpl) const
249 { 266 {
250 // Delete all impl thread animations for which there is no corresponding mai n thread animation. 267 // Delete all impl thread animations for which there is no corresponding mai n thread animation.
251 // Each iteration, controller->m_activeAnimations.size() is decremented or i is incremented 268 // Each iteration, controller->m_activeAnimations.size() is decremented or i is incremented
252 // guaranteeing progress towards loop termination. 269 // guaranteeing progress towards loop termination.
253 for (size_t i = 0; i < controllerImpl->m_activeAnimations.size();) { 270 ScopedPtrVector<Animation>& animations = controllerImpl->m_activeAnimations;
254 Animation* current = getAnimation(controllerImpl->m_activeAnimations[i]- >group(), controllerImpl->m_activeAnimations[i]->targetProperty()); 271 animations.erase(cc::remove_if(animations, animations.begin(), animations.en d(), IsCompleted(*this)), animations.end());
255 if (!current)
256 controllerImpl->m_activeAnimations.remove(i);
257 else
258 i++;
259 }
260 } 272 }
261 273
262 void LayerAnimationController::pushPropertiesToImplThread(LayerAnimationControll er* controllerImpl) const 274 void LayerAnimationController::pushPropertiesToImplThread(LayerAnimationControll er* controllerImpl) const
263 { 275 {
264 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { 276 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
265 Animation* currentImpl = controllerImpl->getAnimation(m_activeAnimations [i]->group(), m_activeAnimations[i]->targetProperty()); 277 Animation* currentImpl = controllerImpl->getAnimation(m_activeAnimations [i]->group(), m_activeAnimations[i]->targetProperty());
266 if (currentImpl) 278 if (currentImpl)
267 m_activeAnimations[i]->pushPropertiesTo(currentImpl); 279 m_activeAnimations[i]->pushPropertiesTo(currentImpl);
268 } 280 }
269 } 281 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 if (groupId == m_activeAnimations[j]->group()) { 395 if (groupId == m_activeAnimations[j]->group()) {
384 if (events) 396 if (events)
385 events->push_back(AnimationEvent(AnimationEvent::Finishe d, m_id, m_activeAnimations[j]->group(), m_activeAnimations[j]->targetProperty() , monotonicTime)); 397 events->push_back(AnimationEvent(AnimationEvent::Finishe d, m_id, m_activeAnimations[j]->group(), m_activeAnimations[j]->targetProperty() , monotonicTime));
386 m_activeAnimations[j]->setRunState(Animation::WaitingForDele tion, monotonicTime); 398 m_activeAnimations[j]->setRunState(Animation::WaitingForDele tion, monotonicTime);
387 } 399 }
388 } 400 }
389 } 401 }
390 } 402 }
391 } 403 }
392 404
405 static bool isWaitingForDeletion(Animation* animation) { return animation->runSt ate() == Animation::WaitingForDeletion; }
406
393 void LayerAnimationController::purgeAnimationsMarkedForDeletion() 407 void LayerAnimationController::purgeAnimationsMarkedForDeletion()
394 { 408 {
395 for (size_t i = 0; i < m_activeAnimations.size();) { 409 ScopedPtrVector<Animation>& animations = m_activeAnimations;
396 if (m_activeAnimations[i]->runState() == Animation::WaitingForDeletion) 410 animations.erase(cc::remove_if(animations, animations.begin(), animations.en d(), isWaitingForDeletion), animations.end());
397 m_activeAnimations.remove(i);
398 else
399 i++;
400 }
401 } 411 }
402 412
403 void LayerAnimationController::replaceImplThreadAnimations(LayerAnimationControl ler* controllerImpl) const 413 void LayerAnimationController::replaceImplThreadAnimations(LayerAnimationControl ler* controllerImpl) const
404 { 414 {
405 controllerImpl->m_activeAnimations.clear(); 415 controllerImpl->m_activeAnimations.clear();
406 for (size_t i = 0; i < m_activeAnimations.size(); ++i) { 416 for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
407 scoped_ptr<Animation> toAdd; 417 scoped_ptr<Animation> toAdd;
408 if (m_activeAnimations[i]->needsSynchronizedStartTime()) { 418 if (m_activeAnimations[i]->needsSynchronizedStartTime()) {
409 // We haven't received an animation started notification yet, so it 419 // We haven't received an animation started notification yet, so it
410 // is important that we add it in a 'waiting' and not 'running' stat e. 420 // is important that we add it in a 'waiting' and not 'running' stat e.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 case Animation::TargetPropertyEnumSize: 465 case Animation::TargetPropertyEnumSize:
456 NOTREACHED(); 466 NOTREACHED();
457 } 467 }
458 } 468 }
459 } 469 }
460 } 470 }
461 471
462 void LayerAnimationController::updateActivation(bool force) 472 void LayerAnimationController::updateActivation(bool force)
463 { 473 {
464 if (m_registrar) { 474 if (m_registrar) {
465 if (!m_activeAnimations.isEmpty() && (!m_isActive || force)) 475 if (!m_activeAnimations.empty() && (!m_isActive || force))
466 m_registrar->DidActivateAnimationController(this); 476 m_registrar->DidActivateAnimationController(this);
467 else if (m_activeAnimations.isEmpty() && (m_isActive || force)) 477 else if (m_activeAnimations.empty() && (m_isActive || force))
468 m_registrar->DidDeactivateAnimationController(this); 478 m_registrar->DidDeactivateAnimationController(this);
469 m_isActive = !m_activeAnimations.isEmpty(); 479 m_isActive = !m_activeAnimations.empty();
470 } 480 }
471 } 481 }
472 482
473 void LayerAnimationController::notifyObserversOpacityAnimated(float opacity) 483 void LayerAnimationController::notifyObserversOpacityAnimated(float opacity)
474 { 484 {
475 FOR_EACH_OBSERVER(LayerAnimationValueObserver, 485 FOR_EACH_OBSERVER(LayerAnimationValueObserver,
476 m_observers, 486 m_observers,
477 OnOpacityAnimated(opacity)); 487 OnOpacityAnimated(opacity));
478 } 488 }
479 489
(...skipping 10 matching lines...) Expand all
490 ObserverListBase<LayerAnimationValueObserver>::Iterator it(m_observers); 500 ObserverListBase<LayerAnimationValueObserver>::Iterator it(m_observers);
491 LayerAnimationValueObserver* obs; 501 LayerAnimationValueObserver* obs;
492 while ((obs = it.GetNext()) != NULL) 502 while ((obs = it.GetNext()) != NULL)
493 if (obs->IsActive()) 503 if (obs->IsActive())
494 return true; 504 return true;
495 } 505 }
496 return false; 506 return false;
497 } 507 }
498 508
499 } // namespace cc 509 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer_animation_controller.h ('k') | cc/layer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698