Implements RLZTrackerDelegate on iOS.
[chromium-blink-merge.git] / cc / animation / animation_host.h
blob0cb40a6eeee558ec62d89712cd427c50631f23e1
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) const;
97 bool IsAnimatingOpacityProperty(int layer_id) const;
98 bool IsAnimatingTransformProperty(int layer_id) const;
100 bool HasPotentiallyRunningOpacityAnimation(int layer_id) const;
101 bool HasPotentiallyRunningTransformAnimation(int layer_id) const;
103 bool HasAnyAnimationTargetingProperty(
104 int layer_id,
105 Animation::TargetProperty property) const;
107 bool FilterIsAnimatingOnImplOnly(int layer_id) const;
108 bool OpacityIsAnimatingOnImplOnly(int layer_id) const;
109 bool TransformIsAnimatingOnImplOnly(int layer_id) const;
111 bool HasFilterAnimationThatInflatesBounds(int layer_id) const;
112 bool HasTransformAnimationThatInflatesBounds(int layer_id) const;
113 bool HasAnimationThatInflatesBounds(int layer_id) const;
115 bool FilterAnimationBoundsForBox(int layer_id,
116 const gfx::BoxF& box,
117 gfx::BoxF* bounds) const;
118 bool TransformAnimationBoundsForBox(int layer_id,
119 const gfx::BoxF& box,
120 gfx::BoxF* bounds) const;
122 bool HasOnlyTranslationTransforms(int layer_id) const;
123 bool AnimationsPreserveAxisAlignment(int layer_id) const;
125 bool MaximumTargetScale(int layer_id, float* max_scale) const;
126 bool AnimationStartScale(int layer_id, float* start_scale) const;
128 bool HasAnyAnimation(int layer_id) const;
129 bool HasActiveAnimation(int layer_id) const;
131 void ImplOnlyScrollAnimationCreate(int layer_id,
132 const gfx::ScrollOffset& target_offset,
133 const gfx::ScrollOffset& current_offset);
134 bool ImplOnlyScrollAnimationUpdateTarget(
135 int layer_id,
136 const gfx::Vector2dF& scroll_delta,
137 const gfx::ScrollOffset& max_scroll_offset,
138 base::TimeTicks frame_monotonic_time);
140 private:
141 explicit AnimationHost(ThreadInstance thread_instance);
143 void PushTimelinesToImplThread(AnimationHost* host_impl) const;
144 void RemoveTimelinesFromImplThread(AnimationHost* host_impl) const;
145 void PushPropertiesToImplThread(AnimationHost* host_impl);
147 void EraseTimelines(AnimationTimelineList::iterator begin,
148 AnimationTimelineList::iterator end);
150 // TODO(loyso): For now AnimationPlayers share LayerAnimationController object
151 // if they are attached to the same element(layer). Note that Element can
152 // contain many Layers.
153 typedef base::ScopedPtrHashMap<int, scoped_ptr<ElementAnimations>>
154 LayerToElementAnimationsMap;
155 LayerToElementAnimationsMap layer_to_element_animations_map_;
157 AnimationTimelineList timelines_;
158 scoped_ptr<AnimationRegistrar> animation_registrar_;
159 MutatorHostClient* mutator_host_client_;
161 class ScrollOffsetAnimations;
162 scoped_ptr<ScrollOffsetAnimations> scroll_offset_animations_;
164 const ThreadInstance thread_instance_;
166 DISALLOW_COPY_AND_ASSIGN(AnimationHost);
169 } // namespace cc
171 #endif // CC_ANIMATION_ANIMATION_HOST_H_