Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: cc/layer_animation_controller.h

Issue 12822004: Part 3 of cc/ directory shuffles: animation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layer.cc ('k') | cc/layer_animation_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef CC_LAYER_ANIMATION_CONTROLLER_H_
6 #define CC_LAYER_ANIMATION_CONTROLLER_H_
7
8 #include "base/basictypes.h"
9 #include "base/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.h"
14 #include "cc/animation_events.h"
15 #include "cc/base/cc_export.h"
16 #include "cc/base/scoped_ptr_vector.h"
17 #include "cc/layer_animation_event_observer.h"
18 #include "ui/gfx/transform.h"
19
20 namespace gfx { class Transform; }
21
22 namespace cc {
23
24 class Animation;
25 class AnimationRegistrar;
26 class KeyframeValueList;
27 class LayerAnimationValueObserver;
28
29 class CC_EXPORT LayerAnimationController
30 : public base::RefCounted<LayerAnimationController>,
31 public LayerAnimationEventObserver {
32 public:
33 static scoped_refptr<LayerAnimationController> Create(int id);
34
35 int id() const { return id_; }
36
37 // These methods are virtual for testing.
38 virtual void AddAnimation(scoped_ptr<Animation> animation);
39 virtual void PauseAnimation(int animation_id, double time_offset);
40 virtual void RemoveAnimation(int animation_id);
41 virtual void RemoveAnimation(int animation_id,
42 Animation::TargetProperty target_property);
43 virtual void SuspendAnimations(double monotonic_time);
44 virtual void ResumeAnimations(double monotonic_time);
45
46 // 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
48 // thread controller.
49 virtual void PushAnimationUpdatesTo(
50 LayerAnimationController* controller_impl);
51
52 void Animate(double monotonic_time);
53 void AccumulatePropertyUpdates(double monotonic_time,
54 AnimationEventsVector* events);
55 void UpdateState(AnimationEventsVector* events);
56
57 // Returns the active animation in the given group, animating the given
58 // property, if such an animation exists.
59 Animation* GetAnimation(int group_id,
60 Animation::TargetProperty target_property) const;
61
62 // Returns the active animation animating the given property that is either
63 // running, or is next to run, if such an animation exists.
64 Animation* GetAnimation(Animation::TargetProperty target_property) const;
65
66 // Returns true if there are any animations that have neither finished nor
67 // aborted.
68 bool HasActiveAnimation() const;
69
70 // Returns true if there are any animations at all to process.
71 bool has_any_animation() const { return !active_animations_.empty(); }
72
73 // 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
75 // the future.
76 bool IsAnimatingProperty(Animation::TargetProperty target_property) const;
77
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
84 // impl thread, all animations will be transferred.
85 void set_force_sync() { force_sync_ = true; }
86
87 void SetAnimationRegistrar(AnimationRegistrar* registrar);
88 AnimationRegistrar* animation_registrar() { return registrar_; }
89
90 void AddObserver(LayerAnimationValueObserver* observer);
91 void RemoveObserver(LayerAnimationValueObserver* observer);
92
93 protected:
94 friend class base::RefCounted<LayerAnimationController>;
95
96 LayerAnimationController(int id);
97 virtual ~LayerAnimationController();
98
99 private:
100 typedef base::hash_set<int> TargetProperties;
101
102 void PushNewAnimationsToImplThread(
103 LayerAnimationController* controller_impl) const;
104 void RemoveAnimationsCompletedOnMainThread(
105 LayerAnimationController* controller_impl) const;
106 void PushPropertiesToImplThread(
107 LayerAnimationController* controller_impl) const;
108 void ReplaceImplThreadAnimations(
109 LayerAnimationController* controller_impl) const;
110
111 void StartAnimationsWaitingForNextTick(double monotonic_time);
112 void StartAnimationsWaitingForStartTime(double monotonic_time);
113 void StartAnimationsWaitingForTargetAvailability(double monotonic_time);
114 void ResolveConflicts(double monotonic_time);
115 void PromoteStartedAnimations(double monotonic_time,
116 AnimationEventsVector* events);
117 void MarkFinishedAnimations(double monotonic_time);
118 void MarkAnimationsForDeletion(double monotonic_time,
119 AnimationEventsVector* events);
120 void PurgeAnimationsMarkedForDeletion();
121
122 void TickAnimations(double monotonic_time);
123
124 enum UpdateActivationType {
125 NormalActivation,
126 ForceActivation
127 };
128 void UpdateActivation(UpdateActivationType type);
129
130 void NotifyObserversOpacityAnimated(float opacity);
131 void NotifyObserversTransformAnimated(const gfx::Transform& transform);
132
133 bool HasActiveObserver();
134
135 // If this is true, we force a sync to the impl thread.
136 bool force_sync_;
137
138 AnimationRegistrar* registrar_;
139 int id_;
140 ScopedPtrVector<Animation> active_animations_;
141
142 // This is used to ensure that we don't spam the registrar.
143 bool is_active_;
144
145 double last_tick_time_;
146
147 ObserverList<LayerAnimationValueObserver> observers_;
148
149 DISALLOW_COPY_AND_ASSIGN(LayerAnimationController);
150 };
151
152 } // namespace cc
153
154 #endif // CC_LAYER_ANIMATION_CONTROLLER_H_
OLDNEW
« no previous file with comments | « cc/layer.cc ('k') | cc/layer_animation_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698