Chromium Code Reviews| Index: cc/layers/layer.cc |
| diff --git a/cc/layers/layer.cc b/cc/layers/layer.cc |
| index 9db52869c0e49e008fe81b5df49df0b10a6f3c53..c17bcc4d608b549b312e9dacf73f9de032931be5 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_converter.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,67 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { |
| num_dependents_need_push_properties_ = 0; |
| } |
| +void Layer::ToLayerNodeProto(proto::LayerNode* proto) const { |
| + proto->set_id(layer_id_); |
| + proto->set_type(proto::Base); |
|
vmpstr
2015/10/23 21:26:10
I assume that layer overrides would do something l
nyquist
2015/10/26 03:14:29
Done.
From what I can understand, it should be en
|
| + |
| + if (parent_) |
| + proto->set_parent_id(parent_->id()); |
| + |
| + DCHECK_EQ(0, proto->children_size()); |
| + for (const auto& child : children_) { |
| + 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) { |
| + DCHECK(proto.has_id()); |
| + layer_id_ = proto.id(); |
| + |
| + // Recursively remove all children. In the case of when the updated |
| + // hierarchy has no children, or the children has changed, the old list |
| + // of children must be removed. The whole hierarchy is always sent, so |
| + // if there were no change in the children, they will be correctly added back |
| + // below. |
| + RemoveAllChildren(); |
| + for (int i = 0; i < proto.children_size(); ++i) { |
| + const proto::LayerNode& child_proto = proto.children(i); |
| + DCHECK(child_proto.has_type()); |
| + scoped_refptr<Layer> child = |
| + LayerProtoConverter::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_ = LayerProtoConverter::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_ = LayerProtoConverter::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); |