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

Side by Side Diff: ui/gfx/compositor/layer_animation_preemption_strategy.cc

Issue 8247009: Explicit animation support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated views desktop demo. Created 9 years, 2 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
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 #include "ui/gfx/compositor/layer_animation_preemption_strategy.h"
6
7 #include "base/logging.h"
8 #include "base/memory/singleton.h"
9 #include "ui/gfx/compositor/layer_animation_sequence.h"
10
11 namespace ui {
12
13 namespace {
14
15 void RemoveAnimation(LayerAnimationSequence* sequence,
16 LayerAnimator::RunningAnimations* running,
17 LayerAnimator::AnimationQueue* queue) {
18 // First remove from running animations
19 LayerAnimator::RunningAnimations::iterator iter = running->begin();
20 while (iter != running->end()) {
21 if ((*iter).sequence == sequence) {
22 running->erase(iter);
23 break;
24 }
25 ++iter;
26 }
27
28 // Then remove from the queue
29 LayerAnimator::AnimationQueue::iterator queue_iter = queue->begin();
30 while (queue_iter != queue->end()) {
31 if ((*queue_iter).get() == sequence) {
32 queue->erase(queue_iter);
33 break;
34 }
35 ++queue_iter;
36 }
37 }
38
39 // Precondition: there is no running animation with a property in common with
40 // sequence.
41 void StartSequence(LayerAnimationSequence* sequence,
42 LayerAnimator::RunningAnimations* running,
43 LayerAnimator::AnimationQueue* queue) {
44 running->push_back(LayerAnimator::RunningAnimation(sequence,
45 base::TimeTicks::Now()));
46
47 // If we don't have the animation in the queue yet, add it.
48 bool found_sequence = false;
49 LayerAnimator::AnimationQueue::iterator queue_iter = queue->begin();
50 while (queue_iter != queue->end()) {
51 if ((*queue_iter).get() == sequence) {
52 found_sequence = true;
53 break;
54 }
55 ++queue_iter;
56 }
57
58 if (!found_sequence)
59 queue->push_front(make_scoped_refptr(sequence));
60 }
61
62 // ImmediatelySetNewTarget -----------------------------------------------------
63
64 class COMPOSITOR_EXPORT ImmediatelySetNewTarget
65 : public LayerAnimationPreemptionStrategy {
66 public:
67 static ImmediatelySetNewTarget* GetInstance();
68 virtual void Preempt(LayerAnimationDelegate* delegate,
69 LayerAnimationSequence* preempting,
70 LayerAnimator::RunningAnimations* running,
71 LayerAnimator::AnimationQueue* queue) {
72 // For all the running animations, if they animate the same property,
73 // progress them to the end and remove them.
74 LayerAnimator::RunningAnimations copy = *running;
75 LayerAnimator::RunningAnimations::const_iterator iter = copy.begin();
76 while (iter != copy.end()) {
77 if ((*iter).sequence->HasCommonProperty(*preempting)) {
78 // Abort the animation.
79 (*iter).sequence->Abort();
80 RemoveAnimation((*iter).sequence, running, queue);
81 }
82 ++iter;
83 }
84
85 // Skip to the end of the animation.
86 preempting->Progress(preempting->duration(), delegate);
87 RemoveAnimation(preempting, running, queue);
88 }
89 private:
90 ImmediatelySetNewTarget() {}
91 friend struct DefaultSingletonTraits<ImmediatelySetNewTarget>;
92 DISALLOW_COPY_AND_ASSIGN(ImmediatelySetNewTarget);
93 };
94
95 ImmediatelySetNewTarget* ImmediatelySetNewTarget::GetInstance() {
96 return Singleton<ImmediatelySetNewTarget>::get();
97 }
98
99 // ImmediatelyAnimateToNewTarget -----------------------------------------------
100
101 class COMPOSITOR_EXPORT ImmediatelyAnimateToNewTarget
102 : public LayerAnimationPreemptionStrategy {
103 public:
104 static ImmediatelyAnimateToNewTarget* GetInstance();
105 virtual void Preempt(LayerAnimationDelegate* delegate,
106 LayerAnimationSequence* preempting,
107 LayerAnimator::RunningAnimations* running,
108 LayerAnimator::AnimationQueue* queue) {
109 // For all the running animations, if they animate the same property,
110 // progress them to the end and remove them.
111 LayerAnimator::RunningAnimations copy = *running;
112 LayerAnimator::RunningAnimations::const_iterator iter = copy.begin();
113 while (iter != copy.end()) {
114 if ((*iter).sequence->HasCommonProperty(*preempting)) {
115 // Abort the animation.
116 (*iter).sequence->Abort();
117 RemoveAnimation((*iter).sequence, running, queue);
118 }
119 ++iter;
120 }
121 StartSequence(preempting, running, queue);
122 }
123 private:
124 ImmediatelyAnimateToNewTarget() {}
125 friend struct DefaultSingletonTraits<ImmediatelyAnimateToNewTarget>;
126 DISALLOW_COPY_AND_ASSIGN(ImmediatelyAnimateToNewTarget);
127 };
128
129 ImmediatelyAnimateToNewTarget* ImmediatelyAnimateToNewTarget::GetInstance() {
130 return Singleton<ImmediatelyAnimateToNewTarget>::get();
131 }
132
133 // EnqueueNewAnimation ---------------------------------------------------------
134
135 class COMPOSITOR_EXPORT EnqueueNewAnimation
136 : public LayerAnimationPreemptionStrategy {
137 public:
138 static EnqueueNewAnimation* GetInstance();
139 virtual void Preempt(LayerAnimationDelegate* delegate,
140 LayerAnimationSequence* preempting,
141 LayerAnimator::RunningAnimations* running,
142 LayerAnimator::AnimationQueue* queue) {
143 // It is assumed that if there was no conflicting animation, we would not
144 // have been called. No need to check for a collision, then. Just add to the
145 // queue.
146 queue->push_back(make_scoped_refptr(preempting));
147 }
148 private:
149 EnqueueNewAnimation() {}
150 friend struct DefaultSingletonTraits<EnqueueNewAnimation>;
151 DISALLOW_COPY_AND_ASSIGN(EnqueueNewAnimation);
152 };
153
154 EnqueueNewAnimation* EnqueueNewAnimation::GetInstance() {
155 return Singleton<EnqueueNewAnimation>::get();
156 }
157
158 // BlendCurrentWithNewAnimation ------------------------------------------------
159
160 class COMPOSITOR_EXPORT BlendCurrentWithNewAnimation
161 : public LayerAnimationPreemptionStrategy {
162 public:
163 static BlendCurrentWithNewAnimation* GetInstance();
164 virtual void Preempt(LayerAnimationDelegate* delegate,
165 LayerAnimationSequence* preempting,
166 LayerAnimator::RunningAnimations* running,
167 LayerAnimator::AnimationQueue* queue) {
168 // TODO(vollick) Add support for blended sequences, and use them here.
169 NOTIMPLEMENTED();
170 }
171 private:
172 BlendCurrentWithNewAnimation() {}
173 friend struct DefaultSingletonTraits<BlendCurrentWithNewAnimation>;
174 DISALLOW_COPY_AND_ASSIGN(BlendCurrentWithNewAnimation);
175 };
176
177 BlendCurrentWithNewAnimation* BlendCurrentWithNewAnimation::GetInstance() {
178 return Singleton<BlendCurrentWithNewAnimation>::get();
179 }
180
181 } // namespace
182
183 // LayerAnimationPreemptionStrategy --------------------------------------------
184
185 /* static */
186 LayerAnimationPreemptionStrategy*
187 LayerAnimationPreemptionStrategy::GetImmediatelySetNewTarget() {
188 return ImmediatelySetNewTarget::GetInstance();
189 }
190
191 /* static */
192 LayerAnimationPreemptionStrategy*
193 LayerAnimationPreemptionStrategy::GetImmediatelyAnimateToNewTarget() {
194 return ImmediatelyAnimateToNewTarget::GetInstance();
195 }
196
197 /* static */
198 LayerAnimationPreemptionStrategy*
199 LayerAnimationPreemptionStrategy::GetEnqueueNewAnimation() {
200 return EnqueueNewAnimation::GetInstance();
201 }
202
203 /* static */
204 LayerAnimationPreemptionStrategy*
205 LayerAnimationPreemptionStrategy::GetBlendCurrentWithNewAnimation() {
206 return BlendCurrentWithNewAnimation::GetInstance();
207 }
208
209 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698