| Index: ui/compositor/layer_animator.cc
|
| diff --git a/ui/compositor/layer_animator.cc b/ui/compositor/layer_animator.cc
|
| index b4afd2e0dfc30d31bbfaf65ac10880ba0deba818..691e020cdebb6d238b5ee69f38dc41eb94766984 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,10 @@ LayerAnimator::LayerAnimator(base::TimeDelta transition_duration)
|
| is_started_(false),
|
| disable_timer_for_test_(false),
|
| adding_animations_(false) {
|
| + if (Layer::UILayerSettings().use_compositor_animation_timelines) {
|
| + animation_player_ =
|
| + cc::AnimationPlayer::Create(cc::AnimationIdProvider::NextPlayerId());
|
| + }
|
| }
|
|
|
| LayerAnimator::~LayerAnimator() {
|
| @@ -126,11 +134,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());
|
| }
|
| - if (new_layer)
|
| - new_layer->AddLayerAnimationEventObserver(this);
|
| +}
|
| +
|
| +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 (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) {
|
|
|