Chromium Code Reviews| Index: ui/compositor/layer_animator.cc |
| diff --git a/ui/compositor/layer_animator.cc b/ui/compositor/layer_animator.cc |
| index c298d0dcf87c90eb7d7101a9e7327841b581cb2b..2052782ed6830dd4fb07bf9aa26f55330859dcf1 100644 |
| --- a/ui/compositor/layer_animator.cc |
| +++ b/ui/compositor/layer_animator.cc |
| @@ -8,6 +8,10 @@ |
| #include "base/memory/scoped_ptr.h" |
| #include "base/trace_event/trace_event.h" |
| #include "cc/animation/animation_id_provider.h" |
| +#include "cc/animation/animation_player.h" |
| +#include "cc/animation/animation_timeline.h" |
| +#include "cc/animation/element_animations.h" |
| +#include "cc/layers/layer_settings.h" |
| #include "cc/output/begin_frame_args.h" |
| #include "ui/compositor/compositor.h" |
| #include "ui/compositor/layer.h" |
| @@ -47,6 +51,9 @@ LayerAnimator::LayerAnimator(base::TimeDelta transition_duration) |
| is_started_(false), |
| disable_timer_for_test_(false), |
| adding_animations_(false) { |
| + 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.
|
| + animation_player_ = |
| + cc::AnimationPlayer::Create(cc::AnimationIdProvider::NextPlayerId()); |
| } |
| LayerAnimator::~LayerAnimator() { |
| @@ -110,12 +117,12 @@ base::TimeDelta LayerAnimator::GetTransitionDuration() const { |
| } |
| void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) { |
| - SwitchToLayer(delegate ? delegate->GetCcLayer() : nullptr); |
| if (delegate_ && is_started_) { |
| LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); |
| if (collection) |
| collection->StopAnimator(this); |
| } |
| + SwitchToLayer(delegate ? delegate->GetCcLayer() : nullptr); |
|
loyso (OOO)
2015/12/17 05:53:53
I'll move this fix to the base "depends on" CL.
|
| delegate_ = delegate; |
| if (delegate_ && is_started_) { |
| LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); |
| @@ -126,11 +133,78 @@ void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) { |
| void LayerAnimator::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { |
| if (delegate_) { |
| + if (animation_player_) |
| + DetachLayerFromAnimationPlayer(); |
| + else |
| + delegate_->GetCcLayer()->RemoveLayerAnimationEventObserver(this); |
| + } |
| + if (new_layer) { |
| + if (animation_player_) |
| + AttachLayerToAnimationPlayer(new_layer->id()); |
| + else |
| + new_layer->AddLayerAnimationEventObserver(this); |
| + } |
| +} |
| + |
| +void LayerAnimator::SetCompositor(Compositor* compositor) { |
| + DCHECK(compositor); |
| + if (animation_player_) { |
| + cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); |
| + DCHECK(timeline); |
| + timeline->AttachPlayer(animation_player_); |
| + |
| DCHECK(delegate_->GetCcLayer()); |
| - delegate_->GetCcLayer()->RemoveLayerAnimationEventObserver(this); |
| + AttachLayerToAnimationPlayer(delegate_->GetCcLayer()->id()); |
| + } |
| +} |
| + |
| +void LayerAnimator::ResetCompositor(Compositor* compositor) { |
| + DCHECK(compositor); |
| + if (animation_player_) { |
| + DetachLayerFromAnimationPlayer(); |
| + |
| + cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); |
| + DCHECK(timeline); |
| + timeline->DetachPlayer(animation_player_); |
| + } |
| +} |
| + |
| +void LayerAnimator::AttachLayerToAnimationPlayer(int layer_id) { |
| + DCHECK(animation_player_); |
| + |
| + if (!animation_player_->layer_id()) |
| + animation_player_->AttachLayer(layer_id); |
| + else |
| + DCHECK_EQ(animation_player_->layer_id(), layer_id); |
| + |
| + if (animation_player_->element_animations()) { |
| + animation_player_->element_animations() |
| + ->layer_animation_controller() |
| + ->AddEventObserver(this); |
| + } |
| +} |
| + |
| +void LayerAnimator::DetachLayerFromAnimationPlayer() { |
| + DCHECK(animation_player_); |
| + |
| + if (animation_player_->element_animations()) { |
| + animation_player_->element_animations() |
| + ->layer_animation_controller() |
| + ->RemoveEventObserver(this); |
| } |
| - if (new_layer) |
| - new_layer->AddLayerAnimationEventObserver(this); |
| + |
| + if (animation_player_->layer_id()) |
| + animation_player_->DetachLayer(); |
| +} |
| + |
| +void LayerAnimator::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) { |
| + DCHECK(animation_player_); |
| + animation_player_->AddAnimation(std::move(animation)); |
| +} |
| + |
| +void LayerAnimator::RemoveThreadedAnimation(int animation_id) { |
| + DCHECK(animation_player_); |
| + animation_player_->RemoveAnimation(animation_id); |
| } |
| void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) { |