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.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 Loading... |
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. |
| 137 void ProgressToEffectiveStart(LayerAnimationDelegate* delegate); |
121 | 138 |
122 // Updates the delegate to the appropriate value for |now|. Returns true | 139 // Updates the delegate to the appropriate value for |now|. Returns true |
123 // if a redraw is required. | 140 // if a redraw is required. |
124 bool Progress(base::TimeTicks now, LayerAnimationDelegate* delegate); | 141 bool Progress(base::TimeTicks now, LayerAnimationDelegate* delegate); |
125 | 142 |
126 // If calling Progress now, with the given time, will finish the animation, | 143 // 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 | 144 // returns true and sets |end_duration| to the actual duration for this |
128 // animation, incuding any queueing delays. | 145 // animation, incuding any queueing delays. |
129 bool IsFinished(base::TimeTicks time, base::TimeDelta* total_duration); | 146 bool IsFinished(base::TimeTicks time, base::TimeDelta* total_duration); |
130 | 147 |
131 // Updates the delegate to the end of the animation. Returns true if a | 148 // Updates the delegate to the end of the animation. Returns true if a |
132 // redraw is required. | 149 // redraw is required. |
133 bool ProgressToEnd(LayerAnimationDelegate* delegate); | 150 bool ProgressToEnd(LayerAnimationDelegate* delegate); |
134 | 151 |
135 // Called if the animation is not allowed to complete. This may be called | 152 // Called if the animation is not allowed to complete. This may be called |
136 // before OnStarted or Progress. | 153 // before OnStarted or Progress. |
137 void Abort(); | 154 void Abort(LayerAnimationDelegate* delegate); |
138 | 155 |
139 // Assigns the target value to |target|. | 156 // Assigns the target value to |target|. |
140 void GetTargetValue(TargetValue* target) const; | 157 void GetTargetValue(TargetValue* target) const; |
141 | 158 |
142 // The properties that the element modifies. | 159 // The properties that the element modifies. |
143 const AnimatableProperties& properties() const { return properties_; } | 160 const AnimatableProperties& properties() const { return properties_; } |
144 | 161 |
| 162 // Whether this element animates on the compositor thread. |
| 163 virtual bool IsThreaded() const; |
| 164 |
145 Tween::Type tween_type() const { return tween_type_; } | 165 Tween::Type tween_type() const { return tween_type_; } |
146 void set_tween_type(Tween::Type tween_type) { tween_type_ = tween_type; } | 166 void set_tween_type(Tween::Type tween_type) { tween_type_ = tween_type; } |
147 | 167 |
| 168 // Used to identify animations. |
| 169 int animation_id() const { return animation_id_; } |
| 170 void set_animation_id(int id) { animation_id_ = id; } |
| 171 int animation_group_id() const { return animation_group_id_; } |
| 172 void set_animation_group_id(int id) { animation_group_id_ = id; } |
| 173 |
148 protected: | 174 protected: |
149 // Called once each time the animation element is run before any call to | 175 // Called once each time the animation element is run before any call to |
150 // OnProgress. | 176 // OnProgress. |
151 virtual void OnStart(LayerAnimationDelegate* delegate) = 0; | 177 virtual void OnStart(LayerAnimationDelegate* delegate) = 0; |
152 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) = 0; | 178 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) = 0; |
153 virtual void OnGetTarget(TargetValue* target) const = 0; | 179 virtual void OnGetTarget(TargetValue* target) const = 0; |
154 virtual void OnAbort() = 0; | 180 virtual void OnAbort(LayerAnimationDelegate* delegate) = 0; |
| 181 |
| 182 base::TimeDelta duration() const { return duration_; } |
| 183 |
| 184 // Actually start the animation, dispatching to another thread if needed. |
| 185 virtual void RequestEffectiveStart(LayerAnimationDelegate* delegate); |
155 | 186 |
156 private: | 187 private: |
157 // For debugging purposes, we sometimes alter the duration we actually use. | 188 // 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 | 189 // For example, during tests we often set duration = 0, and it is sometimes |
159 // useful to slow animations down to see them more clearly. | 190 // useful to slow animations down to see them more clearly. |
160 base::TimeDelta GetEffectiveDuration(const base::TimeDelta& delta); | 191 base::TimeDelta GetEffectiveDuration(const base::TimeDelta& delta); |
161 | 192 |
162 bool first_frame_; | 193 bool first_frame_; |
163 const AnimatableProperties properties_; | 194 const AnimatableProperties properties_; |
164 base::TimeTicks start_time_; | 195 base::TimeTicks requested_start_time_; |
| 196 |
| 197 // When the animation actually started, taking into account queueing delays. |
| 198 base::TimeTicks effective_start_time_; |
165 const base::TimeDelta duration_; | 199 const base::TimeDelta duration_; |
166 Tween::Type tween_type_; | 200 Tween::Type tween_type_; |
167 | 201 |
| 202 int animation_id_; |
| 203 int animation_group_id_; |
| 204 |
168 DISALLOW_COPY_AND_ASSIGN(LayerAnimationElement); | 205 DISALLOW_COPY_AND_ASSIGN(LayerAnimationElement); |
169 }; | 206 }; |
170 | 207 |
171 } // namespace ui | 208 } // namespace ui |
172 | 209 |
173 #endif // UI_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_ | 210 #endif // UI_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_ |
OLD | NEW |