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

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

Issue 11896017: Thread ui opacity animations (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address comments Created 7 years, 10 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
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_ANIMATION_ELEMENT_H_ 5 #ifndef UI_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_
6 #define UI_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_ 6 #define UI_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/time.h" 10 #include "base/time.h"
11 #include "cc/animation.h"
12 #include "cc/animation_events.h"
11 #include "third_party/skia/include/core/SkColor.h" 13 #include "third_party/skia/include/core/SkColor.h"
12 #include "ui/base/animation/tween.h" 14 #include "ui/base/animation/tween.h"
13 #include "ui/compositor/compositor_export.h" 15 #include "ui/compositor/compositor_export.h"
14 #include "ui/gfx/rect.h" 16 #include "ui/gfx/rect.h"
15 #include "ui/gfx/transform.h" 17 #include "ui/gfx/transform.h"
16 18
17 namespace ui { 19 namespace ui {
18 20
19 class InterpolatedTransform; 21 class InterpolatedTransform;
20 class LayerAnimationDelegate; 22 class LayerAnimationDelegate;
21 23
22 // LayerAnimationElements represent one segment of an animation between two 24 // LayerAnimationElements represent one segment of an animation between two
23 // keyframes. They know how to update a LayerAnimationDelegate given a value 25 // keyframes. They know how to update a LayerAnimationDelegate given a value
24 // between 0 and 1 (0 for initial, and 1 for final). 26 // between 0 and 1 (0 for initial, and 1 for final).
25 class COMPOSITOR_EXPORT LayerAnimationElement { 27 class COMPOSITOR_EXPORT LayerAnimationElement {
26 public: 28 public:
27 enum AnimatableProperty { 29 enum AnimatableProperty {
28 TRANSFORM = 0, 30 TRANSFORM = 0,
29 BOUNDS, 31 BOUNDS,
30 OPACITY, 32 OPACITY,
31 VISIBILITY, 33 VISIBILITY,
32 BRIGHTNESS, 34 BRIGHTNESS,
33 GRAYSCALE, 35 GRAYSCALE,
34 COLOR, 36 COLOR,
35 }; 37 };
36 38
39 static AnimatableProperty ToAnimatableProperty(
40 cc::Animation::TargetProperty property);
41
37 struct COMPOSITOR_EXPORT TargetValue { 42 struct COMPOSITOR_EXPORT TargetValue {
38 TargetValue(); 43 TargetValue();
39 // Initializes the target value to match the delegate. NULL may be supplied. 44 // Initializes the target value to match the delegate. NULL may be supplied.
40 explicit TargetValue(const LayerAnimationDelegate* delegate); 45 explicit TargetValue(const LayerAnimationDelegate* delegate);
41 46
42 gfx::Rect bounds; 47 gfx::Rect bounds;
43 gfx::Transform transform; 48 gfx::Transform transform;
44 float opacity; 49 float opacity;
45 bool visibility; 50 bool visibility;
46 float brightness; 51 float brightness;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 114
110 // Creates an element that transitions to the given color. The caller owns the 115 // Creates an element that transitions to the given color. The caller owns the
111 // return value. 116 // return value.
112 static LayerAnimationElement* CreateColorElement( 117 static LayerAnimationElement* CreateColorElement(
113 SkColor color, 118 SkColor color,
114 base::TimeDelta duration); 119 base::TimeDelta duration);
115 120
116 // Sets the start time for the animation. This must be called before the first 121 // Sets the start time for the animation. This must be called before the first
117 // call to {Progress, IsFinished}. Once the animation is finished, this must 122 // call to {Progress, IsFinished}. Once the animation is finished, this must
118 // be called again in order to restart the animation. 123 // be called again in order to restart the animation.
119 void set_start_time(base::TimeTicks start_time) { start_time_ = start_time; } 124 void set_requested_start_time(base::TimeTicks start_time) {
120 base::TimeTicks start_time() const { return start_time_; } 125 requested_start_time_ = start_time;
126 }
127 base::TimeTicks requested_start_time() const { return requested_start_time_; }
128
129 // Sets the actual start time for the animation, taking into account any
130 // queueing delays.
131 void set_effective_start_time(base::TimeTicks start_time) {
132 effective_start_time_ = start_time;
133 }
134
135 // If starting the animation involves dispatching to another thread, then
136 // proceed with that dispatch; this will ultimately result in the animation
137 // getting an effective start time (the time the animation starts on the other
138 // thread).
139 void ProgressToEffectiveStart(LayerAnimationDelegate* delegate);
sky 2013/02/19 17:06:56 Can this be called Start() and always invoked? Int
ajuma 2013/02/20 16:09:10 Done. I've similarly renamed LayerAnimationSequenc
121 140
122 // Updates the delegate to the appropriate value for |now|. Returns true 141 // Updates the delegate to the appropriate value for |now|. Returns true
123 // if a redraw is required. 142 // if a redraw is required.
124 bool Progress(base::TimeTicks now, LayerAnimationDelegate* delegate); 143 bool Progress(base::TimeTicks now, LayerAnimationDelegate* delegate);
125 144
126 // If calling Progress now, with the given time, will finish the animation, 145 // If calling Progress now, with the given time, will finish the animation,
127 // returns true and sets |end_duration| to the actual duration for this 146 // returns true and sets |end_duration| to the actual duration for this
128 // animation, incuding any queueing delays. 147 // animation, incuding any queueing delays.
129 bool IsFinished(base::TimeTicks time, base::TimeDelta* total_duration); 148 bool IsFinished(base::TimeTicks time, base::TimeDelta* total_duration);
130 149
131 // Updates the delegate to the end of the animation. Returns true if a 150 // Updates the delegate to the end of the animation. Returns true if a
132 // redraw is required. 151 // redraw is required.
133 bool ProgressToEnd(LayerAnimationDelegate* delegate); 152 bool ProgressToEnd(LayerAnimationDelegate* delegate);
134 153
135 // Called if the animation is not allowed to complete. This may be called 154 // Called if the animation is not allowed to complete. This may be called
136 // before OnStarted or Progress. 155 // before OnStarted or Progress.
137 void Abort(); 156 void Abort(LayerAnimationDelegate* delegate);
138 157
139 // Assigns the target value to |target|. 158 // Assigns the target value to |target|.
140 void GetTargetValue(TargetValue* target) const; 159 void GetTargetValue(TargetValue* target) const;
141 160
142 // The properties that the element modifies. 161 // The properties that the element modifies.
143 const AnimatableProperties& properties() const { return properties_; } 162 const AnimatableProperties& properties() const { return properties_; }
144 163
164 // Whether this element animates on the compositor thread.
165 virtual bool IsThreaded() const;
166
145 Tween::Type tween_type() const { return tween_type_; } 167 Tween::Type tween_type() const { return tween_type_; }
146 void set_tween_type(Tween::Type tween_type) { tween_type_ = tween_type; } 168 void set_tween_type(Tween::Type tween_type) { tween_type_ = tween_type; }
147 169
170 // Used to identify animations.
sky 2013/02/19 17:06:56 These need better descriptions. In particular how
ajuma 2013/02/20 16:09:10 Done.
171 int animation_id() const { return animation_id_; }
172 void set_animation_id(int id) { animation_id_ = id; }
173 int animation_group_id() const { return animation_group_id_; }
174 void set_animation_group_id(int id) { animation_group_id_ = id; }
175
176 // The fraction of the animation that has been completed after the last
177 // call made to {Progress, ProgressToEnd}.
178 double last_progressed_fraction() const { return last_progressed_fraction_; }
179
148 protected: 180 protected:
149 // Called once each time the animation element is run before any call to 181 // Called once each time the animation element is run before any call to
150 // OnProgress. 182 // OnProgress.
151 virtual void OnStart(LayerAnimationDelegate* delegate) = 0; 183 virtual void OnStart(LayerAnimationDelegate* delegate) = 0;
152 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) = 0; 184 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) = 0;
153 virtual void OnGetTarget(TargetValue* target) const = 0; 185 virtual void OnGetTarget(TargetValue* target) const = 0;
154 virtual void OnAbort() = 0; 186 virtual void OnAbort(LayerAnimationDelegate* delegate) = 0;
187
188 base::TimeDelta duration() const { return duration_; }
189
190 // Actually start the animation, dispatching to another thread if needed.
191 virtual void RequestEffectiveStart(LayerAnimationDelegate* delegate);
155 192
156 private: 193 private:
157 // For debugging purposes, we sometimes alter the duration we actually use. 194 // For debugging purposes, we sometimes alter the duration we actually use.
158 // For example, during tests we often set duration = 0, and it is sometimes 195 // For example, during tests we often set duration = 0, and it is sometimes
159 // useful to slow animations down to see them more clearly. 196 // useful to slow animations down to see them more clearly.
160 base::TimeDelta GetEffectiveDuration(const base::TimeDelta& delta); 197 base::TimeDelta GetEffectiveDuration(const base::TimeDelta& delta);
161 198
162 bool first_frame_; 199 bool first_frame_;
163 const AnimatableProperties properties_; 200 const AnimatableProperties properties_;
164 base::TimeTicks start_time_; 201 base::TimeTicks requested_start_time_;
202
203 // When the animation actually started, taking into account queueing delays.
204 base::TimeTicks effective_start_time_;
165 const base::TimeDelta duration_; 205 const base::TimeDelta duration_;
166 Tween::Type tween_type_; 206 Tween::Type tween_type_;
167 207
208 int animation_id_;
209 int animation_group_id_;
210
211 double last_progressed_fraction_;
212
168 DISALLOW_COPY_AND_ASSIGN(LayerAnimationElement); 213 DISALLOW_COPY_AND_ASSIGN(LayerAnimationElement);
169 }; 214 };
170 215
171 } // namespace ui 216 } // namespace ui
172 217
173 #endif // UI_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_ 218 #endif // UI_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698