| 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> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 13 #include "cc/animation/animation_host.h" | 13 #include "cc/animation/animation_host.h" |
| 14 #include "cc/animation/animation_id_provider.h" | 14 #include "cc/animation/animation_id_provider.h" |
| 15 #include "cc/animation/animation_player.h" | 15 #include "cc/animation/animation_player.h" |
| 16 #include "cc/animation/animation_timeline.h" | 16 #include "cc/animation/animation_timeline.h" |
| 17 #include "cc/animation/element_animations.h" | 17 #include "cc/animation/element_animations.h" |
| 18 #include "cc/animation/layer_animation_controller.h" | |
| 19 #include "cc/output/begin_frame_args.h" | 18 #include "cc/output/begin_frame_args.h" |
| 20 #include "ui/compositor/compositor.h" | 19 #include "ui/compositor/compositor.h" |
| 21 #include "ui/compositor/layer.h" | 20 #include "ui/compositor/layer.h" |
| 22 #include "ui/compositor/layer_animation_delegate.h" | 21 #include "ui/compositor/layer_animation_delegate.h" |
| 23 #include "ui/compositor/layer_animation_observer.h" | 22 #include "ui/compositor/layer_animation_observer.h" |
| 24 #include "ui/compositor/layer_animation_sequence.h" | 23 #include "ui/compositor/layer_animation_sequence.h" |
| 25 #include "ui/compositor/layer_animator_collection.h" | 24 #include "ui/compositor/layer_animator_collection.h" |
| 26 | 25 |
| 27 #define SAFE_INVOKE_VOID(function, running_anim, ...) \ | 26 #define SAFE_INVOKE_VOID(function, running_anim, ...) \ |
| 28 if (running_anim.is_sequence_alive()) \ | 27 if (running_anim.is_sequence_alive()) \ |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 SwitchToLayer(delegate ? delegate->GetCcLayer() : nullptr); | 128 SwitchToLayer(delegate ? delegate->GetCcLayer() : nullptr); |
| 130 delegate_ = delegate; | 129 delegate_ = delegate; |
| 131 if (delegate_ && is_started_) { | 130 if (delegate_ && is_started_) { |
| 132 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); | 131 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); |
| 133 if (collection) | 132 if (collection) |
| 134 collection->StartAnimator(this); | 133 collection->StartAnimator(this); |
| 135 } | 134 } |
| 136 } | 135 } |
| 137 | 136 |
| 138 void LayerAnimator::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { | 137 void LayerAnimator::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { |
| 139 // Release LAC state for old layer. | 138 // Release ElementAnimations state for old layer. |
| 140 animation_controller_state_ = nullptr; | 139 element_animations_state_ = nullptr; |
| 141 | 140 |
| 142 if (delegate_) | 141 if (delegate_) |
| 143 DetachLayerFromAnimationPlayer(); | 142 DetachLayerFromAnimationPlayer(); |
| 144 if (new_layer) | 143 if (new_layer) |
| 145 AttachLayerToAnimationPlayer(new_layer->id()); | 144 AttachLayerToAnimationPlayer(new_layer->id()); |
| 146 } | 145 } |
| 147 | 146 |
| 148 void LayerAnimator::SetCompositor(Compositor* compositor) { | 147 void LayerAnimator::SetCompositor(Compositor* compositor) { |
| 149 DCHECK(compositor); | 148 DCHECK(compositor); |
| 150 | 149 |
| 151 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); | 150 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); |
| 152 DCHECK(timeline); | 151 DCHECK(timeline); |
| 153 | 152 |
| 154 DCHECK(delegate_->GetCcLayer()); | 153 DCHECK(delegate_->GetCcLayer()); |
| 155 | 154 |
| 156 // Register LAC so ElementAnimations picks it up via | 155 // Register ElementAnimations so it will be picked up by |
| 157 // AnimationRegistrar::GetAnimationControllerForId. | 156 // AnimationHost::RegisterPlayerForLayer via |
| 158 if (animation_controller_state_) { | 157 // AnimationHost::GetElementAnimationsForLayerId. |
| 159 DCHECK_EQ(animation_controller_state_->id(), | 158 if (element_animations_state_) { |
| 159 DCHECK_EQ(element_animations_state_->layer_id(), |
| 160 delegate_->GetCcLayer()->id()); | 160 delegate_->GetCcLayer()->id()); |
| 161 timeline->animation_host() | 161 timeline->animation_host()->RegisterElementAnimations( |
| 162 ->RegisterAnimationController(animation_controller_state_.get()); | 162 element_animations_state_.get()); |
| 163 } | 163 } |
| 164 | 164 |
| 165 timeline->AttachPlayer(animation_player_); | 165 timeline->AttachPlayer(animation_player_); |
| 166 | 166 |
| 167 AttachLayerToAnimationPlayer(delegate_->GetCcLayer()->id()); | 167 AttachLayerToAnimationPlayer(delegate_->GetCcLayer()->id()); |
| 168 | 168 |
| 169 // Release LAC (it is referenced in ElementAnimations). | 169 // Release ElementAnimations state. |
| 170 animation_controller_state_ = nullptr; | 170 element_animations_state_ = nullptr; |
| 171 } | 171 } |
| 172 | 172 |
| 173 void LayerAnimator::ResetCompositor(Compositor* compositor) { | 173 void LayerAnimator::ResetCompositor(Compositor* compositor) { |
| 174 DCHECK(compositor); | 174 DCHECK(compositor); |
| 175 | 175 |
| 176 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); | 176 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); |
| 177 DCHECK(timeline); | 177 DCHECK(timeline); |
| 178 | 178 |
| 179 const int layer_id = animation_player_->layer_id(); | 179 const int layer_id = animation_player_->layer_id(); |
| 180 | 180 |
| 181 // Store a reference to LAC if any so it may be picked up in SetCompositor. | 181 // Store a reference to ElementAnimations (if any) |
| 182 // so it may be picked up in LayerAnimator::SetCompositor. |
| 182 if (layer_id) { | 183 if (layer_id) { |
| 183 animation_controller_state_ = | 184 element_animations_state_ = |
| 184 timeline->animation_host()->GetControllerForLayerId(layer_id); | 185 timeline->animation_host()->GetElementAnimationsForLayerId(layer_id); |
| 185 } | 186 } |
| 186 | 187 |
| 187 DetachLayerFromAnimationPlayer(); | 188 DetachLayerFromAnimationPlayer(); |
| 188 | 189 |
| 189 timeline->DetachPlayer(animation_player_); | 190 timeline->DetachPlayer(animation_player_); |
| 190 } | 191 } |
| 191 | 192 |
| 192 void LayerAnimator::AttachLayerToAnimationPlayer(int layer_id) { | 193 void LayerAnimator::AttachLayerToAnimationPlayer(int layer_id) { |
| 193 if (!animation_player_->layer_id()) | 194 if (!animation_player_->layer_id()) |
| 194 animation_player_->AttachLayer(layer_id); | 195 animation_player_->AttachLayer(layer_id); |
| (...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 const base::WeakPtr<LayerAnimationSequence>& sequence) | 964 const base::WeakPtr<LayerAnimationSequence>& sequence) |
| 964 : sequence_(sequence) { | 965 : sequence_(sequence) { |
| 965 } | 966 } |
| 966 | 967 |
| 967 LayerAnimator::RunningAnimation::RunningAnimation( | 968 LayerAnimator::RunningAnimation::RunningAnimation( |
| 968 const RunningAnimation& other) = default; | 969 const RunningAnimation& other) = default; |
| 969 | 970 |
| 970 LayerAnimator::RunningAnimation::~RunningAnimation() { } | 971 LayerAnimator::RunningAnimation::~RunningAnimation() { } |
| 971 | 972 |
| 972 } // namespace ui | 973 } // namespace ui |
| OLD | NEW |