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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
397 virtual bool OnProgress(double t, | 401 virtual bool OnProgress(double t, |
398 LayerAnimationDelegate* delegate) OVERRIDE { | 402 LayerAnimationDelegate* delegate) OVERRIDE { |
399 if (t < 1.0) | 403 if (t < 1.0) |
400 return false; | 404 return false; |
401 | 405 |
402 if (Started()) { | 406 if (Started()) { |
403 delegate->RemoveThreadedAnimation(animation_id()); | 407 delegate->RemoveThreadedAnimation(animation_id()); |
404 } | 408 } |
405 | 409 |
406 OnEnd(delegate); | 410 OnEnd(delegate); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 } | 560 } |
557 | 561 |
558 gfx::Transform start_; | 562 gfx::Transform start_; |
559 gfx::Transform cc_start_; | 563 gfx::Transform cc_start_; |
560 const gfx::Transform target_; | 564 const gfx::Transform target_; |
561 gfx::Transform cc_target_; | 565 gfx::Transform cc_target_; |
562 | 566 |
563 DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition); | 567 DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition); |
564 }; | 568 }; |
565 | 569 |
| 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 |
566 } // namespace | 681 } // namespace |
567 | 682 |
568 // LayerAnimationElement::TargetValue ------------------------------------------ | 683 // LayerAnimationElement::TargetValue ------------------------------------------ |
569 | 684 |
570 LayerAnimationElement::TargetValue::TargetValue() | 685 LayerAnimationElement::TargetValue::TargetValue() |
571 : opacity(0.0f), | 686 : opacity(0.0f), |
572 visibility(false), | 687 visibility(false), |
573 brightness(0.0f), | 688 brightness(0.0f), |
574 grayscale(0.0f), | 689 grayscale(0.0f), |
575 color(SK_ColorBLACK) { | 690 color(SK_ColorBLACK) { |
(...skipping 18 matching lines...) Expand all Loading... |
594 base::TimeDelta duration) | 709 base::TimeDelta duration) |
595 : first_frame_(true), | 710 : first_frame_(true), |
596 properties_(properties), | 711 properties_(properties), |
597 duration_(GetEffectiveDuration(duration)), | 712 duration_(GetEffectiveDuration(duration)), |
598 tween_type_(Tween::LINEAR), | 713 tween_type_(Tween::LINEAR), |
599 animation_id_(cc::AnimationIdProvider::NextAnimationId()), | 714 animation_id_(cc::AnimationIdProvider::NextAnimationId()), |
600 animation_group_id_(0), | 715 animation_group_id_(0), |
601 last_progressed_fraction_(0.0) { | 716 last_progressed_fraction_(0.0) { |
602 } | 717 } |
603 | 718 |
| 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 |
604 LayerAnimationElement::~LayerAnimationElement() { | 730 LayerAnimationElement::~LayerAnimationElement() { |
605 } | 731 } |
606 | 732 |
607 void LayerAnimationElement::Start(LayerAnimationDelegate* delegate, | 733 void LayerAnimationElement::Start(LayerAnimationDelegate* delegate, |
608 int animation_group_id) { | 734 int animation_group_id) { |
609 DCHECK(requested_start_time_ != base::TimeTicks()); | 735 DCHECK(requested_start_time_ != base::TimeTicks()); |
610 DCHECK(first_frame_); | 736 DCHECK(first_frame_); |
611 animation_group_id_ = animation_group_id; | 737 animation_group_id_ = animation_group_id; |
612 last_progressed_fraction_ = 0.0; | 738 last_progressed_fraction_ = 0.0; |
613 OnStart(delegate); | 739 OnStart(delegate); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 } | 848 } |
723 | 849 |
724 // static | 850 // static |
725 LayerAnimationElement* LayerAnimationElement::CreateTransformElement( | 851 LayerAnimationElement* LayerAnimationElement::CreateTransformElement( |
726 const gfx::Transform& transform, | 852 const gfx::Transform& transform, |
727 base::TimeDelta duration) { | 853 base::TimeDelta duration) { |
728 return new ThreadedTransformTransition(transform, duration); | 854 return new ThreadedTransformTransition(transform, duration); |
729 } | 855 } |
730 | 856 |
731 // static | 857 // 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 |
732 LayerAnimationElement* | 865 LayerAnimationElement* |
733 LayerAnimationElement::CreateInterpolatedTransformElement( | 866 LayerAnimationElement::CreateInterpolatedTransformElement( |
734 InterpolatedTransform* interpolated_transform, | 867 InterpolatedTransform* interpolated_transform, |
735 base::TimeDelta duration) { | 868 base::TimeDelta duration) { |
736 return new InterpolatedTransformTransition(interpolated_transform, duration); | 869 return new InterpolatedTransformTransition(interpolated_transform, duration); |
737 } | 870 } |
738 | 871 |
739 // static | 872 // static |
740 LayerAnimationElement* LayerAnimationElement::CreateBoundsElement( | 873 LayerAnimationElement* LayerAnimationElement::CreateBoundsElement( |
741 const gfx::Rect& bounds, | 874 const gfx::Rect& bounds, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 } | 912 } |
780 | 913 |
781 // static | 914 // static |
782 LayerAnimationElement* LayerAnimationElement::CreateColorElement( | 915 LayerAnimationElement* LayerAnimationElement::CreateColorElement( |
783 SkColor color, | 916 SkColor color, |
784 base::TimeDelta duration) { | 917 base::TimeDelta duration) { |
785 return new ColorTransition(color, duration); | 918 return new ColorTransition(color, duration); |
786 } | 919 } |
787 | 920 |
788 } // namespace ui | 921 } // namespace ui |
OLD | NEW |