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/base/animation/tween.h" | 10 #include "ui/base/animation/tween.h" |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
556 } | 556 } |
557 | 557 |
558 gfx::Transform start_; | 558 gfx::Transform start_; |
559 gfx::Transform cc_start_; | 559 gfx::Transform cc_start_; |
560 const gfx::Transform target_; | 560 const gfx::Transform target_; |
561 gfx::Transform cc_target_; | 561 gfx::Transform cc_target_; |
562 | 562 |
563 DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition); | 563 DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition); |
564 }; | 564 }; |
565 | 565 |
566 // ChildCounterTransformTransition --------------------------------------------- | |
Ian Vollick
2013/08/26 14:19:55
I wonder if we could avoid the child/parent verbag
avallee
2013/08/27 19:29:25
Done.
| |
567 | |
568 class ChildCounterTransformTransition : public ThreadedLayerAnimationElement { | |
569 public: | |
570 ChildCounterTransformTransition(const gfx::Transform& parent_start, | |
571 const LayerAnimationElement* parent, | |
572 base::TimeDelta duration) | |
Ian Vollick
2013/08/26 14:19:55
This duration can be pulled from the 'parent' elem
avallee
2013/08/27 19:29:25
Plumbed through duration in a LAE constructor, mak
| |
573 : ThreadedLayerAnimationElement(GetProperties(), duration), | |
574 parent_start_(parent_start), | |
575 parent_transition_(CheckAndCast(parent)) { | |
576 } | |
577 virtual ~ChildCounterTransformTransition() {} | |
578 | |
579 protected: | |
580 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | |
581 start_ = delegate->GetTransformForAnimation(); | |
582 effective_start_ = parent_start_ * start_; | |
583 | |
584 TargetValue target; | |
585 parent_transition_->GetTargetValue(&target); | |
586 parent_target_ = target.transform; | |
587 | |
588 set_tween_type(parent_transition_->tween_type()); | |
589 float device_scale_factor = delegate->GetDeviceScaleFactor(); | |
590 cc_start_ = Layer::ConvertTransformToCCTransform(start_, | |
591 device_scale_factor); | |
592 cc_parent_start_ = Layer::ConvertTransformToCCTransform( | |
593 parent_start_, | |
594 device_scale_factor); | |
595 cc_parent_target_ = Layer::ConvertTransformToCCTransform( | |
596 parent_target_, | |
597 device_scale_factor); | |
598 } | |
599 | |
600 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE { | |
601 if (delegate && Started()) { | |
602 ThreadedLayerAnimationElement::OnAbort(delegate); | |
603 delegate->SetTransformFromAnimation(ComputeCurrentTransform()); | |
604 } | |
605 } | |
606 | |
607 virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE { | |
608 delegate->SetTransformFromAnimation( | |
609 ComputeWithParentTransform(effective_start_, parent_target_)); | |
610 } | |
611 | |
612 virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE { | |
613 TransformAnimationCurveAdapter parent_curve(tween_type(), | |
Ian Vollick
2013/08/26 14:19:55
The values in this function are built based on con
avallee
2013/08/27 19:29:25
Done.
| |
614 cc_parent_start_, | |
615 cc_parent_target_, | |
616 duration()); | |
617 scoped_ptr<cc::AnimationCurve> animation_curve( | |
618 new CounterTransformCurveAdapter(parent_curve, | |
619 cc_start_, | |
620 duration())); | |
621 scoped_ptr<cc::Animation> animation( | |
622 cc::Animation::Create(animation_curve.Pass(), | |
623 animation_id(), | |
624 animation_group_id(), | |
625 cc::Animation::Transform)); | |
626 return animation.Pass(); | |
627 } | |
628 | |
629 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | |
630 target->transform = ComputeWithParentTransform(effective_start_, | |
631 parent_target_); | |
632 } | |
633 | |
634 private: | |
635 gfx::Transform ComputeCurrentTransform() const { | |
636 gfx::Transform parent_current = Tween::ValueBetween( | |
637 Tween::CalculateValue(tween_type(), last_progressed_fraction()), | |
638 parent_start_, | |
639 parent_target_); | |
640 return ComputeWithParentTransform(effective_start_, parent_current); | |
641 } | |
642 | |
643 gfx::Transform ComputeWithParentTransform(gfx::Transform start, | |
644 gfx::Transform parent) const { | |
645 gfx::Transform to_return(gfx::Transform::kSkipInitialization); | |
646 DCHECK(parent.GetInverse(&to_return)); | |
647 | |
648 to_return.PreconcatTransform(start); | |
649 return to_return; | |
650 } | |
651 | |
652 static AnimatableProperties GetProperties() { | |
653 AnimatableProperties properties; | |
654 properties.insert(LayerAnimationElement::TRANSFORM); | |
655 return properties; | |
656 } | |
657 | |
658 static const ThreadedTransformTransition* CheckAndCast( | |
659 const LayerAnimationElement* element) { | |
660 const AnimatableProperties& properties = element->properties(); | |
661 DCHECK(properties.find(TRANSFORM) != properties.end()); | |
662 return static_cast<const ThreadedTransformTransition*>(element); | |
663 } | |
664 | |
665 gfx::Transform start_; | |
Ian Vollick
2013/08/26 14:19:55
Do we need to store this at all?
avallee
2013/08/27 19:29:25
Thought we did, but reworked it so that it's no lo
| |
666 gfx::Transform cc_start_; | |
667 gfx::Transform effective_start_; | |
668 | |
669 const gfx::Transform parent_start_; | |
670 gfx::Transform cc_parent_start_; | |
671 gfx::Transform parent_target_; | |
672 gfx::Transform cc_parent_target_; | |
673 | |
674 const ThreadedTransformTransition* const parent_transition_; | |
675 | |
676 DISALLOW_COPY_AND_ASSIGN(ChildCounterTransformTransition); | |
677 }; | |
678 | |
566 } // namespace | 679 } // namespace |
567 | 680 |
568 // LayerAnimationElement::TargetValue ------------------------------------------ | 681 // LayerAnimationElement::TargetValue ------------------------------------------ |
569 | 682 |
570 LayerAnimationElement::TargetValue::TargetValue() | 683 LayerAnimationElement::TargetValue::TargetValue() |
571 : opacity(0.0f), | 684 : opacity(0.0f), |
572 visibility(false), | 685 visibility(false), |
573 brightness(0.0f), | 686 brightness(0.0f), |
574 grayscale(0.0f), | 687 grayscale(0.0f), |
575 color(SK_ColorBLACK) { | 688 color(SK_ColorBLACK) { |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
722 } | 835 } |
723 | 836 |
724 // static | 837 // static |
725 LayerAnimationElement* LayerAnimationElement::CreateTransformElement( | 838 LayerAnimationElement* LayerAnimationElement::CreateTransformElement( |
726 const gfx::Transform& transform, | 839 const gfx::Transform& transform, |
727 base::TimeDelta duration) { | 840 base::TimeDelta duration) { |
728 return new ThreadedTransformTransition(transform, duration); | 841 return new ThreadedTransformTransition(transform, duration); |
729 } | 842 } |
730 | 843 |
731 // static | 844 // static |
845 LayerAnimationElement* LayerAnimationElement::CreateCounterTransformElement( | |
846 const gfx::Transform& parent_start, | |
847 const LayerAnimationElement* parent) { | |
848 return new ChildCounterTransformTransition(parent_start, | |
849 parent, | |
850 parent->duration()); | |
Ian Vollick
2013/08/26 14:19:55
See above about ditching the 3rd param.
avallee
2013/08/27 19:29:25
Done.
| |
851 } | |
852 | |
853 // static | |
732 LayerAnimationElement* | 854 LayerAnimationElement* |
733 LayerAnimationElement::CreateInterpolatedTransformElement( | 855 LayerAnimationElement::CreateInterpolatedTransformElement( |
734 InterpolatedTransform* interpolated_transform, | 856 InterpolatedTransform* interpolated_transform, |
735 base::TimeDelta duration) { | 857 base::TimeDelta duration) { |
736 return new InterpolatedTransformTransition(interpolated_transform, duration); | 858 return new InterpolatedTransformTransition(interpolated_transform, duration); |
737 } | 859 } |
738 | 860 |
739 // static | 861 // static |
740 LayerAnimationElement* LayerAnimationElement::CreateBoundsElement( | 862 LayerAnimationElement* LayerAnimationElement::CreateBoundsElement( |
741 const gfx::Rect& bounds, | 863 const gfx::Rect& bounds, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
779 } | 901 } |
780 | 902 |
781 // static | 903 // static |
782 LayerAnimationElement* LayerAnimationElement::CreateColorElement( | 904 LayerAnimationElement* LayerAnimationElement::CreateColorElement( |
783 SkColor color, | 905 SkColor color, |
784 base::TimeDelta duration) { | 906 base::TimeDelta duration) { |
785 return new ColorTransition(color, duration); | 907 return new ColorTransition(color, duration); |
786 } | 908 } |
787 | 909 |
788 } // namespace ui | 910 } // namespace ui |
OLD | NEW |