Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: cc/trees/tree_synchronizer.cc

Issue 2035863003: cc: Add mask and replica layer ids to the effect tree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/property_tree_unittest.cc ('k') | cc/trees/tree_synchronizer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 LayerTreeType>
22 void SynchronizeTreesInternal(LayerType* layer_root, LayerTreeImpl* tree_impl) { 22 void SynchronizeTreesInternal(LayerTreeType* source_tree,
23 LayerTreeImpl* tree_impl,
24 PropertyTrees* property_trees) {
23 DCHECK(tree_impl); 25 DCHECK(tree_impl);
24 26
25 TRACE_EVENT0("cc", "TreeSynchronizer::SynchronizeTrees"); 27 TRACE_EVENT0("cc", "TreeSynchronizer::SynchronizeTrees");
26 std::unique_ptr<OwnedLayerImplList> old_layers(tree_impl->DetachLayers()); 28 std::unique_ptr<OwnedLayerImplList> old_layers(tree_impl->DetachLayers());
27 29
28 OwnedLayerImplMap old_layer_map; 30 OwnedLayerImplMap old_layer_map;
29 for (auto& it : *old_layers) 31 for (auto& it : *old_layers)
30 old_layer_map[it->id()] = std::move(it); 32 old_layer_map[it->id()] = std::move(it);
31 33
32 PushLayerList(&old_layer_map, layer_root, tree_impl); 34 PushLayerList(&old_layer_map, source_tree, tree_impl);
33 35
34 for (auto& it : old_layer_map) { 36 for (int id : property_trees->effect_tree.mask_replica_layer_ids()) {
35 if (it.second) { 37 std::unique_ptr<LayerImpl> layer_impl(ReuseOrCreateLayerImpl(
36 // Need to ensure that layer destruction doesn't tear down other layers 38 &old_layer_map, source_tree->LayerById(id), tree_impl));
37 // linked to this LayerImpl that have been used in the new tree. 39 tree_impl->AddLayer(std::move(layer_impl));
38 it.second->ClearLinksToOtherLayers();
39 }
40 } 40 }
41 } 41 }
42 42
43 void TreeSynchronizer::SynchronizeTrees(Layer* layer_root, 43 void TreeSynchronizer::SynchronizeTrees(Layer* layer_root,
44 LayerTreeImpl* tree_impl) { 44 LayerTreeImpl* tree_impl) {
45 if (!layer_root) 45 if (!layer_root) {
46 tree_impl->DetachLayers(); 46 tree_impl->DetachLayers();
47 else 47 } else {
48 SynchronizeTreesInternal(layer_root, tree_impl); 48 SynchronizeTreesInternal(layer_root->layer_tree_host(), tree_impl,
49 layer_root->layer_tree_host()->property_trees());
50 }
49 } 51 }
50 52
51 void TreeSynchronizer::SynchronizeTrees(LayerImpl* layer_root, 53 void TreeSynchronizer::SynchronizeTrees(LayerImpl* layer_root,
52 LayerTreeImpl* tree_impl) { 54 LayerTreeImpl* tree_impl) {
53 if (!layer_root) 55 if (!layer_root) {
54 tree_impl->DetachLayers(); 56 tree_impl->DetachLayers();
55 else 57 } else {
56 SynchronizeTreesInternal(layer_root, tree_impl); 58 SynchronizeTreesInternal(layer_root->layer_tree_impl(), tree_impl,
59 layer_root->layer_tree_impl()->property_trees());
60 }
57 } 61 }
58 62
59 template <typename LayerType> 63 template <typename LayerType>
60 std::unique_ptr<LayerImpl> ReuseOrCreateLayerImpl(OwnedLayerImplMap* old_layers, 64 std::unique_ptr<LayerImpl> ReuseOrCreateLayerImpl(OwnedLayerImplMap* old_layers,
61 LayerType* layer, 65 LayerType* layer,
62 LayerTreeImpl* tree_impl) { 66 LayerTreeImpl* tree_impl) {
63 if (!layer) 67 if (!layer)
64 return nullptr; 68 return nullptr;
65 std::unique_ptr<LayerImpl> layer_impl = std::move((*old_layers)[layer->id()]); 69 std::unique_ptr<LayerImpl> layer_impl = std::move((*old_layers)[layer->id()]);
66 if (!layer_impl) 70 if (!layer_impl)
67 layer_impl = layer->CreateLayerImpl(tree_impl); 71 layer_impl = layer->CreateLayerImpl(tree_impl);
68 return layer_impl; 72 return layer_impl;
69 } 73 }
70 74
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> 75 template <typename LayerTreeType>
97 void PushLayerListInternal(OwnedLayerImplMap* old_layers, 76 void PushLayerList(OwnedLayerImplMap* old_layers,
98 LayerTreeType* host, 77 LayerTreeType* host,
99 LayerTreeImpl* tree_impl) { 78 LayerTreeImpl* tree_impl) {
100 tree_impl->ClearLayerList(); 79 tree_impl->ClearLayerList();
101 for (auto* layer : *host) { 80 for (auto* layer : *host) {
102 std::unique_ptr<LayerImpl> layer_impl( 81 std::unique_ptr<LayerImpl> layer_impl(
103 ReuseOrCreateLayerImpl(old_layers, layer, tree_impl)); 82 ReuseOrCreateLayerImpl(old_layers, layer, tree_impl));
104 83
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()); 84 tree_impl->AddToLayerList(layer_impl.get());
120 tree_impl->AddLayer(std::move(layer_impl)); 85 tree_impl->AddLayer(std::move(layer_impl));
121 } 86 }
122 }
123
124 void PushLayerList(OwnedLayerImplMap* old_layers,
125 Layer* old_root,
126 LayerTreeImpl* tree_impl) {
127 PushLayerListInternal(old_layers, old_root->layer_tree_host(), tree_impl);
128 tree_impl->SetRootLayerFromLayerList(); 87 tree_impl->SetRootLayerFromLayerList();
129 } 88 }
130 89
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();
136 }
137
138 template <typename LayerType> 90 template <typename LayerType>
139 static void PushLayerPropertiesInternal( 91 static void PushLayerPropertiesInternal(
140 std::unordered_set<LayerType*> layers_that_should_push_properties, 92 std::unordered_set<LayerType*> layers_that_should_push_properties,
141 LayerTreeImpl* impl_tree) { 93 LayerTreeImpl* impl_tree) {
142 for (auto layer : layers_that_should_push_properties) { 94 for (auto layer : layers_that_should_push_properties) {
143 LayerImpl* layer_impl = impl_tree->LayerById(layer->id()); 95 LayerImpl* layer_impl = impl_tree->LayerById(layer->id());
144 DCHECK(layer_impl); 96 DCHECK(layer_impl);
145 layer->PushPropertiesTo(layer_impl); 97 layer->PushPropertiesTo(layer_impl);
146 } 98 }
147 } 99 }
148 100
149 void TreeSynchronizer::PushLayerProperties(LayerTreeImpl* pending_tree, 101 void TreeSynchronizer::PushLayerProperties(LayerTreeImpl* pending_tree,
150 LayerTreeImpl* active_tree) { 102 LayerTreeImpl* active_tree) {
151 PushLayerPropertiesInternal(pending_tree->LayersThatShouldPushProperties(), 103 PushLayerPropertiesInternal(pending_tree->LayersThatShouldPushProperties(),
152 active_tree); 104 active_tree);
153 } 105 }
154 106
155 void TreeSynchronizer::PushLayerProperties(LayerTreeHost* host_tree, 107 void TreeSynchronizer::PushLayerProperties(LayerTreeHost* host_tree,
156 LayerTreeImpl* impl_tree) { 108 LayerTreeImpl* impl_tree) {
157 PushLayerPropertiesInternal(host_tree->LayersThatShouldPushProperties(), 109 PushLayerPropertiesInternal(host_tree->LayersThatShouldPushProperties(),
158 impl_tree); 110 impl_tree);
159 } 111 }
160 112
161 } // namespace cc 113 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/property_tree_unittest.cc ('k') | cc/trees/tree_synchronizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698