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 | |
loyso (OOO)
2016/05/11 06:25:44
Code style: Brackets on multiline if else blocks,
ymalik
2016/05/12 22:31:25
Done.
| |
42 scroll_offset_animations_ = | |
43 base::WrapUnique(new ScrollOffsetAnimations(this)); | |
39 } | 44 } |
40 | 45 |
41 AnimationHost::~AnimationHost() { | 46 AnimationHost::~AnimationHost() { |
42 scroll_offset_animations_impl_ = nullptr; | 47 scroll_offset_animations_impl_ = nullptr; |
43 | 48 |
44 ClearTimelines(); | 49 ClearTimelines(); |
45 DCHECK(!mutator_host_client()); | 50 DCHECK(!mutator_host_client()); |
46 DCHECK(element_to_animations_map_.empty()); | 51 DCHECK(element_to_animations_map_.empty()); |
47 } | 52 } |
48 | 53 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 void AnimationHost::SetNeedsCommit() { | 146 void AnimationHost::SetNeedsCommit() { |
142 DCHECK(mutator_host_client_); | 147 DCHECK(mutator_host_client_); |
143 mutator_host_client_->SetMutatorsNeedCommit(); | 148 mutator_host_client_->SetMutatorsNeedCommit(); |
144 } | 149 } |
145 | 150 |
146 void AnimationHost::SetNeedsRebuildPropertyTrees() { | 151 void AnimationHost::SetNeedsRebuildPropertyTrees() { |
147 DCHECK(mutator_host_client_); | 152 DCHECK(mutator_host_client_); |
148 mutator_host_client_->SetMutatorsNeedRebuildPropertyTrees(); | 153 mutator_host_client_->SetMutatorsNeedRebuildPropertyTrees(); |
149 } | 154 } |
150 | 155 |
151 void AnimationHost::PushPropertiesTo(AnimationHost* host_impl) { | 156 void AnimationHost::PushPropertiesTo(AnimationHost* host_impl, |
157 base::TimeTicks frame_monotonic_time) { | |
152 PushTimelinesToImplThread(host_impl); | 158 PushTimelinesToImplThread(host_impl); |
153 RemoveTimelinesFromImplThread(host_impl); | 159 RemoveTimelinesFromImplThread(host_impl); |
154 PushPropertiesToImplThread(host_impl); | 160 PushPropertiesToImplThread(host_impl, frame_monotonic_time); |
155 animation_waiting_for_deletion_ = false; | 161 animation_waiting_for_deletion_ = false; |
156 } | 162 } |
157 | 163 |
158 void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const { | 164 void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const { |
159 for (auto& kv : id_to_timeline_map_) { | 165 for (auto& kv : id_to_timeline_map_) { |
160 auto& timeline = kv.second; | 166 auto& timeline = kv.second; |
161 AnimationTimeline* timeline_impl = | 167 AnimationTimeline* timeline_impl = |
162 host_impl->GetTimelineById(timeline->id()); | 168 host_impl->GetTimelineById(timeline->id()); |
163 if (timeline_impl) | 169 if (timeline_impl) |
164 continue; | 170 continue; |
(...skipping 12 matching lines...) Expand all Loading... | |
177 auto& timeline_impl = it->second; | 183 auto& timeline_impl = it->second; |
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( |
188 // Firstly, sync all players with impl thread to create ElementAnimations. | 194 AnimationHost* host_impl, |
loyso (OOO)
2016/05/11 06:25:44
Firstly, secondly - it meant the constraint on the
ymalik
2016/05/12 22:31:25
I only see value in extracting things out if they'
| |
195 base::TimeTicks frame_monotonic_time) { | |
196 // Sync all players with impl thread to create ElementAnimations. | |
189 for (auto& kv : id_to_timeline_map_) { | 197 for (auto& kv : id_to_timeline_map_) { |
190 AnimationTimeline* timeline = kv.second.get(); | 198 AnimationTimeline* timeline = kv.second.get(); |
191 AnimationTimeline* timeline_impl = | 199 AnimationTimeline* timeline_impl = |
192 host_impl->GetTimelineById(timeline->id()); | 200 host_impl->GetTimelineById(timeline->id()); |
193 if (timeline_impl) | 201 if (timeline_impl) |
194 timeline->PushPropertiesTo(timeline_impl); | 202 timeline->PushPropertiesTo(timeline_impl); |
195 } | 203 } |
196 | 204 |
197 // Secondly, sync properties for created ElementAnimations. | 205 // Update the impl-only scroll offset animations. This needs to happen |
206 // before the sync below because it may add new animations that will need to | |
207 // be pushed to the impl thread. | |
208 scroll_offset_animations_->PushPropertiesTo( | |
209 host_impl->scroll_offset_animations_impl_.get(), frame_monotonic_time); | |
210 | |
211 // Sync properties for created ElementAnimations. | |
198 for (auto& kv : element_to_animations_map_) { | 212 for (auto& kv : element_to_animations_map_) { |
199 const auto& element_animations = kv.second; | 213 const auto& element_animations = kv.second; |
200 auto element_animations_impl = | 214 auto element_animations_impl = |
201 host_impl->GetElementAnimationsForElementId(kv.first); | 215 host_impl->GetElementAnimationsForElementId(kv.first); |
202 if (element_animations_impl) | 216 if (element_animations_impl) |
203 element_animations->PushPropertiesTo(std::move(element_animations_impl)); | 217 element_animations->PushPropertiesTo(std::move(element_animations_impl)); |
204 } | 218 } |
205 } | 219 } |
206 | 220 |
207 scoped_refptr<ElementAnimations> | 221 scoped_refptr<ElementAnimations> |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
526 bool AnimationHost::ImplOnlyScrollAnimationUpdateTarget( | 540 bool AnimationHost::ImplOnlyScrollAnimationUpdateTarget( |
527 ElementId element_id, | 541 ElementId element_id, |
528 const gfx::Vector2dF& scroll_delta, | 542 const gfx::Vector2dF& scroll_delta, |
529 const gfx::ScrollOffset& max_scroll_offset, | 543 const gfx::ScrollOffset& max_scroll_offset, |
530 base::TimeTicks frame_monotonic_time) { | 544 base::TimeTicks frame_monotonic_time) { |
531 DCHECK(scroll_offset_animations_impl_); | 545 DCHECK(scroll_offset_animations_impl_); |
532 return scroll_offset_animations_impl_->ScrollAnimationUpdateTarget( | 546 return scroll_offset_animations_impl_->ScrollAnimationUpdateTarget( |
533 element_id, scroll_delta, max_scroll_offset, frame_monotonic_time); | 547 element_id, scroll_delta, max_scroll_offset, frame_monotonic_time); |
534 } | 548 } |
535 | 549 |
550 ScrollOffsetAnimations& AnimationHost::scroll_offset_animations() const { | |
551 DCHECK(scroll_offset_animations_); | |
552 return *scroll_offset_animations_.get(); | |
553 } | |
554 | |
536 void AnimationHost::ScrollAnimationAbort(bool needs_completion) { | 555 void AnimationHost::ScrollAnimationAbort(bool needs_completion) { |
537 DCHECK(scroll_offset_animations_impl_); | 556 DCHECK(scroll_offset_animations_impl_); |
538 return scroll_offset_animations_impl_->ScrollAnimationAbort(needs_completion); | 557 return scroll_offset_animations_impl_->ScrollAnimationAbort(needs_completion); |
539 } | 558 } |
540 | 559 |
541 void AnimationHost::DidActivateElementAnimations( | 560 void AnimationHost::DidActivateElementAnimations( |
542 ElementAnimations* element_animations) { | 561 ElementAnimations* element_animations) { |
543 DCHECK(element_animations->element_id()); | 562 DCHECK(element_animations->element_id()); |
544 active_element_to_animations_map_[element_animations->element_id()] = | 563 active_element_to_animations_map_[element_animations->element_id()] = |
545 element_animations; | 564 element_animations; |
(...skipping 27 matching lines...) Expand all Loading... | |
573 const AnimationHost::ElementToAnimationsMap& | 592 const AnimationHost::ElementToAnimationsMap& |
574 AnimationHost::all_element_animations_for_testing() const { | 593 AnimationHost::all_element_animations_for_testing() const { |
575 return element_to_animations_map_; | 594 return element_to_animations_map_; |
576 } | 595 } |
577 | 596 |
578 void AnimationHost::OnAnimationWaitingForDeletion() { | 597 void AnimationHost::OnAnimationWaitingForDeletion() { |
579 animation_waiting_for_deletion_ = true; | 598 animation_waiting_for_deletion_ = true; |
580 } | 599 } |
581 | 600 |
582 } // namespace cc | 601 } // namespace cc |
OLD | NEW |