OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 #include "ui/gfx/geometry/vector2d_conversions.h" | 63 #include "ui/gfx/geometry/vector2d_conversions.h" |
64 | 64 |
65 using testing::_; | 65 using testing::_; |
66 using testing::AnyNumber; | 66 using testing::AnyNumber; |
67 using testing::AtLeast; | 67 using testing::AtLeast; |
68 using testing::Mock; | 68 using testing::Mock; |
69 | 69 |
70 namespace cc { | 70 namespace cc { |
71 namespace { | 71 namespace { |
72 | 72 |
73 class LayerTreeHostTest : public LayerTreeTest {}; | 73 class LayerTreeHostTest : public LayerTreeTest { |
| 74 public: |
| 75 LayerTreeHostTest() : contents_texture_manager_(nullptr) {} |
| 76 |
| 77 void DidInitializeOutputSurface() override { |
| 78 contents_texture_manager_ = layer_tree_host()->contents_texture_manager(); |
| 79 } |
| 80 |
| 81 protected: |
| 82 PrioritizedResourceManager* contents_texture_manager_; |
| 83 }; |
74 | 84 |
75 // Test if the LTHI receives ReadyToActivate notifications from the TileManager | 85 // Test if the LTHI receives ReadyToActivate notifications from the TileManager |
76 // when no raster tasks get scheduled. | 86 // when no raster tasks get scheduled. |
77 class LayerTreeHostTestReadyToActivateEmpty : public LayerTreeHostTest { | 87 class LayerTreeHostTestReadyToActivateEmpty : public LayerTreeHostTest { |
78 public: | 88 public: |
79 LayerTreeHostTestReadyToActivateEmpty() | 89 LayerTreeHostTestReadyToActivateEmpty() |
80 : did_notify_ready_to_activate_(false), | 90 : did_notify_ready_to_activate_(false), |
81 all_tiles_required_for_activation_are_ready_to_draw_(false), | 91 all_tiles_required_for_activation_are_ready_to_draw_(false), |
82 required_for_activation_count_(0) {} | 92 required_for_activation_count_(0) {} |
83 | 93 |
(...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1456 layer_tree_host()->SetRootLayer(layer_); | 1466 layer_tree_host()->SetRootLayer(layer_); |
1457 LayerTreeHostTest::SetupTree(); | 1467 LayerTreeHostTest::SetupTree(); |
1458 } | 1468 } |
1459 | 1469 |
1460 void BeginTest() override { | 1470 void BeginTest() override { |
1461 drew_frame_ = -1; | 1471 drew_frame_ = -1; |
1462 PostSetNeedsCommitToMainThread(); | 1472 PostSetNeedsCommitToMainThread(); |
1463 } | 1473 } |
1464 | 1474 |
1465 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { | 1475 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
1466 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates); | 1476 ASSERT_EQ(0u, impl->settings().max_partial_texture_updates); |
1467 | 1477 |
1468 TestWebGraphicsContext3D* context = TestContext(); | 1478 TestWebGraphicsContext3D* context = TestContext(); |
1469 | 1479 |
1470 switch (impl->active_tree()->source_frame_number()) { | 1480 switch (impl->active_tree()->source_frame_number()) { |
1471 case 0: | 1481 case 0: |
1472 // Number of textures should be one for each layer | 1482 // Number of textures should be one for each layer |
1473 ASSERT_EQ(2u, context->NumTextures()); | 1483 ASSERT_EQ(2u, context->NumTextures()); |
1474 // Number of textures used for commit should be one for each layer. | 1484 // Number of textures used for commit should be one for each layer. |
1475 EXPECT_EQ(2u, context->NumUsedTextures()); | 1485 EXPECT_EQ(2u, context->NumUsedTextures()); |
1476 // Verify that used texture is correct. | 1486 // Verify that used texture is correct. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 }; | 1545 }; |
1536 | 1546 |
1537 MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( | 1547 MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( |
1538 LayerTreeHostTestDirectRendererAtomicCommit); | 1548 LayerTreeHostTestDirectRendererAtomicCommit); |
1539 | 1549 |
1540 // TODO(sohanjg) : Remove it once impl-side painting ships everywhere. | 1550 // TODO(sohanjg) : Remove it once impl-side painting ships everywhere. |
1541 class LayerTreeHostTestDelegatingRendererAtomicCommit | 1551 class LayerTreeHostTestDelegatingRendererAtomicCommit |
1542 : public LayerTreeHostTestDirectRendererAtomicCommit { | 1552 : public LayerTreeHostTestDirectRendererAtomicCommit { |
1543 public: | 1553 public: |
1544 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { | 1554 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
1545 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates); | 1555 ASSERT_EQ(0u, impl->settings().max_partial_texture_updates); |
1546 | 1556 |
1547 TestWebGraphicsContext3D* context = TestContext(); | 1557 TestWebGraphicsContext3D* context = TestContext(); |
1548 | 1558 |
1549 switch (impl->active_tree()->source_frame_number()) { | 1559 switch (impl->active_tree()->source_frame_number()) { |
1550 case 0: | 1560 case 0: |
1551 // Number of textures should be one for each layer | 1561 // Number of textures should be one for each layer |
1552 ASSERT_EQ(2u, context->NumTextures()); | 1562 ASSERT_EQ(2u, context->NumTextures()); |
1553 // Number of textures used for commit should be one for each layer. | 1563 // Number of textures used for commit should be one for each layer. |
1554 EXPECT_EQ(2u, context->NumUsedTextures()); | 1564 EXPECT_EQ(2u, context->NumUsedTextures()); |
1555 // Verify that used texture is correct. | 1565 // Verify that used texture is correct. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1652 case 5: | 1662 case 5: |
1653 EndTest(); | 1663 EndTest(); |
1654 break; | 1664 break; |
1655 default: | 1665 default: |
1656 NOTREACHED() << layer_tree_host()->source_frame_number(); | 1666 NOTREACHED() << layer_tree_host()->source_frame_number(); |
1657 break; | 1667 break; |
1658 } | 1668 } |
1659 } | 1669 } |
1660 | 1670 |
1661 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { | 1671 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { |
1662 ASSERT_EQ(1u, layer_tree_host()->settings().max_partial_texture_updates); | 1672 ASSERT_EQ(1u, impl->settings().max_partial_texture_updates); |
1663 | 1673 |
1664 TestWebGraphicsContext3D* context = TestContext(); | 1674 TestWebGraphicsContext3D* context = TestContext(); |
1665 | 1675 |
1666 switch (impl->active_tree()->source_frame_number()) { | 1676 switch (impl->active_tree()->source_frame_number()) { |
1667 case 0: | 1677 case 0: |
1668 // Number of textures should be one for each layer. | 1678 // Number of textures should be one for each layer. |
1669 ASSERT_EQ(2u, context->NumTextures()); | 1679 ASSERT_EQ(2u, context->NumTextures()); |
1670 // Number of textures used for commit should be one for each layer. | 1680 // Number of textures used for commit should be one for each layer. |
1671 EXPECT_EQ(2u, context->NumUsedTextures()); | 1681 EXPECT_EQ(2u, context->NumUsedTextures()); |
1672 // Verify that used textures are correct. | 1682 // Verify that used textures are correct. |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2376 root_layer_->AddChild(child_layer1_); | 2386 root_layer_->AddChild(child_layer1_); |
2377 root_layer_->AddChild(child_layer2_); | 2387 root_layer_->AddChild(child_layer2_); |
2378 layer_tree_host()->SetRootLayer(root_layer_); | 2388 layer_tree_host()->SetRootLayer(root_layer_); |
2379 PostSetNeedsCommitToMainThread(); | 2389 PostSetNeedsCommitToMainThread(); |
2380 } | 2390 } |
2381 | 2391 |
2382 void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl, | 2392 void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl, |
2383 bool visible) override { | 2393 bool visible) override { |
2384 if (visible) { | 2394 if (visible) { |
2385 // One backing should remain unevicted. | 2395 // One backing should remain unevicted. |
2386 EXPECT_EQ( | 2396 EXPECT_EQ(100u * 100u * 4u * 1u, |
2387 100u * 100u * 4u * 1u, | 2397 contents_texture_manager_->MemoryUseBytes()); |
2388 layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); | |
2389 } else { | 2398 } else { |
2390 EXPECT_EQ( | 2399 EXPECT_EQ(0u, contents_texture_manager_->MemoryUseBytes()); |
2391 0u, layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); | |
2392 } | 2400 } |
2393 | 2401 |
2394 // Make sure that contents textures are marked as having been | 2402 // Make sure that contents textures are marked as having been |
2395 // purged. | 2403 // purged. |
2396 EXPECT_TRUE(host_impl->active_tree()->ContentsTexturesPurged()); | 2404 EXPECT_TRUE(host_impl->active_tree()->ContentsTexturesPurged()); |
2397 // End the test in this state. | 2405 // End the test in this state. |
2398 EndTest(); | 2406 EndTest(); |
2399 } | 2407 } |
2400 | 2408 |
2401 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 2409 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
2402 ++num_commits_; | 2410 ++num_commits_; |
2403 switch (num_commits_) { | 2411 switch (num_commits_) { |
2404 case 1: | 2412 case 1: |
2405 // All three backings should have memory. | 2413 // All three backings should have memory. |
2406 EXPECT_EQ( | 2414 EXPECT_EQ(100u * 100u * 4u * 3u, |
2407 100u * 100u * 4u * 3u, | 2415 contents_texture_manager_->MemoryUseBytes()); |
2408 layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); | 2416 |
2409 // Set a new policy that will kick out 1 of the 3 resources. | 2417 // Set a new policy that will kick out 1 of the 3 resources. |
2410 // Because a resource was evicted, a commit will be kicked off. | 2418 // Because a resource was evicted, a commit will be kicked off. |
2411 host_impl->SetMemoryPolicy( | 2419 host_impl->SetMemoryPolicy( |
2412 ManagedMemoryPolicy(100 * 100 * 4 * 2, | 2420 ManagedMemoryPolicy(100 * 100 * 4 * 2, |
2413 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, | 2421 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, |
2414 1000)); | 2422 1000)); |
2415 break; | 2423 break; |
2416 case 2: | 2424 case 2: |
2417 // Only two backings should have memory. | 2425 // Only two backings should have memory. |
2418 EXPECT_EQ( | 2426 EXPECT_EQ(100u * 100u * 4u * 2u, |
2419 100u * 100u * 4u * 2u, | 2427 contents_texture_manager_->MemoryUseBytes()); |
2420 layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); | |
2421 // Become backgrounded, which will cause 1 more resource to be | 2428 // Become backgrounded, which will cause 1 more resource to be |
2422 // evicted. | 2429 // evicted. |
2423 PostSetVisibleToMainThread(false); | 2430 PostSetVisibleToMainThread(false); |
2424 break; | 2431 break; |
2425 default: | 2432 default: |
2426 // No further commits should happen because this is not visible | 2433 // No further commits should happen because this is not visible |
2427 // anymore. | 2434 // anymore. |
2428 NOTREACHED(); | 2435 NOTREACHED(); |
2429 break; | 2436 break; |
2430 } | 2437 } |
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3239 break; | 3246 break; |
3240 case 4: | 3247 case 4: |
3241 // Creation after deletion: two more creates should total up to | 3248 // Creation after deletion: two more creates should total up to |
3242 // three textures. | 3249 // three textures. |
3243 ASSERT_EQ(3u, context->NumTextures()); | 3250 ASSERT_EQ(3u, context->NumTextures()); |
3244 break; | 3251 break; |
3245 } | 3252 } |
3246 } | 3253 } |
3247 | 3254 |
3248 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { | 3255 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { |
3249 if (!layer_tree_host()->settings().impl_side_painting) | 3256 if (!impl->settings().impl_side_painting) |
3250 PerformTest(impl); | 3257 PerformTest(impl); |
3251 } | 3258 } |
3252 | 3259 |
3253 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { | 3260 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
3254 if (layer_tree_host()->settings().impl_side_painting) | 3261 if (impl->settings().impl_side_painting) |
3255 PerformTest(impl); | 3262 PerformTest(impl); |
3256 } | 3263 } |
3257 | 3264 |
3258 void AfterTest() override {} | 3265 void AfterTest() override {} |
3259 | 3266 |
3260 private: | 3267 private: |
3261 // Must clear all resources before exiting. | 3268 // Must clear all resources before exiting. |
3262 void ClearResources() { | 3269 void ClearResources() { |
3263 for (int i = 0; i < num_ui_resources_; i++) | 3270 for (int i = 0; i < num_ui_resources_; i++) |
3264 ui_resources_[i] = nullptr; | 3271 ui_resources_[i] = nullptr; |
(...skipping 3292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6557 | 6564 |
6558 void AfterTest() override {} | 6565 void AfterTest() override {} |
6559 | 6566 |
6560 private: | 6567 private: |
6561 scoped_refptr<Layer> child_; | 6568 scoped_refptr<Layer> child_; |
6562 }; | 6569 }; |
6563 | 6570 |
6564 SINGLE_AND_MULTI_THREAD_TEST_F(LayerPreserveRenderSurfaceFromOutputRequests); | 6571 SINGLE_AND_MULTI_THREAD_TEST_F(LayerPreserveRenderSurfaceFromOutputRequests); |
6565 | 6572 |
6566 } // namespace cc | 6573 } // namespace cc |
OLD | NEW |