OLD | NEW |
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 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/memory/linked_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "cc/animation/layer_animation_event_observer.h" |
17 #include "ui/compositor/compositor_export.h" | 18 #include "ui/compositor/compositor_export.h" |
18 #include "ui/compositor/layer_animation_element.h" | 19 #include "ui/compositor/layer_animation_element.h" |
19 #include "ui/gfx/animation/tween.h" | 20 #include "ui/gfx/animation/tween.h" |
20 | 21 |
| 22 namespace cc { |
| 23 class Layer; |
| 24 } |
| 25 |
21 namespace gfx { | 26 namespace gfx { |
22 class Animation; | 27 class Animation; |
23 class Rect; | 28 class Rect; |
24 class Transform; | 29 class Transform; |
25 } | 30 } |
26 | 31 |
27 namespace ui { | 32 namespace ui { |
28 class Layer; | 33 class Layer; |
29 class LayerAnimationSequence; | 34 class LayerAnimationSequence; |
30 class LayerAnimationDelegate; | 35 class LayerAnimationDelegate; |
31 class LayerAnimationObserver; | 36 class LayerAnimationObserver; |
32 class LayerAnimatorCollection; | 37 class LayerAnimatorCollection; |
33 class ScopedLayerAnimationSettings; | 38 class ScopedLayerAnimationSettings; |
34 | 39 |
35 // When a property of layer needs to be changed it is set by way of | 40 // When a property of layer needs to be changed it is set by way of |
36 // LayerAnimator. This enables LayerAnimator to animate property changes. | 41 // LayerAnimator. This enables LayerAnimator to animate property changes. |
37 // NB: during many tests, set_disable_animations_for_test is used and causes | 42 // NB: during many tests, set_disable_animations_for_test is used and causes |
38 // all animations to complete immediately. The layer animation is ref counted | 43 // all animations to complete immediately. The layer animation is ref counted |
39 // so that if its owning layer is deleted (and the owning layer is only other | 44 // so that if its owning layer is deleted (and the owning layer is only other |
40 // class that should ever hold a ref ptr to a LayerAnimator), the animator can | 45 // class that should ever hold a ref ptr to a LayerAnimator), the animator can |
41 // ensure that it is not disposed of until it finishes executing. It does this | 46 // ensure that it is not disposed of until it finishes executing. It does this |
42 // by holding a reference to itself for the duration of methods for which it | 47 // by holding a reference to itself for the duration of methods for which it |
43 // must guarantee that |this| is valid. | 48 // must guarantee that |this| is valid. |
44 class COMPOSITOR_EXPORT LayerAnimator : public base::RefCounted<LayerAnimator> { | 49 class COMPOSITOR_EXPORT LayerAnimator |
| 50 : public base::RefCounted<LayerAnimator>, |
| 51 NON_EXPORTED_BASE(public cc::LayerAnimationEventObserver) { |
45 public: | 52 public: |
46 enum PreemptionStrategy { | 53 enum PreemptionStrategy { |
47 IMMEDIATELY_SET_NEW_TARGET, | 54 IMMEDIATELY_SET_NEW_TARGET, |
48 IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 55 IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
49 ENQUEUE_NEW_ANIMATION, | 56 ENQUEUE_NEW_ANIMATION, |
50 REPLACE_QUEUED_ANIMATIONS, | 57 REPLACE_QUEUED_ANIMATIONS, |
51 BLEND_WITH_CURRENT_ANIMATION | 58 BLEND_WITH_CURRENT_ANIMATION |
52 }; | 59 }; |
53 | 60 |
54 explicit LayerAnimator(base::TimeDelta transition_duration); | 61 explicit LayerAnimator(base::TimeDelta transition_duration); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // Returns the default length of animations, including adjustment for slow | 97 // Returns the default length of animations, including adjustment for slow |
91 // animation mode if set. | 98 // animation mode if set. |
92 base::TimeDelta GetTransitionDuration() const; | 99 base::TimeDelta GetTransitionDuration() const; |
93 | 100 |
94 // Sets the layer animation delegate the animator is associated with. The | 101 // Sets the layer animation delegate the animator is associated with. The |
95 // animator does not own the delegate. The layer animator expects a non-NULL | 102 // animator does not own the delegate. The layer animator expects a non-NULL |
96 // delegate for most of its operations, so do not call any methods without | 103 // delegate for most of its operations, so do not call any methods without |
97 // a valid delegate installed. | 104 // a valid delegate installed. |
98 void SetDelegate(LayerAnimationDelegate* delegate); | 105 void SetDelegate(LayerAnimationDelegate* delegate); |
99 | 106 |
| 107 // Unsubscribe from |cc_layer_| and subscribe to |new_layer|. |
| 108 void SwitchToLayer(scoped_refptr<cc::Layer> new_layer); |
| 109 |
100 // Sets the animation preemption strategy. This determines the behaviour if | 110 // Sets the animation preemption strategy. This determines the behaviour if |
101 // a property is set during an animation. The default is | 111 // a property is set during an animation. The default is |
102 // IMMEDIATELY_SET_NEW_TARGET (see ImmediatelySetNewTarget below). | 112 // IMMEDIATELY_SET_NEW_TARGET (see ImmediatelySetNewTarget below). |
103 void set_preemption_strategy(PreemptionStrategy strategy) { | 113 void set_preemption_strategy(PreemptionStrategy strategy) { |
104 preemption_strategy_ = strategy; | 114 preemption_strategy_ = strategy; |
105 } | 115 } |
106 | 116 |
107 PreemptionStrategy preemption_strategy() const { | 117 PreemptionStrategy preemption_strategy() const { |
108 return preemption_strategy_; | 118 return preemption_strategy_; |
109 } | 119 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 last_step_time_ = time; | 196 last_step_time_ = time; |
187 } | 197 } |
188 base::TimeTicks last_step_time() const { return last_step_time_; } | 198 base::TimeTicks last_step_time() const { return last_step_time_; } |
189 | 199 |
190 void Step(base::TimeTicks time_now); | 200 void Step(base::TimeTicks time_now); |
191 | 201 |
192 void AddToCollection(LayerAnimatorCollection* collection); | 202 void AddToCollection(LayerAnimatorCollection* collection); |
193 void RemoveFromCollection(LayerAnimatorCollection* collection); | 203 void RemoveFromCollection(LayerAnimatorCollection* collection); |
194 | 204 |
195 protected: | 205 protected: |
196 virtual ~LayerAnimator(); | 206 ~LayerAnimator() override; |
197 | 207 |
198 LayerAnimationDelegate* delegate() { return delegate_; } | 208 LayerAnimationDelegate* delegate() { return delegate_; } |
199 const LayerAnimationDelegate* delegate() const { return delegate_; } | 209 const LayerAnimationDelegate* delegate() const { return delegate_; } |
200 | 210 |
201 // Virtual for testing. | 211 // Virtual for testing. |
202 virtual void ProgressAnimation(LayerAnimationSequence* sequence, | 212 virtual void ProgressAnimation(LayerAnimationSequence* sequence, |
203 base::TimeTicks now); | 213 base::TimeTicks now); |
204 | 214 |
205 void ProgressAnimationToEnd(LayerAnimationSequence* sequence); | 215 void ProgressAnimationToEnd(LayerAnimationSequence* sequence); |
206 | 216 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 314 |
305 // Clears the animation queues and notifies any running animations that they | 315 // Clears the animation queues and notifies any running animations that they |
306 // have been aborted. | 316 // have been aborted. |
307 void ClearAnimationsInternal(); | 317 void ClearAnimationsInternal(); |
308 | 318 |
309 // Cleans up any running animations that may have been deleted. | 319 // Cleans up any running animations that may have been deleted. |
310 void PurgeDeletedAnimations(); | 320 void PurgeDeletedAnimations(); |
311 | 321 |
312 LayerAnimatorCollection* GetLayerAnimatorCollection(); | 322 LayerAnimatorCollection* GetLayerAnimatorCollection(); |
313 | 323 |
| 324 // LayerAnimationEventObserver |
| 325 void OnAnimationStarted(const cc::AnimationEvent& event) override; |
| 326 |
314 // This is the queue of animations to run. | 327 // This is the queue of animations to run. |
315 AnimationQueue animation_queue_; | 328 AnimationQueue animation_queue_; |
316 | 329 |
317 // The target of all layer animations. | 330 // The target of all layer animations. |
318 LayerAnimationDelegate* delegate_; | 331 LayerAnimationDelegate* delegate_; |
319 | 332 |
320 // The currently running animations. | 333 // The currently running animations. |
321 RunningAnimations running_animations_; | 334 RunningAnimations running_animations_; |
322 | 335 |
323 // Determines how animations are replaced. | 336 // Determines how animations are replaced. |
(...skipping 26 matching lines...) Expand all Loading... |
350 // Observers are notified when layer animations end, are scheduled or are | 363 // Observers are notified when layer animations end, are scheduled or are |
351 // aborted. | 364 // aborted. |
352 base::ObserverList<LayerAnimationObserver> observers_; | 365 base::ObserverList<LayerAnimationObserver> observers_; |
353 | 366 |
354 DISALLOW_COPY_AND_ASSIGN(LayerAnimator); | 367 DISALLOW_COPY_AND_ASSIGN(LayerAnimator); |
355 }; | 368 }; |
356 | 369 |
357 } // namespace ui | 370 } // namespace ui |
358 | 371 |
359 #endif // UI_COMPOSITOR_LAYER_ANIMATOR_H_ | 372 #endif // UI_COMPOSITOR_LAYER_ANIMATOR_H_ |
OLD | NEW |