| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/animation_player.h" | 5 #include "cc/animation/animation_player.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "cc/animation/animation_delegate.h" | 9 #include "cc/animation/animation_delegate.h" |
| 10 #include "cc/animation/animation_host.h" | 10 #include "cc/animation/animation_host.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // Destroy ElementAnimations or release it if it's still needed. | 99 // Destroy ElementAnimations or release it if it's still needed. |
| 100 animation_host_->UnregisterPlayerForElement(element_id_, this); | 100 animation_host_->UnregisterPlayerForElement(element_id_, this); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void AnimationPlayer::BindElementAnimations() { | 103 void AnimationPlayer::BindElementAnimations() { |
| 104 DCHECK(!element_animations_); | 104 DCHECK(!element_animations_); |
| 105 element_animations_ = | 105 element_animations_ = |
| 106 animation_host_->GetElementAnimationsForElementId(element_id_); | 106 animation_host_->GetElementAnimationsForElementId(element_id_); |
| 107 DCHECK(element_animations_); | 107 DCHECK(element_animations_); |
| 108 | 108 |
| 109 for (auto& animation : animations_) | 109 if (!animations_.empty()) |
| 110 AnimationAddedForProperty(animation->target_property()); | 110 AnimationAdded(); |
| 111 | 111 |
| 112 SetNeedsPushProperties(); | 112 SetNeedsPushProperties(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void AnimationPlayer::UnbindElementAnimations() { | 115 void AnimationPlayer::UnbindElementAnimations() { |
| 116 SetNeedsPushProperties(); | 116 SetNeedsPushProperties(); |
| 117 element_animations_ = nullptr; | 117 element_animations_ = nullptr; |
| 118 } | 118 } |
| 119 | 119 |
| 120 void AnimationPlayer::AddAnimation(std::unique_ptr<Animation> animation) { | 120 void AnimationPlayer::AddAnimation(std::unique_ptr<Animation> animation) { |
| 121 DCHECK(animation->target_property() != TargetProperty::SCROLL_OFFSET || | 121 DCHECK(animation->target_property() != TargetProperty::SCROLL_OFFSET || |
| 122 (animation_host_ && animation_host_->SupportsScrollAnimations())); | 122 (animation_host_ && animation_host_->SupportsScrollAnimations())); |
| 123 DCHECK(!animation->is_impl_only() || | 123 DCHECK(!animation->is_impl_only() || |
| 124 animation->target_property() == TargetProperty::SCROLL_OFFSET); | 124 animation->target_property() == TargetProperty::SCROLL_OFFSET); |
| 125 | 125 |
| 126 TargetProperty::Type target_property = animation->target_property(); | |
| 127 animations_.push_back(std::move(animation)); | 126 animations_.push_back(std::move(animation)); |
| 128 if (element_animations_) { | 127 if (element_animations_) { |
| 129 AnimationAddedForProperty(target_property); | 128 AnimationAdded(); |
| 130 SetNeedsPushProperties(); | 129 SetNeedsPushProperties(); |
| 131 } | 130 } |
| 132 } | 131 } |
| 133 | 132 |
| 134 void AnimationPlayer::AnimationAddedForProperty( | 133 void AnimationPlayer::AnimationAdded() { |
| 135 TargetProperty::Type target_property) { | |
| 136 DCHECK(element_animations_); | 134 DCHECK(element_animations_); |
| 137 | 135 |
| 138 SetNeedsCommit(); | 136 SetNeedsCommit(); |
| 139 needs_to_start_animations_ = true; | 137 needs_to_start_animations_ = true; |
| 140 | 138 |
| 141 element_animations_->UpdateActivationNormal(); | 139 element_animations_->UpdateActivationNormal(); |
| 142 element_animations_->UpdateClientAnimationState(target_property); | 140 element_animations_->UpdateClientAnimationState(); |
| 143 } | 141 } |
| 144 | 142 |
| 145 void AnimationPlayer::PauseAnimation(int animation_id, double time_offset) { | 143 void AnimationPlayer::PauseAnimation(int animation_id, double time_offset) { |
| 146 const base::TimeDelta time_delta = base::TimeDelta::FromSecondsD(time_offset); | 144 const base::TimeDelta time_delta = base::TimeDelta::FromSecondsD(time_offset); |
| 147 | 145 |
| 148 for (size_t i = 0; i < animations_.size(); ++i) { | 146 for (size_t i = 0; i < animations_.size(); ++i) { |
| 149 if (animations_[i]->id() == animation_id) { | 147 if (animations_[i]->id() == animation_id) { |
| 150 animations_[i]->SetRunState(Animation::PAUSED, | 148 animations_[i]->SetRunState(Animation::PAUSED, |
| 151 time_delta + animations_[i]->start_time() + | 149 time_delta + animations_[i]->start_time() + |
| 152 animations_[i]->time_offset()); | 150 animations_[i]->time_offset()); |
| 153 } | 151 } |
| 154 } | 152 } |
| 155 | 153 |
| 156 if (element_animations_) { | 154 if (element_animations_) { |
| 157 SetNeedsCommit(); | 155 SetNeedsCommit(); |
| 158 SetNeedsPushProperties(); | 156 SetNeedsPushProperties(); |
| 159 } | 157 } |
| 160 } | 158 } |
| 161 | 159 |
| 162 void AnimationPlayer::RemoveAnimation(int animation_id) { | 160 void AnimationPlayer::RemoveAnimation(int animation_id) { |
| 163 bool removed_transform_animation = false; | 161 bool animation_removed = false; |
| 164 bool removed_opacity_animation = false; | 162 |
| 165 bool removed_filter_animation = false; | |
| 166 // Since we want to use the animations that we're going to remove, we need to | 163 // Since we want to use the animations that we're going to remove, we need to |
| 167 // use a stable_parition here instead of remove_if. Remove_if leaves the | 164 // use a stable_parition here instead of remove_if. Remove_if leaves the |
| 168 // removed items in an unspecified state. | 165 // removed items in an unspecified state. |
| 169 auto animations_to_remove = std::stable_partition( | 166 auto animations_to_remove = std::stable_partition( |
| 170 animations_.begin(), animations_.end(), | 167 animations_.begin(), animations_.end(), |
| 171 [animation_id](const std::unique_ptr<Animation>& animation) { | 168 [animation_id](const std::unique_ptr<Animation>& animation) { |
| 172 return animation->id() != animation_id; | 169 return animation->id() != animation_id; |
| 173 }); | 170 }); |
| 174 for (auto it = animations_to_remove; it != animations_.end(); ++it) { | 171 for (auto it = animations_to_remove; it != animations_.end(); ++it) { |
| 175 if ((*it)->target_property() == TargetProperty::SCROLL_OFFSET) { | 172 if ((*it)->target_property() == TargetProperty::SCROLL_OFFSET) { |
| 176 if (element_animations_) | 173 if (element_animations_) |
| 177 element_animations_->SetScrollOffsetAnimationWasInterrupted(); | 174 element_animations_->SetScrollOffsetAnimationWasInterrupted(); |
| 178 } else if ((*it)->target_property() == TargetProperty::TRANSFORM && | 175 } else if (!(*it)->is_finished()) { |
| 179 !(*it)->is_finished()) { | 176 animation_removed = true; |
| 180 removed_transform_animation = true; | |
| 181 } else if ((*it)->target_property() == TargetProperty::OPACITY && | |
| 182 !(*it)->is_finished()) { | |
| 183 removed_opacity_animation = true; | |
| 184 } else if ((*it)->target_property() == TargetProperty::FILTER && | |
| 185 !(*it)->is_finished()) { | |
| 186 removed_filter_animation = true; | |
| 187 } | 177 } |
| 188 } | 178 } |
| 189 | 179 |
| 190 animations_.erase(animations_to_remove, animations_.end()); | 180 animations_.erase(animations_to_remove, animations_.end()); |
| 191 | 181 |
| 192 if (element_animations_) { | 182 if (element_animations_) { |
| 193 element_animations_->UpdateActivationNormal(); | 183 element_animations_->UpdateActivationNormal(); |
| 194 element_animations_->UpdateClientAnimationState(removed_transform_animation, | 184 if (animation_removed) |
| 195 removed_opacity_animation, | 185 element_animations_->UpdateClientAnimationState(); |
| 196 removed_filter_animation); | |
| 197 SetNeedsCommit(); | 186 SetNeedsCommit(); |
| 198 SetNeedsPushProperties(); | 187 SetNeedsPushProperties(); |
| 199 } | 188 } |
| 200 } | 189 } |
| 201 | 190 |
| 202 void AnimationPlayer::AbortAnimation(int animation_id) { | 191 void AnimationPlayer::AbortAnimation(int animation_id) { |
| 203 if (Animation* animation = GetAnimationById(animation_id)) { | 192 if (Animation* animation = GetAnimationById(animation_id)) { |
| 204 if (!animation->is_finished()) { | 193 if (!animation->is_finished()) { |
| 205 animation->SetRunState(Animation::ABORTED, last_tick_time_); | 194 animation->SetRunState(Animation::ABORTED, last_tick_time_); |
| 206 if (element_animations_) | 195 if (element_animations_) |
| 207 element_animations_->UpdateClientAnimationState( | 196 element_animations_->UpdateClientAnimationState(); |
| 208 animation->target_property()); | |
| 209 } | 197 } |
| 210 } | 198 } |
| 211 | 199 |
| 212 if (element_animations_) { | 200 if (element_animations_) { |
| 213 SetNeedsCommit(); | 201 SetNeedsCommit(); |
| 214 SetNeedsPushProperties(); | 202 SetNeedsPushProperties(); |
| 215 } | 203 } |
| 216 } | 204 } |
| 217 | 205 |
| 218 void AnimationPlayer::AbortAnimations(TargetProperty::Type target_property, | 206 void AnimationPlayer::AbortAnimations(TargetProperty::Type target_property, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 231 last_tick_time_); | 219 last_tick_time_); |
| 232 } else { | 220 } else { |
| 233 animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_); | 221 animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_); |
| 234 } | 222 } |
| 235 aborted_animation = true; | 223 aborted_animation = true; |
| 236 } | 224 } |
| 237 } | 225 } |
| 238 | 226 |
| 239 if (element_animations_) { | 227 if (element_animations_) { |
| 240 if (aborted_animation) | 228 if (aborted_animation) |
| 241 element_animations_->UpdateClientAnimationState(target_property); | 229 element_animations_->UpdateClientAnimationState(); |
| 242 SetNeedsCommit(); | 230 SetNeedsCommit(); |
| 243 SetNeedsPushProperties(); | 231 SetNeedsPushProperties(); |
| 244 } | 232 } |
| 245 } | 233 } |
| 246 | 234 |
| 247 void AnimationPlayer::PushPropertiesTo(AnimationPlayer* player_impl) { | 235 void AnimationPlayer::PushPropertiesTo(AnimationPlayer* player_impl) { |
| 248 if (!needs_push_properties_) | 236 if (!needs_push_properties_) |
| 249 return; | 237 return; |
| 250 needs_push_properties_ = false; | 238 needs_push_properties_ = false; |
| 251 | 239 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 animations_[j]->affects_pending_elements(); | 428 animations_[j]->affects_pending_elements(); |
| 441 } | 429 } |
| 442 } | 430 } |
| 443 | 431 |
| 444 // Check to see if intersection of the list of properties affected by | 432 // Check to see if intersection of the list of properties affected by |
| 445 // the group and the list of currently blocked properties is null, taking | 433 // the group and the list of currently blocked properties is null, taking |
| 446 // into account the type(s) of elements affected by the group. In any | 434 // into account the type(s) of elements affected by the group. In any |
| 447 // case, the group's target properties need to be added to the lists of | 435 // case, the group's target properties need to be added to the lists of |
| 448 // blocked properties. | 436 // blocked properties. |
| 449 bool null_intersection = true; | 437 bool null_intersection = true; |
| 450 static_assert(TargetProperty::FIRST_TARGET_PROPERTY == 0, | |
| 451 "TargetProperty must be 0-based enum"); | |
| 452 for (int property = TargetProperty::FIRST_TARGET_PROPERTY; | 438 for (int property = TargetProperty::FIRST_TARGET_PROPERTY; |
| 453 property <= TargetProperty::LAST_TARGET_PROPERTY; ++property) { | 439 property <= TargetProperty::LAST_TARGET_PROPERTY; ++property) { |
| 454 if (enqueued_properties[property]) { | 440 if (enqueued_properties[property]) { |
| 455 if (affects_active_elements) { | 441 if (affects_active_elements) { |
| 456 if (blocked_properties_for_active_elements[property]) | 442 if (blocked_properties_for_active_elements[property]) |
| 457 null_intersection = false; | 443 null_intersection = false; |
| 458 else | 444 else |
| 459 blocked_properties_for_active_elements[property] = true; | 445 blocked_properties_for_active_elements[property] = true; |
| 460 } | 446 } |
| 461 if (affects_pending_elements) { | 447 if (affects_pending_elements) { |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 break; | 705 break; |
| 720 } | 706 } |
| 721 } | 707 } |
| 722 } | 708 } |
| 723 } | 709 } |
| 724 | 710 |
| 725 last_tick_time_ = monotonic_time; | 711 last_tick_time_ = monotonic_time; |
| 726 } | 712 } |
| 727 | 713 |
| 728 void AnimationPlayer::MarkFinishedAnimations(base::TimeTicks monotonic_time) { | 714 void AnimationPlayer::MarkFinishedAnimations(base::TimeTicks monotonic_time) { |
| 729 bool finished_transform_animation = false; | 715 bool animation_finished = false; |
| 730 bool finished_opacity_animation = false; | 716 |
| 731 bool finished_filter_animation = false; | |
| 732 for (size_t i = 0; i < animations_.size(); ++i) { | 717 for (size_t i = 0; i < animations_.size(); ++i) { |
| 733 if (!animations_[i]->is_finished() && | 718 if (!animations_[i]->is_finished() && |
| 734 animations_[i]->IsFinishedAt(monotonic_time)) { | 719 animations_[i]->IsFinishedAt(monotonic_time)) { |
| 735 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time); | 720 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time); |
| 736 if (animations_[i]->target_property() == TargetProperty::TRANSFORM) | 721 animation_finished = true; |
| 737 finished_transform_animation = true; | |
| 738 else if (animations_[i]->target_property() == TargetProperty::OPACITY) | |
| 739 finished_opacity_animation = true; | |
| 740 else if (animations_[i]->target_property() == TargetProperty::FILTER) | |
| 741 finished_filter_animation = true; | |
| 742 } | 722 } |
| 743 } | 723 } |
| 744 | 724 |
| 745 DCHECK(element_animations_); | 725 DCHECK(element_animations_); |
| 746 element_animations_->UpdateClientAnimationState(finished_transform_animation, | 726 if (animation_finished) |
| 747 finished_opacity_animation, | 727 element_animations_->UpdateClientAnimationState(); |
| 748 finished_filter_animation); | |
| 749 } | 728 } |
| 750 | 729 |
| 751 void AnimationPlayer::ActivateAnimations(bool* changed_transform_animation, | 730 void AnimationPlayer::ActivateAnimations() { |
| 752 bool* changed_opacity_animation, | 731 bool animation_activated = false; |
| 753 bool* changed_filter_animation) { | 732 |
| 754 for (size_t i = 0; i < animations_.size(); ++i) { | 733 for (size_t i = 0; i < animations_.size(); ++i) { |
| 755 if (animations_[i]->affects_active_elements() != | 734 if (animations_[i]->affects_active_elements() != |
| 756 animations_[i]->affects_pending_elements()) { | 735 animations_[i]->affects_pending_elements()) { |
| 757 if (animations_[i]->target_property() == TargetProperty::TRANSFORM) | 736 animation_activated = true; |
| 758 *changed_transform_animation = true; | |
| 759 else if (animations_[i]->target_property() == TargetProperty::OPACITY) | |
| 760 *changed_opacity_animation = true; | |
| 761 else if (animations_[i]->target_property() == TargetProperty::FILTER) | |
| 762 *changed_filter_animation = true; | |
| 763 } | 737 } |
| 764 animations_[i]->set_affects_active_elements( | 738 animations_[i]->set_affects_active_elements( |
| 765 animations_[i]->affects_pending_elements()); | 739 animations_[i]->affects_pending_elements()); |
| 766 } | 740 } |
| 767 auto affects_no_elements = [](const std::unique_ptr<Animation>& animation) { | 741 auto affects_no_elements = [](const std::unique_ptr<Animation>& animation) { |
| 768 return !animation->affects_active_elements() && | 742 return !animation->affects_active_elements() && |
| 769 !animation->affects_pending_elements(); | 743 !animation->affects_pending_elements(); |
| 770 }; | 744 }; |
| 771 animations_.erase(std::remove_if(animations_.begin(), animations_.end(), | 745 animations_.erase(std::remove_if(animations_.begin(), animations_.end(), |
| 772 affects_no_elements), | 746 affects_no_elements), |
| 773 animations_.end()); | 747 animations_.end()); |
| 748 |
| 749 if (animation_activated) |
| 750 element_animations_->UpdateClientAnimationState(); |
| 774 } | 751 } |
| 775 | 752 |
| 776 bool AnimationPlayer::HasFilterAnimationThatInflatesBounds() const { | 753 bool AnimationPlayer::HasFilterAnimationThatInflatesBounds() const { |
| 777 for (size_t i = 0; i < animations_.size(); ++i) { | 754 for (size_t i = 0; i < animations_.size(); ++i) { |
| 778 if (!animations_[i]->is_finished() && | 755 if (!animations_[i]->is_finished() && |
| 779 animations_[i]->target_property() == TargetProperty::FILTER && | 756 animations_[i]->target_property() == TargetProperty::FILTER && |
| 780 animations_[i] | 757 animations_[i] |
| 781 ->curve() | 758 ->curve() |
| 782 ->ToFilterAnimationCurve() | 759 ->ToFilterAnimationCurve() |
| 783 ->HasFilterThatMovesPixels()) | 760 ->HasFilterThatMovesPixels()) |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 return nullptr; | 966 return nullptr; |
| 990 } | 967 } |
| 991 | 968 |
| 992 Animation* AnimationPlayer::GetAnimationById(int animation_id) const { | 969 Animation* AnimationPlayer::GetAnimationById(int animation_id) const { |
| 993 for (size_t i = 0; i < animations_.size(); ++i) | 970 for (size_t i = 0; i < animations_.size(); ++i) |
| 994 if (animations_[i]->id() == animation_id) | 971 if (animations_[i]->id() == animation_id) |
| 995 return animations_[i].get(); | 972 return animations_[i].get(); |
| 996 return nullptr; | 973 return nullptr; |
| 997 } | 974 } |
| 998 | 975 |
| 999 void AnimationPlayer::GetPropertyAnimationStateFor( | 976 void AnimationPlayer::GetPropertyAnimationState( |
| 1000 TargetProperty::Type property, | 977 PropertyAnimationState* pending_state, |
| 1001 PropertyAnimationState* state) const { | 978 PropertyAnimationState* active_state) const { |
| 1002 state->Clear(); | 979 pending_state->Clear(); |
| 980 active_state->Clear(); |
| 981 |
| 1003 for (const auto& animation : animations_) { | 982 for (const auto& animation : animations_) { |
| 1004 if (!animation->is_finished() && animation->target_property() == property) { | 983 if (!animation->is_finished()) { |
| 1005 state->potentially_animating_for_active_elements |= | 984 bool in_effect = animation->InEffect(last_tick_time_); |
| 1006 animation->affects_active_elements(); | 985 bool active = animation->affects_active_elements(); |
| 1007 state->potentially_animating_for_pending_elements |= | 986 bool pending = animation->affects_pending_elements(); |
| 1008 animation->affects_pending_elements(); | 987 TargetProperty::Type property = animation->target_property(); |
| 1009 state->currently_running_for_active_elements |= | 988 |
| 1010 animation->affects_active_elements() && | 989 if (pending) |
| 1011 animation->InEffect(last_tick_time_); | 990 pending_state->potentially_animating[property] = true; |
| 1012 state->currently_running_for_pending_elements |= | 991 if (pending && in_effect) |
| 1013 animation->affects_pending_elements() && | 992 pending_state->currently_running[property] = true; |
| 1014 animation->InEffect(last_tick_time_); | 993 |
| 994 if (active) |
| 995 active_state->potentially_animating[property] = true; |
| 996 if (active && in_effect) |
| 997 active_state->currently_running[property] = true; |
| 1015 } | 998 } |
| 1016 } | 999 } |
| 1017 } | 1000 } |
| 1018 | 1001 |
| 1019 void AnimationPlayer::MarkAbortedAnimationsForDeletion( | 1002 void AnimationPlayer::MarkAbortedAnimationsForDeletion( |
| 1020 AnimationPlayer* animation_player_impl) const { | 1003 AnimationPlayer* animation_player_impl) const { |
| 1021 bool aborted_transform_animation = false; | 1004 bool animation_aborted = false; |
| 1022 bool aborted_opacity_animation = false; | 1005 |
| 1023 bool aborted_filter_animation = false; | |
| 1024 auto& animations_impl = animation_player_impl->animations_; | 1006 auto& animations_impl = animation_player_impl->animations_; |
| 1025 for (const auto& animation_impl : animations_impl) { | 1007 for (const auto& animation_impl : animations_impl) { |
| 1026 // If the animation has been aborted on the main thread, mark it for | 1008 // If the animation has been aborted on the main thread, mark it for |
| 1027 // deletion. | 1009 // deletion. |
| 1028 if (Animation* animation = GetAnimationById(animation_impl->id())) { | 1010 if (Animation* animation = GetAnimationById(animation_impl->id())) { |
| 1029 if (animation->run_state() == Animation::ABORTED) { | 1011 if (animation->run_state() == Animation::ABORTED) { |
| 1030 animation_impl->SetRunState(Animation::WAITING_FOR_DELETION, | 1012 animation_impl->SetRunState(Animation::WAITING_FOR_DELETION, |
| 1031 animation_player_impl->last_tick_time_); | 1013 animation_player_impl->last_tick_time_); |
| 1032 animation->SetRunState(Animation::WAITING_FOR_DELETION, | 1014 animation->SetRunState(Animation::WAITING_FOR_DELETION, |
| 1033 last_tick_time_); | 1015 last_tick_time_); |
| 1034 if (animation_impl->target_property() == TargetProperty::TRANSFORM) | 1016 animation_aborted = true; |
| 1035 aborted_transform_animation = true; | |
| 1036 else if (animation_impl->target_property() == TargetProperty::OPACITY) | |
| 1037 aborted_opacity_animation = true; | |
| 1038 else if (animation_impl->target_property() == TargetProperty::FILTER) | |
| 1039 aborted_filter_animation = true; | |
| 1040 } | 1017 } |
| 1041 } | 1018 } |
| 1042 } | 1019 } |
| 1043 | 1020 |
| 1044 if (element_animations_) | 1021 if (element_animations_ && animation_aborted) |
| 1045 element_animations_->SetNeedsUpdateImplClientState( | 1022 element_animations_->SetNeedsUpdateImplClientState(); |
| 1046 aborted_transform_animation, aborted_opacity_animation, | |
| 1047 aborted_filter_animation); | |
| 1048 } | 1023 } |
| 1049 | 1024 |
| 1050 void AnimationPlayer::PurgeAnimationsMarkedForDeletion() { | 1025 void AnimationPlayer::PurgeAnimationsMarkedForDeletion() { |
| 1051 animations_.erase( | 1026 animations_.erase( |
| 1052 std::remove_if(animations_.begin(), animations_.end(), | 1027 std::remove_if(animations_.begin(), animations_.end(), |
| 1053 [](const std::unique_ptr<Animation>& animation) { | 1028 [](const std::unique_ptr<Animation>& animation) { |
| 1054 return animation->run_state() == | 1029 return animation->run_state() == |
| 1055 Animation::WAITING_FOR_DELETION; | 1030 Animation::WAITING_FOR_DELETION; |
| 1056 }), | 1031 }), |
| 1057 animations_.end()); | 1032 animations_.end()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 const AnimationPlayer* main_thread_player) { | 1075 const AnimationPlayer* main_thread_player) { |
| 1101 if (animation->is_impl_only()) { | 1076 if (animation->is_impl_only()) { |
| 1102 return (animation->run_state() == Animation::WAITING_FOR_DELETION); | 1077 return (animation->run_state() == Animation::WAITING_FOR_DELETION); |
| 1103 } else { | 1078 } else { |
| 1104 return !main_thread_player->GetAnimationById(animation->id()); | 1079 return !main_thread_player->GetAnimationById(animation->id()); |
| 1105 } | 1080 } |
| 1106 } | 1081 } |
| 1107 | 1082 |
| 1108 void AnimationPlayer::RemoveAnimationsCompletedOnMainThread( | 1083 void AnimationPlayer::RemoveAnimationsCompletedOnMainThread( |
| 1109 AnimationPlayer* animation_player_impl) const { | 1084 AnimationPlayer* animation_player_impl) const { |
| 1110 bool removed_transform_animation = false; | 1085 bool animation_completed = false; |
| 1111 bool removed_opacity_animation = false; | 1086 |
| 1112 bool removed_filter_animation = false; | |
| 1113 // Animations removed on the main thread should no longer affect pending | 1087 // Animations removed on the main thread should no longer affect pending |
| 1114 // elements, and should stop affecting active elements after the next call | 1088 // elements, and should stop affecting active elements after the next call |
| 1115 // to ActivateAnimations. If already WAITING_FOR_DELETION, they can be removed | 1089 // to ActivateAnimations. If already WAITING_FOR_DELETION, they can be removed |
| 1116 // immediately. | 1090 // immediately. |
| 1117 auto& animations = animation_player_impl->animations_; | 1091 auto& animations = animation_player_impl->animations_; |
| 1118 for (const auto& animation : animations) { | 1092 for (const auto& animation : animations) { |
| 1119 if (IsCompleted(animation.get(), this)) { | 1093 if (IsCompleted(animation.get(), this)) { |
| 1120 animation->set_affects_pending_elements(false); | 1094 animation->set_affects_pending_elements(false); |
| 1121 if (animation->target_property() == TargetProperty::TRANSFORM) | 1095 animation_completed = true; |
| 1122 removed_transform_animation = true; | |
| 1123 else if (animation->target_property() == TargetProperty::OPACITY) | |
| 1124 removed_opacity_animation = true; | |
| 1125 else if (animation->target_property() == TargetProperty::FILTER) | |
| 1126 removed_filter_animation = true; | |
| 1127 } | 1096 } |
| 1128 } | 1097 } |
| 1129 auto affects_active_only_and_is_waiting_for_deletion = | 1098 auto affects_active_only_and_is_waiting_for_deletion = |
| 1130 [](const std::unique_ptr<Animation>& animation) { | 1099 [](const std::unique_ptr<Animation>& animation) { |
| 1131 return animation->run_state() == Animation::WAITING_FOR_DELETION && | 1100 return animation->run_state() == Animation::WAITING_FOR_DELETION && |
| 1132 !animation->affects_pending_elements(); | 1101 !animation->affects_pending_elements(); |
| 1133 }; | 1102 }; |
| 1134 animations.erase( | 1103 animations.erase( |
| 1135 std::remove_if(animations.begin(), animations.end(), | 1104 std::remove_if(animations.begin(), animations.end(), |
| 1136 affects_active_only_and_is_waiting_for_deletion), | 1105 affects_active_only_and_is_waiting_for_deletion), |
| 1137 animations.end()); | 1106 animations.end()); |
| 1138 | 1107 |
| 1139 if (element_animations_) | 1108 if (element_animations_ && animation_completed) |
| 1140 element_animations_->SetNeedsUpdateImplClientState( | 1109 element_animations_->SetNeedsUpdateImplClientState(); |
| 1141 removed_transform_animation, removed_opacity_animation, | |
| 1142 removed_filter_animation); | |
| 1143 } | 1110 } |
| 1144 | 1111 |
| 1145 void AnimationPlayer::PushPropertiesToImplThread( | 1112 void AnimationPlayer::PushPropertiesToImplThread( |
| 1146 AnimationPlayer* animation_player_impl) { | 1113 AnimationPlayer* animation_player_impl) { |
| 1147 for (size_t i = 0; i < animations_.size(); ++i) { | 1114 for (size_t i = 0; i < animations_.size(); ++i) { |
| 1148 Animation* current_impl = | 1115 Animation* current_impl = |
| 1149 animation_player_impl->GetAnimationById(animations_[i]->id()); | 1116 animation_player_impl->GetAnimationById(animations_[i]->id()); |
| 1150 if (current_impl) | 1117 if (current_impl) |
| 1151 animations_[i]->PushPropertiesTo(current_impl); | 1118 animations_[i]->PushPropertiesTo(current_impl); |
| 1152 } | 1119 } |
| 1153 } | 1120 } |
| 1154 | 1121 |
| 1155 } // namespace cc | 1122 } // namespace cc |
| OLD | NEW |