| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 animation_host_->UnregisterPlayerForElement(element_id_, this); | 97 animation_host_->UnregisterPlayerForElement(element_id_, this); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void AnimationPlayer::BindElementAnimations() { | 100 void AnimationPlayer::BindElementAnimations() { |
| 101 DCHECK(!element_animations_); | 101 DCHECK(!element_animations_); |
| 102 element_animations_ = | 102 element_animations_ = |
| 103 animation_host_->GetElementAnimationsForElementId(element_id_); | 103 animation_host_->GetElementAnimationsForElementId(element_id_); |
| 104 DCHECK(element_animations_); | 104 DCHECK(element_animations_); |
| 105 | 105 |
| 106 // Pass all accumulated animations to ElementAnimations. | 106 // Pass all accumulated animations to ElementAnimations. |
| 107 for (auto& animation : animations_) { | 107 for (auto& animation : animations_) |
| 108 element_animations_->AddAnimation(std::move(animation)); | 108 element_animations_->AddAnimation(std::move(animation)); |
| 109 } | |
| 110 if (!animations_.empty()) | |
| 111 SetNeedsCommit(); | |
| 112 animations_.clear(); | 109 animations_.clear(); |
| 110 |
| 111 SetNeedsPushProperties(); |
| 113 } | 112 } |
| 114 | 113 |
| 115 void AnimationPlayer::UnbindElementAnimations() { | 114 void AnimationPlayer::UnbindElementAnimations() { |
| 115 SetNeedsPushProperties(); |
| 116 |
| 116 element_animations_ = nullptr; | 117 element_animations_ = nullptr; |
| 117 DCHECK(animations_.empty()); | 118 DCHECK(animations_.empty()); |
| 118 } | 119 } |
| 119 | 120 |
| 120 void AnimationPlayer::AddAnimation(std::unique_ptr<Animation> animation) { | 121 void AnimationPlayer::AddAnimation(std::unique_ptr<Animation> animation) { |
| 121 DCHECK(animation->target_property() != TargetProperty::SCROLL_OFFSET || | 122 DCHECK(animation->target_property() != TargetProperty::SCROLL_OFFSET || |
| 122 (animation_host_ && animation_host_->SupportsScrollAnimations())); | 123 (animation_host_ && animation_host_->SupportsScrollAnimations())); |
| 123 | 124 |
| 124 if (element_animations_) { | 125 if (element_animations_) { |
| 125 element_animations_->AddAnimation(std::move(animation)); | 126 element_animations_->AddAnimation(std::move(animation)); |
| 126 SetNeedsCommit(); | 127 SetNeedsPushProperties(); |
| 127 } else { | 128 } else { |
| 128 animations_.push_back(std::move(animation)); | 129 animations_.push_back(std::move(animation)); |
| 129 } | 130 } |
| 130 } | 131 } |
| 131 | 132 |
| 132 void AnimationPlayer::PauseAnimation(int animation_id, double time_offset) { | 133 void AnimationPlayer::PauseAnimation(int animation_id, double time_offset) { |
| 133 DCHECK(element_animations_); | 134 DCHECK(element_animations_); |
| 134 element_animations_->PauseAnimation( | 135 element_animations_->PauseAnimation( |
| 135 animation_id, base::TimeDelta::FromSecondsD(time_offset)); | 136 animation_id, base::TimeDelta::FromSecondsD(time_offset)); |
| 136 SetNeedsCommit(); | 137 SetNeedsPushProperties(); |
| 137 } | 138 } |
| 138 | 139 |
| 139 void AnimationPlayer::RemoveAnimation(int animation_id) { | 140 void AnimationPlayer::RemoveAnimation(int animation_id) { |
| 140 if (element_animations_) { | 141 if (element_animations_) { |
| 141 element_animations_->RemoveAnimation(animation_id); | 142 element_animations_->RemoveAnimation(animation_id); |
| 142 SetNeedsCommit(); | 143 SetNeedsPushProperties(); |
| 143 } else { | 144 } else { |
| 144 auto animations_to_remove = std::remove_if( | 145 auto animations_to_remove = std::remove_if( |
| 145 animations_.begin(), animations_.end(), | 146 animations_.begin(), animations_.end(), |
| 146 [animation_id](const std::unique_ptr<Animation>& animation) { | 147 [animation_id](const std::unique_ptr<Animation>& animation) { |
| 147 return animation->id() == animation_id; | 148 return animation->id() == animation_id; |
| 148 }); | 149 }); |
| 149 animations_.erase(animations_to_remove, animations_.end()); | 150 animations_.erase(animations_to_remove, animations_.end()); |
| 150 } | 151 } |
| 151 } | 152 } |
| 152 | 153 |
| 153 void AnimationPlayer::AbortAnimation(int animation_id) { | 154 void AnimationPlayer::AbortAnimation(int animation_id) { |
| 154 DCHECK(element_animations_); | 155 DCHECK(element_animations_); |
| 155 element_animations_->AbortAnimation(animation_id); | 156 element_animations_->AbortAnimation(animation_id); |
| 156 SetNeedsCommit(); | 157 SetNeedsPushProperties(); |
| 157 } | 158 } |
| 158 | 159 |
| 159 void AnimationPlayer::AbortAnimations(TargetProperty::Type target_property, | 160 void AnimationPlayer::AbortAnimations(TargetProperty::Type target_property, |
| 160 bool needs_completion) { | 161 bool needs_completion) { |
| 161 if (element_animations_) { | 162 if (element_animations_) { |
| 162 element_animations_->AbortAnimations(target_property, needs_completion); | 163 element_animations_->AbortAnimations(target_property, needs_completion); |
| 163 SetNeedsCommit(); | 164 SetNeedsPushProperties(); |
| 164 } else { | 165 } else { |
| 165 auto animations_to_remove = std::remove_if( | 166 auto animations_to_remove = std::remove_if( |
| 166 animations_.begin(), animations_.end(), | 167 animations_.begin(), animations_.end(), |
| 167 [target_property](const std::unique_ptr<Animation>& animation) { | 168 [target_property](const std::unique_ptr<Animation>& animation) { |
| 168 return animation->target_property() == target_property; | 169 return animation->target_property() == target_property; |
| 169 }); | 170 }); |
| 170 animations_.erase(animations_to_remove, animations_.end()); | 171 animations_.erase(animations_to_remove, animations_.end()); |
| 171 } | 172 } |
| 172 } | 173 } |
| 173 | 174 |
| 174 void AnimationPlayer::PushPropertiesTo(AnimationPlayer* player_impl) { | 175 void AnimationPlayer::PushPropertiesTo(AnimationPlayer* player_impl) { |
| 176 if (!needs_push_properties_) |
| 177 return; |
| 178 needs_push_properties_ = false; |
| 179 |
| 175 if (element_id_ != player_impl->element_id()) { | 180 if (element_id_ != player_impl->element_id()) { |
| 176 if (player_impl->element_id()) | 181 if (player_impl->element_id()) |
| 177 player_impl->DetachElement(); | 182 player_impl->DetachElement(); |
| 178 if (element_id_) | 183 if (element_id_) |
| 179 player_impl->AttachElement(element_id_); | 184 player_impl->AttachElement(element_id_); |
| 180 } | 185 } |
| 181 } | 186 } |
| 182 | 187 |
| 183 void AnimationPlayer::NotifyAnimationStarted( | 188 void AnimationPlayer::NotifyAnimationStarted( |
| 184 base::TimeTicks monotonic_time, | 189 base::TimeTicks monotonic_time, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 200 | 205 |
| 201 void AnimationPlayer::NotifyAnimationAborted( | 206 void AnimationPlayer::NotifyAnimationAborted( |
| 202 base::TimeTicks monotonic_time, | 207 base::TimeTicks monotonic_time, |
| 203 TargetProperty::Type target_property, | 208 TargetProperty::Type target_property, |
| 204 int group) { | 209 int group) { |
| 205 if (animation_delegate_) | 210 if (animation_delegate_) |
| 206 animation_delegate_->NotifyAnimationAborted(monotonic_time, target_property, | 211 animation_delegate_->NotifyAnimationAborted(monotonic_time, target_property, |
| 207 group); | 212 group); |
| 208 } | 213 } |
| 209 | 214 |
| 215 void AnimationPlayer::NotifyAnimationWaitingForDeletion() { |
| 216 SetNeedsPushProperties(); |
| 217 } |
| 218 |
| 210 void AnimationPlayer::NotifyAnimationTakeover( | 219 void AnimationPlayer::NotifyAnimationTakeover( |
| 211 base::TimeTicks monotonic_time, | 220 base::TimeTicks monotonic_time, |
| 212 TargetProperty::Type target_property, | 221 TargetProperty::Type target_property, |
| 213 double animation_start_time, | 222 double animation_start_time, |
| 214 std::unique_ptr<AnimationCurve> curve) { | 223 std::unique_ptr<AnimationCurve> curve) { |
| 215 if (animation_delegate_) { | 224 if (animation_delegate_) { |
| 216 DCHECK(curve); | 225 DCHECK(curve); |
| 217 animation_delegate_->NotifyAnimationTakeover( | 226 animation_delegate_->NotifyAnimationTakeover( |
| 218 monotonic_time, target_property, animation_start_time, | 227 monotonic_time, target_property, animation_start_time, |
| 219 std::move(curve)); | 228 std::move(curve)); |
| 220 } | 229 } |
| 221 } | 230 } |
| 222 | 231 |
| 223 void AnimationPlayer::SetNeedsCommit() { | 232 void AnimationPlayer::SetNeedsPushProperties() { |
| 224 DCHECK(animation_host_); | 233 needs_push_properties_ = true; |
| 225 animation_host_->SetNeedsCommit(); | 234 |
| 226 animation_host_->SetNeedsRebuildPropertyTrees(); | 235 DCHECK(animation_timeline_); |
| 236 animation_timeline_->SetNeedsPushProperties(); |
| 237 |
| 238 DCHECK(element_animations_); |
| 239 element_animations_->SetNeedsPushProperties(); |
| 227 } | 240 } |
| 228 | 241 |
| 229 } // namespace cc | 242 } // namespace cc |
| OLD | NEW |