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

Side by Side Diff: ui/compositor/layer_animator.h

Issue 10942034: Revert 156318 - I had originally tried to build upon http://codereview.chromium.org/10869066/, but … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « ui/compositor/layer_animation_sequence.cc ('k') | ui/compositor/layer_animator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_COMPOSITOR_LAYER_ANIMATOR_H_ 5 #ifndef UI_COMPOSITOR_LAYER_ANIMATOR_H_
6 #define UI_COMPOSITOR_LAYER_ANIMATOR_H_ 6 #define UI_COMPOSITOR_LAYER_ANIMATOR_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 16 matching lines...) Expand all
27 class Layer; 27 class Layer;
28 class LayerAnimationSequence; 28 class LayerAnimationSequence;
29 class LayerAnimationDelegate; 29 class LayerAnimationDelegate;
30 class LayerAnimationObserver; 30 class LayerAnimationObserver;
31 class ScopedLayerAnimationSettings; 31 class ScopedLayerAnimationSettings;
32 class Transform; 32 class Transform;
33 33
34 // When a property of layer needs to be changed it is set by way of 34 // When a property of layer needs to be changed it is set by way of
35 // LayerAnimator. This enables LayerAnimator to animate property changes. 35 // LayerAnimator. This enables LayerAnimator to animate property changes.
36 // NB: during many tests, set_disable_animations_for_test is used and causes 36 // NB: during many tests, set_disable_animations_for_test is used and causes
37 // all animations to complete immediately. The layer animation is ref counted 37 // all animations to complete immediately.
38 // so that if its owning layer is deleted (and the owning layer is only other 38 class COMPOSITOR_EXPORT LayerAnimator : public AnimationContainerElement {
39 // class that should ever hold a ref ptr to a LayerAnimator), the animator can
40 // ensure that it is not disposed of until it finishes executing. It does this
41 // by holding a reference to itself for the duration of methods for which it
42 // must guarantee that |this| is valid.
43 class COMPOSITOR_EXPORT LayerAnimator
44 : public AnimationContainerElement, public base::RefCounted<LayerAnimator> {
45 public: 39 public:
46 enum PreemptionStrategy { 40 enum PreemptionStrategy {
47 IMMEDIATELY_SET_NEW_TARGET, 41 IMMEDIATELY_SET_NEW_TARGET,
48 IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 42 IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
49 ENQUEUE_NEW_ANIMATION, 43 ENQUEUE_NEW_ANIMATION,
50 REPLACE_QUEUED_ANIMATIONS, 44 REPLACE_QUEUED_ANIMATIONS,
51 BLEND_WITH_CURRENT_ANIMATION 45 BLEND_WITH_CURRENT_ANIMATION
52 }; 46 };
53 47
54 explicit LayerAnimator(base::TimeDelta transition_duration); 48 explicit LayerAnimator(base::TimeDelta transition_duration);
49 virtual ~LayerAnimator();
55 50
56 // No implicit animations when properties are set. 51 // No implicit animations when properties are set.
57 static LayerAnimator* CreateDefaultAnimator(); 52 static LayerAnimator* CreateDefaultAnimator();
58 53
59 // Implicitly animates when properties are set. 54 // Implicitly animates when properties are set.
60 static LayerAnimator* CreateImplicitAnimator(); 55 static LayerAnimator* CreateImplicitAnimator();
61 56
62 // Sets the transform on the delegate. May cause an implicit animation. 57 // Sets the transform on the delegate. May cause an implicit animation.
63 virtual void SetTransform(const Transform& transform); 58 virtual void SetTransform(const Transform& transform);
64 Transform GetTargetTransform() const; 59 Transform GetTargetTransform() const;
(...skipping 12 matching lines...) Expand all
77 72
78 // Sets the brightness on the delegate. May cause an implicit animation. 73 // Sets the brightness on the delegate. May cause an implicit animation.
79 virtual void SetBrightness(float brightness); 74 virtual void SetBrightness(float brightness);
80 float GetTargetBrightness() const; 75 float GetTargetBrightness() const;
81 76
82 // Sets the grayscale on the delegate. May cause an implicit animation. 77 // Sets the grayscale on the delegate. May cause an implicit animation.
83 virtual void SetGrayscale(float grayscale); 78 virtual void SetGrayscale(float grayscale);
84 float GetTargetGrayscale() const; 79 float GetTargetGrayscale() const;
85 80
86 // Sets the layer animation delegate the animator is associated with. The 81 // Sets the layer animation delegate the animator is associated with. The
87 // animator does not own the delegate. The layer animator expects a non-NULL 82 // animator does not own the delegate.
88 // delegate for most of its operations, so do not call any methods without
89 // a valid delegate installed.
90 void SetDelegate(LayerAnimationDelegate* delegate); 83 void SetDelegate(LayerAnimationDelegate* delegate);
91 84
92 // Sets the animation preemption strategy. This determines the behaviour if 85 // Sets the animation preemption strategy. This determines the behaviour if
93 // a property is set during an animation. The default is 86 // a property is set during an animation. The default is
94 // IMMEDIATELY_SET_NEW_TARGET (see ImmediatelySetNewTarget below). 87 // IMMEDIATELY_SET_NEW_TARGET (see ImmediatelySetNewTarget below).
95 void set_preemption_strategy(PreemptionStrategy strategy) { 88 void set_preemption_strategy(PreemptionStrategy strategy) {
96 preemption_strategy_ = strategy; 89 preemption_strategy_ = strategy;
97 } 90 }
98 91
99 PreemptionStrategy preemption_strategy() const { 92 PreemptionStrategy preemption_strategy() const {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 // When set to true, all animations complete immediately. 167 // When set to true, all animations complete immediately.
175 static void set_disable_animations_for_test(bool disable_animations) { 168 static void set_disable_animations_for_test(bool disable_animations) {
176 disable_animations_for_test_ = disable_animations; 169 disable_animations_for_test_ = disable_animations;
177 } 170 }
178 171
179 static bool disable_animations_for_test() { 172 static bool disable_animations_for_test() {
180 return disable_animations_for_test_; 173 return disable_animations_for_test_;
181 } 174 }
182 175
183 protected: 176 protected:
184 virtual ~LayerAnimator();
185
186 LayerAnimationDelegate* delegate() { return delegate_; } 177 LayerAnimationDelegate* delegate() { return delegate_; }
187 const LayerAnimationDelegate* delegate() const { return delegate_; } 178 const LayerAnimationDelegate* delegate() const { return delegate_; }
188 179
189 // Virtual for testing. 180 // Virtual for testing.
190 virtual void ProgressAnimation(LayerAnimationSequence* sequence, 181 virtual bool ProgressAnimation(LayerAnimationSequence* sequence,
191 base::TimeDelta delta); 182 base::TimeDelta delta);
192 183
193 // Returns true if the sequence is owned by this animator. 184 // Returns true if the sequence is owned by this animator.
194 bool HasAnimation(LayerAnimationSequence* sequence) const; 185 bool HasAnimation(LayerAnimationSequence* sequence) const;
195 186
196 private: 187 private:
197 friend class base::RefCounted<LayerAnimator>;
198 friend class ScopedLayerAnimationSettings; 188 friend class ScopedLayerAnimationSettings;
199 189
190 class DestroyedTracker;
191
192 // Used by FinishAnimation() to indicate if this has been destroyed.
193 enum DestroyedType {
194 DESTROYED,
195 NOT_DESTROYED,
196 };
197
200 // We need to keep track of the start time of every running animation. 198 // We need to keep track of the start time of every running animation.
201 struct RunningAnimation { 199 struct RunningAnimation {
202 RunningAnimation(LayerAnimationSequence* sequence, 200 RunningAnimation(LayerAnimationSequence* sequence,
203 base::TimeTicks start_time) 201 base::TimeTicks start_time)
204 : sequence(sequence), 202 : sequence(sequence),
205 start_time(start_time) { 203 start_time(start_time) {
206 } 204 }
207 LayerAnimationSequence* sequence; 205 LayerAnimationSequence* sequence;
208 base::TimeTicks start_time; 206 base::TimeTicks start_time;
209 }; 207 };
210 208
211 typedef std::vector<RunningAnimation> RunningAnimations; 209 typedef std::vector<RunningAnimation> RunningAnimations;
212 typedef std::deque<linked_ptr<LayerAnimationSequence> > AnimationQueue; 210 typedef std::deque<linked_ptr<LayerAnimationSequence> > AnimationQueue;
213 211
214 // Implementation of AnimationContainerElement 212 // Implementation of AnimationContainerElement
215 virtual void SetStartTime(base::TimeTicks start_time) OVERRIDE; 213 virtual void SetStartTime(base::TimeTicks start_time) OVERRIDE;
216 virtual void Step(base::TimeTicks time_now) OVERRIDE; 214 virtual void Step(base::TimeTicks time_now) OVERRIDE;
217 virtual base::TimeDelta GetTimerInterval() const OVERRIDE; 215 virtual base::TimeDelta GetTimerInterval() const OVERRIDE;
218 216
219 // Starts or stops stepping depending on whether thare are running animations. 217 // Starts or stops stepping depending on whether thare are running animations.
220 void UpdateAnimationState(); 218 void UpdateAnimationState();
221 219
222 // Removes the sequences from both the running animations and the queue. 220 // Removes the sequences from both the running animations and the queue.
223 // Returns a pointer to the removed animation, if any. NOTE: the caller is 221 // Returns a pointer to the removed animation, if any. NOTE: the caller is
224 // responsible for deleting the returned pointer. 222 // responsible for deleting the returned pointer.
225 LayerAnimationSequence* RemoveAnimation( 223 LayerAnimationSequence* RemoveAnimation(
226 LayerAnimationSequence* sequence) WARN_UNUSED_RESULT; 224 LayerAnimationSequence* sequence) WARN_UNUSED_RESULT;
227 225
228 // Progresses to the end of the sequence before removing it. 226 // Progresses to the end of the sequence before removing it.
229 void FinishAnimation(LayerAnimationSequence* sequence); 227 DestroyedType FinishAnimation(
228 LayerAnimationSequence* sequence) WARN_UNUSED_RESULT;
230 229
231 // Finishes any running animation with zero duration. 230 // Finishes any running animation with zero duration.
232 void FinishAnyAnimationWithZeroDuration(); 231 void FinishAnyAnimationWithZeroDuration();
233 232
234 // Clears the running animations and the queue. No sequences are progressed. 233 // Clears the running animations and the queue. No sequences are progressed.
235 void ClearAnimations(); 234 void ClearAnimations();
236 235
237 // Returns the running animation animating the given property, if any. 236 // Returns the running animation animating the given property, if any.
238 RunningAnimation* GetRunningAnimation( 237 RunningAnimation* GetRunningAnimation(
239 LayerAnimationElement::AnimatableProperty property); 238 LayerAnimationElement::AnimatableProperty property);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 void GetTargetValue(LayerAnimationElement::TargetValue* target) const; 275 void GetTargetValue(LayerAnimationElement::TargetValue* target) const;
277 276
278 // Called whenever an animation is added to the animation queue. Either by 277 // Called whenever an animation is added to the animation queue. Either by
279 // starting the animation or adding to the queue. 278 // starting the animation or adding to the queue.
280 void OnScheduled(LayerAnimationSequence* sequence); 279 void OnScheduled(LayerAnimationSequence* sequence);
281 280
282 // Returns the default length of animations, including adjustment for slow 281 // Returns the default length of animations, including adjustment for slow
283 // animation mode if set. 282 // animation mode if set.
284 base::TimeDelta GetTransitionDuration() const; 283 base::TimeDelta GetTransitionDuration() const;
285 284
286 // Clears the animation queues and notifies any running animations that they
287 // have been aborted.
288 void ClearAnimationsInternal();
289
290 // This is the queue of animations to run. 285 // This is the queue of animations to run.
291 AnimationQueue animation_queue_; 286 AnimationQueue animation_queue_;
292 287
293 // The target of all layer animations. 288 // The target of all layer animations.
294 LayerAnimationDelegate* delegate_; 289 LayerAnimationDelegate* delegate_;
295 290
296 // The currently running animations. 291 // The currently running animations.
297 RunningAnimations running_animations_; 292 RunningAnimations running_animations_;
298 293
299 // Determines how animations are replaced. 294 // Determines how animations are replaced.
(...skipping 21 matching lines...) Expand all
321 // Slows down all animations for visual debugging. 316 // Slows down all animations for visual debugging.
322 static bool slow_animation_mode_; 317 static bool slow_animation_mode_;
323 318
324 // Amount to slow animations for debugging. 319 // Amount to slow animations for debugging.
325 static int slow_animation_scale_factor_; 320 static int slow_animation_scale_factor_;
326 321
327 // Observers are notified when layer animations end, are scheduled or are 322 // Observers are notified when layer animations end, are scheduled or are
328 // aborted. 323 // aborted.
329 ObserverList<LayerAnimationObserver> observers_; 324 ObserverList<LayerAnimationObserver> observers_;
330 325
326 scoped_refptr<DestroyedTracker> destroyed_tracker_;
327
331 DISALLOW_COPY_AND_ASSIGN(LayerAnimator); 328 DISALLOW_COPY_AND_ASSIGN(LayerAnimator);
332 }; 329 };
333 330
334 } // namespace ui 331 } // namespace ui
335 332
336 #endif // UI_COMPOSITOR_LAYER_ANIMATOR_H_ 333 #endif // UI_COMPOSITOR_LAYER_ANIMATOR_H_
OLDNEW
« no previous file with comments | « ui/compositor/layer_animation_sequence.cc ('k') | ui/compositor/layer_animator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698