OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 CC_LAYER_ANIMATION_CONTROLLER_H_ | 5 #ifndef CC_LAYER_ANIMATION_CONTROLLER_H_ |
6 #define CC_LAYER_ANIMATION_CONTROLLER_H_ | 6 #define CC_LAYER_ANIMATION_CONTROLLER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/hash_tables.h" | 9 #include "base/hash_tables.h" |
| 10 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/time.h" |
11 #include "cc/animation_events.h" | 13 #include "cc/animation_events.h" |
12 #include "cc/cc_export.h" | 14 #include "cc/cc_export.h" |
13 #include "cc/scoped_ptr_vector.h" | 15 #include "cc/scoped_ptr_vector.h" |
| 16 #include "ui/gfx/transform.h" |
14 | 17 |
15 namespace gfx { | 18 namespace gfx { |
16 class Transform; | 19 class Transform; |
17 } | 20 } |
18 | 21 |
19 namespace cc { | 22 namespace cc { |
20 | 23 |
21 class Animation; | 24 class Animation; |
| 25 class AnimationRegistrar; |
22 class KeyframeValueList; | 26 class KeyframeValueList; |
23 | 27 |
24 class CC_EXPORT LayerAnimationControllerClient { | 28 class CC_EXPORT LayerAnimationController |
| 29 : public base::RefCounted<LayerAnimationController> { |
25 public: | 30 public: |
26 virtual ~LayerAnimationControllerClient() { } | 31 static scoped_refptr<LayerAnimationController> create(); |
27 | |
28 virtual int id() const = 0; | |
29 virtual void setOpacityFromAnimation(float) = 0; | |
30 virtual float opacity() const = 0; | |
31 virtual void setTransformFromAnimation(const gfx::Transform&) = 0; | |
32 virtual const gfx::Transform& transform() const = 0; | |
33 }; | |
34 | |
35 class CC_EXPORT LayerAnimationController { | |
36 public: | |
37 static scoped_ptr<LayerAnimationController> create(LayerAnimationControllerC
lient*); | |
38 | |
39 virtual ~LayerAnimationController(); | |
40 | 32 |
41 // These methods are virtual for testing. | 33 // These methods are virtual for testing. |
42 virtual void addAnimation(scoped_ptr<ActiveAnimation>); | 34 virtual void addAnimation(scoped_ptr<ActiveAnimation>); |
43 virtual void pauseAnimation(int animationId, double timeOffset); | 35 virtual void pauseAnimation(int animationId, double timeOffset); |
44 virtual void removeAnimation(int animationId); | 36 virtual void removeAnimation(int animationId); |
45 virtual void removeAnimation(int animationId, ActiveAnimation::TargetPropert
y); | 37 virtual void removeAnimation(int animationId, ActiveAnimation::TargetPropert
y); |
46 virtual void suspendAnimations(double monotonicTime); | 38 virtual void suspendAnimations(double monotonicTime); |
47 virtual void resumeAnimations(double monotonicTime); | 39 virtual void resumeAnimations(double monotonicTime); |
48 | 40 |
49 // Ensures that the list of active animations on the main thread and the imp
l thread | 41 // Ensures that the list of active animations on the main thread and the imp
l thread |
(...skipping 18 matching lines...) Expand all Loading... |
68 bool isAnimatingProperty(ActiveAnimation::TargetProperty) const; | 60 bool isAnimatingProperty(ActiveAnimation::TargetProperty) const; |
69 | 61 |
70 // This is called in response to an animation being started on the impl thre
ad. This | 62 // This is called in response to an animation being started on the impl thre
ad. This |
71 // function updates the corresponding main thread animation's start time. | 63 // function updates the corresponding main thread animation's start time. |
72 void notifyAnimationStarted(const AnimationEvent&); | 64 void notifyAnimationStarted(const AnimationEvent&); |
73 | 65 |
74 // If a sync is forced, then the next time animation updates are pushed to t
he impl | 66 // If a sync is forced, then the next time animation updates are pushed to t
he impl |
75 // thread, all animations will be transferred. | 67 // thread, all animations will be transferred. |
76 void setForceSync() { m_forceSync = true; } | 68 void setForceSync() { m_forceSync = true; } |
77 | 69 |
78 void setClient(LayerAnimationControllerClient*); | 70 void setAnimationRegistrar(AnimationRegistrar*); |
| 71 void setId(int id); |
| 72 |
| 73 // Gets the last animated opacity value. |
| 74 float opacity() const { return m_opacity; } |
| 75 |
| 76 // Returns the time at which opacity was updated. |
| 77 base::TimeTicks opacityLastUpdateTime() const { return m_opacityLastUpdateTi
me; } |
| 78 |
| 79 // Gets the last animate transform value. |
| 80 const gfx::Transform& transform() const { return m_transform; } |
| 81 |
| 82 // Returns the time at which the transform was updated. |
| 83 base::TimeTicks transformLastUpdateTime() const { return m_transformLastUpda
teTime; } |
79 | 84 |
80 protected: | 85 protected: |
81 explicit LayerAnimationController(LayerAnimationControllerClient*); | 86 friend class base::RefCounted<LayerAnimationController>; |
| 87 |
| 88 LayerAnimationController(); |
| 89 virtual ~LayerAnimationController(); |
82 | 90 |
83 private: | 91 private: |
84 typedef base::hash_set<int> TargetProperties; | 92 typedef base::hash_set<int> TargetProperties; |
85 | 93 |
86 void pushNewAnimationsToImplThread(LayerAnimationController*) const; | 94 void pushNewAnimationsToImplThread(LayerAnimationController*) const; |
87 void removeAnimationsCompletedOnMainThread(LayerAnimationController*) const; | 95 void removeAnimationsCompletedOnMainThread(LayerAnimationController*) const; |
88 void pushPropertiesToImplThread(LayerAnimationController*) const; | 96 void pushPropertiesToImplThread(LayerAnimationController*) const; |
89 void replaceImplThreadAnimations(LayerAnimationController*) const; | 97 void replaceImplThreadAnimations(LayerAnimationController*) const; |
90 | 98 |
91 void startAnimationsWaitingForNextTick(double monotonicTime, AnimationEvents
Vector*); | 99 void startAnimationsWaitingForNextTick(double monotonicTime, AnimationEvents
Vector*); |
92 void startAnimationsWaitingForStartTime(double monotonicTime, AnimationEvent
sVector*); | 100 void startAnimationsWaitingForStartTime(double monotonicTime, AnimationEvent
sVector*); |
93 void startAnimationsWaitingForTargetAvailability(double monotonicTime, Anima
tionEventsVector*); | 101 void startAnimationsWaitingForTargetAvailability(double monotonicTime, Anima
tionEventsVector*); |
94 void resolveConflicts(double monotonicTime); | 102 void resolveConflicts(double monotonicTime); |
95 void markAnimationsForDeletion(double monotonicTime, AnimationEventsVector*)
; | 103 void markAnimationsForDeletion(double monotonicTime, AnimationEventsVector*)
; |
96 void purgeAnimationsMarkedForDeletion(); | 104 void purgeAnimationsMarkedForDeletion(); |
97 | 105 |
98 void tickAnimations(double monotonicTime); | 106 void tickAnimations(double monotonicTime); |
99 | 107 |
| 108 void updateRegistration(); |
| 109 |
100 // If this is true, we force a sync to the impl thread. | 110 // If this is true, we force a sync to the impl thread. |
101 bool m_forceSync; | 111 bool m_forceSync; |
102 | 112 |
103 LayerAnimationControllerClient* m_client; | 113 base::TimeTicks m_opacityLastUpdateTime; |
| 114 base::TimeTicks m_transformLastUpdateTime; |
| 115 |
| 116 float m_opacity; |
| 117 gfx::Transform m_transform; |
| 118 |
| 119 AnimationRegistrar* m_registrar; |
| 120 int m_id; |
104 ScopedPtrVector<ActiveAnimation> m_activeAnimations; | 121 ScopedPtrVector<ActiveAnimation> m_activeAnimations; |
105 | 122 |
106 DISALLOW_COPY_AND_ASSIGN(LayerAnimationController); | 123 DISALLOW_COPY_AND_ASSIGN(LayerAnimationController); |
107 }; | 124 }; |
108 | 125 |
109 } // namespace cc | 126 } // namespace cc |
110 | 127 |
111 #endif // CC_LAYER_ANIMATION_CONTROLLER_H_ | 128 #endif // CC_LAYER_ANIMATION_CONTROLLER_H_ |
OLD | NEW |