| 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_events.h" | |
| 14 #include "cc/animation/animation_host.h" | 13 #include "cc/animation/animation_host.h" |
| 15 #include "cc/animation/animation_id_provider.h" | 14 #include "cc/animation/animation_id_provider.h" |
| 16 #include "cc/animation/animation_player.h" | 15 #include "cc/animation/animation_player.h" |
| 17 #include "cc/animation/animation_timeline.h" | 16 #include "cc/animation/animation_timeline.h" |
| 18 #include "cc/animation/element_animations.h" | 17 #include "cc/animation/element_animations.h" |
| 19 #include "cc/animation/layer_animation_controller.h" | 18 #include "cc/animation/layer_animation_controller.h" |
| 20 #include "cc/output/begin_frame_args.h" | 19 #include "cc/output/begin_frame_args.h" |
| 21 #include "ui/compositor/compositor.h" | 20 #include "ui/compositor/compositor.h" |
| 22 #include "ui/compositor/layer.h" | 21 #include "ui/compositor/layer.h" |
| 23 #include "ui/compositor/layer_animation_delegate.h" | 22 #include "ui/compositor/layer_animation_delegate.h" |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 188 |
| 190 timeline->DetachPlayer(animation_player_); | 189 timeline->DetachPlayer(animation_player_); |
| 191 } | 190 } |
| 192 | 191 |
| 193 void LayerAnimator::AttachLayerToAnimationPlayer(int layer_id) { | 192 void LayerAnimator::AttachLayerToAnimationPlayer(int layer_id) { |
| 194 if (!animation_player_->layer_id()) | 193 if (!animation_player_->layer_id()) |
| 195 animation_player_->AttachLayer(layer_id); | 194 animation_player_->AttachLayer(layer_id); |
| 196 else | 195 else |
| 197 DCHECK_EQ(animation_player_->layer_id(), layer_id); | 196 DCHECK_EQ(animation_player_->layer_id(), layer_id); |
| 198 | 197 |
| 199 if (animation_player_->element_animations()) | 198 animation_player_->set_layer_animation_delegate(this); |
| 200 animation_player_->element_animations()->SetEventObserver(this); | |
| 201 } | 199 } |
| 202 | 200 |
| 203 void LayerAnimator::DetachLayerFromAnimationPlayer() { | 201 void LayerAnimator::DetachLayerFromAnimationPlayer() { |
| 204 if (animation_player_->element_animations()) | 202 animation_player_->set_layer_animation_delegate(nullptr); |
| 205 animation_player_->element_animations()->SetEventObserver(nullptr); | |
| 206 | 203 |
| 207 if (animation_player_->layer_id()) | 204 if (animation_player_->layer_id()) |
| 208 animation_player_->DetachLayer(); | 205 animation_player_->DetachLayer(); |
| 209 } | 206 } |
| 210 | 207 |
| 211 void LayerAnimator::AddThreadedAnimation( | 208 void LayerAnimator::AddThreadedAnimation( |
| 212 std::unique_ptr<cc::Animation> animation) { | 209 std::unique_ptr<cc::Animation> animation) { |
| 213 animation_player_->AddAnimation(std::move(animation)); | 210 animation_player_->AddAnimation(std::move(animation)); |
| 214 } | 211 } |
| 215 | 212 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 void LayerAnimator::RemoveObserver(LayerAnimationObserver* observer) { | 395 void LayerAnimator::RemoveObserver(LayerAnimationObserver* observer) { |
| 399 observers_.RemoveObserver(observer); | 396 observers_.RemoveObserver(observer); |
| 400 // Remove the observer from all sequences as well. | 397 // Remove the observer from all sequences as well. |
| 401 for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); | 398 for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); |
| 402 queue_iter != animation_queue_.end(); ++queue_iter) { | 399 queue_iter != animation_queue_.end(); ++queue_iter) { |
| 403 (*queue_iter)->RemoveObserver(observer); | 400 (*queue_iter)->RemoveObserver(observer); |
| 404 } | 401 } |
| 405 } | 402 } |
| 406 | 403 |
| 407 void LayerAnimator::OnThreadedAnimationStarted( | 404 void LayerAnimator::OnThreadedAnimationStarted( |
| 408 const cc::AnimationEvent& event) { | 405 base::TimeTicks monotonic_time, |
| 406 cc::TargetProperty::Type target_property, |
| 407 int group_id) { |
| 409 LayerAnimationElement::AnimatableProperty property = | 408 LayerAnimationElement::AnimatableProperty property = |
| 410 LayerAnimationElement::ToAnimatableProperty(event.target_property); | 409 LayerAnimationElement::ToAnimatableProperty(target_property); |
| 411 | 410 |
| 412 RunningAnimation* running = GetRunningAnimation(property); | 411 RunningAnimation* running = GetRunningAnimation(property); |
| 413 if (!running) | 412 if (!running) |
| 414 return; | 413 return; |
| 415 DCHECK(running->is_sequence_alive()); | 414 DCHECK(running->is_sequence_alive()); |
| 416 | 415 |
| 417 if (running->sequence()->animation_group_id() != event.group_id) | 416 if (running->sequence()->animation_group_id() != group_id) |
| 418 return; | 417 return; |
| 419 | 418 |
| 420 running->sequence()->OnThreadedAnimationStarted(event); | 419 running->sequence()->OnThreadedAnimationStarted(monotonic_time, |
| 420 target_property, group_id); |
| 421 if (!running->sequence()->waiting_for_group_start()) | 421 if (!running->sequence()->waiting_for_group_start()) |
| 422 return; | 422 return; |
| 423 | 423 |
| 424 base::TimeTicks start_time = event.monotonic_time; | 424 base::TimeTicks start_time = monotonic_time; |
| 425 | 425 |
| 426 running->sequence()->set_waiting_for_group_start(false); | 426 running->sequence()->set_waiting_for_group_start(false); |
| 427 | 427 |
| 428 // The call to GetRunningAnimation made above already purged deleted | 428 // The call to GetRunningAnimation made above already purged deleted |
| 429 // animations, so we are guaranteed that all the animations we iterate | 429 // animations, so we are guaranteed that all the animations we iterate |
| 430 // over now are alive. | 430 // over now are alive. |
| 431 for (RunningAnimations::iterator iter = running_animations_.begin(); | 431 for (RunningAnimations::iterator iter = running_animations_.begin(); |
| 432 iter != running_animations_.end(); ++iter) { | 432 iter != running_animations_.end(); ++iter) { |
| 433 // Ensure that each sequence is only Started once, regardless of the | 433 // Ensure that each sequence is only Started once, regardless of the |
| 434 // number of sequences in the group that have threaded first elements. | 434 // number of sequences in the group that have threaded first elements. |
| 435 if (((*iter).sequence()->animation_group_id() == event.group_id) && | 435 if (((*iter).sequence()->animation_group_id() == group_id) && |
| 436 !(*iter).sequence()->IsFirstElementThreaded() && | 436 !(*iter).sequence()->IsFirstElementThreaded() && |
| 437 (*iter).sequence()->waiting_for_group_start()) { | 437 (*iter).sequence()->waiting_for_group_start()) { |
| 438 (*iter).sequence()->set_start_time(start_time); | 438 (*iter).sequence()->set_start_time(start_time); |
| 439 (*iter).sequence()->set_waiting_for_group_start(false); | 439 (*iter).sequence()->set_waiting_for_group_start(false); |
| 440 (*iter).sequence()->Start(delegate()); | 440 (*iter).sequence()->Start(delegate()); |
| 441 } | 441 } |
| 442 } | 442 } |
| 443 } | 443 } |
| 444 | 444 |
| 445 void LayerAnimator::AddToCollection(LayerAnimatorCollection* collection) { | 445 void LayerAnimator::AddToCollection(LayerAnimatorCollection* collection) { |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 running_animations_.erase(running_animations_.begin() + i); | 945 running_animations_.erase(running_animations_.begin() + i); |
| 946 else | 946 else |
| 947 i++; | 947 i++; |
| 948 } | 948 } |
| 949 } | 949 } |
| 950 | 950 |
| 951 LayerAnimatorCollection* LayerAnimator::GetLayerAnimatorCollection() { | 951 LayerAnimatorCollection* LayerAnimator::GetLayerAnimatorCollection() { |
| 952 return delegate_ ? delegate_->GetLayerAnimatorCollection() : NULL; | 952 return delegate_ ? delegate_->GetLayerAnimatorCollection() : NULL; |
| 953 } | 953 } |
| 954 | 954 |
| 955 void LayerAnimator::OnAnimationStarted(const cc::AnimationEvent& event) { | 955 void LayerAnimator::NotifyAnimationStarted( |
| 956 OnThreadedAnimationStarted(event); | 956 base::TimeTicks monotonic_time, |
| 957 cc::TargetProperty::Type target_property, |
| 958 int group) { |
| 959 OnThreadedAnimationStarted(monotonic_time, target_property, group); |
| 957 } | 960 } |
| 958 | 961 |
| 959 LayerAnimator::RunningAnimation::RunningAnimation( | 962 LayerAnimator::RunningAnimation::RunningAnimation( |
| 960 const base::WeakPtr<LayerAnimationSequence>& sequence) | 963 const base::WeakPtr<LayerAnimationSequence>& sequence) |
| 961 : sequence_(sequence) { | 964 : sequence_(sequence) { |
| 962 } | 965 } |
| 963 | 966 |
| 964 LayerAnimator::RunningAnimation::RunningAnimation( | 967 LayerAnimator::RunningAnimation::RunningAnimation( |
| 965 const RunningAnimation& other) = default; | 968 const RunningAnimation& other) = default; |
| 966 | 969 |
| 967 LayerAnimator::RunningAnimation::~RunningAnimation() { } | 970 LayerAnimator::RunningAnimation::~RunningAnimation() { } |
| 968 | 971 |
| 969 } // namespace ui | 972 } // namespace ui |
| OLD | NEW |