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 |
| 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, typename LayerTreeType> |
| 22 void SynchronizeTreesInternal(LayerType* layer_root, LayerTreeImpl* tree_impl) { | 22 void SynchronizeTreesInternal(LayerType* layer_root, |
|
jaydasika
2016/06/14 06:12:06
I think layer_root is a redundant argument for thi
ajuma
2016/06/14 12:45:26
Done. This also allowed merging PushLayerList and
| |
| 23 LayerTreeType* source_tree, | |
| 24 LayerTreeImpl* tree_impl, | |
| 25 PropertyTrees* property_trees) { | |
| 23 DCHECK(tree_impl); | 26 DCHECK(tree_impl); |
| 24 | 27 |
| 25 TRACE_EVENT0("cc", "TreeSynchronizer::SynchronizeTrees"); | 28 TRACE_EVENT0("cc", "TreeSynchronizer::SynchronizeTrees"); |
| 26 std::unique_ptr<OwnedLayerImplList> old_layers(tree_impl->DetachLayers()); | 29 std::unique_ptr<OwnedLayerImplList> old_layers(tree_impl->DetachLayers()); |
| 27 | 30 |
| 28 OwnedLayerImplMap old_layer_map; | 31 OwnedLayerImplMap old_layer_map; |
| 29 for (auto& it : *old_layers) | 32 for (auto& it : *old_layers) |
| 30 old_layer_map[it->id()] = std::move(it); | 33 old_layer_map[it->id()] = std::move(it); |
| 31 | 34 |
| 32 PushLayerList(&old_layer_map, layer_root, tree_impl); | 35 PushLayerList(&old_layer_map, layer_root, tree_impl); |
| 33 | 36 |
| 34 for (auto& it : old_layer_map) { | 37 for (int id : property_trees->effect_tree.mask_replica_layer_ids()) { |
| 35 if (it.second) { | 38 std::unique_ptr<LayerImpl> layer_impl(ReuseOrCreateLayerImpl( |
| 36 // Need to ensure that layer destruction doesn't tear down other layers | 39 &old_layer_map, source_tree->LayerById(id), tree_impl)); |
| 37 // linked to this LayerImpl that have been used in the new tree. | 40 tree_impl->AddLayer(std::move(layer_impl)); |
| 38 it.second->ClearLinksToOtherLayers(); | |
| 39 } | |
| 40 } | 41 } |
| 41 } | 42 } |
| 42 | 43 |
| 43 void TreeSynchronizer::SynchronizeTrees(Layer* layer_root, | 44 void TreeSynchronizer::SynchronizeTrees(Layer* layer_root, |
| 44 LayerTreeImpl* tree_impl) { | 45 LayerTreeImpl* tree_impl) { |
| 45 if (!layer_root) | 46 if (!layer_root) { |
| 46 tree_impl->DetachLayers(); | 47 tree_impl->DetachLayers(); |
| 47 else | 48 } else { |
| 48 SynchronizeTreesInternal(layer_root, tree_impl); | 49 SynchronizeTreesInternal(layer_root, layer_root->layer_tree_host(), |
| 50 tree_impl, | |
| 51 layer_root->layer_tree_host()->property_trees()); | |
| 52 } | |
| 49 } | 53 } |
| 50 | 54 |
| 51 void TreeSynchronizer::SynchronizeTrees(LayerImpl* layer_root, | 55 void TreeSynchronizer::SynchronizeTrees(LayerImpl* layer_root, |
| 52 LayerTreeImpl* tree_impl) { | 56 LayerTreeImpl* tree_impl) { |
| 53 if (!layer_root) | 57 if (!layer_root) { |
| 54 tree_impl->DetachLayers(); | 58 tree_impl->DetachLayers(); |
| 55 else | 59 } else { |
| 56 SynchronizeTreesInternal(layer_root, tree_impl); | 60 SynchronizeTreesInternal(layer_root, layer_root->layer_tree_impl(), |
| 61 tree_impl, | |
| 62 layer_root->layer_tree_impl()->property_trees()); | |
| 63 } | |
| 57 } | 64 } |
| 58 | 65 |
| 59 template <typename LayerType> | 66 template <typename LayerType> |
| 60 std::unique_ptr<LayerImpl> ReuseOrCreateLayerImpl(OwnedLayerImplMap* old_layers, | 67 std::unique_ptr<LayerImpl> ReuseOrCreateLayerImpl(OwnedLayerImplMap* old_layers, |
| 61 LayerType* layer, | 68 LayerType* layer, |
| 62 LayerTreeImpl* tree_impl) { | 69 LayerTreeImpl* tree_impl) { |
| 63 if (!layer) | 70 if (!layer) |
| 64 return nullptr; | 71 return nullptr; |
| 65 std::unique_ptr<LayerImpl> layer_impl = std::move((*old_layers)[layer->id()]); | 72 std::unique_ptr<LayerImpl> layer_impl = std::move((*old_layers)[layer->id()]); |
| 66 if (!layer_impl) | 73 if (!layer_impl) |
| 67 layer_impl = layer->CreateLayerImpl(tree_impl); | 74 layer_impl = layer->CreateLayerImpl(tree_impl); |
| 68 return layer_impl; | 75 return layer_impl; |
| 69 } | 76 } |
| 70 | 77 |
| 71 static void SynchronizeReplicaLayer(LayerImpl* layer_impl, | |
| 72 std::unique_ptr<LayerImpl> new_replica, | |
| 73 LayerTreeImpl* tree_impl) { | |
| 74 if (layer_impl->replica_layer() && | |
| 75 layer_impl->replica_layer() == new_replica.get()) { | |
| 76 // In this case, we only need to update the ownership, as we're essentially | |
| 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 } | |
| 83 | |
| 84 static void SynchronizeMaskLayer(LayerImpl* layer_impl, | |
| 85 std::unique_ptr<LayerImpl> new_mask, | |
| 86 LayerTreeImpl* tree_impl) { | |
| 87 if (layer_impl->mask_layer() && layer_impl->mask_layer() == new_mask.get()) { | |
| 88 // In this case, we only need to update the ownership, as we're essentially | |
| 89 // just resetting the mask layer. | |
| 90 tree_impl->AddLayer(std::move(new_mask)); | |
| 91 } else { | |
| 92 layer_impl->SetMaskLayer(std::move(new_mask)); | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 template <typename LayerTreeType> | 78 template <typename LayerTreeType> |
| 97 void PushLayerListInternal(OwnedLayerImplMap* old_layers, | 79 void PushLayerListInternal(OwnedLayerImplMap* old_layers, |
| 98 LayerTreeType* host, | 80 LayerTreeType* host, |
| 99 LayerTreeImpl* tree_impl) { | 81 LayerTreeImpl* tree_impl) { |
| 100 tree_impl->ClearLayerList(); | 82 tree_impl->ClearLayerList(); |
| 101 for (auto* layer : *host) { | 83 for (auto* layer : *host) { |
| 102 std::unique_ptr<LayerImpl> layer_impl( | 84 std::unique_ptr<LayerImpl> layer_impl( |
| 103 ReuseOrCreateLayerImpl(old_layers, layer, tree_impl)); | 85 ReuseOrCreateLayerImpl(old_layers, layer, tree_impl)); |
| 104 | 86 |
| 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()); | 87 tree_impl->AddToLayerList(layer_impl.get()); |
| 120 tree_impl->AddLayer(std::move(layer_impl)); | 88 tree_impl->AddLayer(std::move(layer_impl)); |
| 121 } | 89 } |
| 122 } | 90 } |
| 123 | 91 |
| 124 void PushLayerList(OwnedLayerImplMap* old_layers, | 92 void PushLayerList(OwnedLayerImplMap* old_layers, |
| 125 Layer* old_root, | 93 Layer* old_root, |
| 126 LayerTreeImpl* tree_impl) { | 94 LayerTreeImpl* tree_impl) { |
| 127 PushLayerListInternal(old_layers, old_root->layer_tree_host(), tree_impl); | 95 PushLayerListInternal(old_layers, old_root->layer_tree_host(), tree_impl); |
| 128 tree_impl->SetRootLayerFromLayerList(); | 96 tree_impl->SetRootLayerFromLayerList(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 152 active_tree); | 120 active_tree); |
| 153 } | 121 } |
| 154 | 122 |
| 155 void TreeSynchronizer::PushLayerProperties(LayerTreeHost* host_tree, | 123 void TreeSynchronizer::PushLayerProperties(LayerTreeHost* host_tree, |
| 156 LayerTreeImpl* impl_tree) { | 124 LayerTreeImpl* impl_tree) { |
| 157 PushLayerPropertiesInternal(host_tree->LayersThatShouldPushProperties(), | 125 PushLayerPropertiesInternal(host_tree->LayersThatShouldPushProperties(), |
| 158 impl_tree); | 126 impl_tree); |
| 159 } | 127 } |
| 160 | 128 |
| 161 } // namespace cc | 129 } // namespace cc |
| OLD | NEW |