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/observer_list.h" |
| 13 #include "base/time.h" |
11 #include "cc/animation_events.h" | 14 #include "cc/animation_events.h" |
12 #include "cc/cc_export.h" | 15 #include "cc/cc_export.h" |
13 #include "cc/layer_animation_observer.h" | 16 #include "cc/layer_animation_event_observer.h" |
14 #include "cc/scoped_ptr_vector.h" | 17 #include "cc/scoped_ptr_vector.h" |
| 18 #include "ui/gfx/transform.h" |
15 | 19 |
16 namespace gfx { | 20 namespace gfx { |
17 class Transform; | 21 class Transform; |
18 } | 22 } |
19 | 23 |
20 namespace cc { | 24 namespace cc { |
21 | 25 |
22 class Animation; | 26 class Animation; |
| 27 class AnimationRegistrar; |
23 class KeyframeValueList; | 28 class KeyframeValueList; |
| 29 class LayerAnimationValueObserver; |
24 | 30 |
25 class CC_EXPORT LayerAnimationControllerClient { | 31 class CC_EXPORT LayerAnimationController |
| 32 : public base::RefCounted<LayerAnimationController>, |
| 33 public LayerAnimationEventObserver { |
26 public: | 34 public: |
27 virtual ~LayerAnimationControllerClient() { } | 35 static scoped_refptr<LayerAnimationController> create(int id); |
28 | 36 |
29 virtual int id() const = 0; | 37 int id() const { return m_id; } |
30 virtual void setOpacityFromAnimation(float) = 0; | |
31 virtual float opacity() const = 0; | |
32 virtual void setTransformFromAnimation(const gfx::Transform&) = 0; | |
33 virtual const gfx::Transform& transform() const = 0; | |
34 }; | |
35 | |
36 class CC_EXPORT LayerAnimationController : public LayerAnimationObserver { | |
37 public: | |
38 static scoped_ptr<LayerAnimationController> create(LayerAnimationControllerC
lient*); | |
39 | |
40 virtual ~LayerAnimationController(); | |
41 | 38 |
42 // These methods are virtual for testing. | 39 // These methods are virtual for testing. |
43 virtual void addAnimation(scoped_ptr<ActiveAnimation>); | 40 virtual void addAnimation(scoped_ptr<ActiveAnimation>); |
44 virtual void pauseAnimation(int animationId, double timeOffset); | 41 virtual void pauseAnimation(int animationId, double timeOffset); |
45 virtual void removeAnimation(int animationId); | 42 virtual void removeAnimation(int animationId); |
46 virtual void removeAnimation(int animationId, ActiveAnimation::TargetPropert
y); | 43 virtual void removeAnimation(int animationId, ActiveAnimation::TargetPropert
y); |
47 virtual void suspendAnimations(double monotonicTime); | 44 virtual void suspendAnimations(double monotonicTime); |
48 virtual void resumeAnimations(double monotonicTime); | 45 virtual void resumeAnimations(double monotonicTime); |
49 | 46 |
50 // Ensures that the list of active animations on the main thread and the imp
l thread | 47 // Ensures that the list of active animations on the main thread and the imp
l thread |
51 // are kept in sync. This function does not take ownership of the impl threa
d controller. | 48 // are kept in sync. This function does not take ownership of the impl threa
d controller. |
52 virtual void pushAnimationUpdatesTo(LayerAnimationController*); | 49 virtual void pushAnimationUpdatesTo(LayerAnimationController*); |
53 | 50 |
54 void animate(double monotonicTime, AnimationEventsVector*); | 51 void animate(double monotonicTime, AnimationEventsVector*); |
55 | 52 |
56 // Returns the active animation in the given group, animating the given prop
erty, if such an | 53 // Returns the active animation in the given group, animating the given prop
erty, if such an |
57 // animation exists. | 54 // animation exists. |
58 ActiveAnimation* getActiveAnimation(int groupId, ActiveAnimation::TargetProp
erty) const; | 55 ActiveAnimation* getActiveAnimation(int groupId, ActiveAnimation::TargetProp
erty) const; |
59 | 56 |
60 // Returns the active animation animating the given property that is either
running, or is | 57 // Returns the active animation animating the given property that is either
running, or is |
61 // next to run, if such an animation exists. | 58 // next to run, if such an animation exists. |
62 ActiveAnimation* getActiveAnimation(ActiveAnimation::TargetProperty) const; | 59 ActiveAnimation* getActiveAnimation(ActiveAnimation::TargetProperty) const; |
63 | 60 |
64 // Returns true if there are any animations that have neither finished nor a
borted. | 61 // Returns true if there are any animations that have neither finished nor a
borted. |
65 bool hasActiveAnimation() const; | 62 bool hasActiveAnimation() const; |
66 | 63 |
| 64 // Returns true if there are any animations at all to process. |
| 65 bool hasAnyAnimation() const { return !m_activeAnimations.isEmpty(); } |
| 66 |
67 // Returns true if there is an animation currently animating the given prope
rty, or | 67 // Returns true if there is an animation currently animating the given prope
rty, or |
68 // if there is an animation scheduled to animate this property in the future
. | 68 // if there is an animation scheduled to animate this property in the future
. |
69 bool isAnimatingProperty(ActiveAnimation::TargetProperty) const; | 69 bool isAnimatingProperty(ActiveAnimation::TargetProperty) const; |
70 | 70 |
71 // This is called in response to an animation being started on the impl thre
ad. This | 71 // This is called in response to an animation being started on the impl thre
ad. This |
72 // function updates the corresponding main thread animation's start time. | 72 // function updates the corresponding main thread animation's start time. |
73 virtual void OnAnimationStarted(const AnimationEvent&) OVERRIDE; | 73 virtual void OnAnimationStarted(const AnimationEvent&) OVERRIDE; |
74 | 74 |
75 // If a sync is forced, then the next time animation updates are pushed to t
he impl | 75 // If a sync is forced, then the next time animation updates are pushed to t
he impl |
76 // thread, all animations will be transferred. | 76 // thread, all animations will be transferred. |
77 void setForceSync() { m_forceSync = true; } | 77 void setForceSync() { m_forceSync = true; } |
78 | 78 |
79 void setClient(LayerAnimationControllerClient*); | 79 void setAnimationRegistrar(AnimationRegistrar*); |
| 80 |
| 81 void addObserver(LayerAnimationValueObserver*); |
| 82 void removeObserver(LayerAnimationValueObserver*); |
80 | 83 |
81 protected: | 84 protected: |
82 explicit LayerAnimationController(LayerAnimationControllerClient*); | 85 friend class base::RefCounted<LayerAnimationController>; |
| 86 |
| 87 LayerAnimationController(int id); |
| 88 virtual ~LayerAnimationController(); |
83 | 89 |
84 private: | 90 private: |
85 typedef base::hash_set<int> TargetProperties; | 91 typedef base::hash_set<int> TargetProperties; |
86 | 92 |
87 void pushNewAnimationsToImplThread(LayerAnimationController*) const; | 93 void pushNewAnimationsToImplThread(LayerAnimationController*) const; |
88 void removeAnimationsCompletedOnMainThread(LayerAnimationController*) const; | 94 void removeAnimationsCompletedOnMainThread(LayerAnimationController*) const; |
89 void pushPropertiesToImplThread(LayerAnimationController*) const; | 95 void pushPropertiesToImplThread(LayerAnimationController*) const; |
90 void replaceImplThreadAnimations(LayerAnimationController*) const; | 96 void replaceImplThreadAnimations(LayerAnimationController*) const; |
91 | 97 |
92 void startAnimationsWaitingForNextTick(double monotonicTime, AnimationEvents
Vector*); | 98 void startAnimationsWaitingForNextTick(double monotonicTime, AnimationEvents
Vector*); |
93 void startAnimationsWaitingForStartTime(double monotonicTime, AnimationEvent
sVector*); | 99 void startAnimationsWaitingForStartTime(double monotonicTime, AnimationEvent
sVector*); |
94 void startAnimationsWaitingForTargetAvailability(double monotonicTime, Anima
tionEventsVector*); | 100 void startAnimationsWaitingForTargetAvailability(double monotonicTime, Anima
tionEventsVector*); |
95 void resolveConflicts(double monotonicTime); | 101 void resolveConflicts(double monotonicTime); |
96 void markAnimationsForDeletion(double monotonicTime, AnimationEventsVector*)
; | 102 void markAnimationsForDeletion(double monotonicTime, AnimationEventsVector*)
; |
97 void purgeAnimationsMarkedForDeletion(); | 103 void purgeAnimationsMarkedForDeletion(); |
98 | 104 |
99 void tickAnimations(double monotonicTime); | 105 void tickAnimations(double monotonicTime); |
100 | 106 |
| 107 void updateActivation(bool force = false); |
| 108 |
| 109 void notifyObserversOpacityAnimated(float opacity); |
| 110 void notifyObserversTransformAnimated(const gfx::Transform& transform); |
| 111 |
101 // If this is true, we force a sync to the impl thread. | 112 // If this is true, we force a sync to the impl thread. |
102 bool m_forceSync; | 113 bool m_forceSync; |
103 | 114 |
104 LayerAnimationControllerClient* m_client; | 115 AnimationRegistrar* m_registrar; |
| 116 int m_id; |
105 ScopedPtrVector<ActiveAnimation> m_activeAnimations; | 117 ScopedPtrVector<ActiveAnimation> m_activeAnimations; |
106 | 118 |
| 119 // This is used to ensure that we don't spam the registrar. |
| 120 bool m_isActive; |
| 121 |
| 122 ObserverList<LayerAnimationValueObserver> m_observers; |
| 123 |
107 DISALLOW_COPY_AND_ASSIGN(LayerAnimationController); | 124 DISALLOW_COPY_AND_ASSIGN(LayerAnimationController); |
108 }; | 125 }; |
109 | 126 |
110 } // namespace cc | 127 } // namespace cc |
111 | 128 |
112 #endif // CC_LAYER_ANIMATION_CONTROLLER_H_ | 129 #endif // CC_LAYER_ANIMATION_CONTROLLER_H_ |
OLD | NEW |