| 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" |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 layer2->AddChild(std::move(layer3)); | 233 layer2->AddChild(std::move(layer3)); |
| 234 layer2->AddChild(std::move(layer4)); | 234 layer2->AddChild(std::move(layer4)); |
| 235 | 235 |
| 236 layer5->AddChild(std::move(layer6)); | 236 layer5->AddChild(std::move(layer6)); |
| 237 layer5->AddChild(std::move(layer7)); | 237 layer5->AddChild(std::move(layer7)); |
| 238 | 238 |
| 239 layer1->AddChild(std::move(layer2)); | 239 layer1->AddChild(std::move(layer2)); |
| 240 layer1->AddChild(std::move(layer5)); | 240 layer1->AddChild(std::move(layer5)); |
| 241 | 241 |
| 242 host_impl.active_tree()->SetRootLayer(std::move(layer1)); | 242 host_impl.active_tree()->SetRootLayer(std::move(layer1)); |
| 243 host_impl.active_tree()->BuildLayerListForTesting(); |
| 243 | 244 |
| 244 int i = 1; | 245 int i = 1; |
| 245 for (auto* layer : *host_impl.active_tree()) { | 246 for (auto* layer : *host_impl.active_tree()) { |
| 246 EXPECT_EQ(i++, layer->id()); | 247 EXPECT_EQ(i++, layer->id()); |
| 247 } | 248 } |
| 248 EXPECT_EQ(8, i); | 249 EXPECT_EQ(8, i); |
| 249 } | 250 } |
| 250 | 251 |
| 251 TEST(LayerListIteratorTest, VerifySingleLayerImpl) { | 252 TEST(LayerListIteratorTest, VerifySingleLayerImpl) { |
| 252 // Unfortunate preamble. | 253 // Unfortunate preamble. |
| 253 FakeImplTaskRunnerProvider task_runner_provider; | 254 FakeImplTaskRunnerProvider task_runner_provider; |
| 254 TestSharedBitmapManager shared_bitmap_manager; | 255 TestSharedBitmapManager shared_bitmap_manager; |
| 255 TestTaskGraphRunner task_graph_runner; | 256 TestTaskGraphRunner task_graph_runner; |
| 256 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); | 257 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); |
| 257 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | 258 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
| 258 &task_graph_runner); | 259 &task_graph_runner); |
| 259 host_impl.SetVisible(true); | 260 host_impl.SetVisible(true); |
| 260 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); | 261 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); |
| 261 | 262 |
| 262 // This test constructs a tree consisting of a single layer. | 263 // This test constructs a tree consisting of a single layer. |
| 263 std::unique_ptr<LayerImpl> layer1 = | 264 std::unique_ptr<LayerImpl> layer1 = |
| 264 LayerImpl::Create(host_impl.active_tree(), 1); | 265 LayerImpl::Create(host_impl.active_tree(), 1); |
| 265 host_impl.active_tree()->SetRootLayer(std::move(layer1)); | 266 host_impl.active_tree()->SetRootLayer(std::move(layer1)); |
| 267 host_impl.active_tree()->BuildLayerListForTesting(); |
| 266 | 268 |
| 267 int i = 1; | 269 int i = 1; |
| 268 for (auto* layer : *host_impl.active_tree()) { | 270 for (auto* layer : *host_impl.active_tree()) { |
| 269 EXPECT_EQ(i++, layer->id()); | 271 EXPECT_EQ(i++, layer->id()); |
| 270 } | 272 } |
| 271 EXPECT_EQ(2, i); | 273 EXPECT_EQ(2, i); |
| 272 } | 274 } |
| 273 | 275 |
| 274 TEST(LayerListIteratorTest, VerifyNullFirstLayerImpl) { | 276 TEST(LayerListIteratorTest, VerifyNullFirstLayerImpl) { |
| 275 // Ensures that if an iterator is constructed with a nullptr, that it can be | 277 // Ensures that if an iterator is constructed with a nullptr, that it can be |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 layer2->AddChild(std::move(layer3)); | 323 layer2->AddChild(std::move(layer3)); |
| 322 layer2->AddChild(std::move(layer4)); | 324 layer2->AddChild(std::move(layer4)); |
| 323 | 325 |
| 324 layer5->AddChild(std::move(layer6)); | 326 layer5->AddChild(std::move(layer6)); |
| 325 layer5->AddChild(std::move(layer7)); | 327 layer5->AddChild(std::move(layer7)); |
| 326 | 328 |
| 327 layer1->AddChild(std::move(layer2)); | 329 layer1->AddChild(std::move(layer2)); |
| 328 layer1->AddChild(std::move(layer5)); | 330 layer1->AddChild(std::move(layer5)); |
| 329 | 331 |
| 330 host_impl.active_tree()->SetRootLayer(std::move(layer1)); | 332 host_impl.active_tree()->SetRootLayer(std::move(layer1)); |
| 333 host_impl.active_tree()->BuildLayerListForTesting(); |
| 331 | 334 |
| 332 int i = 7; | 335 int i = 7; |
| 333 | 336 |
| 334 for (auto* layer : base::Reversed(*host_impl.active_tree())) { | 337 for (auto* layer : base::Reversed(*host_impl.active_tree())) { |
| 335 EXPECT_EQ(i--, layer->id()); | 338 EXPECT_EQ(i--, layer->id()); |
| 336 } | 339 } |
| 337 | 340 |
| 338 EXPECT_EQ(0, i); | 341 EXPECT_EQ(0, i); |
| 339 } | 342 } |
| 340 | 343 |
| 341 TEST(LayerListReverseIteratorTest, VerifySingleLayerImpl) { | 344 TEST(LayerListReverseIteratorTest, VerifySingleLayerImpl) { |
| 342 // Unfortunate preamble. | 345 // Unfortunate preamble. |
| 343 FakeImplTaskRunnerProvider task_runner_provider; | 346 FakeImplTaskRunnerProvider task_runner_provider; |
| 344 TestSharedBitmapManager shared_bitmap_manager; | 347 TestSharedBitmapManager shared_bitmap_manager; |
| 345 TestTaskGraphRunner task_graph_runner; | 348 TestTaskGraphRunner task_graph_runner; |
| 346 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); | 349 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); |
| 347 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | 350 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
| 348 &task_graph_runner); | 351 &task_graph_runner); |
| 349 host_impl.SetVisible(true); | 352 host_impl.SetVisible(true); |
| 350 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); | 353 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); |
| 351 | 354 |
| 352 // This test constructs a tree consisting of a single layer. | 355 // This test constructs a tree consisting of a single layer. |
| 353 std::unique_ptr<LayerImpl> layer1 = | 356 std::unique_ptr<LayerImpl> layer1 = |
| 354 LayerImpl::Create(host_impl.active_tree(), 1); | 357 LayerImpl::Create(host_impl.active_tree(), 1); |
| 355 host_impl.active_tree()->SetRootLayer(std::move(layer1)); | 358 host_impl.active_tree()->SetRootLayer(std::move(layer1)); |
| 359 host_impl.active_tree()->BuildLayerListForTesting(); |
| 356 | 360 |
| 357 int i = 1; | 361 int i = 1; |
| 358 for (auto* layer : base::Reversed(*host_impl.active_tree())) { | 362 for (auto* layer : base::Reversed(*host_impl.active_tree())) { |
| 359 EXPECT_EQ(i--, layer->id()); | 363 EXPECT_EQ(i--, layer->id()); |
| 360 } | 364 } |
| 361 EXPECT_EQ(0, i); | 365 EXPECT_EQ(0, i); |
| 362 } | 366 } |
| 363 | 367 |
| 364 TEST(LayerListReverseIteratorTest, VerifyNullFirstLayerImpl) { | 368 TEST(LayerListReverseIteratorTest, VerifyNullFirstLayerImpl) { |
| 365 // Ensures that if an iterator is constructed with a nullptr, that it can be | 369 // 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 | 370 // iterated without issue and that it remains equal to any other |
| 367 // null-initialized iterator. | 371 // null-initialized iterator. |
| 368 LayerListReverseIterator<LayerImpl> it(nullptr); | 372 LayerListReverseIterator<LayerImpl> it(nullptr); |
| 369 LayerListReverseIterator<LayerImpl> end(nullptr); | 373 LayerListReverseIterator<LayerImpl> end(nullptr); |
| 370 | 374 |
| 371 EXPECT_EQ(it, end); | 375 EXPECT_EQ(it, end); |
| 372 ++it; | 376 ++it; |
| 373 EXPECT_EQ(it, end); | 377 EXPECT_EQ(it, end); |
| 374 } | 378 } |
| 375 | 379 |
| 376 } // namespace | 380 } // namespace |
| 377 } // namespace cc | 381 } // namespace cc |
| OLD | NEW |