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_animator.h" | 5 #include "ui/compositor/layer_animator.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include <memory> |
| 10 |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
12 #include "cc/animation/animation_events.h" | 13 #include "cc/animation/animation_events.h" |
13 #include "cc/animation/animation_host.h" | 14 #include "cc/animation/animation_host.h" |
14 #include "cc/animation/animation_id_provider.h" | 15 #include "cc/animation/animation_id_provider.h" |
15 #include "cc/animation/animation_player.h" | 16 #include "cc/animation/animation_player.h" |
16 #include "cc/animation/animation_registrar.h" | 17 #include "cc/animation/animation_registrar.h" |
17 #include "cc/animation/animation_timeline.h" | 18 #include "cc/animation/animation_timeline.h" |
18 #include "cc/animation/element_animations.h" | 19 #include "cc/animation/element_animations.h" |
19 #include "cc/animation/layer_animation_controller.h" | 20 #include "cc/animation/layer_animation_controller.h" |
20 #include "cc/output/begin_frame_args.h" | 21 #include "cc/output/begin_frame_args.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 return new LayerAnimator( | 81 return new LayerAnimator( |
81 base::TimeDelta::FromMilliseconds(kDefaultTransitionDurationMs)); | 82 base::TimeDelta::FromMilliseconds(kDefaultTransitionDurationMs)); |
82 } | 83 } |
83 | 84 |
84 // This macro provides the implementation for the setter and getter (well, | 85 // This macro provides the implementation for the setter and getter (well, |
85 // the getter of the target value) for an animated property. For example, | 86 // the getter of the target value) for an animated property. For example, |
86 // it is used for the implementations of SetTransform and GetTargetTransform. | 87 // it is used for the implementations of SetTransform and GetTargetTransform. |
87 // It is worth noting that SetFoo avoids invoking the usual animation machinery | 88 // It is worth noting that SetFoo avoids invoking the usual animation machinery |
88 // if the transition duration is zero -- in this case we just set the property | 89 // if the transition duration is zero -- in this case we just set the property |
89 // on the layer animation delegate immediately. | 90 // on the layer animation delegate immediately. |
90 #define ANIMATED_PROPERTY(type, property, name, member_type, member) \ | 91 #define ANIMATED_PROPERTY(type, property, name, member_type, member) \ |
91 void LayerAnimator::Set##name(type value) { \ | 92 void LayerAnimator::Set##name(type value) { \ |
92 base::TimeDelta duration = GetTransitionDuration(); \ | 93 base::TimeDelta duration = GetTransitionDuration(); \ |
93 if (duration == base::TimeDelta() && delegate() && \ | 94 if (duration == base::TimeDelta() && delegate() && \ |
94 (preemption_strategy_ != ENQUEUE_NEW_ANIMATION)) { \ | 95 (preemption_strategy_ != ENQUEUE_NEW_ANIMATION)) { \ |
95 StopAnimatingProperty(LayerAnimationElement::property); \ | 96 StopAnimatingProperty(LayerAnimationElement::property); \ |
96 delegate()->Set##name##FromAnimation(value); \ | 97 delegate()->Set##name##FromAnimation(value); \ |
97 return; \ | 98 return; \ |
98 } \ | 99 } \ |
99 scoped_ptr<LayerAnimationElement> element( \ | 100 std::unique_ptr<LayerAnimationElement> element( \ |
100 LayerAnimationElement::Create##name##Element(value, duration)); \ | 101 LayerAnimationElement::Create##name##Element(value, duration)); \ |
101 element->set_tween_type(tween_type_); \ | 102 element->set_tween_type(tween_type_); \ |
102 StartAnimation(new LayerAnimationSequence(element.release())); \ | 103 StartAnimation(new LayerAnimationSequence(element.release())); \ |
103 } \ | 104 } \ |
104 \ | 105 \ |
105 member_type LayerAnimator::GetTarget##name() const { \ | 106 member_type LayerAnimator::GetTarget##name() const { \ |
106 LayerAnimationElement::TargetValue target(delegate()); \ | 107 LayerAnimationElement::TargetValue target(delegate()); \ |
107 GetTargetValue(&target); \ | 108 GetTargetValue(&target); \ |
108 return target.member; \ | 109 return target.member; \ |
109 } | 110 } |
110 | 111 |
111 ANIMATED_PROPERTY( | 112 ANIMATED_PROPERTY( |
112 const gfx::Transform&, TRANSFORM, Transform, gfx::Transform, transform); | 113 const gfx::Transform&, TRANSFORM, Transform, gfx::Transform, transform); |
113 ANIMATED_PROPERTY(const gfx::Rect&, BOUNDS, Bounds, gfx::Rect, bounds); | 114 ANIMATED_PROPERTY(const gfx::Rect&, BOUNDS, Bounds, gfx::Rect, bounds); |
114 ANIMATED_PROPERTY(float, OPACITY, Opacity, float, opacity); | 115 ANIMATED_PROPERTY(float, OPACITY, Opacity, float, opacity); |
115 ANIMATED_PROPERTY(bool, VISIBILITY, Visibility, bool, visibility); | 116 ANIMATED_PROPERTY(bool, VISIBILITY, Visibility, bool, visibility); |
116 ANIMATED_PROPERTY(float, BRIGHTNESS, Brightness, float, brightness); | 117 ANIMATED_PROPERTY(float, BRIGHTNESS, Brightness, float, brightness); |
117 ANIMATED_PROPERTY(float, GRAYSCALE, Grayscale, float, grayscale); | 118 ANIMATED_PROPERTY(float, GRAYSCALE, Grayscale, float, grayscale); |
118 ANIMATED_PROPERTY(SkColor, COLOR, Color, SkColor, color); | 119 ANIMATED_PROPERTY(SkColor, COLOR, Color, SkColor, color); |
119 | 120 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 if (animation_player_->element_animations()) { | 206 if (animation_player_->element_animations()) { |
206 animation_player_->element_animations() | 207 animation_player_->element_animations() |
207 ->layer_animation_controller() | 208 ->layer_animation_controller() |
208 ->RemoveEventObserver(this); | 209 ->RemoveEventObserver(this); |
209 } | 210 } |
210 | 211 |
211 if (animation_player_->layer_id()) | 212 if (animation_player_->layer_id()) |
212 animation_player_->DetachLayer(); | 213 animation_player_->DetachLayer(); |
213 } | 214 } |
214 | 215 |
215 void LayerAnimator::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) { | 216 void LayerAnimator::AddThreadedAnimation( |
| 217 std::unique_ptr<cc::Animation> animation) { |
216 animation_player_->AddAnimation(std::move(animation)); | 218 animation_player_->AddAnimation(std::move(animation)); |
217 } | 219 } |
218 | 220 |
219 void LayerAnimator::RemoveThreadedAnimation(int animation_id) { | 221 void LayerAnimator::RemoveThreadedAnimation(int animation_id) { |
220 animation_player_->RemoveAnimation(animation_id); | 222 animation_player_->RemoveAnimation(animation_id); |
221 } | 223 } |
222 | 224 |
223 bool LayerAnimator::HasPendingThreadedAnimationsForTesting() const { | 225 bool LayerAnimator::HasPendingThreadedAnimationsForTesting() const { |
224 return animation_player_->has_pending_animations_for_testing(); | 226 return animation_player_->has_pending_animations_for_testing(); |
225 } | 227 } |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 (*queue_iter)->Start(delegate()); | 611 (*queue_iter)->Start(delegate()); |
610 } | 612 } |
611 } | 613 } |
612 } | 614 } |
613 return to_return.release(); | 615 return to_return.release(); |
614 } | 616 } |
615 | 617 |
616 void LayerAnimator::FinishAnimation( | 618 void LayerAnimator::FinishAnimation( |
617 LayerAnimationSequence* sequence, bool abort) { | 619 LayerAnimationSequence* sequence, bool abort) { |
618 scoped_refptr<LayerAnimator> retain(this); | 620 scoped_refptr<LayerAnimator> retain(this); |
619 scoped_ptr<LayerAnimationSequence> removed(RemoveAnimation(sequence)); | 621 std::unique_ptr<LayerAnimationSequence> removed(RemoveAnimation(sequence)); |
620 if (abort) | 622 if (abort) |
621 sequence->Abort(delegate()); | 623 sequence->Abort(delegate()); |
622 else | 624 else |
623 ProgressAnimationToEnd(sequence); | 625 ProgressAnimationToEnd(sequence); |
624 if (!delegate()) | 626 if (!delegate()) |
625 return; | 627 return; |
626 ProcessQueue(); | 628 ProcessQueue(); |
627 UpdateAnimationState(); | 629 UpdateAnimationState(); |
628 } | 630 } |
629 | 631 |
630 void LayerAnimator::FinishAnyAnimationWithZeroDuration() { | 632 void LayerAnimator::FinishAnyAnimationWithZeroDuration() { |
631 scoped_refptr<LayerAnimator> retain(this); | 633 scoped_refptr<LayerAnimator> retain(this); |
632 // Special case: if we've started a 0 duration animation, just finish it now | 634 // Special case: if we've started a 0 duration animation, just finish it now |
633 // and get rid of it. We need to make a copy because Progress may indirectly | 635 // and get rid of it. We need to make a copy because Progress may indirectly |
634 // cause new animations to start running. | 636 // cause new animations to start running. |
635 RunningAnimations running_animations_copy = running_animations_; | 637 RunningAnimations running_animations_copy = running_animations_; |
636 for (size_t i = 0; i < running_animations_copy.size(); ++i) { | 638 for (size_t i = 0; i < running_animations_copy.size(); ++i) { |
637 if (!SAFE_INVOKE_BOOL(HasAnimation, running_animations_copy[i])) | 639 if (!SAFE_INVOKE_BOOL(HasAnimation, running_animations_copy[i])) |
638 continue; | 640 continue; |
639 | 641 |
640 if (running_animations_copy[i].sequence()->IsFinished( | 642 if (running_animations_copy[i].sequence()->IsFinished( |
641 running_animations_copy[i].sequence()->start_time())) { | 643 running_animations_copy[i].sequence()->start_time())) { |
642 SAFE_INVOKE_VOID(ProgressAnimationToEnd, running_animations_copy[i]); | 644 SAFE_INVOKE_VOID(ProgressAnimationToEnd, running_animations_copy[i]); |
643 scoped_ptr<LayerAnimationSequence> removed( | 645 std::unique_ptr<LayerAnimationSequence> removed( |
644 SAFE_INVOKE_PTR(RemoveAnimation, running_animations_copy[i])); | 646 SAFE_INVOKE_PTR(RemoveAnimation, running_animations_copy[i])); |
645 } | 647 } |
646 } | 648 } |
647 ProcessQueue(); | 649 ProcessQueue(); |
648 UpdateAnimationState(); | 650 UpdateAnimationState(); |
649 } | 651 } |
650 | 652 |
651 void LayerAnimator::ClearAnimations() { | 653 void LayerAnimator::ClearAnimations() { |
652 scoped_refptr<LayerAnimator> retain(this); | 654 scoped_refptr<LayerAnimator> retain(this); |
653 ClearAnimationsInternal(); | 655 ClearAnimationsInternal(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 // progress them to the end and remove them. Note, Aborting or Progressing | 687 // progress them to the end and remove them. Note, Aborting or Progressing |
686 // animations may affect the collection of running animations, so we need to | 688 // animations may affect the collection of running animations, so we need to |
687 // operate on a copy. | 689 // operate on a copy. |
688 RunningAnimations running_animations_copy = running_animations_; | 690 RunningAnimations running_animations_copy = running_animations_; |
689 for (size_t i = 0; i < running_animations_copy.size(); ++i) { | 691 for (size_t i = 0; i < running_animations_copy.size(); ++i) { |
690 if (!SAFE_INVOKE_BOOL(HasAnimation, running_animations_copy[i])) | 692 if (!SAFE_INVOKE_BOOL(HasAnimation, running_animations_copy[i])) |
691 continue; | 693 continue; |
692 | 694 |
693 if (running_animations_copy[i].sequence()->HasConflictingProperty( | 695 if (running_animations_copy[i].sequence()->HasConflictingProperty( |
694 sequence->properties())) { | 696 sequence->properties())) { |
695 scoped_ptr<LayerAnimationSequence> removed( | 697 std::unique_ptr<LayerAnimationSequence> removed( |
696 SAFE_INVOKE_PTR(RemoveAnimation, running_animations_copy[i])); | 698 SAFE_INVOKE_PTR(RemoveAnimation, running_animations_copy[i])); |
697 if (abort) | 699 if (abort) |
698 running_animations_copy[i].sequence()->Abort(delegate()); | 700 running_animations_copy[i].sequence()->Abort(delegate()); |
699 else | 701 else |
700 SAFE_INVOKE_VOID(ProgressAnimationToEnd, running_animations_copy[i]); | 702 SAFE_INVOKE_VOID(ProgressAnimationToEnd, running_animations_copy[i]); |
701 } | 703 } |
702 } | 704 } |
703 | 705 |
704 // Same for the queued animations that haven't been started. Again, we'll | 706 // Same for the queued animations that haven't been started. Again, we'll |
705 // need to operate on a copy. | 707 // need to operate on a copy. |
706 std::vector<base::WeakPtr<LayerAnimationSequence> > sequences; | 708 std::vector<base::WeakPtr<LayerAnimationSequence> > sequences; |
707 for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); | 709 for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); |
708 queue_iter != animation_queue_.end(); ++queue_iter) | 710 queue_iter != animation_queue_.end(); ++queue_iter) |
709 sequences.push_back((*queue_iter)->AsWeakPtr()); | 711 sequences.push_back((*queue_iter)->AsWeakPtr()); |
710 | 712 |
711 for (size_t i = 0; i < sequences.size(); ++i) { | 713 for (size_t i = 0; i < sequences.size(); ++i) { |
712 if (!sequences[i].get() || !HasAnimation(sequences[i].get())) | 714 if (!sequences[i].get() || !HasAnimation(sequences[i].get())) |
713 continue; | 715 continue; |
714 | 716 |
715 if (sequences[i]->HasConflictingProperty(sequence->properties())) { | 717 if (sequences[i]->HasConflictingProperty(sequence->properties())) { |
716 scoped_ptr<LayerAnimationSequence> removed( | 718 std::unique_ptr<LayerAnimationSequence> removed( |
717 RemoveAnimation(sequences[i].get())); | 719 RemoveAnimation(sequences[i].get())); |
718 if (abort) | 720 if (abort) |
719 sequences[i]->Abort(delegate()); | 721 sequences[i]->Abort(delegate()); |
720 else | 722 else |
721 ProgressAnimationToEnd(sequences[i].get()); | 723 ProgressAnimationToEnd(sequences[i].get()); |
722 } | 724 } |
723 } | 725 } |
724 } | 726 } |
725 | 727 |
726 void LayerAnimator::ImmediatelySetNewTarget(LayerAnimationSequence* sequence) { | 728 void LayerAnimator::ImmediatelySetNewTarget(LayerAnimationSequence* sequence) { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 void LayerAnimator::ClearAnimationsInternal() { | 925 void LayerAnimator::ClearAnimationsInternal() { |
924 PurgeDeletedAnimations(); | 926 PurgeDeletedAnimations(); |
925 | 927 |
926 // Abort should never affect the set of running animations, but just in case | 928 // Abort should never affect the set of running animations, but just in case |
927 // clients are badly behaved, we will use a copy of the running animations. | 929 // clients are badly behaved, we will use a copy of the running animations. |
928 RunningAnimations running_animations_copy = running_animations_; | 930 RunningAnimations running_animations_copy = running_animations_; |
929 for (size_t i = 0; i < running_animations_copy.size(); ++i) { | 931 for (size_t i = 0; i < running_animations_copy.size(); ++i) { |
930 if (!SAFE_INVOKE_BOOL(HasAnimation, running_animations_copy[i])) | 932 if (!SAFE_INVOKE_BOOL(HasAnimation, running_animations_copy[i])) |
931 continue; | 933 continue; |
932 | 934 |
933 scoped_ptr<LayerAnimationSequence> removed( | 935 std::unique_ptr<LayerAnimationSequence> removed( |
934 RemoveAnimation(running_animations_copy[i].sequence())); | 936 RemoveAnimation(running_animations_copy[i].sequence())); |
935 if (removed.get()) | 937 if (removed.get()) |
936 removed->Abort(delegate()); | 938 removed->Abort(delegate()); |
937 } | 939 } |
938 // This *should* have cleared the list of running animations. | 940 // This *should* have cleared the list of running animations. |
939 DCHECK(running_animations_.empty()); | 941 DCHECK(running_animations_.empty()); |
940 running_animations_.clear(); | 942 running_animations_.clear(); |
941 animation_queue_.clear(); | 943 animation_queue_.clear(); |
942 UpdateAnimationState(); | 944 UpdateAnimationState(); |
943 } | 945 } |
(...skipping 19 matching lines...) Expand all Loading... |
963 const base::WeakPtr<LayerAnimationSequence>& sequence) | 965 const base::WeakPtr<LayerAnimationSequence>& sequence) |
964 : sequence_(sequence) { | 966 : sequence_(sequence) { |
965 } | 967 } |
966 | 968 |
967 LayerAnimator::RunningAnimation::RunningAnimation( | 969 LayerAnimator::RunningAnimation::RunningAnimation( |
968 const RunningAnimation& other) = default; | 970 const RunningAnimation& other) = default; |
969 | 971 |
970 LayerAnimator::RunningAnimation::~RunningAnimation() { } | 972 LayerAnimator::RunningAnimation::~RunningAnimation() { } |
971 | 973 |
972 } // namespace ui | 974 } // namespace ui |
OLD | NEW |