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 |
(...skipping 24 matching lines...) Expand all Loading... |
35 // An AnimationHost contains all the state required to play animations. | 35 // An AnimationHost contains all the state required to play animations. |
36 // Specifically, it owns all the AnimationTimelines objects. | 36 // Specifically, it owns all the AnimationTimelines objects. |
37 // There is just one AnimationHost for LayerTreeHost on main renderer thread | 37 // There is just one AnimationHost for LayerTreeHost on main renderer thread |
38 // and just one AnimationHost for LayerTreeHostImpl on impl thread. | 38 // and just one AnimationHost for LayerTreeHostImpl on impl thread. |
39 // We synchronize them during the commit process in a one-way data flow process | 39 // We synchronize them during the commit process in a one-way data flow process |
40 // (PushPropertiesTo). | 40 // (PushPropertiesTo). |
41 // An AnimationHost talks to its correspondent LayerTreeHost via | 41 // An AnimationHost talks to its correspondent LayerTreeHost via |
42 // LayerTreeMutatorsClient interface. | 42 // LayerTreeMutatorsClient interface. |
43 class CC_EXPORT AnimationHost { | 43 class CC_EXPORT AnimationHost { |
44 public: | 44 public: |
45 using LayerToElementAnimationsMap = | 45 using ElementToAnimationsMap = |
46 std::unordered_map<int, scoped_refptr<ElementAnimations>>; | 46 std::unordered_map<ElementId, scoped_refptr<ElementAnimations>>; |
47 | 47 |
48 static std::unique_ptr<AnimationHost> Create(ThreadInstance thread_instance); | 48 static std::unique_ptr<AnimationHost> Create(ThreadInstance thread_instance); |
49 ~AnimationHost(); | 49 ~AnimationHost(); |
50 | 50 |
51 void AddAnimationTimeline(scoped_refptr<AnimationTimeline> timeline); | 51 void AddAnimationTimeline(scoped_refptr<AnimationTimeline> timeline); |
52 void RemoveAnimationTimeline(scoped_refptr<AnimationTimeline> timeline); | 52 void RemoveAnimationTimeline(scoped_refptr<AnimationTimeline> timeline); |
53 AnimationTimeline* GetTimelineById(int timeline_id) const; | 53 AnimationTimeline* GetTimelineById(int timeline_id) const; |
54 | 54 |
55 void ClearTimelines(); | 55 void ClearTimelines(); |
56 | 56 |
57 void RegisterLayer(ElementId element_id, LayerTreeType tree_type); | 57 void RegisterElement(ElementId element_id, ElementListType list_type); |
58 void UnregisterLayer(ElementId element_id, LayerTreeType tree_type); | 58 void UnregisterElement(ElementId element_id, ElementListType list_type); |
59 | 59 |
60 void RegisterPlayerForLayer(ElementId element_id, AnimationPlayer* player); | 60 void RegisterPlayerForElement(ElementId element_id, AnimationPlayer* player); |
61 void UnregisterPlayerForLayer(ElementId element_id, AnimationPlayer* player); | 61 void UnregisterPlayerForElement(ElementId element_id, |
| 62 AnimationPlayer* player); |
62 | 63 |
63 scoped_refptr<ElementAnimations> GetElementAnimationsForLayerId( | 64 scoped_refptr<ElementAnimations> GetElementAnimationsForElementId( |
64 ElementId element_id) const; | 65 ElementId element_id) const; |
65 | 66 |
66 // Parent LayerTreeHost or LayerTreeHostImpl. | 67 // Parent LayerTreeHost or LayerTreeHostImpl. |
67 MutatorHostClient* mutator_host_client() { return mutator_host_client_; } | 68 MutatorHostClient* mutator_host_client() { return mutator_host_client_; } |
68 const MutatorHostClient* mutator_host_client() const { | 69 const MutatorHostClient* mutator_host_client() const { |
69 return mutator_host_client_; | 70 return mutator_host_client_; |
70 } | 71 } |
71 void SetMutatorHostClient(MutatorHostClient* client); | 72 void SetMutatorHostClient(MutatorHostClient* client); |
72 | 73 |
73 void SetNeedsCommit(); | 74 void SetNeedsCommit(); |
74 void SetNeedsRebuildPropertyTrees(); | 75 void SetNeedsRebuildPropertyTrees(); |
75 | 76 |
76 void PushPropertiesTo(AnimationHost* host_impl); | 77 void PushPropertiesTo(AnimationHost* host_impl); |
77 | 78 |
78 void SetSupportsScrollAnimations(bool supports_scroll_animations); | 79 void SetSupportsScrollAnimations(bool supports_scroll_animations); |
79 bool SupportsScrollAnimations() const; | 80 bool SupportsScrollAnimations() const; |
80 bool NeedsAnimateLayers() const; | 81 bool NeedsAnimateLayers() const; |
81 | 82 |
82 bool ActivateAnimations(); | 83 bool ActivateAnimations(); |
83 bool AnimateLayers(base::TimeTicks monotonic_time); | 84 bool AnimateLayers(base::TimeTicks monotonic_time); |
84 bool UpdateAnimationState(bool start_ready_animations, | 85 bool UpdateAnimationState(bool start_ready_animations, |
85 AnimationEvents* events); | 86 AnimationEvents* events); |
86 | 87 |
87 std::unique_ptr<AnimationEvents> CreateEvents(); | 88 std::unique_ptr<AnimationEvents> CreateEvents(); |
88 void SetAnimationEvents(std::unique_ptr<AnimationEvents> events); | 89 void SetAnimationEvents(std::unique_ptr<AnimationEvents> events); |
89 | 90 |
90 bool ScrollOffsetAnimationWasInterrupted(ElementId element_id) const; | 91 bool ScrollOffsetAnimationWasInterrupted(ElementId element_id) const; |
91 | 92 |
92 bool IsAnimatingFilterProperty(ElementId element_id, | 93 bool IsAnimatingFilterProperty(ElementId element_id, |
93 LayerTreeType tree_type) const; | 94 ElementListType list_type) const; |
94 bool IsAnimatingOpacityProperty(ElementId element_id, | 95 bool IsAnimatingOpacityProperty(ElementId element_id, |
95 LayerTreeType tree_type) const; | 96 ElementListType list_type) const; |
96 bool IsAnimatingTransformProperty(ElementId element_id, | 97 bool IsAnimatingTransformProperty(ElementId element_id, |
97 LayerTreeType tree_type) const; | 98 ElementListType list_type) const; |
98 | 99 |
99 bool HasPotentiallyRunningFilterAnimation(ElementId element_id, | 100 bool HasPotentiallyRunningFilterAnimation(ElementId element_id, |
100 LayerTreeType tree_type) const; | 101 ElementListType list_type) const; |
101 bool HasPotentiallyRunningOpacityAnimation(ElementId element_id, | 102 bool HasPotentiallyRunningOpacityAnimation(ElementId element_id, |
102 LayerTreeType tree_type) const; | 103 ElementListType list_type) const; |
103 bool HasPotentiallyRunningTransformAnimation(ElementId element_id, | 104 bool HasPotentiallyRunningTransformAnimation(ElementId element_id, |
104 LayerTreeType tree_type) const; | 105 ElementListType list_type) const; |
105 | 106 |
106 bool HasAnyAnimationTargetingProperty(ElementId element_id, | 107 bool HasAnyAnimationTargetingProperty(ElementId element_id, |
107 TargetProperty::Type property) const; | 108 TargetProperty::Type property) const; |
108 | 109 |
109 bool FilterIsAnimatingOnImplOnly(ElementId element_id) const; | 110 bool FilterIsAnimatingOnImplOnly(ElementId element_id) const; |
110 bool OpacityIsAnimatingOnImplOnly(ElementId element_id) const; | 111 bool OpacityIsAnimatingOnImplOnly(ElementId element_id) const; |
111 bool ScrollOffsetIsAnimatingOnImplOnly(ElementId element_id) const; | 112 bool ScrollOffsetIsAnimatingOnImplOnly(ElementId element_id) const; |
112 bool TransformIsAnimatingOnImplOnly(ElementId element_id) const; | 113 bool TransformIsAnimatingOnImplOnly(ElementId element_id) const; |
113 | 114 |
114 bool HasFilterAnimationThatInflatesBounds(ElementId element_id) const; | 115 bool HasFilterAnimationThatInflatesBounds(ElementId element_id) const; |
115 bool HasTransformAnimationThatInflatesBounds(ElementId element_id) const; | 116 bool HasTransformAnimationThatInflatesBounds(ElementId element_id) const; |
116 bool HasAnimationThatInflatesBounds(ElementId element_id) const; | 117 bool HasAnimationThatInflatesBounds(ElementId element_id) const; |
117 | 118 |
118 bool FilterAnimationBoundsForBox(ElementId element_id, | 119 bool FilterAnimationBoundsForBox(ElementId element_id, |
119 const gfx::BoxF& box, | 120 const gfx::BoxF& box, |
120 gfx::BoxF* bounds) const; | 121 gfx::BoxF* bounds) const; |
121 bool TransformAnimationBoundsForBox(ElementId element_id, | 122 bool TransformAnimationBoundsForBox(ElementId element_id, |
122 const gfx::BoxF& box, | 123 const gfx::BoxF& box, |
123 gfx::BoxF* bounds) const; | 124 gfx::BoxF* bounds) const; |
124 | 125 |
125 bool HasOnlyTranslationTransforms(ElementId element_id, | 126 bool HasOnlyTranslationTransforms(ElementId element_id, |
126 LayerTreeType tree_type) const; | 127 ElementListType list_type) const; |
127 bool AnimationsPreserveAxisAlignment(ElementId element_id) const; | 128 bool AnimationsPreserveAxisAlignment(ElementId element_id) const; |
128 | 129 |
129 bool MaximumTargetScale(ElementId element_id, | 130 bool MaximumTargetScale(ElementId element_id, |
130 LayerTreeType tree_type, | 131 ElementListType list_type, |
131 float* max_scale) const; | 132 float* max_scale) const; |
132 bool AnimationStartScale(ElementId element_id, | 133 bool AnimationStartScale(ElementId element_id, |
133 LayerTreeType tree_type, | 134 ElementListType list_type, |
134 float* start_scale) const; | 135 float* start_scale) const; |
135 | 136 |
136 bool HasAnyAnimation(ElementId element_id) const; | 137 bool HasAnyAnimation(ElementId element_id) const; |
137 bool HasActiveAnimationForTesting(ElementId element_id) const; | 138 bool HasActiveAnimationForTesting(ElementId element_id) const; |
138 | 139 |
139 void ImplOnlyScrollAnimationCreate(ElementId element_id, | 140 void ImplOnlyScrollAnimationCreate(ElementId element_id, |
140 const gfx::ScrollOffset& target_offset, | 141 const gfx::ScrollOffset& target_offset, |
141 const gfx::ScrollOffset& current_offset); | 142 const gfx::ScrollOffset& current_offset); |
142 bool ImplOnlyScrollAnimationUpdateTarget( | 143 bool ImplOnlyScrollAnimationUpdateTarget( |
143 ElementId element_id, | 144 ElementId element_id, |
144 const gfx::Vector2dF& scroll_delta, | 145 const gfx::Vector2dF& scroll_delta, |
145 const gfx::ScrollOffset& max_scroll_offset, | 146 const gfx::ScrollOffset& max_scroll_offset, |
146 base::TimeTicks frame_monotonic_time); | 147 base::TimeTicks frame_monotonic_time); |
147 | 148 |
148 void ScrollAnimationAbort(bool needs_completion); | 149 void ScrollAnimationAbort(bool needs_completion); |
149 | 150 |
150 // Registers the given element animations as active. An active element | 151 // Registers the given element animations as active. An active element |
151 // animations is one that has a running animation that needs to be ticked. | 152 // animations is one that has a running animation that needs to be ticked. |
152 void DidActivateElementAnimations(ElementAnimations* element_animations); | 153 void DidActivateElementAnimations(ElementAnimations* element_animations); |
153 | 154 |
154 // Unregisters the given element animations. When this happens, the | 155 // Unregisters the given element animations. When this happens, the |
155 // element animations will no longer be ticked (since it's not active). | 156 // element animations will no longer be ticked (since it's not active). |
156 void DidDeactivateElementAnimations(ElementAnimations* element_animations); | 157 void DidDeactivateElementAnimations(ElementAnimations* element_animations); |
157 | 158 |
158 // Registers the given ElementAnimations as alive. | 159 // Registers the given ElementAnimations as alive. |
159 void RegisterElementAnimations(ElementAnimations* element_animations); | 160 void RegisterElementAnimations(ElementAnimations* element_animations); |
160 // Unregisters the given ElementAnimations as alive. | 161 // Unregisters the given ElementAnimations as alive. |
161 void UnregisterElementAnimations(ElementAnimations* element_animations); | 162 void UnregisterElementAnimations(ElementAnimations* element_animations); |
162 | 163 |
163 const LayerToElementAnimationsMap& active_element_animations_for_testing() | 164 const ElementToAnimationsMap& active_element_animations_for_testing() const; |
164 const; | 165 const ElementToAnimationsMap& all_element_animations_for_testing() const; |
165 const LayerToElementAnimationsMap& all_element_animations_for_testing() const; | |
166 | 166 |
167 bool animation_waiting_for_deletion() const { | 167 bool animation_waiting_for_deletion() const { |
168 return animation_waiting_for_deletion_; | 168 return animation_waiting_for_deletion_; |
169 } | 169 } |
170 void OnAnimationWaitingForDeletion(); | 170 void OnAnimationWaitingForDeletion(); |
171 | 171 |
172 private: | 172 private: |
173 explicit AnimationHost(ThreadInstance thread_instance); | 173 explicit AnimationHost(ThreadInstance thread_instance); |
174 | 174 |
175 void PushTimelinesToImplThread(AnimationHost* host_impl) const; | 175 void PushTimelinesToImplThread(AnimationHost* host_impl) const; |
176 void RemoveTimelinesFromImplThread(AnimationHost* host_impl) const; | 176 void RemoveTimelinesFromImplThread(AnimationHost* host_impl) const; |
177 void PushPropertiesToImplThread(AnimationHost* host_impl); | 177 void PushPropertiesToImplThread(AnimationHost* host_impl); |
178 | 178 |
179 void EraseTimeline(scoped_refptr<AnimationTimeline> timeline); | 179 void EraseTimeline(scoped_refptr<AnimationTimeline> timeline); |
180 | 180 |
181 LayerToElementAnimationsMap layer_to_element_animations_map_; | 181 ElementToAnimationsMap element_to_animations_map_; |
182 LayerToElementAnimationsMap active_element_animations_map_; | 182 ElementToAnimationsMap active_element_to_animations_map_; |
183 | 183 |
184 // A list of all timelines which this host owns. | 184 // A list of all timelines which this host owns. |
185 using IdToTimelineMap = | 185 using IdToTimelineMap = |
186 std::unordered_map<int, scoped_refptr<AnimationTimeline>>; | 186 std::unordered_map<int, scoped_refptr<AnimationTimeline>>; |
187 IdToTimelineMap id_to_timeline_map_; | 187 IdToTimelineMap id_to_timeline_map_; |
188 | 188 |
189 MutatorHostClient* mutator_host_client_; | 189 MutatorHostClient* mutator_host_client_; |
190 | 190 |
191 class ScrollOffsetAnimations; | 191 class ScrollOffsetAnimations; |
192 std::unique_ptr<ScrollOffsetAnimations> scroll_offset_animations_; | 192 std::unique_ptr<ScrollOffsetAnimations> scroll_offset_animations_; |
193 | 193 |
194 const ThreadInstance thread_instance_; | 194 const ThreadInstance thread_instance_; |
195 | 195 |
196 bool supports_scroll_animations_; | 196 bool supports_scroll_animations_; |
197 bool animation_waiting_for_deletion_; | 197 bool animation_waiting_for_deletion_; |
198 | 198 |
199 DISALLOW_COPY_AND_ASSIGN(AnimationHost); | 199 DISALLOW_COPY_AND_ASSIGN(AnimationHost); |
200 }; | 200 }; |
201 | 201 |
202 } // namespace cc | 202 } // namespace cc |
203 | 203 |
204 #endif // CC_ANIMATION_ANIMATION_HOST_H_ | 204 #endif // CC_ANIMATION_ANIMATION_HOST_H_ |
OLD | NEW |