Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: cc/test/animation_test_common.cc

Issue 1904653002: CC Animation: Merge LayerAnimationController into ElementAnimations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor optimization: Don't init value observations if same host. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/test/animation_test_common.h ('k') | cc/test/animation_timelines_test_common.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/memory/ptr_util.h"
8 #include "cc/animation/animation_host.h" 8 #include "cc/animation/animation_host.h"
9 #include "cc/animation/animation_id_provider.h" 9 #include "cc/animation/animation_id_provider.h"
10 #include "cc/animation/animation_player.h" 10 #include "cc/animation/animation_player.h"
11 #include "cc/animation/element_animations.h"
11 #include "cc/animation/keyframed_animation_curve.h" 12 #include "cc/animation/keyframed_animation_curve.h"
12 #include "cc/animation/layer_animation_controller.h"
13 #include "cc/animation/transform_operations.h" 13 #include "cc/animation/transform_operations.h"
14 #include "cc/base/time_util.h" 14 #include "cc/base/time_util.h"
15 #include "cc/layers/layer.h" 15 #include "cc/layers/layer.h"
16 #include "cc/layers/layer_impl.h" 16 #include "cc/layers/layer_impl.h"
17 17
18 using cc::Animation; 18 using cc::Animation;
19 using cc::AnimationCurve; 19 using cc::AnimationCurve;
20 using cc::EaseTimingFunction; 20 using cc::EaseTimingFunction;
21 using cc::FloatKeyframe; 21 using cc::FloatKeyframe;
22 using cc::KeyframedFloatAnimationCurve; 22 using cc::KeyframedFloatAnimationCurve;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 return duration_; 204 return duration_;
205 } 205 }
206 206
207 float FakeFloatTransition::GetValue(base::TimeDelta time) const { 207 float FakeFloatTransition::GetValue(base::TimeDelta time) const {
208 double progress = TimeUtil::Divide(time, duration_); 208 double progress = TimeUtil::Divide(time, duration_);
209 if (progress >= 1.0) 209 if (progress >= 1.0)
210 progress = 1.0; 210 progress = 1.0;
211 return (1.0 - progress) * from_ + progress * to_; 211 return (1.0 - progress) * from_ + progress * to_;
212 } 212 }
213 213
214 gfx::ScrollOffset FakeLayerAnimationValueProvider::ScrollOffsetForAnimation()
215 const {
216 return scroll_offset_;
217 }
218
219 FakeLayerAnimationValueObserver::FakeLayerAnimationValueObserver()
220 : animation_waiting_for_deletion_(false) {
221 opacity_[ToIndex(LayerTreeType::ACTIVE)] = 0.0f;
222 opacity_[ToIndex(LayerTreeType::PENDING)] = 0.0f;
223
224 transform_is_animating_[ToIndex(LayerTreeType::ACTIVE)] = false;
225 transform_is_animating_[ToIndex(LayerTreeType::PENDING)] = false;
226 }
227
228 FakeLayerAnimationValueObserver::~FakeLayerAnimationValueObserver() {}
229
230 int FakeLayerAnimationValueObserver::ToIndex(LayerTreeType tree_type) {
231 int index = static_cast<int>(tree_type);
232 DCHECK_GE(index, 0);
233 DCHECK_LE(index, 1);
234 return index;
235 }
236
237 void FakeLayerAnimationValueObserver::OnFilterAnimated(
238 LayerTreeType tree_type,
239 const FilterOperations& filters) {
240 filters_[ToIndex(tree_type)] = filters;
241 }
242
243 void FakeLayerAnimationValueObserver::OnOpacityAnimated(LayerTreeType tree_type,
244 float opacity) {
245 opacity_[ToIndex(tree_type)] = opacity;
246 }
247
248 void FakeLayerAnimationValueObserver::OnTransformAnimated(
249 LayerTreeType tree_type,
250 const gfx::Transform& transform) {
251 transform_[ToIndex(tree_type)] = transform;
252 }
253
254 void FakeLayerAnimationValueObserver::OnScrollOffsetAnimated(
255 LayerTreeType tree_type,
256 const gfx::ScrollOffset& scroll_offset) {
257 scroll_offset_[ToIndex(tree_type)] = scroll_offset;
258 }
259
260 void FakeLayerAnimationValueObserver::OnAnimationWaitingForDeletion() {
261 animation_waiting_for_deletion_ = true;
262 }
263
264 void FakeLayerAnimationValueObserver::OnTransformIsPotentiallyAnimatingChanged(
265 LayerTreeType tree_type,
266 bool is_animating) {
267 transform_is_animating_[ToIndex(tree_type)] = is_animating;
268 }
269
270 std::unique_ptr<AnimationCurve> FakeFloatTransition::Clone() const { 214 std::unique_ptr<AnimationCurve> FakeFloatTransition::Clone() const {
271 return base::WrapUnique(new FakeFloatTransition(*this)); 215 return base::WrapUnique(new FakeFloatTransition(*this));
272 } 216 }
273 217
274 int AddOpacityTransitionToController(LayerAnimationController* controller, 218 int AddOpacityTransitionToElementAnimations(ElementAnimations* target,
275 double duration, 219 double duration,
276 float start_opacity, 220 float start_opacity,
277 float end_opacity, 221 float end_opacity,
278 bool use_timing_function) { 222 bool use_timing_function) {
279 return AddOpacityTransition(controller, 223 return AddOpacityTransition(target, duration, start_opacity, end_opacity,
280 duration,
281 start_opacity,
282 end_opacity,
283 use_timing_function); 224 use_timing_function);
284 } 225 }
285 226
286 int AddAnimatedTransformToController(LayerAnimationController* controller, 227 int AddAnimatedTransformToElementAnimations(ElementAnimations* target,
287 double duration, 228 double duration,
288 int delta_x, 229 int delta_x,
289 int delta_y) { 230 int delta_y) {
290 return AddAnimatedTransform(controller, 231 return AddAnimatedTransform(target, duration, delta_x, delta_y);
291 duration,
292 delta_x,
293 delta_y);
294 } 232 }
295 233
296 int AddAnimatedFilterToController(LayerAnimationController* controller, 234 int AddAnimatedFilterToElementAnimations(ElementAnimations* target,
297 double duration, 235 double duration,
298 float start_brightness, 236 float start_brightness,
299 float end_brightness) { 237 float end_brightness) {
300 return AddAnimatedFilter( 238 return AddAnimatedFilter(target, duration, start_brightness, end_brightness);
301 controller, duration, start_brightness, end_brightness);
302 } 239 }
303 240
304 int AddAnimatedTransformToPlayer(AnimationPlayer* player, 241 int AddAnimatedTransformToPlayer(AnimationPlayer* player,
305 double duration, 242 double duration,
306 int delta_x, 243 int delta_x,
307 int delta_y) { 244 int delta_y) {
308 return AddAnimatedTransform(player, duration, delta_x, delta_y); 245 return AddAnimatedTransform(player, duration, delta_x, delta_y);
309 } 246 }
310 247
311 int AddAnimatedTransformToPlayer(AnimationPlayer* player, 248 int AddAnimatedTransformToPlayer(AnimationPlayer* player,
(...skipping 12 matching lines...) Expand all
324 use_timing_function); 261 use_timing_function);
325 } 262 }
326 263
327 int AddAnimatedFilterToPlayer(AnimationPlayer* player, 264 int AddAnimatedFilterToPlayer(AnimationPlayer* player,
328 double duration, 265 double duration,
329 float start_brightness, 266 float start_brightness,
330 float end_brightness) { 267 float end_brightness) {
331 return AddAnimatedFilter(player, duration, start_brightness, end_brightness); 268 return AddAnimatedFilter(player, duration, start_brightness, end_brightness);
332 } 269 }
333 270
334 int AddOpacityStepsToController(LayerAnimationController* target, 271 int AddOpacityStepsToElementAnimations(ElementAnimations* target,
335 double duration, 272 double duration,
336 float start_opacity, 273 float start_opacity,
337 float end_opacity, 274 float end_opacity,
338 int num_steps) { 275 int num_steps) {
339 std::unique_ptr<KeyframedFloatAnimationCurve> curve( 276 std::unique_ptr<KeyframedFloatAnimationCurve> curve(
340 KeyframedFloatAnimationCurve::Create()); 277 KeyframedFloatAnimationCurve::Create());
341 278
342 std::unique_ptr<TimingFunction> func = 279 std::unique_ptr<TimingFunction> func =
343 StepsTimingFunction::Create(num_steps, 0.5f); 280 StepsTimingFunction::Create(num_steps, 0.5f);
344 if (duration > 0.0) 281 if (duration > 0.0)
345 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), start_opacity, 282 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), start_opacity,
346 std::move(func))); 283 std::move(func)));
347 curve->AddKeyframe(FloatKeyframe::Create( 284 curve->AddKeyframe(FloatKeyframe::Create(
348 base::TimeDelta::FromSecondsD(duration), end_opacity, nullptr)); 285 base::TimeDelta::FromSecondsD(duration), end_opacity, nullptr));
(...skipping 17 matching lines...) Expand all
366 timeline->AttachPlayer(player); 303 timeline->AttachPlayer(player);
367 player->AttachLayer(layer_id); 304 player->AttachLayer(layer_id);
368 DCHECK(player->element_animations()); 305 DCHECK(player->element_animations());
369 player->AddAnimation(std::move(animation)); 306 player->AddAnimation(std::move(animation));
370 } 307 }
371 308
372 void AddAnimationToLayerWithExistingPlayer( 309 void AddAnimationToLayerWithExistingPlayer(
373 int layer_id, 310 int layer_id,
374 scoped_refptr<AnimationTimeline> timeline, 311 scoped_refptr<AnimationTimeline> timeline,
375 std::unique_ptr<Animation> animation) { 312 std::unique_ptr<Animation> animation) {
376 LayerAnimationController* controller = 313 scoped_refptr<ElementAnimations> element_animations =
377 timeline->animation_host()->GetControllerForLayerId(layer_id); 314 timeline->animation_host()->GetElementAnimationsForLayerId(layer_id);
378 DCHECK(controller); 315 DCHECK(element_animations);
379 controller->AddAnimation(std::move(animation)); 316 element_animations->AddAnimation(std::move(animation));
380 } 317 }
381 318
382 void RemoveAnimationFromLayerWithExistingPlayer( 319 void RemoveAnimationFromLayerWithExistingPlayer(
383 int layer_id, 320 int layer_id,
384 scoped_refptr<AnimationTimeline> timeline, 321 scoped_refptr<AnimationTimeline> timeline,
385 int animation_id) { 322 int animation_id) {
386 LayerAnimationController* controller = 323 scoped_refptr<ElementAnimations> element_animations =
387 timeline->animation_host()->GetControllerForLayerId(layer_id); 324 timeline->animation_host()->GetElementAnimationsForLayerId(layer_id);
388 DCHECK(controller); 325 DCHECK(element_animations);
389 controller->RemoveAnimation(animation_id); 326 element_animations->RemoveAnimation(animation_id);
390 } 327 }
391 328
392 Animation* GetAnimationFromLayerWithExistingPlayer( 329 Animation* GetAnimationFromLayerWithExistingPlayer(
393 int layer_id, 330 int layer_id,
394 scoped_refptr<AnimationTimeline> timeline, 331 scoped_refptr<AnimationTimeline> timeline,
395 int animation_id) { 332 int animation_id) {
396 LayerAnimationController* controller = 333 scoped_refptr<ElementAnimations> element_animations =
397 timeline->animation_host()->GetControllerForLayerId(layer_id); 334 timeline->animation_host()->GetElementAnimationsForLayerId(layer_id);
398 DCHECK(controller); 335 DCHECK(element_animations);
399 return controller->GetAnimationById(animation_id); 336 return element_animations->GetAnimationById(animation_id);
400 } 337 }
401 338
402 int AddAnimatedFilterToLayerWithPlayer( 339 int AddAnimatedFilterToLayerWithPlayer(
403 int layer_id, 340 int layer_id,
404 scoped_refptr<AnimationTimeline> timeline, 341 scoped_refptr<AnimationTimeline> timeline,
405 double duration, 342 double duration,
406 float start_brightness, 343 float start_brightness,
407 float end_brightness) { 344 float end_brightness) {
408 scoped_refptr<AnimationPlayer> player = 345 scoped_refptr<AnimationPlayer> player =
409 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); 346 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 timeline->AttachPlayer(player); 392 timeline->AttachPlayer(player);
456 player->AttachLayer(layer_id); 393 player->AttachLayer(layer_id);
457 DCHECK(player->element_animations()); 394 DCHECK(player->element_animations());
458 return AddOpacityTransitionToPlayer(player.get(), duration, start_opacity, 395 return AddOpacityTransitionToPlayer(player.get(), duration, start_opacity,
459 end_opacity, use_timing_function); 396 end_opacity, use_timing_function);
460 } 397 }
461 398
462 void AbortAnimationsOnLayerWithPlayer(int layer_id, 399 void AbortAnimationsOnLayerWithPlayer(int layer_id,
463 scoped_refptr<AnimationTimeline> timeline, 400 scoped_refptr<AnimationTimeline> timeline,
464 TargetProperty::Type target_property) { 401 TargetProperty::Type target_property) {
465 LayerAnimationController* controller = 402 scoped_refptr<ElementAnimations> element_animations =
466 timeline->animation_host()->GetControllerForLayerId(layer_id); 403 timeline->animation_host()->GetElementAnimationsForLayerId(layer_id);
467 DCHECK(controller); 404 DCHECK(element_animations);
468 controller->AbortAnimations(target_property); 405 element_animations->AbortAnimations(target_property);
469 } 406 }
470 407
471 } // namespace cc 408 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/animation_test_common.h ('k') | cc/test/animation_timelines_test_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698