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

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