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

Side by Side Diff: ui/compositor/layer_animation_element.cc

Issue 22861008: Add support for inverse transform animations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add support for inverse transform animations. Created 7 years, 4 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
OLDNEW
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
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 ---------------------------------------------
567
568 class ChildCounterTransformTransition : public ThreadedLayerAnimationElement {
569 public:
570 ChildCounterTransformTransition(const gfx::Transform& parent_start,
571 const gfx::Transform& parent_target,
572 base::TimeDelta duration)
573 : ThreadedLayerAnimationElement(GetProperties(), duration),
574 parent_start_(parent_start),
575 parent_target_(parent_target) {
576 }
577 virtual ~ChildCounterTransformTransition() {}
578
579 protected:
580 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
581 start_ = delegate->GetTransformForAnimation();
582 effective_start_ = start_ * parent_start_;
583 float device_scale_factor = delegate->GetDeviceScaleFactor();
584 cc_start_ = Layer::ConvertTransformToCCTransform(start_,
585 device_scale_factor);
586 cc_effective_start_ = Layer::ConvertTransformToCCTransform(
587 effective_start_,
588 device_scale_factor);
589 cc_parent_start_ = Layer::ConvertTransformToCCTransform(
590 parent_start_,
591 device_scale_factor);
592 cc_parent_target_ = Layer::ConvertTransformToCCTransform(
593 parent_target_,
594 device_scale_factor);
595 }
596
597 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {
598 if (delegate && Started()) {
599 ThreadedLayerAnimationElement::OnAbort(delegate);
600 delegate->SetTransformFromAnimation(ComputeCurrentTransform());
601 }
602 }
603
604 virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE {
605 delegate->SetTransformFromAnimation(
606 ComputeWithParentTransform(start_, parent_target_));
607 }
608
609 virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE {
610 gfx::Transform target = ComputeWithParentTransform(cc_effective_start_,
611 cc_parent_target_);
612 scoped_ptr<cc::AnimationCurve> animation_curve(
613 new TransformAnimationCurveAdapter(tween_type(),
ajuma 2013/08/20 15:32:41 I think we'll to perform matrix inversion in the c
avallee 2013/08/22 22:21:59 Done.
614 cc_start_,
615 target,
616 duration()));
617 scoped_ptr<cc::Animation> animation(
618 cc::Animation::Create(animation_curve.Pass(),
619 animation_id(),
620 animation_group_id(),
621 cc::Animation::Transform));
622 return animation.Pass();
623 }
624
625 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
626 target->transform = ComputeWithParentTransform(start_, parent_target_);
ajuma 2013/08/20 15:32:41 If ComputeWithParentTransform turns out to be more
avallee 2013/08/22 22:21:59 I'll leave this here for now. We could compute the
627 }
628
629 private:
630 gfx::Transform ComputeCurrentTransform() const {
631 gfx::Transform parent_current = Tween::ValueBetween(
632 Tween::CalculateValue(tween_type(), last_progressed_fraction()),
633 parent_start_,
634 parent_target_);
635 return ComputeWithParentTransform(effective_start_, parent_current);
636 }
637
638 gfx::Transform ComputeWithParentTransform(gfx::Transform start,
639 gfx::Transform parent) const {
640 gfx::Transform to_return(gfx::Transform::kSkipInitialization);
641 if (!parent.GetInverse(&to_return)) {
642 DLOG(WARNING) << "Parent transform not invertible.";
ajuma 2013/08/20 15:32:41 Use a DCHECK instead of a DLOG (so that we crash a
avallee 2013/08/22 22:21:59 Done.
643 to_return.MakeIdentity();
644 }
645 to_return.ConcatTransform(start);
ajuma 2013/08/20 15:32:41 Since we're skipping initialization above, this is
avallee 2013/08/22 22:21:59 It's initialized either by successfully getting th
646 return to_return;
ajuma 2013/08/20 15:32:41 This method isn't using |parent| anywhere. Is some
avallee 2013/08/22 22:21:59 parent.GetInverse inside the if statement.
647 }
648
649 static AnimatableProperties GetProperties() {
650 AnimatableProperties properties;
651 properties.insert(LayerAnimationElement::TRANSFORM);
652 return properties;
653 }
654
655 gfx::Transform start_;
656 gfx::Transform cc_start_;
657 gfx::Transform effective_start_;
658 gfx::Transform cc_effective_start_;
659
660 const gfx::Transform parent_start_;
661 gfx::Transform cc_parent_start_;
662 const gfx::Transform parent_target_;
663 gfx::Transform cc_parent_target_;
664
665 DISALLOW_COPY_AND_ASSIGN(ChildCounterTransformTransition);
666 };
667
566 } // namespace 668 } // namespace
567 669
568 // LayerAnimationElement::TargetValue ------------------------------------------ 670 // LayerAnimationElement::TargetValue ------------------------------------------
569 671
570 LayerAnimationElement::TargetValue::TargetValue() 672 LayerAnimationElement::TargetValue::TargetValue()
571 : opacity(0.0f), 673 : opacity(0.0f),
572 visibility(false), 674 visibility(false),
573 brightness(0.0f), 675 brightness(0.0f),
574 grayscale(0.0f), 676 grayscale(0.0f),
575 color(SK_ColorBLACK) { 677 color(SK_ColorBLACK) {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 } 824 }
723 825
724 // static 826 // static
725 LayerAnimationElement* LayerAnimationElement::CreateTransformElement( 827 LayerAnimationElement* LayerAnimationElement::CreateTransformElement(
726 const gfx::Transform& transform, 828 const gfx::Transform& transform,
727 base::TimeDelta duration) { 829 base::TimeDelta duration) {
728 return new ThreadedTransformTransition(transform, duration); 830 return new ThreadedTransformTransition(transform, duration);
729 } 831 }
730 832
731 // static 833 // static
834 LayerAnimationElement* LayerAnimationElement::CreateInverseTransformElement(
835 const gfx::Transform& parent_start,
836 const gfx::Transform& parent_end,
837 base::TimeDelta duration) {
838 return new ChildCounterTransformTransition(parent_start,
839 parent_end,
840 duration);
841 }
842
843 // static
732 LayerAnimationElement* 844 LayerAnimationElement*
733 LayerAnimationElement::CreateInterpolatedTransformElement( 845 LayerAnimationElement::CreateInterpolatedTransformElement(
734 InterpolatedTransform* interpolated_transform, 846 InterpolatedTransform* interpolated_transform,
735 base::TimeDelta duration) { 847 base::TimeDelta duration) {
736 return new InterpolatedTransformTransition(interpolated_transform, duration); 848 return new InterpolatedTransformTransition(interpolated_transform, duration);
737 } 849 }
738 850
739 // static 851 // static
740 LayerAnimationElement* LayerAnimationElement::CreateBoundsElement( 852 LayerAnimationElement* LayerAnimationElement::CreateBoundsElement(
741 const gfx::Rect& bounds, 853 const gfx::Rect& bounds,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 } 891 }
780 892
781 // static 893 // static
782 LayerAnimationElement* LayerAnimationElement::CreateColorElement( 894 LayerAnimationElement* LayerAnimationElement::CreateColorElement(
783 SkColor color, 895 SkColor color,
784 base::TimeDelta duration) { 896 base::TimeDelta duration) {
785 return new ColorTransition(color, duration); 897 return new ColorTransition(color, duration);
786 } 898 }
787 899
788 } // namespace ui 900 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698