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.h" | 8 #include "cc/animation.h" |
9 #include "cc/animation_id_provider.h" | 9 #include "cc/animation_id_provider.h" |
10 #include "ui/base/animation/tween.h" | 10 #include "ui/base/animation/tween.h" |
11 #include "ui/compositor/float_animation_curve_adapter.h" | 11 #include "ui/compositor/float_animation_curve_adapter.h" |
| 12 #include "ui/compositor/layer.h" |
12 #include "ui/compositor/layer_animation_delegate.h" | 13 #include "ui/compositor/layer_animation_delegate.h" |
13 #include "ui/compositor/layer_animator.h" | 14 #include "ui/compositor/layer_animator.h" |
| 15 #include "ui/compositor/transform_animation_curve_adapter.h" |
14 #include "ui/gfx/interpolated_transform.h" | 16 #include "ui/gfx/interpolated_transform.h" |
15 | 17 |
16 namespace ui { | 18 namespace ui { |
17 | 19 |
18 namespace { | 20 namespace { |
19 | 21 |
20 // Pause ----------------------------------------------------------------------- | 22 // Pause ----------------------------------------------------------------------- |
21 class Pause : public LayerAnimationElement { | 23 class Pause : public LayerAnimationElement { |
22 public: | 24 public: |
23 Pause(const AnimatableProperties& properties, base::TimeDelta duration) | 25 Pause(const AnimatableProperties& properties, base::TimeDelta duration) |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 properties.insert(LayerAnimationElement::OPACITY); | 479 properties.insert(LayerAnimationElement::OPACITY); |
478 return properties; | 480 return properties; |
479 } | 481 } |
480 | 482 |
481 float start_; | 483 float start_; |
482 const float target_; | 484 const float target_; |
483 | 485 |
484 DISALLOW_COPY_AND_ASSIGN(ThreadedOpacityTransition); | 486 DISALLOW_COPY_AND_ASSIGN(ThreadedOpacityTransition); |
485 }; | 487 }; |
486 | 488 |
| 489 // ThreadedTransformTransition ------------------------------------------------- |
| 490 |
| 491 class ThreadedTransformTransition : public ThreadedLayerAnimationElement { |
| 492 public: |
| 493 ThreadedTransformTransition(const gfx::Transform& target, |
| 494 base::TimeDelta duration) |
| 495 : ThreadedLayerAnimationElement(GetProperties(), duration), |
| 496 target_(target) { |
| 497 } |
| 498 virtual ~ThreadedTransformTransition() {} |
| 499 |
| 500 protected: |
| 501 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
| 502 gfx::Transform start_ = delegate->GetTransformForAnimation(); |
| 503 gfx::Rect bounds = delegate->GetBoundsForAnimation(); |
| 504 float device_scale_factor = delegate->GetDeviceScaleFactor(); |
| 505 cc_start_ = Layer::ConvertTransformToCCTransform(start_, |
| 506 bounds, |
| 507 device_scale_factor); |
| 508 cc_target_ = Layer::ConvertTransformToCCTransform(target_, |
| 509 bounds, |
| 510 device_scale_factor); |
| 511 } |
| 512 |
| 513 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE { |
| 514 if (delegate && animation_id()) { |
| 515 ThreadedLayerAnimationElement::OnAbort(delegate); |
| 516 delegate->SetTransformFromAnimation( |
| 517 Tween::ValueBetween(last_progressed_fraction(), start_, target_)); |
| 518 } |
| 519 } |
| 520 |
| 521 virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE { |
| 522 delegate->SetTransformFromAnimation(target_); |
| 523 } |
| 524 |
| 525 virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE { |
| 526 scoped_ptr<cc::AnimationCurve> animation_curve( |
| 527 new TransformAnimationCurveAdapter(tween_type(), |
| 528 cc_start_, |
| 529 cc_target_, |
| 530 duration())); |
| 531 scoped_ptr<cc::Animation> animation( |
| 532 cc::Animation::create(animation_curve.Pass(), |
| 533 animation_id(), |
| 534 animation_group_id(), |
| 535 cc::Animation::Transform)); |
| 536 return animation.Pass(); |
| 537 } |
| 538 |
| 539 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
| 540 target->transform = target_; |
| 541 } |
| 542 |
| 543 private: |
| 544 static AnimatableProperties GetProperties() { |
| 545 AnimatableProperties properties; |
| 546 properties.insert(LayerAnimationElement::TRANSFORM); |
| 547 return properties; |
| 548 } |
| 549 |
| 550 gfx::Transform start_; |
| 551 gfx::Transform cc_start_; |
| 552 const gfx::Transform target_; |
| 553 gfx::Transform cc_target_; |
| 554 |
| 555 DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition); |
| 556 }; |
| 557 |
487 } // namespace | 558 } // namespace |
488 | 559 |
489 // LayerAnimationElement::TargetValue ------------------------------------------ | 560 // LayerAnimationElement::TargetValue ------------------------------------------ |
490 | 561 |
491 LayerAnimationElement::TargetValue::TargetValue() | 562 LayerAnimationElement::TargetValue::TargetValue() |
492 : opacity(0.0f), | 563 : opacity(0.0f), |
493 visibility(false), | 564 visibility(false), |
494 brightness(0.0f), | 565 brightness(0.0f), |
495 grayscale(0.0f), | 566 grayscale(0.0f), |
496 color(SK_ColorBLACK) { | 567 color(SK_ColorBLACK) { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 if (LayerAnimator::slow_animation_mode()) | 717 if (LayerAnimator::slow_animation_mode()) |
647 return duration * LayerAnimator::slow_animation_scale_factor(); | 718 return duration * LayerAnimator::slow_animation_scale_factor(); |
648 | 719 |
649 return duration; | 720 return duration; |
650 } | 721 } |
651 | 722 |
652 // static | 723 // static |
653 LayerAnimationElement* LayerAnimationElement::CreateTransformElement( | 724 LayerAnimationElement* LayerAnimationElement::CreateTransformElement( |
654 const gfx::Transform& transform, | 725 const gfx::Transform& transform, |
655 base::TimeDelta duration) { | 726 base::TimeDelta duration) { |
656 return new TransformTransition(transform, duration); | 727 return new ThreadedTransformTransition(transform, duration); |
657 } | 728 } |
658 | 729 |
659 // static | 730 // static |
660 LayerAnimationElement* | 731 LayerAnimationElement* |
661 LayerAnimationElement::CreateInterpolatedTransformElement( | 732 LayerAnimationElement::CreateInterpolatedTransformElement( |
662 InterpolatedTransform* interpolated_transform, | 733 InterpolatedTransform* interpolated_transform, |
663 base::TimeDelta duration) { | 734 base::TimeDelta duration) { |
664 return new InterpolatedTransformTransition(interpolated_transform, duration); | 735 return new InterpolatedTransformTransition(interpolated_transform, duration); |
665 } | 736 } |
666 | 737 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 } | 778 } |
708 | 779 |
709 // static | 780 // static |
710 LayerAnimationElement* LayerAnimationElement::CreateColorElement( | 781 LayerAnimationElement* LayerAnimationElement::CreateColorElement( |
711 SkColor color, | 782 SkColor color, |
712 base::TimeDelta duration) { | 783 base::TimeDelta duration) { |
713 return new ColorTransition(color, duration); | 784 return new ColorTransition(color, duration); |
714 } | 785 } |
715 | 786 |
716 } // namespace ui | 787 } // namespace ui |
OLD | NEW |