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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 #include "ui/gfx/geometry/vector2d_conversions.h" | 61 #include "ui/gfx/geometry/vector2d_conversions.h" |
62 | 62 |
63 using testing::_; | 63 using testing::_; |
64 using testing::AnyNumber; | 64 using testing::AnyNumber; |
65 using testing::AtLeast; | 65 using testing::AtLeast; |
66 using testing::Mock; | 66 using testing::Mock; |
67 | 67 |
68 namespace cc { | 68 namespace cc { |
69 namespace { | 69 namespace { |
70 | 70 |
71 class LayerTreeHostTest : public LayerTreeTest {}; | 71 class LayerTreeHostTest : public LayerTreeTest { |
| 72 public: |
| 73 LayerTreeHostTest() : contents_texture_manager_(nullptr) {} |
| 74 |
| 75 void DidInitializeOutputSurface() override { |
| 76 contents_texture_manager_ = layer_tree_host()->contents_texture_manager(); |
| 77 } |
| 78 |
| 79 protected: |
| 80 PrioritizedResourceManager* contents_texture_manager_; |
| 81 }; |
72 | 82 |
73 // Test if the LTHI receives ReadyToActivate notifications from the TileManager | 83 // Test if the LTHI receives ReadyToActivate notifications from the TileManager |
74 // when no raster tasks get scheduled. | 84 // when no raster tasks get scheduled. |
75 class LayerTreeHostTestReadyToActivateEmpty : public LayerTreeHostTest { | 85 class LayerTreeHostTestReadyToActivateEmpty : public LayerTreeHostTest { |
76 public: | 86 public: |
77 LayerTreeHostTestReadyToActivateEmpty() | 87 LayerTreeHostTestReadyToActivateEmpty() |
78 : did_notify_ready_to_activate_(false), | 88 : did_notify_ready_to_activate_(false), |
79 all_tiles_required_for_activation_are_ready_to_draw_(false), | 89 all_tiles_required_for_activation_are_ready_to_draw_(false), |
80 required_for_activation_count_(0) {} | 90 required_for_activation_count_(0) {} |
81 | 91 |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 private: | 476 private: |
467 int num_draws_; | 477 int num_draws_; |
468 const gfx::Size bounds_; | 478 const gfx::Size bounds_; |
469 const gfx::Rect invalid_rect_; | 479 const gfx::Rect invalid_rect_; |
470 FakeContentLayerClient client_; | 480 FakeContentLayerClient client_; |
471 scoped_refptr<Layer> root_layer_; | 481 scoped_refptr<Layer> root_layer_; |
472 }; | 482 }; |
473 | 483 |
474 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedrawRect); | 484 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedrawRect); |
475 | 485 |
| 486 // Ensure the texture size of the pending and active trees are identical when a |
| 487 // layer is not in the viewport and a resize happens on the viewport |
| 488 class LayerTreeHostTestGpuRasterDeviceSizeChanged : public LayerTreeHostTest { |
| 489 public: |
| 490 LayerTreeHostTestGpuRasterDeviceSizeChanged() |
| 491 : num_draws_(0), bounds_(500, 64), invalid_rect_(10, 10, 20, 20) {} |
| 492 |
| 493 void BeginTest() override { |
| 494 client_.set_fill_with_nonsolid_color(true); |
| 495 root_layer_ = FakePictureLayer::Create(&client_); |
| 496 root_layer_->SetIsDrawable(true); |
| 497 gfx::Transform transform; |
| 498 // Translate the layer out of the viewport to force it to not update its |
| 499 // tile size via PushProperties. |
| 500 transform.Translate(10000.0, 10000.0); |
| 501 root_layer_->SetTransform(transform); |
| 502 root_layer_->SetBounds(bounds_); |
| 503 layer_tree_host()->SetRootLayer(root_layer_); |
| 504 layer_tree_host()->SetViewportSize(bounds_); |
| 505 |
| 506 PostSetNeedsCommitToMainThread(); |
| 507 } |
| 508 |
| 509 void InitializeSettings(LayerTreeSettings* settings) override { |
| 510 settings->gpu_rasterization_enabled = true; |
| 511 settings->gpu_rasterization_forced = true; |
| 512 } |
| 513 |
| 514 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| 515 // Perform 2 commits. |
| 516 if (!num_draws_) { |
| 517 PostSetNeedsRedrawRectToMainThread(invalid_rect_); |
| 518 } else { |
| 519 EndTest(); |
| 520 } |
| 521 num_draws_++; |
| 522 } |
| 523 |
| 524 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 525 if (num_draws_ == 2) { |
| 526 auto pending_tree = host_impl->pending_tree(); |
| 527 auto pending_layer_impl = |
| 528 static_cast<FakePictureLayerImpl*>(pending_tree->root_layer()); |
| 529 EXPECT_NE(pending_layer_impl, nullptr); |
| 530 |
| 531 auto active_tree = host_impl->pending_tree(); |
| 532 auto active_layer_impl = |
| 533 static_cast<FakePictureLayerImpl*>(active_tree->root_layer()); |
| 534 EXPECT_NE(pending_layer_impl, nullptr); |
| 535 |
| 536 auto active_tiling_set = active_layer_impl->picture_layer_tiling_set(); |
| 537 auto active_tiling = active_tiling_set->tiling_at(0); |
| 538 auto pending_tiling_set = pending_layer_impl->picture_layer_tiling_set(); |
| 539 auto pending_tiling = pending_tiling_set->tiling_at(0); |
| 540 EXPECT_EQ( |
| 541 pending_tiling->TilingDataForTesting().max_texture_size().width(), |
| 542 active_tiling->TilingDataForTesting().max_texture_size().width()); |
| 543 } |
| 544 } |
| 545 |
| 546 void DidCommitAndDrawFrame() override { |
| 547 // On the second commit, resize the viewport. |
| 548 if (num_draws_ == 1) { |
| 549 layer_tree_host()->SetViewportSize(gfx::Size(400, 64)); |
| 550 } |
| 551 } |
| 552 |
| 553 void AfterTest() override {} |
| 554 |
| 555 private: |
| 556 int num_draws_; |
| 557 const gfx::Size bounds_; |
| 558 const gfx::Rect invalid_rect_; |
| 559 FakeContentLayerClient client_; |
| 560 scoped_refptr<FakePictureLayer> root_layer_; |
| 561 }; |
| 562 |
| 563 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F( |
| 564 LayerTreeHostTestGpuRasterDeviceSizeChanged); |
| 565 |
476 class LayerTreeHostTestNoExtraCommitFromInvalidate : public LayerTreeHostTest { | 566 class LayerTreeHostTestNoExtraCommitFromInvalidate : public LayerTreeHostTest { |
477 public: | 567 public: |
478 void InitializeSettings(LayerTreeSettings* settings) override { | 568 void InitializeSettings(LayerTreeSettings* settings) override { |
479 settings->layer_transforms_should_scale_layer_contents = true; | 569 settings->layer_transforms_should_scale_layer_contents = true; |
480 } | 570 } |
481 | 571 |
482 void SetupTree() override { | 572 void SetupTree() override { |
483 root_layer_ = Layer::Create(); | 573 root_layer_ = Layer::Create(); |
484 root_layer_->SetBounds(gfx::Size(10, 20)); | 574 root_layer_->SetBounds(gfx::Size(10, 20)); |
485 root_layer_->CreateRenderSurface(); | 575 root_layer_->CreateRenderSurface(); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 | 775 |
686 SINGLE_AND_MULTI_THREAD_BLOCKNOTIFY_TEST_F( | 776 SINGLE_AND_MULTI_THREAD_BLOCKNOTIFY_TEST_F( |
687 LayerTreeHostTestSetNextCommitForcesRedraw); | 777 LayerTreeHostTestSetNextCommitForcesRedraw); |
688 | 778 |
689 // Tests that if a layer is not drawn because of some reason in the parent then | 779 // Tests that if a layer is not drawn because of some reason in the parent then |
690 // its damage is preserved until the next time it is drawn. | 780 // its damage is preserved until the next time it is drawn. |
691 class LayerTreeHostTestUndrawnLayersDamageLater : public LayerTreeHostTest { | 781 class LayerTreeHostTestUndrawnLayersDamageLater : public LayerTreeHostTest { |
692 public: | 782 public: |
693 LayerTreeHostTestUndrawnLayersDamageLater() {} | 783 LayerTreeHostTestUndrawnLayersDamageLater() {} |
694 | 784 |
| 785 void InitializeSettings(LayerTreeSettings* settings) override { |
| 786 // If we don't set the minimum contents scale, it's harder to verify whether |
| 787 // the damage we get is correct. For other scale amounts, please see |
| 788 // LayerTreeHostTestDamageWithScale. |
| 789 settings->minimum_contents_scale = 1.f; |
| 790 } |
| 791 |
695 void SetupTree() override { | 792 void SetupTree() override { |
696 if (layer_tree_host()->settings().impl_side_painting) | 793 if (layer_tree_host()->settings().impl_side_painting) |
697 root_layer_ = FakePictureLayer::Create(&client_); | 794 root_layer_ = FakePictureLayer::Create(&client_); |
698 else | 795 else |
699 root_layer_ = ContentLayer::Create(&client_); | 796 root_layer_ = ContentLayer::Create(&client_); |
700 root_layer_->SetIsDrawable(true); | 797 root_layer_->SetIsDrawable(true); |
701 root_layer_->SetBounds(gfx::Size(50, 50)); | 798 root_layer_->SetBounds(gfx::Size(50, 50)); |
702 layer_tree_host()->SetRootLayer(root_layer_); | 799 layer_tree_host()->SetRootLayer(root_layer_); |
703 | 800 |
704 // The initially transparent layer has a larger child layer, which is | 801 // The initially transparent layer has a larger child layer, which is |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 | 876 |
780 private: | 877 private: |
781 FakeContentLayerClient client_; | 878 FakeContentLayerClient client_; |
782 scoped_refptr<Layer> root_layer_; | 879 scoped_refptr<Layer> root_layer_; |
783 scoped_refptr<Layer> parent_layer_; | 880 scoped_refptr<Layer> parent_layer_; |
784 scoped_refptr<Layer> child_layer_; | 881 scoped_refptr<Layer> child_layer_; |
785 }; | 882 }; |
786 | 883 |
787 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUndrawnLayersDamageLater); | 884 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUndrawnLayersDamageLater); |
788 | 885 |
| 886 // Tests that if a layer is not drawn because of some reason in the parent then |
| 887 // its damage is preserved until the next time it is drawn. |
| 888 class LayerTreeHostTestDamageWithScale : public LayerTreeHostTest { |
| 889 public: |
| 890 LayerTreeHostTestDamageWithScale() {} |
| 891 |
| 892 void SetupTree() override { |
| 893 client_.set_fill_with_nonsolid_color(true); |
| 894 |
| 895 scoped_ptr<FakePicturePile> pile( |
| 896 new FakePicturePile(ImplSidePaintingSettings().minimum_contents_scale, |
| 897 ImplSidePaintingSettings().default_tile_grid_size)); |
| 898 root_layer_ = |
| 899 FakePictureLayer::CreateWithRecordingSource(&client_, pile.Pass()); |
| 900 root_layer_->SetBounds(gfx::Size(50, 50)); |
| 901 |
| 902 pile.reset( |
| 903 new FakePicturePile(ImplSidePaintingSettings().minimum_contents_scale, |
| 904 ImplSidePaintingSettings().default_tile_grid_size)); |
| 905 child_layer_ = |
| 906 FakePictureLayer::CreateWithRecordingSource(&client_, pile.Pass()); |
| 907 child_layer_->SetBounds(gfx::Size(25, 25)); |
| 908 child_layer_->SetIsDrawable(true); |
| 909 child_layer_->SetContentsOpaque(true); |
| 910 root_layer_->AddChild(child_layer_); |
| 911 |
| 912 layer_tree_host()->SetRootLayer(root_layer_); |
| 913 LayerTreeHostTest::SetupTree(); |
| 914 } |
| 915 |
| 916 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| 917 // Force the layer to have a tiling at 1.3f scale. Note that if we simply |
| 918 // add tiling, it will be gone by the time we draw because of aggressive |
| 919 // cleanup. AddTilingUntilNextDraw ensures that it remains there during |
| 920 // damage calculation. |
| 921 FakePictureLayerImpl* child_layer_impl = static_cast<FakePictureLayerImpl*>( |
| 922 host_impl->active_tree()->LayerById(child_layer_->id())); |
| 923 child_layer_impl->AddTilingUntilNextDraw(1.3f); |
| 924 } |
| 925 |
| 926 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 927 |
| 928 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 929 LayerTreeHostImpl::FrameData* frame_data, |
| 930 DrawResult draw_result) override { |
| 931 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
| 932 |
| 933 gfx::RectF root_damage_rect; |
| 934 if (!frame_data->render_passes.empty()) |
| 935 root_damage_rect = frame_data->render_passes.back()->damage_rect; |
| 936 |
| 937 // The first time, the whole view needs be drawn. |
| 938 // Afterwards, just the opacity of surface_layer1 is changed a few times, |
| 939 // and each damage should be the bounding box of it and its child. If this |
| 940 // was working improperly, the damage might not include its childs bounding |
| 941 // box. |
| 942 switch (host_impl->active_tree()->source_frame_number()) { |
| 943 case 0: |
| 944 EXPECT_EQ(gfx::Rect(root_layer_->bounds()), root_damage_rect); |
| 945 break; |
| 946 case 1: { |
| 947 FakePictureLayerImpl* child_layer_impl = |
| 948 static_cast<FakePictureLayerImpl*>( |
| 949 host_impl->active_tree()->LayerById(child_layer_->id())); |
| 950 // We remove tilings pretty aggressively if they are not ideal. Add this |
| 951 // back in so that we can compare |
| 952 // child_layer_impl->GetEnclosingRectInTargetSpace to the damage. |
| 953 child_layer_impl->AddTilingUntilNextDraw(1.3f); |
| 954 |
| 955 EXPECT_EQ(gfx::Rect(26, 26), root_damage_rect); |
| 956 EXPECT_EQ(child_layer_impl->GetEnclosingRectInTargetSpace(), |
| 957 root_damage_rect); |
| 958 EXPECT_TRUE(child_layer_impl->GetEnclosingRectInTargetSpace().Contains( |
| 959 gfx::Rect(child_layer_->bounds()))); |
| 960 break; |
| 961 } |
| 962 default: |
| 963 NOTREACHED(); |
| 964 } |
| 965 |
| 966 return draw_result; |
| 967 } |
| 968 |
| 969 void DidCommitAndDrawFrame() override { |
| 970 switch (layer_tree_host()->source_frame_number()) { |
| 971 case 1: { |
| 972 // Test not owning the surface. |
| 973 child_layer_->SetOpacity(0.5f); |
| 974 break; |
| 975 } |
| 976 case 2: |
| 977 EndTest(); |
| 978 break; |
| 979 default: |
| 980 NOTREACHED(); |
| 981 } |
| 982 } |
| 983 |
| 984 void AfterTest() override {} |
| 985 |
| 986 private: |
| 987 FakeContentLayerClient client_; |
| 988 scoped_refptr<Layer> root_layer_; |
| 989 scoped_refptr<Layer> child_layer_; |
| 990 }; |
| 991 |
| 992 MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestDamageWithScale); |
| 993 |
789 // Tests that if a layer is not drawn because of some reason in the parent, | 994 // Tests that if a layer is not drawn because of some reason in the parent, |
790 // causing its content bounds to not be computed, then when it is later drawn, | 995 // causing its content bounds to not be computed, then when it is later drawn, |
791 // its content bounds get pushed. | 996 // its content bounds get pushed. |
792 class LayerTreeHostTestUndrawnLayersPushContentBoundsLater | 997 class LayerTreeHostTestUndrawnLayersPushContentBoundsLater |
793 : public LayerTreeHostTest { | 998 : public LayerTreeHostTest { |
794 public: | 999 public: |
795 LayerTreeHostTestUndrawnLayersPushContentBoundsLater() | 1000 LayerTreeHostTestUndrawnLayersPushContentBoundsLater() |
796 : root_layer_(Layer::Create()) {} | 1001 : root_layer_(Layer::Create()) {} |
797 | 1002 |
798 void SetupTree() override { | 1003 void SetupTree() override { |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1339 layer_tree_host()->SetRootLayer(layer_); | 1544 layer_tree_host()->SetRootLayer(layer_); |
1340 LayerTreeHostTest::SetupTree(); | 1545 LayerTreeHostTest::SetupTree(); |
1341 } | 1546 } |
1342 | 1547 |
1343 void BeginTest() override { | 1548 void BeginTest() override { |
1344 drew_frame_ = -1; | 1549 drew_frame_ = -1; |
1345 PostSetNeedsCommitToMainThread(); | 1550 PostSetNeedsCommitToMainThread(); |
1346 } | 1551 } |
1347 | 1552 |
1348 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { | 1553 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
1349 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates); | 1554 ASSERT_EQ(0u, impl->settings().max_partial_texture_updates); |
1350 | 1555 |
1351 TestWebGraphicsContext3D* context = TestContext(); | 1556 TestWebGraphicsContext3D* context = TestContext(); |
1352 | 1557 |
1353 switch (impl->active_tree()->source_frame_number()) { | 1558 switch (impl->active_tree()->source_frame_number()) { |
1354 case 0: | 1559 case 0: |
1355 // Number of textures should be one for each layer | 1560 // Number of textures should be one for each layer |
1356 ASSERT_EQ(2u, context->NumTextures()); | 1561 ASSERT_EQ(2u, context->NumTextures()); |
1357 // Number of textures used for commit should be one for each layer. | 1562 // Number of textures used for commit should be one for each layer. |
1358 EXPECT_EQ(2u, context->NumUsedTextures()); | 1563 EXPECT_EQ(2u, context->NumUsedTextures()); |
1359 // Verify that used texture is correct. | 1564 // Verify that used texture is correct. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1418 }; | 1623 }; |
1419 | 1624 |
1420 MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( | 1625 MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( |
1421 LayerTreeHostTestDirectRendererAtomicCommit); | 1626 LayerTreeHostTestDirectRendererAtomicCommit); |
1422 | 1627 |
1423 // TODO(sohanjg) : Remove it once impl-side painting ships everywhere. | 1628 // TODO(sohanjg) : Remove it once impl-side painting ships everywhere. |
1424 class LayerTreeHostTestDelegatingRendererAtomicCommit | 1629 class LayerTreeHostTestDelegatingRendererAtomicCommit |
1425 : public LayerTreeHostTestDirectRendererAtomicCommit { | 1630 : public LayerTreeHostTestDirectRendererAtomicCommit { |
1426 public: | 1631 public: |
1427 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { | 1632 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
1428 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates); | 1633 ASSERT_EQ(0u, impl->settings().max_partial_texture_updates); |
1429 | 1634 |
1430 TestWebGraphicsContext3D* context = TestContext(); | 1635 TestWebGraphicsContext3D* context = TestContext(); |
1431 | 1636 |
1432 switch (impl->active_tree()->source_frame_number()) { | 1637 switch (impl->active_tree()->source_frame_number()) { |
1433 case 0: | 1638 case 0: |
1434 // Number of textures should be one for each layer | 1639 // Number of textures should be one for each layer |
1435 ASSERT_EQ(2u, context->NumTextures()); | 1640 ASSERT_EQ(2u, context->NumTextures()); |
1436 // Number of textures used for commit should be one for each layer. | 1641 // Number of textures used for commit should be one for each layer. |
1437 EXPECT_EQ(2u, context->NumUsedTextures()); | 1642 EXPECT_EQ(2u, context->NumUsedTextures()); |
1438 // Verify that used texture is correct. | 1643 // Verify that used texture is correct. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 case 5: | 1740 case 5: |
1536 EndTest(); | 1741 EndTest(); |
1537 break; | 1742 break; |
1538 default: | 1743 default: |
1539 NOTREACHED() << layer_tree_host()->source_frame_number(); | 1744 NOTREACHED() << layer_tree_host()->source_frame_number(); |
1540 break; | 1745 break; |
1541 } | 1746 } |
1542 } | 1747 } |
1543 | 1748 |
1544 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { | 1749 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { |
1545 ASSERT_EQ(1u, layer_tree_host()->settings().max_partial_texture_updates); | 1750 ASSERT_EQ(1u, impl->settings().max_partial_texture_updates); |
1546 | 1751 |
1547 TestWebGraphicsContext3D* context = TestContext(); | 1752 TestWebGraphicsContext3D* context = TestContext(); |
1548 | 1753 |
1549 switch (impl->active_tree()->source_frame_number()) { | 1754 switch (impl->active_tree()->source_frame_number()) { |
1550 case 0: | 1755 case 0: |
1551 // Number of textures should be one for each layer. | 1756 // Number of textures should be one for each layer. |
1552 ASSERT_EQ(2u, context->NumTextures()); | 1757 ASSERT_EQ(2u, context->NumTextures()); |
1553 // Number of textures used for commit should be one for each layer. | 1758 // Number of textures used for commit should be one for each layer. |
1554 EXPECT_EQ(2u, context->NumUsedTextures()); | 1759 EXPECT_EQ(2u, context->NumUsedTextures()); |
1555 // Verify that used textures are correct. | 1760 // Verify that used textures are correct. |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2075 int num_send_begin_main_frame_; | 2280 int num_send_begin_main_frame_; |
2076 }; | 2281 }; |
2077 | 2282 |
2078 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits); | 2283 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits); |
2079 | 2284 |
2080 class LayerTreeHostWithProxy : public LayerTreeHost { | 2285 class LayerTreeHostWithProxy : public LayerTreeHost { |
2081 public: | 2286 public: |
2082 LayerTreeHostWithProxy(FakeLayerTreeHostClient* client, | 2287 LayerTreeHostWithProxy(FakeLayerTreeHostClient* client, |
2083 const LayerTreeSettings& settings, | 2288 const LayerTreeSettings& settings, |
2084 scoped_ptr<FakeProxy> proxy) | 2289 scoped_ptr<FakeProxy> proxy) |
2085 : LayerTreeHost(client, NULL, NULL, settings) { | 2290 : LayerTreeHost(client, NULL, NULL, NULL, settings) { |
2086 proxy->SetLayerTreeHost(this); | 2291 proxy->SetLayerTreeHost(this); |
2087 client->SetLayerTreeHost(this); | 2292 client->SetLayerTreeHost(this); |
2088 InitializeForTesting(proxy.Pass()); | 2293 InitializeForTesting(proxy.Pass()); |
2089 } | 2294 } |
2090 }; | 2295 }; |
2091 | 2296 |
2092 TEST(LayerTreeHostTest, LimitPartialUpdates) { | 2297 TEST(LayerTreeHostTest, LimitPartialUpdates) { |
2093 // When partial updates are not allowed, max updates should be 0. | 2298 // When partial updates are not allowed, max updates should be 0. |
2094 { | 2299 { |
2095 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 2300 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2147 TEST(LayerTreeHostTest, PartialUpdatesWithGLRenderer) { | 2352 TEST(LayerTreeHostTest, PartialUpdatesWithGLRenderer) { |
2148 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 2353 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
2149 | 2354 |
2150 LayerTreeSettings settings; | 2355 LayerTreeSettings settings; |
2151 settings.max_partial_texture_updates = 4; | 2356 settings.max_partial_texture_updates = 4; |
2152 settings.single_thread_proxy_scheduler = false; | 2357 settings.single_thread_proxy_scheduler = false; |
2153 settings.impl_side_painting = false; | 2358 settings.impl_side_painting = false; |
2154 | 2359 |
2155 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 2360 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( |
2156 new TestSharedBitmapManager()); | 2361 new TestSharedBitmapManager()); |
2157 scoped_ptr<LayerTreeHost> host = | 2362 scoped_ptr<LayerTreeHost> host = LayerTreeHost::CreateSingleThreaded( |
2158 LayerTreeHost::CreateSingleThreaded(&client, | 2363 &client, &client, shared_bitmap_manager.get(), NULL, NULL, settings, |
2159 &client, | 2364 base::MessageLoopProxy::current(), nullptr); |
2160 shared_bitmap_manager.get(), | |
2161 NULL, | |
2162 settings, | |
2163 base::MessageLoopProxy::current(), | |
2164 nullptr); | |
2165 client.SetLayerTreeHost(host.get()); | 2365 client.SetLayerTreeHost(host.get()); |
2166 host->Composite(base::TimeTicks::Now()); | 2366 host->Composite(base::TimeTicks::Now()); |
2167 | 2367 |
2168 EXPECT_EQ(4u, host->settings().max_partial_texture_updates); | 2368 EXPECT_EQ(4u, host->settings().max_partial_texture_updates); |
2169 } | 2369 } |
2170 | 2370 |
2171 TEST(LayerTreeHostTest, PartialUpdatesWithSoftwareRenderer) { | 2371 TEST(LayerTreeHostTest, PartialUpdatesWithSoftwareRenderer) { |
2172 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_SOFTWARE); | 2372 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_SOFTWARE); |
2173 | 2373 |
2174 LayerTreeSettings settings; | 2374 LayerTreeSettings settings; |
2175 settings.max_partial_texture_updates = 4; | 2375 settings.max_partial_texture_updates = 4; |
2176 settings.single_thread_proxy_scheduler = false; | 2376 settings.single_thread_proxy_scheduler = false; |
2177 settings.impl_side_painting = false; | 2377 settings.impl_side_painting = false; |
2178 | 2378 |
2179 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 2379 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( |
2180 new TestSharedBitmapManager()); | 2380 new TestSharedBitmapManager()); |
2181 scoped_ptr<LayerTreeHost> host = | 2381 scoped_ptr<LayerTreeHost> host = LayerTreeHost::CreateSingleThreaded( |
2182 LayerTreeHost::CreateSingleThreaded(&client, | 2382 &client, &client, shared_bitmap_manager.get(), NULL, NULL, settings, |
2183 &client, | 2383 base::MessageLoopProxy::current(), nullptr); |
2184 shared_bitmap_manager.get(), | |
2185 NULL, | |
2186 settings, | |
2187 base::MessageLoopProxy::current(), | |
2188 nullptr); | |
2189 client.SetLayerTreeHost(host.get()); | 2384 client.SetLayerTreeHost(host.get()); |
2190 host->Composite(base::TimeTicks::Now()); | 2385 host->Composite(base::TimeTicks::Now()); |
2191 | 2386 |
2192 EXPECT_EQ(4u, host->settings().max_partial_texture_updates); | 2387 EXPECT_EQ(4u, host->settings().max_partial_texture_updates); |
2193 } | 2388 } |
2194 | 2389 |
2195 TEST(LayerTreeHostTest, PartialUpdatesWithDelegatingRendererAndGLContent) { | 2390 TEST(LayerTreeHostTest, PartialUpdatesWithDelegatingRendererAndGLContent) { |
2196 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DELEGATED_3D); | 2391 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DELEGATED_3D); |
2197 | 2392 |
2198 LayerTreeSettings settings; | 2393 LayerTreeSettings settings; |
2199 settings.max_partial_texture_updates = 4; | 2394 settings.max_partial_texture_updates = 4; |
2200 settings.single_thread_proxy_scheduler = false; | 2395 settings.single_thread_proxy_scheduler = false; |
2201 settings.impl_side_painting = false; | 2396 settings.impl_side_painting = false; |
2202 | 2397 |
2203 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 2398 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( |
2204 new TestSharedBitmapManager()); | 2399 new TestSharedBitmapManager()); |
2205 scoped_ptr<LayerTreeHost> host = | 2400 scoped_ptr<LayerTreeHost> host = LayerTreeHost::CreateSingleThreaded( |
2206 LayerTreeHost::CreateSingleThreaded(&client, | 2401 &client, &client, shared_bitmap_manager.get(), NULL, NULL, settings, |
2207 &client, | 2402 base::MessageLoopProxy::current(), nullptr); |
2208 shared_bitmap_manager.get(), | |
2209 NULL, | |
2210 settings, | |
2211 base::MessageLoopProxy::current(), | |
2212 nullptr); | |
2213 client.SetLayerTreeHost(host.get()); | 2403 client.SetLayerTreeHost(host.get()); |
2214 host->Composite(base::TimeTicks::Now()); | 2404 host->Composite(base::TimeTicks::Now()); |
2215 | 2405 |
2216 EXPECT_EQ(0u, host->MaxPartialTextureUpdates()); | 2406 EXPECT_EQ(0u, host->MaxPartialTextureUpdates()); |
2217 } | 2407 } |
2218 | 2408 |
2219 TEST(LayerTreeHostTest, | 2409 TEST(LayerTreeHostTest, |
2220 PartialUpdatesWithDelegatingRendererAndSoftwareContent) { | 2410 PartialUpdatesWithDelegatingRendererAndSoftwareContent) { |
2221 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DELEGATED_SOFTWARE); | 2411 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DELEGATED_SOFTWARE); |
2222 | 2412 |
2223 LayerTreeSettings settings; | 2413 LayerTreeSettings settings; |
2224 settings.max_partial_texture_updates = 4; | 2414 settings.max_partial_texture_updates = 4; |
2225 settings.single_thread_proxy_scheduler = false; | 2415 settings.single_thread_proxy_scheduler = false; |
2226 settings.impl_side_painting = false; | 2416 settings.impl_side_painting = false; |
2227 | 2417 |
2228 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 2418 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( |
2229 new TestSharedBitmapManager()); | 2419 new TestSharedBitmapManager()); |
2230 scoped_ptr<LayerTreeHost> host = | 2420 scoped_ptr<LayerTreeHost> host = LayerTreeHost::CreateSingleThreaded( |
2231 LayerTreeHost::CreateSingleThreaded(&client, | 2421 &client, &client, shared_bitmap_manager.get(), NULL, NULL, settings, |
2232 &client, | 2422 base::MessageLoopProxy::current(), nullptr); |
2233 shared_bitmap_manager.get(), | |
2234 NULL, | |
2235 settings, | |
2236 base::MessageLoopProxy::current(), | |
2237 nullptr); | |
2238 client.SetLayerTreeHost(host.get()); | 2423 client.SetLayerTreeHost(host.get()); |
2239 host->Composite(base::TimeTicks::Now()); | 2424 host->Composite(base::TimeTicks::Now()); |
2240 | 2425 |
2241 EXPECT_EQ(0u, host->MaxPartialTextureUpdates()); | 2426 EXPECT_EQ(0u, host->MaxPartialTextureUpdates()); |
2242 } | 2427 } |
2243 | 2428 |
2244 // TODO(sohanjg) : Remove it once impl-side painting ships everywhere. | 2429 // TODO(sohanjg) : Remove it once impl-side painting ships everywhere. |
2245 class LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted | 2430 class LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted |
2246 : public LayerTreeHostTest { | 2431 : public LayerTreeHostTest { |
2247 public: | 2432 public: |
(...skipping 11 matching lines...) Expand all Loading... |
2259 root_layer_->AddChild(child_layer1_); | 2444 root_layer_->AddChild(child_layer1_); |
2260 root_layer_->AddChild(child_layer2_); | 2445 root_layer_->AddChild(child_layer2_); |
2261 layer_tree_host()->SetRootLayer(root_layer_); | 2446 layer_tree_host()->SetRootLayer(root_layer_); |
2262 PostSetNeedsCommitToMainThread(); | 2447 PostSetNeedsCommitToMainThread(); |
2263 } | 2448 } |
2264 | 2449 |
2265 void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl, | 2450 void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl, |
2266 bool visible) override { | 2451 bool visible) override { |
2267 if (visible) { | 2452 if (visible) { |
2268 // One backing should remain unevicted. | 2453 // One backing should remain unevicted. |
2269 EXPECT_EQ( | 2454 EXPECT_EQ(100u * 100u * 4u * 1u, |
2270 100u * 100u * 4u * 1u, | 2455 contents_texture_manager_->MemoryUseBytes()); |
2271 layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); | |
2272 } else { | 2456 } else { |
2273 EXPECT_EQ( | 2457 EXPECT_EQ(0u, contents_texture_manager_->MemoryUseBytes()); |
2274 0u, layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); | |
2275 } | 2458 } |
2276 | 2459 |
2277 // Make sure that contents textures are marked as having been | 2460 // Make sure that contents textures are marked as having been |
2278 // purged. | 2461 // purged. |
2279 EXPECT_TRUE(host_impl->active_tree()->ContentsTexturesPurged()); | 2462 EXPECT_TRUE(host_impl->active_tree()->ContentsTexturesPurged()); |
2280 // End the test in this state. | 2463 // End the test in this state. |
2281 EndTest(); | 2464 EndTest(); |
2282 } | 2465 } |
2283 | 2466 |
2284 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 2467 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
2285 ++num_commits_; | 2468 ++num_commits_; |
2286 switch (num_commits_) { | 2469 switch (num_commits_) { |
2287 case 1: | 2470 case 1: |
2288 // All three backings should have memory. | 2471 // All three backings should have memory. |
2289 EXPECT_EQ( | 2472 EXPECT_EQ(100u * 100u * 4u * 3u, |
2290 100u * 100u * 4u * 3u, | 2473 contents_texture_manager_->MemoryUseBytes()); |
2291 layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); | 2474 |
2292 // Set a new policy that will kick out 1 of the 3 resources. | 2475 // Set a new policy that will kick out 1 of the 3 resources. |
2293 // Because a resource was evicted, a commit will be kicked off. | 2476 // Because a resource was evicted, a commit will be kicked off. |
2294 host_impl->SetMemoryPolicy( | 2477 host_impl->SetMemoryPolicy( |
2295 ManagedMemoryPolicy(100 * 100 * 4 * 2, | 2478 ManagedMemoryPolicy(100 * 100 * 4 * 2, |
2296 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, | 2479 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, |
2297 1000)); | 2480 1000)); |
2298 break; | 2481 break; |
2299 case 2: | 2482 case 2: |
2300 // Only two backings should have memory. | 2483 // Only two backings should have memory. |
2301 EXPECT_EQ( | 2484 EXPECT_EQ(100u * 100u * 4u * 2u, |
2302 100u * 100u * 4u * 2u, | 2485 contents_texture_manager_->MemoryUseBytes()); |
2303 layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); | |
2304 // Become backgrounded, which will cause 1 more resource to be | 2486 // Become backgrounded, which will cause 1 more resource to be |
2305 // evicted. | 2487 // evicted. |
2306 PostSetVisibleToMainThread(false); | 2488 PostSetVisibleToMainThread(false); |
2307 break; | 2489 break; |
2308 default: | 2490 default: |
2309 // No further commits should happen because this is not visible | 2491 // No further commits should happen because this is not visible |
2310 // anymore. | 2492 // anymore. |
2311 NOTREACHED(); | 2493 NOTREACHED(); |
2312 break; | 2494 break; |
2313 } | 2495 } |
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3122 break; | 3304 break; |
3123 case 4: | 3305 case 4: |
3124 // Creation after deletion: two more creates should total up to | 3306 // Creation after deletion: two more creates should total up to |
3125 // three textures. | 3307 // three textures. |
3126 ASSERT_EQ(3u, context->NumTextures()); | 3308 ASSERT_EQ(3u, context->NumTextures()); |
3127 break; | 3309 break; |
3128 } | 3310 } |
3129 } | 3311 } |
3130 | 3312 |
3131 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { | 3313 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { |
3132 if (!layer_tree_host()->settings().impl_side_painting) | 3314 if (!impl->settings().impl_side_painting) |
3133 PerformTest(impl); | 3315 PerformTest(impl); |
3134 } | 3316 } |
3135 | 3317 |
3136 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { | 3318 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
3137 if (layer_tree_host()->settings().impl_side_painting) | 3319 if (impl->settings().impl_side_painting) |
3138 PerformTest(impl); | 3320 PerformTest(impl); |
3139 } | 3321 } |
3140 | 3322 |
3141 void AfterTest() override {} | 3323 void AfterTest() override {} |
3142 | 3324 |
3143 private: | 3325 private: |
3144 // Must clear all resources before exiting. | 3326 // Must clear all resources before exiting. |
3145 void ClearResources() { | 3327 void ClearResources() { |
3146 for (int i = 0; i < num_ui_resources_; i++) | 3328 for (int i = 0; i < num_ui_resources_; i++) |
3147 ui_resources_[i] = nullptr; | 3329 ui_resources_[i] = nullptr; |
(...skipping 3270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6418 | 6600 |
6419 void AfterTest() override {} | 6601 void AfterTest() override {} |
6420 | 6602 |
6421 private: | 6603 private: |
6422 scoped_refptr<Layer> child_; | 6604 scoped_refptr<Layer> child_; |
6423 }; | 6605 }; |
6424 | 6606 |
6425 SINGLE_AND_MULTI_THREAD_TEST_F(LayerPreserveRenderSurfaceFromOutputRequests); | 6607 SINGLE_AND_MULTI_THREAD_TEST_F(LayerPreserveRenderSurfaceFromOutputRequests); |
6426 | 6608 |
6427 } // namespace cc | 6609 } // namespace cc |
OLD | NEW |