DPCHECK known conditions when we guess false in CurrentProcessHasOpenDirectories
[chromium-blink-merge.git] / cc / test / animation_test_common.cc
blob7ab26a5d8b548500392d6acf9b21ae4b0c8e0bf6
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.
5 #include "cc/test/animation_test_common.h"
7 #include "cc/animation/animation_id_provider.h"
8 #include "cc/animation/keyframed_animation_curve.h"
9 #include "cc/animation/layer_animation_controller.h"
10 #include "cc/animation/transform_operations.h"
11 #include "cc/layers/layer.h"
12 #include "cc/layers/layer_impl.h"
14 using cc::Animation;
15 using cc::AnimationCurve;
16 using cc::EaseTimingFunction;
17 using cc::FloatKeyframe;
18 using cc::KeyframedFloatAnimationCurve;
19 using cc::KeyframedTransformAnimationCurve;
20 using cc::TimingFunction;
21 using cc::TransformKeyframe;
23 namespace cc {
25 template <class Target>
26 int AddOpacityTransition(Target* target,
27 double duration,
28 float start_opacity,
29 float end_opacity,
30 bool use_timing_function) {
31 scoped_ptr<KeyframedFloatAnimationCurve>
32 curve(KeyframedFloatAnimationCurve::Create());
34 scoped_ptr<TimingFunction> func;
35 if (!use_timing_function)
36 func = EaseTimingFunction::Create();
37 if (duration > 0.0)
38 curve->AddKeyframe(FloatKeyframe::Create(0.0, start_opacity, func.Pass()));
39 curve->AddKeyframe(FloatKeyframe::Create(duration,
40 end_opacity,
41 scoped_ptr<cc::TimingFunction>()));
43 int id = AnimationIdProvider::NextAnimationId();
45 scoped_ptr<Animation> animation(Animation::Create(
46 curve.PassAs<AnimationCurve>(),
47 id,
48 AnimationIdProvider::NextGroupId(),
49 Animation::Opacity));
50 animation->set_needs_synchronized_start_time(true);
52 target->AddAnimation(animation.Pass());
53 return id;
56 template <class Target>
57 int AddAnimatedTransform(Target* target,
58 double duration,
59 int delta_x,
60 int delta_y) {
61 scoped_ptr<KeyframedTransformAnimationCurve>
62 curve(KeyframedTransformAnimationCurve::Create());
64 if (duration > 0.0) {
65 TransformOperations start_operations;
66 start_operations.AppendTranslate(delta_x, delta_y, 0.0);
67 curve->AddKeyframe(TransformKeyframe::Create(
68 0.0,
69 start_operations,
70 scoped_ptr<cc::TimingFunction>()));
73 TransformOperations operations;
74 operations.AppendTranslate(delta_x, delta_y, 0.0);
75 curve->AddKeyframe(TransformKeyframe::Create(
76 duration,
77 operations,
78 scoped_ptr<cc::TimingFunction>()));
80 int id = AnimationIdProvider::NextAnimationId();
82 scoped_ptr<Animation> animation(Animation::Create(
83 curve.PassAs<AnimationCurve>(),
84 id,
85 AnimationIdProvider::NextGroupId(),
86 Animation::Transform));
87 animation->set_needs_synchronized_start_time(true);
89 target->AddAnimation(animation.Pass());
90 return id;
93 template <class Target>
94 int AddAnimatedFilter(Target* target,
95 double duration,
96 float start_brightness,
97 float end_brightness) {
98 scoped_ptr<KeyframedFilterAnimationCurve>
99 curve(KeyframedFilterAnimationCurve::Create());
101 if (duration > 0.0) {
102 FilterOperations start_filters;
103 start_filters.Append(
104 FilterOperation::CreateBrightnessFilter(start_brightness));
105 curve->AddKeyframe(FilterKeyframe::Create(
106 0.0, start_filters, scoped_ptr<cc::TimingFunction>()));
109 FilterOperations filters;
110 filters.Append(FilterOperation::CreateBrightnessFilter(end_brightness));
111 curve->AddKeyframe(FilterKeyframe::Create(
112 duration, filters, scoped_ptr<cc::TimingFunction>()));
114 int id = AnimationIdProvider::NextAnimationId();
116 scoped_ptr<Animation> animation(Animation::Create(
117 curve.PassAs<AnimationCurve>(),
119 AnimationIdProvider::NextGroupId(),
120 Animation::Filter));
121 animation->set_needs_synchronized_start_time(true);
123 target->AddAnimation(animation.Pass());
124 return id;
127 FakeFloatAnimationCurve::FakeFloatAnimationCurve()
128 : duration_(1.0) {}
130 FakeFloatAnimationCurve::FakeFloatAnimationCurve(double duration)
131 : duration_(duration) {}
133 FakeFloatAnimationCurve::~FakeFloatAnimationCurve() {}
135 double FakeFloatAnimationCurve::Duration() const {
136 return duration_;
139 float FakeFloatAnimationCurve::GetValue(double now) const {
140 return 0.0f;
143 scoped_ptr<cc::AnimationCurve> FakeFloatAnimationCurve::Clone() const {
144 return make_scoped_ptr(
145 new FakeFloatAnimationCurve).PassAs<cc::AnimationCurve>();
148 FakeTransformTransition::FakeTransformTransition(double duration)
149 : duration_(duration) {}
151 FakeTransformTransition::~FakeTransformTransition() {}
153 double FakeTransformTransition::Duration() const {
154 return duration_;
157 gfx::Transform FakeTransformTransition::GetValue(double time) const {
158 return gfx::Transform();
161 bool FakeTransformTransition::AnimatedBoundsForBox(const gfx::BoxF& box,
162 gfx::BoxF* bounds) const {
163 return false;
166 scoped_ptr<cc::AnimationCurve> FakeTransformTransition::Clone() const {
167 return make_scoped_ptr(
168 new FakeTransformTransition(*this)).PassAs<cc::AnimationCurve>();
172 FakeFloatTransition::FakeFloatTransition(double duration, float from, float to)
173 : duration_(duration), from_(from), to_(to) {}
175 FakeFloatTransition::~FakeFloatTransition() {}
177 double FakeFloatTransition::Duration() const {
178 return duration_;
181 float FakeFloatTransition::GetValue(double time) const {
182 time /= duration_;
183 if (time >= 1.0)
184 time = 1.0;
185 return (1.0 - time) * from_ + time * to_;
188 FakeLayerAnimationValueObserver::FakeLayerAnimationValueObserver()
189 : opacity_(0.0f),
190 animation_waiting_for_deletion_(false) {}
192 FakeLayerAnimationValueObserver::~FakeLayerAnimationValueObserver() {}
194 void FakeLayerAnimationValueObserver::OnFilterAnimated(
195 const FilterOperations& filters) {
196 filters_ = filters;
199 void FakeLayerAnimationValueObserver::OnOpacityAnimated(float opacity) {
200 opacity_ = opacity;
203 void FakeLayerAnimationValueObserver::OnTransformAnimated(
204 const gfx::Transform& transform) {
205 transform_ = transform;
208 void FakeLayerAnimationValueObserver::OnAnimationWaitingForDeletion() {
209 animation_waiting_for_deletion_ = true;
212 bool FakeLayerAnimationValueObserver::IsActive() const {
213 return true;
216 bool FakeInactiveLayerAnimationValueObserver::IsActive() const {
217 return false;
220 scoped_ptr<cc::AnimationCurve> FakeFloatTransition::Clone() const {
221 return make_scoped_ptr(
222 new FakeFloatTransition(*this)).PassAs<cc::AnimationCurve>();
225 int AddOpacityTransitionToController(cc::LayerAnimationController* controller,
226 double duration,
227 float start_opacity,
228 float end_opacity,
229 bool use_timing_function) {
230 return AddOpacityTransition(controller,
231 duration,
232 start_opacity,
233 end_opacity,
234 use_timing_function);
237 int AddAnimatedTransformToController(cc::LayerAnimationController* controller,
238 double duration,
239 int delta_x,
240 int delta_y) {
241 return AddAnimatedTransform(controller,
242 duration,
243 delta_x,
244 delta_y);
247 int AddAnimatedFilterToController(cc::LayerAnimationController* controller,
248 double duration,
249 float start_brightness,
250 float end_brightness) {
251 return AddAnimatedFilter(
252 controller, duration, start_brightness, end_brightness);
255 int AddOpacityTransitionToLayer(cc::Layer* layer,
256 double duration,
257 float start_opacity,
258 float end_opacity,
259 bool use_timing_function) {
260 return AddOpacityTransition(layer,
261 duration,
262 start_opacity,
263 end_opacity,
264 use_timing_function);
267 int AddOpacityTransitionToLayer(cc::LayerImpl* layer,
268 double duration,
269 float start_opacity,
270 float end_opacity,
271 bool use_timing_function) {
272 return AddOpacityTransition(layer->layer_animation_controller(),
273 duration,
274 start_opacity,
275 end_opacity,
276 use_timing_function);
279 int AddAnimatedTransformToLayer(cc::Layer* layer,
280 double duration,
281 int delta_x,
282 int delta_y) {
283 return AddAnimatedTransform(layer, duration, delta_x, delta_y);
286 int AddAnimatedTransformToLayer(cc::LayerImpl* layer,
287 double duration,
288 int delta_x,
289 int delta_y) {
290 return AddAnimatedTransform(layer->layer_animation_controller(),
291 duration,
292 delta_x,
293 delta_y);
296 int AddAnimatedFilterToLayer(cc::Layer* layer,
297 double duration,
298 float start_brightness,
299 float end_brightness) {
300 return AddAnimatedFilter(layer, duration, start_brightness, end_brightness);
303 int AddAnimatedFilterToLayer(cc::LayerImpl* layer,
304 double duration,
305 float start_brightness,
306 float end_brightness) {
307 return AddAnimatedFilter(layer->layer_animation_controller(),
308 duration,
309 start_brightness,
310 end_brightness);
313 } // namespace cc