IndexedDB: fsync after transactions.
[chromium-blink-merge.git] / cc / animation / layer_animation_controller.h
blobbb75107f8938528c38d3bfae95ee38f8efb7f944
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
3 // found in the LICENSE file.
5 #ifndef CC_ANIMATION_LAYER_ANIMATION_CONTROLLER_H_
6 #define CC_ANIMATION_LAYER_ANIMATION_CONTROLLER_H_
8 #include "base/basictypes.h"
9 #include "base/containers/hash_tables.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h"
13 #include "base/time/time.h"
14 #include "cc/animation/animation_events.h"
15 #include "cc/animation/layer_animation_event_observer.h"
16 #include "cc/base/cc_export.h"
17 #include "cc/base/scoped_ptr_vector.h"
18 #include "ui/gfx/transform.h"
20 namespace gfx {
21 class BoxF;
22 class Transform;
25 namespace cc {
27 class Animation;
28 class AnimationDelegate;
29 class AnimationRegistrar;
30 class FilterOperations;
31 class KeyframeValueList;
32 class LayerAnimationValueObserver;
33 class LayerAnimationValueProvider;
35 class CC_EXPORT LayerAnimationController
36 : public base::RefCounted<LayerAnimationController> {
37 public:
38 static scoped_refptr<LayerAnimationController> Create(int id);
40 int id() const { return id_; }
42 void AddAnimation(scoped_ptr<Animation> animation);
43 void PauseAnimation(int animation_id, double time_offset);
44 void RemoveAnimation(int animation_id);
45 void RemoveAnimation(int animation_id,
46 Animation::TargetProperty target_property);
47 void AbortAnimations(Animation::TargetProperty target_property);
49 // Ensures that the list of active animations on the main thread and the impl
50 // thread are kept in sync. This function does not take ownership of the impl
51 // thread controller. This method is virtual for testing.
52 virtual void PushAnimationUpdatesTo(
53 LayerAnimationController* controller_impl);
55 void Animate(double monotonic_time);
56 void AccumulatePropertyUpdates(double monotonic_time,
57 AnimationEventsVector* events);
59 void UpdateState(bool start_ready_animations,
60 AnimationEventsVector* events);
62 // Returns the active animation in the given group, animating the given
63 // property, if such an animation exists.
64 Animation* GetAnimation(int group_id,
65 Animation::TargetProperty target_property) const;
67 // Returns the active animation animating the given property that is either
68 // running, or is next to run, if such an animation exists.
69 Animation* GetAnimation(Animation::TargetProperty target_property) const;
71 // Returns true if there are any animations that have neither finished nor
72 // aborted.
73 bool HasActiveAnimation() const;
75 // Returns true if there are any animations at all to process.
76 bool has_any_animation() const { return !active_animations_.empty(); }
78 // Returns true if there is an animation currently animating the given
79 // property, or if there is an animation scheduled to animate this property in
80 // the future.
81 bool IsAnimatingProperty(Animation::TargetProperty target_property) const;
83 void SetAnimationRegistrar(AnimationRegistrar* registrar);
84 AnimationRegistrar* animation_registrar() { return registrar_; }
86 void NotifyAnimationStarted(const AnimationEvent& event,
87 double wall_clock_time);
88 void NotifyAnimationFinished(const AnimationEvent& event,
89 double wall_clock_time);
90 void NotifyAnimationAborted(const AnimationEvent& event);
91 void NotifyAnimationPropertyUpdate(const AnimationEvent& event);
93 void AddValueObserver(LayerAnimationValueObserver* observer);
94 void RemoveValueObserver(LayerAnimationValueObserver* observer);
96 void AddEventObserver(LayerAnimationEventObserver* observer);
97 void RemoveEventObserver(LayerAnimationEventObserver* observer);
99 void set_value_provider(LayerAnimationValueProvider* provider) {
100 value_provider_ = provider;
103 void remove_value_provider(LayerAnimationValueProvider* provider) {
104 if (value_provider_ == provider)
105 value_provider_ = NULL;
108 void set_layer_animation_delegate(AnimationDelegate* delegate) {
109 layer_animation_delegate_ = delegate;
112 bool HasFilterAnimationThatInflatesBounds() const;
113 bool HasTransformAnimationThatInflatesBounds() const;
114 bool HasAnimationThatInflatesBounds() const {
115 return HasTransformAnimationThatInflatesBounds() ||
116 HasFilterAnimationThatInflatesBounds();
119 bool FilterAnimationBoundsForBox(const gfx::BoxF& box,
120 gfx::BoxF* bounds) const;
121 bool TransformAnimationBoundsForBox(const gfx::BoxF& box,
122 gfx::BoxF* bounds) const;
124 protected:
125 friend class base::RefCounted<LayerAnimationController>;
127 explicit LayerAnimationController(int id);
128 virtual ~LayerAnimationController();
130 private:
131 typedef base::hash_set<int> TargetProperties;
133 void PushNewAnimationsToImplThread(
134 LayerAnimationController* controller_impl) const;
135 void RemoveAnimationsCompletedOnMainThread(
136 LayerAnimationController* controller_impl) const;
137 void PushPropertiesToImplThread(
138 LayerAnimationController* controller_impl) const;
140 void StartAnimations(double monotonic_time);
141 void PromoteStartedAnimations(double monotonic_time,
142 AnimationEventsVector* events);
143 void MarkFinishedAnimations(double monotonic_time);
144 void MarkAnimationsForDeletion(double monotonic_time,
145 AnimationEventsVector* events);
146 void PurgeAnimationsMarkedForDeletion();
148 void TickAnimations(double monotonic_time);
150 enum UpdateActivationType {
151 NormalActivation,
152 ForceActivation
154 void UpdateActivation(UpdateActivationType type);
156 void NotifyObserversOpacityAnimated(float opacity);
157 void NotifyObserversTransformAnimated(const gfx::Transform& transform);
158 void NotifyObserversFilterAnimated(const FilterOperations& filter);
159 void NotifyObserversScrollOffsetAnimated(const gfx::Vector2dF& scroll_offset);
161 void NotifyObserversAnimationWaitingForDeletion();
163 bool HasValueObserver();
164 bool HasActiveValueObserver();
166 AnimationRegistrar* registrar_;
167 int id_;
168 ScopedPtrVector<Animation> active_animations_;
170 // This is used to ensure that we don't spam the registrar.
171 bool is_active_;
173 double last_tick_time_;
175 ObserverList<LayerAnimationValueObserver> value_observers_;
176 ObserverList<LayerAnimationEventObserver> event_observers_;
178 LayerAnimationValueProvider* value_provider_;
180 AnimationDelegate* layer_animation_delegate_;
182 DISALLOW_COPY_AND_ASSIGN(LayerAnimationController);
185 } // namespace cc
187 #endif // CC_ANIMATION_LAYER_ANIMATION_CONTROLLER_H_