| 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/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" |
| 11 #include "cc/animation/animation_delegate.h" | 11 #include "cc/animation/animation_delegate.h" |
| 12 #include "cc/animation/animation_registrar.h" | 12 #include "cc/animation/animation_registrar.h" |
| 13 #include "cc/animation/keyframed_animation_curve.h" | 13 #include "cc/animation/keyframed_animation_curve.h" |
| 14 #include "cc/animation/layer_animation_value_observer.h" | 14 #include "cc/animation/layer_animation_value_observer.h" |
| 15 #include "cc/animation/layer_animation_value_provider.h" | 15 #include "cc/animation/layer_animation_value_provider.h" |
| 16 #include "cc/animation/scroll_offset_animation_curve.h" | 16 #include "cc/animation/scroll_offset_animation_curve.h" |
| 17 #include "cc/base/scoped_ptr_algorithm.h" | 17 #include "cc/base/scoped_ptr_algorithm.h" |
| 18 #include "cc/output/filter_operations.h" | 18 #include "cc/output/filter_operations.h" |
| 19 #include "ui/gfx/geometry/box_f.h" | 19 #include "ui/gfx/geometry/box_f.h" |
| 20 #include "ui/gfx/transform.h" | 20 #include "ui/gfx/transform.h" |
| 21 | 21 |
| 22 namespace cc { | 22 namespace cc { |
| 23 | 23 |
| 24 LayerAnimationController::LayerAnimationController(int id) | 24 LayerAnimationController::LayerAnimationController(int id) |
| 25 : registrar_(0), | 25 : registrar_(0), |
| 26 id_(id), | 26 id_(id), |
| 27 is_active_(false), | 27 is_active_(false), |
| 28 value_provider_(nullptr), | 28 value_provider_(nullptr), |
| 29 layer_animation_delegate_(nullptr), | 29 layer_animation_delegate_(nullptr), |
| 30 needs_to_start_animations_(false) { | 30 needs_to_start_animations_(false), |
| 31 scroll_offset_animation_was_interrupted_(false) { |
| 31 } | 32 } |
| 32 | 33 |
| 33 LayerAnimationController::~LayerAnimationController() { | 34 LayerAnimationController::~LayerAnimationController() { |
| 34 if (registrar_) | 35 if (registrar_) |
| 35 registrar_->UnregisterAnimationController(this); | 36 registrar_->UnregisterAnimationController(this); |
| 36 } | 37 } |
| 37 | 38 |
| 38 scoped_refptr<LayerAnimationController> LayerAnimationController::Create( | 39 scoped_refptr<LayerAnimationController> LayerAnimationController::Create( |
| 39 int id) { | 40 int id) { |
| 40 return make_scoped_refptr(new LayerAnimationController(id)); | 41 return make_scoped_refptr(new LayerAnimationController(id)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 58 | 59 |
| 59 private: | 60 private: |
| 60 int id_; | 61 int id_; |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 void LayerAnimationController::RemoveAnimation(int animation_id) { | 64 void LayerAnimationController::RemoveAnimation(int animation_id) { |
| 64 auto animations_to_remove = | 65 auto animations_to_remove = |
| 65 animations_.remove_if(HasAnimationId(animation_id)); | 66 animations_.remove_if(HasAnimationId(animation_id)); |
| 66 for (auto it = animations_to_remove; it != animations_.end(); ++it) { | 67 for (auto it = animations_to_remove; it != animations_.end(); ++it) { |
| 67 if ((*it)->target_property() == Animation::ScrollOffset) { | 68 if ((*it)->target_property() == Animation::ScrollOffset) { |
| 68 NotifyObserversScrollOffsetAnimationRemoved(); | 69 scroll_offset_animation_was_interrupted_ = true; |
| 69 break; | 70 break; |
| 70 } | 71 } |
| 71 } | 72 } |
| 72 animations_.erase(animations_to_remove, animations_.end()); | 73 animations_.erase(animations_to_remove, animations_.end()); |
| 73 UpdateActivation(NormalActivation); | 74 UpdateActivation(NormalActivation); |
| 74 } | 75 } |
| 75 | 76 |
| 76 struct HasAnimationIdAndProperty { | 77 struct HasAnimationIdAndProperty { |
| 77 HasAnimationIdAndProperty(int id, Animation::TargetProperty target_property) | 78 HasAnimationIdAndProperty(int id, Animation::TargetProperty target_property) |
| 78 : id_(id), target_property_(target_property) {} | 79 : id_(id), target_property_(target_property) {} |
| 79 bool operator()(Animation* animation) const { | 80 bool operator()(Animation* animation) const { |
| 80 return animation->id() == id_ && | 81 return animation->id() == id_ && |
| 81 animation->target_property() == target_property_; | 82 animation->target_property() == target_property_; |
| 82 } | 83 } |
| 83 | 84 |
| 84 private: | 85 private: |
| 85 int id_; | 86 int id_; |
| 86 Animation::TargetProperty target_property_; | 87 Animation::TargetProperty target_property_; |
| 87 }; | 88 }; |
| 88 | 89 |
| 89 void LayerAnimationController::RemoveAnimation( | 90 void LayerAnimationController::RemoveAnimation( |
| 90 int animation_id, | 91 int animation_id, |
| 91 Animation::TargetProperty target_property) { | 92 Animation::TargetProperty target_property) { |
| 92 auto animations_to_remove = animations_.remove_if( | 93 auto animations_to_remove = animations_.remove_if( |
| 93 HasAnimationIdAndProperty(animation_id, target_property)); | 94 HasAnimationIdAndProperty(animation_id, target_property)); |
| 94 if (target_property == Animation::ScrollOffset && | 95 if (target_property == Animation::ScrollOffset && |
| 95 animations_to_remove != animations_.end()) | 96 animations_to_remove != animations_.end()) |
| 96 NotifyObserversScrollOffsetAnimationRemoved(); | 97 scroll_offset_animation_was_interrupted_ = true; |
| 97 | 98 |
| 98 animations_.erase(animations_to_remove, animations_.end()); | 99 animations_.erase(animations_to_remove, animations_.end()); |
| 99 UpdateActivation(NormalActivation); | 100 UpdateActivation(NormalActivation); |
| 100 } | 101 } |
| 101 | 102 |
| 102 void LayerAnimationController::AbortAnimations( | 103 void LayerAnimationController::AbortAnimations( |
| 103 Animation::TargetProperty target_property) { | 104 Animation::TargetProperty target_property) { |
| 104 for (size_t i = 0; i < animations_.size(); ++i) { | 105 for (size_t i = 0; i < animations_.size(); ++i) { |
| 105 if (animations_[i]->target_property() == target_property && | 106 if (animations_[i]->target_property() == target_property && |
| 106 !animations_[i]->is_finished()) | 107 !animations_[i]->is_finished()) |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 void LayerAnimationController::ActivateAnimations() { | 250 void LayerAnimationController::ActivateAnimations() { |
| 250 for (size_t i = 0; i < animations_.size(); ++i) { | 251 for (size_t i = 0; i < animations_.size(); ++i) { |
| 251 animations_[i]->set_affects_active_observers( | 252 animations_[i]->set_affects_active_observers( |
| 252 animations_[i]->affects_pending_observers()); | 253 animations_[i]->affects_pending_observers()); |
| 253 } | 254 } |
| 254 animations_.erase(cc::remove_if(&animations_, | 255 animations_.erase(cc::remove_if(&animations_, |
| 255 animations_.begin(), | 256 animations_.begin(), |
| 256 animations_.end(), | 257 animations_.end(), |
| 257 AffectsNoObservers()), | 258 AffectsNoObservers()), |
| 258 animations_.end()); | 259 animations_.end()); |
| 260 scroll_offset_animation_was_interrupted_ = false; |
| 259 UpdateActivation(NormalActivation); | 261 UpdateActivation(NormalActivation); |
| 260 } | 262 } |
| 261 | 263 |
| 262 void LayerAnimationController::AddAnimation(scoped_ptr<Animation> animation) { | 264 void LayerAnimationController::AddAnimation(scoped_ptr<Animation> animation) { |
| 263 animations_.push_back(animation.Pass()); | 265 animations_.push_back(animation.Pass()); |
| 264 needs_to_start_animations_ = true; | 266 needs_to_start_animations_ = true; |
| 265 UpdateActivation(NormalActivation); | 267 UpdateActivation(NormalActivation); |
| 266 } | 268 } |
| 267 | 269 |
| 268 Animation* LayerAnimationController::GetAnimation( | 270 Animation* LayerAnimationController::GetAnimation( |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 animations[i]->set_affects_pending_observers(false); | 623 animations[i]->set_affects_pending_observers(false); |
| 622 } | 624 } |
| 623 animations.erase(cc::remove_if(&animations, | 625 animations.erase(cc::remove_if(&animations, |
| 624 animations.begin(), | 626 animations.begin(), |
| 625 animations.end(), | 627 animations.end(), |
| 626 AffectsActiveOnlyAndIsWaitingForDeletion), | 628 AffectsActiveOnlyAndIsWaitingForDeletion), |
| 627 animations.end()); | 629 animations.end()); |
| 628 } | 630 } |
| 629 | 631 |
| 630 void LayerAnimationController::PushPropertiesToImplThread( | 632 void LayerAnimationController::PushPropertiesToImplThread( |
| 631 LayerAnimationController* controller_impl) const { | 633 LayerAnimationController* controller_impl) { |
| 632 for (size_t i = 0; i < animations_.size(); ++i) { | 634 for (size_t i = 0; i < animations_.size(); ++i) { |
| 633 Animation* current_impl = | 635 Animation* current_impl = |
| 634 controller_impl->GetAnimationById(animations_[i]->id()); | 636 controller_impl->GetAnimationById(animations_[i]->id()); |
| 635 if (current_impl) | 637 if (current_impl) |
| 636 animations_[i]->PushPropertiesTo(current_impl); | 638 animations_[i]->PushPropertiesTo(current_impl); |
| 637 } | 639 } |
| 640 controller_impl->scroll_offset_animation_was_interrupted_ = |
| 641 scroll_offset_animation_was_interrupted_; |
| 642 scroll_offset_animation_was_interrupted_ = false; |
| 638 } | 643 } |
| 639 | 644 |
| 640 void LayerAnimationController::StartAnimations(base::TimeTicks monotonic_time) { | 645 void LayerAnimationController::StartAnimations(base::TimeTicks monotonic_time) { |
| 641 DCHECK(needs_to_start_animations_); | 646 DCHECK(needs_to_start_animations_); |
| 642 needs_to_start_animations_ = false; | 647 needs_to_start_animations_ = false; |
| 643 // First collect running properties affecting each type of observer. | 648 // First collect running properties affecting each type of observer. |
| 644 TargetProperties blocked_properties_for_active_observers; | 649 TargetProperties blocked_properties_for_active_observers; |
| 645 TargetProperties blocked_properties_for_pending_observers; | 650 TargetProperties blocked_properties_for_pending_observers; |
| 646 std::vector<size_t> animations_waiting_for_target; | 651 std::vector<size_t> animations_waiting_for_target; |
| 647 | 652 |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1027 } | 1032 } |
| 1028 } | 1033 } |
| 1029 } | 1034 } |
| 1030 | 1035 |
| 1031 void LayerAnimationController::NotifyObserversAnimationWaitingForDeletion() { | 1036 void LayerAnimationController::NotifyObserversAnimationWaitingForDeletion() { |
| 1032 FOR_EACH_OBSERVER(LayerAnimationValueObserver, | 1037 FOR_EACH_OBSERVER(LayerAnimationValueObserver, |
| 1033 value_observers_, | 1038 value_observers_, |
| 1034 OnAnimationWaitingForDeletion()); | 1039 OnAnimationWaitingForDeletion()); |
| 1035 } | 1040 } |
| 1036 | 1041 |
| 1037 void LayerAnimationController::NotifyObserversScrollOffsetAnimationRemoved() { | |
| 1038 FOR_EACH_OBSERVER(LayerAnimationValueObserver, value_observers_, | |
| 1039 OnScrollOffsetAnimationRemoved()); | |
| 1040 } | |
| 1041 | |
| 1042 bool LayerAnimationController::HasValueObserver() { | 1042 bool LayerAnimationController::HasValueObserver() { |
| 1043 if (value_observers_.might_have_observers()) { | 1043 if (value_observers_.might_have_observers()) { |
| 1044 ObserverListBase<LayerAnimationValueObserver>::Iterator it( | 1044 ObserverListBase<LayerAnimationValueObserver>::Iterator it( |
| 1045 value_observers_); | 1045 value_observers_); |
| 1046 return it.GetNext() != nullptr; | 1046 return it.GetNext() != nullptr; |
| 1047 } | 1047 } |
| 1048 return false; | 1048 return false; |
| 1049 } | 1049 } |
| 1050 | 1050 |
| 1051 bool LayerAnimationController::HasActiveValueObserver() { | 1051 bool LayerAnimationController::HasActiveValueObserver() { |
| 1052 if (value_observers_.might_have_observers()) { | 1052 if (value_observers_.might_have_observers()) { |
| 1053 ObserverListBase<LayerAnimationValueObserver>::Iterator it( | 1053 ObserverListBase<LayerAnimationValueObserver>::Iterator it( |
| 1054 value_observers_); | 1054 value_observers_); |
| 1055 LayerAnimationValueObserver* obs; | 1055 LayerAnimationValueObserver* obs; |
| 1056 while ((obs = it.GetNext()) != nullptr) | 1056 while ((obs = it.GetNext()) != nullptr) |
| 1057 if (obs->IsActive()) | 1057 if (obs->IsActive()) |
| 1058 return true; | 1058 return true; |
| 1059 } | 1059 } |
| 1060 return false; | 1060 return false; |
| 1061 } | 1061 } |
| 1062 | 1062 |
| 1063 } // namespace cc | 1063 } // namespace cc |
| OLD | NEW |