Chromium Code Reviews| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 void AnimationHost::SetNeedsCommit() { | 147 void AnimationHost::SetNeedsCommit() { |
| 142 DCHECK(mutator_host_client_); | 148 DCHECK(mutator_host_client_); |
| 143 mutator_host_client_->SetMutatorsNeedCommit(); | 149 mutator_host_client_->SetMutatorsNeedCommit(); |
| 144 } | 150 } |
| 145 | 151 |
| 146 void AnimationHost::SetNeedsRebuildPropertyTrees() { | 152 void AnimationHost::SetNeedsRebuildPropertyTrees() { |
| 147 DCHECK(mutator_host_client_); | 153 DCHECK(mutator_host_client_); |
| 148 mutator_host_client_->SetMutatorsNeedRebuildPropertyTrees(); | 154 mutator_host_client_->SetMutatorsNeedRebuildPropertyTrees(); |
| 149 } | 155 } |
| 150 | 156 |
| 151 void AnimationHost::PushPropertiesTo(AnimationHost* host_impl) { | 157 void AnimationHost::PushPropertiesTo(AnimationHost* host_impl, |
| 158 base::TimeTicks frame_monotonic_time) { | |
| 152 PushTimelinesToImplThread(host_impl); | 159 PushTimelinesToImplThread(host_impl); |
| 153 RemoveTimelinesFromImplThread(host_impl); | 160 RemoveTimelinesFromImplThread(host_impl); |
| 154 PushPropertiesToImplThread(host_impl); | 161 PushPropertiesToImplThread(host_impl, frame_monotonic_time); |
| 155 animation_waiting_for_deletion_ = false; | 162 animation_waiting_for_deletion_ = false; |
| 156 } | 163 } |
| 157 | 164 |
| 158 void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const { | 165 void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const { |
| 159 for (auto& kv : id_to_timeline_map_) { | 166 for (auto& kv : id_to_timeline_map_) { |
| 160 auto& timeline = kv.second; | 167 auto& timeline = kv.second; |
| 161 AnimationTimeline* timeline_impl = | 168 AnimationTimeline* timeline_impl = |
| 162 host_impl->GetTimelineById(timeline->id()); | 169 host_impl->GetTimelineById(timeline->id()); |
| 163 if (timeline_impl) | 170 if (timeline_impl) |
| 164 continue; | 171 continue; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 177 auto& timeline_impl = it->second; | 184 auto& timeline_impl = it->second; |
| 178 if (timeline_impl->is_impl_only() || GetTimelineById(timeline_impl->id())) { | 185 if (timeline_impl->is_impl_only() || GetTimelineById(timeline_impl->id())) { |
| 179 ++it; | 186 ++it; |
| 180 } else { | 187 } else { |
| 181 host_impl->EraseTimeline(it->second); | 188 host_impl->EraseTimeline(it->second); |
| 182 it = timelines_impl.erase(it); | 189 it = timelines_impl.erase(it); |
| 183 } | 190 } |
| 184 } | 191 } |
| 185 } | 192 } |
| 186 | 193 |
| 187 void AnimationHost::PushPropertiesToImplThread(AnimationHost* host_impl) { | 194 void AnimationHost::PushPropertiesToImplThread( |
| 188 // Firstly, sync all players with impl thread to create ElementAnimations. | 195 AnimationHost* host_impl, |
| 196 base::TimeTicks frame_monotonic_time) { | |
| 197 // Sync all players with impl thread to create ElementAnimations. This needs | |
| 198 // to happen before the element animations are synced below. | |
| 189 for (auto& kv : id_to_timeline_map_) { | 199 for (auto& kv : id_to_timeline_map_) { |
| 190 AnimationTimeline* timeline = kv.second.get(); | 200 AnimationTimeline* timeline = kv.second.get(); |
| 191 AnimationTimeline* timeline_impl = | 201 AnimationTimeline* timeline_impl = |
| 192 host_impl->GetTimelineById(timeline->id()); | 202 host_impl->GetTimelineById(timeline->id()); |
| 193 if (timeline_impl) | 203 if (timeline_impl) |
| 194 timeline->PushPropertiesTo(timeline_impl); | 204 timeline->PushPropertiesTo(timeline_impl); |
| 195 } | 205 } |
| 196 | 206 |
| 197 // Secondly, sync properties for created ElementAnimations. | 207 // Update the impl-only scroll offset animations. This needs to happen |
| 208 // before the sync below because it may add new animations that will need to | |
| 209 // be pushed to the impl thread. | |
|
loyso (OOO)
2016/05/13 01:14:19
"it may add new animations that will need to be pu
ymalik
2016/05/13 03:11:03
You're absolutely right. This doesn't need to happ
| |
| 210 scroll_offset_animations_->PushPropertiesTo( | |
| 211 host_impl->scroll_offset_animations_impl_.get(), frame_monotonic_time); | |
| 212 | |
| 213 // Sync properties for created ElementAnimations. | |
| 198 for (auto& kv : element_to_animations_map_) { | 214 for (auto& kv : element_to_animations_map_) { |
| 199 const auto& element_animations = kv.second; | 215 const auto& element_animations = kv.second; |
| 200 auto element_animations_impl = | 216 auto element_animations_impl = |
| 201 host_impl->GetElementAnimationsForElementId(kv.first); | 217 host_impl->GetElementAnimationsForElementId(kv.first); |
| 202 if (element_animations_impl) | 218 if (element_animations_impl) |
| 203 element_animations->PushPropertiesTo(std::move(element_animations_impl)); | 219 element_animations->PushPropertiesTo(std::move(element_animations_impl)); |
| 204 } | 220 } |
| 205 } | 221 } |
| 206 | 222 |
| 207 scoped_refptr<ElementAnimations> | 223 scoped_refptr<ElementAnimations> |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 bool AnimationHost::ImplOnlyScrollAnimationUpdateTarget( | 542 bool AnimationHost::ImplOnlyScrollAnimationUpdateTarget( |
| 527 ElementId element_id, | 543 ElementId element_id, |
| 528 const gfx::Vector2dF& scroll_delta, | 544 const gfx::Vector2dF& scroll_delta, |
| 529 const gfx::ScrollOffset& max_scroll_offset, | 545 const gfx::ScrollOffset& max_scroll_offset, |
| 530 base::TimeTicks frame_monotonic_time) { | 546 base::TimeTicks frame_monotonic_time) { |
| 531 DCHECK(scroll_offset_animations_impl_); | 547 DCHECK(scroll_offset_animations_impl_); |
| 532 return scroll_offset_animations_impl_->ScrollAnimationUpdateTarget( | 548 return scroll_offset_animations_impl_->ScrollAnimationUpdateTarget( |
| 533 element_id, scroll_delta, max_scroll_offset, frame_monotonic_time); | 549 element_id, scroll_delta, max_scroll_offset, frame_monotonic_time); |
| 534 } | 550 } |
| 535 | 551 |
| 552 ScrollOffsetAnimations& AnimationHost::scroll_offset_animations() const { | |
| 553 DCHECK(scroll_offset_animations_); | |
| 554 return *scroll_offset_animations_.get(); | |
| 555 } | |
| 556 | |
| 536 void AnimationHost::ScrollAnimationAbort(bool needs_completion) { | 557 void AnimationHost::ScrollAnimationAbort(bool needs_completion) { |
| 537 DCHECK(scroll_offset_animations_impl_); | 558 DCHECK(scroll_offset_animations_impl_); |
| 538 return scroll_offset_animations_impl_->ScrollAnimationAbort(needs_completion); | 559 return scroll_offset_animations_impl_->ScrollAnimationAbort(needs_completion); |
| 539 } | 560 } |
| 540 | 561 |
| 541 void AnimationHost::DidActivateElementAnimations( | 562 void AnimationHost::DidActivateElementAnimations( |
| 542 ElementAnimations* element_animations) { | 563 ElementAnimations* element_animations) { |
| 543 DCHECK(element_animations->element_id()); | 564 DCHECK(element_animations->element_id()); |
| 544 active_element_to_animations_map_[element_animations->element_id()] = | 565 active_element_to_animations_map_[element_animations->element_id()] = |
| 545 element_animations; | 566 element_animations; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 573 const AnimationHost::ElementToAnimationsMap& | 594 const AnimationHost::ElementToAnimationsMap& |
| 574 AnimationHost::all_element_animations_for_testing() const { | 595 AnimationHost::all_element_animations_for_testing() const { |
| 575 return element_to_animations_map_; | 596 return element_to_animations_map_; |
| 576 } | 597 } |
| 577 | 598 |
| 578 void AnimationHost::OnAnimationWaitingForDeletion() { | 599 void AnimationHost::OnAnimationWaitingForDeletion() { |
| 579 animation_waiting_for_deletion_ = true; | 600 animation_waiting_for_deletion_ = true; |
| 580 } | 601 } |
| 581 | 602 |
| 582 } // namespace cc | 603 } // namespace cc |
| OLD | NEW |