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

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

Issue 23809002: Revert 220479 "Add support for inverse transform animations." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 base::TimeDelta duration) 387 base::TimeDelta duration)
388 : LayerAnimationElement(properties, duration) { 388 : LayerAnimationElement(properties, duration) {
389 } 389 }
390 virtual ~ThreadedLayerAnimationElement() {} 390 virtual ~ThreadedLayerAnimationElement() {}
391 391
392 virtual bool IsThreaded() const OVERRIDE { 392 virtual bool IsThreaded() const OVERRIDE {
393 return (duration() != base::TimeDelta()); 393 return (duration() != base::TimeDelta());
394 } 394 }
395 395
396 protected: 396 protected:
397 explicit ThreadedLayerAnimationElement(const LayerAnimationElement& element)
398 : LayerAnimationElement(element) {
399 }
400
401 virtual bool OnProgress(double t, 397 virtual bool OnProgress(double t,
402 LayerAnimationDelegate* delegate) OVERRIDE { 398 LayerAnimationDelegate* delegate) OVERRIDE {
403 if (t < 1.0) 399 if (t < 1.0)
404 return false; 400 return false;
405 401
406 if (Started()) { 402 if (Started()) {
407 delegate->RemoveThreadedAnimation(animation_id()); 403 delegate->RemoveThreadedAnimation(animation_id());
408 } 404 }
409 405
410 OnEnd(delegate); 406 OnEnd(delegate);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 } 556 }
561 557
562 gfx::Transform start_; 558 gfx::Transform start_;
563 gfx::Transform cc_start_; 559 gfx::Transform cc_start_;
564 const gfx::Transform target_; 560 const gfx::Transform target_;
565 gfx::Transform cc_target_; 561 gfx::Transform cc_target_;
566 562
567 DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition); 563 DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition);
568 }; 564 };
569 565
570 // InverseTransformTransision --------------------------------------------------
571
572 class InverseTransformTransition : public ThreadedLayerAnimationElement {
573 public:
574 InverseTransformTransition(const gfx::Transform& base_transform,
575 const LayerAnimationElement* uninverted_transition)
576 : ThreadedLayerAnimationElement(*uninverted_transition),
577 base_transform_(base_transform),
578 uninverted_transition_(CheckAndCast(uninverted_transition)) {
579 }
580 virtual ~InverseTransformTransition() {}
581
582 protected:
583 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
584 gfx::Transform start(delegate->GetTransformForAnimation());
585 effective_start_ = base_transform_ * start;
586
587 TargetValue target;
588 uninverted_transition_->GetTargetValue(&target);
589 base_target_ = target.transform;
590
591 set_tween_type(uninverted_transition_->tween_type());
592
593 float device_scale_factor = delegate->GetDeviceScaleFactor();
594 const gfx::Transform cc_base_start = Layer::ConvertTransformToCCTransform(
595 base_transform_,
596 device_scale_factor);
597 const gfx::Transform cc_base_target = Layer::ConvertTransformToCCTransform(
598 base_target_,
599 device_scale_factor);
600 TransformAnimationCurveAdapter base_curve(tween_type(),
601 cc_base_start,
602 cc_base_target,
603 duration());
604
605 const gfx::Transform cc_start = Layer::ConvertTransformToCCTransform(
606 start, device_scale_factor);
607 animation_curve_.reset(new InverseTransformCurveAdapter(
608 base_curve, cc_start, duration()));
609 computed_target_transform_ = ComputeWithBaseTransform(effective_start_,
610 base_target_);
611 }
612
613 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {
614 if (delegate && Started()) {
615 ThreadedLayerAnimationElement::OnAbort(delegate);
616 delegate->SetTransformFromAnimation(ComputeCurrentTransform());
617 }
618 }
619
620 virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE {
621 delegate->SetTransformFromAnimation(computed_target_transform_);
622 }
623
624 virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE {
625 scoped_ptr<cc::Animation> animation(
626 cc::Animation::Create(animation_curve_->Clone(),
627 animation_id(),
628 animation_group_id(),
629 cc::Animation::Transform));
630 return animation.Pass();
631 }
632
633 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
634 target->transform = computed_target_transform_;
635 }
636
637 private:
638 gfx::Transform ComputeCurrentTransform() const {
639 gfx::Transform base_current = Tween::ValueBetween(
640 Tween::CalculateValue(tween_type(), last_progressed_fraction()),
641 base_transform_,
642 base_target_);
643 return ComputeWithBaseTransform(effective_start_, base_current);
644 }
645
646 gfx::Transform ComputeWithBaseTransform(gfx::Transform start,
647 gfx::Transform target) const {
648 gfx::Transform to_return(gfx::Transform::kSkipInitialization);
649 DCHECK(target.GetInverse(&to_return));
650
651 to_return.PreconcatTransform(start);
652 return to_return;
653 }
654
655 static AnimatableProperties GetProperties() {
656 AnimatableProperties properties;
657 properties.insert(LayerAnimationElement::TRANSFORM);
658 return properties;
659 }
660
661 static const ThreadedTransformTransition* CheckAndCast(
662 const LayerAnimationElement* element) {
663 const AnimatableProperties& properties = element->properties();
664 DCHECK(properties.find(TRANSFORM) != properties.end());
665 return static_cast<const ThreadedTransformTransition*>(element);
666 }
667
668 gfx::Transform effective_start_;
669 gfx::Transform computed_target_transform_;
670
671 const gfx::Transform base_transform_;
672 gfx::Transform base_target_;
673
674 scoped_ptr<cc::AnimationCurve> animation_curve_;
675
676 const ThreadedTransformTransition* const uninverted_transition_;
677
678 DISALLOW_COPY_AND_ASSIGN(InverseTransformTransition);
679 };
680
681 } // namespace 566 } // namespace
682 567
683 // LayerAnimationElement::TargetValue ------------------------------------------ 568 // LayerAnimationElement::TargetValue ------------------------------------------
684 569
685 LayerAnimationElement::TargetValue::TargetValue() 570 LayerAnimationElement::TargetValue::TargetValue()
686 : opacity(0.0f), 571 : opacity(0.0f),
687 visibility(false), 572 visibility(false),
688 brightness(0.0f), 573 brightness(0.0f),
689 grayscale(0.0f), 574 grayscale(0.0f),
690 color(SK_ColorBLACK) { 575 color(SK_ColorBLACK) {
(...skipping 18 matching lines...) Expand all
709 base::TimeDelta duration) 594 base::TimeDelta duration)
710 : first_frame_(true), 595 : first_frame_(true),
711 properties_(properties), 596 properties_(properties),
712 duration_(GetEffectiveDuration(duration)), 597 duration_(GetEffectiveDuration(duration)),
713 tween_type_(Tween::LINEAR), 598 tween_type_(Tween::LINEAR),
714 animation_id_(cc::AnimationIdProvider::NextAnimationId()), 599 animation_id_(cc::AnimationIdProvider::NextAnimationId()),
715 animation_group_id_(0), 600 animation_group_id_(0),
716 last_progressed_fraction_(0.0) { 601 last_progressed_fraction_(0.0) {
717 } 602 }
718 603
719 LayerAnimationElement::LayerAnimationElement(
720 const LayerAnimationElement &element)
721 : first_frame_(element.first_frame_),
722 properties_(element.properties_),
723 duration_(element.duration_),
724 tween_type_(element.tween_type_),
725 animation_id_(cc::AnimationIdProvider::NextAnimationId()),
726 animation_group_id_(element.animation_group_id_),
727 last_progressed_fraction_(element.last_progressed_fraction_) {
728 }
729
730 LayerAnimationElement::~LayerAnimationElement() { 604 LayerAnimationElement::~LayerAnimationElement() {
731 } 605 }
732 606
733 void LayerAnimationElement::Start(LayerAnimationDelegate* delegate, 607 void LayerAnimationElement::Start(LayerAnimationDelegate* delegate,
734 int animation_group_id) { 608 int animation_group_id) {
735 DCHECK(requested_start_time_ != base::TimeTicks()); 609 DCHECK(requested_start_time_ != base::TimeTicks());
736 DCHECK(first_frame_); 610 DCHECK(first_frame_);
737 animation_group_id_ = animation_group_id; 611 animation_group_id_ = animation_group_id;
738 last_progressed_fraction_ = 0.0; 612 last_progressed_fraction_ = 0.0;
739 OnStart(delegate); 613 OnStart(delegate);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 } 722 }
849 723
850 // static 724 // static
851 LayerAnimationElement* LayerAnimationElement::CreateTransformElement( 725 LayerAnimationElement* LayerAnimationElement::CreateTransformElement(
852 const gfx::Transform& transform, 726 const gfx::Transform& transform,
853 base::TimeDelta duration) { 727 base::TimeDelta duration) {
854 return new ThreadedTransformTransition(transform, duration); 728 return new ThreadedTransformTransition(transform, duration);
855 } 729 }
856 730
857 // static 731 // static
858 LayerAnimationElement* LayerAnimationElement::CreateInverseTransformElement(
859 const gfx::Transform& base_transform,
860 const LayerAnimationElement* uninverted_transition) {
861 return new InverseTransformTransition(base_transform, uninverted_transition);
862 }
863
864 // static
865 LayerAnimationElement* 732 LayerAnimationElement*
866 LayerAnimationElement::CreateInterpolatedTransformElement( 733 LayerAnimationElement::CreateInterpolatedTransformElement(
867 InterpolatedTransform* interpolated_transform, 734 InterpolatedTransform* interpolated_transform,
868 base::TimeDelta duration) { 735 base::TimeDelta duration) {
869 return new InterpolatedTransformTransition(interpolated_transform, duration); 736 return new InterpolatedTransformTransition(interpolated_transform, duration);
870 } 737 }
871 738
872 // static 739 // static
873 LayerAnimationElement* LayerAnimationElement::CreateBoundsElement( 740 LayerAnimationElement* LayerAnimationElement::CreateBoundsElement(
874 const gfx::Rect& bounds, 741 const gfx::Rect& bounds,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 } 779 }
913 780
914 // static 781 // static
915 LayerAnimationElement* LayerAnimationElement::CreateColorElement( 782 LayerAnimationElement* LayerAnimationElement::CreateColorElement(
916 SkColor color, 783 SkColor color,
917 base::TimeDelta duration) { 784 base::TimeDelta duration) {
918 return new ColorTransition(color, duration); 785 return new ColorTransition(color, duration);
919 } 786 }
920 787
921 } // namespace ui 788 } // namespace ui
OLDNEW
« no previous file with comments | « trunk/src/ui/compositor/layer_animation_element.h ('k') | trunk/src/ui/compositor/layer_animation_element_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698