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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 #include "cc/animation/animation_id_provider.h" | 10 #include "cc/animation/animation_id_provider.h" |
11 #include "cc/animation/animation_player.h" | |
12 #include "cc/animation/animation_timeline.h" | |
13 #include "cc/animation/element_animations.h" | |
14 #include "cc/layers/layer_settings.h" | |
11 #include "cc/output/begin_frame_args.h" | 15 #include "cc/output/begin_frame_args.h" |
12 #include "ui/compositor/compositor.h" | 16 #include "ui/compositor/compositor.h" |
13 #include "ui/compositor/layer.h" | 17 #include "ui/compositor/layer.h" |
14 #include "ui/compositor/layer_animation_delegate.h" | 18 #include "ui/compositor/layer_animation_delegate.h" |
15 #include "ui/compositor/layer_animation_observer.h" | 19 #include "ui/compositor/layer_animation_observer.h" |
16 #include "ui/compositor/layer_animation_sequence.h" | 20 #include "ui/compositor/layer_animation_sequence.h" |
17 #include "ui/compositor/layer_animator_collection.h" | 21 #include "ui/compositor/layer_animator_collection.h" |
18 | 22 |
19 #define SAFE_INVOKE_VOID(function, running_anim, ...) \ | 23 #define SAFE_INVOKE_VOID(function, running_anim, ...) \ |
20 if (running_anim.is_sequence_alive()) \ | 24 if (running_anim.is_sequence_alive()) \ |
(...skipping 19 matching lines...) Expand all Loading... | |
40 | 44 |
41 LayerAnimator::LayerAnimator(base::TimeDelta transition_duration) | 45 LayerAnimator::LayerAnimator(base::TimeDelta transition_duration) |
42 : delegate_(NULL), | 46 : delegate_(NULL), |
43 preemption_strategy_(IMMEDIATELY_SET_NEW_TARGET), | 47 preemption_strategy_(IMMEDIATELY_SET_NEW_TARGET), |
44 is_transition_duration_locked_(false), | 48 is_transition_duration_locked_(false), |
45 transition_duration_(transition_duration), | 49 transition_duration_(transition_duration), |
46 tween_type_(gfx::Tween::LINEAR), | 50 tween_type_(gfx::Tween::LINEAR), |
47 is_started_(false), | 51 is_started_(false), |
48 disable_timer_for_test_(false), | 52 disable_timer_for_test_(false), |
49 adding_animations_(false) { | 53 adding_animations_(false) { |
54 if (Layer::UILayerSettings().use_compositor_animation_timelines) | |
piman
2015/12/17 05:37:28
nit: needs {}
loyso (OOO)
2015/12/17 05:53:53
Done.
| |
55 animation_player_ = | |
56 cc::AnimationPlayer::Create(cc::AnimationIdProvider::NextPlayerId()); | |
50 } | 57 } |
51 | 58 |
52 LayerAnimator::~LayerAnimator() { | 59 LayerAnimator::~LayerAnimator() { |
53 for (size_t i = 0; i < running_animations_.size(); ++i) { | 60 for (size_t i = 0; i < running_animations_.size(); ++i) { |
54 if (running_animations_[i].is_sequence_alive()) | 61 if (running_animations_[i].is_sequence_alive()) |
55 running_animations_[i].sequence()->OnAnimatorDestroyed(); | 62 running_animations_[i].sequence()->OnAnimatorDestroyed(); |
56 } | 63 } |
57 ClearAnimationsInternal(); | 64 ClearAnimationsInternal(); |
58 delegate_ = NULL; | 65 delegate_ = NULL; |
59 } | 66 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 ANIMATED_PROPERTY(bool, VISIBILITY, Visibility, bool, visibility); | 110 ANIMATED_PROPERTY(bool, VISIBILITY, Visibility, bool, visibility); |
104 ANIMATED_PROPERTY(float, BRIGHTNESS, Brightness, float, brightness); | 111 ANIMATED_PROPERTY(float, BRIGHTNESS, Brightness, float, brightness); |
105 ANIMATED_PROPERTY(float, GRAYSCALE, Grayscale, float, grayscale); | 112 ANIMATED_PROPERTY(float, GRAYSCALE, Grayscale, float, grayscale); |
106 ANIMATED_PROPERTY(SkColor, COLOR, Color, SkColor, color); | 113 ANIMATED_PROPERTY(SkColor, COLOR, Color, SkColor, color); |
107 | 114 |
108 base::TimeDelta LayerAnimator::GetTransitionDuration() const { | 115 base::TimeDelta LayerAnimator::GetTransitionDuration() const { |
109 return transition_duration_; | 116 return transition_duration_; |
110 } | 117 } |
111 | 118 |
112 void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) { | 119 void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) { |
113 SwitchToLayer(delegate ? delegate->GetCcLayer() : nullptr); | |
114 if (delegate_ && is_started_) { | 120 if (delegate_ && is_started_) { |
115 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); | 121 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); |
116 if (collection) | 122 if (collection) |
117 collection->StopAnimator(this); | 123 collection->StopAnimator(this); |
118 } | 124 } |
125 SwitchToLayer(delegate ? delegate->GetCcLayer() : nullptr); | |
loyso (OOO)
2015/12/17 05:53:53
I'll move this fix to the base "depends on" CL.
| |
119 delegate_ = delegate; | 126 delegate_ = delegate; |
120 if (delegate_ && is_started_) { | 127 if (delegate_ && is_started_) { |
121 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); | 128 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); |
122 if (collection) | 129 if (collection) |
123 collection->StartAnimator(this); | 130 collection->StartAnimator(this); |
124 } | 131 } |
125 } | 132 } |
126 | 133 |
127 void LayerAnimator::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { | 134 void LayerAnimator::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { |
128 if (delegate_) { | 135 if (delegate_) { |
136 if (animation_player_) | |
137 DetachLayerFromAnimationPlayer(); | |
138 else | |
139 delegate_->GetCcLayer()->RemoveLayerAnimationEventObserver(this); | |
140 } | |
141 if (new_layer) { | |
142 if (animation_player_) | |
143 AttachLayerToAnimationPlayer(new_layer->id()); | |
144 else | |
145 new_layer->AddLayerAnimationEventObserver(this); | |
146 } | |
147 } | |
148 | |
149 void LayerAnimator::SetCompositor(Compositor* compositor) { | |
150 DCHECK(compositor); | |
151 if (animation_player_) { | |
152 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); | |
153 DCHECK(timeline); | |
154 timeline->AttachPlayer(animation_player_); | |
155 | |
129 DCHECK(delegate_->GetCcLayer()); | 156 DCHECK(delegate_->GetCcLayer()); |
130 delegate_->GetCcLayer()->RemoveLayerAnimationEventObserver(this); | 157 AttachLayerToAnimationPlayer(delegate_->GetCcLayer()->id()); |
131 } | 158 } |
132 if (new_layer) | 159 } |
133 new_layer->AddLayerAnimationEventObserver(this); | 160 |
161 void LayerAnimator::ResetCompositor(Compositor* compositor) { | |
162 DCHECK(compositor); | |
163 if (animation_player_) { | |
164 DetachLayerFromAnimationPlayer(); | |
165 | |
166 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); | |
167 DCHECK(timeline); | |
168 timeline->DetachPlayer(animation_player_); | |
169 } | |
170 } | |
171 | |
172 void LayerAnimator::AttachLayerToAnimationPlayer(int layer_id) { | |
173 DCHECK(animation_player_); | |
174 | |
175 if (!animation_player_->layer_id()) | |
176 animation_player_->AttachLayer(layer_id); | |
177 else | |
178 DCHECK_EQ(animation_player_->layer_id(), layer_id); | |
179 | |
180 if (animation_player_->element_animations()) { | |
181 animation_player_->element_animations() | |
182 ->layer_animation_controller() | |
183 ->AddEventObserver(this); | |
184 } | |
185 } | |
186 | |
187 void LayerAnimator::DetachLayerFromAnimationPlayer() { | |
188 DCHECK(animation_player_); | |
189 | |
190 if (animation_player_->element_animations()) { | |
191 animation_player_->element_animations() | |
192 ->layer_animation_controller() | |
193 ->RemoveEventObserver(this); | |
194 } | |
195 | |
196 if (animation_player_->layer_id()) | |
197 animation_player_->DetachLayer(); | |
198 } | |
199 | |
200 void LayerAnimator::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) { | |
201 DCHECK(animation_player_); | |
202 animation_player_->AddAnimation(std::move(animation)); | |
203 } | |
204 | |
205 void LayerAnimator::RemoveThreadedAnimation(int animation_id) { | |
206 DCHECK(animation_player_); | |
207 animation_player_->RemoveAnimation(animation_id); | |
134 } | 208 } |
135 | 209 |
136 void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) { | 210 void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) { |
137 scoped_refptr<LayerAnimator> retain(this); | 211 scoped_refptr<LayerAnimator> retain(this); |
138 OnScheduled(animation); | 212 OnScheduled(animation); |
139 if (!StartSequenceImmediately(animation)) { | 213 if (!StartSequenceImmediately(animation)) { |
140 // Attempt to preempt a running animation. | 214 // Attempt to preempt a running animation. |
141 switch (preemption_strategy_) { | 215 switch (preemption_strategy_) { |
142 case IMMEDIATELY_SET_NEW_TARGET: | 216 case IMMEDIATELY_SET_NEW_TARGET: |
143 ImmediatelySetNewTarget(animation); | 217 ImmediatelySetNewTarget(animation); |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
865 } | 939 } |
866 | 940 |
867 LayerAnimator::RunningAnimation::RunningAnimation( | 941 LayerAnimator::RunningAnimation::RunningAnimation( |
868 const base::WeakPtr<LayerAnimationSequence>& sequence) | 942 const base::WeakPtr<LayerAnimationSequence>& sequence) |
869 : sequence_(sequence) { | 943 : sequence_(sequence) { |
870 } | 944 } |
871 | 945 |
872 LayerAnimator::RunningAnimation::~RunningAnimation() { } | 946 LayerAnimator::RunningAnimation::~RunningAnimation() { } |
873 | 947 |
874 } // namespace ui | 948 } // namespace ui |
OLD | NEW |