Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / cc / animation / animation_host.h
blob05782c097866b8999f2a41de49a02a5351e5307f
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.
5 #ifndef CC_ANIMATION_ANIMATION_HOST_H_
6 #define CC_ANIMATION_ANIMATION_HOST_H_
8 #include <vector>
10 #include "base/containers/scoped_ptr_hash_map.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time/time.h"
14 #include "cc/animation/animation_events.h"
15 #include "cc/base/cc_export.h"
16 #include "cc/trees/mutator_host_client.h"
18 namespace gfx {
19 class ScrollOffset;
22 namespace cc {
24 class AnimationPlayer;
25 class AnimationRegistrar;
26 class AnimationTimeline;
27 class ElementAnimations;
28 class LayerAnimationController;
29 class LayerTreeHost;
31 enum class ThreadInstance { MAIN, IMPL };
33 typedef std::vector<scoped_refptr<AnimationTimeline>> AnimationTimelineList;
35 // An AnimationHost contains all the state required to play animations.
36 // Specifically, it owns all the AnimationTimelines objects.
37 // There is just one AnimationHost for LayerTreeHost on main renderer thread
38 // and just one AnimationHost for LayerTreeHostImpl on impl thread.
39 // We synchronize them during the commit process in a one-way data flow process
40 // (PushPropertiesTo).
41 // An AnimationHost talks to its correspondent LayerTreeHost via
42 // LayerTreeMutatorsClient interface.
43 // AnimationHost has it's own instance of AnimationRegistrar,
44 // we want to merge AnimationRegistrar into AnimationHost.
45 class CC_EXPORT AnimationHost {
46 public:
47 static scoped_ptr<AnimationHost> Create(ThreadInstance thread_instance);
48 virtual ~AnimationHost();
50 void AddAnimationTimeline(scoped_refptr<AnimationTimeline> timeline);
51 void RemoveAnimationTimeline(scoped_refptr<AnimationTimeline> timeline);
52 AnimationTimeline* GetTimelineById(int timeline_id) const;
54 void ClearTimelines();
56 void RegisterLayer(int layer_id, LayerTreeType tree_type);
57 void UnregisterLayer(int layer_id, LayerTreeType tree_type);
59 void RegisterPlayerForLayer(int layer_id, AnimationPlayer* player);
60 void UnregisterPlayerForLayer(int layer_id, AnimationPlayer* player);
62 ElementAnimations* GetElementAnimationsForLayerId(int layer_id) const;
64 // TODO(loyso): Get rid of LayerAnimationController.
65 LayerAnimationController* GetControllerForLayerId(int layer_id) const;
67 // Parent LayerTreeHost or LayerTreeHostImpl.
68 MutatorHostClient* mutator_host_client() { return mutator_host_client_; }
69 const MutatorHostClient* mutator_host_client() const {
70 return mutator_host_client_;
72 void SetMutatorHostClient(MutatorHostClient* client);
74 void SetNeedsCommit();
76 void PushPropertiesTo(AnimationHost* host_impl);
78 AnimationRegistrar* animation_registrar() const {
79 return animation_registrar_.get();
82 void SetSupportsScrollAnimations(bool supports_scroll_animations);
83 bool SupportsScrollAnimations() const;
84 bool NeedsAnimateLayers() const;
86 bool ActivateAnimations();
87 bool AnimateLayers(base::TimeTicks monotonic_time);
88 bool UpdateAnimationState(bool start_ready_animations,
89 AnimationEventsVector* events);
91 scoped_ptr<AnimationEventsVector> CreateEvents();
92 void SetAnimationEvents(scoped_ptr<AnimationEventsVector> events);
94 bool ScrollOffsetAnimationWasInterrupted(int layer_id) const;
96 bool IsAnimatingFilterProperty(int layer_id, LayerTreeType tree_type) const;
97 bool IsAnimatingOpacityProperty(int layer_id, LayerTreeType tree_type) const;
98 bool IsAnimatingTransformProperty(int layer_id,
99 LayerTreeType tree_type) const;
101 bool HasPotentiallyRunningFilterAnimation(int layer_id,
102 LayerTreeType tree_type) const;
103 bool HasPotentiallyRunningOpacityAnimation(int layer_id,
104 LayerTreeType tree_type) const;
105 bool HasPotentiallyRunningTransformAnimation(int layer_id,
106 LayerTreeType tree_type) const;
108 bool HasAnyAnimationTargetingProperty(
109 int layer_id,
110 Animation::TargetProperty property) const;
112 bool FilterIsAnimatingOnImplOnly(int layer_id) const;
113 bool OpacityIsAnimatingOnImplOnly(int layer_id) const;
114 bool TransformIsAnimatingOnImplOnly(int layer_id) const;
116 bool HasFilterAnimationThatInflatesBounds(int layer_id) const;
117 bool HasTransformAnimationThatInflatesBounds(int layer_id) const;
118 bool HasAnimationThatInflatesBounds(int layer_id) const;
120 bool FilterAnimationBoundsForBox(int layer_id,
121 const gfx::BoxF& box,
122 gfx::BoxF* bounds) const;
123 bool TransformAnimationBoundsForBox(int layer_id,
124 const gfx::BoxF& box,
125 gfx::BoxF* bounds) const;
127 bool HasOnlyTranslationTransforms(int layer_id,
128 LayerTreeType tree_type) const;
129 bool AnimationsPreserveAxisAlignment(int layer_id) const;
131 bool MaximumTargetScale(int layer_id,
132 LayerTreeType tree_type,
133 float* max_scale) const;
134 bool AnimationStartScale(int layer_id,
135 LayerTreeType tree_type,
136 float* start_scale) const;
138 bool HasAnyAnimation(int layer_id) const;
139 bool HasActiveAnimation(int layer_id) const;
141 void ImplOnlyScrollAnimationCreate(int layer_id,
142 const gfx::ScrollOffset& target_offset,
143 const gfx::ScrollOffset& current_offset);
144 bool ImplOnlyScrollAnimationUpdateTarget(
145 int layer_id,
146 const gfx::Vector2dF& scroll_delta,
147 const gfx::ScrollOffset& max_scroll_offset,
148 base::TimeTicks frame_monotonic_time);
150 private:
151 explicit AnimationHost(ThreadInstance thread_instance);
153 void PushTimelinesToImplThread(AnimationHost* host_impl) const;
154 void RemoveTimelinesFromImplThread(AnimationHost* host_impl) const;
155 void PushPropertiesToImplThread(AnimationHost* host_impl);
157 void EraseTimelines(AnimationTimelineList::iterator begin,
158 AnimationTimelineList::iterator end);
160 // TODO(loyso): For now AnimationPlayers share LayerAnimationController object
161 // if they are attached to the same element(layer). Note that Element can
162 // contain many Layers.
163 typedef base::ScopedPtrHashMap<int, scoped_ptr<ElementAnimations>>
164 LayerToElementAnimationsMap;
165 LayerToElementAnimationsMap layer_to_element_animations_map_;
167 AnimationTimelineList timelines_;
168 scoped_ptr<AnimationRegistrar> animation_registrar_;
169 MutatorHostClient* mutator_host_client_;
171 class ScrollOffsetAnimations;
172 scoped_ptr<ScrollOffsetAnimations> scroll_offset_animations_;
174 const ThreadInstance thread_instance_;
176 DISALLOW_COPY_AND_ASSIGN(AnimationHost);
179 } // namespace cc
181 #endif // CC_ANIMATION_ANIMATION_HOST_H_