| Index: ui/compositor/layer.cc
|
| diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc
|
| index f29f9aa651e69571b15301dfdaf2a7f67623ac88..cfa0dc293653320c85bf1671fba99ec7abef0951 100644
|
| --- a/ui/compositor/layer.cc
|
| +++ b/ui/compositor/layer.cc
|
| @@ -155,18 +155,18 @@ void Layer::SetCompositor(Compositor* compositor,
|
|
|
| compositor_ = compositor;
|
| OnDeviceScaleFactorChanged(compositor->device_scale_factor());
|
| - AddAnimatorsInTreeToCollection(compositor_->layer_animator_collection());
|
|
|
| root_layer->AddChild(cc_layer_);
|
| + SetCompositorForAnimatorsInTree(compositor);
|
| SendPendingThreadedAnimations();
|
| }
|
|
|
| void Layer::ResetCompositor() {
|
| DCHECK(!parent_);
|
| - if (compositor_)
|
| - RemoveAnimatorsInTreeFromCollection(
|
| - compositor_->layer_animator_collection());
|
| - compositor_ = nullptr;
|
| + if (compositor_) {
|
| + ResetCompositorForAnimatorsInTree(compositor_);
|
| + compositor_ = nullptr;
|
| + }
|
| }
|
|
|
| void Layer::Add(Layer* child) {
|
| @@ -177,11 +177,11 @@ 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->SetCompositorForAnimatorsInTree(compositor);
|
| child->SendPendingThreadedAnimations();
|
| - LayerAnimatorCollection* collection = GetLayerAnimatorCollection();
|
| - if (collection)
|
| - child->AddAnimatorsInTreeToCollection(collection);
|
| + }
|
| }
|
|
|
| void Layer::Remove(Layer* child) {
|
| @@ -190,9 +190,10 @@ void Layer::Remove(Layer* child) {
|
| LayerAnimator* child_animator = child->animator_.get();
|
| if (child_animator)
|
| child_animator->StopAnimatingProperty(ui::LayerAnimationElement::BOUNDS);
|
| - LayerAnimatorCollection* collection = GetLayerAnimatorCollection();
|
| - if (collection)
|
| - child->RemoveAnimatorsInTreeFromCollection(collection);
|
| +
|
| + Compositor* compositor = GetCompositor();
|
| + if (compositor)
|
| + child->ResetCompositorForAnimatorsInTree(compositor);
|
|
|
| std::vector<Layer*>::iterator i =
|
| std::find(children_.begin(), children_.end(), child);
|
| @@ -820,7 +821,7 @@ scoped_refptr<base::trace_event::ConvertableToTraceFormat> Layer::TakeDebugInfo(
|
|
|
| void Layer::CollectAnimators(
|
| std::vector<scoped_refptr<LayerAnimator>>* animators) {
|
| - if (IsAnimating())
|
| + if (animator_ && animator_->is_animating())
|
| animators->push_back(animator_);
|
| for (auto* child : children_)
|
| child->CollectAnimators(animators);
|
| @@ -973,16 +974,27 @@ 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(std::move(animation));
|
| - else
|
| + if (GetCompositor()) {
|
| + if (UILayerSettings().use_compositor_animation_timelines) {
|
| + DCHECK(animator_);
|
| + animator_->AddThreadedAnimation(std::move(animation));
|
| + } else {
|
| + cc_layer_->AddAnimation(std::move(animation));
|
| + }
|
| + } else {
|
| pending_threaded_animations_.push_back(std::move(animation));
|
| + }
|
| }
|
|
|
| void Layer::RemoveThreadedAnimation(int animation_id) {
|
| DCHECK(cc_layer_);
|
| if (pending_threaded_animations_.size() == 0) {
|
| - cc_layer_->RemoveAnimation(animation_id);
|
| + if (UILayerSettings().use_compositor_animation_timelines) {
|
| + DCHECK(animator_);
|
| + animator_->RemoveThreadedAnimation(animation_id);
|
| + } else {
|
| + cc_layer_->RemoveAnimation(animation_id);
|
| + }
|
| return;
|
| }
|
|
|
| @@ -1006,8 +1018,14 @@ cc::Layer* Layer::GetCcLayer() const {
|
| }
|
|
|
| void Layer::SendPendingThreadedAnimations() {
|
| - for (auto& animation : pending_threaded_animations_)
|
| - cc_layer_->AddAnimation(std::move(animation));
|
| + for (auto& animation : pending_threaded_animations_) {
|
| + if (UILayerSettings().use_compositor_animation_timelines) {
|
| + DCHECK(animator_);
|
| + animator_->AddThreadedAnimation(std::move(animation));
|
| + } else {
|
| + cc_layer_->AddAnimation(std::move(animation));
|
| + }
|
| + }
|
| pending_threaded_animations_.clear();
|
|
|
| for (auto* child : children_)
|
| @@ -1057,26 +1075,32 @@ void Layer::RecomputePosition() {
|
| subpixel_position_offset_);
|
| }
|
|
|
| -void Layer::AddAnimatorsInTreeToCollection(
|
| - LayerAnimatorCollection* collection) {
|
| - DCHECK(collection);
|
| - if (IsAnimating())
|
| - animator_->AddToCollection(collection);
|
| - for (auto* child : children_)
|
| - child->AddAnimatorsInTreeToCollection(collection);
|
| -}
|
| +void Layer::SetCompositorForAnimatorsInTree(Compositor* compositor) {
|
| + DCHECK(compositor);
|
| + LayerAnimatorCollection* collection = compositor->layer_animator_collection();
|
| +
|
| + if (animator_) {
|
| + if (animator_->is_animating())
|
| + animator_->AddToCollection(collection);
|
| + animator_->SetCompositor(compositor);
|
| + }
|
|
|
| -void Layer::RemoveAnimatorsInTreeFromCollection(
|
| - LayerAnimatorCollection* collection) {
|
| - DCHECK(collection);
|
| - if (IsAnimating())
|
| - animator_->RemoveFromCollection(collection);
|
| for (auto* child : children_)
|
| - child->RemoveAnimatorsInTreeFromCollection(collection);
|
| + child->SetCompositorForAnimatorsInTree(compositor);
|
| }
|
|
|
| -bool Layer::IsAnimating() const {
|
| - return animator_.get() && animator_->is_animating();
|
| +void Layer::ResetCompositorForAnimatorsInTree(Compositor* compositor) {
|
| + DCHECK(compositor);
|
| + LayerAnimatorCollection* collection = compositor->layer_animator_collection();
|
| +
|
| + if (animator_) {
|
| + animator_->ResetCompositor(compositor);
|
| + if (animator_->is_animating())
|
| + animator_->RemoveFromCollection(collection);
|
| + }
|
| +
|
| + for (auto* child : children_)
|
| + child->ResetCompositorForAnimatorsInTree(compositor);
|
| }
|
|
|
| } // namespace ui
|
|
|