| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/layers/layer_impl.h" | 5 #include "cc/layers/layer_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> |
| 10 #include <utility> | 11 #include <utility> |
| 11 | 12 |
| 12 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
| 13 #include "base/numerics/safe_conversions.h" | 14 #include "base/numerics/safe_conversions.h" |
| 14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 15 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
| 16 #include "base/trace_event/trace_event_argument.h" | 17 #include "base/trace_event/trace_event_argument.h" |
| 17 #include "cc/animation/mutable_properties.h" | 18 #include "cc/animation/mutable_properties.h" |
| 18 #include "cc/base/math_util.h" | 19 #include "cc/base/math_util.h" |
| 19 #include "cc/base/simple_enclosed_region.h" | 20 #include "cc/base/simple_enclosed_region.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 39 #include "ui/gfx/geometry/rect_conversions.h" | 40 #include "ui/gfx/geometry/rect_conversions.h" |
| 40 #include "ui/gfx/geometry/size_conversions.h" | 41 #include "ui/gfx/geometry/size_conversions.h" |
| 41 #include "ui/gfx/geometry/vector2d_conversions.h" | 42 #include "ui/gfx/geometry/vector2d_conversions.h" |
| 42 | 43 |
| 43 namespace cc { | 44 namespace cc { |
| 44 LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, int id) | 45 LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, int id) |
| 45 : parent_(nullptr), | 46 : parent_(nullptr), |
| 46 scroll_parent_(nullptr), | 47 scroll_parent_(nullptr), |
| 47 clip_parent_(nullptr), | 48 clip_parent_(nullptr), |
| 48 mask_layer_id_(-1), | 49 mask_layer_id_(-1), |
| 50 mask_layer_(nullptr), |
| 49 replica_layer_id_(-1), | 51 replica_layer_id_(-1), |
| 52 replica_layer_(nullptr), |
| 50 layer_id_(id), | 53 layer_id_(id), |
| 51 layer_tree_impl_(tree_impl), | 54 layer_tree_impl_(tree_impl), |
| 52 scroll_clip_layer_id_(Layer::INVALID_ID), | 55 scroll_clip_layer_id_(Layer::INVALID_ID), |
| 53 main_thread_scrolling_reasons_( | 56 main_thread_scrolling_reasons_( |
| 54 MainThreadScrollingReason::kNotScrollingOnMain), | 57 MainThreadScrollingReason::kNotScrollingOnMain), |
| 55 user_scrollable_horizontal_(true), | 58 user_scrollable_horizontal_(true), |
| 56 user_scrollable_vertical_(true), | 59 user_scrollable_vertical_(true), |
| 57 double_sided_(true), | 60 double_sided_(true), |
| 58 should_flatten_transform_(true), | 61 should_flatten_transform_(true), |
| 59 should_flatten_transform_from_property_tree_(false), | 62 should_flatten_transform_from_property_tree_(false), |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 if (!copy_requests_.empty() && layer_tree_impl_->IsActiveTree()) | 110 if (!copy_requests_.empty() && layer_tree_impl_->IsActiveTree()) |
| 108 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this); | 111 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this); |
| 109 layer_tree_impl_->UnregisterScrollLayer(this); | 112 layer_tree_impl_->UnregisterScrollLayer(this); |
| 110 layer_tree_impl_->UnregisterLayer(this); | 113 layer_tree_impl_->UnregisterLayer(this); |
| 111 layer_tree_impl_->RemoveLayerShouldPushProperties(this); | 114 layer_tree_impl_->RemoveLayerShouldPushProperties(this); |
| 112 | 115 |
| 113 layer_tree_impl_->RemoveFromElementMap(this); | 116 layer_tree_impl_->RemoveFromElementMap(this); |
| 114 | 117 |
| 115 TRACE_EVENT_OBJECT_DELETED_WITH_ID( | 118 TRACE_EVENT_OBJECT_DELETED_WITH_ID( |
| 116 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this); | 119 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this); |
| 120 |
| 121 if (mask_layer_) |
| 122 layer_tree_impl_->RemoveLayer(mask_layer_id_); |
| 123 if (replica_layer_) |
| 124 layer_tree_impl_->RemoveLayer(replica_layer_id_); |
| 125 ClearChildList(); |
| 117 } | 126 } |
| 118 | 127 |
| 119 void LayerImpl::AddChild(scoped_ptr<LayerImpl> child) { | 128 void LayerImpl::AddChild(scoped_ptr<LayerImpl> child) { |
| 120 child->SetParent(this); | 129 child->SetParent(this); |
| 121 DCHECK_EQ(layer_tree_impl(), child->layer_tree_impl()); | 130 DCHECK_EQ(layer_tree_impl(), child->layer_tree_impl()); |
| 122 children_.push_back(std::move(child)); | 131 children_.push_back(child.get()); |
| 123 layer_tree_impl()->set_needs_update_draw_properties(); | 132 layer_tree_impl_->AddLayer(std::move(child)); |
| 124 } | 133 } |
| 125 | 134 |
| 126 scoped_ptr<LayerImpl> LayerImpl::RemoveChild(LayerImpl* child) { | 135 scoped_ptr<LayerImpl> LayerImpl::RemoveChild(LayerImpl* child) { |
| 127 for (OwnedLayerImplList::iterator it = children_.begin(); | 136 auto it = std::find(children_.begin(), children_.end(), child); |
| 128 it != children_.end(); | 137 if (it != children_.end()) |
| 129 ++it) { | 138 children_.erase(it); |
| 130 if (it->get() == child) { | 139 return layer_tree_impl_->RemoveLayer(child->id()); |
| 131 scoped_ptr<LayerImpl> ret = std::move(*it); | |
| 132 children_.erase(it); | |
| 133 layer_tree_impl()->set_needs_update_draw_properties(); | |
| 134 return ret; | |
| 135 } | |
| 136 } | |
| 137 return nullptr; | |
| 138 } | 140 } |
| 139 | 141 |
| 140 void LayerImpl::SetParent(LayerImpl* parent) { | 142 void LayerImpl::SetParent(LayerImpl* parent) { |
| 141 parent_ = parent; | 143 parent_ = parent; |
| 142 } | 144 } |
| 143 | 145 |
| 144 void LayerImpl::ClearChildList() { | 146 void LayerImpl::ClearChildList() { |
| 145 if (children_.empty()) | 147 if (children_.empty()) |
| 146 return; | 148 return; |
| 147 | 149 for (auto* child : children_) |
| 150 layer_tree_impl_->RemoveLayer(child->id()); |
| 148 children_.clear(); | 151 children_.clear(); |
| 149 layer_tree_impl()->set_needs_update_draw_properties(); | |
| 150 } | 152 } |
| 151 | 153 |
| 152 bool LayerImpl::HasAncestor(const LayerImpl* ancestor) const { | 154 bool LayerImpl::HasAncestor(const LayerImpl* ancestor) const { |
| 153 if (!ancestor) | 155 if (!ancestor) |
| 154 return false; | 156 return false; |
| 155 | 157 |
| 156 for (const LayerImpl* layer = this; layer; layer = layer->parent()) { | 158 for (const LayerImpl* layer = this; layer; layer = layer->parent()) { |
| 157 if (layer == ancestor) | 159 if (layer == ancestor) |
| 158 return true; | 160 return true; |
| 159 } | 161 } |
| (...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) { | 991 void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) { |
| 990 int new_layer_id = mask_layer ? mask_layer->id() : -1; | 992 int new_layer_id = mask_layer ? mask_layer->id() : -1; |
| 991 | 993 |
| 992 if (mask_layer) { | 994 if (mask_layer) { |
| 993 DCHECK_EQ(layer_tree_impl(), mask_layer->layer_tree_impl()); | 995 DCHECK_EQ(layer_tree_impl(), mask_layer->layer_tree_impl()); |
| 994 DCHECK_NE(new_layer_id, mask_layer_id_); | 996 DCHECK_NE(new_layer_id, mask_layer_id_); |
| 995 } else if (new_layer_id == mask_layer_id_) { | 997 } else if (new_layer_id == mask_layer_id_) { |
| 996 return; | 998 return; |
| 997 } | 999 } |
| 998 | 1000 |
| 999 mask_layer_ = std::move(mask_layer); | 1001 if (mask_layer_) |
| 1002 layer_tree_impl_->RemoveLayer(mask_layer_->id()); |
| 1003 mask_layer_ = mask_layer.get(); |
| 1004 if (mask_layer_) |
| 1005 layer_tree_impl_->AddLayer(std::move(mask_layer)); |
| 1006 |
| 1000 mask_layer_id_ = new_layer_id; | 1007 mask_layer_id_ = new_layer_id; |
| 1001 if (mask_layer_) | 1008 if (mask_layer_) |
| 1002 mask_layer_->SetParent(this); | 1009 mask_layer_->SetParent(this); |
| 1003 } | 1010 } |
| 1004 | 1011 |
| 1005 scoped_ptr<LayerImpl> LayerImpl::TakeMaskLayer() { | 1012 scoped_ptr<LayerImpl> LayerImpl::TakeMaskLayer() { |
| 1006 mask_layer_id_ = -1; | 1013 mask_layer_id_ = -1; |
| 1007 return std::move(mask_layer_); | 1014 scoped_ptr<LayerImpl> ret; |
| 1015 if (mask_layer_) |
| 1016 ret = layer_tree_impl_->RemoveLayer(mask_layer_->id()); |
| 1017 mask_layer_ = nullptr; |
| 1018 return ret; |
| 1008 } | 1019 } |
| 1009 | 1020 |
| 1010 void LayerImpl::SetReplicaLayer(scoped_ptr<LayerImpl> replica_layer) { | 1021 void LayerImpl::SetReplicaLayer(scoped_ptr<LayerImpl> replica_layer) { |
| 1011 int new_layer_id = replica_layer ? replica_layer->id() : -1; | 1022 int new_layer_id = replica_layer ? replica_layer->id() : -1; |
| 1012 | 1023 |
| 1013 if (replica_layer) { | 1024 if (replica_layer) { |
| 1014 DCHECK_EQ(layer_tree_impl(), replica_layer->layer_tree_impl()); | 1025 DCHECK_EQ(layer_tree_impl(), replica_layer->layer_tree_impl()); |
| 1015 DCHECK_NE(new_layer_id, replica_layer_id_); | 1026 DCHECK_NE(new_layer_id, replica_layer_id_); |
| 1016 } else if (new_layer_id == replica_layer_id_) { | 1027 } else if (new_layer_id == replica_layer_id_) { |
| 1017 return; | 1028 return; |
| 1018 } | 1029 } |
| 1019 | 1030 |
| 1020 replica_layer_ = std::move(replica_layer); | 1031 if (replica_layer_) |
| 1032 layer_tree_impl_->RemoveLayer(replica_layer_->id()); |
| 1033 replica_layer_ = replica_layer.get(); |
| 1034 if (replica_layer_) |
| 1035 layer_tree_impl_->AddLayer(std::move(replica_layer)); |
| 1036 |
| 1021 replica_layer_id_ = new_layer_id; | 1037 replica_layer_id_ = new_layer_id; |
| 1022 if (replica_layer_) | 1038 if (replica_layer_) |
| 1023 replica_layer_->SetParent(this); | 1039 replica_layer_->SetParent(this); |
| 1024 } | 1040 } |
| 1025 | 1041 |
| 1026 scoped_ptr<LayerImpl> LayerImpl::TakeReplicaLayer() { | 1042 scoped_ptr<LayerImpl> LayerImpl::TakeReplicaLayer() { |
| 1027 replica_layer_id_ = -1; | 1043 replica_layer_id_ = -1; |
| 1028 return std::move(replica_layer_); | 1044 scoped_ptr<LayerImpl> ret; |
| 1045 if (replica_layer_) |
| 1046 ret = layer_tree_impl_->RemoveLayer(replica_layer_->id()); |
| 1047 replica_layer_ = nullptr; |
| 1048 return ret; |
| 1029 } | 1049 } |
| 1030 | 1050 |
| 1031 ScrollbarLayerImplBase* LayerImpl::ToScrollbarLayer() { | 1051 ScrollbarLayerImplBase* LayerImpl::ToScrollbarLayer() { |
| 1032 return nullptr; | 1052 return nullptr; |
| 1033 } | 1053 } |
| 1034 | 1054 |
| 1035 void LayerImpl::SetDrawsContent(bool draws_content) { | 1055 void LayerImpl::SetDrawsContent(bool draws_content) { |
| 1036 if (draws_content_ == draws_content) | 1056 if (draws_content_ == draws_content) |
| 1037 return; | 1057 return; |
| 1038 | 1058 |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1580 .layer_transforms_should_scale_layer_contents) { | 1600 .layer_transforms_should_scale_layer_contents) { |
| 1581 return default_scale; | 1601 return default_scale; |
| 1582 } | 1602 } |
| 1583 | 1603 |
| 1584 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( | 1604 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( |
| 1585 DrawTransform(), default_scale); | 1605 DrawTransform(), default_scale); |
| 1586 return std::max(transform_scales.x(), transform_scales.y()); | 1606 return std::max(transform_scales.x(), transform_scales.y()); |
| 1587 } | 1607 } |
| 1588 | 1608 |
| 1589 } // namespace cc | 1609 } // namespace cc |
| OLD | NEW |