Chromium Code Reviews| 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/containers/linked_list.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "cc/base/cc_export.h" | |
| 15 #include "cc/trees/layer_tree_mutators_client.h" | |
| 16 | |
| 17 namespace cc { | |
| 18 | |
| 19 class AnimationPlayer; | |
| 20 class AnimationRegistrar; | |
| 21 class AnimationTimeline; | |
| 22 class LayerAnimationController; | |
| 23 class LayerTreeHost; | |
| 24 | |
| 25 enum class ThreadInstance { MAIN, IMPL }; | |
|
Ian Vollick
2015/06/22 13:58:39
This looks much nicer. Thanks!
| |
| 26 | |
| 27 typedef std::vector<scoped_refptr<AnimationTimeline>> AnimationTimelineList; | |
| 28 | |
| 29 // An AnimationHost contains all the state required to play animations. | |
| 30 // Specifically, it owns all the AnimationTimelines objects. | |
| 31 // There is just one AnimationHost for LayerTreeHost on main renderer thread | |
| 32 // and just one AnimationHost for LayerTreeHostImpl on impl thread. | |
| 33 // We synchronize them during the commit process in a one-way data flow process | |
| 34 // (PushPropertiesTo). | |
| 35 // An AnimationHost talks to its correspondent LayerTreeHost via | |
| 36 // LayerTreeMutatorsClient interface. | |
| 37 // AnimationHost has it's own instance of AnimationRegistrar, | |
| 38 // we want to merge AnimationRegistrar into AnimationHost. | |
| 39 class CC_EXPORT AnimationHost { | |
| 40 public: | |
| 41 static scoped_ptr<AnimationHost> Create(ThreadInstance thread_instance); | |
| 42 virtual ~AnimationHost(); | |
| 43 | |
| 44 void AddAnimationTimeline(scoped_refptr<AnimationTimeline> timeline); | |
| 45 void RemoveAnimationTimeline(scoped_refptr<AnimationTimeline> timeline); | |
| 46 AnimationTimeline* GetTimelineById(int timeline_id) const; | |
| 47 | |
| 48 void ClearTimelines(); | |
| 49 | |
| 50 void RegisterLayer(int layer_id, LayerTreeType tree_type); | |
| 51 void UnregisterLayer(int layer_id, LayerTreeType tree_type); | |
| 52 | |
| 53 void RegisterPlayerForLayer(int layer_id, AnimationPlayer* player); | |
| 54 void UnregisterPlayerForLayer(int layer_id, AnimationPlayer* player); | |
| 55 | |
| 56 typedef base::LinkedList<AnimationPlayer> PlayersList; | |
| 57 PlayersList* GetPlayersForLayerId(int layer_id) const; | |
| 58 | |
| 59 // Parent LayerTreeHost or LayerTreeHostImpl. | |
| 60 LayerTreeMutatorsClient* layer_tree_mutators_client() { | |
| 61 return layer_tree_mutators_client_; | |
| 62 } | |
| 63 const LayerTreeMutatorsClient* layer_tree_mutators_client() const { | |
| 64 return layer_tree_mutators_client_; | |
| 65 } | |
| 66 void SetLayerTreeMutatorsClient(LayerTreeMutatorsClient* client); | |
| 67 | |
| 68 void SetNeedsCommit(); | |
| 69 | |
| 70 void PushPropertiesTo(AnimationHost* host_impl); | |
| 71 | |
| 72 AnimationRegistrar* animation_registrar() const { | |
| 73 return animation_registrar_.get(); | |
| 74 } | |
| 75 | |
| 76 private: | |
| 77 explicit AnimationHost(ThreadInstance thread_instance); | |
| 78 | |
| 79 LayerAnimationController* GetControllerForLayerId(int layer_id) const; | |
| 80 | |
| 81 bool EnsureListPlayersShareController(const PlayersList& players_list) const; | |
| 82 | |
| 83 void PushTimelinesToImplThread(AnimationHost* host_impl) const; | |
| 84 void RemoveTimelinesFromImplThread(AnimationHost* host_impl) const; | |
| 85 void PushPropertiesToImplThread(AnimationHost* host_impl); | |
| 86 | |
| 87 void EraseTimelines(AnimationTimelineList::iterator begin, | |
| 88 AnimationTimelineList::iterator end); | |
| 89 | |
| 90 // TODO(loyso): For now AnimationPlayers share LayerAnimationController object | |
| 91 // if they are attached to the same layer. Introduce LayersAnimations object | |
| 92 // to make AnimationPlayers-to-Layers relationship explicit (many-to-many). | |
| 93 // (a CC counterpart for blink::ElementAnimations. Note that Element can | |
| 94 // contain many Layers). | |
| 95 typedef base::hash_map<int, PlayersList*> LayerToPlayersMap; | |
|
Ian Vollick
2015/06/22 13:58:39
The PlayersList is a good idea -- it does make thi
| |
| 96 LayerToPlayersMap layer_to_players_map_; | |
| 97 | |
| 98 AnimationTimelineList timelines_; | |
| 99 scoped_ptr<AnimationRegistrar> animation_registrar_; | |
| 100 LayerTreeMutatorsClient* layer_tree_mutators_client_; | |
| 101 | |
| 102 const ThreadInstance thread_instance_; | |
| 103 | |
| 104 DISALLOW_COPY_AND_ASSIGN(AnimationHost); | |
| 105 }; | |
| 106 | |
| 107 } // namespace cc | |
| 108 | |
| 109 #endif // CC_ANIMATION_ANIMATION_HOST_H_ | |
| OLD | NEW |