OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/compositor/layer_animation_element.h" | 5 #include "ui/compositor/layer_animation_element.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "cc/animation/animation.h" | 8 #include "cc/animation/animation.h" |
9 #include "cc/animation/animation_id_provider.h" | 9 #include "cc/animation/animation_id_provider.h" |
10 #include "ui/compositor/float_animation_curve_adapter.h" | 10 #include "ui/compositor/float_animation_curve_adapter.h" |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 ThreadedTransformTransition(const gfx::Transform& target, | 442 ThreadedTransformTransition(const gfx::Transform& target, |
443 base::TimeDelta duration) | 443 base::TimeDelta duration) |
444 : ThreadedLayerAnimationElement(TRANSFORM, duration), | 444 : ThreadedLayerAnimationElement(TRANSFORM, duration), |
445 target_(target) { | 445 target_(target) { |
446 } | 446 } |
447 virtual ~ThreadedTransformTransition() {} | 447 virtual ~ThreadedTransformTransition() {} |
448 | 448 |
449 protected: | 449 protected: |
450 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 450 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
451 start_ = delegate->GetTransformForAnimation(); | 451 start_ = delegate->GetTransformForAnimation(); |
452 float device_scale_factor = delegate->GetDeviceScaleFactor(); | |
453 cc_start_ = Layer::ConvertTransformToCCTransform(start_, | |
454 device_scale_factor); | |
455 cc_target_ = Layer::ConvertTransformToCCTransform(target_, | |
456 device_scale_factor); | |
457 } | 452 } |
458 | 453 |
459 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE { | 454 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE { |
460 if (delegate && Started()) { | 455 if (delegate && Started()) { |
461 ThreadedLayerAnimationElement::OnAbort(delegate); | 456 ThreadedLayerAnimationElement::OnAbort(delegate); |
462 delegate->SetTransformFromAnimation(gfx::Tween::TransformValueBetween( | 457 delegate->SetTransformFromAnimation(gfx::Tween::TransformValueBetween( |
463 gfx::Tween::CalculateValue(tween_type(), last_progressed_fraction()), | 458 gfx::Tween::CalculateValue(tween_type(), last_progressed_fraction()), |
464 start_, | 459 start_, |
465 target_)); | 460 target_)); |
466 } | 461 } |
467 } | 462 } |
468 | 463 |
469 virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE { | 464 virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE { |
470 delegate->SetTransformFromAnimation(target_); | 465 delegate->SetTransformFromAnimation(target_); |
471 } | 466 } |
472 | 467 |
473 virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE { | 468 virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE { |
474 scoped_ptr<cc::AnimationCurve> animation_curve( | 469 scoped_ptr<cc::AnimationCurve> animation_curve( |
475 new TransformAnimationCurveAdapter(tween_type(), | 470 new TransformAnimationCurveAdapter(tween_type(), |
476 cc_start_, | 471 start_, |
477 cc_target_, | 472 target_, |
478 duration())); | 473 duration())); |
479 scoped_ptr<cc::Animation> animation( | 474 scoped_ptr<cc::Animation> animation( |
480 cc::Animation::Create(animation_curve.Pass(), | 475 cc::Animation::Create(animation_curve.Pass(), |
481 animation_id(), | 476 animation_id(), |
482 animation_group_id(), | 477 animation_group_id(), |
483 cc::Animation::Transform)); | 478 cc::Animation::Transform)); |
484 return animation.Pass(); | 479 return animation.Pass(); |
485 } | 480 } |
486 | 481 |
487 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 482 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
488 target->transform = target_; | 483 target->transform = target_; |
489 } | 484 } |
490 | 485 |
491 private: | 486 private: |
492 gfx::Transform start_; | 487 gfx::Transform start_; |
493 gfx::Transform cc_start_; | |
494 const gfx::Transform target_; | 488 const gfx::Transform target_; |
495 gfx::Transform cc_target_; | |
496 | 489 |
497 DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition); | 490 DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition); |
498 }; | 491 }; |
499 | 492 |
500 // InverseTransformTransision -------------------------------------------------- | 493 // InverseTransformTransision -------------------------------------------------- |
501 | 494 |
502 class InverseTransformTransition : public ThreadedLayerAnimationElement { | 495 class InverseTransformTransition : public ThreadedLayerAnimationElement { |
503 public: | 496 public: |
504 InverseTransformTransition(const gfx::Transform& base_transform, | 497 InverseTransformTransition(const gfx::Transform& base_transform, |
505 const LayerAnimationElement* uninverted_transition) | 498 const LayerAnimationElement* uninverted_transition) |
(...skipping 16 matching lines...) Expand all Loading... |
522 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 515 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
523 gfx::Transform start(delegate->GetTransformForAnimation()); | 516 gfx::Transform start(delegate->GetTransformForAnimation()); |
524 effective_start_ = base_transform_ * start; | 517 effective_start_ = base_transform_ * start; |
525 | 518 |
526 TargetValue target; | 519 TargetValue target; |
527 uninverted_transition_->GetTargetValue(&target); | 520 uninverted_transition_->GetTargetValue(&target); |
528 base_target_ = target.transform; | 521 base_target_ = target.transform; |
529 | 522 |
530 set_tween_type(uninverted_transition_->tween_type()); | 523 set_tween_type(uninverted_transition_->tween_type()); |
531 | 524 |
532 float device_scale_factor = delegate->GetDeviceScaleFactor(); | |
533 const gfx::Transform cc_base_start = Layer::ConvertTransformToCCTransform( | |
534 base_transform_, | |
535 device_scale_factor); | |
536 const gfx::Transform cc_base_target = Layer::ConvertTransformToCCTransform( | |
537 base_target_, | |
538 device_scale_factor); | |
539 TransformAnimationCurveAdapter base_curve(tween_type(), | 525 TransformAnimationCurveAdapter base_curve(tween_type(), |
540 cc_base_start, | 526 base_transform_, |
541 cc_base_target, | 527 base_target_, |
542 duration()); | 528 duration()); |
543 | 529 |
544 const gfx::Transform cc_start = Layer::ConvertTransformToCCTransform( | |
545 start, device_scale_factor); | |
546 animation_curve_.reset(new InverseTransformCurveAdapter( | 530 animation_curve_.reset(new InverseTransformCurveAdapter( |
547 base_curve, cc_start, duration())); | 531 base_curve, start, duration())); |
548 computed_target_transform_ = ComputeWithBaseTransform(effective_start_, | 532 computed_target_transform_ = ComputeWithBaseTransform(effective_start_, |
549 base_target_); | 533 base_target_); |
550 } | 534 } |
551 | 535 |
552 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE { | 536 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE { |
553 if (delegate && Started()) { | 537 if (delegate && Started()) { |
554 ThreadedLayerAnimationElement::OnAbort(delegate); | 538 ThreadedLayerAnimationElement::OnAbort(delegate); |
555 delegate->SetTransformFromAnimation(ComputeCurrentTransform()); | 539 delegate->SetTransformFromAnimation(ComputeCurrentTransform()); |
556 } | 540 } |
557 } | 541 } |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 } | 843 } |
860 | 844 |
861 // static | 845 // static |
862 LayerAnimationElement* LayerAnimationElement::CreateColorElement( | 846 LayerAnimationElement* LayerAnimationElement::CreateColorElement( |
863 SkColor color, | 847 SkColor color, |
864 base::TimeDelta duration) { | 848 base::TimeDelta duration) { |
865 return new ColorTransition(color, duration); | 849 return new ColorTransition(color, duration); |
866 } | 850 } |
867 | 851 |
868 } // namespace ui | 852 } // namespace ui |
OLD | NEW |