| 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/scroll_offset_animations.h" |
| 21 #include "cc/animation/scroll_offset_animations_impl.h" |
| 20 #include "cc/animation/timing_function.h" | 22 #include "cc/animation/timing_function.h" |
| 21 #include "ui/gfx/geometry/box_f.h" | 23 #include "ui/gfx/geometry/box_f.h" |
| 22 #include "ui/gfx/geometry/scroll_offset.h" | 24 #include "ui/gfx/geometry/scroll_offset.h" |
| 23 | 25 |
| 24 namespace cc { | 26 namespace cc { |
| 25 | 27 |
| 26 std::unique_ptr<AnimationHost> AnimationHost::Create( | 28 std::unique_ptr<AnimationHost> AnimationHost::Create( |
| 27 ThreadInstance thread_instance) { | 29 ThreadInstance thread_instance) { |
| 28 return base::WrapUnique(new AnimationHost(thread_instance)); | 30 return base::WrapUnique(new AnimationHost(thread_instance)); |
| 29 } | 31 } |
| 30 | 32 |
| 31 AnimationHost::AnimationHost(ThreadInstance thread_instance) | 33 AnimationHost::AnimationHost(ThreadInstance thread_instance) |
| 32 : mutator_host_client_(nullptr), | 34 : mutator_host_client_(nullptr), |
| 33 thread_instance_(thread_instance), | 35 thread_instance_(thread_instance), |
| 34 supports_scroll_animations_(false), | 36 supports_scroll_animations_(false), |
| 35 animation_waiting_for_deletion_(false) { | 37 animation_waiting_for_deletion_(false) { |
| 36 if (thread_instance_ == ThreadInstance::IMPL) | 38 if (thread_instance_ == ThreadInstance::IMPL) { |
| 37 scroll_offset_animations_impl_ = | 39 scroll_offset_animations_impl_ = |
| 38 base::WrapUnique(new ScrollOffsetAnimationsImpl(this)); | 40 base::WrapUnique(new ScrollOffsetAnimationsImpl(this)); |
| 41 } else { |
| 42 scroll_offset_animations_ = |
| 43 base::WrapUnique(new ScrollOffsetAnimations(this)); |
| 44 } |
| 39 } | 45 } |
| 40 | 46 |
| 41 AnimationHost::~AnimationHost() { | 47 AnimationHost::~AnimationHost() { |
| 42 scroll_offset_animations_impl_ = nullptr; | 48 scroll_offset_animations_impl_ = nullptr; |
| 43 | 49 |
| 44 ClearTimelines(); | 50 ClearTimelines(); |
| 45 DCHECK(!mutator_host_client()); | 51 DCHECK(!mutator_host_client()); |
| 46 DCHECK(element_to_animations_map_.empty()); | 52 DCHECK(element_to_animations_map_.empty()); |
| 47 } | 53 } |
| 48 | 54 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 if (timeline_impl->is_impl_only() || GetTimelineById(timeline_impl->id())) { | 184 if (timeline_impl->is_impl_only() || GetTimelineById(timeline_impl->id())) { |
| 179 ++it; | 185 ++it; |
| 180 } else { | 186 } else { |
| 181 host_impl->EraseTimeline(it->second); | 187 host_impl->EraseTimeline(it->second); |
| 182 it = timelines_impl.erase(it); | 188 it = timelines_impl.erase(it); |
| 183 } | 189 } |
| 184 } | 190 } |
| 185 } | 191 } |
| 186 | 192 |
| 187 void AnimationHost::PushPropertiesToImplThread(AnimationHost* host_impl) { | 193 void AnimationHost::PushPropertiesToImplThread(AnimationHost* host_impl) { |
| 188 // Firstly, sync all players with impl thread to create ElementAnimations. | 194 // Sync all players with impl thread to create ElementAnimations. This needs |
| 195 // to happen before the element animations are synced below. |
| 189 for (auto& kv : id_to_timeline_map_) { | 196 for (auto& kv : id_to_timeline_map_) { |
| 190 AnimationTimeline* timeline = kv.second.get(); | 197 AnimationTimeline* timeline = kv.second.get(); |
| 191 AnimationTimeline* timeline_impl = | 198 AnimationTimeline* timeline_impl = |
| 192 host_impl->GetTimelineById(timeline->id()); | 199 host_impl->GetTimelineById(timeline->id()); |
| 193 if (timeline_impl) | 200 if (timeline_impl) |
| 194 timeline->PushPropertiesTo(timeline_impl); | 201 timeline->PushPropertiesTo(timeline_impl); |
| 195 } | 202 } |
| 196 | 203 |
| 197 // Secondly, sync properties for created ElementAnimations. | 204 // Sync properties for created ElementAnimations. |
| 198 for (auto& kv : element_to_animations_map_) { | 205 for (auto& kv : element_to_animations_map_) { |
| 199 const auto& element_animations = kv.second; | 206 const auto& element_animations = kv.second; |
| 200 auto element_animations_impl = | 207 auto element_animations_impl = |
| 201 host_impl->GetElementAnimationsForElementId(kv.first); | 208 host_impl->GetElementAnimationsForElementId(kv.first); |
| 202 if (element_animations_impl) | 209 if (element_animations_impl) |
| 203 element_animations->PushPropertiesTo(std::move(element_animations_impl)); | 210 element_animations->PushPropertiesTo(std::move(element_animations_impl)); |
| 204 } | 211 } |
| 212 |
| 213 // Update the impl-only scroll offset animations. |
| 214 scroll_offset_animations_->PushPropertiesTo( |
| 215 host_impl->scroll_offset_animations_impl_.get()); |
| 205 } | 216 } |
| 206 | 217 |
| 207 scoped_refptr<ElementAnimations> | 218 scoped_refptr<ElementAnimations> |
| 208 AnimationHost::GetElementAnimationsForElementId(ElementId element_id) const { | 219 AnimationHost::GetElementAnimationsForElementId(ElementId element_id) const { |
| 209 DCHECK(element_id); | 220 DCHECK(element_id); |
| 210 auto iter = element_to_animations_map_.find(element_id); | 221 auto iter = element_to_animations_map_.find(element_id); |
| 211 return iter == element_to_animations_map_.end() ? nullptr : iter->second; | 222 return iter == element_to_animations_map_.end() ? nullptr : iter->second; |
| 212 } | 223 } |
| 213 | 224 |
| 214 void AnimationHost::SetSupportsScrollAnimations( | 225 void AnimationHost::SetSupportsScrollAnimations( |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 bool AnimationHost::ImplOnlyScrollAnimationUpdateTarget( | 537 bool AnimationHost::ImplOnlyScrollAnimationUpdateTarget( |
| 527 ElementId element_id, | 538 ElementId element_id, |
| 528 const gfx::Vector2dF& scroll_delta, | 539 const gfx::Vector2dF& scroll_delta, |
| 529 const gfx::ScrollOffset& max_scroll_offset, | 540 const gfx::ScrollOffset& max_scroll_offset, |
| 530 base::TimeTicks frame_monotonic_time) { | 541 base::TimeTicks frame_monotonic_time) { |
| 531 DCHECK(scroll_offset_animations_impl_); | 542 DCHECK(scroll_offset_animations_impl_); |
| 532 return scroll_offset_animations_impl_->ScrollAnimationUpdateTarget( | 543 return scroll_offset_animations_impl_->ScrollAnimationUpdateTarget( |
| 533 element_id, scroll_delta, max_scroll_offset, frame_monotonic_time); | 544 element_id, scroll_delta, max_scroll_offset, frame_monotonic_time); |
| 534 } | 545 } |
| 535 | 546 |
| 547 ScrollOffsetAnimations& AnimationHost::scroll_offset_animations() const { |
| 548 DCHECK(scroll_offset_animations_); |
| 549 return *scroll_offset_animations_.get(); |
| 550 } |
| 551 |
| 536 void AnimationHost::ScrollAnimationAbort(bool needs_completion) { | 552 void AnimationHost::ScrollAnimationAbort(bool needs_completion) { |
| 537 DCHECK(scroll_offset_animations_impl_); | 553 DCHECK(scroll_offset_animations_impl_); |
| 538 return scroll_offset_animations_impl_->ScrollAnimationAbort(needs_completion); | 554 return scroll_offset_animations_impl_->ScrollAnimationAbort(needs_completion); |
| 539 } | 555 } |
| 540 | 556 |
| 541 void AnimationHost::DidActivateElementAnimations( | 557 void AnimationHost::DidActivateElementAnimations( |
| 542 ElementAnimations* element_animations) { | 558 ElementAnimations* element_animations) { |
| 543 DCHECK(element_animations->element_id()); | 559 DCHECK(element_animations->element_id()); |
| 544 active_element_to_animations_map_[element_animations->element_id()] = | 560 active_element_to_animations_map_[element_animations->element_id()] = |
| 545 element_animations; | 561 element_animations; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 573 const AnimationHost::ElementToAnimationsMap& | 589 const AnimationHost::ElementToAnimationsMap& |
| 574 AnimationHost::all_element_animations_for_testing() const { | 590 AnimationHost::all_element_animations_for_testing() const { |
| 575 return element_to_animations_map_; | 591 return element_to_animations_map_; |
| 576 } | 592 } |
| 577 | 593 |
| 578 void AnimationHost::OnAnimationWaitingForDeletion() { | 594 void AnimationHost::OnAnimationWaitingForDeletion() { |
| 579 animation_waiting_for_deletion_ = true; | 595 animation_waiting_for_deletion_ = true; |
| 580 } | 596 } |
| 581 | 597 |
| 582 } // namespace cc | 598 } // namespace cc |
| OLD | NEW |