Chromium Code Reviews| Index: cc/trees/tree_synchronizer.cc |
| diff --git a/cc/trees/tree_synchronizer.cc b/cc/trees/tree_synchronizer.cc |
| index ef403834b93ebd97da690dac46328f346ec45da1..004e3cdebc012a70f3440c38b6a5be6b93c235a7 100644 |
| --- a/cc/trees/tree_synchronizer.cc |
| +++ b/cc/trees/tree_synchronizer.cc |
| @@ -68,60 +68,65 @@ std::unique_ptr<LayerImpl> ReuseOrCreateLayerImpl(OwnedLayerImplMap* old_layers, |
| return layer_impl; |
| } |
| -template <typename LayerType> |
| -std::unique_ptr<LayerImpl> SynchronizeTreesRecursiveInternal( |
| - OwnedLayerImplMap* old_layers, |
| - LayerType* layer, |
| - LayerTreeImpl* tree_impl) { |
| - if (!layer) |
| - return nullptr; |
| - |
| - std::unique_ptr<LayerImpl> layer_impl( |
| - ReuseOrCreateLayerImpl(old_layers, layer, tree_impl)); |
| - |
| - layer_impl->children().clear(); |
| - for (size_t i = 0; i < layer->children().size(); ++i) { |
| - layer_impl->AddChild(SynchronizeTreesRecursiveInternal( |
| - old_layers, layer->child_at(i), tree_impl)); |
| - } |
| +static void SynchronizeReplicaLayer(LayerImpl* layer_impl, |
| + std::unique_ptr<LayerImpl> new_replica, |
| + LayerTreeImpl* tree_impl) { |
| + if (layer_impl->replica_layer() && |
| + layer_impl->replica_layer() == new_replica.get()) |
| + tree_impl->AddLayer(std::move(new_replica)); |
| + else |
| + layer_impl->SetReplicaLayer(std::move(new_replica)); |
| +} |
| - std::unique_ptr<LayerImpl> mask_layer = SynchronizeTreesRecursiveInternal( |
| - old_layers, layer->mask_layer(), tree_impl); |
| - if (layer_impl->mask_layer() && mask_layer && |
| - layer_impl->mask_layer() == mask_layer.get()) { |
| - // In this case, we only need to update the ownership, as we're essentially |
| - // just resetting the mask layer. |
| - tree_impl->AddLayer(std::move(mask_layer)); |
| - } else { |
| - layer_impl->SetMaskLayer(std::move(mask_layer)); |
| - } |
| +static void SynchronizeMaskLayer(LayerImpl* layer_impl, |
| + std::unique_ptr<LayerImpl> new_mask, |
| + LayerTreeImpl* tree_impl) { |
| + if (layer_impl->mask_layer() && layer_impl->mask_layer() == new_mask.get()) |
| + tree_impl->AddLayer(std::move(new_mask)); |
| + else |
| + layer_impl->SetMaskLayer(std::move(new_mask)); |
| +} |
| - std::unique_ptr<LayerImpl> replica_layer = SynchronizeTreesRecursiveInternal( |
| - old_layers, layer->replica_layer(), tree_impl); |
| - if (layer_impl->replica_layer() && replica_layer && |
| - layer_impl->replica_layer() == replica_layer.get()) { |
| - // In this case, we only need to update the ownership, as we're essentially |
| - // just resetting the replica layer. |
| - tree_impl->AddLayer(std::move(replica_layer)); |
| - } else { |
| - layer_impl->SetReplicaLayer(std::move(replica_layer)); |
| +template <typename LayerTreeType> |
| +void PushLayerListInternal(OwnedLayerImplMap* old_layers, |
| + LayerTreeType* host, |
| + LayerTreeImpl* tree_impl) { |
| + tree_impl->ClearLayerList(); |
| + for (auto* layer : *host) { |
| + std::unique_ptr<LayerImpl> layer_impl( |
| + ReuseOrCreateLayerImpl(old_layers, layer, tree_impl)); |
| + |
| + std::unique_ptr<LayerImpl> mask_layer( |
| + ReuseOrCreateLayerImpl(old_layers, layer->mask_layer(), tree_impl)); |
| + SynchronizeMaskLayer(layer_impl.get(), std::move(mask_layer), tree_impl); |
| + |
| + std::unique_ptr<LayerImpl> replica_layer( |
| + ReuseOrCreateLayerImpl(old_layers, layer->replica_layer(), tree_impl)); |
| + SynchronizeReplicaLayer(layer_impl.get(), std::move(replica_layer), |
| + tree_impl); |
| + if (layer->replica_layer()) { |
| + std::unique_ptr<LayerImpl> replica_mask_layer(ReuseOrCreateLayerImpl( |
| + old_layers, layer->replica_layer()->mask_layer(), tree_impl)); |
| + SynchronizeMaskLayer(layer_impl->replica_layer(), |
| + std::move(replica_mask_layer), tree_impl); |
| + } |
| + tree_impl->AddToLayerList(layer_impl.get()); |
| + tree_impl->AddLayer(std::move(layer_impl)); |
| } |
| - |
| - return layer_impl; |
| } |
| void SynchronizeTreesRecursive(OwnedLayerImplMap* old_layers, |
|
ajuma
2016/06/09 15:15:19
Nit: this isn't recursive anymore. Would PushLayer
jaydasika
2016/06/09 16:56:26
Done.
|
| Layer* old_root, |
| LayerTreeImpl* tree_impl) { |
| - tree_impl->SetRootLayer( |
| - SynchronizeTreesRecursiveInternal(old_layers, old_root, tree_impl)); |
| + PushLayerListInternal(old_layers, old_root->layer_tree_host(), tree_impl); |
| + tree_impl->SetRootLayerFromLayerList(); |
| } |
| void SynchronizeTreesRecursive(OwnedLayerImplMap* old_layers, |
| LayerImpl* old_root, |
| LayerTreeImpl* tree_impl) { |
| - tree_impl->SetRootLayer( |
| - SynchronizeTreesRecursiveInternal(old_layers, old_root, tree_impl)); |
| + PushLayerListInternal(old_layers, old_root->layer_tree_impl(), tree_impl); |
| + tree_impl->SetRootLayerFromLayerList(); |
| } |
| template <typename LayerType> |