| 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 "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 cc::AnimationPlayer::Create(cc::AnimationIdProvider::NextPlayerId()); | 61 cc::AnimationPlayer::Create(cc::AnimationIdProvider::NextPlayerId()); |
| 62 } | 62 } |
| 63 | 63 |
| 64 LayerAnimator::~LayerAnimator() { | 64 LayerAnimator::~LayerAnimator() { |
| 65 for (size_t i = 0; i < running_animations_.size(); ++i) { | 65 for (size_t i = 0; i < running_animations_.size(); ++i) { |
| 66 if (running_animations_[i].is_sequence_alive()) | 66 if (running_animations_[i].is_sequence_alive()) |
| 67 running_animations_[i].sequence()->OnAnimatorDestroyed(); | 67 running_animations_[i].sequence()->OnAnimatorDestroyed(); |
| 68 } | 68 } |
| 69 ClearAnimationsInternal(); | 69 ClearAnimationsInternal(); |
| 70 delegate_ = NULL; | 70 delegate_ = NULL; |
| 71 DCHECK(!animation_player_ || !animation_player_->animation_timeline()); | 71 DCHECK(!animation_player_->animation_timeline()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // static | 74 // static |
| 75 LayerAnimator* LayerAnimator::CreateDefaultAnimator() { | 75 LayerAnimator* LayerAnimator::CreateDefaultAnimator() { |
| 76 return new LayerAnimator(base::TimeDelta::FromMilliseconds(0)); | 76 return new LayerAnimator(base::TimeDelta::FromMilliseconds(0)); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // static | 79 // static |
| 80 LayerAnimator* LayerAnimator::CreateImplicitAnimator() { | 80 LayerAnimator* LayerAnimator::CreateImplicitAnimator() { |
| 81 return new LayerAnimator( | 81 return new LayerAnimator( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); | 134 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); |
| 135 if (collection) | 135 if (collection) |
| 136 collection->StartAnimator(this); | 136 collection->StartAnimator(this); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 void LayerAnimator::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { | 140 void LayerAnimator::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { |
| 141 // Release LAC state for old layer. | 141 // Release LAC state for old layer. |
| 142 animation_controller_state_ = nullptr; | 142 animation_controller_state_ = nullptr; |
| 143 | 143 |
| 144 if (delegate_) { | 144 if (delegate_) |
| 145 if (animation_player_) | 145 DetachLayerFromAnimationPlayer(); |
| 146 DetachLayerFromAnimationPlayer(); | 146 if (new_layer) |
| 147 else | 147 AttachLayerToAnimationPlayer(new_layer->id()); |
| 148 delegate_->GetCcLayer()->RemoveLayerAnimationEventObserver(this); | |
| 149 } | |
| 150 if (new_layer) { | |
| 151 if (animation_player_) | |
| 152 AttachLayerToAnimationPlayer(new_layer->id()); | |
| 153 else | |
| 154 new_layer->AddLayerAnimationEventObserver(this); | |
| 155 } | |
| 156 } | 148 } |
| 157 | 149 |
| 158 void LayerAnimator::SetCompositor(Compositor* compositor) { | 150 void LayerAnimator::SetCompositor(Compositor* compositor) { |
| 159 DCHECK(compositor); | 151 DCHECK(compositor); |
| 160 if (animation_player_) { | |
| 161 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); | |
| 162 DCHECK(timeline); | |
| 163 | 152 |
| 164 DCHECK(delegate_->GetCcLayer()); | 153 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); |
| 154 DCHECK(timeline); |
| 165 | 155 |
| 166 // Register LAC so ElementAnimations picks it up via | 156 DCHECK(delegate_->GetCcLayer()); |
| 167 // AnimationRegistrar::GetAnimationControllerForId. | |
| 168 if (animation_controller_state_) { | |
| 169 DCHECK_EQ(animation_controller_state_->id(), | |
| 170 delegate_->GetCcLayer()->id()); | |
| 171 timeline->animation_host() | |
| 172 ->animation_registrar() | |
| 173 ->RegisterAnimationController(animation_controller_state_.get()); | |
| 174 } | |
| 175 | 157 |
| 176 timeline->AttachPlayer(animation_player_); | 158 // Register LAC so ElementAnimations picks it up via |
| 159 // AnimationRegistrar::GetAnimationControllerForId. |
| 160 if (animation_controller_state_) { |
| 161 DCHECK_EQ(animation_controller_state_->id(), |
| 162 delegate_->GetCcLayer()->id()); |
| 163 timeline->animation_host() |
| 164 ->animation_registrar() |
| 165 ->RegisterAnimationController(animation_controller_state_.get()); |
| 166 } |
| 177 | 167 |
| 178 AttachLayerToAnimationPlayer(delegate_->GetCcLayer()->id()); | 168 timeline->AttachPlayer(animation_player_); |
| 179 | 169 |
| 180 // Release LAC (it is referenced in ElementAnimations). | 170 AttachLayerToAnimationPlayer(delegate_->GetCcLayer()->id()); |
| 181 animation_controller_state_ = nullptr; | 171 |
| 182 } | 172 // Release LAC (it is referenced in ElementAnimations). |
| 173 animation_controller_state_ = nullptr; |
| 183 } | 174 } |
| 184 | 175 |
| 185 void LayerAnimator::ResetCompositor(Compositor* compositor) { | 176 void LayerAnimator::ResetCompositor(Compositor* compositor) { |
| 186 DCHECK(compositor); | 177 DCHECK(compositor); |
| 187 if (animation_player_) { | |
| 188 // Store a reference to LAC if any so it may be picked up in SetCompositor. | |
| 189 if (animation_player_->element_animations()) { | |
| 190 animation_controller_state_ = | |
| 191 animation_player_->element_animations()->layer_animation_controller(); | |
| 192 } | |
| 193 | 178 |
| 194 DetachLayerFromAnimationPlayer(); | 179 // Store a reference to LAC if any so it may be picked up in SetCompositor. |
| 180 if (animation_player_->element_animations()) { |
| 181 animation_controller_state_ = |
| 182 animation_player_->element_animations()->layer_animation_controller(); |
| 183 } |
| 195 | 184 |
| 196 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); | 185 DetachLayerFromAnimationPlayer(); |
| 197 DCHECK(timeline); | 186 |
| 198 timeline->DetachPlayer(animation_player_); | 187 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); |
| 199 } | 188 DCHECK(timeline); |
| 189 timeline->DetachPlayer(animation_player_); |
| 200 } | 190 } |
| 201 | 191 |
| 202 void LayerAnimator::AttachLayerToAnimationPlayer(int layer_id) { | 192 void LayerAnimator::AttachLayerToAnimationPlayer(int layer_id) { |
| 203 DCHECK(animation_player_); | |
| 204 | |
| 205 if (!animation_player_->layer_id()) | 193 if (!animation_player_->layer_id()) |
| 206 animation_player_->AttachLayer(layer_id); | 194 animation_player_->AttachLayer(layer_id); |
| 207 else | 195 else |
| 208 DCHECK_EQ(animation_player_->layer_id(), layer_id); | 196 DCHECK_EQ(animation_player_->layer_id(), layer_id); |
| 209 | 197 |
| 210 if (animation_player_->element_animations()) { | 198 if (animation_player_->element_animations()) { |
| 211 animation_player_->element_animations() | 199 animation_player_->element_animations() |
| 212 ->layer_animation_controller() | 200 ->layer_animation_controller() |
| 213 ->AddEventObserver(this); | 201 ->AddEventObserver(this); |
| 214 } | 202 } |
| 215 } | 203 } |
| 216 | 204 |
| 217 void LayerAnimator::DetachLayerFromAnimationPlayer() { | 205 void LayerAnimator::DetachLayerFromAnimationPlayer() { |
| 218 DCHECK(animation_player_); | |
| 219 | |
| 220 if (animation_player_->element_animations()) { | 206 if (animation_player_->element_animations()) { |
| 221 animation_player_->element_animations() | 207 animation_player_->element_animations() |
| 222 ->layer_animation_controller() | 208 ->layer_animation_controller() |
| 223 ->RemoveEventObserver(this); | 209 ->RemoveEventObserver(this); |
| 224 } | 210 } |
| 225 | 211 |
| 226 if (animation_player_->layer_id()) | 212 if (animation_player_->layer_id()) |
| 227 animation_player_->DetachLayer(); | 213 animation_player_->DetachLayer(); |
| 228 } | 214 } |
| 229 | 215 |
| 230 void LayerAnimator::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) { | 216 void LayerAnimator::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) { |
| 231 DCHECK(animation_player_); | |
| 232 animation_player_->AddAnimation(std::move(animation)); | 217 animation_player_->AddAnimation(std::move(animation)); |
| 233 } | 218 } |
| 234 | 219 |
| 235 void LayerAnimator::RemoveThreadedAnimation(int animation_id) { | 220 void LayerAnimator::RemoveThreadedAnimation(int animation_id) { |
| 236 DCHECK(animation_player_); | |
| 237 animation_player_->RemoveAnimation(animation_id); | 221 animation_player_->RemoveAnimation(animation_id); |
| 238 } | 222 } |
| 239 | 223 |
| 240 bool LayerAnimator::HasPendingThreadedAnimationsForTesting() const { | 224 bool LayerAnimator::HasPendingThreadedAnimationsForTesting() const { |
| 241 DCHECK(animation_player_); | |
| 242 return animation_player_->has_pending_animations_for_testing(); | 225 return animation_player_->has_pending_animations_for_testing(); |
| 243 } | 226 } |
| 244 | 227 |
| 245 cc::AnimationPlayer* LayerAnimator::GetAnimationPlayerForTesting() const { | 228 cc::AnimationPlayer* LayerAnimator::GetAnimationPlayerForTesting() const { |
| 246 return animation_player_.get(); | 229 return animation_player_.get(); |
| 247 } | 230 } |
| 248 | 231 |
| 249 void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) { | 232 void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) { |
| 250 scoped_refptr<LayerAnimator> retain(this); | 233 scoped_refptr<LayerAnimator> retain(this); |
| 251 OnScheduled(animation); | 234 OnScheduled(animation); |
| (...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 const base::WeakPtr<LayerAnimationSequence>& sequence) | 964 const base::WeakPtr<LayerAnimationSequence>& sequence) |
| 982 : sequence_(sequence) { | 965 : sequence_(sequence) { |
| 983 } | 966 } |
| 984 | 967 |
| 985 LayerAnimator::RunningAnimation::RunningAnimation( | 968 LayerAnimator::RunningAnimation::RunningAnimation( |
| 986 const RunningAnimation& other) = default; | 969 const RunningAnimation& other) = default; |
| 987 | 970 |
| 988 LayerAnimator::RunningAnimation::~RunningAnimation() { } | 971 LayerAnimator::RunningAnimation::~RunningAnimation() { } |
| 989 | 972 |
| 990 } // namespace ui | 973 } // namespace ui |
| OLD | NEW |