| 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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 std::unique_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 PushLayerList(&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 |
| 37 // linked to this LayerImpl that have been used in the new tree. | 37 // linked to this LayerImpl that have been used in the new tree. |
| 38 it.second->ClearLinksToOtherLayers(); | 38 it.second->ClearLinksToOtherLayers(); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 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 std::unique_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 static void SynchronizeReplicaLayer(LayerImpl* layer_impl, |
| 72 std::unique_ptr<LayerImpl> SynchronizeTreesRecursiveInternal( | 72 std::unique_ptr<LayerImpl> new_replica, |
| 73 OwnedLayerImplMap* old_layers, | 73 LayerTreeImpl* tree_impl) { |
| 74 LayerType* layer, | 74 if (layer_impl->replica_layer() && |
| 75 LayerTreeImpl* tree_impl) { | 75 layer_impl->replica_layer() == new_replica.get()) { |
| 76 if (!layer) | 76 // In this case, we only need to update the ownership, as we're essentially |
| 77 return nullptr; | 77 // just resetting the replica layer. |
| 78 tree_impl->AddLayer(std::move(new_replica)); |
| 79 } else { |
| 80 layer_impl->SetReplicaLayer(std::move(new_replica)); |
| 81 } |
| 82 } |
| 78 | 83 |
| 79 std::unique_ptr<LayerImpl> layer_impl( | 84 static void SynchronizeMaskLayer(LayerImpl* layer_impl, |
| 80 ReuseOrCreateLayerImpl(old_layers, layer, tree_impl)); | 85 std::unique_ptr<LayerImpl> new_mask, |
| 81 | 86 LayerTreeImpl* tree_impl) { |
| 82 layer_impl->children().clear(); | 87 if (layer_impl->mask_layer() && layer_impl->mask_layer() == new_mask.get()) { |
| 83 for (size_t i = 0; i < layer->children().size(); ++i) { | |
| 84 layer_impl->AddChild(SynchronizeTreesRecursiveInternal( | |
| 85 old_layers, layer->child_at(i), tree_impl)); | |
| 86 } | |
| 87 | |
| 88 std::unique_ptr<LayerImpl> mask_layer = SynchronizeTreesRecursiveInternal( | |
| 89 old_layers, layer->mask_layer(), tree_impl); | |
| 90 if (layer_impl->mask_layer() && mask_layer && | |
| 91 layer_impl->mask_layer() == mask_layer.get()) { | |
| 92 // In this case, we only need to update the ownership, as we're essentially | 88 // In this case, we only need to update the ownership, as we're essentially |
| 93 // just resetting the mask layer. | 89 // just resetting the mask layer. |
| 94 tree_impl->AddLayer(std::move(mask_layer)); | 90 tree_impl->AddLayer(std::move(new_mask)); |
| 95 } else { | 91 } else { |
| 96 layer_impl->SetMaskLayer(std::move(mask_layer)); | 92 layer_impl->SetMaskLayer(std::move(new_mask)); |
| 97 } | 93 } |
| 98 | |
| 99 std::unique_ptr<LayerImpl> replica_layer = SynchronizeTreesRecursiveInternal( | |
| 100 old_layers, layer->replica_layer(), tree_impl); | |
| 101 if (layer_impl->replica_layer() && replica_layer && | |
| 102 layer_impl->replica_layer() == replica_layer.get()) { | |
| 103 // In this case, we only need to update the ownership, as we're essentially | |
| 104 // just resetting the replica layer. | |
| 105 tree_impl->AddLayer(std::move(replica_layer)); | |
| 106 } else { | |
| 107 layer_impl->SetReplicaLayer(std::move(replica_layer)); | |
| 108 } | |
| 109 | |
| 110 return layer_impl; | |
| 111 } | 94 } |
| 112 | 95 |
| 113 void SynchronizeTreesRecursive(OwnedLayerImplMap* old_layers, | 96 template <typename LayerTreeType> |
| 114 Layer* old_root, | 97 void PushLayerListInternal(OwnedLayerImplMap* old_layers, |
| 115 LayerTreeImpl* tree_impl) { | 98 LayerTreeType* host, |
| 116 tree_impl->SetRootLayer( | 99 LayerTreeImpl* tree_impl) { |
| 117 SynchronizeTreesRecursiveInternal(old_layers, old_root, tree_impl)); | 100 tree_impl->ClearLayerList(); |
| 101 for (auto* layer : *host) { |
| 102 std::unique_ptr<LayerImpl> layer_impl( |
| 103 ReuseOrCreateLayerImpl(old_layers, layer, tree_impl)); |
| 104 |
| 105 std::unique_ptr<LayerImpl> mask_layer( |
| 106 ReuseOrCreateLayerImpl(old_layers, layer->mask_layer(), tree_impl)); |
| 107 SynchronizeMaskLayer(layer_impl.get(), std::move(mask_layer), tree_impl); |
| 108 |
| 109 std::unique_ptr<LayerImpl> replica_layer( |
| 110 ReuseOrCreateLayerImpl(old_layers, layer->replica_layer(), tree_impl)); |
| 111 SynchronizeReplicaLayer(layer_impl.get(), std::move(replica_layer), |
| 112 tree_impl); |
| 113 if (layer->replica_layer()) { |
| 114 std::unique_ptr<LayerImpl> replica_mask_layer(ReuseOrCreateLayerImpl( |
| 115 old_layers, layer->replica_layer()->mask_layer(), tree_impl)); |
| 116 SynchronizeMaskLayer(layer_impl->replica_layer(), |
| 117 std::move(replica_mask_layer), tree_impl); |
| 118 } |
| 119 tree_impl->AddToLayerList(layer_impl.get()); |
| 120 tree_impl->AddLayer(std::move(layer_impl)); |
| 121 } |
| 118 } | 122 } |
| 119 | 123 |
| 120 void SynchronizeTreesRecursive(OwnedLayerImplMap* old_layers, | 124 void PushLayerList(OwnedLayerImplMap* old_layers, |
| 121 LayerImpl* old_root, | 125 Layer* old_root, |
| 122 LayerTreeImpl* tree_impl) { | 126 LayerTreeImpl* tree_impl) { |
| 123 tree_impl->SetRootLayer( | 127 PushLayerListInternal(old_layers, old_root->layer_tree_host(), tree_impl); |
| 124 SynchronizeTreesRecursiveInternal(old_layers, old_root, tree_impl)); | 128 tree_impl->SetRootLayerFromLayerList(); |
| 129 } |
| 130 |
| 131 void PushLayerList(OwnedLayerImplMap* old_layers, |
| 132 LayerImpl* old_root, |
| 133 LayerTreeImpl* tree_impl) { |
| 134 PushLayerListInternal(old_layers, old_root->layer_tree_impl(), tree_impl); |
| 135 tree_impl->SetRootLayerFromLayerList(); |
| 125 } | 136 } |
| 126 | 137 |
| 127 template <typename LayerType> | 138 template <typename LayerType> |
| 128 static void PushLayerPropertiesInternal( | 139 static void PushLayerPropertiesInternal( |
| 129 std::unordered_set<LayerType*> layers_that_should_push_properties, | 140 std::unordered_set<LayerType*> layers_that_should_push_properties, |
| 130 LayerTreeImpl* impl_tree) { | 141 LayerTreeImpl* impl_tree) { |
| 131 for (auto layer : layers_that_should_push_properties) { | 142 for (auto layer : layers_that_should_push_properties) { |
| 132 LayerImpl* layer_impl = impl_tree->LayerById(layer->id()); | 143 LayerImpl* layer_impl = impl_tree->LayerById(layer->id()); |
| 133 DCHECK(layer_impl); | 144 DCHECK(layer_impl); |
| 134 layer->PushPropertiesTo(layer_impl); | 145 layer->PushPropertiesTo(layer_impl); |
| 135 } | 146 } |
| 136 } | 147 } |
| 137 | 148 |
| 138 void TreeSynchronizer::PushLayerProperties(LayerTreeImpl* pending_tree, | 149 void TreeSynchronizer::PushLayerProperties(LayerTreeImpl* pending_tree, |
| 139 LayerTreeImpl* active_tree) { | 150 LayerTreeImpl* active_tree) { |
| 140 PushLayerPropertiesInternal(pending_tree->LayersThatShouldPushProperties(), | 151 PushLayerPropertiesInternal(pending_tree->LayersThatShouldPushProperties(), |
| 141 active_tree); | 152 active_tree); |
| 142 } | 153 } |
| 143 | 154 |
| 144 void TreeSynchronizer::PushLayerProperties(LayerTreeHost* host_tree, | 155 void TreeSynchronizer::PushLayerProperties(LayerTreeHost* host_tree, |
| 145 LayerTreeImpl* impl_tree) { | 156 LayerTreeImpl* impl_tree) { |
| 146 PushLayerPropertiesInternal(host_tree->LayersThatShouldPushProperties(), | 157 PushLayerPropertiesInternal(host_tree->LayersThatShouldPushProperties(), |
| 147 impl_tree); | 158 impl_tree); |
| 148 } | 159 } |
| 149 | 160 |
| 150 } // namespace cc | 161 } // namespace cc |
| OLD | NEW |