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

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

Issue 291843012: compositor: Tick the UI animations from cc, instead of from timer callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « ui/compositor/layer_animation_delegate.h ('k') | ui/compositor/layer_animator.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_ANIMATOR_H_ 5 #ifndef UI_COMPOSITOR_LAYER_ANIMATOR_H_
6 #define UI_COMPOSITOR_LAYER_ANIMATOR_H_ 6 #define UI_COMPOSITOR_LAYER_ANIMATOR_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h"
12 #include "base/memory/linked_ptr.h" 13 #include "base/memory/linked_ptr.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
14 #include "base/observer_list.h" 15 #include "base/observer_list.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "ui/compositor/compositor_export.h" 17 #include "ui/compositor/compositor_export.h"
17 #include "ui/compositor/layer_animation_element.h" 18 #include "ui/compositor/layer_animation_element.h"
18 #include "ui/gfx/animation/animation_container_element.h"
19 #include "ui/gfx/animation/tween.h" 19 #include "ui/gfx/animation/tween.h"
20 20
21 namespace gfx { 21 namespace gfx {
22 class Animation; 22 class Animation;
23 class Rect; 23 class Rect;
24 class Transform; 24 class Transform;
25 } 25 }
26 26
27 namespace ui { 27 namespace ui {
28 class Layer; 28 class Layer;
29 class LayerAnimationSequence; 29 class LayerAnimationSequence;
30 class LayerAnimationDelegate; 30 class LayerAnimationDelegate;
31 class LayerAnimationObserver; 31 class LayerAnimationObserver;
32 class LayerAnimatorCollection;
32 class ScopedLayerAnimationSettings; 33 class ScopedLayerAnimationSettings;
33 34
34 // When a property of layer needs to be changed it is set by way of 35 // When a property of layer needs to be changed it is set by way of
35 // LayerAnimator. This enables LayerAnimator to animate property changes. 36 // LayerAnimator. This enables LayerAnimator to animate property changes.
36 // NB: during many tests, set_disable_animations_for_test is used and causes 37 // NB: during many tests, set_disable_animations_for_test is used and causes
37 // all animations to complete immediately. The layer animation is ref counted 38 // all animations to complete immediately. The layer animation is ref counted
38 // so that if its owning layer is deleted (and the owning layer is only other 39 // so that if its owning layer is deleted (and the owning layer is only other
39 // class that should ever hold a ref ptr to a LayerAnimator), the animator can 40 // class that should ever hold a ref ptr to a LayerAnimator), the animator can
40 // ensure that it is not disposed of until it finishes executing. It does this 41 // ensure that it is not disposed of until it finishes executing. It does this
41 // by holding a reference to itself for the duration of methods for which it 42 // by holding a reference to itself for the duration of methods for which it
42 // must guarantee that |this| is valid. 43 // must guarantee that |this| is valid.
43 class COMPOSITOR_EXPORT LayerAnimator 44 class COMPOSITOR_EXPORT LayerAnimator : public base::RefCounted<LayerAnimator> {
44 : public gfx::AnimationContainerElement,
45 public base::RefCounted<LayerAnimator> {
46 public: 45 public:
47 enum PreemptionStrategy { 46 enum PreemptionStrategy {
48 IMMEDIATELY_SET_NEW_TARGET, 47 IMMEDIATELY_SET_NEW_TARGET,
49 IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 48 IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
50 ENQUEUE_NEW_ANIMATION, 49 ENQUEUE_NEW_ANIMATION,
51 REPLACE_QUEUED_ANIMATIONS, 50 REPLACE_QUEUED_ANIMATIONS,
52 BLEND_WITH_CURRENT_ANIMATION 51 BLEND_WITH_CURRENT_ANIMATION
53 }; 52 };
54 53
55 explicit LayerAnimator(base::TimeDelta transition_duration); 54 explicit LayerAnimator(base::TimeDelta transition_duration);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // For testing purposes only. 180 // For testing purposes only.
182 void set_disable_timer_for_test(bool disable_timer) { 181 void set_disable_timer_for_test(bool disable_timer) {
183 disable_timer_for_test_ = disable_timer; 182 disable_timer_for_test_ = disable_timer;
184 } 183 }
185 184
186 void set_last_step_time(base::TimeTicks time) { 185 void set_last_step_time(base::TimeTicks time) {
187 last_step_time_ = time; 186 last_step_time_ = time;
188 } 187 }
189 base::TimeTicks last_step_time() const { return last_step_time_; } 188 base::TimeTicks last_step_time() const { return last_step_time_; }
190 189
190 void Step(base::TimeTicks time_now);
191
192 void AddToCollection(LayerAnimatorCollection* collection);
193 void RemoveFromCollection(LayerAnimatorCollection* collection);
194
191 protected: 195 protected:
192 virtual ~LayerAnimator(); 196 virtual ~LayerAnimator();
193 197
194 LayerAnimationDelegate* delegate() { return delegate_; } 198 LayerAnimationDelegate* delegate() { return delegate_; }
195 const LayerAnimationDelegate* delegate() const { return delegate_; } 199 const LayerAnimationDelegate* delegate() const { return delegate_; }
196 200
197 // Virtual for testing. 201 // Virtual for testing.
198 virtual void ProgressAnimation(LayerAnimationSequence* sequence, 202 virtual void ProgressAnimation(LayerAnimationSequence* sequence,
199 base::TimeTicks now); 203 base::TimeTicks now);
200 204
201 void ProgressAnimationToEnd(LayerAnimationSequence* sequence); 205 void ProgressAnimationToEnd(LayerAnimationSequence* sequence);
202 206
203 // Returns true if the sequence is owned by this animator. 207 // Returns true if the sequence is owned by this animator.
204 bool HasAnimation(LayerAnimationSequence* sequence) const; 208 bool HasAnimation(LayerAnimationSequence* sequence) const;
205 209
206 private: 210 private:
207 friend class base::RefCounted<LayerAnimator>; 211 friend class base::RefCounted<LayerAnimator>;
208 friend class ScopedLayerAnimationSettings; 212 friend class ScopedLayerAnimationSettings;
209 friend class LayerAnimatorTestController; 213 friend class LayerAnimatorTestController;
214 FRIEND_TEST_ALL_PREFIXES(LayerAnimatorTest, AnimatorStartedCorrectly);
215 FRIEND_TEST_ALL_PREFIXES(LayerAnimatorTest,
216 AnimatorRemovedFromCollectionWhenLayerIsDestroyed);
210 217
211 class RunningAnimation { 218 class RunningAnimation {
212 public: 219 public:
213 RunningAnimation(const base::WeakPtr<LayerAnimationSequence>& sequence); 220 RunningAnimation(const base::WeakPtr<LayerAnimationSequence>& sequence);
214 ~RunningAnimation(); 221 ~RunningAnimation();
215 222
216 bool is_sequence_alive() const { return !!sequence_.get(); } 223 bool is_sequence_alive() const { return !!sequence_.get(); }
217 LayerAnimationSequence* sequence() const { return sequence_.get(); } 224 LayerAnimationSequence* sequence() const { return sequence_.get(); }
218 225
219 private: 226 private:
220 base::WeakPtr<LayerAnimationSequence> sequence_; 227 base::WeakPtr<LayerAnimationSequence> sequence_;
221 228
222 // Copy and assign are allowed. 229 // Copy and assign are allowed.
223 }; 230 };
224 231
225 typedef std::vector<RunningAnimation> RunningAnimations; 232 typedef std::vector<RunningAnimation> RunningAnimations;
226 typedef std::deque<linked_ptr<LayerAnimationSequence> > AnimationQueue; 233 typedef std::deque<linked_ptr<LayerAnimationSequence> > AnimationQueue;
227 234
228 // Implementation of AnimationContainerElement
229 virtual void SetStartTime(base::TimeTicks start_time) OVERRIDE;
230 virtual void Step(base::TimeTicks time_now) OVERRIDE;
231 virtual base::TimeDelta GetTimerInterval() const OVERRIDE;
232
233 // Finishes all animations by either advancing them to their final state or by 235 // Finishes all animations by either advancing them to their final state or by
234 // aborting them. 236 // aborting them.
235 void StopAnimatingInternal(bool abort); 237 void StopAnimatingInternal(bool abort);
236 238
237 // Starts or stops stepping depending on whether thare are running animations. 239 // Starts or stops stepping depending on whether thare are running animations.
238 void UpdateAnimationState(); 240 void UpdateAnimationState();
239 241
240 // Removes the sequences from both the running animations and the queue. 242 // Removes the sequences from both the running animations and the queue.
241 // Returns a pointer to the removed animation, if any. NOTE: the caller is 243 // Returns a pointer to the removed animation, if any. NOTE: the caller is
242 // responsible for deleting the returned pointer. 244 // responsible for deleting the returned pointer.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 // Sets |transition_duration_| unless |is_transition_duration_locked_| is set. 302 // Sets |transition_duration_| unless |is_transition_duration_locked_| is set.
301 void SetTransitionDuration(base::TimeDelta duration); 303 void SetTransitionDuration(base::TimeDelta duration);
302 304
303 // Clears the animation queues and notifies any running animations that they 305 // Clears the animation queues and notifies any running animations that they
304 // have been aborted. 306 // have been aborted.
305 void ClearAnimationsInternal(); 307 void ClearAnimationsInternal();
306 308
307 // Cleans up any running animations that may have been deleted. 309 // Cleans up any running animations that may have been deleted.
308 void PurgeDeletedAnimations(); 310 void PurgeDeletedAnimations();
309 311
312 LayerAnimatorCollection* GetLayerAnimatorCollection();
313
310 // This is the queue of animations to run. 314 // This is the queue of animations to run.
311 AnimationQueue animation_queue_; 315 AnimationQueue animation_queue_;
312 316
313 // The target of all layer animations. 317 // The target of all layer animations.
314 LayerAnimationDelegate* delegate_; 318 LayerAnimationDelegate* delegate_;
315 319
316 // The currently running animations. 320 // The currently running animations.
317 RunningAnimations running_animations_; 321 RunningAnimations running_animations_;
318 322
319 // Determines how animations are replaced. 323 // Determines how animations are replaced.
(...skipping 26 matching lines...) Expand all
346 // Observers are notified when layer animations end, are scheduled or are 350 // Observers are notified when layer animations end, are scheduled or are
347 // aborted. 351 // aborted.
348 ObserverList<LayerAnimationObserver> observers_; 352 ObserverList<LayerAnimationObserver> observers_;
349 353
350 DISALLOW_COPY_AND_ASSIGN(LayerAnimator); 354 DISALLOW_COPY_AND_ASSIGN(LayerAnimator);
351 }; 355 };
352 356
353 } // namespace ui 357 } // namespace ui
354 358
355 #endif // UI_COMPOSITOR_LAYER_ANIMATOR_H_ 359 #endif // UI_COMPOSITOR_LAYER_ANIMATOR_H_
OLDNEW
« no previous file with comments | « ui/compositor/layer_animation_delegate.h ('k') | ui/compositor/layer_animator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698