| 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_host.h" | 5 #include "cc/animation/animation_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "base/trace_event/trace_event_argument.h" | 12 #include "base/trace_event/trace_event_argument.h" |
| 13 #include "cc/animation/animation_delegate.h" | 13 #include "cc/animation/animation_delegate.h" |
| 14 #include "cc/animation/animation_events.h" | 14 #include "cc/animation/animation_events.h" |
| 15 #include "cc/animation/animation_id_provider.h" | 15 #include "cc/animation/animation_id_provider.h" |
| 16 #include "cc/animation/animation_player.h" | 16 #include "cc/animation/animation_player.h" |
| 17 #include "cc/animation/animation_timeline.h" | 17 #include "cc/animation/animation_timeline.h" |
| 18 #include "cc/animation/element_animations.h" | 18 #include "cc/animation/element_animations.h" |
| 19 #include "cc/animation/scroll_offset_animation_curve.h" | 19 #include "cc/animation/scroll_offset_animation_curve.h" |
| 20 #include "cc/animation/timing_function.h" | 20 #include "cc/animation/timing_function.h" |
| 21 #include "cc/trees/mutator_host_client.h" | |
| 22 #include "ui/gfx/geometry/box_f.h" | 21 #include "ui/gfx/geometry/box_f.h" |
| 23 #include "ui/gfx/geometry/scroll_offset.h" | 22 #include "ui/gfx/geometry/scroll_offset.h" |
| 24 | 23 |
| 25 namespace cc { | 24 namespace cc { |
| 26 | 25 |
| 27 class AnimationHost::ScrollOffsetAnimations : public AnimationDelegate { | 26 class AnimationHost::ScrollOffsetAnimations : public AnimationDelegate { |
| 28 public: | 27 public: |
| 29 explicit ScrollOffsetAnimations(AnimationHost* animation_host) | 28 explicit ScrollOffsetAnimations(AnimationHost* animation_host) |
| 30 : animation_host_(animation_host), | 29 : animation_host_(animation_host), |
| 31 scroll_offset_timeline_( | 30 scroll_offset_timeline_( |
| 32 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId())), | 31 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId())), |
| 33 scroll_offset_animation_player_( | 32 scroll_offset_animation_player_( |
| 34 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId())) { | 33 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId())) { |
| 35 scroll_offset_timeline_->set_is_impl_only(true); | 34 scroll_offset_timeline_->set_is_impl_only(true); |
| 36 scroll_offset_animation_player_->set_layer_animation_delegate(this); | 35 scroll_offset_animation_player_->set_layer_animation_delegate(this); |
| 37 | 36 |
| 38 animation_host_->AddAnimationTimeline(scroll_offset_timeline_.get()); | 37 animation_host_->AddAnimationTimeline(scroll_offset_timeline_.get()); |
| 39 scroll_offset_timeline_->AttachPlayer( | 38 scroll_offset_timeline_->AttachPlayer( |
| 40 scroll_offset_animation_player_.get()); | 39 scroll_offset_animation_player_.get()); |
| 41 } | 40 } |
| 42 | 41 |
| 43 ~ScrollOffsetAnimations() override { | 42 ~ScrollOffsetAnimations() override { |
| 44 scroll_offset_timeline_->DetachPlayer( | 43 scroll_offset_timeline_->DetachPlayer( |
| 45 scroll_offset_animation_player_.get()); | 44 scroll_offset_animation_player_.get()); |
| 46 animation_host_->RemoveAnimationTimeline(scroll_offset_timeline_.get()); | 45 animation_host_->RemoveAnimationTimeline(scroll_offset_timeline_.get()); |
| 47 } | 46 } |
| 48 | 47 |
| 49 void ScrollAnimationCreate(int layer_id, | 48 void ScrollAnimationCreate(ElementId element_id, |
| 50 const gfx::ScrollOffset& target_offset, | 49 const gfx::ScrollOffset& target_offset, |
| 51 const gfx::ScrollOffset& current_offset) { | 50 const gfx::ScrollOffset& current_offset) { |
| 52 std::unique_ptr<ScrollOffsetAnimationCurve> curve = | 51 std::unique_ptr<ScrollOffsetAnimationCurve> curve = |
| 53 ScrollOffsetAnimationCurve::Create( | 52 ScrollOffsetAnimationCurve::Create( |
| 54 target_offset, EaseInOutTimingFunction::Create(), | 53 target_offset, EaseInOutTimingFunction::Create(), |
| 55 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA); | 54 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA); |
| 56 curve->SetInitialValue(current_offset); | 55 curve->SetInitialValue(current_offset); |
| 57 | 56 |
| 58 std::unique_ptr<Animation> animation = Animation::Create( | 57 std::unique_ptr<Animation> animation = Animation::Create( |
| 59 std::move(curve), AnimationIdProvider::NextAnimationId(), | 58 std::move(curve), AnimationIdProvider::NextAnimationId(), |
| 60 AnimationIdProvider::NextGroupId(), TargetProperty::SCROLL_OFFSET); | 59 AnimationIdProvider::NextGroupId(), TargetProperty::SCROLL_OFFSET); |
| 61 animation->set_is_impl_only(true); | 60 animation->set_is_impl_only(true); |
| 62 | 61 |
| 63 DCHECK(scroll_offset_animation_player_); | 62 DCHECK(scroll_offset_animation_player_); |
| 64 DCHECK(scroll_offset_animation_player_->animation_timeline()); | 63 DCHECK(scroll_offset_animation_player_->animation_timeline()); |
| 65 | 64 |
| 66 ReattachScrollOffsetPlayerIfNeeded(layer_id); | 65 ReattachScrollOffsetPlayerIfNeeded(element_id); |
| 67 | 66 |
| 68 scroll_offset_animation_player_->AddAnimation(std::move(animation)); | 67 scroll_offset_animation_player_->AddAnimation(std::move(animation)); |
| 69 } | 68 } |
| 70 | 69 |
| 71 bool ScrollAnimationUpdateTarget(int layer_id, | 70 bool ScrollAnimationUpdateTarget(ElementId element_id, |
| 72 const gfx::Vector2dF& scroll_delta, | 71 const gfx::Vector2dF& scroll_delta, |
| 73 const gfx::ScrollOffset& max_scroll_offset, | 72 const gfx::ScrollOffset& max_scroll_offset, |
| 74 base::TimeTicks frame_monotonic_time) { | 73 base::TimeTicks frame_monotonic_time) { |
| 75 DCHECK(scroll_offset_animation_player_); | 74 DCHECK(scroll_offset_animation_player_); |
| 76 if (!scroll_offset_animation_player_->element_animations()) | 75 if (!scroll_offset_animation_player_->element_animations()) |
| 77 return false; | 76 return false; |
| 78 | 77 |
| 79 DCHECK_EQ(layer_id, scroll_offset_animation_player_->layer_id()); | 78 DCHECK_EQ(element_id, scroll_offset_animation_player_->element_id()); |
| 80 | 79 |
| 81 Animation* animation = scroll_offset_animation_player_->element_animations() | 80 Animation* animation = scroll_offset_animation_player_->element_animations() |
| 82 ->GetAnimation(TargetProperty::SCROLL_OFFSET); | 81 ->GetAnimation(TargetProperty::SCROLL_OFFSET); |
| 83 if (!animation) { | 82 if (!animation) { |
| 84 scroll_offset_animation_player_->DetachLayer(); | 83 scroll_offset_animation_player_->DetachLayer(); |
| 85 return false; | 84 return false; |
| 86 } | 85 } |
| 87 | 86 |
| 88 ScrollOffsetAnimationCurve* curve = | 87 ScrollOffsetAnimationCurve* curve = |
| 89 animation->curve()->ToScrollOffsetAnimationCurve(); | 88 animation->curve()->ToScrollOffsetAnimationCurve(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 120 void NotifyAnimationAborted(base::TimeTicks monotonic_time, | 119 void NotifyAnimationAborted(base::TimeTicks monotonic_time, |
| 121 TargetProperty::Type target_property, | 120 TargetProperty::Type target_property, |
| 122 int group) override {} | 121 int group) override {} |
| 123 void NotifyAnimationTakeover(base::TimeTicks monotonic_time, | 122 void NotifyAnimationTakeover(base::TimeTicks monotonic_time, |
| 124 TargetProperty::Type target_property, | 123 TargetProperty::Type target_property, |
| 125 double animation_start_time, | 124 double animation_start_time, |
| 126 std::unique_ptr<AnimationCurve> curve) override { | 125 std::unique_ptr<AnimationCurve> curve) override { |
| 127 } | 126 } |
| 128 | 127 |
| 129 private: | 128 private: |
| 130 void ReattachScrollOffsetPlayerIfNeeded(int layer_id) { | 129 void ReattachScrollOffsetPlayerIfNeeded(ElementId element_id) { |
| 131 if (scroll_offset_animation_player_->layer_id() != layer_id) { | 130 if (scroll_offset_animation_player_->element_id() != element_id) { |
| 132 if (scroll_offset_animation_player_->layer_id()) | 131 if (scroll_offset_animation_player_->element_id()) |
| 133 scroll_offset_animation_player_->DetachLayer(); | 132 scroll_offset_animation_player_->DetachLayer(); |
| 134 if (layer_id) | 133 if (element_id) |
| 135 scroll_offset_animation_player_->AttachLayer(layer_id); | 134 scroll_offset_animation_player_->AttachLayer(element_id); |
| 136 } | 135 } |
| 137 } | 136 } |
| 138 | 137 |
| 139 AnimationHost* animation_host_; | 138 AnimationHost* animation_host_; |
| 140 scoped_refptr<AnimationTimeline> scroll_offset_timeline_; | 139 scoped_refptr<AnimationTimeline> scroll_offset_timeline_; |
| 141 | 140 |
| 142 // We have just one player for impl-only scroll offset animations. | 141 // We have just one player for impl-only scroll offset animations. |
| 143 // I.e. only one layer can have an impl-only scroll offset animation at | 142 // I.e. only one layer can have an impl-only scroll offset animation at |
| 144 // any given time. | 143 // any given time. |
| 145 scoped_refptr<AnimationPlayer> scroll_offset_animation_player_; | 144 scoped_refptr<AnimationPlayer> scroll_offset_animation_player_; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 std::make_pair(timeline->id(), std::move(timeline))); | 193 std::make_pair(timeline->id(), std::move(timeline))); |
| 195 } | 194 } |
| 196 | 195 |
| 197 void AnimationHost::RemoveAnimationTimeline( | 196 void AnimationHost::RemoveAnimationTimeline( |
| 198 scoped_refptr<AnimationTimeline> timeline) { | 197 scoped_refptr<AnimationTimeline> timeline) { |
| 199 DCHECK(timeline->id()); | 198 DCHECK(timeline->id()); |
| 200 EraseTimeline(timeline); | 199 EraseTimeline(timeline); |
| 201 id_to_timeline_map_.erase(timeline->id()); | 200 id_to_timeline_map_.erase(timeline->id()); |
| 202 } | 201 } |
| 203 | 202 |
| 204 void AnimationHost::RegisterLayer(int layer_id, LayerTreeType tree_type) { | 203 void AnimationHost::RegisterLayer(ElementId element_id, |
| 204 LayerTreeType tree_type) { |
| 205 scoped_refptr<ElementAnimations> element_animations = | 205 scoped_refptr<ElementAnimations> element_animations = |
| 206 GetElementAnimationsForLayerId(layer_id); | 206 GetElementAnimationsForLayerId(element_id); |
| 207 if (element_animations) | 207 if (element_animations) |
| 208 element_animations->LayerRegistered(layer_id, tree_type); | 208 element_animations->LayerRegistered(element_id, tree_type); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void AnimationHost::UnregisterLayer(int layer_id, LayerTreeType tree_type) { | 211 void AnimationHost::UnregisterLayer(ElementId element_id, |
| 212 LayerTreeType tree_type) { |
| 212 scoped_refptr<ElementAnimations> element_animations = | 213 scoped_refptr<ElementAnimations> element_animations = |
| 213 GetElementAnimationsForLayerId(layer_id); | 214 GetElementAnimationsForLayerId(element_id); |
| 214 if (element_animations) | 215 if (element_animations) |
| 215 element_animations->LayerUnregistered(layer_id, tree_type); | 216 element_animations->LayerUnregistered(element_id, tree_type); |
| 216 } | 217 } |
| 217 | 218 |
| 218 void AnimationHost::RegisterPlayerForLayer(int layer_id, | 219 void AnimationHost::RegisterPlayerForLayer(ElementId element_id, |
| 219 AnimationPlayer* player) { | 220 AnimationPlayer* player) { |
| 220 DCHECK(layer_id); | 221 DCHECK(element_id); |
| 221 DCHECK(player); | 222 DCHECK(player); |
| 222 | 223 |
| 223 scoped_refptr<ElementAnimations> element_animations = | 224 scoped_refptr<ElementAnimations> element_animations = |
| 224 GetElementAnimationsForLayerId(layer_id); | 225 GetElementAnimationsForLayerId(element_id); |
| 225 if (!element_animations) { | 226 if (!element_animations) { |
| 226 element_animations = ElementAnimations::Create(); | 227 element_animations = ElementAnimations::Create(); |
| 227 element_animations->SetLayerId(layer_id); | 228 element_animations->SetElementId(element_id); |
| 228 RegisterElementAnimations(element_animations.get()); | 229 RegisterElementAnimations(element_animations.get()); |
| 229 } | 230 } |
| 230 | 231 |
| 231 if (element_animations->animation_host() != this) { | 232 if (element_animations->animation_host() != this) { |
| 232 element_animations->SetAnimationHost(this); | 233 element_animations->SetAnimationHost(this); |
| 233 element_animations->InitAffectedElementTypes(); | 234 element_animations->InitAffectedElementTypes(); |
| 234 } | 235 } |
| 235 | 236 |
| 236 element_animations->AddPlayer(player); | 237 element_animations->AddPlayer(player); |
| 237 } | 238 } |
| 238 | 239 |
| 239 void AnimationHost::UnregisterPlayerForLayer(int layer_id, | 240 void AnimationHost::UnregisterPlayerForLayer(ElementId element_id, |
| 240 AnimationPlayer* player) { | 241 AnimationPlayer* player) { |
| 241 DCHECK(layer_id); | 242 DCHECK(element_id); |
| 242 DCHECK(player); | 243 DCHECK(player); |
| 243 | 244 |
| 244 scoped_refptr<ElementAnimations> element_animations = | 245 scoped_refptr<ElementAnimations> element_animations = |
| 245 GetElementAnimationsForLayerId(layer_id); | 246 GetElementAnimationsForLayerId(element_id); |
| 246 DCHECK(element_animations); | 247 DCHECK(element_animations); |
| 247 element_animations->RemovePlayer(player); | 248 element_animations->RemovePlayer(player); |
| 248 | 249 |
| 249 if (element_animations->IsEmpty()) { | 250 if (element_animations->IsEmpty()) { |
| 250 element_animations->ClearAffectedElementTypes(); | 251 element_animations->ClearAffectedElementTypes(); |
| 251 UnregisterElementAnimations(element_animations.get()); | 252 UnregisterElementAnimations(element_animations.get()); |
| 252 element_animations->SetAnimationHost(nullptr); | 253 element_animations->SetAnimationHost(nullptr); |
| 253 } | 254 } |
| 254 } | 255 } |
| 255 | 256 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 for (auto& kv : layer_to_element_animations_map_) { | 321 for (auto& kv : layer_to_element_animations_map_) { |
| 321 const auto& element_animations = kv.second; | 322 const auto& element_animations = kv.second; |
| 322 auto element_animations_impl = | 323 auto element_animations_impl = |
| 323 host_impl->GetElementAnimationsForLayerId(kv.first); | 324 host_impl->GetElementAnimationsForLayerId(kv.first); |
| 324 if (element_animations_impl) | 325 if (element_animations_impl) |
| 325 element_animations->PushPropertiesTo(std::move(element_animations_impl)); | 326 element_animations->PushPropertiesTo(std::move(element_animations_impl)); |
| 326 } | 327 } |
| 327 } | 328 } |
| 328 | 329 |
| 329 scoped_refptr<ElementAnimations> AnimationHost::GetElementAnimationsForLayerId( | 330 scoped_refptr<ElementAnimations> AnimationHost::GetElementAnimationsForLayerId( |
| 330 int layer_id) const { | 331 ElementId element_id) const { |
| 331 DCHECK(layer_id); | 332 DCHECK(element_id); |
| 332 auto iter = layer_to_element_animations_map_.find(layer_id); | 333 auto iter = layer_to_element_animations_map_.find(element_id); |
| 333 return iter == layer_to_element_animations_map_.end() ? nullptr | 334 return iter == layer_to_element_animations_map_.end() ? nullptr |
| 334 : iter->second; | 335 : iter->second; |
| 335 } | 336 } |
| 336 | 337 |
| 337 void AnimationHost::SetSupportsScrollAnimations( | 338 void AnimationHost::SetSupportsScrollAnimations( |
| 338 bool supports_scroll_animations) { | 339 bool supports_scroll_animations) { |
| 339 supports_scroll_animations_ = supports_scroll_animations; | 340 supports_scroll_animations_ = supports_scroll_animations; |
| 340 } | 341 } |
| 341 | 342 |
| 342 bool AnimationHost::SupportsScrollAnimations() const { | 343 bool AnimationHost::SupportsScrollAnimations() const { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 } | 389 } |
| 389 | 390 |
| 390 std::unique_ptr<AnimationEvents> AnimationHost::CreateEvents() { | 391 std::unique_ptr<AnimationEvents> AnimationHost::CreateEvents() { |
| 391 return base::WrapUnique(new AnimationEvents()); | 392 return base::WrapUnique(new AnimationEvents()); |
| 392 } | 393 } |
| 393 | 394 |
| 394 void AnimationHost::SetAnimationEvents( | 395 void AnimationHost::SetAnimationEvents( |
| 395 std::unique_ptr<AnimationEvents> events) { | 396 std::unique_ptr<AnimationEvents> events) { |
| 396 for (size_t event_index = 0; event_index < events->events_.size(); | 397 for (size_t event_index = 0; event_index < events->events_.size(); |
| 397 ++event_index) { | 398 ++event_index) { |
| 398 int event_layer_id = events->events_[event_index].layer_id; | 399 int event_layer_id = events->events_[event_index].element_id; |
| 399 | 400 |
| 400 // Use the map of all ElementAnimations, not just active ones, since | 401 // Use the map of all ElementAnimations, not just active ones, since |
| 401 // non-active ElementAnimations may still receive events for impl-only | 402 // non-active ElementAnimations may still receive events for impl-only |
| 402 // animations. | 403 // animations. |
| 403 const LayerToElementAnimationsMap& all_element_animations = | 404 const LayerToElementAnimationsMap& all_element_animations = |
| 404 layer_to_element_animations_map_; | 405 layer_to_element_animations_map_; |
| 405 auto iter = all_element_animations.find(event_layer_id); | 406 auto iter = all_element_animations.find(event_layer_id); |
| 406 if (iter != all_element_animations.end()) { | 407 if (iter != all_element_animations.end()) { |
| 407 switch (events->events_[event_index].type) { | 408 switch (events->events_[event_index].type) { |
| 408 case AnimationEvent::STARTED: | 409 case AnimationEvent::STARTED: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 423 break; | 424 break; |
| 424 | 425 |
| 425 case AnimationEvent::TAKEOVER: | 426 case AnimationEvent::TAKEOVER: |
| 426 (*iter).second->NotifyAnimationTakeover(events->events_[event_index]); | 427 (*iter).second->NotifyAnimationTakeover(events->events_[event_index]); |
| 427 break; | 428 break; |
| 428 } | 429 } |
| 429 } | 430 } |
| 430 } | 431 } |
| 431 } | 432 } |
| 432 | 433 |
| 433 bool AnimationHost::ScrollOffsetAnimationWasInterrupted(int layer_id) const { | 434 bool AnimationHost::ScrollOffsetAnimationWasInterrupted( |
| 434 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 435 ElementId element_id) const { |
| 436 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 435 return element_animations | 437 return element_animations |
| 436 ? element_animations->scroll_offset_animation_was_interrupted() | 438 ? element_animations->scroll_offset_animation_was_interrupted() |
| 437 : false; | 439 : false; |
| 438 } | 440 } |
| 439 | 441 |
| 440 bool AnimationHost::IsAnimatingFilterProperty(int layer_id, | 442 bool AnimationHost::IsAnimatingFilterProperty(ElementId element_id, |
| 441 LayerTreeType tree_type) const { | 443 LayerTreeType tree_type) const { |
| 442 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 444 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 443 return element_animations | 445 return element_animations |
| 444 ? element_animations->IsCurrentlyAnimatingProperty( | 446 ? element_animations->IsCurrentlyAnimatingProperty( |
| 445 TargetProperty::FILTER, tree_type) | 447 TargetProperty::FILTER, tree_type) |
| 446 : false; | 448 : false; |
| 447 } | 449 } |
| 448 | 450 |
| 449 bool AnimationHost::IsAnimatingOpacityProperty(int layer_id, | 451 bool AnimationHost::IsAnimatingOpacityProperty(ElementId element_id, |
| 450 LayerTreeType tree_type) const { | 452 LayerTreeType tree_type) const { |
| 451 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 453 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 452 return element_animations | 454 return element_animations |
| 453 ? element_animations->IsCurrentlyAnimatingProperty( | 455 ? element_animations->IsCurrentlyAnimatingProperty( |
| 454 TargetProperty::OPACITY, tree_type) | 456 TargetProperty::OPACITY, tree_type) |
| 455 : false; | 457 : false; |
| 456 } | 458 } |
| 457 | 459 |
| 458 bool AnimationHost::IsAnimatingTransformProperty( | 460 bool AnimationHost::IsAnimatingTransformProperty( |
| 459 int layer_id, | 461 ElementId element_id, |
| 460 LayerTreeType tree_type) const { | 462 LayerTreeType tree_type) const { |
| 461 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 463 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 462 return element_animations | 464 return element_animations |
| 463 ? element_animations->IsCurrentlyAnimatingProperty( | 465 ? element_animations->IsCurrentlyAnimatingProperty( |
| 464 TargetProperty::TRANSFORM, tree_type) | 466 TargetProperty::TRANSFORM, tree_type) |
| 465 : false; | 467 : false; |
| 466 } | 468 } |
| 467 | 469 |
| 468 bool AnimationHost::HasPotentiallyRunningFilterAnimation( | 470 bool AnimationHost::HasPotentiallyRunningFilterAnimation( |
| 469 int layer_id, | 471 ElementId element_id, |
| 470 LayerTreeType tree_type) const { | 472 LayerTreeType tree_type) const { |
| 471 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 473 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 472 return element_animations | 474 return element_animations |
| 473 ? element_animations->IsPotentiallyAnimatingProperty( | 475 ? element_animations->IsPotentiallyAnimatingProperty( |
| 474 TargetProperty::FILTER, tree_type) | 476 TargetProperty::FILTER, tree_type) |
| 475 : false; | 477 : false; |
| 476 } | 478 } |
| 477 | 479 |
| 478 bool AnimationHost::HasPotentiallyRunningOpacityAnimation( | 480 bool AnimationHost::HasPotentiallyRunningOpacityAnimation( |
| 479 int layer_id, | 481 ElementId element_id, |
| 480 LayerTreeType tree_type) const { | 482 LayerTreeType tree_type) const { |
| 481 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 483 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 482 return element_animations | 484 return element_animations |
| 483 ? element_animations->IsPotentiallyAnimatingProperty( | 485 ? element_animations->IsPotentiallyAnimatingProperty( |
| 484 TargetProperty::OPACITY, tree_type) | 486 TargetProperty::OPACITY, tree_type) |
| 485 : false; | 487 : false; |
| 486 } | 488 } |
| 487 | 489 |
| 488 bool AnimationHost::HasPotentiallyRunningTransformAnimation( | 490 bool AnimationHost::HasPotentiallyRunningTransformAnimation( |
| 489 int layer_id, | 491 ElementId element_id, |
| 490 LayerTreeType tree_type) const { | 492 LayerTreeType tree_type) const { |
| 491 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 493 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 492 return element_animations | 494 return element_animations |
| 493 ? element_animations->IsPotentiallyAnimatingProperty( | 495 ? element_animations->IsPotentiallyAnimatingProperty( |
| 494 TargetProperty::TRANSFORM, tree_type) | 496 TargetProperty::TRANSFORM, tree_type) |
| 495 : false; | 497 : false; |
| 496 } | 498 } |
| 497 | 499 |
| 498 bool AnimationHost::HasAnyAnimationTargetingProperty( | 500 bool AnimationHost::HasAnyAnimationTargetingProperty( |
| 499 int layer_id, | 501 ElementId element_id, |
| 500 TargetProperty::Type property) const { | 502 TargetProperty::Type property) const { |
| 501 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 503 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 502 if (!element_animations) | 504 if (!element_animations) |
| 503 return false; | 505 return false; |
| 504 | 506 |
| 505 return !!element_animations->GetAnimation(property); | 507 return !!element_animations->GetAnimation(property); |
| 506 } | 508 } |
| 507 | 509 |
| 508 bool AnimationHost::FilterIsAnimatingOnImplOnly(int layer_id) const { | 510 bool AnimationHost::FilterIsAnimatingOnImplOnly(ElementId element_id) const { |
| 509 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 511 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 510 if (!element_animations) | 512 if (!element_animations) |
| 511 return false; | 513 return false; |
| 512 | 514 |
| 513 Animation* animation = | 515 Animation* animation = |
| 514 element_animations->GetAnimation(TargetProperty::FILTER); | 516 element_animations->GetAnimation(TargetProperty::FILTER); |
| 515 return animation && animation->is_impl_only(); | 517 return animation && animation->is_impl_only(); |
| 516 } | 518 } |
| 517 | 519 |
| 518 bool AnimationHost::OpacityIsAnimatingOnImplOnly(int layer_id) const { | 520 bool AnimationHost::OpacityIsAnimatingOnImplOnly(ElementId element_id) const { |
| 519 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 521 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 520 if (!element_animations) | 522 if (!element_animations) |
| 521 return false; | 523 return false; |
| 522 | 524 |
| 523 Animation* animation = | 525 Animation* animation = |
| 524 element_animations->GetAnimation(TargetProperty::OPACITY); | 526 element_animations->GetAnimation(TargetProperty::OPACITY); |
| 525 return animation && animation->is_impl_only(); | 527 return animation && animation->is_impl_only(); |
| 526 } | 528 } |
| 527 | 529 |
| 528 bool AnimationHost::ScrollOffsetIsAnimatingOnImplOnly(int layer_id) const { | 530 bool AnimationHost::ScrollOffsetIsAnimatingOnImplOnly( |
| 529 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 531 ElementId element_id) const { |
| 532 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 530 if (!element_animations) | 533 if (!element_animations) |
| 531 return false; | 534 return false; |
| 532 | 535 |
| 533 Animation* animation = | 536 Animation* animation = |
| 534 element_animations->GetAnimation(TargetProperty::SCROLL_OFFSET); | 537 element_animations->GetAnimation(TargetProperty::SCROLL_OFFSET); |
| 535 return animation && animation->is_impl_only(); | 538 return animation && animation->is_impl_only(); |
| 536 } | 539 } |
| 537 | 540 |
| 538 bool AnimationHost::TransformIsAnimatingOnImplOnly(int layer_id) const { | 541 bool AnimationHost::TransformIsAnimatingOnImplOnly(ElementId element_id) const { |
| 539 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 542 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 540 if (!element_animations) | 543 if (!element_animations) |
| 541 return false; | 544 return false; |
| 542 | 545 |
| 543 Animation* animation = | 546 Animation* animation = |
| 544 element_animations->GetAnimation(TargetProperty::TRANSFORM); | 547 element_animations->GetAnimation(TargetProperty::TRANSFORM); |
| 545 return animation && animation->is_impl_only(); | 548 return animation && animation->is_impl_only(); |
| 546 } | 549 } |
| 547 | 550 |
| 548 bool AnimationHost::HasFilterAnimationThatInflatesBounds(int layer_id) const { | 551 bool AnimationHost::HasFilterAnimationThatInflatesBounds( |
| 549 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 552 ElementId element_id) const { |
| 553 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 550 return element_animations | 554 return element_animations |
| 551 ? element_animations->HasFilterAnimationThatInflatesBounds() | 555 ? element_animations->HasFilterAnimationThatInflatesBounds() |
| 552 : false; | 556 : false; |
| 553 } | 557 } |
| 554 | 558 |
| 555 bool AnimationHost::HasTransformAnimationThatInflatesBounds( | 559 bool AnimationHost::HasTransformAnimationThatInflatesBounds( |
| 556 int layer_id) const { | 560 ElementId element_id) const { |
| 557 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 561 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 558 return element_animations | 562 return element_animations |
| 559 ? element_animations->HasTransformAnimationThatInflatesBounds() | 563 ? element_animations->HasTransformAnimationThatInflatesBounds() |
| 560 : false; | 564 : false; |
| 561 } | 565 } |
| 562 | 566 |
| 563 bool AnimationHost::HasAnimationThatInflatesBounds(int layer_id) const { | 567 bool AnimationHost::HasAnimationThatInflatesBounds(ElementId element_id) const { |
| 564 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 568 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 565 return element_animations | 569 return element_animations |
| 566 ? element_animations->HasAnimationThatInflatesBounds() | 570 ? element_animations->HasAnimationThatInflatesBounds() |
| 567 : false; | 571 : false; |
| 568 } | 572 } |
| 569 | 573 |
| 570 bool AnimationHost::FilterAnimationBoundsForBox(int layer_id, | 574 bool AnimationHost::FilterAnimationBoundsForBox(ElementId element_id, |
| 571 const gfx::BoxF& box, | 575 const gfx::BoxF& box, |
| 572 gfx::BoxF* bounds) const { | 576 gfx::BoxF* bounds) const { |
| 573 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 577 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 574 return element_animations | 578 return element_animations |
| 575 ? element_animations->FilterAnimationBoundsForBox(box, bounds) | 579 ? element_animations->FilterAnimationBoundsForBox(box, bounds) |
| 576 : false; | 580 : false; |
| 577 } | 581 } |
| 578 | 582 |
| 579 bool AnimationHost::TransformAnimationBoundsForBox(int layer_id, | 583 bool AnimationHost::TransformAnimationBoundsForBox(ElementId element_id, |
| 580 const gfx::BoxF& box, | 584 const gfx::BoxF& box, |
| 581 gfx::BoxF* bounds) const { | 585 gfx::BoxF* bounds) const { |
| 582 *bounds = gfx::BoxF(); | 586 *bounds = gfx::BoxF(); |
| 583 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 587 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 584 return element_animations | 588 return element_animations |
| 585 ? element_animations->TransformAnimationBoundsForBox(box, bounds) | 589 ? element_animations->TransformAnimationBoundsForBox(box, bounds) |
| 586 : true; | 590 : true; |
| 587 } | 591 } |
| 588 | 592 |
| 589 bool AnimationHost::HasOnlyTranslationTransforms( | 593 bool AnimationHost::HasOnlyTranslationTransforms( |
| 590 int layer_id, | 594 ElementId element_id, |
| 591 LayerTreeType tree_type) const { | 595 LayerTreeType tree_type) const { |
| 592 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 596 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 593 return element_animations | 597 return element_animations |
| 594 ? element_animations->HasOnlyTranslationTransforms(tree_type) | 598 ? element_animations->HasOnlyTranslationTransforms(tree_type) |
| 595 : true; | 599 : true; |
| 596 } | 600 } |
| 597 | 601 |
| 598 bool AnimationHost::AnimationsPreserveAxisAlignment(int layer_id) const { | 602 bool AnimationHost::AnimationsPreserveAxisAlignment( |
| 599 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 603 ElementId element_id) const { |
| 604 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 600 return element_animations | 605 return element_animations |
| 601 ? element_animations->AnimationsPreserveAxisAlignment() | 606 ? element_animations->AnimationsPreserveAxisAlignment() |
| 602 : true; | 607 : true; |
| 603 } | 608 } |
| 604 | 609 |
| 605 bool AnimationHost::MaximumTargetScale(int layer_id, | 610 bool AnimationHost::MaximumTargetScale(ElementId element_id, |
| 606 LayerTreeType tree_type, | 611 LayerTreeType tree_type, |
| 607 float* max_scale) const { | 612 float* max_scale) const { |
| 608 *max_scale = 0.f; | 613 *max_scale = 0.f; |
| 609 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 614 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 610 return element_animations | 615 return element_animations |
| 611 ? element_animations->MaximumTargetScale(tree_type, max_scale) | 616 ? element_animations->MaximumTargetScale(tree_type, max_scale) |
| 612 : true; | 617 : true; |
| 613 } | 618 } |
| 614 | 619 |
| 615 bool AnimationHost::AnimationStartScale(int layer_id, | 620 bool AnimationHost::AnimationStartScale(ElementId element_id, |
| 616 LayerTreeType tree_type, | 621 LayerTreeType tree_type, |
| 617 float* start_scale) const { | 622 float* start_scale) const { |
| 618 *start_scale = 0.f; | 623 *start_scale = 0.f; |
| 619 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 624 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 620 return element_animations | 625 return element_animations |
| 621 ? element_animations->AnimationStartScale(tree_type, start_scale) | 626 ? element_animations->AnimationStartScale(tree_type, start_scale) |
| 622 : true; | 627 : true; |
| 623 } | 628 } |
| 624 | 629 |
| 625 bool AnimationHost::HasAnyAnimation(int layer_id) const { | 630 bool AnimationHost::HasAnyAnimation(ElementId element_id) const { |
| 626 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 631 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 627 return element_animations ? element_animations->has_any_animation() : false; | 632 return element_animations ? element_animations->has_any_animation() : false; |
| 628 } | 633 } |
| 629 | 634 |
| 630 bool AnimationHost::HasActiveAnimationForTesting(int layer_id) const { | 635 bool AnimationHost::HasActiveAnimationForTesting(ElementId element_id) const { |
| 631 auto element_animations = GetElementAnimationsForLayerId(layer_id); | 636 auto element_animations = GetElementAnimationsForLayerId(element_id); |
| 632 return element_animations ? element_animations->HasActiveAnimation() : false; | 637 return element_animations ? element_animations->HasActiveAnimation() : false; |
| 633 } | 638 } |
| 634 | 639 |
| 635 void AnimationHost::ImplOnlyScrollAnimationCreate( | 640 void AnimationHost::ImplOnlyScrollAnimationCreate( |
| 636 int layer_id, | 641 ElementId element_id, |
| 637 const gfx::ScrollOffset& target_offset, | 642 const gfx::ScrollOffset& target_offset, |
| 638 const gfx::ScrollOffset& current_offset) { | 643 const gfx::ScrollOffset& current_offset) { |
| 639 DCHECK(scroll_offset_animations_); | 644 DCHECK(scroll_offset_animations_); |
| 640 scroll_offset_animations_->ScrollAnimationCreate(layer_id, target_offset, | 645 scroll_offset_animations_->ScrollAnimationCreate(element_id, target_offset, |
| 641 current_offset); | 646 current_offset); |
| 642 } | 647 } |
| 643 | 648 |
| 644 bool AnimationHost::ImplOnlyScrollAnimationUpdateTarget( | 649 bool AnimationHost::ImplOnlyScrollAnimationUpdateTarget( |
| 645 int layer_id, | 650 ElementId element_id, |
| 646 const gfx::Vector2dF& scroll_delta, | 651 const gfx::Vector2dF& scroll_delta, |
| 647 const gfx::ScrollOffset& max_scroll_offset, | 652 const gfx::ScrollOffset& max_scroll_offset, |
| 648 base::TimeTicks frame_monotonic_time) { | 653 base::TimeTicks frame_monotonic_time) { |
| 649 DCHECK(scroll_offset_animations_); | 654 DCHECK(scroll_offset_animations_); |
| 650 return scroll_offset_animations_->ScrollAnimationUpdateTarget( | 655 return scroll_offset_animations_->ScrollAnimationUpdateTarget( |
| 651 layer_id, scroll_delta, max_scroll_offset, frame_monotonic_time); | 656 element_id, scroll_delta, max_scroll_offset, frame_monotonic_time); |
| 652 } | 657 } |
| 653 | 658 |
| 654 void AnimationHost::ScrollAnimationAbort(bool needs_completion) { | 659 void AnimationHost::ScrollAnimationAbort(bool needs_completion) { |
| 655 DCHECK(scroll_offset_animations_); | 660 DCHECK(scroll_offset_animations_); |
| 656 return scroll_offset_animations_->ScrollAnimationAbort(needs_completion); | 661 return scroll_offset_animations_->ScrollAnimationAbort(needs_completion); |
| 657 } | 662 } |
| 658 | 663 |
| 659 void AnimationHost::DidActivateElementAnimations( | 664 void AnimationHost::DidActivateElementAnimations( |
| 660 ElementAnimations* element_animations) { | 665 ElementAnimations* element_animations) { |
| 661 DCHECK(element_animations->layer_id()); | 666 DCHECK(element_animations->element_id()); |
| 662 active_element_animations_map_[element_animations->layer_id()] = | 667 active_element_animations_map_[element_animations->element_id()] = |
| 663 element_animations; | 668 element_animations; |
| 664 } | 669 } |
| 665 | 670 |
| 666 void AnimationHost::DidDeactivateElementAnimations( | 671 void AnimationHost::DidDeactivateElementAnimations( |
| 667 ElementAnimations* element_animations) { | 672 ElementAnimations* element_animations) { |
| 668 DCHECK(element_animations->layer_id()); | 673 DCHECK(element_animations->element_id()); |
| 669 active_element_animations_map_.erase(element_animations->layer_id()); | 674 active_element_animations_map_.erase(element_animations->element_id()); |
| 670 } | 675 } |
| 671 | 676 |
| 672 void AnimationHost::RegisterElementAnimations( | 677 void AnimationHost::RegisterElementAnimations( |
| 673 ElementAnimations* element_animations) { | 678 ElementAnimations* element_animations) { |
| 674 DCHECK(element_animations->layer_id()); | 679 DCHECK(element_animations->element_id()); |
| 675 layer_to_element_animations_map_[element_animations->layer_id()] = | 680 layer_to_element_animations_map_[element_animations->element_id()] = |
| 676 element_animations; | 681 element_animations; |
| 677 } | 682 } |
| 678 | 683 |
| 679 void AnimationHost::UnregisterElementAnimations( | 684 void AnimationHost::UnregisterElementAnimations( |
| 680 ElementAnimations* element_animations) { | 685 ElementAnimations* element_animations) { |
| 681 DCHECK(element_animations->layer_id()); | 686 DCHECK(element_animations->element_id()); |
| 682 layer_to_element_animations_map_.erase(element_animations->layer_id()); | 687 layer_to_element_animations_map_.erase(element_animations->element_id()); |
| 683 DidDeactivateElementAnimations(element_animations); | 688 DidDeactivateElementAnimations(element_animations); |
| 684 } | 689 } |
| 685 | 690 |
| 686 const AnimationHost::LayerToElementAnimationsMap& | 691 const AnimationHost::LayerToElementAnimationsMap& |
| 687 AnimationHost::active_element_animations_for_testing() const { | 692 AnimationHost::active_element_animations_for_testing() const { |
| 688 return active_element_animations_map_; | 693 return active_element_animations_map_; |
| 689 } | 694 } |
| 690 | 695 |
| 691 const AnimationHost::LayerToElementAnimationsMap& | 696 const AnimationHost::LayerToElementAnimationsMap& |
| 692 AnimationHost::all_element_animations_for_testing() const { | 697 AnimationHost::all_element_animations_for_testing() const { |
| 693 return layer_to_element_animations_map_; | 698 return layer_to_element_animations_map_; |
| 694 } | 699 } |
| 695 | 700 |
| 696 void AnimationHost::OnAnimationWaitingForDeletion() { | 701 void AnimationHost::OnAnimationWaitingForDeletion() { |
| 697 animation_waiting_for_deletion_ = true; | 702 animation_waiting_for_deletion_ = true; |
| 698 } | 703 } |
| 699 | 704 |
| 700 } // namespace cc | 705 } // namespace cc |
| OLD | NEW |