OLD | NEW |
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.h" |
12 #include "cc/test/fake_layer_tree_host_impl.h" | 12 #include "cc/test/fake_layer_tree_host_impl.h" |
13 #include "cc/test/fake_output_surface.h" | 13 #include "cc/test/fake_output_surface.h" |
14 #include "cc/test/test_shared_bitmap_manager.h" | 14 #include "cc/test/test_shared_bitmap_manager.h" |
15 #include "cc/test/test_task_graph_runner.h" | 15 #include "cc/test/test_task_graph_runner.h" |
16 #include "cc/trees/layer_tree_impl.h" | 16 #include "cc/trees/layer_tree_impl.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 namespace cc { | 19 namespace cc { |
20 namespace { | 20 namespace { |
21 | 21 |
22 // Layer version unit tests | 22 // Layer version unit tests |
23 | 23 |
24 TEST(LayerListIteratorTest, VerifyTraversalOrder) { | 24 TEST(LayerListIteratorTest, VerifyTraversalOrder) { |
25 // Unfortunate preamble. | 25 // Unfortunate preamble. |
26 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 26 FakeLayerTreeHostClient client; |
27 TestTaskGraphRunner task_graph_runner; | 27 TestTaskGraphRunner task_graph_runner; |
28 std::unique_ptr<FakeLayerTreeHost> host_ptr = | 28 std::unique_ptr<FakeLayerTreeHost> host_ptr = |
29 FakeLayerTreeHost::Create(&client, &task_graph_runner); | 29 FakeLayerTreeHost::Create(&client, &task_graph_runner); |
30 FakeLayerTreeHost* host = host_ptr.get(); | 30 FakeLayerTreeHost* host = host_ptr.get(); |
31 | 31 |
32 // This test constructs the following tree. | 32 // This test constructs the following tree. |
33 // 1 | 33 // 1 |
34 // +-2 | 34 // +-2 |
35 // | +-3 | 35 // | +-3 |
36 // | +-4 | 36 // | +-4 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 68 |
69 int i = 1; | 69 int i = 1; |
70 for (auto* layer : *host) { | 70 for (auto* layer : *host) { |
71 EXPECT_EQ(i++, layer_id_to_order[layer->id()]); | 71 EXPECT_EQ(i++, layer_id_to_order[layer->id()]); |
72 } | 72 } |
73 EXPECT_EQ(8, i); | 73 EXPECT_EQ(8, i); |
74 } | 74 } |
75 | 75 |
76 TEST(LayerListIteratorTest, VerifySingleLayer) { | 76 TEST(LayerListIteratorTest, VerifySingleLayer) { |
77 // Unfortunate preamble. | 77 // Unfortunate preamble. |
78 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 78 FakeLayerTreeHostClient client; |
79 TestTaskGraphRunner task_graph_runner; | 79 TestTaskGraphRunner task_graph_runner; |
80 std::unique_ptr<FakeLayerTreeHost> host_ptr = | 80 std::unique_ptr<FakeLayerTreeHost> host_ptr = |
81 FakeLayerTreeHost::Create(&client, &task_graph_runner); | 81 FakeLayerTreeHost::Create(&client, &task_graph_runner); |
82 FakeLayerTreeHost* host = host_ptr.get(); | 82 FakeLayerTreeHost* host = host_ptr.get(); |
83 | 83 |
84 // This test constructs a tree consisting of a single layer. | 84 // This test constructs a tree consisting of a single layer. |
85 scoped_refptr<Layer> layer1 = Layer::Create(); | 85 scoped_refptr<Layer> layer1 = Layer::Create(); |
86 std::unordered_map<int, int> layer_id_to_order; | 86 std::unordered_map<int, int> layer_id_to_order; |
87 layer_id_to_order[layer1->id()] = 1; | 87 layer_id_to_order[layer1->id()] = 1; |
88 host->SetRootLayer(std::move(layer1)); | 88 host->SetRootLayer(std::move(layer1)); |
(...skipping 12 matching lines...) Expand all Loading... |
101 LayerListIterator<Layer> it(nullptr); | 101 LayerListIterator<Layer> it(nullptr); |
102 LayerListIterator<Layer> end(nullptr); | 102 LayerListIterator<Layer> end(nullptr); |
103 | 103 |
104 EXPECT_EQ(it, end); | 104 EXPECT_EQ(it, end); |
105 ++it; | 105 ++it; |
106 EXPECT_EQ(it, end); | 106 EXPECT_EQ(it, end); |
107 } | 107 } |
108 | 108 |
109 TEST(LayerListReverseIteratorTest, VerifyTraversalOrder) { | 109 TEST(LayerListReverseIteratorTest, VerifyTraversalOrder) { |
110 // Unfortunate preamble. | 110 // Unfortunate preamble. |
111 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 111 FakeLayerTreeHostClient client; |
112 TestTaskGraphRunner task_graph_runner; | 112 TestTaskGraphRunner task_graph_runner; |
113 std::unique_ptr<FakeLayerTreeHost> host_ptr = | 113 std::unique_ptr<FakeLayerTreeHost> host_ptr = |
114 FakeLayerTreeHost::Create(&client, &task_graph_runner); | 114 FakeLayerTreeHost::Create(&client, &task_graph_runner); |
115 FakeLayerTreeHost* host = host_ptr.get(); | 115 FakeLayerTreeHost* host = host_ptr.get(); |
116 | 116 |
117 // This test constructs the following tree. | 117 // This test constructs the following tree. |
118 // 1 | 118 // 1 |
119 // +-2 | 119 // +-2 |
120 // | +-3 | 120 // | +-3 |
121 // | +-4 | 121 // | +-4 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 for (auto* layer : base::Reversed(*host)) { | 156 for (auto* layer : base::Reversed(*host)) { |
157 EXPECT_EQ(i--, layer_id_to_order[layer->id()]); | 157 EXPECT_EQ(i--, layer_id_to_order[layer->id()]); |
158 } | 158 } |
159 | 159 |
160 EXPECT_EQ(0, i); | 160 EXPECT_EQ(0, i); |
161 } | 161 } |
162 | 162 |
163 TEST(LayerListReverseIteratorTest, VerifySingleLayer) { | 163 TEST(LayerListReverseIteratorTest, VerifySingleLayer) { |
164 // Unfortunate preamble. | 164 // Unfortunate preamble. |
165 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 165 FakeLayerTreeHostClient client; |
166 TestTaskGraphRunner task_graph_runner; | 166 TestTaskGraphRunner task_graph_runner; |
167 std::unique_ptr<FakeLayerTreeHost> host_ptr = | 167 std::unique_ptr<FakeLayerTreeHost> host_ptr = |
168 FakeLayerTreeHost::Create(&client, &task_graph_runner); | 168 FakeLayerTreeHost::Create(&client, &task_graph_runner); |
169 FakeLayerTreeHost* host = host_ptr.get(); | 169 FakeLayerTreeHost* host = host_ptr.get(); |
170 | 170 |
171 // This test constructs a tree consisting of a single layer. | 171 // This test constructs a tree consisting of a single layer. |
172 scoped_refptr<Layer> layer1 = Layer::Create(); | 172 scoped_refptr<Layer> layer1 = Layer::Create(); |
173 std::unordered_map<int, int> layer_id_to_order; | 173 std::unordered_map<int, int> layer_id_to_order; |
174 layer_id_to_order[layer1->id()] = 1; | 174 layer_id_to_order[layer1->id()] = 1; |
175 host->SetRootLayer(std::move(layer1)); | 175 host->SetRootLayer(std::move(layer1)); |
(...skipping 17 matching lines...) Expand all Loading... |
193 EXPECT_EQ(it, end); | 193 EXPECT_EQ(it, end); |
194 } | 194 } |
195 | 195 |
196 // LayerImpl version unit tests | 196 // LayerImpl version unit tests |
197 | 197 |
198 TEST(LayerListIteratorTest, VerifyTraversalOrderImpl) { | 198 TEST(LayerListIteratorTest, VerifyTraversalOrderImpl) { |
199 // Unfortunate preamble. | 199 // Unfortunate preamble. |
200 FakeImplTaskRunnerProvider task_runner_provider; | 200 FakeImplTaskRunnerProvider task_runner_provider; |
201 TestSharedBitmapManager shared_bitmap_manager; | 201 TestSharedBitmapManager shared_bitmap_manager; |
202 TestTaskGraphRunner task_graph_runner; | 202 TestTaskGraphRunner task_graph_runner; |
203 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); | 203 std::unique_ptr<OutputSurface> output_surface = |
| 204 FakeOutputSurface::CreateDelegating3d(); |
204 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | 205 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
205 &task_graph_runner); | 206 &task_graph_runner); |
206 host_impl.SetVisible(true); | 207 host_impl.SetVisible(true); |
207 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); | 208 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); |
208 | 209 |
209 // This test constructs the following tree. | 210 // This test constructs the following tree. |
210 // 1 | 211 // 1 |
211 // +-2 | 212 // +-2 |
212 // | +-3 | 213 // | +-3 |
213 // | +-4 | 214 // | +-4 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 EXPECT_EQ(i++, layer->id()); | 248 EXPECT_EQ(i++, layer->id()); |
248 } | 249 } |
249 EXPECT_EQ(8, i); | 250 EXPECT_EQ(8, i); |
250 } | 251 } |
251 | 252 |
252 TEST(LayerListIteratorTest, VerifySingleLayerImpl) { | 253 TEST(LayerListIteratorTest, VerifySingleLayerImpl) { |
253 // Unfortunate preamble. | 254 // Unfortunate preamble. |
254 FakeImplTaskRunnerProvider task_runner_provider; | 255 FakeImplTaskRunnerProvider task_runner_provider; |
255 TestSharedBitmapManager shared_bitmap_manager; | 256 TestSharedBitmapManager shared_bitmap_manager; |
256 TestTaskGraphRunner task_graph_runner; | 257 TestTaskGraphRunner task_graph_runner; |
257 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); | 258 std::unique_ptr<OutputSurface> output_surface = |
| 259 FakeOutputSurface::CreateDelegating3d(); |
258 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | 260 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
259 &task_graph_runner); | 261 &task_graph_runner); |
260 host_impl.SetVisible(true); | 262 host_impl.SetVisible(true); |
261 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); | 263 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); |
262 | 264 |
263 // This test constructs a tree consisting of a single layer. | 265 // This test constructs a tree consisting of a single layer. |
264 std::unique_ptr<LayerImpl> layer1 = | 266 std::unique_ptr<LayerImpl> layer1 = |
265 LayerImpl::Create(host_impl.active_tree(), 1); | 267 LayerImpl::Create(host_impl.active_tree(), 1); |
266 host_impl.active_tree()->SetRootLayerForTesting(std::move(layer1)); | 268 host_impl.active_tree()->SetRootLayerForTesting(std::move(layer1)); |
267 host_impl.active_tree()->BuildLayerListForTesting(); | 269 host_impl.active_tree()->BuildLayerListForTesting(); |
(...skipping 15 matching lines...) Expand all Loading... |
283 EXPECT_EQ(it, end); | 285 EXPECT_EQ(it, end); |
284 ++it; | 286 ++it; |
285 EXPECT_EQ(it, end); | 287 EXPECT_EQ(it, end); |
286 } | 288 } |
287 | 289 |
288 TEST(LayerListReverseIteratorTest, VerifyTraversalOrderImpl) { | 290 TEST(LayerListReverseIteratorTest, VerifyTraversalOrderImpl) { |
289 // Unfortunate preamble. | 291 // Unfortunate preamble. |
290 FakeImplTaskRunnerProvider task_runner_provider; | 292 FakeImplTaskRunnerProvider task_runner_provider; |
291 TestSharedBitmapManager shared_bitmap_manager; | 293 TestSharedBitmapManager shared_bitmap_manager; |
292 TestTaskGraphRunner task_graph_runner; | 294 TestTaskGraphRunner task_graph_runner; |
293 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); | 295 std::unique_ptr<OutputSurface> output_surface = |
| 296 FakeOutputSurface::CreateDelegating3d(); |
294 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | 297 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
295 &task_graph_runner); | 298 &task_graph_runner); |
296 host_impl.SetVisible(true); | 299 host_impl.SetVisible(true); |
297 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); | 300 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); |
298 | 301 |
299 // This test constructs the following tree. | 302 // This test constructs the following tree. |
300 // 1 | 303 // 1 |
301 // +-2 | 304 // +-2 |
302 // | +-3 | 305 // | +-3 |
303 // | +-4 | 306 // | +-4 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 } | 342 } |
340 | 343 |
341 EXPECT_EQ(0, i); | 344 EXPECT_EQ(0, i); |
342 } | 345 } |
343 | 346 |
344 TEST(LayerListReverseIteratorTest, VerifySingleLayerImpl) { | 347 TEST(LayerListReverseIteratorTest, VerifySingleLayerImpl) { |
345 // Unfortunate preamble. | 348 // Unfortunate preamble. |
346 FakeImplTaskRunnerProvider task_runner_provider; | 349 FakeImplTaskRunnerProvider task_runner_provider; |
347 TestSharedBitmapManager shared_bitmap_manager; | 350 TestSharedBitmapManager shared_bitmap_manager; |
348 TestTaskGraphRunner task_graph_runner; | 351 TestTaskGraphRunner task_graph_runner; |
349 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); | 352 std::unique_ptr<OutputSurface> output_surface = |
| 353 FakeOutputSurface::CreateDelegating3d(); |
350 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | 354 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
351 &task_graph_runner); | 355 &task_graph_runner); |
352 host_impl.SetVisible(true); | 356 host_impl.SetVisible(true); |
353 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); | 357 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); |
354 | 358 |
355 // This test constructs a tree consisting of a single layer. | 359 // This test constructs a tree consisting of a single layer. |
356 std::unique_ptr<LayerImpl> layer1 = | 360 std::unique_ptr<LayerImpl> layer1 = |
357 LayerImpl::Create(host_impl.active_tree(), 1); | 361 LayerImpl::Create(host_impl.active_tree(), 1); |
358 host_impl.active_tree()->SetRootLayerForTesting(std::move(layer1)); | 362 host_impl.active_tree()->SetRootLayerForTesting(std::move(layer1)); |
359 host_impl.active_tree()->BuildLayerListForTesting(); | 363 host_impl.active_tree()->BuildLayerListForTesting(); |
(...skipping 12 matching lines...) Expand all Loading... |
372 LayerListReverseIterator<LayerImpl> it(nullptr); | 376 LayerListReverseIterator<LayerImpl> it(nullptr); |
373 LayerListReverseIterator<LayerImpl> end(nullptr); | 377 LayerListReverseIterator<LayerImpl> end(nullptr); |
374 | 378 |
375 EXPECT_EQ(it, end); | 379 EXPECT_EQ(it, end); |
376 ++it; | 380 ++it; |
377 EXPECT_EQ(it, end); | 381 EXPECT_EQ(it, end); |
378 } | 382 } |
379 | 383 |
380 } // namespace | 384 } // namespace |
381 } // namespace cc | 385 } // namespace cc |
OLD | NEW |