| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/tree_synchronizer.h" | 5 #include "cc/trees/tree_synchronizer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 13 #include "cc/layers/layer.h" | 13 #include "cc/layers/layer.h" |
| 14 #include "cc/layers/layer_collections.h" | 14 #include "cc/layers/layer_collections.h" |
| 15 #include "cc/layers/layer_impl.h" | 15 #include "cc/layers/layer_impl.h" |
| 16 #include "cc/trees/layer_tree_host.h" | 16 #include "cc/trees/layer_tree_host.h" |
| 17 #include "cc/trees/layer_tree_impl.h" | 17 #include "cc/trees/layer_tree_impl.h" |
| 18 | 18 |
| 19 namespace cc { | 19 namespace cc { |
| 20 | 20 |
| 21 template <typename LayerType> | 21 template <typename LayerType> |
| 22 void SynchronizeTreesInternal(LayerType* layer_root, LayerTreeImpl* tree_impl) { | 22 void SynchronizeTreesInternal(LayerType* layer_root, LayerTreeImpl* tree_impl) { |
| 23 DCHECK(tree_impl); | 23 DCHECK(tree_impl); |
| 24 | 24 |
| 25 TRACE_EVENT0("cc", "TreeSynchronizer::SynchronizeTrees"); | 25 TRACE_EVENT0("cc", "TreeSynchronizer::SynchronizeTrees"); |
| 26 scoped_ptr<OwnedLayerImplList> old_layers(tree_impl->DetachLayers()); | 26 std::unique_ptr<OwnedLayerImplList> old_layers(tree_impl->DetachLayers()); |
| 27 | 27 |
| 28 OwnedLayerImplMap old_layer_map; | 28 OwnedLayerImplMap old_layer_map; |
| 29 for (auto& it : *old_layers) | 29 for (auto& it : *old_layers) |
| 30 old_layer_map[it->id()] = std::move(it); | 30 old_layer_map[it->id()] = std::move(it); |
| 31 | 31 |
| 32 SynchronizeTreesRecursive(&old_layer_map, layer_root, tree_impl); | 32 SynchronizeTreesRecursive(&old_layer_map, layer_root, tree_impl); |
| 33 | 33 |
| 34 for (auto& it : old_layer_map) { | 34 for (auto& it : old_layer_map) { |
| 35 if (it.second) { | 35 if (it.second) { |
| 36 // Need to ensure that layer destruction doesn't tear down other layers | 36 // Need to ensure that layer destruction doesn't tear down other layers |
| (...skipping 13 matching lines...) Expand all Loading... |
| 50 | 50 |
| 51 void TreeSynchronizer::SynchronizeTrees(LayerImpl* layer_root, | 51 void TreeSynchronizer::SynchronizeTrees(LayerImpl* layer_root, |
| 52 LayerTreeImpl* tree_impl) { | 52 LayerTreeImpl* tree_impl) { |
| 53 if (!layer_root) | 53 if (!layer_root) |
| 54 tree_impl->ClearLayers(); | 54 tree_impl->ClearLayers(); |
| 55 else | 55 else |
| 56 SynchronizeTreesInternal(layer_root, tree_impl); | 56 SynchronizeTreesInternal(layer_root, tree_impl); |
| 57 } | 57 } |
| 58 | 58 |
| 59 template <typename LayerType> | 59 template <typename LayerType> |
| 60 scoped_ptr<LayerImpl> ReuseOrCreateLayerImpl(OwnedLayerImplMap* old_layers, | 60 std::unique_ptr<LayerImpl> ReuseOrCreateLayerImpl(OwnedLayerImplMap* old_layers, |
| 61 LayerType* layer, | 61 LayerType* layer, |
| 62 LayerTreeImpl* tree_impl) { | 62 LayerTreeImpl* tree_impl) { |
| 63 if (!layer) | 63 if (!layer) |
| 64 return nullptr; | 64 return nullptr; |
| 65 scoped_ptr<LayerImpl> layer_impl = std::move((*old_layers)[layer->id()]); | 65 std::unique_ptr<LayerImpl> layer_impl = std::move((*old_layers)[layer->id()]); |
| 66 if (!layer_impl) | 66 if (!layer_impl) |
| 67 layer_impl = layer->CreateLayerImpl(tree_impl); | 67 layer_impl = layer->CreateLayerImpl(tree_impl); |
| 68 return layer_impl; | 68 return layer_impl; |
| 69 } | 69 } |
| 70 | 70 |
| 71 template <typename LayerType> | 71 template <typename LayerType> |
| 72 scoped_ptr<LayerImpl> SynchronizeTreesRecursiveInternal( | 72 std::unique_ptr<LayerImpl> SynchronizeTreesRecursiveInternal( |
| 73 OwnedLayerImplMap* old_layers, | 73 OwnedLayerImplMap* old_layers, |
| 74 LayerType* layer, | 74 LayerType* layer, |
| 75 LayerTreeImpl* tree_impl) { | 75 LayerTreeImpl* tree_impl) { |
| 76 if (!layer) | 76 if (!layer) |
| 77 return nullptr; | 77 return nullptr; |
| 78 | 78 |
| 79 scoped_ptr<LayerImpl> layer_impl( | 79 std::unique_ptr<LayerImpl> layer_impl( |
| 80 ReuseOrCreateLayerImpl(old_layers, layer, tree_impl)); | 80 ReuseOrCreateLayerImpl(old_layers, layer, tree_impl)); |
| 81 | 81 |
| 82 layer_impl->children().clear(); | 82 layer_impl->children().clear(); |
| 83 for (size_t i = 0; i < layer->children().size(); ++i) { | 83 for (size_t i = 0; i < layer->children().size(); ++i) { |
| 84 layer_impl->AddChild(SynchronizeTreesRecursiveInternal( | 84 layer_impl->AddChild(SynchronizeTreesRecursiveInternal( |
| 85 old_layers, layer->child_at(i), tree_impl)); | 85 old_layers, layer->child_at(i), tree_impl)); |
| 86 } | 86 } |
| 87 | 87 |
| 88 scoped_ptr<LayerImpl> mask_layer = SynchronizeTreesRecursiveInternal( | 88 std::unique_ptr<LayerImpl> mask_layer = SynchronizeTreesRecursiveInternal( |
| 89 old_layers, layer->mask_layer(), tree_impl); | 89 old_layers, layer->mask_layer(), tree_impl); |
| 90 if (layer_impl->mask_layer() && mask_layer && | 90 if (layer_impl->mask_layer() && mask_layer && |
| 91 layer_impl->mask_layer() == mask_layer.get()) { | 91 layer_impl->mask_layer() == mask_layer.get()) { |
| 92 // In this case, we only need to update the ownership, as we're essentially | 92 // In this case, we only need to update the ownership, as we're essentially |
| 93 // just resetting the mask layer. | 93 // just resetting the mask layer. |
| 94 tree_impl->AddLayer(std::move(mask_layer)); | 94 tree_impl->AddLayer(std::move(mask_layer)); |
| 95 } else { | 95 } else { |
| 96 layer_impl->SetMaskLayer(std::move(mask_layer)); | 96 layer_impl->SetMaskLayer(std::move(mask_layer)); |
| 97 } | 97 } |
| 98 | 98 |
| 99 scoped_ptr<LayerImpl> replica_layer = SynchronizeTreesRecursiveInternal( | 99 std::unique_ptr<LayerImpl> replica_layer = SynchronizeTreesRecursiveInternal( |
| 100 old_layers, layer->replica_layer(), tree_impl); | 100 old_layers, layer->replica_layer(), tree_impl); |
| 101 if (layer_impl->replica_layer() && replica_layer && | 101 if (layer_impl->replica_layer() && replica_layer && |
| 102 layer_impl->replica_layer() == replica_layer.get()) { | 102 layer_impl->replica_layer() == replica_layer.get()) { |
| 103 // In this case, we only need to update the ownership, as we're essentially | 103 // In this case, we only need to update the ownership, as we're essentially |
| 104 // just resetting the replica layer. | 104 // just resetting the replica layer. |
| 105 tree_impl->AddLayer(std::move(replica_layer)); | 105 tree_impl->AddLayer(std::move(replica_layer)); |
| 106 } else { | 106 } else { |
| 107 layer_impl->SetReplicaLayer(std::move(replica_layer)); | 107 layer_impl->SetReplicaLayer(std::move(replica_layer)); |
| 108 } | 108 } |
| 109 | 109 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 PushLayerPropertiesInternal(host_tree->LayersThatShouldPushProperties(), | 203 PushLayerPropertiesInternal(host_tree->LayersThatShouldPushProperties(), |
| 204 impl_tree); | 204 impl_tree); |
| 205 | 205 |
| 206 #if DCHECK_IS_ON() | 206 #if DCHECK_IS_ON() |
| 207 if (host_tree->root_layer() && impl_tree->root_layer()) | 207 if (host_tree->root_layer() && impl_tree->root_layer()) |
| 208 CheckScrollAndClipPointers(host_tree, impl_tree); | 208 CheckScrollAndClipPointers(host_tree, impl_tree); |
| 209 #endif | 209 #endif |
| 210 } | 210 } |
| 211 | 211 |
| 212 } // namespace cc | 212 } // namespace cc |
| OLD | NEW |