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

Side by Side Diff: cc/layers/layer_list_iterator_unittest.cc

Issue 1900723002: Revert of cc: Add a main thread LayerListIterator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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/layers/layer_list_iterator.cc ('k') | cc/trees/layer_tree_host.h » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/layers/layer_list_iterator.h" 5 #include "cc/layers/layer_list_iterator.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/containers/adapters.h" 9 #include "base/containers/adapters.h"
10 #include "cc/test/fake_impl_task_runner_provider.h" 10 #include "cc/test/fake_impl_task_runner_provider.h"
11 #include "cc/test/fake_layer_tree_host.h"
12 #include "cc/test/fake_layer_tree_host_impl.h" 11 #include "cc/test/fake_layer_tree_host_impl.h"
13 #include "cc/test/fake_output_surface.h" 12 #include "cc/test/fake_output_surface.h"
14 #include "cc/test/test_shared_bitmap_manager.h" 13 #include "cc/test/test_shared_bitmap_manager.h"
15 #include "cc/test/test_task_graph_runner.h" 14 #include "cc/test/test_task_graph_runner.h"
16 #include "cc/trees/layer_tree_impl.h" 15 #include "cc/trees/layer_tree_impl.h"
17 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
18 17
19 namespace cc { 18 namespace cc {
20 namespace { 19 namespace {
21 20
22 // Layer version unit tests
23
24 TEST(LayerListIteratorTest, VerifyTraversalOrder) { 21 TEST(LayerListIteratorTest, VerifyTraversalOrder) {
25 // Unfortunate preamble. 22 // Unfortunate preamble.
26 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
27 TestTaskGraphRunner task_graph_runner;
28 std::unique_ptr<FakeLayerTreeHost> host_ptr =
29 FakeLayerTreeHost::Create(&client, &task_graph_runner);
30 FakeLayerTreeHost* host = host_ptr.get();
31
32 // This test constructs the following tree.
33 // 1
34 // +-2
35 // | +-3
36 // | +-4
37 // + 5
38 // +-6
39 // +-7
40 // We expect to visit all seven layers in that order.
41 scoped_refptr<Layer> layer1 = Layer::Create();
42 scoped_refptr<Layer> layer2 = Layer::Create();
43 scoped_refptr<Layer> layer3 = Layer::Create();
44 scoped_refptr<Layer> layer4 = Layer::Create();
45 scoped_refptr<Layer> layer5 = Layer::Create();
46 scoped_refptr<Layer> layer6 = Layer::Create();
47 scoped_refptr<Layer> layer7 = Layer::Create();
48
49 std::unordered_map<int, int> layer_id_to_order;
50 layer_id_to_order[layer1->id()] = 1;
51 layer_id_to_order[layer2->id()] = 2;
52 layer_id_to_order[layer3->id()] = 3;
53 layer_id_to_order[layer4->id()] = 4;
54 layer_id_to_order[layer5->id()] = 5;
55 layer_id_to_order[layer6->id()] = 6;
56 layer_id_to_order[layer7->id()] = 7;
57
58 layer2->AddChild(std::move(layer3));
59 layer2->AddChild(std::move(layer4));
60
61 layer5->AddChild(std::move(layer6));
62 layer5->AddChild(std::move(layer7));
63
64 layer1->AddChild(std::move(layer2));
65 layer1->AddChild(std::move(layer5));
66
67 host->SetRootLayer(std::move(layer1));
68
69 int i = 1;
70 for (auto* layer : *host) {
71 EXPECT_EQ(i++, layer_id_to_order[layer->id()]);
72 }
73 EXPECT_EQ(8, i);
74 }
75
76 TEST(LayerListIteratorTest, VerifySingleLayer) {
77 // Unfortunate preamble.
78 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
79 TestTaskGraphRunner task_graph_runner;
80 std::unique_ptr<FakeLayerTreeHost> host_ptr =
81 FakeLayerTreeHost::Create(&client, &task_graph_runner);
82 FakeLayerTreeHost* host = host_ptr.get();
83
84 // This test constructs a tree consisting of a single layer.
85 scoped_refptr<Layer> layer1 = Layer::Create();
86 std::unordered_map<int, int> layer_id_to_order;
87 layer_id_to_order[layer1->id()] = 1;
88 host->SetRootLayer(std::move(layer1));
89
90 int i = 1;
91 for (auto* layer : *host) {
92 EXPECT_EQ(i++, layer_id_to_order[layer->id()]);
93 }
94 EXPECT_EQ(2, i);
95 }
96
97 TEST(LayerListIteratorTest, VerifyNullFirstLayer) {
98 // Ensures that if an iterator is constructed with a nullptr, that it can be
99 // iterated without issue and that it remains equal to any other
100 // null-initialized iterator.
101 LayerListIterator<Layer> it(nullptr);
102 LayerListIterator<Layer> end(nullptr);
103
104 EXPECT_EQ(it, end);
105 ++it;
106 EXPECT_EQ(it, end);
107 }
108
109 TEST(LayerListReverseIteratorTest, VerifyTraversalOrder) {
110 // Unfortunate preamble.
111 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
112 TestTaskGraphRunner task_graph_runner;
113 std::unique_ptr<FakeLayerTreeHost> host_ptr =
114 FakeLayerTreeHost::Create(&client, &task_graph_runner);
115 FakeLayerTreeHost* host = host_ptr.get();
116
117 // This test constructs the following tree.
118 // 1
119 // +-2
120 // | +-3
121 // | +-4
122 // + 5
123 // +-6
124 // +-7
125 // We expect to visit all seven layers in reverse order.
126 scoped_refptr<Layer> layer1 = Layer::Create();
127 scoped_refptr<Layer> layer2 = Layer::Create();
128 scoped_refptr<Layer> layer3 = Layer::Create();
129 scoped_refptr<Layer> layer4 = Layer::Create();
130 scoped_refptr<Layer> layer5 = Layer::Create();
131 scoped_refptr<Layer> layer6 = Layer::Create();
132 scoped_refptr<Layer> layer7 = Layer::Create();
133
134 std::unordered_map<int, int> layer_id_to_order;
135 layer_id_to_order[layer1->id()] = 1;
136 layer_id_to_order[layer2->id()] = 2;
137 layer_id_to_order[layer3->id()] = 3;
138 layer_id_to_order[layer4->id()] = 4;
139 layer_id_to_order[layer5->id()] = 5;
140 layer_id_to_order[layer6->id()] = 6;
141 layer_id_to_order[layer7->id()] = 7;
142
143 layer2->AddChild(std::move(layer3));
144 layer2->AddChild(std::move(layer4));
145
146 layer5->AddChild(std::move(layer6));
147 layer5->AddChild(std::move(layer7));
148
149 layer1->AddChild(std::move(layer2));
150 layer1->AddChild(std::move(layer5));
151
152 host->SetRootLayer(std::move(layer1));
153
154 int i = 7;
155
156 for (auto* layer : base::Reversed(*host)) {
157 EXPECT_EQ(i--, layer_id_to_order[layer->id()]);
158 }
159
160 EXPECT_EQ(0, i);
161 }
162
163 TEST(LayerListReverseIteratorTest, VerifySingleLayer) {
164 // Unfortunate preamble.
165 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
166 TestTaskGraphRunner task_graph_runner;
167 std::unique_ptr<FakeLayerTreeHost> host_ptr =
168 FakeLayerTreeHost::Create(&client, &task_graph_runner);
169 FakeLayerTreeHost* host = host_ptr.get();
170
171 // This test constructs a tree consisting of a single layer.
172 scoped_refptr<Layer> layer1 = Layer::Create();
173 std::unordered_map<int, int> layer_id_to_order;
174 layer_id_to_order[layer1->id()] = 1;
175 host->SetRootLayer(std::move(layer1));
176
177 int i = 1;
178 for (auto* layer : base::Reversed(*host)) {
179 EXPECT_EQ(i--, layer_id_to_order[layer->id()]);
180 }
181 EXPECT_EQ(0, i);
182 }
183
184 TEST(LayerListReverseIteratorTest, VerifyNullFirstLayer) {
185 // Ensures that if an iterator is constructed with a nullptr, that it can be
186 // iterated without issue and that it remains equal to any other
187 // null-initialized iterator.
188 LayerListReverseIterator<Layer> it(nullptr);
189 LayerListReverseIterator<Layer> end(nullptr);
190
191 EXPECT_EQ(it, end);
192 ++it;
193 EXPECT_EQ(it, end);
194 }
195
196 // LayerImpl version unit tests
197
198 TEST(LayerListIteratorTest, VerifyTraversalOrderImpl) {
199 // Unfortunate preamble.
200 FakeImplTaskRunnerProvider task_runner_provider; 23 FakeImplTaskRunnerProvider task_runner_provider;
201 TestSharedBitmapManager shared_bitmap_manager; 24 TestSharedBitmapManager shared_bitmap_manager;
202 TestTaskGraphRunner task_graph_runner; 25 TestTaskGraphRunner task_graph_runner;
203 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); 26 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
204 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, 27 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
205 &task_graph_runner); 28 &task_graph_runner);
206 host_impl.SetVisible(true); 29 host_impl.SetVisible(true);
207 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); 30 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get()));
208 31
209 // This test constructs the following tree. 32 // This test constructs the following tree.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 64
242 host_impl.active_tree()->SetRootLayer(std::move(layer1)); 65 host_impl.active_tree()->SetRootLayer(std::move(layer1));
243 66
244 int i = 1; 67 int i = 1;
245 for (auto* layer : *host_impl.active_tree()) { 68 for (auto* layer : *host_impl.active_tree()) {
246 EXPECT_EQ(i++, layer->id()); 69 EXPECT_EQ(i++, layer->id());
247 } 70 }
248 EXPECT_EQ(8, i); 71 EXPECT_EQ(8, i);
249 } 72 }
250 73
251 TEST(LayerListIteratorTest, VerifySingleLayerImpl) { 74 TEST(LayerListIteratorTest, VerifySingleLayer) {
252 // Unfortunate preamble. 75 // Unfortunate preamble.
253 FakeImplTaskRunnerProvider task_runner_provider; 76 FakeImplTaskRunnerProvider task_runner_provider;
254 TestSharedBitmapManager shared_bitmap_manager; 77 TestSharedBitmapManager shared_bitmap_manager;
255 TestTaskGraphRunner task_graph_runner; 78 TestTaskGraphRunner task_graph_runner;
256 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); 79 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
257 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, 80 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
258 &task_graph_runner); 81 &task_graph_runner);
259 host_impl.SetVisible(true); 82 host_impl.SetVisible(true);
260 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); 83 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get()));
261 84
262 // This test constructs a tree consisting of a single layer. 85 // This test constructs a tree consisting of a single layer.
263 std::unique_ptr<LayerImpl> layer1 = 86 std::unique_ptr<LayerImpl> layer1 =
264 LayerImpl::Create(host_impl.active_tree(), 1); 87 LayerImpl::Create(host_impl.active_tree(), 1);
265 host_impl.active_tree()->SetRootLayer(std::move(layer1)); 88 host_impl.active_tree()->SetRootLayer(std::move(layer1));
266 89
267 int i = 1; 90 int i = 1;
268 for (auto* layer : *host_impl.active_tree()) { 91 for (auto* layer : *host_impl.active_tree()) {
269 EXPECT_EQ(i++, layer->id()); 92 EXPECT_EQ(i++, layer->id());
270 } 93 }
271 EXPECT_EQ(2, i); 94 EXPECT_EQ(2, i);
272 } 95 }
273 96
274 TEST(LayerListIteratorTest, VerifyNullFirstLayerImpl) { 97 TEST(LayerListIteratorTest, VerifyNullFirstLayer) {
275 // Ensures that if an iterator is constructed with a nullptr, that it can be 98 // Ensures that if an iterator is constructed with a nullptr, that it can be
276 // iterated without issue and that it remains equal to any other 99 // iterated without issue and that it remains equal to any other
277 // null-initialized iterator. 100 // null-initialized iterator.
278 LayerListIterator<LayerImpl> it(nullptr); 101 LayerListIterator it(nullptr);
279 LayerListIterator<LayerImpl> end(nullptr); 102 LayerListIterator end(nullptr);
280 103
281 EXPECT_EQ(it, end); 104 EXPECT_EQ(it, end);
282 ++it; 105 ++it;
283 EXPECT_EQ(it, end); 106 EXPECT_EQ(it, end);
284 } 107 }
285 108
286 TEST(LayerListReverseIteratorTest, VerifyTraversalOrderImpl) { 109 TEST(LayerListReverseIteratorTest, VerifyTraversalOrder) {
287 // Unfortunate preamble. 110 // Unfortunate preamble.
288 FakeImplTaskRunnerProvider task_runner_provider; 111 FakeImplTaskRunnerProvider task_runner_provider;
289 TestSharedBitmapManager shared_bitmap_manager; 112 TestSharedBitmapManager shared_bitmap_manager;
290 TestTaskGraphRunner task_graph_runner; 113 TestTaskGraphRunner task_graph_runner;
291 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); 114 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
292 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, 115 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
293 &task_graph_runner); 116 &task_graph_runner);
294 host_impl.SetVisible(true); 117 host_impl.SetVisible(true);
295 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); 118 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get()));
296 119
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 154
332 int i = 7; 155 int i = 7;
333 156
334 for (auto* layer : base::Reversed(*host_impl.active_tree())) { 157 for (auto* layer : base::Reversed(*host_impl.active_tree())) {
335 EXPECT_EQ(i--, layer->id()); 158 EXPECT_EQ(i--, layer->id());
336 } 159 }
337 160
338 EXPECT_EQ(0, i); 161 EXPECT_EQ(0, i);
339 } 162 }
340 163
341 TEST(LayerListReverseIteratorTest, VerifySingleLayerImpl) { 164 TEST(LayerListReverseIteratorTest, VerifySingleLayer) {
342 // Unfortunate preamble. 165 // Unfortunate preamble.
343 FakeImplTaskRunnerProvider task_runner_provider; 166 FakeImplTaskRunnerProvider task_runner_provider;
344 TestSharedBitmapManager shared_bitmap_manager; 167 TestSharedBitmapManager shared_bitmap_manager;
345 TestTaskGraphRunner task_graph_runner; 168 TestTaskGraphRunner task_graph_runner;
346 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); 169 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
347 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, 170 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
348 &task_graph_runner); 171 &task_graph_runner);
349 host_impl.SetVisible(true); 172 host_impl.SetVisible(true);
350 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); 173 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get()));
351 174
352 // This test constructs a tree consisting of a single layer. 175 // This test constructs a tree consisting of a single layer.
353 std::unique_ptr<LayerImpl> layer1 = 176 std::unique_ptr<LayerImpl> layer1 =
354 LayerImpl::Create(host_impl.active_tree(), 1); 177 LayerImpl::Create(host_impl.active_tree(), 1);
355 host_impl.active_tree()->SetRootLayer(std::move(layer1)); 178 host_impl.active_tree()->SetRootLayer(std::move(layer1));
356 179
357 int i = 1; 180 int i = 1;
358 for (auto* layer : base::Reversed(*host_impl.active_tree())) { 181 for (auto* layer : base::Reversed(*host_impl.active_tree())) {
359 EXPECT_EQ(i--, layer->id()); 182 EXPECT_EQ(i--, layer->id());
360 } 183 }
361 EXPECT_EQ(0, i); 184 EXPECT_EQ(0, i);
362 } 185 }
363 186
364 TEST(LayerListReverseIteratorTest, VerifyNullFirstLayerImpl) { 187 TEST(LayerListReverseIteratorTest, VerifyNullFirstLayer) {
365 // Ensures that if an iterator is constructed with a nullptr, that it can be 188 // Ensures that if an iterator is constructed with a nullptr, that it can be
366 // iterated without issue and that it remains equal to any other 189 // iterated without issue and that it remains equal to any other
367 // null-initialized iterator. 190 // null-initialized iterator.
368 LayerListReverseIterator<LayerImpl> it(nullptr); 191 LayerListReverseIterator it(nullptr);
369 LayerListReverseIterator<LayerImpl> end(nullptr); 192 LayerListReverseIterator end(nullptr);
370 193
371 EXPECT_EQ(it, end); 194 EXPECT_EQ(it, end);
372 ++it; 195 ++it;
373 EXPECT_EQ(it, end); 196 EXPECT_EQ(it, end);
374 } 197 }
375 198
376 } // namespace 199 } // namespace
377 } // namespace cc 200 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer_list_iterator.cc ('k') | cc/trees/layer_tree_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698