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 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/test/animation_test_common.h" | 7 #include "cc/test/animation_test_common.h" |
8 | 8 |
9 #include "cc/keyframed_animation_curve.h" | 9 #include "cc/keyframed_animation_curve.h" |
10 #include "cc/layer.h" | 10 #include "cc/layer.h" |
11 #include "cc/layer_animation_controller.h" | 11 #include "cc/layer_animation_controller.h" |
12 #include "cc/layer_impl.h" | 12 #include "cc/layer_impl.h" |
13 #include <public/WebTransformOperations.h> | 13 #include <public/WebTransformOperations.h> |
14 | 14 |
15 using namespace cc; | 15 using namespace cc; |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
| 19 static int nextAnimationId = 0; |
| 20 |
19 template <class Target> | 21 template <class Target> |
20 void addOpacityTransition(Target& target, double duration, float startOpacity, f
loat endOpacity, bool useTimingFunction) | 22 int addOpacityTransition(Target& target, double duration, float startOpacity, fl
oat endOpacity, bool useTimingFunction) |
21 { | 23 { |
22 scoped_ptr<KeyframedFloatAnimationCurve> curve(KeyframedFloatAnimationCurve:
:create()); | 24 scoped_ptr<KeyframedFloatAnimationCurve> curve(KeyframedFloatAnimationCurve:
:create()); |
23 | 25 |
24 scoped_ptr<TimingFunction> func; | 26 scoped_ptr<TimingFunction> func; |
25 if (!useTimingFunction) | 27 if (!useTimingFunction) |
26 func = EaseTimingFunction::create(); | 28 func = EaseTimingFunction::create(); |
27 if (duration > 0) | 29 if (duration > 0) |
28 curve->addKeyframe(FloatKeyframe::create(0, startOpacity, func.Pass())); | 30 curve->addKeyframe(FloatKeyframe::create(0, startOpacity, func.Pass())); |
29 curve->addKeyframe(FloatKeyframe::create(duration, endOpacity, scoped_ptr<cc
::TimingFunction>())); | 31 curve->addKeyframe(FloatKeyframe::create(duration, endOpacity, scoped_ptr<cc
::TimingFunction>())); |
30 | 32 |
31 scoped_ptr<ActiveAnimation> animation(ActiveAnimation::create(curve.PassAs<A
nimationCurve>(), 0, 0, ActiveAnimation::Opacity)); | 33 int id = nextAnimationId++; |
| 34 |
| 35 scoped_ptr<ActiveAnimation> animation(ActiveAnimation::create(curve.PassAs<A
nimationCurve>(), id, 0, ActiveAnimation::Opacity)); |
32 animation->setNeedsSynchronizedStartTime(true); | 36 animation->setNeedsSynchronizedStartTime(true); |
33 | 37 |
34 target.addAnimation(animation.Pass()); | 38 target.addAnimation(animation.Pass()); |
| 39 return id; |
35 } | 40 } |
36 | 41 |
37 template <class Target> | 42 template <class Target> |
38 void addAnimatedTransform(Target& target, double duration, int deltaX, int delta
Y) | 43 int addAnimatedTransform(Target& target, double duration, int deltaX, int deltaY
) |
39 { | 44 { |
40 static int id = 0; | |
41 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati
onCurve::create()); | 45 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati
onCurve::create()); |
42 | 46 |
43 if (duration > 0) { | 47 if (duration > 0) { |
44 WebKit::WebTransformOperations startOperations; | 48 WebKit::WebTransformOperations startOperations; |
45 startOperations.appendTranslate(deltaX, deltaY, 0); | 49 startOperations.appendTranslate(deltaX, deltaY, 0); |
46 curve->addKeyframe(TransformKeyframe::create(0, startOperations, scoped_
ptr<cc::TimingFunction>())); | 50 curve->addKeyframe(TransformKeyframe::create(0, startOperations, scoped_
ptr<cc::TimingFunction>())); |
47 } | 51 } |
48 | 52 |
49 WebKit::WebTransformOperations operations; | 53 WebKit::WebTransformOperations operations; |
50 operations.appendTranslate(deltaX, deltaY, 0); | 54 operations.appendTranslate(deltaX, deltaY, 0); |
51 curve->addKeyframe(TransformKeyframe::create(duration, operations, scoped_pt
r<cc::TimingFunction>())); | 55 curve->addKeyframe(TransformKeyframe::create(duration, operations, scoped_pt
r<cc::TimingFunction>())); |
52 | 56 |
53 scoped_ptr<ActiveAnimation> animation(ActiveAnimation::create(curve.PassAs<A
nimationCurve>(), id++, 0, ActiveAnimation::Transform)); | 57 int id = nextAnimationId++; |
| 58 |
| 59 scoped_ptr<ActiveAnimation> animation(ActiveAnimation::create(curve.PassAs<A
nimationCurve>(), id, 0, ActiveAnimation::Transform)); |
54 animation->setNeedsSynchronizedStartTime(true); | 60 animation->setNeedsSynchronizedStartTime(true); |
55 | 61 |
56 target.addAnimation(animation.Pass()); | 62 target.addAnimation(animation.Pass()); |
| 63 return id; |
57 } | 64 } |
58 | 65 |
59 } // namespace | 66 } // namespace |
60 | 67 |
61 namespace WebKitTests { | 68 namespace WebKitTests { |
62 | 69 |
63 FakeFloatAnimationCurve::FakeFloatAnimationCurve() | 70 FakeFloatAnimationCurve::FakeFloatAnimationCurve() |
64 : m_duration(1) | 71 : m_duration(1) |
65 { | 72 { |
66 } | 73 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 const WebKit::WebTransformationMatrix& FakeLayerAnimationControllerClient::trans
form() const | 177 const WebKit::WebTransformationMatrix& FakeLayerAnimationControllerClient::trans
form() const |
171 { | 178 { |
172 return m_transform; | 179 return m_transform; |
173 } | 180 } |
174 | 181 |
175 scoped_ptr<cc::AnimationCurve> FakeFloatTransition::clone() const | 182 scoped_ptr<cc::AnimationCurve> FakeFloatTransition::clone() const |
176 { | 183 { |
177 return make_scoped_ptr(new FakeFloatTransition(*this)).PassAs<cc::AnimationC
urve>(); | 184 return make_scoped_ptr(new FakeFloatTransition(*this)).PassAs<cc::AnimationC
urve>(); |
178 } | 185 } |
179 | 186 |
180 void addOpacityTransitionToController(cc::LayerAnimationController& controller,
double duration, float startOpacity, float endOpacity, bool useTimingFunction) | 187 int addOpacityTransitionToController(cc::LayerAnimationController& controller, d
ouble duration, float startOpacity, float endOpacity, bool useTimingFunction) |
181 { | 188 { |
182 addOpacityTransition(controller, duration, startOpacity, endOpacity, useTimi
ngFunction); | 189 return addOpacityTransition(controller, duration, startOpacity, endOpacity,
useTimingFunction); |
183 } | 190 } |
184 | 191 |
185 void addAnimatedTransformToController(cc::LayerAnimationController& controller,
double duration, int deltaX, int deltaY) | 192 int addAnimatedTransformToController(cc::LayerAnimationController& controller, d
ouble duration, int deltaX, int deltaY) |
186 { | 193 { |
187 addAnimatedTransform(controller, duration, deltaX, deltaY); | 194 return addAnimatedTransform(controller, duration, deltaX, deltaY); |
188 } | 195 } |
189 | 196 |
190 void addOpacityTransitionToLayer(cc::Layer& layer, double duration, float startO
pacity, float endOpacity, bool useTimingFunction) | 197 int addOpacityTransitionToLayer(cc::Layer& layer, double duration, float startOp
acity, float endOpacity, bool useTimingFunction) |
191 { | 198 { |
192 addOpacityTransition(layer, duration, startOpacity, endOpacity, useTimingFun
ction); | 199 return addOpacityTransition(layer, duration, startOpacity, endOpacity, useTi
mingFunction); |
193 } | 200 } |
194 | 201 |
195 void addOpacityTransitionToLayer(cc::LayerImpl& layer, double duration, float st
artOpacity, float endOpacity, bool useTimingFunction) | 202 int addOpacityTransitionToLayer(cc::LayerImpl& layer, double duration, float sta
rtOpacity, float endOpacity, bool useTimingFunction) |
196 { | 203 { |
197 addOpacityTransition(*layer.layerAnimationController(), duration, startOpaci
ty, endOpacity, useTimingFunction); | 204 return addOpacityTransition(*layer.layerAnimationController(), duration, sta
rtOpacity, endOpacity, useTimingFunction); |
198 } | 205 } |
199 | 206 |
200 void addAnimatedTransformToLayer(cc::Layer& layer, double duration, int deltaX,
int deltaY) | 207 int addAnimatedTransformToLayer(cc::Layer& layer, double duration, int deltaX, i
nt deltaY) |
201 { | 208 { |
202 addAnimatedTransform(layer, duration, deltaX, deltaY); | 209 return addAnimatedTransform(layer, duration, deltaX, deltaY); |
203 } | 210 } |
204 | 211 |
205 void addAnimatedTransformToLayer(cc::LayerImpl& layer, double duration, int delt
aX, int deltaY) | 212 int addAnimatedTransformToLayer(cc::LayerImpl& layer, double duration, int delta
X, int deltaY) |
206 { | 213 { |
207 addAnimatedTransform(*layer.layerAnimationController(), duration, deltaX, de
ltaY); | 214 return addAnimatedTransform(*layer.layerAnimationController(), duration, del
taX, deltaY); |
208 } | 215 } |
209 | 216 |
210 } // namespace WebKitTests | 217 } // namespace WebKitTests |
OLD | NEW |