From e2fed92523da11098b5c510bfdaeacb61cf6c9e5 Mon Sep 17 00:00:00 2001 From: loyso Date: Tue, 8 Mar 2016 20:41:55 -0800 Subject: UI Compositor: Erase old CC animation system (continued) Basically, specialize all the code as if animation_player_ is always created. Previous episode: https://codereview.chromium.org/1749573002/ BUG=575041 Review URL: https://codereview.chromium.org/1777773002 Cr-Commit-Position: refs/heads/master@{#380066} --- ui/compositor/layer_animator.cc | 83 ++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 50 deletions(-) diff --git a/ui/compositor/layer_animator.cc b/ui/compositor/layer_animator.cc index 20d268e..7b49485 100644 --- a/ui/compositor/layer_animator.cc +++ b/ui/compositor/layer_animator.cc @@ -68,7 +68,7 @@ LayerAnimator::~LayerAnimator() { } ClearAnimationsInternal(); delegate_ = NULL; - DCHECK(!animation_player_ || !animation_player_->animation_timeline()); + DCHECK(!animation_player_->animation_timeline()); } // static @@ -141,67 +141,55 @@ void LayerAnimator::SwitchToLayer(scoped_refptr new_layer) { // Release LAC state for old layer. animation_controller_state_ = nullptr; - 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); - } + if (delegate_) + DetachLayerFromAnimationPlayer(); + if (new_layer) + AttachLayerToAnimationPlayer(new_layer->id()); } void LayerAnimator::SetCompositor(Compositor* compositor) { DCHECK(compositor); - if (animation_player_) { - cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); - DCHECK(timeline); - - DCHECK(delegate_->GetCcLayer()); - - // Register LAC so ElementAnimations picks it up via - // AnimationRegistrar::GetAnimationControllerForId. - if (animation_controller_state_) { - DCHECK_EQ(animation_controller_state_->id(), - delegate_->GetCcLayer()->id()); - timeline->animation_host() - ->animation_registrar() - ->RegisterAnimationController(animation_controller_state_.get()); - } - timeline->AttachPlayer(animation_player_); + cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); + DCHECK(timeline); - AttachLayerToAnimationPlayer(delegate_->GetCcLayer()->id()); + DCHECK(delegate_->GetCcLayer()); - // Release LAC (it is referenced in ElementAnimations). - animation_controller_state_ = nullptr; + // Register LAC so ElementAnimations picks it up via + // AnimationRegistrar::GetAnimationControllerForId. + if (animation_controller_state_) { + DCHECK_EQ(animation_controller_state_->id(), + delegate_->GetCcLayer()->id()); + timeline->animation_host() + ->animation_registrar() + ->RegisterAnimationController(animation_controller_state_.get()); } + + timeline->AttachPlayer(animation_player_); + + AttachLayerToAnimationPlayer(delegate_->GetCcLayer()->id()); + + // Release LAC (it is referenced in ElementAnimations). + animation_controller_state_ = nullptr; } void LayerAnimator::ResetCompositor(Compositor* compositor) { DCHECK(compositor); - if (animation_player_) { - // Store a reference to LAC if any so it may be picked up in SetCompositor. - if (animation_player_->element_animations()) { - animation_controller_state_ = - animation_player_->element_animations()->layer_animation_controller(); - } - DetachLayerFromAnimationPlayer(); - - cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); - DCHECK(timeline); - timeline->DetachPlayer(animation_player_); + // Store a reference to LAC if any so it may be picked up in SetCompositor. + if (animation_player_->element_animations()) { + animation_controller_state_ = + animation_player_->element_animations()->layer_animation_controller(); } + + 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 @@ -215,8 +203,6 @@ void LayerAnimator::AttachLayerToAnimationPlayer(int layer_id) { } void LayerAnimator::DetachLayerFromAnimationPlayer() { - DCHECK(animation_player_); - if (animation_player_->element_animations()) { animation_player_->element_animations() ->layer_animation_controller() @@ -228,17 +214,14 @@ void LayerAnimator::DetachLayerFromAnimationPlayer() { } void LayerAnimator::AddThreadedAnimation(scoped_ptr animation) { - DCHECK(animation_player_); animation_player_->AddAnimation(std::move(animation)); } void LayerAnimator::RemoveThreadedAnimation(int animation_id) { - DCHECK(animation_player_); animation_player_->RemoveAnimation(animation_id); } bool LayerAnimator::HasPendingThreadedAnimationsForTesting() const { - DCHECK(animation_player_); return animation_player_->has_pending_animations_for_testing(); } -- cgit v1.1