| OLD | NEW |
| (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 #include "config.h" | |
| 6 | |
| 7 #include "CCAnimationTestCommon.h" | |
| 8 | |
| 9 #include "CCKeyframedAnimationCurve.h" | |
| 10 #include "CCLayerAnimationController.h" | |
| 11 #include "CCLayerImpl.h" | |
| 12 #include "LayerChromium.h" | |
| 13 #include <public/WebTransformOperations.h> | |
| 14 | |
| 15 using namespace cc; | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 template <class Target> | |
| 20 void addOpacityTransition(Target& target, double duration, float startOpacity, f
loat endOpacity, bool useTimingFunction) | |
| 21 { | |
| 22 scoped_ptr<CCKeyframedFloatAnimationCurve> curve(CCKeyframedFloatAnimationCu
rve::create()); | |
| 23 | |
| 24 scoped_ptr<CCTimingFunction> func; | |
| 25 if (!useTimingFunction) | |
| 26 func = CCEaseTimingFunction::create(); | |
| 27 if (duration > 0) | |
| 28 curve->addKeyframe(CCFloatKeyframe::create(0, startOpacity, func.Pass())
); | |
| 29 curve->addKeyframe(CCFloatKeyframe::create(duration, endOpacity, scoped_ptr<
cc::CCTimingFunction>())); | |
| 30 | |
| 31 scoped_ptr<CCActiveAnimation> animation(CCActiveAnimation::create(curve.Pass
As<CCAnimationCurve>(), 0, 0, CCActiveAnimation::Opacity)); | |
| 32 animation->setNeedsSynchronizedStartTime(true); | |
| 33 | |
| 34 target.addAnimation(animation.Pass()); | |
| 35 } | |
| 36 | |
| 37 template <class Target> | |
| 38 void addAnimatedTransform(Target& target, double duration, int deltaX, int delta
Y) | |
| 39 { | |
| 40 static int id = 0; | |
| 41 scoped_ptr<CCKeyframedTransformAnimationCurve> curve(CCKeyframedTransformAni
mationCurve::create()); | |
| 42 | |
| 43 if (duration > 0) { | |
| 44 WebKit::WebTransformOperations startOperations; | |
| 45 startOperations.appendTranslate(deltaX, deltaY, 0); | |
| 46 curve->addKeyframe(CCTransformKeyframe::create(0, startOperations, scope
d_ptr<cc::CCTimingFunction>())); | |
| 47 } | |
| 48 | |
| 49 WebKit::WebTransformOperations operations; | |
| 50 operations.appendTranslate(deltaX, deltaY, 0); | |
| 51 curve->addKeyframe(CCTransformKeyframe::create(duration, operations, scoped_
ptr<cc::CCTimingFunction>())); | |
| 52 | |
| 53 scoped_ptr<CCActiveAnimation> animation(CCActiveAnimation::create(curve.Pass
As<CCAnimationCurve>(), id++, 0, CCActiveAnimation::Transform)); | |
| 54 animation->setNeedsSynchronizedStartTime(true); | |
| 55 | |
| 56 target.addAnimation(animation.Pass()); | |
| 57 } | |
| 58 | |
| 59 } // namespace | |
| 60 | |
| 61 namespace WebKitTests { | |
| 62 | |
| 63 FakeFloatAnimationCurve::FakeFloatAnimationCurve() | |
| 64 : m_duration(1) | |
| 65 { | |
| 66 } | |
| 67 | |
| 68 FakeFloatAnimationCurve::FakeFloatAnimationCurve(double duration) | |
| 69 : m_duration(duration) | |
| 70 { | |
| 71 } | |
| 72 | |
| 73 FakeFloatAnimationCurve::~FakeFloatAnimationCurve() | |
| 74 { | |
| 75 } | |
| 76 | |
| 77 double FakeFloatAnimationCurve::duration() const | |
| 78 { | |
| 79 return m_duration; | |
| 80 } | |
| 81 | |
| 82 float FakeFloatAnimationCurve::getValue(double now) const | |
| 83 { | |
| 84 return 0; | |
| 85 } | |
| 86 | |
| 87 scoped_ptr<cc::CCAnimationCurve> FakeFloatAnimationCurve::clone() const | |
| 88 { | |
| 89 return make_scoped_ptr(new FakeFloatAnimationCurve).PassAs<cc::CCAnimationCu
rve>(); | |
| 90 } | |
| 91 | |
| 92 FakeTransformTransition::FakeTransformTransition(double duration) | |
| 93 : m_duration(duration) | |
| 94 { | |
| 95 } | |
| 96 | |
| 97 FakeTransformTransition::~FakeTransformTransition() | |
| 98 { | |
| 99 } | |
| 100 | |
| 101 double FakeTransformTransition::duration() const | |
| 102 { | |
| 103 return m_duration; | |
| 104 } | |
| 105 | |
| 106 WebKit::WebTransformationMatrix FakeTransformTransition::getValue(double time) c
onst | |
| 107 { | |
| 108 return WebKit::WebTransformationMatrix(); | |
| 109 } | |
| 110 | |
| 111 scoped_ptr<cc::CCAnimationCurve> FakeTransformTransition::clone() const | |
| 112 { | |
| 113 return make_scoped_ptr(new FakeTransformTransition(*this)).PassAs<cc::CCAnim
ationCurve>(); | |
| 114 } | |
| 115 | |
| 116 | |
| 117 FakeFloatTransition::FakeFloatTransition(double duration, float from, float to) | |
| 118 : m_duration(duration) | |
| 119 , m_from(from) | |
| 120 , m_to(to) | |
| 121 { | |
| 122 } | |
| 123 | |
| 124 FakeFloatTransition::~FakeFloatTransition() | |
| 125 { | |
| 126 } | |
| 127 | |
| 128 double FakeFloatTransition::duration() const | |
| 129 { | |
| 130 return m_duration; | |
| 131 } | |
| 132 | |
| 133 float FakeFloatTransition::getValue(double time) const | |
| 134 { | |
| 135 time /= m_duration; | |
| 136 if (time >= 1) | |
| 137 time = 1; | |
| 138 return (1 - time) * m_from + time * m_to; | |
| 139 } | |
| 140 | |
| 141 FakeLayerAnimationControllerClient::FakeLayerAnimationControllerClient() | |
| 142 : m_opacity(0) | |
| 143 { | |
| 144 } | |
| 145 | |
| 146 FakeLayerAnimationControllerClient::~FakeLayerAnimationControllerClient() | |
| 147 { | |
| 148 } | |
| 149 | |
| 150 int FakeLayerAnimationControllerClient::id() const | |
| 151 { | |
| 152 return 0; | |
| 153 } | |
| 154 | |
| 155 void FakeLayerAnimationControllerClient::setOpacityFromAnimation(float opacity) | |
| 156 { | |
| 157 m_opacity = opacity; | |
| 158 } | |
| 159 | |
| 160 float FakeLayerAnimationControllerClient::opacity() const | |
| 161 { | |
| 162 return m_opacity; | |
| 163 } | |
| 164 | |
| 165 void FakeLayerAnimationControllerClient::setTransformFromAnimation(const WebKit:
:WebTransformationMatrix& transform) | |
| 166 { | |
| 167 m_transform = transform; | |
| 168 } | |
| 169 | |
| 170 const WebKit::WebTransformationMatrix& FakeLayerAnimationControllerClient::trans
form() const | |
| 171 { | |
| 172 return m_transform; | |
| 173 } | |
| 174 | |
| 175 scoped_ptr<cc::CCAnimationCurve> FakeFloatTransition::clone() const | |
| 176 { | |
| 177 return make_scoped_ptr(new FakeFloatTransition(*this)).PassAs<cc::CCAnimatio
nCurve>(); | |
| 178 } | |
| 179 | |
| 180 void addOpacityTransitionToController(cc::CCLayerAnimationController& controller
, double duration, float startOpacity, float endOpacity, bool useTimingFunction) | |
| 181 { | |
| 182 addOpacityTransition(controller, duration, startOpacity, endOpacity, useTimi
ngFunction); | |
| 183 } | |
| 184 | |
| 185 void addAnimatedTransformToController(cc::CCLayerAnimationController& controller
, double duration, int deltaX, int deltaY) | |
| 186 { | |
| 187 addAnimatedTransform(controller, duration, deltaX, deltaY); | |
| 188 } | |
| 189 | |
| 190 void addOpacityTransitionToLayer(cc::LayerChromium& layer, double duration, floa
t startOpacity, float endOpacity, bool useTimingFunction) | |
| 191 { | |
| 192 addOpacityTransition(layer, duration, startOpacity, endOpacity, useTimingFun
ction); | |
| 193 } | |
| 194 | |
| 195 void addOpacityTransitionToLayer(cc::CCLayerImpl& layer, double duration, float
startOpacity, float endOpacity, bool useTimingFunction) | |
| 196 { | |
| 197 addOpacityTransition(*layer.layerAnimationController(), duration, startOpaci
ty, endOpacity, useTimingFunction); | |
| 198 } | |
| 199 | |
| 200 void addAnimatedTransformToLayer(cc::LayerChromium& layer, double duration, int
deltaX, int deltaY) | |
| 201 { | |
| 202 addAnimatedTransform(layer, duration, deltaX, deltaY); | |
| 203 } | |
| 204 | |
| 205 void addAnimatedTransformToLayer(cc::CCLayerImpl& layer, double duration, int de
ltaX, int deltaY) | |
| 206 { | |
| 207 addAnimatedTransform(*layer.layerAnimationController(), duration, deltaX, de
ltaY); | |
| 208 } | |
| 209 | |
| 210 } // namespace WebKitTests | |
| OLD | NEW |