| 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.h" | 5 #include "ui/compositor/layer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 compositor_->SetRootLayer(NULL); | 113 compositor_->SetRootLayer(NULL); |
| 114 if (parent_) | 114 if (parent_) |
| 115 parent_->Remove(this); | 115 parent_->Remove(this); |
| 116 if (layer_mask_) | 116 if (layer_mask_) |
| 117 SetMaskLayer(NULL); | 117 SetMaskLayer(NULL); |
| 118 if (layer_mask_back_link_) | 118 if (layer_mask_back_link_) |
| 119 layer_mask_back_link_->SetMaskLayer(NULL); | 119 layer_mask_back_link_->SetMaskLayer(NULL); |
| 120 for (size_t i = 0; i < children_.size(); ++i) | 120 for (size_t i = 0; i < children_.size(); ++i) |
| 121 children_[i]->parent_ = NULL; | 121 children_[i]->parent_ = NULL; |
| 122 | 122 |
| 123 cc_layer_->RemoveLayerAnimationEventObserver(this); | |
| 124 cc_layer_->RemoveFromParent(); | 123 cc_layer_->RemoveFromParent(); |
| 125 } | 124 } |
| 126 | 125 |
| 127 // static | 126 // static |
| 128 const cc::LayerSettings& Layer::UILayerSettings() { | 127 const cc::LayerSettings& Layer::UILayerSettings() { |
| 129 return g_ui_layer_settings.Get(); | 128 return g_ui_layer_settings.Get(); |
| 130 } | 129 } |
| 131 | 130 |
| 132 // static | 131 // static |
| 133 void Layer::InitializeUILayerSettings() { | 132 void Layer::InitializeUILayerSettings() { |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 | 480 |
| 482 void Layer::SetFillsBoundsCompletely(bool fills_bounds_completely) { | 481 void Layer::SetFillsBoundsCompletely(bool fills_bounds_completely) { |
| 483 fills_bounds_completely_ = fills_bounds_completely; | 482 fills_bounds_completely_ = fills_bounds_completely; |
| 484 } | 483 } |
| 485 | 484 |
| 486 void Layer::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { | 485 void Layer::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { |
| 487 // Finish animations being handled by cc_layer_. | 486 // Finish animations being handled by cc_layer_. |
| 488 if (animator_.get()) { | 487 if (animator_.get()) { |
| 489 animator_->StopAnimatingProperty(LayerAnimationElement::TRANSFORM); | 488 animator_->StopAnimatingProperty(LayerAnimationElement::TRANSFORM); |
| 490 animator_->StopAnimatingProperty(LayerAnimationElement::OPACITY); | 489 animator_->StopAnimatingProperty(LayerAnimationElement::OPACITY); |
| 490 animator_->SwitchToLayer(new_layer); |
| 491 } | 491 } |
| 492 | 492 |
| 493 if (texture_layer_.get()) | 493 if (texture_layer_.get()) |
| 494 texture_layer_->ClearClient(); | 494 texture_layer_->ClearClient(); |
| 495 // TODO(piman): delegated_renderer_layer_ cleanup. | 495 // TODO(piman): delegated_renderer_layer_ cleanup. |
| 496 | 496 |
| 497 cc_layer_->RemoveAllChildren(); | 497 cc_layer_->RemoveAllChildren(); |
| 498 if (cc_layer_->parent()) { | 498 if (cc_layer_->parent()) { |
| 499 cc_layer_->parent()->ReplaceChild(cc_layer_, new_layer); | 499 cc_layer_->parent()->ReplaceChild(cc_layer_, new_layer); |
| 500 } | 500 } |
| 501 cc_layer_->SetLayerClient(NULL); | 501 cc_layer_->SetLayerClient(NULL); |
| 502 cc_layer_->RemoveLayerAnimationEventObserver(this); | |
| 503 new_layer->SetOpacity(cc_layer_->opacity()); | 502 new_layer->SetOpacity(cc_layer_->opacity()); |
| 504 new_layer->SetTransform(cc_layer_->transform()); | 503 new_layer->SetTransform(cc_layer_->transform()); |
| 505 new_layer->SetPosition(cc_layer_->position()); | 504 new_layer->SetPosition(cc_layer_->position()); |
| 506 new_layer->SetBackgroundColor(cc_layer_->background_color()); | 505 new_layer->SetBackgroundColor(cc_layer_->background_color()); |
| 507 | 506 |
| 508 cc_layer_ = new_layer.get(); | 507 cc_layer_ = new_layer.get(); |
| 509 content_layer_ = NULL; | 508 content_layer_ = NULL; |
| 510 solid_color_layer_ = NULL; | 509 solid_color_layer_ = NULL; |
| 511 texture_layer_ = NULL; | 510 texture_layer_ = NULL; |
| 512 delegated_renderer_layer_ = NULL; | 511 delegated_renderer_layer_ = NULL; |
| 513 surface_layer_ = NULL; | 512 surface_layer_ = NULL; |
| 514 | 513 |
| 515 cc_layer_->AddLayerAnimationEventObserver(this); | |
| 516 for (size_t i = 0; i < children_.size(); ++i) { | 514 for (size_t i = 0; i < children_.size(); ++i) { |
| 517 DCHECK(children_[i]->cc_layer_); | 515 DCHECK(children_[i]->cc_layer_); |
| 518 cc_layer_->AddChild(children_[i]->cc_layer_); | 516 cc_layer_->AddChild(children_[i]->cc_layer_); |
| 519 } | 517 } |
| 520 cc_layer_->SetLayerClient(this); | 518 cc_layer_->SetLayerClient(this); |
| 521 cc_layer_->SetTransformOrigin(gfx::Point3F()); | 519 cc_layer_->SetTransformOrigin(gfx::Point3F()); |
| 522 cc_layer_->SetContentsOpaque(fills_bounds_opaquely_); | 520 cc_layer_->SetContentsOpaque(fills_bounds_opaquely_); |
| 523 cc_layer_->SetForceRenderSurface(force_render_surface_); | 521 cc_layer_->SetForceRenderSurface(force_render_surface_); |
| 524 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); | 522 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); |
| 525 cc_layer_->SetHideLayerAndSubtree(!visible_); | 523 cc_layer_->SetHideLayerAndSubtree(!visible_); |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 private: | 810 private: |
| 813 ~LayerDebugInfo() override {} | 811 ~LayerDebugInfo() override {} |
| 814 std::string name_; | 812 std::string name_; |
| 815 }; | 813 }; |
| 816 | 814 |
| 817 scoped_refptr<base::trace_event::ConvertableToTraceFormat> Layer::TakeDebugInfo( | 815 scoped_refptr<base::trace_event::ConvertableToTraceFormat> Layer::TakeDebugInfo( |
| 818 cc::Layer* layer) { | 816 cc::Layer* layer) { |
| 819 return new LayerDebugInfo(name_); | 817 return new LayerDebugInfo(name_); |
| 820 } | 818 } |
| 821 | 819 |
| 822 void Layer::OnAnimationStarted(const cc::AnimationEvent& event) { | |
| 823 if (animator_.get()) | |
| 824 animator_->OnThreadedAnimationStarted(event); | |
| 825 } | |
| 826 | |
| 827 void Layer::CollectAnimators( | 820 void Layer::CollectAnimators( |
| 828 std::vector<scoped_refptr<LayerAnimator>>* animators) { | 821 std::vector<scoped_refptr<LayerAnimator>>* animators) { |
| 829 if (IsAnimating()) | 822 if (IsAnimating()) |
| 830 animators->push_back(animator_); | 823 animators->push_back(animator_); |
| 831 for (auto* child : children_) | 824 for (auto* child : children_) |
| 832 child->CollectAnimators(animators); | 825 child->CollectAnimators(animators); |
| 833 } | 826 } |
| 834 | 827 |
| 835 void Layer::StackRelativeTo(Layer* child, Layer* other, bool above) { | 828 void Layer::StackRelativeTo(Layer* child, Layer* other, bool above) { |
| 836 DCHECK_NE(child, other); | 829 DCHECK_NE(child, other); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 return animation->id() == animation_id; | 993 return animation->id() == animation_id; |
| 1001 }), | 994 }), |
| 1002 pending_threaded_animations_.end()); | 995 pending_threaded_animations_.end()); |
| 1003 } | 996 } |
| 1004 | 997 |
| 1005 LayerAnimatorCollection* Layer::GetLayerAnimatorCollection() { | 998 LayerAnimatorCollection* Layer::GetLayerAnimatorCollection() { |
| 1006 Compositor* compositor = GetCompositor(); | 999 Compositor* compositor = GetCompositor(); |
| 1007 return compositor ? compositor->layer_animator_collection() : NULL; | 1000 return compositor ? compositor->layer_animator_collection() : NULL; |
| 1008 } | 1001 } |
| 1009 | 1002 |
| 1003 cc::Layer* Layer::GetCcLayer() const { |
| 1004 return cc_layer_; |
| 1005 } |
| 1006 |
| 1010 void Layer::SendPendingThreadedAnimations() { | 1007 void Layer::SendPendingThreadedAnimations() { |
| 1011 for (auto& animation : pending_threaded_animations_) | 1008 for (auto& animation : pending_threaded_animations_) |
| 1012 cc_layer_->AddAnimation(std::move(animation)); | 1009 cc_layer_->AddAnimation(std::move(animation)); |
| 1013 pending_threaded_animations_.clear(); | 1010 pending_threaded_animations_.clear(); |
| 1014 | 1011 |
| 1015 for (auto* child : children_) | 1012 for (auto* child : children_) |
| 1016 child->SendPendingThreadedAnimations(); | 1013 child->SendPendingThreadedAnimations(); |
| 1017 } | 1014 } |
| 1018 | 1015 |
| 1019 void Layer::CreateCcLayer() { | 1016 void Layer::CreateCcLayer() { |
| 1020 if (type_ == LAYER_SOLID_COLOR) { | 1017 if (type_ == LAYER_SOLID_COLOR) { |
| 1021 solid_color_layer_ = cc::SolidColorLayer::Create(UILayerSettings()); | 1018 solid_color_layer_ = cc::SolidColorLayer::Create(UILayerSettings()); |
| 1022 cc_layer_ = solid_color_layer_.get(); | 1019 cc_layer_ = solid_color_layer_.get(); |
| 1023 } else if (type_ == LAYER_NINE_PATCH) { | 1020 } else if (type_ == LAYER_NINE_PATCH) { |
| 1024 nine_patch_layer_ = cc::NinePatchLayer::Create(UILayerSettings()); | 1021 nine_patch_layer_ = cc::NinePatchLayer::Create(UILayerSettings()); |
| 1025 cc_layer_ = nine_patch_layer_.get(); | 1022 cc_layer_ = nine_patch_layer_.get(); |
| 1026 } else { | 1023 } else { |
| 1027 content_layer_ = cc::PictureLayer::Create(UILayerSettings(), this); | 1024 content_layer_ = cc::PictureLayer::Create(UILayerSettings(), this); |
| 1028 cc_layer_ = content_layer_.get(); | 1025 cc_layer_ = content_layer_.get(); |
| 1029 } | 1026 } |
| 1030 cc_layer_->SetTransformOrigin(gfx::Point3F()); | 1027 cc_layer_->SetTransformOrigin(gfx::Point3F()); |
| 1031 cc_layer_->SetContentsOpaque(true); | 1028 cc_layer_->SetContentsOpaque(true); |
| 1032 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); | 1029 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); |
| 1033 cc_layer_->AddLayerAnimationEventObserver(this); | |
| 1034 cc_layer_->SetLayerClient(this); | 1030 cc_layer_->SetLayerClient(this); |
| 1035 RecomputePosition(); | 1031 RecomputePosition(); |
| 1036 } | 1032 } |
| 1037 | 1033 |
| 1038 gfx::Transform Layer::transform() const { | 1034 gfx::Transform Layer::transform() const { |
| 1039 return cc_layer_->transform(); | 1035 return cc_layer_->transform(); |
| 1040 } | 1036 } |
| 1041 | 1037 |
| 1042 void Layer::RecomputeDrawsContentAndUVRect() { | 1038 void Layer::RecomputeDrawsContentAndUVRect() { |
| 1043 DCHECK(cc_layer_); | 1039 DCHECK(cc_layer_); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 animator_->RemoveFromCollection(collection); | 1072 animator_->RemoveFromCollection(collection); |
| 1077 for (auto* child : children_) | 1073 for (auto* child : children_) |
| 1078 child->RemoveAnimatorsInTreeFromCollection(collection); | 1074 child->RemoveAnimatorsInTreeFromCollection(collection); |
| 1079 } | 1075 } |
| 1080 | 1076 |
| 1081 bool Layer::IsAnimating() const { | 1077 bool Layer::IsAnimating() const { |
| 1082 return animator_.get() && animator_->is_animating(); | 1078 return animator_.get() && animator_->is_animating(); |
| 1083 } | 1079 } |
| 1084 | 1080 |
| 1085 } // namespace ui | 1081 } // namespace ui |
| OLD | NEW |