Chromium Code Reviews| Index: cc/animation/animation_host.h |
| diff --git a/cc/animation/animation_host.h b/cc/animation/animation_host.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ab2db779cef45bcb199beed991e510f7b244066f |
| --- /dev/null |
| +++ b/cc/animation/animation_host.h |
| @@ -0,0 +1,109 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CC_ANIMATION_ANIMATION_HOST_H_ |
| +#define CC_ANIMATION_ANIMATION_HOST_H_ |
| + |
| +#include <vector> |
| + |
| +#include "base/containers/hash_tables.h" |
| +#include "base/containers/linked_list.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "cc/base/cc_export.h" |
| +#include "cc/trees/layer_tree_mutators_client.h" |
| + |
| +namespace cc { |
| + |
| +class AnimationPlayer; |
| +class AnimationRegistrar; |
| +class AnimationTimeline; |
| +class LayerAnimationController; |
| +class LayerTreeHost; |
| + |
| +enum class ThreadInstance { MAIN, IMPL }; |
|
Ian Vollick
2015/06/22 13:58:39
This looks much nicer. Thanks!
|
| + |
| +typedef std::vector<scoped_refptr<AnimationTimeline>> AnimationTimelineList; |
| + |
| +// An AnimationHost contains all the state required to play animations. |
| +// Specifically, it owns all the AnimationTimelines objects. |
| +// There is just one AnimationHost for LayerTreeHost on main renderer thread |
| +// and just one AnimationHost for LayerTreeHostImpl on impl thread. |
| +// We synchronize them during the commit process in a one-way data flow process |
| +// (PushPropertiesTo). |
| +// An AnimationHost talks to its correspondent LayerTreeHost via |
| +// LayerTreeMutatorsClient interface. |
| +// AnimationHost has it's own instance of AnimationRegistrar, |
| +// we want to merge AnimationRegistrar into AnimationHost. |
| +class CC_EXPORT AnimationHost { |
| + public: |
| + static scoped_ptr<AnimationHost> Create(ThreadInstance thread_instance); |
| + virtual ~AnimationHost(); |
| + |
| + void AddAnimationTimeline(scoped_refptr<AnimationTimeline> timeline); |
| + void RemoveAnimationTimeline(scoped_refptr<AnimationTimeline> timeline); |
| + AnimationTimeline* GetTimelineById(int timeline_id) const; |
| + |
| + void ClearTimelines(); |
| + |
| + void RegisterLayer(int layer_id, LayerTreeType tree_type); |
| + void UnregisterLayer(int layer_id, LayerTreeType tree_type); |
| + |
| + void RegisterPlayerForLayer(int layer_id, AnimationPlayer* player); |
| + void UnregisterPlayerForLayer(int layer_id, AnimationPlayer* player); |
| + |
| + typedef base::LinkedList<AnimationPlayer> PlayersList; |
| + PlayersList* GetPlayersForLayerId(int layer_id) const; |
| + |
| + // Parent LayerTreeHost or LayerTreeHostImpl. |
| + LayerTreeMutatorsClient* layer_tree_mutators_client() { |
| + return layer_tree_mutators_client_; |
| + } |
| + const LayerTreeMutatorsClient* layer_tree_mutators_client() const { |
| + return layer_tree_mutators_client_; |
| + } |
| + void SetLayerTreeMutatorsClient(LayerTreeMutatorsClient* client); |
| + |
| + void SetNeedsCommit(); |
| + |
| + void PushPropertiesTo(AnimationHost* host_impl); |
| + |
| + AnimationRegistrar* animation_registrar() const { |
| + return animation_registrar_.get(); |
| + } |
| + |
| + private: |
| + explicit AnimationHost(ThreadInstance thread_instance); |
| + |
| + LayerAnimationController* GetControllerForLayerId(int layer_id) const; |
| + |
| + bool EnsureListPlayersShareController(const PlayersList& players_list) const; |
| + |
| + void PushTimelinesToImplThread(AnimationHost* host_impl) const; |
| + void RemoveTimelinesFromImplThread(AnimationHost* host_impl) const; |
| + void PushPropertiesToImplThread(AnimationHost* host_impl); |
| + |
| + void EraseTimelines(AnimationTimelineList::iterator begin, |
| + AnimationTimelineList::iterator end); |
| + |
| + // TODO(loyso): For now AnimationPlayers share LayerAnimationController object |
| + // if they are attached to the same layer. Introduce LayersAnimations object |
| + // to make AnimationPlayers-to-Layers relationship explicit (many-to-many). |
| + // (a CC counterpart for blink::ElementAnimations. Note that Element can |
| + // contain many Layers). |
| + 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
|
| + LayerToPlayersMap layer_to_players_map_; |
| + |
| + AnimationTimelineList timelines_; |
| + scoped_ptr<AnimationRegistrar> animation_registrar_; |
| + LayerTreeMutatorsClient* layer_tree_mutators_client_; |
| + |
| + const ThreadInstance thread_instance_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AnimationHost); |
| +}; |
| + |
| +} // namespace cc |
| + |
| +#endif // CC_ANIMATION_ANIMATION_HOST_H_ |