Chromium Code Reviews| Index: cc/layers/layer.cc |
| diff --git a/cc/layers/layer.cc b/cc/layers/layer.cc |
| index 9db52869c0e49e008fe81b5df49df0b10a6f3c53..5eb07cc899006e61f4593e324153796b689bcdac 100644 |
| --- a/cc/layers/layer.cc |
| +++ b/cc/layers/layer.cc |
| @@ -21,9 +21,11 @@ |
| #include "cc/debug/frame_viewer_instrumentation.h" |
| #include "cc/layers/layer_client.h" |
| #include "cc/layers/layer_impl.h" |
| +#include "cc/layers/layer_proto_factory.h" |
| #include "cc/layers/scrollbar_layer_interface.h" |
| #include "cc/output/copy_output_request.h" |
| #include "cc/output/copy_output_result.h" |
| +#include "cc/proto/layer.pb.h" |
| #include "cc/trees/draw_property_utils.h" |
| #include "cc/trees/layer_tree_host.h" |
| #include "cc/trees/layer_tree_impl.h" |
| @@ -1345,6 +1347,65 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { |
| num_dependents_need_push_properties_ = 0; |
| } |
| +void Layer::ToLayerNodeProto(proto::LayerNode* proto) { |
|
vmpstr
2015/10/21 22:34:14
Can this function be const?
nyquist
2015/10/23 00:12:30
Done.
|
| + proto->set_id(layer_id_); |
| + proto->set_type(proto::Base); |
| + |
| + if (parent_) { |
|
vmpstr
2015/10/21 22:34:14
nit: braces optional.
nyquist
2015/10/23 00:12:30
Done.
|
| + proto->set_parent_id(parent_->id()); |
| + } |
| + proto->clear_children(); |
|
vmpstr
2015/10/21 22:34:13
DCHECK that children size is 0 instead? Or are the
nyquist
2015/10/23 00:12:30
Done.
|
| + for (auto child : children_) { |
|
vmpstr
2015/10/21 22:34:14
What's the type of child? if it's a raw pointer, t
nyquist
2015/10/23 00:12:30
Done.
|
| + child->ToLayerNodeProto(proto->add_children()); |
| + } |
| + |
| + if (mask_layer_) |
| + mask_layer_->ToLayerNodeProto(proto->mutable_mask_layer()); |
| + if (replica_layer_) |
| + replica_layer_->ToLayerNodeProto(proto->mutable_replica_layer()); |
| +} |
| + |
| +void Layer::FromLayerNodeProto(const proto::LayerNode& proto, |
| + const LayerIdMap& layer_map) { |
| + if (proto.has_id()) |
|
vmpstr
2015/10/21 22:34:13
Are there cases where this isn't set? If not, then
nyquist
2015/10/23 00:12:30
Done.
|
| + layer_id_ = proto.id(); |
| + |
| + // Recursively remove all children. |
| + RemoveAllChildren(); |
|
vmpstr
2015/10/21 22:34:13
I assume this is needed because we're using layer_
nyquist
2015/10/23 00:12:30
Yeah, the issue is if you remove all children from
|
| + for (int i = 0; i < proto.children_size(); ++i) { |
| + const proto::LayerNode& child_proto = proto.children(i); |
| + if (!child_proto.has_type()) { |
|
vmpstr
2015/10/21 22:34:13
When would this happen?
nyquist
2015/10/23 00:12:30
DCHECK here as well now, so done.
|
| + continue; |
| + } |
| + scoped_refptr<Layer> child = |
| + LayerProtoFactory::FindOrAllocateAndConstruct(child_proto, layer_map); |
| + child->FromLayerNodeProto(child_proto, layer_map); |
| + AddChild(child); |
| + } |
| + |
| + if (mask_layer_) |
| + mask_layer_->RemoveFromParent(); |
| + if (proto.has_mask_layer()) { |
| + mask_layer_ = LayerProtoFactory::FindOrAllocateAndConstruct( |
| + proto.mask_layer(), layer_map); |
| + mask_layer_->FromLayerNodeProto(proto.mask_layer(), layer_map); |
| + mask_layer_->SetParent(this); |
| + } else { |
| + mask_layer_ = nullptr; |
| + } |
| + |
| + if (replica_layer_) |
| + replica_layer_->RemoveFromParent(); |
| + if (proto.has_replica_layer()) { |
| + replica_layer_ = LayerProtoFactory::FindOrAllocateAndConstruct( |
| + proto.replica_layer(), layer_map); |
| + replica_layer_->FromLayerNodeProto(proto.replica_layer(), layer_map); |
| + replica_layer_->SetParent(this); |
| + } else { |
| + replica_layer_ = nullptr; |
| + } |
| +} |
| + |
| scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
| return LayerImpl::Create(tree_impl, layer_id_, |
| new LayerImpl::SyncedScrollOffset); |