OLD | NEW |
| (Empty) |
1 // Copyright 2012 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_LAYER_ANIMATION_CONTROLLER_H_ | |
6 #define CC_ANIMATION_LAYER_ANIMATION_CONTROLLER_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/containers/hash_tables.h" | |
10 #include "base/memory/ref_counted.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/observer_list.h" | |
13 #include "base/time/time.h" | |
14 #include "cc/animation/animation_events.h" | |
15 #include "cc/animation/layer_animation_event_observer.h" | |
16 #include "cc/base/cc_export.h" | |
17 #include "cc/base/scoped_ptr_vector.h" | |
18 #include "ui/gfx/geometry/scroll_offset.h" | |
19 #include "ui/gfx/transform.h" | |
20 | |
21 namespace gfx { | |
22 class BoxF; | |
23 class Transform; | |
24 } | |
25 | |
26 namespace cc { | |
27 | |
28 class Animation; | |
29 class AnimationDelegate; | |
30 class AnimationRegistrar; | |
31 class FilterOperations; | |
32 class KeyframeValueList; | |
33 class LayerAnimationValueObserver; | |
34 class LayerAnimationValueProvider; | |
35 | |
36 class CC_EXPORT LayerAnimationController | |
37 : public base::RefCounted<LayerAnimationController> { | |
38 public: | |
39 static scoped_refptr<LayerAnimationController> Create(int id); | |
40 | |
41 int id() const { return id_; } | |
42 | |
43 void AddAnimation(scoped_ptr<Animation> animation); | |
44 void PauseAnimation(int animation_id, base::TimeDelta time_offset); | |
45 void RemoveAnimation(int animation_id); | |
46 void RemoveAnimation(int animation_id, | |
47 Animation::TargetProperty target_property); | |
48 void AbortAnimations(Animation::TargetProperty target_property); | |
49 | |
50 // Ensures that the list of active animations on the main thread and the impl | |
51 // thread are kept in sync. This function does not take ownership of the impl | |
52 // thread controller. This method is virtual for testing. | |
53 virtual void PushAnimationUpdatesTo( | |
54 LayerAnimationController* controller_impl); | |
55 | |
56 void Animate(base::TimeTicks monotonic_time); | |
57 void AccumulatePropertyUpdates(base::TimeTicks monotonic_time, | |
58 AnimationEventsVector* events); | |
59 | |
60 void UpdateState(bool start_ready_animations, | |
61 AnimationEventsVector* events); | |
62 | |
63 // Make animations affect active observers if and only if they affect | |
64 // pending observers. Any animations that no longer affect any observers | |
65 // are deleted. | |
66 void ActivateAnimations(); | |
67 | |
68 // Returns the active animation animating the given property that is either | |
69 // running, or is next to run, if such an animation exists. | |
70 Animation* GetAnimation(Animation::TargetProperty target_property) const; | |
71 | |
72 // Returns the active animation for the given unique animation id. | |
73 Animation* GetAnimationById(int animation_id) const; | |
74 | |
75 // Returns true if there are any animations that have neither finished nor | |
76 // aborted. | |
77 bool HasActiveAnimation() const; | |
78 | |
79 // Returns true if there are any animations at all to process. | |
80 bool has_any_animation() const { return !animations_.empty(); } | |
81 | |
82 // Returns true if there is an animation currently animating the given | |
83 // property, or if there is an animation scheduled to animate this property in | |
84 // the future. | |
85 bool IsAnimatingProperty(Animation::TargetProperty target_property) const; | |
86 | |
87 void SetAnimationRegistrar(AnimationRegistrar* registrar); | |
88 AnimationRegistrar* animation_registrar() { return registrar_; } | |
89 | |
90 void NotifyAnimationStarted(const AnimationEvent& event); | |
91 void NotifyAnimationFinished(const AnimationEvent& event); | |
92 void NotifyAnimationAborted(const AnimationEvent& event); | |
93 void NotifyAnimationPropertyUpdate(const AnimationEvent& event); | |
94 | |
95 void AddValueObserver(LayerAnimationValueObserver* observer); | |
96 void RemoveValueObserver(LayerAnimationValueObserver* observer); | |
97 | |
98 void AddEventObserver(LayerAnimationEventObserver* observer); | |
99 void RemoveEventObserver(LayerAnimationEventObserver* observer); | |
100 | |
101 void set_value_provider(LayerAnimationValueProvider* provider) { | |
102 value_provider_ = provider; | |
103 } | |
104 | |
105 void remove_value_provider(LayerAnimationValueProvider* provider) { | |
106 if (value_provider_ == provider) | |
107 value_provider_ = nullptr; | |
108 } | |
109 | |
110 void set_layer_animation_delegate(AnimationDelegate* delegate) { | |
111 layer_animation_delegate_ = delegate; | |
112 } | |
113 | |
114 void remove_layer_animation_delegate(AnimationDelegate* delegate) { | |
115 if (layer_animation_delegate_ == delegate) | |
116 layer_animation_delegate_ = nullptr; | |
117 } | |
118 | |
119 bool HasFilterAnimationThatInflatesBounds() const; | |
120 bool HasTransformAnimationThatInflatesBounds() const; | |
121 bool HasAnimationThatInflatesBounds() const { | |
122 return HasTransformAnimationThatInflatesBounds() || | |
123 HasFilterAnimationThatInflatesBounds(); | |
124 } | |
125 | |
126 bool FilterAnimationBoundsForBox(const gfx::BoxF& box, | |
127 gfx::BoxF* bounds) const; | |
128 bool TransformAnimationBoundsForBox(const gfx::BoxF& box, | |
129 gfx::BoxF* bounds) const; | |
130 | |
131 bool HasAnimationThatAffectsScale() const; | |
132 | |
133 bool HasOnlyTranslationTransforms() const; | |
134 | |
135 bool AnimationsPreserveAxisAlignment() const; | |
136 | |
137 // Sets |max_scale| to the maximum scale along any dimension at any | |
138 // destination in active animations. Returns false if the maximum scale cannot | |
139 // be computed. | |
140 bool MaximumTargetScale(float* max_scale) const; | |
141 | |
142 // When a scroll animation is removed on the main thread, its compositor | |
143 // thread counterpart continues producing scroll deltas until activation. | |
144 // These scroll deltas need to be cleared at activation, so that the active | |
145 // layer's scroll offset matches the offset provided by the main thread | |
146 // rather than a combination of this offset and scroll deltas produced by | |
147 // the removed animation. This is to provide the illusion of synchronicity to | |
148 // JS that simultaneously removes an animation and sets the scroll offset. | |
149 bool scroll_offset_animation_was_interrupted() const { | |
150 return scroll_offset_animation_was_interrupted_; | |
151 } | |
152 | |
153 bool needs_to_start_animations_for_testing() { | |
154 return needs_to_start_animations_; | |
155 } | |
156 | |
157 protected: | |
158 friend class base::RefCounted<LayerAnimationController>; | |
159 | |
160 explicit LayerAnimationController(int id); | |
161 virtual ~LayerAnimationController(); | |
162 | |
163 private: | |
164 typedef base::hash_set<int> TargetProperties; | |
165 | |
166 void PushNewAnimationsToImplThread( | |
167 LayerAnimationController* controller_impl) const; | |
168 void RemoveAnimationsCompletedOnMainThread( | |
169 LayerAnimationController* controller_impl) const; | |
170 void PushPropertiesToImplThread(LayerAnimationController* controller_impl); | |
171 | |
172 void StartAnimations(base::TimeTicks monotonic_time); | |
173 void PromoteStartedAnimations(base::TimeTicks monotonic_time, | |
174 AnimationEventsVector* events); | |
175 void MarkFinishedAnimations(base::TimeTicks monotonic_time); | |
176 void MarkAnimationsForDeletion(base::TimeTicks monotonic_time, | |
177 AnimationEventsVector* events); | |
178 void PurgeAnimationsMarkedForDeletion(); | |
179 | |
180 void TickAnimations(base::TimeTicks monotonic_time); | |
181 | |
182 enum UpdateActivationType { NORMAL_ACTIVATION, FORCE_ACTIVATION }; | |
183 void UpdateActivation(UpdateActivationType type); | |
184 | |
185 void NotifyObserversOpacityAnimated(float opacity, | |
186 bool notify_active_observers, | |
187 bool notify_pending_observers); | |
188 void NotifyObserversTransformAnimated(const gfx::Transform& transform, | |
189 bool notify_active_observers, | |
190 bool notify_pending_observers); | |
191 void NotifyObserversFilterAnimated(const FilterOperations& filter, | |
192 bool notify_active_observers, | |
193 bool notify_pending_observers); | |
194 void NotifyObserversScrollOffsetAnimated( | |
195 const gfx::ScrollOffset& scroll_offset, | |
196 bool notify_active_observers, | |
197 bool notify_pending_observers); | |
198 | |
199 void NotifyObserversAnimationWaitingForDeletion(); | |
200 | |
201 bool HasValueObserver(); | |
202 bool HasActiveValueObserver(); | |
203 | |
204 AnimationRegistrar* registrar_; | |
205 int id_; | |
206 ScopedPtrVector<Animation> animations_; | |
207 | |
208 // This is used to ensure that we don't spam the registrar. | |
209 bool is_active_; | |
210 | |
211 base::TimeTicks last_tick_time_; | |
212 | |
213 ObserverList<LayerAnimationValueObserver> value_observers_; | |
214 ObserverList<LayerAnimationEventObserver> event_observers_; | |
215 | |
216 LayerAnimationValueProvider* value_provider_; | |
217 | |
218 AnimationDelegate* layer_animation_delegate_; | |
219 | |
220 // Only try to start animations when new animations are added or when the | |
221 // previous attempt at starting animations failed to start all animations. | |
222 bool needs_to_start_animations_; | |
223 | |
224 bool scroll_offset_animation_was_interrupted_; | |
225 | |
226 DISALLOW_COPY_AND_ASSIGN(LayerAnimationController); | |
227 }; | |
228 | |
229 } // namespace cc | |
230 | |
231 #endif // CC_ANIMATION_LAYER_ANIMATION_CONTROLLER_H_ | |
OLD | NEW |