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_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/time.h" | 10 #include "base/time/time.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 bool visibility; | 50 bool visibility; |
51 float brightness; | 51 float brightness; |
52 float grayscale; | 52 float grayscale; |
53 SkColor color; | 53 SkColor color; |
54 }; | 54 }; |
55 | 55 |
56 typedef std::set<AnimatableProperty> AnimatableProperties; | 56 typedef std::set<AnimatableProperty> AnimatableProperties; |
57 | 57 |
58 LayerAnimationElement(const AnimatableProperties& properties, | 58 LayerAnimationElement(const AnimatableProperties& properties, |
59 base::TimeDelta duration); | 59 base::TimeDelta duration); |
| 60 |
60 virtual ~LayerAnimationElement(); | 61 virtual ~LayerAnimationElement(); |
61 | 62 |
62 // Creates an element that transitions to the given transform. The caller owns | 63 // Creates an element that transitions to the given transform. The caller owns |
63 // the return value. | 64 // the return value. |
64 static LayerAnimationElement* CreateTransformElement( | 65 static LayerAnimationElement* CreateTransformElement( |
65 const gfx::Transform& transform, | 66 const gfx::Transform& transform, |
66 base::TimeDelta duration); | 67 base::TimeDelta duration); |
67 | 68 |
| 69 // Creates an element that counters a transition to the given transform. |
| 70 // This element maintains the invariant uninverted_transition->at(t) * |
| 71 // this->at(t) == base_transform * this->at(t_start) for any t. The caller |
| 72 // owns the return value. |
| 73 static LayerAnimationElement* CreateInverseTransformElement( |
| 74 const gfx::Transform& base_transform, |
| 75 const LayerAnimationElement* uninverted_transition); |
| 76 |
68 // Creates an element that transitions to another in a way determined by an | 77 // Creates an element that transitions to another in a way determined by an |
69 // interpolated transform. The element accepts ownership of the interpolated | 78 // interpolated transform. The element accepts ownership of the interpolated |
70 // transform. NB: at every step, the interpolated transform clobbers the | 79 // transform. NB: at every step, the interpolated transform clobbers the |
71 // existing transform. That is, it does not interpolate between the existing | 80 // existing transform. That is, it does not interpolate between the existing |
72 // transform and the last value the interpolated transform will assume. It is | 81 // transform and the last value the interpolated transform will assume. It is |
73 // therefore important that the value of the interpolated at time 0 matches | 82 // therefore important that the value of the interpolated at time 0 matches |
74 // the current transform. | 83 // the current transform. |
75 static LayerAnimationElement* CreateInterpolatedTransformElement( | 84 static LayerAnimationElement* CreateInterpolatedTransformElement( |
76 InterpolatedTransform* interpolated_transform, | 85 InterpolatedTransform* interpolated_transform, |
77 base::TimeDelta duration); | 86 base::TimeDelta duration); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 Tween::Type tween_type() const { return tween_type_; } | 180 Tween::Type tween_type() const { return tween_type_; } |
172 void set_tween_type(Tween::Type tween_type) { tween_type_ = tween_type; } | 181 void set_tween_type(Tween::Type tween_type) { tween_type_ = tween_type; } |
173 | 182 |
174 // Each LayerAnimationElement has a unique animation_id. Elements belonging | 183 // Each LayerAnimationElement has a unique animation_id. Elements belonging |
175 // to sequences that are supposed to start together have the same | 184 // to sequences that are supposed to start together have the same |
176 // animation_group_id. | 185 // animation_group_id. |
177 int animation_id() const { return animation_id_; } | 186 int animation_id() const { return animation_id_; } |
178 int animation_group_id() const { return animation_group_id_; } | 187 int animation_group_id() const { return animation_group_id_; } |
179 void set_animation_group_id(int id) { animation_group_id_ = id; } | 188 void set_animation_group_id(int id) { animation_group_id_ = id; } |
180 | 189 |
| 190 base::TimeDelta duration() const { return duration_; } |
| 191 |
181 // The fraction of the animation that has been completed after the last | 192 // The fraction of the animation that has been completed after the last |
182 // call made to {Progress, ProgressToEnd}. | 193 // call made to {Progress, ProgressToEnd}. |
183 double last_progressed_fraction() const { return last_progressed_fraction_; } | 194 double last_progressed_fraction() const { return last_progressed_fraction_; } |
184 | 195 |
185 protected: | 196 protected: |
186 // Called once each time the animation element is run before any call to | 197 // Called once each time the animation element is run before any call to |
187 // OnProgress. | 198 // OnProgress. |
188 virtual void OnStart(LayerAnimationDelegate* delegate) = 0; | 199 virtual void OnStart(LayerAnimationDelegate* delegate) = 0; |
189 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) = 0; | 200 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) = 0; |
190 virtual void OnGetTarget(TargetValue* target) const = 0; | 201 virtual void OnGetTarget(TargetValue* target) const = 0; |
191 virtual void OnAbort(LayerAnimationDelegate* delegate) = 0; | 202 virtual void OnAbort(LayerAnimationDelegate* delegate) = 0; |
192 | 203 |
193 base::TimeDelta duration() const { return duration_; } | |
194 | |
195 // Actually start the animation, dispatching to another thread if needed. | 204 // Actually start the animation, dispatching to another thread if needed. |
196 virtual void RequestEffectiveStart(LayerAnimationDelegate* delegate); | 205 virtual void RequestEffectiveStart(LayerAnimationDelegate* delegate); |
197 | 206 |
| 207 LayerAnimationElement(const LayerAnimationElement& element); |
| 208 |
198 private: | 209 private: |
199 // For debugging purposes, we sometimes alter the duration we actually use. | 210 // For debugging purposes, we sometimes alter the duration we actually use. |
200 // For example, during tests we often set duration = 0, and it is sometimes | 211 // For example, during tests we often set duration = 0, and it is sometimes |
201 // useful to slow animations down to see them more clearly. | 212 // useful to slow animations down to see them more clearly. |
202 base::TimeDelta GetEffectiveDuration(const base::TimeDelta& delta); | 213 base::TimeDelta GetEffectiveDuration(const base::TimeDelta& delta); |
203 | 214 |
204 bool first_frame_; | 215 bool first_frame_; |
205 const AnimatableProperties properties_; | 216 const AnimatableProperties properties_; |
206 base::TimeTicks requested_start_time_; | 217 base::TimeTicks requested_start_time_; |
207 | 218 |
208 // When the animation actually started, taking into account queueing delays. | 219 // When the animation actually started, taking into account queueing delays. |
209 base::TimeTicks effective_start_time_; | 220 base::TimeTicks effective_start_time_; |
210 const base::TimeDelta duration_; | 221 const base::TimeDelta duration_; |
211 Tween::Type tween_type_; | 222 Tween::Type tween_type_; |
212 | 223 |
213 const int animation_id_; | 224 const int animation_id_; |
214 int animation_group_id_; | 225 int animation_group_id_; |
215 | 226 |
216 double last_progressed_fraction_; | 227 double last_progressed_fraction_; |
217 | 228 |
218 DISALLOW_COPY_AND_ASSIGN(LayerAnimationElement); | 229 DISALLOW_ASSIGN(LayerAnimationElement); |
219 }; | 230 }; |
220 | 231 |
221 } // namespace ui | 232 } // namespace ui |
222 | 233 |
223 #endif // UI_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_ | 234 #endif // UI_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_ |
OLD | NEW |