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 #ifndef CC_ANIMATION_ANIMATION_HOST_H_ | 5 #ifndef CC_ANIMATION_ANIMATION_HOST_H_ |
6 #define CC_ANIMATION_ANIMATION_HOST_H_ | 6 #define CC_ANIMATION_ANIMATION_HOST_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <unordered_map> | 9 #include <unordered_map> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "cc/animation/animation.h" | 15 #include "cc/animation/animation.h" |
16 #include "cc/animation/scroll_offset_animations_impl.h" | |
17 #include "cc/base/cc_export.h" | 16 #include "cc/base/cc_export.h" |
18 #include "cc/trees/mutator_host_client.h" | 17 #include "cc/trees/mutator_host_client.h" |
19 #include "ui/gfx/geometry/box_f.h" | 18 #include "ui/gfx/geometry/box_f.h" |
20 #include "ui/gfx/geometry/vector2d_f.h" | 19 #include "ui/gfx/geometry/vector2d_f.h" |
21 | 20 |
22 namespace gfx { | 21 namespace gfx { |
23 class ScrollOffset; | 22 class ScrollOffset; |
24 } | 23 } |
25 | 24 |
26 namespace cc { | 25 namespace cc { |
27 | 26 |
28 class AnimationEvents; | 27 class AnimationEvents; |
29 class AnimationPlayer; | 28 class AnimationPlayer; |
30 class AnimationTimeline; | 29 class AnimationTimeline; |
31 class ElementAnimations; | 30 class ElementAnimations; |
32 class LayerTreeHost; | 31 class LayerTreeHost; |
| 32 class ScrollOffsetAnimations; |
| 33 class ScrollOffsetAnimationsImpl; |
33 | 34 |
34 enum class ThreadInstance { MAIN, IMPL }; | 35 enum class ThreadInstance { MAIN, IMPL }; |
35 | 36 |
36 // An AnimationHost contains all the state required to play animations. | 37 // An AnimationHost contains all the state required to play animations. |
37 // Specifically, it owns all the AnimationTimelines objects. | 38 // Specifically, it owns all the AnimationTimelines objects. |
38 // There is just one AnimationHost for LayerTreeHost on main renderer thread | 39 // There is just one AnimationHost for LayerTreeHost on main renderer thread |
39 // and just one AnimationHost for LayerTreeHostImpl on impl thread. | 40 // and just one AnimationHost for LayerTreeHostImpl on impl thread. |
40 // We synchronize them during the commit process in a one-way data flow process | 41 // We synchronize them during the commit process in a one-way data flow process |
41 // (PushPropertiesTo). | 42 // (PushPropertiesTo). |
42 // An AnimationHost talks to its correspondent LayerTreeHost via | 43 // An AnimationHost talks to its correspondent LayerTreeHost via |
(...skipping 25 matching lines...) Expand all Loading... |
68 // Parent LayerTreeHost or LayerTreeHostImpl. | 69 // Parent LayerTreeHost or LayerTreeHostImpl. |
69 MutatorHostClient* mutator_host_client() { return mutator_host_client_; } | 70 MutatorHostClient* mutator_host_client() { return mutator_host_client_; } |
70 const MutatorHostClient* mutator_host_client() const { | 71 const MutatorHostClient* mutator_host_client() const { |
71 return mutator_host_client_; | 72 return mutator_host_client_; |
72 } | 73 } |
73 void SetMutatorHostClient(MutatorHostClient* client); | 74 void SetMutatorHostClient(MutatorHostClient* client); |
74 | 75 |
75 void SetNeedsCommit(); | 76 void SetNeedsCommit(); |
76 void SetNeedsRebuildPropertyTrees(); | 77 void SetNeedsRebuildPropertyTrees(); |
77 | 78 |
78 void PushPropertiesTo(AnimationHost* host_impl); | 79 void PushPropertiesTo(AnimationHost* host_impl, |
| 80 base::TimeTicks frame_monotonic_time); |
79 | 81 |
80 void SetSupportsScrollAnimations(bool supports_scroll_animations); | 82 void SetSupportsScrollAnimations(bool supports_scroll_animations); |
81 bool SupportsScrollAnimations() const; | 83 bool SupportsScrollAnimations() const; |
82 bool NeedsAnimateLayers() const; | 84 bool NeedsAnimateLayers() const; |
83 | 85 |
84 bool ActivateAnimations(); | 86 bool ActivateAnimations(); |
85 bool AnimateLayers(base::TimeTicks monotonic_time); | 87 bool AnimateLayers(base::TimeTicks monotonic_time); |
86 bool UpdateAnimationState(bool start_ready_animations, | 88 bool UpdateAnimationState(bool start_ready_animations, |
87 AnimationEvents* events); | 89 AnimationEvents* events); |
88 | 90 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 const gfx::ScrollOffset& target_offset, | 144 const gfx::ScrollOffset& target_offset, |
143 const gfx::ScrollOffset& current_offset); | 145 const gfx::ScrollOffset& current_offset); |
144 bool ImplOnlyScrollAnimationUpdateTarget( | 146 bool ImplOnlyScrollAnimationUpdateTarget( |
145 ElementId element_id, | 147 ElementId element_id, |
146 const gfx::Vector2dF& scroll_delta, | 148 const gfx::Vector2dF& scroll_delta, |
147 const gfx::ScrollOffset& max_scroll_offset, | 149 const gfx::ScrollOffset& max_scroll_offset, |
148 base::TimeTicks frame_monotonic_time); | 150 base::TimeTicks frame_monotonic_time); |
149 | 151 |
150 void ScrollAnimationAbort(bool needs_completion); | 152 void ScrollAnimationAbort(bool needs_completion); |
151 | 153 |
| 154 // This should only be called from the main thread. |
| 155 ScrollOffsetAnimations& scroll_offset_animations() const; |
| 156 |
152 // Registers the given element animations as active. An active element | 157 // Registers the given element animations as active. An active element |
153 // animations is one that has a running animation that needs to be ticked. | 158 // animations is one that has a running animation that needs to be ticked. |
154 void DidActivateElementAnimations(ElementAnimations* element_animations); | 159 void DidActivateElementAnimations(ElementAnimations* element_animations); |
155 | 160 |
156 // Unregisters the given element animations. When this happens, the | 161 // Unregisters the given element animations. When this happens, the |
157 // element animations will no longer be ticked (since it's not active). | 162 // element animations will no longer be ticked (since it's not active). |
158 void DidDeactivateElementAnimations(ElementAnimations* element_animations); | 163 void DidDeactivateElementAnimations(ElementAnimations* element_animations); |
159 | 164 |
160 // Registers the given ElementAnimations as alive. | 165 // Registers the given ElementAnimations as alive. |
161 void RegisterElementAnimations(ElementAnimations* element_animations); | 166 void RegisterElementAnimations(ElementAnimations* element_animations); |
162 // Unregisters the given ElementAnimations as alive. | 167 // Unregisters the given ElementAnimations as alive. |
163 void UnregisterElementAnimations(ElementAnimations* element_animations); | 168 void UnregisterElementAnimations(ElementAnimations* element_animations); |
164 | 169 |
165 const ElementToAnimationsMap& active_element_animations_for_testing() const; | 170 const ElementToAnimationsMap& active_element_animations_for_testing() const; |
166 const ElementToAnimationsMap& all_element_animations_for_testing() const; | 171 const ElementToAnimationsMap& all_element_animations_for_testing() const; |
167 | 172 |
168 bool animation_waiting_for_deletion() const { | 173 bool animation_waiting_for_deletion() const { |
169 return animation_waiting_for_deletion_; | 174 return animation_waiting_for_deletion_; |
170 } | 175 } |
171 void OnAnimationWaitingForDeletion(); | 176 void OnAnimationWaitingForDeletion(); |
172 | 177 |
173 private: | 178 private: |
174 explicit AnimationHost(ThreadInstance thread_instance); | 179 explicit AnimationHost(ThreadInstance thread_instance); |
175 | 180 |
176 void PushTimelinesToImplThread(AnimationHost* host_impl) const; | 181 void PushTimelinesToImplThread(AnimationHost* host_impl) const; |
177 void RemoveTimelinesFromImplThread(AnimationHost* host_impl) const; | 182 void RemoveTimelinesFromImplThread(AnimationHost* host_impl) const; |
178 void PushPropertiesToImplThread(AnimationHost* host_impl); | 183 void PushPropertiesToImplThread(AnimationHost* host_impl, |
| 184 base::TimeTicks frame_monotonic_time); |
179 | 185 |
180 void EraseTimeline(scoped_refptr<AnimationTimeline> timeline); | 186 void EraseTimeline(scoped_refptr<AnimationTimeline> timeline); |
181 | 187 |
182 ElementToAnimationsMap element_to_animations_map_; | 188 ElementToAnimationsMap element_to_animations_map_; |
183 ElementToAnimationsMap active_element_to_animations_map_; | 189 ElementToAnimationsMap active_element_to_animations_map_; |
184 | 190 |
185 // A list of all timelines which this host owns. | 191 // A list of all timelines which this host owns. |
186 using IdToTimelineMap = | 192 using IdToTimelineMap = |
187 std::unordered_map<int, scoped_refptr<AnimationTimeline>>; | 193 std::unordered_map<int, scoped_refptr<AnimationTimeline>>; |
188 IdToTimelineMap id_to_timeline_map_; | 194 IdToTimelineMap id_to_timeline_map_; |
189 | 195 |
190 MutatorHostClient* mutator_host_client_; | 196 MutatorHostClient* mutator_host_client_; |
191 | 197 |
| 198 std::unique_ptr<ScrollOffsetAnimations> scroll_offset_animations_; |
192 std::unique_ptr<ScrollOffsetAnimationsImpl> scroll_offset_animations_impl_; | 199 std::unique_ptr<ScrollOffsetAnimationsImpl> scroll_offset_animations_impl_; |
193 | 200 |
194 const ThreadInstance thread_instance_; | 201 const ThreadInstance thread_instance_; |
195 | 202 |
196 bool supports_scroll_animations_; | 203 bool supports_scroll_animations_; |
197 bool animation_waiting_for_deletion_; | 204 bool animation_waiting_for_deletion_; |
198 | 205 |
199 DISALLOW_COPY_AND_ASSIGN(AnimationHost); | 206 DISALLOW_COPY_AND_ASSIGN(AnimationHost); |
200 }; | 207 }; |
201 | 208 |
202 } // namespace cc | 209 } // namespace cc |
203 | 210 |
204 #endif // CC_ANIMATION_ANIMATION_HOST_H_ | 211 #endif // CC_ANIMATION_ANIMATION_HOST_H_ |
OLD | NEW |