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

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

Issue 1887703002: cc: Add a main thread LayerListIterator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: For testing only 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"
11 #include "cc/test/fake_layer_tree_host_impl.h" 12 #include "cc/test/fake_layer_tree_host_impl.h"
12 #include "cc/test/fake_output_surface.h" 13 #include "cc/test/fake_output_surface.h"
13 #include "cc/test/test_shared_bitmap_manager.h" 14 #include "cc/test/test_shared_bitmap_manager.h"
14 #include "cc/test/test_task_graph_runner.h" 15 #include "cc/test/test_task_graph_runner.h"
15 #include "cc/trees/layer_tree_impl.h" 16 #include "cc/trees/layer_tree_impl.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 namespace cc { 19 namespace cc {
19 namespace { 20 namespace {
20 21
22 // Layer version unit tests
23
21 TEST(LayerListIteratorTest, VerifyTraversalOrder) { 24 TEST(LayerListIteratorTest, VerifyTraversalOrder) {
22 // Unfortunate preamble. 25 // 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.
23 FakeImplTaskRunnerProvider task_runner_provider; 200 FakeImplTaskRunnerProvider task_runner_provider;
24 TestSharedBitmapManager shared_bitmap_manager; 201 TestSharedBitmapManager shared_bitmap_manager;
25 TestTaskGraphRunner task_graph_runner; 202 TestTaskGraphRunner task_graph_runner;
26 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); 203 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
27 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, 204 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
28 &task_graph_runner); 205 &task_graph_runner);
29 host_impl.SetVisible(true); 206 host_impl.SetVisible(true);
30 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); 207 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get()));
31 208
32 // This test constructs the following tree. 209 // This test constructs the following tree.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 241
65 host_impl.active_tree()->SetRootLayer(std::move(layer1)); 242 host_impl.active_tree()->SetRootLayer(std::move(layer1));
66 243
67 int i = 1; 244 int i = 1;
68 for (auto* layer : *host_impl.active_tree()) { 245 for (auto* layer : *host_impl.active_tree()) {
69 EXPECT_EQ(i++, layer->id()); 246 EXPECT_EQ(i++, layer->id());
70 } 247 }
71 EXPECT_EQ(8, i); 248 EXPECT_EQ(8, i);
72 } 249 }
73 250
74 TEST(LayerListIteratorTest, VerifySingleLayer) { 251 TEST(LayerListIteratorTest, VerifySingleLayerImpl) {
75 // Unfortunate preamble. 252 // Unfortunate preamble.
76 FakeImplTaskRunnerProvider task_runner_provider; 253 FakeImplTaskRunnerProvider task_runner_provider;
77 TestSharedBitmapManager shared_bitmap_manager; 254 TestSharedBitmapManager shared_bitmap_manager;
78 TestTaskGraphRunner task_graph_runner; 255 TestTaskGraphRunner task_graph_runner;
79 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); 256 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
80 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, 257 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
81 &task_graph_runner); 258 &task_graph_runner);
82 host_impl.SetVisible(true); 259 host_impl.SetVisible(true);
83 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); 260 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get()));
84 261
85 // This test constructs a tree consisting of a single layer. 262 // This test constructs a tree consisting of a single layer.
86 std::unique_ptr<LayerImpl> layer1 = 263 std::unique_ptr<LayerImpl> layer1 =
87 LayerImpl::Create(host_impl.active_tree(), 1); 264 LayerImpl::Create(host_impl.active_tree(), 1);
88 host_impl.active_tree()->SetRootLayer(std::move(layer1)); 265 host_impl.active_tree()->SetRootLayer(std::move(layer1));
89 266
90 int i = 1; 267 int i = 1;
91 for (auto* layer : *host_impl.active_tree()) { 268 for (auto* layer : *host_impl.active_tree()) {
92 EXPECT_EQ(i++, layer->id()); 269 EXPECT_EQ(i++, layer->id());
93 } 270 }
94 EXPECT_EQ(2, i); 271 EXPECT_EQ(2, i);
95 } 272 }
96 273
97 TEST(LayerListIteratorTest, VerifyNullFirstLayer) { 274 TEST(LayerListIteratorTest, VerifyNullFirstLayerImpl) {
98 // Ensures that if an iterator is constructed with a nullptr, that it can be 275 // 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 276 // iterated without issue and that it remains equal to any other
100 // null-initialized iterator. 277 // null-initialized iterator.
101 LayerListIterator it(nullptr); 278 LayerListIterator<LayerImpl> it(nullptr);
102 LayerListIterator end(nullptr); 279 LayerListIterator<LayerImpl> end(nullptr);
103 280
104 EXPECT_EQ(it, end); 281 EXPECT_EQ(it, end);
105 ++it; 282 ++it;
106 EXPECT_EQ(it, end); 283 EXPECT_EQ(it, end);
107 } 284 }
108 285
109 TEST(LayerListReverseIteratorTest, VerifyTraversalOrder) { 286 TEST(LayerListReverseIteratorTest, VerifyTraversalOrderImpl) {
110 // Unfortunate preamble. 287 // Unfortunate preamble.
111 FakeImplTaskRunnerProvider task_runner_provider; 288 FakeImplTaskRunnerProvider task_runner_provider;
112 TestSharedBitmapManager shared_bitmap_manager; 289 TestSharedBitmapManager shared_bitmap_manager;
113 TestTaskGraphRunner task_graph_runner; 290 TestTaskGraphRunner task_graph_runner;
114 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); 291 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
115 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, 292 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
116 &task_graph_runner); 293 &task_graph_runner);
117 host_impl.SetVisible(true); 294 host_impl.SetVisible(true);
118 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); 295 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get()));
119 296
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 331
155 int i = 7; 332 int i = 7;
156 333
157 for (auto* layer : base::Reversed(*host_impl.active_tree())) { 334 for (auto* layer : base::Reversed(*host_impl.active_tree())) {
158 EXPECT_EQ(i--, layer->id()); 335 EXPECT_EQ(i--, layer->id());
159 } 336 }
160 337
161 EXPECT_EQ(0, i); 338 EXPECT_EQ(0, i);
162 } 339 }
163 340
164 TEST(LayerListReverseIteratorTest, VerifySingleLayer) { 341 TEST(LayerListReverseIteratorTest, VerifySingleLayerImpl) {
165 // Unfortunate preamble. 342 // Unfortunate preamble.
166 FakeImplTaskRunnerProvider task_runner_provider; 343 FakeImplTaskRunnerProvider task_runner_provider;
167 TestSharedBitmapManager shared_bitmap_manager; 344 TestSharedBitmapManager shared_bitmap_manager;
168 TestTaskGraphRunner task_graph_runner; 345 TestTaskGraphRunner task_graph_runner;
169 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); 346 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
170 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, 347 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
171 &task_graph_runner); 348 &task_graph_runner);
172 host_impl.SetVisible(true); 349 host_impl.SetVisible(true);
173 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); 350 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get()));
174 351
175 // This test constructs a tree consisting of a single layer. 352 // This test constructs a tree consisting of a single layer.
176 std::unique_ptr<LayerImpl> layer1 = 353 std::unique_ptr<LayerImpl> layer1 =
177 LayerImpl::Create(host_impl.active_tree(), 1); 354 LayerImpl::Create(host_impl.active_tree(), 1);
178 host_impl.active_tree()->SetRootLayer(std::move(layer1)); 355 host_impl.active_tree()->SetRootLayer(std::move(layer1));
179 356
180 int i = 1; 357 int i = 1;
181 for (auto* layer : base::Reversed(*host_impl.active_tree())) { 358 for (auto* layer : base::Reversed(*host_impl.active_tree())) {
182 EXPECT_EQ(i--, layer->id()); 359 EXPECT_EQ(i--, layer->id());
183 } 360 }
184 EXPECT_EQ(0, i); 361 EXPECT_EQ(0, i);
185 } 362 }
186 363
187 TEST(LayerListReverseIteratorTest, VerifyNullFirstLayer) { 364 TEST(LayerListReverseIteratorTest, VerifyNullFirstLayerImpl) {
188 // Ensures that if an iterator is constructed with a nullptr, that it can be 365 // Ensures that if an iterator is constructed with a nullptr, that it can be
189 // iterated without issue and that it remains equal to any other 366 // iterated without issue and that it remains equal to any other
190 // null-initialized iterator. 367 // null-initialized iterator.
191 LayerListReverseIterator it(nullptr); 368 LayerListReverseIterator<LayerImpl> it(nullptr);
192 LayerListReverseIterator end(nullptr); 369 LayerListReverseIterator<LayerImpl> end(nullptr);
193 370
194 EXPECT_EQ(it, end); 371 EXPECT_EQ(it, end);
195 ++it; 372 ++it;
196 EXPECT_EQ(it, end); 373 EXPECT_EQ(it, end);
197 } 374 }
198 375
199 } // namespace 376 } // namespace
200 } // namespace cc 377 } // 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