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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 changed_for_active_observers, changed_for_pending_observers); | 89 changed_for_active_observers, changed_for_pending_observers); |
90 } | 90 } |
91 | 91 |
92 void LayerAnimationController::RemoveAnimation(int animation_id) { | 92 void LayerAnimationController::RemoveAnimation(int animation_id) { |
93 bool removed_transform_animation = false; | 93 bool removed_transform_animation = false; |
94 // Since we want to use the animations that we're going to remove, we need to | 94 // Since we want to use the animations that we're going to remove, we need to |
95 // use a stable_parition here instead of remove_if. Remove_if leaves the | 95 // use a stable_parition here instead of remove_if. Remove_if leaves the |
96 // removed items in an unspecified state. | 96 // removed items in an unspecified state. |
97 auto animations_to_remove = std::stable_partition( | 97 auto animations_to_remove = std::stable_partition( |
98 animations_.begin(), animations_.end(), | 98 animations_.begin(), animations_.end(), |
99 [animation_id](const scoped_ptr<Animation>& animation) { | 99 [animation_id](const std::unique_ptr<Animation>& animation) { |
100 return animation->id() != animation_id; | 100 return animation->id() != animation_id; |
101 }); | 101 }); |
102 for (auto it = animations_to_remove; it != animations_.end(); ++it) { | 102 for (auto it = animations_to_remove; it != animations_.end(); ++it) { |
103 if ((*it)->target_property() == TargetProperty::SCROLL_OFFSET) { | 103 if ((*it)->target_property() == TargetProperty::SCROLL_OFFSET) { |
104 scroll_offset_animation_was_interrupted_ = true; | 104 scroll_offset_animation_was_interrupted_ = true; |
105 } else if ((*it)->target_property() == TargetProperty::TRANSFORM && | 105 } else if ((*it)->target_property() == TargetProperty::TRANSFORM && |
106 !(*it)->is_finished()) { | 106 !(*it)->is_finished()) { |
107 removed_transform_animation = true; | 107 removed_transform_animation = true; |
108 } | 108 } |
109 } | 109 } |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 void LayerAnimationController::ActivateAnimations() { | 281 void LayerAnimationController::ActivateAnimations() { |
282 bool changed_transform_animation = false; | 282 bool changed_transform_animation = false; |
283 for (size_t i = 0; i < animations_.size(); ++i) { | 283 for (size_t i = 0; i < animations_.size(); ++i) { |
284 if (animations_[i]->affects_active_observers() != | 284 if (animations_[i]->affects_active_observers() != |
285 animations_[i]->affects_pending_observers() && | 285 animations_[i]->affects_pending_observers() && |
286 animations_[i]->target_property() == TargetProperty::TRANSFORM) | 286 animations_[i]->target_property() == TargetProperty::TRANSFORM) |
287 changed_transform_animation = true; | 287 changed_transform_animation = true; |
288 animations_[i]->set_affects_active_observers( | 288 animations_[i]->set_affects_active_observers( |
289 animations_[i]->affects_pending_observers()); | 289 animations_[i]->affects_pending_observers()); |
290 } | 290 } |
291 auto affects_no_observers = [](const scoped_ptr<Animation>& animation) { | 291 auto affects_no_observers = [](const std::unique_ptr<Animation>& animation) { |
292 return !animation->affects_active_observers() && | 292 return !animation->affects_active_observers() && |
293 !animation->affects_pending_observers(); | 293 !animation->affects_pending_observers(); |
294 }; | 294 }; |
295 animations_.erase(std::remove_if(animations_.begin(), animations_.end(), | 295 animations_.erase(std::remove_if(animations_.begin(), animations_.end(), |
296 affects_no_observers), | 296 affects_no_observers), |
297 animations_.end()); | 297 animations_.end()); |
298 scroll_offset_animation_was_interrupted_ = false; | 298 scroll_offset_animation_was_interrupted_ = false; |
299 UpdateActivation(NORMAL_ACTIVATION); | 299 UpdateActivation(NORMAL_ACTIVATION); |
300 if (changed_transform_animation) | 300 if (changed_transform_animation) |
301 UpdatePotentiallyAnimatingTransform(); | 301 UpdatePotentiallyAnimatingTransform(); |
302 } | 302 } |
303 | 303 |
304 void LayerAnimationController::AddAnimation(scoped_ptr<Animation> animation) { | 304 void LayerAnimationController::AddAnimation( |
| 305 std::unique_ptr<Animation> animation) { |
305 bool added_transform_animation = | 306 bool added_transform_animation = |
306 animation->target_property() == TargetProperty::TRANSFORM; | 307 animation->target_property() == TargetProperty::TRANSFORM; |
307 animations_.push_back(std::move(animation)); | 308 animations_.push_back(std::move(animation)); |
308 needs_to_start_animations_ = true; | 309 needs_to_start_animations_ = true; |
309 UpdateActivation(NORMAL_ACTIVATION); | 310 UpdateActivation(NORMAL_ACTIVATION); |
310 if (added_transform_animation) | 311 if (added_transform_animation) |
311 UpdatePotentiallyAnimatingTransform(); | 312 UpdatePotentiallyAnimatingTransform(); |
312 } | 313 } |
313 | 314 |
314 Animation* LayerAnimationController::GetAnimation( | 315 Animation* LayerAnimationController::GetAnimation( |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 | 434 |
434 return; | 435 return; |
435 } | 436 } |
436 } | 437 } |
437 } | 438 } |
438 | 439 |
439 void LayerAnimationController::NotifyAnimationTakeover( | 440 void LayerAnimationController::NotifyAnimationTakeover( |
440 const AnimationEvent& event) { | 441 const AnimationEvent& event) { |
441 DCHECK(event.target_property == TargetProperty::SCROLL_OFFSET); | 442 DCHECK(event.target_property == TargetProperty::SCROLL_OFFSET); |
442 if (layer_animation_delegate_) { | 443 if (layer_animation_delegate_) { |
443 scoped_ptr<AnimationCurve> animation_curve = event.curve->Clone(); | 444 std::unique_ptr<AnimationCurve> animation_curve = event.curve->Clone(); |
444 layer_animation_delegate_->NotifyAnimationTakeover( | 445 layer_animation_delegate_->NotifyAnimationTakeover( |
445 event.monotonic_time, event.target_property, event.animation_start_time, | 446 event.monotonic_time, event.target_property, event.animation_start_time, |
446 std::move(animation_curve)); | 447 std::move(animation_curve)); |
447 } | 448 } |
448 } | 449 } |
449 | 450 |
450 void LayerAnimationController::NotifyAnimationAborted( | 451 void LayerAnimationController::NotifyAnimationAborted( |
451 const AnimationEvent& event) { | 452 const AnimationEvent& event) { |
452 bool aborted_transform_animation = false; | 453 bool aborted_transform_animation = false; |
453 for (size_t i = 0; i < animations_.size(); ++i) { | 454 for (size_t i = 0; i < animations_.size(); ++i) { |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 // scroll offset will be up-to-date. | 717 // scroll offset will be up-to-date. |
717 current_scroll_offset = value_provider_->ScrollOffsetForAnimation(); | 718 current_scroll_offset = value_provider_->ScrollOffsetForAnimation(); |
718 } | 719 } |
719 animations_[i]->curve()->ToScrollOffsetAnimationCurve()->SetInitialValue( | 720 animations_[i]->curve()->ToScrollOffsetAnimationCurve()->SetInitialValue( |
720 current_scroll_offset); | 721 current_scroll_offset); |
721 } | 722 } |
722 | 723 |
723 // The new animation should be set to run as soon as possible. | 724 // The new animation should be set to run as soon as possible. |
724 Animation::RunState initial_run_state = | 725 Animation::RunState initial_run_state = |
725 Animation::WAITING_FOR_TARGET_AVAILABILITY; | 726 Animation::WAITING_FOR_TARGET_AVAILABILITY; |
726 scoped_ptr<Animation> to_add( | 727 std::unique_ptr<Animation> to_add( |
727 animations_[i]->CloneAndInitialize(initial_run_state)); | 728 animations_[i]->CloneAndInitialize(initial_run_state)); |
728 DCHECK(!to_add->needs_synchronized_start_time()); | 729 DCHECK(!to_add->needs_synchronized_start_time()); |
729 to_add->set_affects_active_observers(false); | 730 to_add->set_affects_active_observers(false); |
730 controller_impl->AddAnimation(std::move(to_add)); | 731 controller_impl->AddAnimation(std::move(to_add)); |
731 } | 732 } |
732 } | 733 } |
733 | 734 |
734 static bool IsCompleted( | 735 static bool IsCompleted( |
735 Animation* animation, | 736 Animation* animation, |
736 const LayerAnimationController* main_thread_controller) { | 737 const LayerAnimationController* main_thread_controller) { |
(...skipping 13 matching lines...) Expand all Loading... |
750 // immediately. | 751 // immediately. |
751 auto& animations = controller_impl->animations_; | 752 auto& animations = controller_impl->animations_; |
752 for (const auto& animation : animations) { | 753 for (const auto& animation : animations) { |
753 if (IsCompleted(animation.get(), this)) { | 754 if (IsCompleted(animation.get(), this)) { |
754 animation->set_affects_pending_observers(false); | 755 animation->set_affects_pending_observers(false); |
755 if (animation->target_property() == TargetProperty::TRANSFORM) | 756 if (animation->target_property() == TargetProperty::TRANSFORM) |
756 removed_transform_animation = true; | 757 removed_transform_animation = true; |
757 } | 758 } |
758 } | 759 } |
759 auto affects_active_only_and_is_waiting_for_deletion = []( | 760 auto affects_active_only_and_is_waiting_for_deletion = []( |
760 const scoped_ptr<Animation>& animation) { | 761 const std::unique_ptr<Animation>& animation) { |
761 return animation->run_state() == Animation::WAITING_FOR_DELETION && | 762 return animation->run_state() == Animation::WAITING_FOR_DELETION && |
762 !animation->affects_pending_observers(); | 763 !animation->affects_pending_observers(); |
763 }; | 764 }; |
764 animations.erase( | 765 animations.erase( |
765 std::remove_if(animations.begin(), animations.end(), | 766 std::remove_if(animations.begin(), animations.end(), |
766 affects_active_only_and_is_waiting_for_deletion), | 767 affects_active_only_and_is_waiting_for_deletion), |
767 animations.end()); | 768 animations.end()); |
768 | 769 |
769 if (removed_transform_animation) | 770 if (removed_transform_animation) |
770 controller_impl->UpdatePotentiallyAnimatingTransform(); | 771 controller_impl->UpdatePotentiallyAnimatingTransform(); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 } | 1075 } |
1075 } | 1076 } |
1076 } | 1077 } |
1077 } | 1078 } |
1078 | 1079 |
1079 if (aborted_transform_animation) | 1080 if (aborted_transform_animation) |
1080 controller_impl->UpdatePotentiallyAnimatingTransform(); | 1081 controller_impl->UpdatePotentiallyAnimatingTransform(); |
1081 } | 1082 } |
1082 | 1083 |
1083 void LayerAnimationController::PurgeAnimationsMarkedForDeletion() { | 1084 void LayerAnimationController::PurgeAnimationsMarkedForDeletion() { |
1084 animations_.erase(std::remove_if(animations_.begin(), animations_.end(), | 1085 animations_.erase( |
1085 [](const scoped_ptr<Animation>& animation) { | 1086 std::remove_if(animations_.begin(), animations_.end(), |
1086 return animation->run_state() == | 1087 [](const std::unique_ptr<Animation>& animation) { |
1087 Animation::WAITING_FOR_DELETION; | 1088 return animation->run_state() == |
1088 }), | 1089 Animation::WAITING_FOR_DELETION; |
1089 animations_.end()); | 1090 }), |
| 1091 animations_.end()); |
1090 } | 1092 } |
1091 | 1093 |
1092 void LayerAnimationController::TickAnimations(base::TimeTicks monotonic_time) { | 1094 void LayerAnimationController::TickAnimations(base::TimeTicks monotonic_time) { |
1093 for (size_t i = 0; i < animations_.size(); ++i) { | 1095 for (size_t i = 0; i < animations_.size(); ++i) { |
1094 if (animations_[i]->run_state() == Animation::STARTING || | 1096 if (animations_[i]->run_state() == Animation::STARTING || |
1095 animations_[i]->run_state() == Animation::RUNNING || | 1097 animations_[i]->run_state() == Animation::RUNNING || |
1096 animations_[i]->run_state() == Animation::PAUSED) { | 1098 animations_[i]->run_state() == Animation::PAUSED) { |
1097 if (!animations_[i]->InEffect(monotonic_time)) | 1099 if (!animations_[i]->InEffect(monotonic_time)) |
1098 continue; | 1100 continue; |
1099 | 1101 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 &value_observers_); | 1287 &value_observers_); |
1286 LayerAnimationValueObserver* obs; | 1288 LayerAnimationValueObserver* obs; |
1287 while ((obs = it.GetNext()) != nullptr) | 1289 while ((obs = it.GetNext()) != nullptr) |
1288 if (obs->IsActive()) | 1290 if (obs->IsActive()) |
1289 return true; | 1291 return true; |
1290 } | 1292 } |
1291 return false; | 1293 return false; |
1292 } | 1294 } |
1293 | 1295 |
1294 } // namespace cc | 1296 } // namespace cc |
OLD | NEW |