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 "cc/test/animation_test_common.h" | 5 #include "cc/test/animation_test_common.h" |
6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
7 #include "cc/animation/animation_host.h" | 8 #include "cc/animation/animation_host.h" |
8 #include "cc/animation/animation_id_provider.h" | 9 #include "cc/animation/animation_id_provider.h" |
9 #include "cc/animation/animation_player.h" | 10 #include "cc/animation/animation_player.h" |
10 #include "cc/animation/keyframed_animation_curve.h" | 11 #include "cc/animation/keyframed_animation_curve.h" |
11 #include "cc/animation/layer_animation_controller.h" | 12 #include "cc/animation/layer_animation_controller.h" |
12 #include "cc/animation/transform_operations.h" | 13 #include "cc/animation/transform_operations.h" |
13 #include "cc/base/time_util.h" | 14 #include "cc/base/time_util.h" |
14 #include "cc/layers/layer.h" | 15 #include "cc/layers/layer.h" |
15 #include "cc/layers/layer_impl.h" | 16 #include "cc/layers/layer_impl.h" |
16 | 17 |
17 using cc::Animation; | 18 using cc::Animation; |
18 using cc::AnimationCurve; | 19 using cc::AnimationCurve; |
19 using cc::EaseTimingFunction; | 20 using cc::EaseTimingFunction; |
20 using cc::FloatKeyframe; | 21 using cc::FloatKeyframe; |
21 using cc::KeyframedFloatAnimationCurve; | 22 using cc::KeyframedFloatAnimationCurve; |
22 using cc::KeyframedTransformAnimationCurve; | 23 using cc::KeyframedTransformAnimationCurve; |
23 using cc::TimingFunction; | 24 using cc::TimingFunction; |
24 using cc::TransformKeyframe; | 25 using cc::TransformKeyframe; |
25 | 26 |
26 namespace cc { | 27 namespace cc { |
27 | 28 |
28 template <class Target> | 29 template <class Target> |
29 int AddOpacityTransition(Target* target, | 30 int AddOpacityTransition(Target* target, |
30 double duration, | 31 double duration, |
31 float start_opacity, | 32 float start_opacity, |
32 float end_opacity, | 33 float end_opacity, |
33 bool use_timing_function) { | 34 bool use_timing_function) { |
34 scoped_ptr<KeyframedFloatAnimationCurve> | 35 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
35 curve(KeyframedFloatAnimationCurve::Create()); | 36 KeyframedFloatAnimationCurve::Create()); |
36 | 37 |
37 scoped_ptr<TimingFunction> func; | 38 std::unique_ptr<TimingFunction> func; |
38 if (!use_timing_function) | 39 if (!use_timing_function) |
39 func = EaseTimingFunction::Create(); | 40 func = EaseTimingFunction::Create(); |
40 if (duration > 0.0) | 41 if (duration > 0.0) |
41 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), start_opacity, | 42 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), start_opacity, |
42 std::move(func))); | 43 std::move(func))); |
43 curve->AddKeyframe(FloatKeyframe::Create( | 44 curve->AddKeyframe(FloatKeyframe::Create( |
44 base::TimeDelta::FromSecondsD(duration), end_opacity, nullptr)); | 45 base::TimeDelta::FromSecondsD(duration), end_opacity, nullptr)); |
45 | 46 |
46 int id = AnimationIdProvider::NextAnimationId(); | 47 int id = AnimationIdProvider::NextAnimationId(); |
47 | 48 |
48 scoped_ptr<Animation> animation(Animation::Create( | 49 std::unique_ptr<Animation> animation(Animation::Create( |
49 std::move(curve), id, AnimationIdProvider::NextGroupId(), | 50 std::move(curve), id, AnimationIdProvider::NextGroupId(), |
50 TargetProperty::OPACITY)); | 51 TargetProperty::OPACITY)); |
51 animation->set_needs_synchronized_start_time(true); | 52 animation->set_needs_synchronized_start_time(true); |
52 | 53 |
53 target->AddAnimation(std::move(animation)); | 54 target->AddAnimation(std::move(animation)); |
54 return id; | 55 return id; |
55 } | 56 } |
56 | 57 |
57 template <class Target> | 58 template <class Target> |
58 int AddAnimatedTransform(Target* target, | 59 int AddAnimatedTransform(Target* target, |
59 double duration, | 60 double duration, |
60 TransformOperations start_operations, | 61 TransformOperations start_operations, |
61 TransformOperations operations) { | 62 TransformOperations operations) { |
62 scoped_ptr<KeyframedTransformAnimationCurve> | 63 std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
63 curve(KeyframedTransformAnimationCurve::Create()); | 64 KeyframedTransformAnimationCurve::Create()); |
64 | 65 |
65 if (duration > 0.0) { | 66 if (duration > 0.0) { |
66 curve->AddKeyframe(TransformKeyframe::Create(base::TimeDelta(), | 67 curve->AddKeyframe(TransformKeyframe::Create(base::TimeDelta(), |
67 start_operations, nullptr)); | 68 start_operations, nullptr)); |
68 } | 69 } |
69 | 70 |
70 curve->AddKeyframe(TransformKeyframe::Create( | 71 curve->AddKeyframe(TransformKeyframe::Create( |
71 base::TimeDelta::FromSecondsD(duration), operations, nullptr)); | 72 base::TimeDelta::FromSecondsD(duration), operations, nullptr)); |
72 | 73 |
73 int id = AnimationIdProvider::NextAnimationId(); | 74 int id = AnimationIdProvider::NextAnimationId(); |
74 | 75 |
75 scoped_ptr<Animation> animation(Animation::Create( | 76 std::unique_ptr<Animation> animation(Animation::Create( |
76 std::move(curve), id, AnimationIdProvider::NextGroupId(), | 77 std::move(curve), id, AnimationIdProvider::NextGroupId(), |
77 TargetProperty::TRANSFORM)); | 78 TargetProperty::TRANSFORM)); |
78 animation->set_needs_synchronized_start_time(true); | 79 animation->set_needs_synchronized_start_time(true); |
79 | 80 |
80 target->AddAnimation(std::move(animation)); | 81 target->AddAnimation(std::move(animation)); |
81 return id; | 82 return id; |
82 } | 83 } |
83 | 84 |
84 template <class Target> | 85 template <class Target> |
85 int AddAnimatedTransform(Target* target, | 86 int AddAnimatedTransform(Target* target, |
86 double duration, | 87 double duration, |
87 int delta_x, | 88 int delta_x, |
88 int delta_y) { | 89 int delta_y) { |
89 TransformOperations start_operations; | 90 TransformOperations start_operations; |
90 if (duration > 0.0) { | 91 if (duration > 0.0) { |
91 start_operations.AppendTranslate(0, 0, 0.0); | 92 start_operations.AppendTranslate(0, 0, 0.0); |
92 } | 93 } |
93 | 94 |
94 TransformOperations operations; | 95 TransformOperations operations; |
95 operations.AppendTranslate(delta_x, delta_y, 0.0); | 96 operations.AppendTranslate(delta_x, delta_y, 0.0); |
96 return AddAnimatedTransform(target, duration, start_operations, operations); | 97 return AddAnimatedTransform(target, duration, start_operations, operations); |
97 } | 98 } |
98 | 99 |
99 template <class Target> | 100 template <class Target> |
100 int AddAnimatedFilter(Target* target, | 101 int AddAnimatedFilter(Target* target, |
101 double duration, | 102 double duration, |
102 float start_brightness, | 103 float start_brightness, |
103 float end_brightness) { | 104 float end_brightness) { |
104 scoped_ptr<KeyframedFilterAnimationCurve> | 105 std::unique_ptr<KeyframedFilterAnimationCurve> curve( |
105 curve(KeyframedFilterAnimationCurve::Create()); | 106 KeyframedFilterAnimationCurve::Create()); |
106 | 107 |
107 if (duration > 0.0) { | 108 if (duration > 0.0) { |
108 FilterOperations start_filters; | 109 FilterOperations start_filters; |
109 start_filters.Append( | 110 start_filters.Append( |
110 FilterOperation::CreateBrightnessFilter(start_brightness)); | 111 FilterOperation::CreateBrightnessFilter(start_brightness)); |
111 curve->AddKeyframe( | 112 curve->AddKeyframe( |
112 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); | 113 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); |
113 } | 114 } |
114 | 115 |
115 FilterOperations filters; | 116 FilterOperations filters; |
116 filters.Append(FilterOperation::CreateBrightnessFilter(end_brightness)); | 117 filters.Append(FilterOperation::CreateBrightnessFilter(end_brightness)); |
117 curve->AddKeyframe(FilterKeyframe::Create( | 118 curve->AddKeyframe(FilterKeyframe::Create( |
118 base::TimeDelta::FromSecondsD(duration), filters, nullptr)); | 119 base::TimeDelta::FromSecondsD(duration), filters, nullptr)); |
119 | 120 |
120 int id = AnimationIdProvider::NextAnimationId(); | 121 int id = AnimationIdProvider::NextAnimationId(); |
121 | 122 |
122 scoped_ptr<Animation> animation(Animation::Create( | 123 std::unique_ptr<Animation> animation(Animation::Create( |
123 std::move(curve), id, AnimationIdProvider::NextGroupId(), | 124 std::move(curve), id, AnimationIdProvider::NextGroupId(), |
124 TargetProperty::FILTER)); | 125 TargetProperty::FILTER)); |
125 animation->set_needs_synchronized_start_time(true); | 126 animation->set_needs_synchronized_start_time(true); |
126 | 127 |
127 target->AddAnimation(std::move(animation)); | 128 target->AddAnimation(std::move(animation)); |
128 return id; | 129 return id; |
129 } | 130 } |
130 | 131 |
131 FakeFloatAnimationCurve::FakeFloatAnimationCurve() | 132 FakeFloatAnimationCurve::FakeFloatAnimationCurve() |
132 : duration_(base::TimeDelta::FromSecondsD(1.0)) { | 133 : duration_(base::TimeDelta::FromSecondsD(1.0)) { |
133 } | 134 } |
134 | 135 |
135 FakeFloatAnimationCurve::FakeFloatAnimationCurve(double duration) | 136 FakeFloatAnimationCurve::FakeFloatAnimationCurve(double duration) |
136 : duration_(base::TimeDelta::FromSecondsD(duration)) { | 137 : duration_(base::TimeDelta::FromSecondsD(duration)) { |
137 } | 138 } |
138 | 139 |
139 FakeFloatAnimationCurve::~FakeFloatAnimationCurve() {} | 140 FakeFloatAnimationCurve::~FakeFloatAnimationCurve() {} |
140 | 141 |
141 base::TimeDelta FakeFloatAnimationCurve::Duration() const { | 142 base::TimeDelta FakeFloatAnimationCurve::Duration() const { |
142 return duration_; | 143 return duration_; |
143 } | 144 } |
144 | 145 |
145 float FakeFloatAnimationCurve::GetValue(base::TimeDelta now) const { | 146 float FakeFloatAnimationCurve::GetValue(base::TimeDelta now) const { |
146 return 0.0f; | 147 return 0.0f; |
147 } | 148 } |
148 | 149 |
149 scoped_ptr<AnimationCurve> FakeFloatAnimationCurve::Clone() const { | 150 std::unique_ptr<AnimationCurve> FakeFloatAnimationCurve::Clone() const { |
150 return make_scoped_ptr(new FakeFloatAnimationCurve); | 151 return base::WrapUnique(new FakeFloatAnimationCurve); |
151 } | 152 } |
152 | 153 |
153 FakeTransformTransition::FakeTransformTransition(double duration) | 154 FakeTransformTransition::FakeTransformTransition(double duration) |
154 : duration_(base::TimeDelta::FromSecondsD(duration)) { | 155 : duration_(base::TimeDelta::FromSecondsD(duration)) { |
155 } | 156 } |
156 | 157 |
157 FakeTransformTransition::~FakeTransformTransition() {} | 158 FakeTransformTransition::~FakeTransformTransition() {} |
158 | 159 |
159 base::TimeDelta FakeTransformTransition::Duration() const { | 160 base::TimeDelta FakeTransformTransition::Duration() const { |
160 return duration_; | 161 return duration_; |
(...skipping 21 matching lines...) Expand all Loading... |
182 *start_scale = 1.f; | 183 *start_scale = 1.f; |
183 return true; | 184 return true; |
184 } | 185 } |
185 | 186 |
186 bool FakeTransformTransition::MaximumTargetScale(bool forward_direction, | 187 bool FakeTransformTransition::MaximumTargetScale(bool forward_direction, |
187 float* max_scale) const { | 188 float* max_scale) const { |
188 *max_scale = 1.f; | 189 *max_scale = 1.f; |
189 return true; | 190 return true; |
190 } | 191 } |
191 | 192 |
192 scoped_ptr<AnimationCurve> FakeTransformTransition::Clone() const { | 193 std::unique_ptr<AnimationCurve> FakeTransformTransition::Clone() const { |
193 return make_scoped_ptr(new FakeTransformTransition(*this)); | 194 return base::WrapUnique(new FakeTransformTransition(*this)); |
194 } | 195 } |
195 | 196 |
196 FakeFloatTransition::FakeFloatTransition(double duration, float from, float to) | 197 FakeFloatTransition::FakeFloatTransition(double duration, float from, float to) |
197 : duration_(base::TimeDelta::FromSecondsD(duration)), from_(from), to_(to) { | 198 : duration_(base::TimeDelta::FromSecondsD(duration)), from_(from), to_(to) { |
198 } | 199 } |
199 | 200 |
200 FakeFloatTransition::~FakeFloatTransition() {} | 201 FakeFloatTransition::~FakeFloatTransition() {} |
201 | 202 |
202 base::TimeDelta FakeFloatTransition::Duration() const { | 203 base::TimeDelta FakeFloatTransition::Duration() const { |
203 return duration_; | 204 return duration_; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 252 |
252 bool FakeInactiveLayerAnimationValueObserver::IsActive() const { | 253 bool FakeInactiveLayerAnimationValueObserver::IsActive() const { |
253 return false; | 254 return false; |
254 } | 255 } |
255 | 256 |
256 gfx::ScrollOffset FakeLayerAnimationValueProvider::ScrollOffsetForAnimation() | 257 gfx::ScrollOffset FakeLayerAnimationValueProvider::ScrollOffsetForAnimation() |
257 const { | 258 const { |
258 return scroll_offset_; | 259 return scroll_offset_; |
259 } | 260 } |
260 | 261 |
261 scoped_ptr<AnimationCurve> FakeFloatTransition::Clone() const { | 262 std::unique_ptr<AnimationCurve> FakeFloatTransition::Clone() const { |
262 return make_scoped_ptr(new FakeFloatTransition(*this)); | 263 return base::WrapUnique(new FakeFloatTransition(*this)); |
263 } | 264 } |
264 | 265 |
265 int AddOpacityTransitionToController(LayerAnimationController* controller, | 266 int AddOpacityTransitionToController(LayerAnimationController* controller, |
266 double duration, | 267 double duration, |
267 float start_opacity, | 268 float start_opacity, |
268 float end_opacity, | 269 float end_opacity, |
269 bool use_timing_function) { | 270 bool use_timing_function) { |
270 return AddOpacityTransition(controller, | 271 return AddOpacityTransition(controller, |
271 duration, | 272 duration, |
272 start_opacity, | 273 start_opacity, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 float start_brightness, | 321 float start_brightness, |
321 float end_brightness) { | 322 float end_brightness) { |
322 return AddAnimatedFilter(player, duration, start_brightness, end_brightness); | 323 return AddAnimatedFilter(player, duration, start_brightness, end_brightness); |
323 } | 324 } |
324 | 325 |
325 int AddOpacityStepsToController(LayerAnimationController* target, | 326 int AddOpacityStepsToController(LayerAnimationController* target, |
326 double duration, | 327 double duration, |
327 float start_opacity, | 328 float start_opacity, |
328 float end_opacity, | 329 float end_opacity, |
329 int num_steps) { | 330 int num_steps) { |
330 scoped_ptr<KeyframedFloatAnimationCurve> curve( | 331 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
331 KeyframedFloatAnimationCurve::Create()); | 332 KeyframedFloatAnimationCurve::Create()); |
332 | 333 |
333 scoped_ptr<TimingFunction> func = | 334 std::unique_ptr<TimingFunction> func = |
334 StepsTimingFunction::Create(num_steps, 0.5f); | 335 StepsTimingFunction::Create(num_steps, 0.5f); |
335 if (duration > 0.0) | 336 if (duration > 0.0) |
336 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), start_opacity, | 337 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), start_opacity, |
337 std::move(func))); | 338 std::move(func))); |
338 curve->AddKeyframe(FloatKeyframe::Create( | 339 curve->AddKeyframe(FloatKeyframe::Create( |
339 base::TimeDelta::FromSecondsD(duration), end_opacity, nullptr)); | 340 base::TimeDelta::FromSecondsD(duration), end_opacity, nullptr)); |
340 | 341 |
341 int id = AnimationIdProvider::NextAnimationId(); | 342 int id = AnimationIdProvider::NextAnimationId(); |
342 | 343 |
343 scoped_ptr<Animation> animation(Animation::Create( | 344 std::unique_ptr<Animation> animation(Animation::Create( |
344 std::move(curve), id, AnimationIdProvider::NextGroupId(), | 345 std::move(curve), id, AnimationIdProvider::NextGroupId(), |
345 TargetProperty::OPACITY)); | 346 TargetProperty::OPACITY)); |
346 animation->set_needs_synchronized_start_time(true); | 347 animation->set_needs_synchronized_start_time(true); |
347 | 348 |
348 target->AddAnimation(std::move(animation)); | 349 target->AddAnimation(std::move(animation)); |
349 return id; | 350 return id; |
350 } | 351 } |
351 | 352 |
352 void AddAnimationToLayerWithPlayer(int layer_id, | 353 void AddAnimationToLayerWithPlayer(int layer_id, |
353 scoped_refptr<AnimationTimeline> timeline, | 354 scoped_refptr<AnimationTimeline> timeline, |
354 scoped_ptr<Animation> animation) { | 355 std::unique_ptr<Animation> animation) { |
355 scoped_refptr<AnimationPlayer> player = | 356 scoped_refptr<AnimationPlayer> player = |
356 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); | 357 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
357 timeline->AttachPlayer(player); | 358 timeline->AttachPlayer(player); |
358 player->AttachLayer(layer_id); | 359 player->AttachLayer(layer_id); |
359 DCHECK(player->element_animations()); | 360 DCHECK(player->element_animations()); |
360 player->AddAnimation(std::move(animation)); | 361 player->AddAnimation(std::move(animation)); |
361 } | 362 } |
362 | 363 |
363 void AddAnimationToLayerWithExistingPlayer( | 364 void AddAnimationToLayerWithExistingPlayer( |
364 int layer_id, | 365 int layer_id, |
365 scoped_refptr<AnimationTimeline> timeline, | 366 scoped_refptr<AnimationTimeline> timeline, |
366 scoped_ptr<Animation> animation) { | 367 std::unique_ptr<Animation> animation) { |
367 LayerAnimationController* controller = | 368 LayerAnimationController* controller = |
368 timeline->animation_host()->GetControllerForLayerId(layer_id); | 369 timeline->animation_host()->GetControllerForLayerId(layer_id); |
369 DCHECK(controller); | 370 DCHECK(controller); |
370 controller->AddAnimation(std::move(animation)); | 371 controller->AddAnimation(std::move(animation)); |
371 } | 372 } |
372 | 373 |
373 void RemoveAnimationFromLayerWithExistingPlayer( | 374 void RemoveAnimationFromLayerWithExistingPlayer( |
374 int layer_id, | 375 int layer_id, |
375 scoped_refptr<AnimationTimeline> timeline, | 376 scoped_refptr<AnimationTimeline> timeline, |
376 int animation_id) { | 377 int animation_id) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 void AbortAnimationsOnLayerWithPlayer(int layer_id, | 454 void AbortAnimationsOnLayerWithPlayer(int layer_id, |
454 scoped_refptr<AnimationTimeline> timeline, | 455 scoped_refptr<AnimationTimeline> timeline, |
455 TargetProperty::Type target_property) { | 456 TargetProperty::Type target_property) { |
456 LayerAnimationController* controller = | 457 LayerAnimationController* controller = |
457 timeline->animation_host()->GetControllerForLayerId(layer_id); | 458 timeline->animation_host()->GetControllerForLayerId(layer_id); |
458 DCHECK(controller); | 459 DCHECK(controller); |
459 controller->AbortAnimations(target_property); | 460 controller->AbortAnimations(target_property); |
460 } | 461 } |
461 | 462 |
462 } // namespace cc | 463 } // namespace cc |
OLD | NEW |