| 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_ = base::WrapUnique(new ScrollOffsetAnimations()); |
| 39 } | 43 } |
| 40 | 44 |
| 41 AnimationHost::~AnimationHost() { | 45 AnimationHost::~AnimationHost() { |
| 42 scroll_offset_animations_impl_ = nullptr; | 46 scroll_offset_animations_impl_ = nullptr; |
| 43 | 47 |
| 44 ClearTimelines(); | 48 ClearTimelines(); |
| 45 DCHECK(!mutator_host_client()); | 49 DCHECK(!mutator_host_client()); |
| 46 DCHECK(element_to_animations_map_.empty()); | 50 DCHECK(element_to_animations_map_.empty()); |
| 47 } | 51 } |
| 48 | 52 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 void AnimationHost::SetNeedsCommit() { | 145 void AnimationHost::SetNeedsCommit() { |
| 142 DCHECK(mutator_host_client_); | 146 DCHECK(mutator_host_client_); |
| 143 mutator_host_client_->SetMutatorsNeedCommit(); | 147 mutator_host_client_->SetMutatorsNeedCommit(); |
| 144 } | 148 } |
| 145 | 149 |
| 146 void AnimationHost::SetNeedsRebuildPropertyTrees() { | 150 void AnimationHost::SetNeedsRebuildPropertyTrees() { |
| 147 DCHECK(mutator_host_client_); | 151 DCHECK(mutator_host_client_); |
| 148 mutator_host_client_->SetMutatorsNeedRebuildPropertyTrees(); | 152 mutator_host_client_->SetMutatorsNeedRebuildPropertyTrees(); |
| 149 } | 153 } |
| 150 | 154 |
| 151 void AnimationHost::PushPropertiesTo(AnimationHost* host_impl) { | 155 void AnimationHost::PushPropertiesTo(AnimationHost* host_impl, |
| 156 base::TimeTicks frame_monotonic_time) { |
| 152 PushTimelinesToImplThread(host_impl); | 157 PushTimelinesToImplThread(host_impl); |
| 153 RemoveTimelinesFromImplThread(host_impl); | 158 RemoveTimelinesFromImplThread(host_impl); |
| 154 PushPropertiesToImplThread(host_impl); | 159 PushPropertiesToImplThread(host_impl, frame_monotonic_time); |
| 155 animation_waiting_for_deletion_ = false; | 160 animation_waiting_for_deletion_ = false; |
| 156 } | 161 } |
| 157 | 162 |
| 158 void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const { | 163 void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const { |
| 159 for (auto& kv : id_to_timeline_map_) { | 164 for (auto& kv : id_to_timeline_map_) { |
| 160 auto& timeline = kv.second; | 165 auto& timeline = kv.second; |
| 161 AnimationTimeline* timeline_impl = | 166 AnimationTimeline* timeline_impl = |
| 162 host_impl->GetTimelineById(timeline->id()); | 167 host_impl->GetTimelineById(timeline->id()); |
| 163 if (timeline_impl) | 168 if (timeline_impl) |
| 164 continue; | 169 continue; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 177 auto& timeline_impl = it->second; | 182 auto& timeline_impl = it->second; |
| 178 if (timeline_impl->is_impl_only() || GetTimelineById(timeline_impl->id())) { | 183 if (timeline_impl->is_impl_only() || GetTimelineById(timeline_impl->id())) { |
| 179 ++it; | 184 ++it; |
| 180 } else { | 185 } else { |
| 181 host_impl->EraseTimeline(it->second); | 186 host_impl->EraseTimeline(it->second); |
| 182 it = timelines_impl.erase(it); | 187 it = timelines_impl.erase(it); |
| 183 } | 188 } |
| 184 } | 189 } |
| 185 } | 190 } |
| 186 | 191 |
| 187 void AnimationHost::PushPropertiesToImplThread(AnimationHost* host_impl) { | 192 void AnimationHost::PushPropertiesToImplThread( |
| 188 // Firstly, sync all players with impl thread to create ElementAnimations. | 193 AnimationHost* host_impl, |
| 194 base::TimeTicks frame_monotonic_time) { |
| 195 // Sync all players with impl thread to create ElementAnimations. |
| 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 // Update the impl-only scroll offset animations. This needs to happen |
| 205 // beforethe sync below because it may add new animations that will need to |
| 206 // be pushed to the impl thread. |
| 207 scroll_offset_animations_->PushPropertiesTo( |
| 208 host_impl->scroll_offset_animations_impl_.get(), frame_monotonic_time); |
| 209 |
| 210 // Sync properties for created ElementAnimations. |
| 198 for (auto& kv : element_to_animations_map_) { | 211 for (auto& kv : element_to_animations_map_) { |
| 199 const auto& element_animations = kv.second; | 212 const auto& element_animations = kv.second; |
| 200 auto element_animations_impl = | 213 auto element_animations_impl = |
| 201 host_impl->GetElementAnimationsForElementId(kv.first); | 214 host_impl->GetElementAnimationsForElementId(kv.first); |
| 202 if (element_animations_impl) | 215 if (element_animations_impl) |
| 203 element_animations->PushPropertiesTo(std::move(element_animations_impl)); | 216 element_animations->PushPropertiesTo(std::move(element_animations_impl)); |
| 204 } | 217 } |
| 205 } | 218 } |
| 206 | 219 |
| 207 scoped_refptr<ElementAnimations> | 220 scoped_refptr<ElementAnimations> |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 bool AnimationHost::ImplOnlyScrollAnimationUpdateTarget( | 539 bool AnimationHost::ImplOnlyScrollAnimationUpdateTarget( |
| 527 ElementId element_id, | 540 ElementId element_id, |
| 528 const gfx::Vector2dF& scroll_delta, | 541 const gfx::Vector2dF& scroll_delta, |
| 529 const gfx::ScrollOffset& max_scroll_offset, | 542 const gfx::ScrollOffset& max_scroll_offset, |
| 530 base::TimeTicks frame_monotonic_time) { | 543 base::TimeTicks frame_monotonic_time) { |
| 531 DCHECK(scroll_offset_animations_impl_); | 544 DCHECK(scroll_offset_animations_impl_); |
| 532 return scroll_offset_animations_impl_->ScrollAnimationUpdateTarget( | 545 return scroll_offset_animations_impl_->ScrollAnimationUpdateTarget( |
| 533 element_id, scroll_delta, max_scroll_offset, frame_monotonic_time); | 546 element_id, scroll_delta, max_scroll_offset, frame_monotonic_time); |
| 534 } | 547 } |
| 535 | 548 |
| 549 void AnimationHost::AddScrollOffsetAnimationUpdate( |
| 550 ScrollOffsetAnimationUpdate update) { |
| 551 DCHECK(scroll_offset_animations_); |
| 552 scroll_offset_animations_->AddUpdate(update); |
| 553 SetNeedsCommit(); |
| 554 } |
| 555 |
| 556 bool AnimationHost::HasScrollOffsetAnimationUpdatesForTesting() const { |
| 557 DCHECK(scroll_offset_animations_); |
| 558 return scroll_offset_animations_->HasUpdates(); |
| 559 } |
| 560 |
| 536 void AnimationHost::ScrollAnimationAbort(bool needs_completion) { | 561 void AnimationHost::ScrollAnimationAbort(bool needs_completion) { |
| 537 DCHECK(scroll_offset_animations_impl_); | 562 DCHECK(scroll_offset_animations_impl_); |
| 538 return scroll_offset_animations_impl_->ScrollAnimationAbort(needs_completion); | 563 return scroll_offset_animations_impl_->ScrollAnimationAbort(needs_completion); |
| 539 } | 564 } |
| 540 | 565 |
| 541 void AnimationHost::DidActivateElementAnimations( | 566 void AnimationHost::DidActivateElementAnimations( |
| 542 ElementAnimations* element_animations) { | 567 ElementAnimations* element_animations) { |
| 543 DCHECK(element_animations->element_id()); | 568 DCHECK(element_animations->element_id()); |
| 544 active_element_to_animations_map_[element_animations->element_id()] = | 569 active_element_to_animations_map_[element_animations->element_id()] = |
| 545 element_animations; | 570 element_animations; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 573 const AnimationHost::ElementToAnimationsMap& | 598 const AnimationHost::ElementToAnimationsMap& |
| 574 AnimationHost::all_element_animations_for_testing() const { | 599 AnimationHost::all_element_animations_for_testing() const { |
| 575 return element_to_animations_map_; | 600 return element_to_animations_map_; |
| 576 } | 601 } |
| 577 | 602 |
| 578 void AnimationHost::OnAnimationWaitingForDeletion() { | 603 void AnimationHost::OnAnimationWaitingForDeletion() { |
| 579 animation_waiting_for_deletion_ = true; | 604 animation_waiting_for_deletion_ = true; |
| 580 } | 605 } |
| 581 | 606 |
| 582 } // namespace cc | 607 } // namespace cc |
| OLD | NEW |