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

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: Fix ash_unittests 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
« no previous file with comments | « ui/compositor/layer_animation_delegate.h ('k') | ui/compositor/layer_animation_element.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_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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 const AnimatableProperties& properties, 112 const AnimatableProperties& properties,
108 base::TimeDelta duration); 113 base::TimeDelta duration);
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 {Start, 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 base::TimeTicks effective_start_time() const { return effective_start_time_; }
135
136 // This must be called before the first call to Progress. If starting the
137 // animation involves dispatching to another thread, then this will proceed
138 // with that dispatch, ultimately resulting in the animation getting an
139 // effective start time (the time the animation starts on the other thread).
140 void Start(LayerAnimationDelegate* delegate, int animation_group_id);
141
142 // Returns true if the animation has started but hasn't finished.
143 bool Started() { return !first_frame_; }
121 144
122 // Updates the delegate to the appropriate value for |now|. Returns true 145 // Updates the delegate to the appropriate value for |now|. Returns true
123 // if a redraw is required. 146 // if a redraw is required.
124 bool Progress(base::TimeTicks now, LayerAnimationDelegate* delegate); 147 bool Progress(base::TimeTicks now, LayerAnimationDelegate* delegate);
125 148
126 // If calling Progress now, with the given time, will finish the animation, 149 // 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 150 // returns true and sets |end_duration| to the actual duration for this
128 // animation, incuding any queueing delays. 151 // animation, incuding any queueing delays.
129 bool IsFinished(base::TimeTicks time, base::TimeDelta* total_duration); 152 bool IsFinished(base::TimeTicks time, base::TimeDelta* total_duration);
130 153
131 // Updates the delegate to the end of the animation. Returns true if a 154 // Updates the delegate to the end of the animation. Returns true if a
132 // redraw is required. 155 // redraw is required.
133 bool ProgressToEnd(LayerAnimationDelegate* delegate); 156 bool ProgressToEnd(LayerAnimationDelegate* delegate);
134 157
135 // Called if the animation is not allowed to complete. This may be called 158 // Called if the animation is not allowed to complete. This may be called
136 // before OnStarted or Progress. 159 // before OnStarted or Progress.
137 void Abort(); 160 void Abort(LayerAnimationDelegate* delegate);
138 161
139 // Assigns the target value to |target|. 162 // Assigns the target value to |target|.
140 void GetTargetValue(TargetValue* target) const; 163 void GetTargetValue(TargetValue* target) const;
141 164
142 // The properties that the element modifies. 165 // The properties that the element modifies.
143 const AnimatableProperties& properties() const { return properties_; } 166 const AnimatableProperties& properties() const { return properties_; }
144 167
168 // Whether this element animates on the compositor thread.
169 virtual bool IsThreaded() const;
170
145 Tween::Type tween_type() const { return tween_type_; } 171 Tween::Type tween_type() const { return tween_type_; }
146 void set_tween_type(Tween::Type tween_type) { tween_type_ = tween_type; } 172 void set_tween_type(Tween::Type tween_type) { tween_type_ = tween_type; }
147 173
174 // Each LayerAnimationElement has a unique animation_id. Elements belonging
175 // to sequences that are supposed to start together have the same
176 // animation_group_id.
177 int animation_id() const { return animation_id_; }
178 int animation_group_id() const { return animation_group_id_; }
179 void set_animation_group_id(int id) { animation_group_id_ = id; }
180
181 // The fraction of the animation that has been completed after the last
182 // call made to {Progress, ProgressToEnd}.
183 double last_progressed_fraction() const { return last_progressed_fraction_; }
184
148 protected: 185 protected:
149 // Called once each time the animation element is run before any call to 186 // Called once each time the animation element is run before any call to
150 // OnProgress. 187 // OnProgress.
151 virtual void OnStart(LayerAnimationDelegate* delegate) = 0; 188 virtual void OnStart(LayerAnimationDelegate* delegate) = 0;
152 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) = 0; 189 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) = 0;
153 virtual void OnGetTarget(TargetValue* target) const = 0; 190 virtual void OnGetTarget(TargetValue* target) const = 0;
154 virtual void OnAbort() = 0; 191 virtual void OnAbort(LayerAnimationDelegate* delegate) = 0;
192
193 base::TimeDelta duration() const { return duration_; }
194
195 // Actually start the animation, dispatching to another thread if needed.
196 virtual void RequestEffectiveStart(LayerAnimationDelegate* delegate);
155 197
156 private: 198 private:
157 // For debugging purposes, we sometimes alter the duration we actually use. 199 // 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 200 // For example, during tests we often set duration = 0, and it is sometimes
159 // useful to slow animations down to see them more clearly. 201 // useful to slow animations down to see them more clearly.
160 base::TimeDelta GetEffectiveDuration(const base::TimeDelta& delta); 202 base::TimeDelta GetEffectiveDuration(const base::TimeDelta& delta);
161 203
162 bool first_frame_; 204 bool first_frame_;
163 const AnimatableProperties properties_; 205 const AnimatableProperties properties_;
164 base::TimeTicks start_time_; 206 base::TimeTicks requested_start_time_;
207
208 // When the animation actually started, taking into account queueing delays.
209 base::TimeTicks effective_start_time_;
165 const base::TimeDelta duration_; 210 const base::TimeDelta duration_;
166 Tween::Type tween_type_; 211 Tween::Type tween_type_;
167 212
213 const int animation_id_;
214 int animation_group_id_;
215
216 double last_progressed_fraction_;
217
168 DISALLOW_COPY_AND_ASSIGN(LayerAnimationElement); 218 DISALLOW_COPY_AND_ASSIGN(LayerAnimationElement);
169 }; 219 };
170 220
171 } // namespace ui 221 } // namespace ui
172 222
173 #endif // UI_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_ 223 #endif // UI_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_
OLDNEW
« no previous file with comments | « ui/compositor/layer_animation_delegate.h ('k') | ui/compositor/layer_animation_element.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698