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

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

Issue 8362006: Reland r107720 - Enable the new layer animation framework. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with master. Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_GFX_COMPOSITOR_LAYER_ANIMATOR_H_ 5 #ifndef UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_
6 #define UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_ 6 #define UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_
7 #pragma once 7 #pragma once
8 8
9 #include <deque> 9 #include <deque>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/memory/linked_ptr.h" 12 #include "base/memory/linked_ptr.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "ui/base/animation/animation_container_element.h" 15 #include "ui/base/animation/animation_container_element.h"
16 #include "ui/gfx/compositor/compositor_export.h" 16 #include "ui/gfx/compositor/compositor_export.h"
17 #include "ui/gfx/compositor/layer_animation_element.h" 17 #include "ui/gfx/compositor/layer_animation_element.h"
18 18
19 namespace gfx { 19 namespace gfx {
20 class Rect; 20 class Rect;
21 } 21 }
22 22
23 namespace ui { 23 namespace ui {
24 class Animation; 24 class Animation;
25 class Layer; 25 class Layer;
26 class LayerAnimationSequence; 26 class LayerAnimationSequence;
27 class LayerAnimatorDelegate;
27 class Transform; 28 class Transform;
28 29
29 // When a property of layer needs to be changed it is set by way of 30 // When a property of layer needs to be changed it is set by way of
30 // LayerAnimator. This enables LayerAnimator to animate property 31 // LayerAnimator. This enables LayerAnimator to animate property changes.
31 // changes.
32 class COMPOSITOR_EXPORT LayerAnimator : public AnimationContainerElement { 32 class COMPOSITOR_EXPORT LayerAnimator : public AnimationContainerElement {
33 public: 33 public:
34 enum PreemptionStrategy { 34 enum PreemptionStrategy {
35 IMMEDIATELY_SET_NEW_TARGET, 35 IMMEDIATELY_SET_NEW_TARGET,
36 IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 36 IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
37 ENQUEUE_NEW_ANIMATION, 37 ENQUEUE_NEW_ANIMATION,
38 REPLACE_QUEUED_ANIMATIONS, 38 REPLACE_QUEUED_ANIMATIONS,
39 BLEND_WITH_CURRENT_ANIMATION 39 BLEND_WITH_CURRENT_ANIMATION
40 }; 40 };
41 41
42 explicit LayerAnimator(base::TimeDelta transition_duration); 42 explicit LayerAnimator(base::TimeDelta transition_duration);
43 virtual ~LayerAnimator(); 43 virtual ~LayerAnimator();
44 44
45 // No implicit animations when properties are set. 45 // No implicit animations when properties are set.
46 static LayerAnimator* CreateDefaultAnimator(); 46 static LayerAnimator* CreateDefaultAnimator();
47 47
48 // Implicitly animates when properties are set. 48 // Implicitly animates when properties are set.
49 static LayerAnimator* CreateImplicitAnimator(); 49 static LayerAnimator* CreateImplicitAnimator();
50 50
51 // Sets the transform on the delegate. May cause an implicit animation. 51 // Sets the transform on the delegate. May cause an implicit animation.
52 virtual void SetTransform(const Transform& transform); 52 virtual void SetTransform(const Transform& transform);
53 Transform GetTargetTransform() const;
53 54
54 // Sets the bounds on the delegate. May cause an implicit animation. 55 // Sets the bounds on the delegate. May cause an implicit animation.
55 virtual void SetBounds(const gfx::Rect& bounds); 56 virtual void SetBounds(const gfx::Rect& bounds);
57 gfx::Rect GetTargetBounds() const;
56 58
57 // Sets the opacity on the delegate. May cause an implicit animation. 59 // Sets the opacity on the delegate. May cause an implicit animation.
58 virtual void SetOpacity(float opacity); 60 virtual void SetOpacity(float opacity);
61 float GetTargetOpacity() const;
59 62
60 // Sets the layer animation delegate the animator is associated with. The 63 // Sets the layer animation delegate the animator is associated with. The
61 // animator does not own the delegate. 64 // animator does not own the delegate.
62 void SetDelegate(LayerAnimationDelegate* delegate); 65 void SetDelegate(LayerAnimatorDelegate* delegate);
63 66
64 // Sets the animation preemption strategy. This determines the behaviour if 67 // Sets the animation preemption strategy. This determines the behaviour if
65 // a property is set during an animation. The default is 68 // a property is set during an animation. The default is
66 // IMMEDIATELY_SET_NEW_TARGET (see ImmediatelySetNewTarget below). 69 // IMMEDIATELY_SET_NEW_TARGET (see ImmediatelySetNewTarget below).
67 void set_preemption_strategy(PreemptionStrategy strategy) { 70 void set_preemption_strategy(PreemptionStrategy strategy) {
68 preemption_strategy_ = strategy; 71 preemption_strategy_ = strategy;
69 } 72 }
70 73
71 // Start an animation sequence. If an animation for the same property is in 74 // Start an animation sequence. If an animation for the same property is in
72 // progress, it needs to be interrupted with the new animation. The animator 75 // progress, it needs to be interrupted with the new animation. The animator
73 // takes ownership of this animation sequence. 76 // takes ownership of this animation sequence.
74 void StartAnimation(LayerAnimationSequence* animation); 77 void StartAnimation(LayerAnimationSequence* animation);
75 78
76 // Schedule an animation to be run when possible. The animator takes ownership 79 // Schedule an animation to be run when possible. The animator takes ownership
77 // of this animation sequence. 80 // of this animation sequence.
78 void ScheduleAnimation(LayerAnimationSequence* animation); 81 void ScheduleAnimation(LayerAnimationSequence* animation);
79 82
80 // Schedules the animations to be run together. Obviously will no work if 83 // Schedules the animations to be run together. Obviously will no work if
81 // they animate any common properties. The animator takes ownership of the 84 // they animate any common properties. The animator takes ownership of the
82 // animation sequences. 85 // animation sequences.
83 void ScheduleTogether(const std::vector<LayerAnimationSequence*>& animations); 86 void ScheduleTogether(const std::vector<LayerAnimationSequence*>& animations);
84 87
88 // These are cover functions that create sequences for you to wrap the given
89 // elements. These sequences are then passed to the corresponding function
90 // above.
91 void StartAnimationElement(LayerAnimationElement* element);
92 void ScheduleAnimationElement(LayerAnimationElement* element);
93 void ScheduleElementsTogether(
94 const std::vector<LayerAnimationElement*>& element);
95
85 // Returns true if there is an animation in the queue (animations remain in 96 // Returns true if there is an animation in the queue (animations remain in
86 // the queue until they complete). 97 // the queue until they complete).
87 bool is_animating() const { return !animation_queue_.empty(); } 98 bool is_animating() const { return !animation_queue_.empty(); }
88 99
89 // Stops animating the given property. No effect if there is no running 100 // Stops animating the given property. No effect if there is no running
90 // animation for the given property. Skips to the final state of the 101 // animation for the given property. Skips to the final state of the
91 // animation. 102 // animation.
92 void StopAnimatingProperty( 103 void StopAnimatingProperty(
93 LayerAnimationElement::AnimatableProperty property); 104 LayerAnimationElement::AnimatableProperty property);
94 105
95 // Stops all animation and clears any queued animations. 106 // Stops all animation and clears any queued animations.
96 void StopAnimating(); 107 void StopAnimating();
97 108
98 // For testing purposes only. 109 // For testing purposes only.
99 void set_disable_timer_for_test(bool enabled) { 110 void set_disable_timer_for_test(bool enabled) {
100 disable_timer_for_test_ = enabled; 111 disable_timer_for_test_ = enabled;
101 } 112 }
102 base::TimeTicks get_last_step_time_for_test() { return last_step_time_; } 113 base::TimeTicks get_last_step_time_for_test() { return last_step_time_; }
103 114
115 // Scoped settings allow you to temporarily change the animator's settings and
116 // these changes are reverted when the object is destroyed.
117 class ScopedSettings {
118 public:
119 explicit ScopedSettings(LayerAnimator* animator);
120 virtual ~ScopedSettings();
121
122 void SetTransitionDuration(base::TimeDelta duration);
123
124 private:
125 LayerAnimator* animator_;
126 base::TimeDelta old_transition_duration_;
127
128 DISALLOW_COPY_AND_ASSIGN(ScopedSettings);
129 };
130
104 protected: 131 protected:
105 LayerAnimationDelegate* delegate() { return delegate_; } 132 LayerAnimatorDelegate* delegate() { return delegate_; }
106 133
107 private: 134 private:
135 friend class TransientSettings;
136
108 // We need to keep track of the start time of every running animation. 137 // We need to keep track of the start time of every running animation.
109 struct RunningAnimation { 138 struct RunningAnimation {
110 RunningAnimation(LayerAnimationSequence* sequence, 139 RunningAnimation(LayerAnimationSequence* sequence,
111 base::TimeTicks start_time) 140 base::TimeTicks start_time)
112 : sequence(sequence), 141 : sequence(sequence),
113 start_time(start_time) { 142 start_time(start_time) {
114 } 143 }
115 LayerAnimationSequence* sequence; 144 LayerAnimationSequence* sequence;
116 base::TimeTicks start_time; 145 base::TimeTicks start_time;
117 }; 146 };
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // If there's an animation in the queue that doesn't animate the same property 198 // If there's an animation in the queue that doesn't animate the same property
170 // as a running animation, or an animation schedule to run before it, start it 199 // as a running animation, or an animation schedule to run before it, start it
171 // up. Repeat until there are no such animations. 200 // up. Repeat until there are no such animations.
172 void ProcessQueue(); 201 void ProcessQueue();
173 202
174 // Attempts to add the sequence to the list of running animations. Returns 203 // Attempts to add the sequence to the list of running animations. Returns
175 // false if there is an animation running that already animates one of the 204 // false if there is an animation running that already animates one of the
176 // properties affected by |sequence|. 205 // properties affected by |sequence|.
177 bool StartSequenceImmediately(LayerAnimationSequence* sequence); 206 bool StartSequenceImmediately(LayerAnimationSequence* sequence);
178 207
208 // Sets the value of target as if all the running and queued animations were
209 // allowed to finish.
210 void GetTargetValue(LayerAnimationElement::TargetValue* target) const;
211
179 // This is the queue of animations to run. 212 // This is the queue of animations to run.
180 AnimationQueue animation_queue_; 213 AnimationQueue animation_queue_;
181 214
182 // The target of all layer animations. 215 // The target of all layer animations.
183 LayerAnimationDelegate* delegate_; 216 LayerAnimatorDelegate* delegate_;
184 217
185 // The currently running animations. 218 // The currently running animations.
186 RunningAnimations running_animations_; 219 RunningAnimations running_animations_;
187 220
188 // Determines how animations are replaced. 221 // Determines how animations are replaced.
189 PreemptionStrategy preemption_strategy_; 222 PreemptionStrategy preemption_strategy_;
190 223
191 // The default length of animations. 224 // The default length of animations.
192 base::TimeDelta transition_duration_; 225 base::TimeDelta transition_duration_;
193 226
194 // Used for coordinating the starting of animations. 227 // Used for coordinating the starting of animations.
195 base::TimeTicks last_step_time_; 228 base::TimeTicks last_step_time_;
196 229
197 // True if we are being stepped by our container. 230 // True if we are being stepped by our container.
198 bool is_started_; 231 bool is_started_;
199 232
200 // This prevents the animator from automatically stepping through animations 233 // This prevents the animator from automatically stepping through animations
201 // and allows for manual stepping. 234 // and allows for manual stepping.
202 bool disable_timer_for_test_; 235 bool disable_timer_for_test_;
203 236
204 DISALLOW_COPY_AND_ASSIGN(LayerAnimator); 237 DISALLOW_COPY_AND_ASSIGN(LayerAnimator);
205 }; 238 };
206 239
207 } // namespace ui 240 } // namespace ui
208 241
209 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_ 242 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698