1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/test/animation_test_common.h"
#include "cc/keyframed_animation_curve.h"
#include "cc/layer.h"
#include "cc/layer_animation_controller.h"
#include "cc/layer_impl.h"
#include <public/WebTransformOperations.h>
using cc::ActiveAnimation;
using cc::AnimationCurve;
using cc::EaseTimingFunction;
using cc::FloatKeyframe;
using cc::KeyframedFloatAnimationCurve;
using cc::KeyframedTransformAnimationCurve;
using cc::TimingFunction;
using cc::TransformKeyframe;
namespace {
static int nextAnimationId = 0;
template <class Target>
int addOpacityTransition(Target& target, double duration, float startOpacity, float endOpacity, bool useTimingFunction)
{
scoped_ptr<KeyframedFloatAnimationCurve> curve(KeyframedFloatAnimationCurve::create());
scoped_ptr<TimingFunction> func;
if (!useTimingFunction)
func = EaseTimingFunction::create();
if (duration > 0)
curve->addKeyframe(FloatKeyframe::create(0, startOpacity, func.Pass()));
curve->addKeyframe(FloatKeyframe::create(duration, endOpacity, scoped_ptr<cc::TimingFunction>()));
int id = nextAnimationId++;
scoped_ptr<ActiveAnimation> animation(ActiveAnimation::create(curve.PassAs<AnimationCurve>(), id, 0, ActiveAnimation::Opacity));
animation->setNeedsSynchronizedStartTime(true);
target.addAnimation(animation.Pass());
return id;
}
template <class Target>
int addAnimatedTransform(Target& target, double duration, int deltaX, int deltaY)
{
scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimationCurve::create());
if (duration > 0) {
WebKit::WebTransformOperations startOperations;
startOperations.appendTranslate(deltaX, deltaY, 0);
curve->addKeyframe(TransformKeyframe::create(0, startOperations, scoped_ptr<cc::TimingFunction>()));
}
WebKit::WebTransformOperations operations;
operations.appendTranslate(deltaX, deltaY, 0);
curve->addKeyframe(TransformKeyframe::create(duration, operations, scoped_ptr<cc::TimingFunction>()));
int id = nextAnimationId++;
scoped_ptr<ActiveAnimation> animation(ActiveAnimation::create(curve.PassAs<AnimationCurve>(), id, 0, ActiveAnimation::Transform));
animation->setNeedsSynchronizedStartTime(true);
target.addAnimation(animation.Pass());
return id;
}
} // namespace
namespace cc {
FakeFloatAnimationCurve::FakeFloatAnimationCurve()
: m_duration(1)
{
}
FakeFloatAnimationCurve::FakeFloatAnimationCurve(double duration)
: m_duration(duration)
{
}
FakeFloatAnimationCurve::~FakeFloatAnimationCurve()
{
}
double FakeFloatAnimationCurve::duration() const
{
return m_duration;
}
float FakeFloatAnimationCurve::getValue(double now) const
{
return 0;
}
scoped_ptr<cc::AnimationCurve> FakeFloatAnimationCurve::clone() const
{
return make_scoped_ptr(new FakeFloatAnimationCurve).PassAs<cc::AnimationCurve>();
}
FakeTransformTransition::FakeTransformTransition(double duration)
: m_duration(duration)
{
}
FakeTransformTransition::~FakeTransformTransition()
{
}
double FakeTransformTransition::duration() const
{
return m_duration;
}
WebKit::WebTransformationMatrix FakeTransformTransition::getValue(double time) const
{
return WebKit::WebTransformationMatrix();
}
scoped_ptr<cc::AnimationCurve> FakeTransformTransition::clone() const
{
return make_scoped_ptr(new FakeTransformTransition(*this)).PassAs<cc::AnimationCurve>();
}
FakeFloatTransition::FakeFloatTransition(double duration, float from, float to)
: m_duration(duration)
, m_from(from)
, m_to(to)
{
}
FakeFloatTransition::~FakeFloatTransition()
{
}
double FakeFloatTransition::duration() const
{
return m_duration;
}
float FakeFloatTransition::getValue(double time) const
{
time /= m_duration;
if (time >= 1)
time = 1;
return (1 - time) * m_from + time * m_to;
}
scoped_ptr<cc::AnimationCurve> FakeFloatTransition::clone() const
{
return make_scoped_ptr(new FakeFloatTransition(*this)).PassAs<cc::AnimationCurve>();
}
int addOpacityTransitionToController(cc::LayerAnimationController& controller, double duration, float startOpacity, float endOpacity, bool useTimingFunction)
{
return addOpacityTransition(controller, duration, startOpacity, endOpacity, useTimingFunction);
}
int addAnimatedTransformToController(cc::LayerAnimationController& controller, double duration, int deltaX, int deltaY)
{
return addAnimatedTransform(controller, duration, deltaX, deltaY);
}
int addOpacityTransitionToLayer(cc::Layer& layer, double duration, float startOpacity, float endOpacity, bool useTimingFunction)
{
return addOpacityTransition(layer, duration, startOpacity, endOpacity, useTimingFunction);
}
int addOpacityTransitionToLayer(cc::LayerImpl& layer, double duration, float startOpacity, float endOpacity, bool useTimingFunction)
{
return addOpacityTransition(*layer.layerAnimationController(), duration, startOpacity, endOpacity, useTimingFunction);
}
int addAnimatedTransformToLayer(cc::Layer& layer, double duration, int deltaX, int deltaY)
{
return addAnimatedTransform(layer, duration, deltaX, deltaY);
}
int addAnimatedTransformToLayer(cc::LayerImpl& layer, double duration, int deltaX, int deltaY)
{
return addAnimatedTransform(*layer.layerAnimationController(), duration, deltaX, deltaY);
}
} // namespace cc
|