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

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

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