| 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 10 matching lines...) Expand all Loading... |
| 21 namespace gfx { | 21 namespace gfx { |
| 22 class ScrollOffset; | 22 class ScrollOffset; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace cc { | 25 namespace cc { |
| 26 | 26 |
| 27 class AnimationEvents; | 27 class AnimationEvents; |
| 28 class AnimationPlayer; | 28 class AnimationPlayer; |
| 29 class AnimationTimeline; | 29 class AnimationTimeline; |
| 30 class ElementAnimations; | 30 class ElementAnimations; |
| 31 class LayerAnimationController; | |
| 32 class LayerTreeHost; | 31 class LayerTreeHost; |
| 33 | 32 |
| 34 enum class ThreadInstance { MAIN, IMPL }; | 33 enum class ThreadInstance { MAIN, IMPL }; |
| 35 | 34 |
| 36 // An AnimationHost contains all the state required to play animations. | 35 // An AnimationHost contains all the state required to play animations. |
| 37 // Specifically, it owns all the AnimationTimelines objects. | 36 // Specifically, it owns all the AnimationTimelines objects. |
| 38 // There is just one AnimationHost for LayerTreeHost on main renderer thread | 37 // There is just one AnimationHost for LayerTreeHost on main renderer thread |
| 39 // and just one AnimationHost for LayerTreeHostImpl on impl thread. | 38 // and just one AnimationHost for LayerTreeHostImpl on impl thread. |
| 40 // 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 |
| 41 // (PushPropertiesTo). | 40 // (PushPropertiesTo). |
| 42 // An AnimationHost talks to its correspondent LayerTreeHost via | 41 // An AnimationHost talks to its correspondent LayerTreeHost via |
| 43 // LayerTreeMutatorsClient interface. | 42 // LayerTreeMutatorsClient interface. |
| 44 class CC_EXPORT AnimationHost { | 43 class CC_EXPORT AnimationHost { |
| 45 public: | 44 public: |
| 46 using AnimationControllerMap = | 45 using LayerToElementAnimationsMap = |
| 47 std::unordered_map<int, LayerAnimationController*>; | 46 std::unordered_map<int, scoped_refptr<ElementAnimations>>; |
| 48 | 47 |
| 49 static std::unique_ptr<AnimationHost> Create(ThreadInstance thread_instance); | 48 static std::unique_ptr<AnimationHost> Create(ThreadInstance thread_instance); |
| 50 ~AnimationHost(); | 49 ~AnimationHost(); |
| 51 | 50 |
| 52 void AddAnimationTimeline(scoped_refptr<AnimationTimeline> timeline); | 51 void AddAnimationTimeline(scoped_refptr<AnimationTimeline> timeline); |
| 53 void RemoveAnimationTimeline(scoped_refptr<AnimationTimeline> timeline); | 52 void RemoveAnimationTimeline(scoped_refptr<AnimationTimeline> timeline); |
| 54 AnimationTimeline* GetTimelineById(int timeline_id) const; | 53 AnimationTimeline* GetTimelineById(int timeline_id) const; |
| 55 | 54 |
| 56 void ClearTimelines(); | 55 void ClearTimelines(); |
| 57 | 56 |
| 58 void RegisterLayer(int layer_id, LayerTreeType tree_type); | 57 void RegisterLayer(int layer_id, LayerTreeType tree_type); |
| 59 void UnregisterLayer(int layer_id, LayerTreeType tree_type); | 58 void UnregisterLayer(int layer_id, LayerTreeType tree_type); |
| 60 | 59 |
| 61 void RegisterPlayerForLayer(int layer_id, AnimationPlayer* player); | 60 void RegisterPlayerForLayer(int layer_id, AnimationPlayer* player); |
| 62 void UnregisterPlayerForLayer(int layer_id, AnimationPlayer* player); | 61 void UnregisterPlayerForLayer(int layer_id, AnimationPlayer* player); |
| 63 | 62 |
| 64 scoped_refptr<ElementAnimations> GetElementAnimationsForLayerId( | 63 scoped_refptr<ElementAnimations> GetElementAnimationsForLayerId( |
| 65 int layer_id) const; | 64 int layer_id) const; |
| 66 | 65 |
| 67 // TODO(loyso): Get rid of LayerAnimationController. | |
| 68 LayerAnimationController* GetControllerForLayerId(int layer_id) const; | |
| 69 | |
| 70 // Parent LayerTreeHost or LayerTreeHostImpl. | 66 // Parent LayerTreeHost or LayerTreeHostImpl. |
| 71 MutatorHostClient* mutator_host_client() { return mutator_host_client_; } | 67 MutatorHostClient* mutator_host_client() { return mutator_host_client_; } |
| 72 const MutatorHostClient* mutator_host_client() const { | 68 const MutatorHostClient* mutator_host_client() const { |
| 73 return mutator_host_client_; | 69 return mutator_host_client_; |
| 74 } | 70 } |
| 75 void SetMutatorHostClient(MutatorHostClient* client); | 71 void SetMutatorHostClient(MutatorHostClient* client); |
| 76 | 72 |
| 77 void SetNeedsCommit(); | 73 void SetNeedsCommit(); |
| 78 void SetNeedsRebuildPropertyTrees(); | 74 void SetNeedsRebuildPropertyTrees(); |
| 79 | 75 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 const gfx::ScrollOffset& target_offset, | 138 const gfx::ScrollOffset& target_offset, |
| 143 const gfx::ScrollOffset& current_offset); | 139 const gfx::ScrollOffset& current_offset); |
| 144 bool ImplOnlyScrollAnimationUpdateTarget( | 140 bool ImplOnlyScrollAnimationUpdateTarget( |
| 145 int layer_id, | 141 int layer_id, |
| 146 const gfx::Vector2dF& scroll_delta, | 142 const gfx::Vector2dF& scroll_delta, |
| 147 const gfx::ScrollOffset& max_scroll_offset, | 143 const gfx::ScrollOffset& max_scroll_offset, |
| 148 base::TimeTicks frame_monotonic_time); | 144 base::TimeTicks frame_monotonic_time); |
| 149 | 145 |
| 150 void ScrollAnimationAbort(bool needs_completion); | 146 void ScrollAnimationAbort(bool needs_completion); |
| 151 | 147 |
| 152 // If an animation has been registered for the given id, return it. Otherwise | 148 // Registers the given element animations as active. An active element |
| 153 // creates a new one and returns a scoped_refptr to it. | 149 // animations is one that has a running animation that needs to be ticked. |
| 154 scoped_refptr<LayerAnimationController> GetAnimationControllerForId(int id); | 150 void DidActivateElementAnimations(ElementAnimations* element_animations); |
| 155 | 151 |
| 156 // Registers the given animation controller as active. An active animation | 152 // Unregisters the given element animations. When this happens, the |
| 157 // controller is one that has a running animation that needs to be ticked. | 153 // element animations will no longer be ticked (since it's not active). |
| 158 void DidActivateAnimationController(LayerAnimationController* controller); | 154 void DidDeactivateElementAnimations(ElementAnimations* element_animations); |
| 159 | 155 |
| 160 // Unregisters the given animation controller. When this happens, the | 156 // Registers the given ElementAnimations as alive. |
| 161 // animation controller will no longer be ticked (since it's not active). It | 157 void RegisterElementAnimations(ElementAnimations* element_animations); |
| 162 // is not an error to call this function with a deactivated controller. | 158 // Unregisters the given ElementAnimations as alive. |
| 163 void DidDeactivateAnimationController(LayerAnimationController* controller); | 159 void UnregisterElementAnimations(ElementAnimations* element_animations); |
| 164 | 160 |
| 165 // Registers the given controller as alive. | 161 const LayerToElementAnimationsMap& active_element_animations_for_testing() |
| 166 void RegisterAnimationController(LayerAnimationController* controller); | 162 const; |
| 167 // Unregisters the given controller as alive. | 163 const LayerToElementAnimationsMap& all_element_animations_for_testing() const; |
| 168 void UnregisterAnimationController(LayerAnimationController* controller); | |
| 169 | 164 |
| 170 const AnimationControllerMap& active_animation_controllers_for_testing() | 165 bool animation_waiting_for_deletion() const { |
| 171 const; | 166 return animation_waiting_for_deletion_; |
| 172 const AnimationControllerMap& all_animation_controllers_for_testing() const; | 167 } |
| 168 void OnAnimationWaitingForDeletion(); |
| 173 | 169 |
| 174 private: | 170 private: |
| 175 explicit AnimationHost(ThreadInstance thread_instance); | 171 explicit AnimationHost(ThreadInstance thread_instance); |
| 176 | 172 |
| 177 void PushTimelinesToImplThread(AnimationHost* host_impl) const; | 173 void PushTimelinesToImplThread(AnimationHost* host_impl) const; |
| 178 void RemoveTimelinesFromImplThread(AnimationHost* host_impl) const; | 174 void RemoveTimelinesFromImplThread(AnimationHost* host_impl) const; |
| 179 void PushPropertiesToImplThread(AnimationHost* host_impl); | 175 void PushPropertiesToImplThread(AnimationHost* host_impl); |
| 180 | 176 |
| 181 void EraseTimeline(scoped_refptr<AnimationTimeline> timeline); | 177 void EraseTimeline(scoped_refptr<AnimationTimeline> timeline); |
| 182 | 178 |
| 183 // AnimationPlayers share ElementAnimations object if they are attached to the | |
| 184 // same element(layer). Note that Element can contain many Layers. | |
| 185 using LayerToElementAnimationsMap = | |
| 186 std::unordered_map<int, scoped_refptr<ElementAnimations>>; | |
| 187 LayerToElementAnimationsMap layer_to_element_animations_map_; | 179 LayerToElementAnimationsMap layer_to_element_animations_map_; |
| 180 LayerToElementAnimationsMap active_element_animations_map_; |
| 188 | 181 |
| 189 // A list of all timelines which this host owns. | 182 // A list of all timelines which this host owns. |
| 190 using IdToTimelineMap = | 183 using IdToTimelineMap = |
| 191 std::unordered_map<int, scoped_refptr<AnimationTimeline>>; | 184 std::unordered_map<int, scoped_refptr<AnimationTimeline>>; |
| 192 IdToTimelineMap id_to_timeline_map_; | 185 IdToTimelineMap id_to_timeline_map_; |
| 193 | 186 |
| 194 AnimationControllerMap active_animation_controllers_; | |
| 195 AnimationControllerMap all_animation_controllers_; | |
| 196 | |
| 197 MutatorHostClient* mutator_host_client_; | 187 MutatorHostClient* mutator_host_client_; |
| 198 | 188 |
| 199 class ScrollOffsetAnimations; | 189 class ScrollOffsetAnimations; |
| 200 std::unique_ptr<ScrollOffsetAnimations> scroll_offset_animations_; | 190 std::unique_ptr<ScrollOffsetAnimations> scroll_offset_animations_; |
| 201 | 191 |
| 202 const ThreadInstance thread_instance_; | 192 const ThreadInstance thread_instance_; |
| 203 | 193 |
| 204 bool supports_scroll_animations_; | 194 bool supports_scroll_animations_; |
| 195 bool animation_waiting_for_deletion_; |
| 205 | 196 |
| 206 DISALLOW_COPY_AND_ASSIGN(AnimationHost); | 197 DISALLOW_COPY_AND_ASSIGN(AnimationHost); |
| 207 }; | 198 }; |
| 208 | 199 |
| 209 } // namespace cc | 200 } // namespace cc |
| 210 | 201 |
| 211 #endif // CC_ANIMATION_ANIMATION_HOST_H_ | 202 #endif // CC_ANIMATION_ANIMATION_HOST_H_ |
| OLD | NEW |