Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: cc/animation/layer_animation_controller.h

Issue 1904653002: CC Animation: Merge LayerAnimationController into ElementAnimations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor optimization: Don't init value observations if same host. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/animation/element_animations_unittest.cc ('k') | cc/animation/layer_animation_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 <bitset>
9 #include <memory>
10 #include <vector>
11
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/time/time.h"
15 #include "cc/animation/animation.h"
16 #include "cc/animation/animation_events.h"
17 #include "cc/animation/target_property.h"
18 #include "cc/base/cc_export.h"
19 #include "ui/gfx/geometry/scroll_offset.h"
20 #include "ui/gfx/transform.h"
21
22 namespace gfx {
23 class BoxF;
24 class Transform;
25 }
26
27 namespace cc {
28
29 class AnimationDelegate;
30 class AnimationEvents;
31 class AnimationHost;
32 class FilterOperations;
33 class KeyframeValueList;
34 class LayerAnimationValueObserver;
35 class LayerAnimationValueProvider;
36
37 class CC_EXPORT LayerAnimationController
38 : public base::RefCounted<LayerAnimationController> {
39 public:
40 enum class ObserverType { ACTIVE, PENDING };
41
42 static scoped_refptr<LayerAnimationController> Create(int id);
43
44 int id() const { return id_; }
45
46 void AddAnimation(std::unique_ptr<Animation> animation);
47 void PauseAnimation(int animation_id, base::TimeDelta time_offset);
48 void RemoveAnimation(int animation_id);
49 void AbortAnimation(int animation_id);
50 void AbortAnimations(TargetProperty::Type target_property,
51 bool needs_completion = false);
52
53 // Ensures that the list of active animations on the main thread and the impl
54 // thread are kept in sync. This function does not take ownership of the impl
55 // thread controller.
56 void PushAnimationUpdatesTo(LayerAnimationController* controller_impl);
57
58 void Animate(base::TimeTicks monotonic_time);
59 void AccumulatePropertyUpdates(base::TimeTicks monotonic_time,
60 AnimationEvents* events);
61
62 void UpdateState(bool start_ready_animations, AnimationEvents* events);
63
64 // Make animations affect active observers if and only if they affect
65 // pending observers. Any animations that no longer affect any observers
66 // are deleted.
67 void ActivateAnimations();
68
69 // Returns the active animation animating the given property that is either
70 // running, or is next to run, if such an animation exists.
71 Animation* GetAnimation(TargetProperty::Type target_property) const;
72
73 // Returns the active animation for the given unique animation id.
74 Animation* GetAnimationById(int animation_id) const;
75
76 // Returns true if there are any animations that have neither finished nor
77 // aborted.
78 bool HasActiveAnimation() const;
79
80 // Returns true if there are any animations at all to process.
81 bool has_any_animation() const { return !animations_.empty(); }
82
83 // Returns true if there is an animation that is either currently animating
84 // the given property or scheduled to animate this property in the future, and
85 // that affects the given observer type.
86 bool IsPotentiallyAnimatingProperty(TargetProperty::Type target_property,
87 ObserverType observer_type) const;
88
89 // Returns true if there is an animation that is currently animating the given
90 // property and that affects the given observer type.
91 bool IsCurrentlyAnimatingProperty(TargetProperty::Type target_property,
92 ObserverType observer_type) const;
93
94 void SetAnimationHost(AnimationHost* host);
95 AnimationHost* animation_host() { return host_; }
96
97 void NotifyAnimationStarted(const AnimationEvent& event);
98 void NotifyAnimationFinished(const AnimationEvent& event);
99 void NotifyAnimationAborted(const AnimationEvent& event);
100 void NotifyAnimationPropertyUpdate(const AnimationEvent& event);
101 void NotifyAnimationTakeover(const AnimationEvent& event);
102
103 void set_value_observer(LayerAnimationValueObserver* observer) {
104 value_observer_ = observer;
105 }
106
107 bool needs_active_value_observations() const {
108 return needs_active_value_observations_;
109 }
110 bool needs_pending_value_observations() const {
111 return needs_pending_value_observations_;
112 }
113
114 void set_needs_active_value_observations(
115 bool needs_active_value_observations) {
116 needs_active_value_observations_ = needs_active_value_observations;
117 }
118 void set_needs_pending_value_observations(
119 bool needs_pending_value_observations) {
120 needs_pending_value_observations_ = needs_pending_value_observations;
121 }
122
123 void set_value_provider(LayerAnimationValueProvider* provider) {
124 value_provider_ = provider;
125 }
126
127 void remove_value_provider(LayerAnimationValueProvider* provider) {
128 if (value_provider_ == provider)
129 value_provider_ = nullptr;
130 }
131
132 void set_layer_animation_delegate(AnimationDelegate* delegate) {
133 layer_animation_delegate_ = delegate;
134 }
135
136 void remove_layer_animation_delegate(AnimationDelegate* delegate) {
137 if (layer_animation_delegate_ == delegate)
138 layer_animation_delegate_ = nullptr;
139 }
140
141 bool HasFilterAnimationThatInflatesBounds() const;
142 bool HasTransformAnimationThatInflatesBounds() const;
143 bool HasAnimationThatInflatesBounds() const {
144 return HasTransformAnimationThatInflatesBounds() ||
145 HasFilterAnimationThatInflatesBounds();
146 }
147
148 bool FilterAnimationBoundsForBox(const gfx::BoxF& box,
149 gfx::BoxF* bounds) const;
150 bool TransformAnimationBoundsForBox(const gfx::BoxF& box,
151 gfx::BoxF* bounds) const;
152
153 bool HasAnimationThatAffectsScale() const;
154
155 bool HasOnlyTranslationTransforms(ObserverType observer_type) const;
156
157 bool AnimationsPreserveAxisAlignment() const;
158
159 // Sets |start_scale| to the maximum of starting animation scale along any
160 // dimension at any destination in active animations. Returns false if the
161 // starting scale cannot be computed.
162 bool AnimationStartScale(ObserverType observer_type,
163 float* start_scale) const;
164
165 // Sets |max_scale| to the maximum scale along any dimension at any
166 // destination in active animations. Returns false if the maximum scale cannot
167 // be computed.
168 bool MaximumTargetScale(ObserverType observer_type, float* max_scale) const;
169
170 // When a scroll animation is removed on the main thread, its compositor
171 // thread counterpart continues producing scroll deltas until activation.
172 // These scroll deltas need to be cleared at activation, so that the active
173 // layer's scroll offset matches the offset provided by the main thread
174 // rather than a combination of this offset and scroll deltas produced by
175 // the removed animation. This is to provide the illusion of synchronicity to
176 // JS that simultaneously removes an animation and sets the scroll offset.
177 bool scroll_offset_animation_was_interrupted() const {
178 return scroll_offset_animation_was_interrupted_;
179 }
180
181 bool needs_to_start_animations_for_testing() {
182 return needs_to_start_animations_;
183 }
184
185 private:
186 friend class base::RefCounted<LayerAnimationController>;
187
188 explicit LayerAnimationController(int id);
189 ~LayerAnimationController();
190
191 // A set of target properties. TargetProperty must be 0-based enum.
192 using TargetProperties =
193 std::bitset<TargetProperty::LAST_TARGET_PROPERTY + 1>;
194
195 void PushNewAnimationsToImplThread(
196 LayerAnimationController* controller_impl) const;
197 void MarkAbortedAnimationsForDeletion(
198 LayerAnimationController* controller_impl) const;
199 void RemoveAnimationsCompletedOnMainThread(
200 LayerAnimationController* controller_impl) const;
201 void PushPropertiesToImplThread(LayerAnimationController* controller_impl);
202
203 void StartAnimations(base::TimeTicks monotonic_time);
204 void PromoteStartedAnimations(base::TimeTicks monotonic_time,
205 AnimationEvents* events);
206 void MarkFinishedAnimations(base::TimeTicks monotonic_time);
207 void MarkAnimationsForDeletion(base::TimeTicks monotonic_time,
208 AnimationEvents* events);
209 void PurgeAnimationsMarkedForDeletion();
210
211 void TickAnimations(base::TimeTicks monotonic_time);
212
213 enum UpdateActivationType { NORMAL_ACTIVATION, FORCE_ACTIVATION };
214 void UpdateActivation(UpdateActivationType type);
215
216 void NotifyObserversOpacityAnimated(float opacity,
217 bool notify_active_observers,
218 bool notify_pending_observers);
219 void NotifyObserversTransformAnimated(const gfx::Transform& transform,
220 bool notify_active_observers,
221 bool notify_pending_observers);
222 void NotifyObserversFilterAnimated(const FilterOperations& filter,
223 bool notify_active_observers,
224 bool notify_pending_observers);
225 void NotifyObserversScrollOffsetAnimated(
226 const gfx::ScrollOffset& scroll_offset,
227 bool notify_active_observers,
228 bool notify_pending_observers);
229
230 void NotifyObserversAnimationWaitingForDeletion();
231
232 void NotifyObserversTransformIsPotentiallyAnimatingChanged(
233 bool notify_active_observers,
234 bool notify_pending_observers);
235
236 void UpdatePotentiallyAnimatingTransform();
237
238 bool HasValueObserver();
239 bool HasActiveValueObserver();
240
241 AnimationHost* host_;
242 int id_;
243 std::vector<std::unique_ptr<Animation>> animations_;
244
245 // This is used to ensure that we don't spam the animation host.
246 bool is_active_;
247
248 base::TimeTicks last_tick_time_;
249
250 LayerAnimationValueObserver* value_observer_;
251 LayerAnimationValueProvider* value_provider_;
252 AnimationDelegate* layer_animation_delegate_;
253
254 bool needs_active_value_observations_;
255 bool needs_pending_value_observations_;
256
257 // Only try to start animations when new animations are added or when the
258 // previous attempt at starting animations failed to start all animations.
259 bool needs_to_start_animations_;
260
261 bool scroll_offset_animation_was_interrupted_;
262
263 bool potentially_animating_transform_for_active_observers_;
264 bool potentially_animating_transform_for_pending_observers_;
265
266 DISALLOW_COPY_AND_ASSIGN(LayerAnimationController);
267 };
268
269 } // namespace cc
270
271 #endif // CC_ANIMATION_LAYER_ANIMATION_CONTROLLER_H_
OLDNEW
« no previous file with comments | « cc/animation/element_animations_unittest.cc ('k') | cc/animation/layer_animation_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698