OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CC_ANIMATION_ANIMATION_HOST_H_ |
| 6 #define CC_ANIMATION_ANIMATION_HOST_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/containers/hash_tables.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "cc/base/cc_export.h" |
| 14 |
| 15 namespace cc { |
| 16 |
| 17 class AnimationPlayer; |
| 18 class AnimationRegistrar; |
| 19 class AnimationTimeline; |
| 20 class LayerTreeHost; |
| 21 class LayerTreeMutatorsClient; |
| 22 |
| 23 typedef std::vector<scoped_refptr<AnimationTimeline>> AnimationTimelineList; |
| 24 |
| 25 // An AnimationHost contains all the state required to play animations. |
| 26 // Specifically, it owns all the AnimationTimelines objects. |
| 27 // There is just one AnimationHost for LayerTreeHost on main renderer thread |
| 28 // and just one AnimationHost for LayerTreeHostImpl on impl thread. |
| 29 // We synchronize them during the commit process in a one-way data flow process |
| 30 // (PushPropertiesTo). |
| 31 // An AnimationHost talks to it's correspondent LayerTreeHost via |
| 32 // LayerTreeMutatorsClient interface. |
| 33 // AnimationHost has it's own instance of AnimationRegistrar (to be merged). |
| 34 class CC_EXPORT AnimationHost { |
| 35 public: |
| 36 static scoped_ptr<AnimationHost> Create(bool is_impl_instance); |
| 37 virtual ~AnimationHost(); |
| 38 |
| 39 void AddAnimationTimeline(scoped_refptr<AnimationTimeline> timeline); |
| 40 void RemoveAnimationTimeline(scoped_refptr<AnimationTimeline> timeline); |
| 41 AnimationTimeline* GetTimelineById(int timeline_id) const; |
| 42 |
| 43 void ClearTimelines(); |
| 44 |
| 45 void RegisterLayer(int layer_id, bool is_active_tree); |
| 46 void UnregisterLayer(int layer_id, bool is_active_tree); |
| 47 |
| 48 void RegisterPlayerForLayer(int layer_id, AnimationPlayer* player); |
| 49 void UnregisterPlayerForLayer(int layer_id, AnimationPlayer* player); |
| 50 AnimationPlayer* GetPlayerForLayerId(int layer_id) const; |
| 51 |
| 52 // Parent LayerTreeHost or LayerTreeHostImpl. |
| 53 LayerTreeMutatorsClient* layer_tree_mutators_client() { |
| 54 return layer_tree_mutators_client_; |
| 55 } |
| 56 const LayerTreeMutatorsClient* layer_tree_mutators_client() const { |
| 57 return layer_tree_mutators_client_; |
| 58 } |
| 59 void SetLayerTreeMutatorsClient(LayerTreeMutatorsClient* client); |
| 60 |
| 61 void SetNeedsCommit(); |
| 62 |
| 63 void PushPropertiesTo(AnimationHost* host_impl); |
| 64 |
| 65 AnimationRegistrar* animation_registrar() const { |
| 66 return animation_registrar_.get(); |
| 67 } |
| 68 |
| 69 private: |
| 70 // TODO(loyso): Temporary 1:1 mapping. AnimationPlayers share |
| 71 // LayerAnimationController for a given layer at the moment. |
| 72 // Introduce LayersAnimations for the many AnimationPlayers to many Layers |
| 73 // mapping (a CC counterpart for blink::ElementAnimations). |
| 74 typedef base::hash_map<int, AnimationPlayer*> LayerToPlayerMap; |
| 75 LayerToPlayerMap layer_to_player_map_; |
| 76 |
| 77 explicit AnimationHost(bool is_impl_instance); |
| 78 |
| 79 void PushTimelinesToImplThread(AnimationHost* host_impl) const; |
| 80 void RemoveTimelinesFromImplThread(AnimationHost* host_impl) const; |
| 81 void PushPropertiesToImplThread(AnimationHost* host_impl); |
| 82 |
| 83 void EraseTimelines(AnimationTimelineList::iterator begin, |
| 84 AnimationTimelineList::iterator end); |
| 85 |
| 86 AnimationTimelineList timelines_; |
| 87 scoped_ptr<AnimationRegistrar> animation_registrar_; |
| 88 LayerTreeMutatorsClient* layer_tree_mutators_client_; |
| 89 |
| 90 const bool is_impl_instance_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(AnimationHost); |
| 93 }; |
| 94 |
| 95 } // namespace cc |
| 96 |
| 97 #endif // CC_ANIMATION_ANIMATION_HOST_H_ |
OLD | NEW |