| 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/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 14 #include "cc/animation/animation.h" | 15 #include "cc/animation/animation.h" |
| 15 #include "cc/base/cc_export.h" | 16 #include "cc/base/cc_export.h" |
| 16 #include "cc/trees/mutator_host_client.h" | 17 #include "cc/trees/mutator_host_client.h" |
| 17 #include "ui/gfx/geometry/box_f.h" | 18 #include "ui/gfx/geometry/box_f.h" |
| 18 #include "ui/gfx/geometry/vector2d_f.h" | 19 #include "ui/gfx/geometry/vector2d_f.h" |
| 19 | 20 |
| 20 namespace gfx { | 21 namespace gfx { |
| 21 class ScrollOffset; | 22 class ScrollOffset; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace cc { | 25 namespace cc { |
| 25 | 26 |
| 26 class AnimationEvents; | 27 class AnimationEvents; |
| 27 class AnimationPlayer; | 28 class AnimationPlayer; |
| 28 class AnimationRegistrar; | |
| 29 class AnimationTimeline; | 29 class AnimationTimeline; |
| 30 class ElementAnimations; | 30 class ElementAnimations; |
| 31 class LayerAnimationController; | 31 class LayerAnimationController; |
| 32 class LayerTreeHost; | 32 class LayerTreeHost; |
| 33 | 33 |
| 34 enum class ThreadInstance { MAIN, IMPL }; | 34 enum class ThreadInstance { MAIN, IMPL }; |
| 35 | 35 |
| 36 // An AnimationHost contains all the state required to play animations. | 36 // An AnimationHost contains all the state required to play animations. |
| 37 // Specifically, it owns all the AnimationTimelines objects. | 37 // Specifically, it owns all the AnimationTimelines objects. |
| 38 // There is just one AnimationHost for LayerTreeHost on main renderer thread | 38 // There is just one AnimationHost for LayerTreeHost on main renderer thread |
| 39 // and just one AnimationHost for LayerTreeHostImpl on impl thread. | 39 // and just one AnimationHost for LayerTreeHostImpl on impl thread. |
| 40 // We synchronize them during the commit process in a one-way data flow process | 40 // We synchronize them during the commit process in a one-way data flow process |
| 41 // (PushPropertiesTo). | 41 // (PushPropertiesTo). |
| 42 // An AnimationHost talks to its correspondent LayerTreeHost via | 42 // An AnimationHost talks to its correspondent LayerTreeHost via |
| 43 // LayerTreeMutatorsClient interface. | 43 // LayerTreeMutatorsClient interface. |
| 44 // AnimationHost has it's own instance of AnimationRegistrar, | |
| 45 // we want to merge AnimationRegistrar into AnimationHost. | |
| 46 class CC_EXPORT AnimationHost { | 44 class CC_EXPORT AnimationHost { |
| 47 public: | 45 public: |
| 46 using AnimationControllerMap = |
| 47 std::unordered_map<int, LayerAnimationController*>; |
| 48 |
| 48 static std::unique_ptr<AnimationHost> Create(ThreadInstance thread_instance); | 49 static std::unique_ptr<AnimationHost> Create(ThreadInstance thread_instance); |
| 49 virtual ~AnimationHost(); | 50 ~AnimationHost(); |
| 50 | 51 |
| 51 void AddAnimationTimeline(scoped_refptr<AnimationTimeline> timeline); | 52 void AddAnimationTimeline(scoped_refptr<AnimationTimeline> timeline); |
| 52 void RemoveAnimationTimeline(scoped_refptr<AnimationTimeline> timeline); | 53 void RemoveAnimationTimeline(scoped_refptr<AnimationTimeline> timeline); |
| 53 AnimationTimeline* GetTimelineById(int timeline_id) const; | 54 AnimationTimeline* GetTimelineById(int timeline_id) const; |
| 54 | 55 |
| 55 void ClearTimelines(); | 56 void ClearTimelines(); |
| 56 | 57 |
| 57 void RegisterLayer(int layer_id, LayerTreeType tree_type); | 58 void RegisterLayer(int layer_id, LayerTreeType tree_type); |
| 58 void UnregisterLayer(int layer_id, LayerTreeType tree_type); | 59 void UnregisterLayer(int layer_id, LayerTreeType tree_type); |
| 59 | 60 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // If an animation has been registered for the given id, return it. Otherwise | 151 // If an animation has been registered for the given id, return it. Otherwise |
| 151 // creates a new one and returns a scoped_refptr to it. | 152 // creates a new one and returns a scoped_refptr to it. |
| 152 scoped_refptr<LayerAnimationController> GetAnimationControllerForId(int id); | 153 scoped_refptr<LayerAnimationController> GetAnimationControllerForId(int id); |
| 153 | 154 |
| 154 void SetAnimationRegistrarFor( | 155 // Registers the given animation controller as active. An active animation |
| 155 scoped_refptr<LayerAnimationController> controller); | 156 // controller is one that has a running animation that needs to be ticked. |
| 156 void ResetAnimationRegistrarFor( | 157 void DidActivateAnimationController(LayerAnimationController* controller); |
| 157 scoped_refptr<LayerAnimationController> controller); | 158 |
| 159 // Unregisters the given animation controller. When this happens, the |
| 160 // animation controller will no longer be ticked (since it's not active). It |
| 161 // is not an error to call this function with a deactivated controller. |
| 162 void DidDeactivateAnimationController(LayerAnimationController* controller); |
| 158 | 163 |
| 159 // Registers the given controller as alive. | 164 // Registers the given controller as alive. |
| 160 void RegisterAnimationController(LayerAnimationController* controller); | 165 void RegisterAnimationController(LayerAnimationController* controller); |
| 161 // Unregisters the given controller as alive. | 166 // Unregisters the given controller as alive. |
| 162 void UnregisterAnimationController(LayerAnimationController* controller); | 167 void UnregisterAnimationController(LayerAnimationController* controller); |
| 163 | 168 |
| 164 using AnimationControllerMap = | |
| 165 std::unordered_map<int, LayerAnimationController*>; | |
| 166 const AnimationControllerMap& active_animation_controllers_for_testing() | 169 const AnimationControllerMap& active_animation_controllers_for_testing() |
| 167 const; | 170 const; |
| 168 const AnimationControllerMap& all_animation_controllers_for_testing() const; | 171 const AnimationControllerMap& all_animation_controllers_for_testing() const; |
| 169 | 172 |
| 170 private: | 173 private: |
| 171 explicit AnimationHost(ThreadInstance thread_instance); | 174 explicit AnimationHost(ThreadInstance thread_instance); |
| 172 | 175 |
| 173 void PushTimelinesToImplThread(AnimationHost* host_impl) const; | 176 void PushTimelinesToImplThread(AnimationHost* host_impl) const; |
| 174 void RemoveTimelinesFromImplThread(AnimationHost* host_impl) const; | 177 void RemoveTimelinesFromImplThread(AnimationHost* host_impl) const; |
| 175 void PushPropertiesToImplThread(AnimationHost* host_impl); | 178 void PushPropertiesToImplThread(AnimationHost* host_impl); |
| 176 | 179 |
| 177 void EraseTimeline(scoped_refptr<AnimationTimeline> timeline); | 180 void EraseTimeline(scoped_refptr<AnimationTimeline> timeline); |
| 178 | 181 |
| 179 // TODO(loyso): For now AnimationPlayers share LayerAnimationController object | 182 // TODO(loyso): For now AnimationPlayers share LayerAnimationController object |
| 180 // if they are attached to the same element(layer). Note that Element can | 183 // if they are attached to the same element(layer). Note that Element can |
| 181 // contain many Layers. | 184 // contain many Layers. |
| 182 using LayerToElementAnimationsMap = | 185 using LayerToElementAnimationsMap = |
| 183 std::unordered_map<int, std::unique_ptr<ElementAnimations>>; | 186 std::unordered_map<int, std::unique_ptr<ElementAnimations>>; |
| 184 LayerToElementAnimationsMap layer_to_element_animations_map_; | 187 LayerToElementAnimationsMap layer_to_element_animations_map_; |
| 185 | 188 |
| 186 // A list of all timelines which this host owns. | 189 // A list of all timelines which this host owns. |
| 187 using IdToTimelineMap = | 190 using IdToTimelineMap = |
| 188 std::unordered_map<int, scoped_refptr<AnimationTimeline>>; | 191 std::unordered_map<int, scoped_refptr<AnimationTimeline>>; |
| 189 IdToTimelineMap id_to_timeline_map_; | 192 IdToTimelineMap id_to_timeline_map_; |
| 190 | 193 |
| 191 std::unique_ptr<AnimationRegistrar> animation_registrar_; | 194 AnimationControllerMap active_animation_controllers_; |
| 195 AnimationControllerMap all_animation_controllers_; |
| 196 |
| 192 MutatorHostClient* mutator_host_client_; | 197 MutatorHostClient* mutator_host_client_; |
| 193 | 198 |
| 194 class ScrollOffsetAnimations; | 199 class ScrollOffsetAnimations; |
| 195 std::unique_ptr<ScrollOffsetAnimations> scroll_offset_animations_; | 200 std::unique_ptr<ScrollOffsetAnimations> scroll_offset_animations_; |
| 196 | 201 |
| 197 const ThreadInstance thread_instance_; | 202 const ThreadInstance thread_instance_; |
| 198 | 203 |
| 204 bool supports_scroll_animations_; |
| 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 |