| Index: ui/compositor/layer.cc
|
| diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc
|
| index 16505f304bb7a25caa92884d59864ed7822047df..77fca4b49774187d2e77c3fb9e3c952099070908 100644
|
| --- a/ui/compositor/layer.cc
|
| +++ b/ui/compositor/layer.cc
|
| @@ -13,6 +13,9 @@
|
| #include "base/logging.h"
|
| #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/base/scoped_ptr_algorithm.h"
|
| #include "cc/layers/content_layer.h"
|
| #include "cc/layers/delegated_renderer_layer.h"
|
| @@ -26,6 +29,7 @@
|
| #include "cc/output/filter_operation.h"
|
| #include "cc/output/filter_operations.h"
|
| #include "cc/resources/transferable_resource.h"
|
| +#include "cc/trees/layer_tree_host.h"
|
| #include "ui/compositor/compositor_switches.h"
|
| #include "ui/compositor/dip_util.h"
|
| #include "ui/compositor/layer_animator.h"
|
| @@ -125,7 +129,10 @@ Layer::~Layer() {
|
| layer_mask_back_link_->SetMaskLayer(NULL);
|
| for (size_t i = 0; i < children_.size(); ++i)
|
| children_[i]->parent_ = NULL;
|
| - cc_layer_->RemoveLayerAnimationEventObserver(this);
|
| +
|
| + if (compositor_)
|
| + DetachLayer();
|
| +
|
| cc_layer_->RemoveFromParent();
|
| }
|
|
|
| @@ -143,17 +150,26 @@ float Layer::opacity() const {
|
| }
|
|
|
| void Layer::SetCompositor(Compositor* compositor) {
|
| + if (compositor)
|
| + RegisterForAnimations(compositor);
|
| +
|
| // This function must only be called to set the compositor on the root layer,
|
| // or to reset it.
|
| DCHECK(!compositor || !compositor_);
|
| DCHECK(!compositor || compositor->root_layer() == this);
|
| DCHECK(!parent_);
|
| if (compositor_) {
|
| + DetachLayer();
|
| + DetachAnimationPlayer();
|
| +
|
| RemoveAnimatorsInTreeFromCollection(
|
| compositor_->layer_animator_collection());
|
| }
|
| compositor_ = compositor;
|
| if (compositor) {
|
| + AttachAnimationPlayer();
|
| + AttachLayer();
|
| +
|
| OnDeviceScaleFactorChanged(compositor->device_scale_factor());
|
| SendPendingThreadedAnimations();
|
| AddAnimatorsInTreeToCollection(compositor_->layer_animator_collection());
|
| @@ -168,8 +184,14 @@ void Layer::Add(Layer* child) {
|
| children_.push_back(child);
|
| cc_layer_->AddChild(child->cc_layer_);
|
| child->OnDeviceScaleFactorChanged(device_scale_factor_);
|
| - if (GetCompositor())
|
| + Compositor* compositor = GetCompositor();
|
| + if (compositor) {
|
| + child->RegisterForAnimations(compositor);
|
| + child->AttachAnimationPlayer();
|
| + child->AttachLayer();
|
| +
|
| child->SendPendingThreadedAnimations();
|
| + }
|
| LayerAnimatorCollection* collection = GetLayerAnimatorCollection();
|
| if (collection)
|
| child->AddAnimatorsInTreeToCollection(collection);
|
| @@ -185,6 +207,12 @@ void Layer::Remove(Layer* child) {
|
| if (collection)
|
| child->RemoveAnimatorsInTreeFromCollection(collection);
|
|
|
| + Compositor* compositor = GetCompositor();
|
| + if (compositor) {
|
| + child->DetachLayer();
|
| + child->DetachAnimationPlayer();
|
| + }
|
| +
|
| std::vector<Layer*>::iterator i =
|
| std::find(children_.begin(), children_.end(), child);
|
| DCHECK(i != children_.end());
|
| @@ -491,7 +519,9 @@ void Layer::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) {
|
| cc_layer_->parent()->ReplaceChild(cc_layer_, new_layer);
|
| }
|
| cc_layer_->SetLayerClient(NULL);
|
| - cc_layer_->RemoveLayerAnimationEventObserver(this);
|
| +
|
| + DetachLayer();
|
| +
|
| new_layer->SetOpacity(cc_layer_->opacity());
|
| new_layer->SetTransform(cc_layer_->transform());
|
| new_layer->SetPosition(cc_layer_->position());
|
| @@ -504,7 +534,8 @@ void Layer::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) {
|
| delegated_renderer_layer_ = NULL;
|
| surface_layer_ = NULL;
|
|
|
| - cc_layer_->AddLayerAnimationEventObserver(this);
|
| + AttachLayer();
|
| +
|
| for (size_t i = 0; i < children_.size(); ++i) {
|
| DCHECK(children_[i]->cc_layer_);
|
| cc_layer_->AddChild(children_[i]->cc_layer_);
|
| @@ -968,9 +999,10 @@ void Layer::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) {
|
| DCHECK(cc_layer_);
|
| // Until this layer has a compositor (and hence cc_layer_ has a
|
| // LayerTreeHost), addAnimation will fail.
|
| - if (GetCompositor())
|
| - cc_layer_->AddAnimation(animation.Pass());
|
| - else
|
| + if (GetCompositor()) {
|
| + animation_player_ ? animation_player_->AddAnimation(animation.Pass())
|
| + : (void)cc_layer_->AddAnimation(animation.Pass());
|
| + } else
|
| pending_threaded_animations_.push_back(animation.Pass());
|
| }
|
|
|
| @@ -993,7 +1025,8 @@ struct HasAnimationId {
|
| void Layer::RemoveThreadedAnimation(int animation_id) {
|
| DCHECK(cc_layer_);
|
| if (pending_threaded_animations_.size() == 0) {
|
| - cc_layer_->RemoveAnimation(animation_id);
|
| + animation_player_ ? animation_player_->RemoveAnimation(animation_id)
|
| + : cc_layer_->RemoveAnimation(animation_id);
|
| return;
|
| }
|
|
|
| @@ -1013,9 +1046,11 @@ LayerAnimatorCollection* Layer::GetLayerAnimatorCollection() {
|
| void Layer::SendPendingThreadedAnimations() {
|
| for (cc::ScopedPtrVector<cc::Animation>::iterator it =
|
| pending_threaded_animations_.begin();
|
| - it != pending_threaded_animations_.end();
|
| - ++it)
|
| - cc_layer_->AddAnimation(pending_threaded_animations_.take(it));
|
| + it != pending_threaded_animations_.end(); ++it) {
|
| + animation_player_
|
| + ? animation_player_->AddAnimation(pending_threaded_animations_.take(it))
|
| + : (void)cc_layer_->AddAnimation(pending_threaded_animations_.take(it));
|
| + }
|
|
|
| pending_threaded_animations_.clear();
|
|
|
| @@ -1040,11 +1075,76 @@ void Layer::CreateCcLayer() {
|
| cc_layer_->SetTransformOrigin(gfx::Point3F());
|
| cc_layer_->SetContentsOpaque(true);
|
| cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN);
|
| - cc_layer_->AddLayerAnimationEventObserver(this);
|
| cc_layer_->SetLayerClient(this);
|
| RecomputePosition();
|
| }
|
|
|
| +void Layer::RegisterForAnimations(Compositor* compositor) {
|
| + DCHECK(compositor);
|
| + const cc::LayerTreeHost& host = compositor->GetLayerTreeHost();
|
| + cc_layer_->RegisterForAnimations(host.animation_registrar(), host.settings());
|
| +
|
| + if (host.settings().use_compositor_animation_timelines) {
|
| + if (!animation_player_) {
|
| + animation_player_ =
|
| + cc::AnimationPlayer::Create(cc::AnimationIdProvider::NextPlayerId());
|
| + }
|
| + }
|
| +
|
| + for (size_t i = 0; i < children_.size(); ++i)
|
| + children_[i]->RegisterForAnimations(compositor);
|
| +}
|
| +
|
| +void Layer::AttachLayer() {
|
| + DCHECK(cc_layer_);
|
| +
|
| + if (animation_player_) {
|
| + animation_player_->AttachLayer(cc_layer_->id());
|
| + DCHECK(animation_player_->layer_animation_controller());
|
| + animation_player_->layer_animation_controller()->AddEventObserver(this);
|
| + } else {
|
| + cc_layer_->AddLayerAnimationEventObserver(this);
|
| + }
|
| +
|
| + for (size_t i = 0; i < children_.size(); ++i)
|
| + children_[i]->AttachLayer();
|
| +}
|
| +
|
| +void Layer::DetachLayer() {
|
| + if (animation_player_) {
|
| + DCHECK(animation_player_->layer_animation_controller());
|
| + animation_player_->layer_animation_controller()->RemoveEventObserver(this);
|
| + animation_player_->DetachLayer();
|
| + } else {
|
| + cc_layer_->RemoveLayerAnimationEventObserver(this);
|
| + }
|
| +
|
| + for (size_t i = 0; i < children_.size(); ++i)
|
| + children_[i]->DetachLayer();
|
| +}
|
| +
|
| +void Layer::AttachAnimationPlayer() {
|
| + Compositor* compositor = GetCompositor();
|
| + DCHECK(compositor);
|
| +
|
| + if (animation_player_)
|
| + compositor->GetAnimationTimeline()->AttachPlayer(animation_player_.get());
|
| +
|
| + for (size_t i = 0; i < children_.size(); ++i)
|
| + children_[i]->AttachAnimationPlayer();
|
| +}
|
| +
|
| +void Layer::DetachAnimationPlayer() {
|
| + Compositor* compositor = GetCompositor();
|
| + DCHECK(compositor);
|
| +
|
| + if (animation_player_)
|
| + compositor->GetAnimationTimeline()->DetachPlayer(animation_player_.get());
|
| +
|
| + for (size_t i = 0; i < children_.size(); ++i)
|
| + children_[i]->DetachAnimationPlayer();
|
| +}
|
| +
|
| gfx::Transform Layer::transform() const {
|
| return cc_layer_->transform();
|
| }
|
|
|