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

Side by Side Diff: cc/animation/layer_animation_controller.cc

Issue 862133002: Update from https://crrev.com/312398 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
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/animation/layer_animation_controller.h" 5 #include "cc/animation/layer_animation_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "cc/animation/animation.h" 10 #include "cc/animation/animation.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 explicit HasAnimationId(int id) : id_(id) {} 54 explicit HasAnimationId(int id) : id_(id) {}
55 bool operator()(Animation* animation) const { 55 bool operator()(Animation* animation) const {
56 return animation->id() == id_; 56 return animation->id() == id_;
57 } 57 }
58 58
59 private: 59 private:
60 int id_; 60 int id_;
61 }; 61 };
62 62
63 void LayerAnimationController::RemoveAnimation(int animation_id) { 63 void LayerAnimationController::RemoveAnimation(int animation_id) {
64 animations_.erase(cc::remove_if(&animations_, 64 auto animations_to_remove =
65 animations_.begin(), 65 animations_.remove_if(HasAnimationId(animation_id));
66 animations_.end(), 66 for (auto it = animations_to_remove; it != animations_.end(); ++it) {
67 HasAnimationId(animation_id)), 67 if ((*it)->target_property() == Animation::ScrollOffset) {
68 animations_.end()); 68 NotifyObserversScrollOffsetAnimationRemoved();
69 break;
70 }
71 }
72 animations_.erase(animations_to_remove, animations_.end());
69 UpdateActivation(NormalActivation); 73 UpdateActivation(NormalActivation);
70 } 74 }
71 75
72 struct HasAnimationIdAndProperty { 76 struct HasAnimationIdAndProperty {
73 HasAnimationIdAndProperty(int id, Animation::TargetProperty target_property) 77 HasAnimationIdAndProperty(int id, Animation::TargetProperty target_property)
74 : id_(id), target_property_(target_property) {} 78 : id_(id), target_property_(target_property) {}
75 bool operator()(Animation* animation) const { 79 bool operator()(Animation* animation) const {
76 return animation->id() == id_ && 80 return animation->id() == id_ &&
77 animation->target_property() == target_property_; 81 animation->target_property() == target_property_;
78 } 82 }
79 83
80 private: 84 private:
81 int id_; 85 int id_;
82 Animation::TargetProperty target_property_; 86 Animation::TargetProperty target_property_;
83 }; 87 };
84 88
85 void LayerAnimationController::RemoveAnimation( 89 void LayerAnimationController::RemoveAnimation(
86 int animation_id, 90 int animation_id,
87 Animation::TargetProperty target_property) { 91 Animation::TargetProperty target_property) {
88 animations_.erase( 92 auto animations_to_remove = animations_.remove_if(
89 cc::remove_if(&animations_, 93 HasAnimationIdAndProperty(animation_id, target_property));
90 animations_.begin(), 94 if (target_property == Animation::ScrollOffset &&
91 animations_.end(), 95 animations_to_remove != animations_.end())
92 HasAnimationIdAndProperty(animation_id, target_property)), 96 NotifyObserversScrollOffsetAnimationRemoved();
93 animations_.end()); 97
98 animations_.erase(animations_to_remove, animations_.end());
94 UpdateActivation(NormalActivation); 99 UpdateActivation(NormalActivation);
95 } 100 }
96 101
97 void LayerAnimationController::AbortAnimations( 102 void LayerAnimationController::AbortAnimations(
98 Animation::TargetProperty target_property) { 103 Animation::TargetProperty target_property) {
99 for (size_t i = 0; i < animations_.size(); ++i) { 104 for (size_t i = 0; i < animations_.size(); ++i) {
100 if (animations_[i]->target_property() == target_property && 105 if (animations_[i]->target_property() == target_property &&
101 !animations_[i]->is_finished()) 106 !animations_[i]->is_finished())
102 animations_[i]->SetRunState(Animation::Aborted, last_tick_time_); 107 animations_[i]->SetRunState(Animation::Aborted, last_tick_time_);
103 } 108 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 UpdateActivation(NormalActivation); 259 UpdateActivation(NormalActivation);
255 } 260 }
256 261
257 void LayerAnimationController::AddAnimation(scoped_ptr<Animation> animation) { 262 void LayerAnimationController::AddAnimation(scoped_ptr<Animation> animation) {
258 animations_.push_back(animation.Pass()); 263 animations_.push_back(animation.Pass());
259 needs_to_start_animations_ = true; 264 needs_to_start_animations_ = true;
260 UpdateActivation(NormalActivation); 265 UpdateActivation(NormalActivation);
261 } 266 }
262 267
263 Animation* LayerAnimationController::GetAnimation( 268 Animation* LayerAnimationController::GetAnimation(
264 int group_id,
265 Animation::TargetProperty target_property) const {
266 for (size_t i = 0; i < animations_.size(); ++i)
267 if (animations_[i]->group() == group_id &&
268 animations_[i]->target_property() == target_property)
269 return animations_[i];
270 return 0;
271 }
272
273 Animation* LayerAnimationController::GetAnimation(
274 Animation::TargetProperty target_property) const { 269 Animation::TargetProperty target_property) const {
275 for (size_t i = 0; i < animations_.size(); ++i) { 270 for (size_t i = 0; i < animations_.size(); ++i) {
276 size_t index = animations_.size() - i - 1; 271 size_t index = animations_.size() - i - 1;
277 if (animations_[index]->target_property() == target_property) 272 if (animations_[index]->target_property() == target_property)
278 return animations_[index]; 273 return animations_[index];
279 } 274 }
280 return 0; 275 return 0;
281 } 276 }
282 277
278 Animation* LayerAnimationController::GetAnimationById(int animation_id) const {
279 for (size_t i = 0; i < animations_.size(); ++i)
280 if (animations_[i]->id() == animation_id)
281 return animations_[i];
282 return nullptr;
283 }
284
283 bool LayerAnimationController::HasActiveAnimation() const { 285 bool LayerAnimationController::HasActiveAnimation() const {
284 for (size_t i = 0; i < animations_.size(); ++i) { 286 for (size_t i = 0; i < animations_.size(); ++i) {
285 if (!animations_[i]->is_finished()) 287 if (!animations_[i]->is_finished())
286 return true; 288 return true;
287 } 289 }
288 return false; 290 return false;
289 } 291 }
290 292
291 bool LayerAnimationController::IsAnimatingProperty( 293 bool LayerAnimationController::IsAnimatingProperty(
292 Animation::TargetProperty target_property) const { 294 Animation::TargetProperty target_property) const {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 return true; 549 return true;
548 } 550 }
549 551
550 void LayerAnimationController::PushNewAnimationsToImplThread( 552 void LayerAnimationController::PushNewAnimationsToImplThread(
551 LayerAnimationController* controller_impl) const { 553 LayerAnimationController* controller_impl) const {
552 // Any new animations owned by the main thread's controller are cloned and 554 // Any new animations owned by the main thread's controller are cloned and
553 // add to the impl thread's controller. 555 // add to the impl thread's controller.
554 for (size_t i = 0; i < animations_.size(); ++i) { 556 for (size_t i = 0; i < animations_.size(); ++i) {
555 // If the animation is already running on the impl thread, there is no 557 // If the animation is already running on the impl thread, there is no
556 // need to copy it over. 558 // need to copy it over.
557 if (controller_impl->GetAnimation(animations_[i]->group(), 559 if (controller_impl->GetAnimationById(animations_[i]->id()))
558 animations_[i]->target_property()))
559 continue; 560 continue;
560 561
561 // If the animation is not running on the impl thread, it does not 562 // If the animation is not running on the impl thread, it does not
562 // necessarily mean that it needs to be copied over and started; it may 563 // necessarily mean that it needs to be copied over and started; it may
563 // have already finished. In this case, the impl thread animation will 564 // have already finished. In this case, the impl thread animation will
564 // have already notified that it has started and the main thread animation 565 // have already notified that it has started and the main thread animation
565 // will no longer need 566 // will no longer need
566 // a synchronized start time. 567 // a synchronized start time.
567 if (!animations_[i]->needs_synchronized_start_time()) 568 if (!animations_[i]->needs_synchronized_start_time())
568 continue; 569 continue;
(...skipping 23 matching lines...) Expand all
592 controller_impl->AddAnimation(to_add.Pass()); 593 controller_impl->AddAnimation(to_add.Pass());
593 } 594 }
594 } 595 }
595 596
596 static bool IsCompleted( 597 static bool IsCompleted(
597 Animation* animation, 598 Animation* animation,
598 const LayerAnimationController* main_thread_controller) { 599 const LayerAnimationController* main_thread_controller) {
599 if (animation->is_impl_only()) { 600 if (animation->is_impl_only()) {
600 return (animation->run_state() == Animation::WaitingForDeletion); 601 return (animation->run_state() == Animation::WaitingForDeletion);
601 } else { 602 } else {
602 return !main_thread_controller->GetAnimation(animation->group(), 603 return !main_thread_controller->GetAnimationById(animation->id());
603 animation->target_property());
604 } 604 }
605 } 605 }
606 606
607 static bool AffectsActiveOnlyAndIsWaitingForDeletion(Animation* animation) { 607 static bool AffectsActiveOnlyAndIsWaitingForDeletion(Animation* animation) {
608 return animation->run_state() == Animation::WaitingForDeletion && 608 return animation->run_state() == Animation::WaitingForDeletion &&
609 !animation->affects_pending_observers(); 609 !animation->affects_pending_observers();
610 } 610 }
611 611
612 void LayerAnimationController::RemoveAnimationsCompletedOnMainThread( 612 void LayerAnimationController::RemoveAnimationsCompletedOnMainThread(
613 LayerAnimationController* controller_impl) const { 613 LayerAnimationController* controller_impl) const {
614 // Animations removed on the main thread should no longer affect pending 614 // Animations removed on the main thread should no longer affect pending
615 // observers, and should stop affecting active observers after the next call 615 // observers, and should stop affecting active observers after the next call
616 // to ActivateAnimations. If already WaitingForDeletion, they can be removed 616 // to ActivateAnimations. If already WaitingForDeletion, they can be removed
617 // immediately. 617 // immediately.
618 ScopedPtrVector<Animation>& animations = controller_impl->animations_; 618 ScopedPtrVector<Animation>& animations = controller_impl->animations_;
619 for (size_t i = 0; i < animations.size(); ++i) { 619 for (size_t i = 0; i < animations.size(); ++i) {
620 if (IsCompleted(animations[i], this)) 620 if (IsCompleted(animations[i], this))
621 animations[i]->set_affects_pending_observers(false); 621 animations[i]->set_affects_pending_observers(false);
622 } 622 }
623 animations.erase(cc::remove_if(&animations, 623 animations.erase(cc::remove_if(&animations,
624 animations.begin(), 624 animations.begin(),
625 animations.end(), 625 animations.end(),
626 AffectsActiveOnlyAndIsWaitingForDeletion), 626 AffectsActiveOnlyAndIsWaitingForDeletion),
627 animations.end()); 627 animations.end());
628 } 628 }
629 629
630 void LayerAnimationController::PushPropertiesToImplThread( 630 void LayerAnimationController::PushPropertiesToImplThread(
631 LayerAnimationController* controller_impl) const { 631 LayerAnimationController* controller_impl) const {
632 for (size_t i = 0; i < animations_.size(); ++i) { 632 for (size_t i = 0; i < animations_.size(); ++i) {
633 Animation* current_impl = controller_impl->GetAnimation( 633 Animation* current_impl =
634 animations_[i]->group(), animations_[i]->target_property()); 634 controller_impl->GetAnimationById(animations_[i]->id());
635 if (current_impl) 635 if (current_impl)
636 animations_[i]->PushPropertiesTo(current_impl); 636 animations_[i]->PushPropertiesTo(current_impl);
637 } 637 }
638 } 638 }
639 639
640 void LayerAnimationController::StartAnimations(base::TimeTicks monotonic_time) { 640 void LayerAnimationController::StartAnimations(base::TimeTicks monotonic_time) {
641 DCHECK(needs_to_start_animations_); 641 DCHECK(needs_to_start_animations_);
642 needs_to_start_animations_ = false; 642 needs_to_start_animations_ = false;
643 // First collect running properties affecting each type of observer. 643 // First collect running properties affecting each type of observer.
644 TargetProperties blocked_properties_for_active_observers; 644 TargetProperties blocked_properties_for_active_observers;
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 } 1027 }
1028 } 1028 }
1029 } 1029 }
1030 1030
1031 void LayerAnimationController::NotifyObserversAnimationWaitingForDeletion() { 1031 void LayerAnimationController::NotifyObserversAnimationWaitingForDeletion() {
1032 FOR_EACH_OBSERVER(LayerAnimationValueObserver, 1032 FOR_EACH_OBSERVER(LayerAnimationValueObserver,
1033 value_observers_, 1033 value_observers_,
1034 OnAnimationWaitingForDeletion()); 1034 OnAnimationWaitingForDeletion());
1035 } 1035 }
1036 1036
1037 void LayerAnimationController::NotifyObserversScrollOffsetAnimationRemoved() {
1038 FOR_EACH_OBSERVER(LayerAnimationValueObserver, value_observers_,
1039 OnScrollOffsetAnimationRemoved());
1040 }
1041
1037 bool LayerAnimationController::HasValueObserver() { 1042 bool LayerAnimationController::HasValueObserver() {
1038 if (value_observers_.might_have_observers()) { 1043 if (value_observers_.might_have_observers()) {
1039 ObserverListBase<LayerAnimationValueObserver>::Iterator it( 1044 ObserverListBase<LayerAnimationValueObserver>::Iterator it(
1040 value_observers_); 1045 value_observers_);
1041 return it.GetNext() != nullptr; 1046 return it.GetNext() != nullptr;
1042 } 1047 }
1043 return false; 1048 return false;
1044 } 1049 }
1045 1050
1046 bool LayerAnimationController::HasActiveValueObserver() { 1051 bool LayerAnimationController::HasActiveValueObserver() {
1047 if (value_observers_.might_have_observers()) { 1052 if (value_observers_.might_have_observers()) {
1048 ObserverListBase<LayerAnimationValueObserver>::Iterator it( 1053 ObserverListBase<LayerAnimationValueObserver>::Iterator it(
1049 value_observers_); 1054 value_observers_);
1050 LayerAnimationValueObserver* obs; 1055 LayerAnimationValueObserver* obs;
1051 while ((obs = it.GetNext()) != nullptr) 1056 while ((obs = it.GetNext()) != nullptr)
1052 if (obs->IsActive()) 1057 if (obs->IsActive())
1053 return true; 1058 return true;
1054 } 1059 }
1055 return false; 1060 return false;
1056 } 1061 }
1057 1062
1058 } // namespace cc 1063 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698