Use Default PasswordStore with Ozone.
[chromium-blink-merge.git] / cc / animation / layer_animation_controller.h
blob564a5933e7f70fb400c200f8aba812c42f5f3604
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 AnimatedBoundsForBox(const gfx::BoxF& box, gfx::BoxF* bounds);
114 protected:
115 friend class base::RefCounted<LayerAnimationController>;
117 explicit LayerAnimationController(int id);
118 virtual ~LayerAnimationController();
120 private:
121 typedef base::hash_set<int> TargetProperties;
123 void PushNewAnimationsToImplThread(
124 LayerAnimationController* controller_impl) const;
125 void RemoveAnimationsCompletedOnMainThread(
126 LayerAnimationController* controller_impl) const;
127 void PushPropertiesToImplThread(
128 LayerAnimationController* controller_impl) const;
130 void StartAnimations(double monotonic_time);
131 void PromoteStartedAnimations(double monotonic_time,
132 AnimationEventsVector* events);
133 void MarkFinishedAnimations(double monotonic_time);
134 void MarkAnimationsForDeletion(double monotonic_time,
135 AnimationEventsVector* events);
136 void PurgeAnimationsMarkedForDeletion();
138 void TickAnimations(double monotonic_time);
140 enum UpdateActivationType {
141 NormalActivation,
142 ForceActivation
144 void UpdateActivation(UpdateActivationType type);
146 void NotifyObserversOpacityAnimated(float opacity);
147 void NotifyObserversTransformAnimated(const gfx::Transform& transform);
148 void NotifyObserversFilterAnimated(const FilterOperations& filter);
149 void NotifyObserversScrollOffsetAnimated(gfx::Vector2dF scroll_offset);
151 void NotifyObserversAnimationWaitingForDeletion();
153 bool HasValueObserver();
154 bool HasActiveValueObserver();
156 AnimationRegistrar* registrar_;
157 int id_;
158 ScopedPtrVector<Animation> active_animations_;
160 // This is used to ensure that we don't spam the registrar.
161 bool is_active_;
163 double last_tick_time_;
165 ObserverList<LayerAnimationValueObserver> value_observers_;
166 ObserverList<LayerAnimationEventObserver> event_observers_;
168 LayerAnimationValueProvider* value_provider_;
170 AnimationDelegate* layer_animation_delegate_;
172 DISALLOW_COPY_AND_ASSIGN(LayerAnimationController);
175 } // namespace cc
177 #endif // CC_ANIMATION_LAYER_ANIMATION_CONTROLLER_H_