Chromium Code Reviews| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 tree_impl->AddLayer(std::move(new_replica)); |
| 77 return nullptr; | 77 else |
| 78 layer_impl->SetReplicaLayer(std::move(new_replica)); | |
| 79 } | |
| 78 | 80 |
| 79 std::unique_ptr<LayerImpl> layer_impl( | 81 static void SynchronizeMaskLayer(LayerImpl* layer_impl, |
| 80 ReuseOrCreateLayerImpl(old_layers, layer, tree_impl)); | 82 std::unique_ptr<LayerImpl> new_mask, |
| 83 LayerTreeImpl* tree_impl) { | |
| 84 if (layer_impl->mask_layer() && layer_impl->mask_layer() == new_mask.get()) | |
| 85 tree_impl->AddLayer(std::move(new_mask)); | |
| 86 else | |
| 87 layer_impl->SetMaskLayer(std::move(new_mask)); | |
| 88 } | |
| 81 | 89 |
| 82 layer_impl->children().clear(); | 90 template <typename LayerTreeType> |
| 83 for (size_t i = 0; i < layer->children().size(); ++i) { | 91 void PushLayerListInternal(OwnedLayerImplMap* old_layers, |
| 84 layer_impl->AddChild(SynchronizeTreesRecursiveInternal( | 92 LayerTreeType* host, |
| 85 old_layers, layer->child_at(i), tree_impl)); | 93 LayerTreeImpl* tree_impl) { |
| 94 tree_impl->ClearLayerList(); | |
| 95 for (auto* layer : *host) { | |
| 96 std::unique_ptr<LayerImpl> layer_impl( | |
| 97 ReuseOrCreateLayerImpl(old_layers, layer, tree_impl)); | |
| 98 | |
| 99 std::unique_ptr<LayerImpl> mask_layer( | |
| 100 ReuseOrCreateLayerImpl(old_layers, layer->mask_layer(), tree_impl)); | |
| 101 SynchronizeMaskLayer(layer_impl.get(), std::move(mask_layer), tree_impl); | |
| 102 | |
| 103 std::unique_ptr<LayerImpl> replica_layer( | |
| 104 ReuseOrCreateLayerImpl(old_layers, layer->replica_layer(), tree_impl)); | |
| 105 SynchronizeReplicaLayer(layer_impl.get(), std::move(replica_layer), | |
| 106 tree_impl); | |
| 107 if (layer->replica_layer()) { | |
| 108 std::unique_ptr<LayerImpl> replica_mask_layer(ReuseOrCreateLayerImpl( | |
| 109 old_layers, layer->replica_layer()->mask_layer(), tree_impl)); | |
| 110 SynchronizeMaskLayer(layer_impl->replica_layer(), | |
| 111 std::move(replica_mask_layer), tree_impl); | |
| 112 } | |
| 113 tree_impl->AddToLayerList(layer_impl.get()); | |
| 114 tree_impl->AddLayer(std::move(layer_impl)); | |
| 86 } | 115 } |
| 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 | |
| 93 // just resetting the mask layer. | |
| 94 tree_impl->AddLayer(std::move(mask_layer)); | |
| 95 } else { | |
| 96 layer_impl->SetMaskLayer(std::move(mask_layer)); | |
| 97 } | |
| 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 } | 116 } |
| 112 | 117 |
| 113 void SynchronizeTreesRecursive(OwnedLayerImplMap* old_layers, | 118 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.
| |
| 114 Layer* old_root, | 119 Layer* old_root, |
| 115 LayerTreeImpl* tree_impl) { | 120 LayerTreeImpl* tree_impl) { |
| 116 tree_impl->SetRootLayer( | 121 PushLayerListInternal(old_layers, old_root->layer_tree_host(), tree_impl); |
| 117 SynchronizeTreesRecursiveInternal(old_layers, old_root, tree_impl)); | 122 tree_impl->SetRootLayerFromLayerList(); |
| 118 } | 123 } |
| 119 | 124 |
| 120 void SynchronizeTreesRecursive(OwnedLayerImplMap* old_layers, | 125 void SynchronizeTreesRecursive(OwnedLayerImplMap* old_layers, |
| 121 LayerImpl* old_root, | 126 LayerImpl* old_root, |
| 122 LayerTreeImpl* tree_impl) { | 127 LayerTreeImpl* tree_impl) { |
| 123 tree_impl->SetRootLayer( | 128 PushLayerListInternal(old_layers, old_root->layer_tree_impl(), tree_impl); |
| 124 SynchronizeTreesRecursiveInternal(old_layers, old_root, tree_impl)); | 129 tree_impl->SetRootLayerFromLayerList(); |
| 125 } | 130 } |
| 126 | 131 |
| 127 template <typename LayerType> | 132 template <typename LayerType> |
| 128 static void PushLayerPropertiesInternal( | 133 static void PushLayerPropertiesInternal( |
| 129 std::unordered_set<LayerType*> layers_that_should_push_properties, | 134 std::unordered_set<LayerType*> layers_that_should_push_properties, |
| 130 LayerTreeImpl* impl_tree) { | 135 LayerTreeImpl* impl_tree) { |
| 131 for (auto layer : layers_that_should_push_properties) { | 136 for (auto layer : layers_that_should_push_properties) { |
| 132 LayerImpl* layer_impl = impl_tree->LayerById(layer->id()); | 137 LayerImpl* layer_impl = impl_tree->LayerById(layer->id()); |
| 133 DCHECK(layer_impl); | 138 DCHECK(layer_impl); |
| 134 layer->PushPropertiesTo(layer_impl); | 139 layer->PushPropertiesTo(layer_impl); |
| 135 } | 140 } |
| 136 } | 141 } |
| 137 | 142 |
| 138 void TreeSynchronizer::PushLayerProperties(LayerTreeImpl* pending_tree, | 143 void TreeSynchronizer::PushLayerProperties(LayerTreeImpl* pending_tree, |
| 139 LayerTreeImpl* active_tree) { | 144 LayerTreeImpl* active_tree) { |
| 140 PushLayerPropertiesInternal(pending_tree->LayersThatShouldPushProperties(), | 145 PushLayerPropertiesInternal(pending_tree->LayersThatShouldPushProperties(), |
| 141 active_tree); | 146 active_tree); |
| 142 } | 147 } |
| 143 | 148 |
| 144 void TreeSynchronizer::PushLayerProperties(LayerTreeHost* host_tree, | 149 void TreeSynchronizer::PushLayerProperties(LayerTreeHost* host_tree, |
| 145 LayerTreeImpl* impl_tree) { | 150 LayerTreeImpl* impl_tree) { |
| 146 PushLayerPropertiesInternal(host_tree->LayersThatShouldPushProperties(), | 151 PushLayerPropertiesInternal(host_tree->LayersThatShouldPushProperties(), |
| 147 impl_tree); | 152 impl_tree); |
| 148 } | 153 } |
| 149 | 154 |
| 150 } // namespace cc | 155 } // namespace cc |
| OLD | NEW |