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_ANIMATION_LAYER_ANIMATION_CONTROLLER_H_ | 5 #ifndef CC_ANIMATION_LAYER_ANIMATION_CONTROLLER_H_ |
6 #define CC_ANIMATION_LAYER_ANIMATION_CONTROLLER_H_ | 6 #define CC_ANIMATION_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/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "cc/animation/animation_events.h" | 14 #include "cc/animation/animation_events.h" |
15 #include "cc/animation/layer_animation_event_observer.h" | 15 #include "cc/animation/layer_animation_event_observer.h" |
16 #include "cc/base/cc_export.h" | 16 #include "cc/base/cc_export.h" |
17 #include "cc/base/scoped_ptr_vector.h" | 17 #include "cc/base/scoped_ptr_vector.h" |
18 #include "ui/gfx/transform.h" | 18 #include "ui/gfx/transform.h" |
19 | 19 |
20 namespace WebKit { | |
21 class WebAnimationDelegate; | |
22 } | |
23 | |
20 namespace gfx { class Transform; } | 24 namespace gfx { class Transform; } |
21 | 25 |
22 namespace cc { | 26 namespace cc { |
23 | 27 |
24 class Animation; | 28 class Animation; |
25 class AnimationRegistrar; | 29 class AnimationRegistrar; |
26 class KeyframeValueList; | 30 class KeyframeValueList; |
27 class LayerAnimationValueObserver; | 31 class LayerAnimationValueObserver; |
28 | 32 |
29 class CC_EXPORT LayerAnimationController | 33 class CC_EXPORT LayerAnimationController |
30 : public base::RefCounted<LayerAnimationController>, | 34 : public base::RefCounted<LayerAnimationController> { |
31 public LayerAnimationEventObserver { | |
32 public: | 35 public: |
33 static scoped_refptr<LayerAnimationController> Create(int id); | 36 static scoped_refptr<LayerAnimationController> Create(int id); |
34 | 37 |
35 int id() const { return id_; } | 38 int id() const { return id_; } |
36 | 39 |
37 // These methods are virtual for testing. | 40 // These methods are virtual for testing. |
38 virtual void AddAnimation(scoped_ptr<Animation> animation); | 41 virtual void AddAnimation(scoped_ptr<Animation> animation); |
39 virtual void PauseAnimation(int animation_id, double time_offset); | 42 virtual void PauseAnimation(int animation_id, double time_offset); |
40 virtual void RemoveAnimation(int animation_id); | 43 virtual void RemoveAnimation(int animation_id); |
41 virtual void RemoveAnimation(int animation_id, | 44 virtual void RemoveAnimation(int animation_id, |
42 Animation::TargetProperty target_property); | 45 Animation::TargetProperty target_property); |
43 virtual void SuspendAnimations(double monotonic_time); | 46 virtual void SuspendAnimations(double monotonic_time); |
44 virtual void ResumeAnimations(double monotonic_time); | 47 virtual void ResumeAnimations(double monotonic_time); |
45 | 48 |
46 // Ensures that the list of active animations on the main thread and the impl | 49 // Ensures that the list of active animations on the main thread and the impl |
47 // thread are kept in sync. This function does not take ownership of the impl | 50 // thread are kept in sync. This function does not take ownership of the impl |
48 // thread controller. | 51 // thread controller. |
49 virtual void PushAnimationUpdatesTo( | 52 virtual void PushAnimationUpdatesTo( |
50 LayerAnimationController* controller_impl); | 53 LayerAnimationController* controller_impl); |
51 | 54 |
55 // Transfers ownership of all animations to other_controller, replacing | |
Ian Vollick
2013/04/04 18:38:58
I think it would really help if you explained how
ajuma
2013/04/05 14:38:18
Done.
| |
56 // any animations currently owned by other_controller. | |
57 void TransferAnimationsTo(LayerAnimationController* other_controller); | |
58 | |
52 void Animate(double monotonic_time); | 59 void Animate(double monotonic_time); |
53 void AccumulatePropertyUpdates(double monotonic_time, | 60 void AccumulatePropertyUpdates(double monotonic_time, |
54 AnimationEventsVector* events); | 61 AnimationEventsVector* events); |
55 void UpdateState(AnimationEventsVector* events); | 62 void UpdateState(AnimationEventsVector* events); |
56 | 63 |
57 // Returns the active animation in the given group, animating the given | 64 // Returns the active animation in the given group, animating the given |
58 // property, if such an animation exists. | 65 // property, if such an animation exists. |
59 Animation* GetAnimation(int group_id, | 66 Animation* GetAnimation(int group_id, |
60 Animation::TargetProperty target_property) const; | 67 Animation::TargetProperty target_property) const; |
61 | 68 |
62 // Returns the active animation animating the given property that is either | 69 // Returns the active animation animating the given property that is either |
63 // running, or is next to run, if such an animation exists. | 70 // running, or is next to run, if such an animation exists. |
64 Animation* GetAnimation(Animation::TargetProperty target_property) const; | 71 Animation* GetAnimation(Animation::TargetProperty target_property) const; |
65 | 72 |
66 // Returns true if there are any animations that have neither finished nor | 73 // Returns true if there are any animations that have neither finished nor |
67 // aborted. | 74 // aborted. |
68 bool HasActiveAnimation() const; | 75 bool HasActiveAnimation() const; |
69 | 76 |
70 // Returns true if there are any animations at all to process. | 77 // Returns true if there are any animations at all to process. |
71 bool has_any_animation() const { return !active_animations_.empty(); } | 78 bool has_any_animation() const { return !active_animations_.empty(); } |
72 | 79 |
73 // Returns true if there is an animation currently animating the given | 80 // Returns true if there is an animation currently animating the given |
74 // property, or if there is an animation scheduled to animate this property in | 81 // property, or if there is an animation scheduled to animate this property in |
75 // the future. | 82 // the future. |
76 bool IsAnimatingProperty(Animation::TargetProperty target_property) const; | 83 bool IsAnimatingProperty(Animation::TargetProperty target_property) const; |
77 | 84 |
78 // This is called in response to an animation being started on the impl | |
79 // thread. This function updates the corresponding main thread animation's | |
80 // start time. | |
81 virtual void OnAnimationStarted(const AnimationEvent& event) OVERRIDE; | |
82 | |
83 // If a sync is forced, then the next time animation updates are pushed to the | 85 // If a sync is forced, then the next time animation updates are pushed to the |
84 // impl thread, all animations will be transferred. | 86 // impl thread, all animations will be transferred. |
85 void set_force_sync() { force_sync_ = true; } | 87 void set_force_sync() { force_sync_ = true; } |
86 | 88 |
87 void SetAnimationRegistrar(AnimationRegistrar* registrar); | 89 void SetAnimationRegistrar(AnimationRegistrar* registrar); |
88 AnimationRegistrar* animation_registrar() { return registrar_; } | 90 AnimationRegistrar* animation_registrar() { return registrar_; } |
89 | 91 |
90 void AddObserver(LayerAnimationValueObserver* observer); | 92 void NotifyAnimationStarted(const AnimationEvent& event, |
91 void RemoveObserver(LayerAnimationValueObserver* observer); | 93 double wall_clock_time); |
94 void NotifyAnimationFinished(const AnimationEvent& event, | |
95 double wall_clock_time); | |
96 void NotifyAnimationPropertyUpdate(const AnimationEvent& event); | |
97 | |
98 void AddValueObserver(LayerAnimationValueObserver* observer); | |
99 void RemoveValueObserver(LayerAnimationValueObserver* observer); | |
100 | |
101 void AddEventObserver(LayerAnimationEventObserver* observer); | |
102 void RemoveEventObserver(LayerAnimationEventObserver* observer); | |
103 | |
104 void set_layer_animation_delegate(WebKit::WebAnimationDelegate* delegate) { | |
105 layer_animation_delegate_ = delegate; | |
106 } | |
92 | 107 |
93 protected: | 108 protected: |
94 friend class base::RefCounted<LayerAnimationController>; | 109 friend class base::RefCounted<LayerAnimationController>; |
95 | 110 |
96 explicit LayerAnimationController(int id); | 111 explicit LayerAnimationController(int id); |
97 virtual ~LayerAnimationController(); | 112 virtual ~LayerAnimationController(); |
98 | 113 |
99 private: | 114 private: |
100 typedef base::hash_set<int> TargetProperties; | 115 typedef base::hash_set<int> TargetProperties; |
101 | 116 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 | 152 |
138 AnimationRegistrar* registrar_; | 153 AnimationRegistrar* registrar_; |
139 int id_; | 154 int id_; |
140 ScopedPtrVector<Animation> active_animations_; | 155 ScopedPtrVector<Animation> active_animations_; |
141 | 156 |
142 // This is used to ensure that we don't spam the registrar. | 157 // This is used to ensure that we don't spam the registrar. |
143 bool is_active_; | 158 bool is_active_; |
144 | 159 |
145 double last_tick_time_; | 160 double last_tick_time_; |
146 | 161 |
147 ObserverList<LayerAnimationValueObserver> observers_; | 162 ObserverList<LayerAnimationValueObserver> value_observers_; |
163 ObserverList<LayerAnimationEventObserver> event_observers_; | |
164 | |
165 WebKit::WebAnimationDelegate* layer_animation_delegate_; | |
148 | 166 |
149 DISALLOW_COPY_AND_ASSIGN(LayerAnimationController); | 167 DISALLOW_COPY_AND_ASSIGN(LayerAnimationController); |
150 }; | 168 }; |
151 | 169 |
152 } // namespace cc | 170 } // namespace cc |
153 | 171 |
154 #endif // CC_ANIMATION_LAYER_ANIMATION_CONTROLLER_H_ | 172 #endif // CC_ANIMATION_LAYER_ANIMATION_CONTROLLER_H_ |
OLD | NEW |