| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "cc/layers/layer_iterator.h" | 11 #include "cc/layers/layer_iterator.h" |
| 12 #include "cc/output/copy_output_request.h" | 12 #include "cc/output/copy_output_request.h" |
| 13 #include "cc/output/copy_output_result.h" | 13 #include "cc/output/copy_output_result.h" |
| 14 #include "cc/output/direct_renderer.h" | |
| 15 #include "cc/surfaces/display.h" | |
| 16 #include "cc/test/fake_content_layer_client.h" | 14 #include "cc/test/fake_content_layer_client.h" |
| 17 #include "cc/test/fake_output_surface.h" | 15 #include "cc/test/fake_output_surface.h" |
| 18 #include "cc/test/fake_picture_layer.h" | 16 #include "cc/test/fake_picture_layer.h" |
| 19 #include "cc/test/layer_tree_test.h" | 17 #include "cc/test/layer_tree_test.h" |
| 20 #include "cc/test/test_delegating_output_surface.h" | |
| 21 #include "cc/trees/layer_tree_impl.h" | 18 #include "cc/trees/layer_tree_impl.h" |
| 22 #include "gpu/GLES2/gl2extchromium.h" | 19 #include "gpu/GLES2/gl2extchromium.h" |
| 23 | 20 |
| 24 namespace cc { | 21 namespace cc { |
| 25 namespace { | 22 namespace { |
| 26 | 23 |
| 27 // These tests only use direct rendering, as there is no output to copy for | 24 // These tests only use direct rendering, as there is no output to copy for |
| 28 // delegated renderers. | 25 // delegated renderers. |
| 29 class LayerTreeHostCopyRequestTest : public LayerTreeTest {}; | 26 class LayerTreeHostCopyRequestTest : public LayerTreeTest {}; |
| 30 | 27 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); | 119 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
| 123 EXPECT_TRUE(result->HasBitmap()); | 120 EXPECT_TRUE(result->HasBitmap()); |
| 124 std::unique_ptr<SkBitmap> bitmap = result->TakeBitmap(); | 121 std::unique_ptr<SkBitmap> bitmap = result->TakeBitmap(); |
| 125 EXPECT_EQ(result->size().ToString(), | 122 EXPECT_EQ(result->size().ToString(), |
| 126 gfx::Size(bitmap->width(), bitmap->height()).ToString()); | 123 gfx::Size(bitmap->width(), bitmap->height()).ToString()); |
| 127 callbacks_[id] = result->size(); | 124 callbacks_[id] = result->size(); |
| 128 } | 125 } |
| 129 | 126 |
| 130 void AfterTest() override { EXPECT_EQ(4u, callbacks_.size()); } | 127 void AfterTest() override { EXPECT_EQ(4u, callbacks_.size()); } |
| 131 | 128 |
| 132 std::unique_ptr<OutputSurface> CreateDisplayOutputSurface( | 129 std::unique_ptr<OutputSurface> CreateOutputSurface() override { |
| 133 scoped_refptr<ContextProvider> compositor_context_provider) override { | |
| 134 if (!use_gl_renderer_) { | 130 if (!use_gl_renderer_) { |
| 135 return FakeOutputSurface::CreateSoftware( | 131 return FakeOutputSurface::CreateSoftware( |
| 136 base::WrapUnique(new SoftwareOutputDevice)); | 132 base::WrapUnique(new SoftwareOutputDevice)); |
| 137 } | 133 } |
| 138 | 134 |
| 139 scoped_refptr<TestContextProvider> display_context_provider = | 135 std::unique_ptr<FakeOutputSurface> output_surface = |
| 140 TestContextProvider::Create(); | 136 FakeOutputSurface::Create3d(TestContextProvider::Create(), |
| 141 TestContextSupport* context_support = display_context_provider->support(); | 137 TestContextProvider::CreateWorker()); |
| 138 TestContextSupport* context_support = static_cast<TestContextSupport*>( |
| 139 output_surface->context_provider()->ContextSupport()); |
| 142 context_support->set_out_of_order_callbacks(out_of_order_callbacks_); | 140 context_support->set_out_of_order_callbacks(out_of_order_callbacks_); |
| 143 | 141 return std::move(output_surface); |
| 144 return FakeOutputSurface::Create3d(std::move(display_context_provider)); | |
| 145 } | 142 } |
| 146 | 143 |
| 147 bool use_gl_renderer_; | 144 bool use_gl_renderer_; |
| 148 bool out_of_order_callbacks_ = false; | 145 bool out_of_order_callbacks_ = false; |
| 149 std::map<size_t, gfx::Size> callbacks_; | 146 std::map<size_t, gfx::Size> callbacks_; |
| 150 FakeContentLayerClient client_; | 147 FakeContentLayerClient client_; |
| 151 scoped_refptr<FakePictureLayer> root; | 148 scoped_refptr<FakePictureLayer> root; |
| 152 scoped_refptr<FakePictureLayer> child; | 149 scoped_refptr<FakePictureLayer> child; |
| 153 scoped_refptr<FakePictureLayer> grand_child; | 150 scoped_refptr<FakePictureLayer> grand_child; |
| 154 }; | 151 }; |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 | 456 |
| 460 copy_layer_ = FakePictureLayer::Create(&client_); | 457 copy_layer_ = FakePictureLayer::Create(&client_); |
| 461 copy_layer_->SetBounds(gfx::Size(10, 10)); | 458 copy_layer_->SetBounds(gfx::Size(10, 10)); |
| 462 parent_layer_->AddChild(copy_layer_); | 459 parent_layer_->AddChild(copy_layer_); |
| 463 | 460 |
| 464 layer_tree_host()->SetRootLayer(root_); | 461 layer_tree_host()->SetRootLayer(root_); |
| 465 LayerTreeHostCopyRequestTest::SetupTree(); | 462 LayerTreeHostCopyRequestTest::SetupTree(); |
| 466 client_.set_bounds(root_->bounds()); | 463 client_.set_bounds(root_->bounds()); |
| 467 } | 464 } |
| 468 | 465 |
| 469 std::unique_ptr<TestDelegatingOutputSurface> CreateDelegatingOutputSurface( | |
| 470 scoped_refptr<ContextProvider> compositor_context_provider, | |
| 471 scoped_refptr<ContextProvider> worker_context_provider) override { | |
| 472 auto surface = LayerTreeHostCopyRequestTest::CreateDelegatingOutputSurface( | |
| 473 std::move(compositor_context_provider), | |
| 474 std::move(worker_context_provider)); | |
| 475 display_ = surface->display(); | |
| 476 return surface; | |
| 477 } | |
| 478 | |
| 479 void BeginTest() override { | 466 void BeginTest() override { |
| 467 did_draw_ = false; |
| 480 PostSetNeedsCommitToMainThread(); | 468 PostSetNeedsCommitToMainThread(); |
| 481 | 469 |
| 482 copy_layer_->RequestCopyOfOutput( | 470 copy_layer_->RequestCopyOfOutput( |
| 483 CopyOutputRequest::CreateBitmapRequest(base::Bind( | 471 CopyOutputRequest::CreateBitmapRequest(base::Bind( |
| 484 &LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest:: | 472 &LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest:: |
| 485 CopyOutputCallback, | 473 CopyOutputCallback, |
| 486 base::Unretained(this)))); | 474 base::Unretained(this)))); |
| 487 } | 475 } |
| 488 | 476 |
| 489 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) { | 477 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) { |
| 490 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); | 478 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
| 491 EXPECT_EQ(copy_layer_->bounds().ToString(), result->size().ToString()); | 479 EXPECT_EQ(copy_layer_->bounds().ToString(), result->size().ToString()); |
| 492 EndTest(); | 480 EndTest(); |
| 493 } | 481 } |
| 494 | 482 |
| 495 void DisplayWillDrawAndSwapOnThread( | 483 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| 496 bool will_draw_and_swap, | 484 Renderer* renderer = host_impl->renderer(); |
| 497 const RenderPassList& render_passes) override { | |
| 498 EXPECT_TRUE(will_draw_and_swap) << did_swap_; | |
| 499 if (did_swap_) { | |
| 500 // TODO(crbug.com/564832): Ignore the extra frame that occurs due to copy | |
| 501 // completion. This can be removed when the extra commit is removed. | |
| 502 EXPECT_EQ(1u, render_passes.size()); | |
| 503 return; | |
| 504 } | |
| 505 | 485 |
| 506 EXPECT_EQ(2u, render_passes.size()); | 486 LayerImpl* parent = |
| 507 // The root pass is the back of the list. | 487 host_impl->active_tree()->LayerById(parent_layer_->id()); |
| 508 copy_layer_render_pass_id = render_passes[0]->id; | 488 LayerImpl* copy_layer = |
| 509 parent_render_pass_id = render_passes[1]->id; | 489 host_impl->active_tree()->LayerById(copy_layer_->id()); |
| 510 } | |
| 511 | |
| 512 void DisplayDidDrawAndSwapOnThread() override { | |
| 513 DirectRenderer* renderer = display_->renderer_for_testing(); | |
| 514 | 490 |
| 515 // |parent| owns a surface, but it was hidden and not part of the copy | 491 // |parent| owns a surface, but it was hidden and not part of the copy |
| 516 // request so it should not allocate any resource. | 492 // request so it should not allocate any resource. |
| 517 EXPECT_FALSE( | 493 EXPECT_FALSE(renderer->HasAllocatedResourcesForTesting( |
| 518 renderer->HasAllocatedResourcesForTesting(parent_render_pass_id)); | 494 parent->render_surface()->GetRenderPassId())); |
| 519 | 495 |
| 520 // TODO(crbug.com/564832): Ignore the extra frame that occurs due to copy | 496 // |copy_layer| should have been rendered to a texture since it was needed |
| 521 // completion. This can be removed when the extra commit is removed. | 497 // for a copy request. |
| 522 if (did_swap_) { | 498 if (did_draw_) { |
| 523 EXPECT_FALSE( | 499 // TODO(crbug.com/564832): Ignore the extra frame that occurs due to copy |
| 524 renderer->HasAllocatedResourcesForTesting(copy_layer_render_pass_id)); | 500 // completion. This can be removed when the extra commit is removed. |
| 501 EXPECT_FALSE(copy_layer->render_surface()); |
| 525 } else { | 502 } else { |
| 526 // |copy_layer| should have been rendered to a texture since it was needed | 503 EXPECT_TRUE(renderer->HasAllocatedResourcesForTesting( |
| 527 // for a copy request. | 504 copy_layer->render_surface()->GetRenderPassId())); |
| 528 EXPECT_TRUE( | |
| 529 renderer->HasAllocatedResourcesForTesting(copy_layer_render_pass_id)); | |
| 530 } | 505 } |
| 531 | 506 |
| 532 did_swap_ = true; | 507 did_draw_ = true; |
| 533 } | 508 } |
| 534 | 509 |
| 535 void AfterTest() override { EXPECT_TRUE(did_swap_); } | 510 void AfterTest() override { EXPECT_TRUE(did_draw_); } |
| 536 | 511 |
| 537 RenderPassId parent_render_pass_id; | |
| 538 RenderPassId copy_layer_render_pass_id; | |
| 539 Display* display_ = nullptr; | |
| 540 bool did_swap_ = false; | |
| 541 FakeContentLayerClient client_; | 512 FakeContentLayerClient client_; |
| 513 bool did_draw_; |
| 542 scoped_refptr<FakePictureLayer> root_; | 514 scoped_refptr<FakePictureLayer> root_; |
| 543 scoped_refptr<FakePictureLayer> grand_parent_layer_; | 515 scoped_refptr<FakePictureLayer> grand_parent_layer_; |
| 544 scoped_refptr<FakePictureLayer> parent_layer_; | 516 scoped_refptr<FakePictureLayer> parent_layer_; |
| 545 scoped_refptr<FakePictureLayer> copy_layer_; | 517 scoped_refptr<FakePictureLayer> copy_layer_; |
| 546 }; | 518 }; |
| 547 | 519 |
| 548 // No output to copy for delegated renderers. | 520 // No output to copy for delegated renderers. |
| 549 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 521 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 550 LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest); | 522 LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest); |
| 551 | 523 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 bool saw_copy_request_; | 700 bool saw_copy_request_; |
| 729 int callback_count_; | 701 int callback_count_; |
| 730 FakeContentLayerClient client_; | 702 FakeContentLayerClient client_; |
| 731 scoped_refptr<FakePictureLayer> root_; | 703 scoped_refptr<FakePictureLayer> root_; |
| 732 scoped_refptr<FakePictureLayer> copy_layer_; | 704 scoped_refptr<FakePictureLayer> copy_layer_; |
| 733 }; | 705 }; |
| 734 | 706 |
| 735 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 707 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 736 LayerTreeHostTestAsyncTwoReadbacksWithoutDraw); | 708 LayerTreeHostTestAsyncTwoReadbacksWithoutDraw); |
| 737 | 709 |
| 738 class LayerTreeHostCopyRequestTestDeleteTexture | 710 class LayerTreeHostCopyRequestTestLostOutputSurface |
| 739 : public LayerTreeHostCopyRequestTest { | 711 : public LayerTreeHostCopyRequestTest { |
| 740 protected: | 712 protected: |
| 741 std::unique_ptr<OutputSurface> CreateDisplayOutputSurface( | 713 std::unique_ptr<OutputSurface> CreateOutputSurface() override { |
| 742 scoped_refptr<ContextProvider> compositor_context_provider) override { | 714 if (!first_context_provider_) { |
| 743 display_context_provider_ = TestContextProvider::Create(); | 715 first_context_provider_ = TestContextProvider::Create(); |
| 744 return FakeOutputSurface::Create3d(display_context_provider_); | 716 return FakeOutputSurface::Create3d(first_context_provider_); |
| 717 } |
| 718 |
| 719 EXPECT_FALSE(second_context_provider_); |
| 720 second_context_provider_ = TestContextProvider::Create(); |
| 721 return FakeOutputSurface::Create3d(second_context_provider_); |
| 745 } | 722 } |
| 746 | 723 |
| 747 void SetupTree() override { | 724 void SetupTree() override { |
| 748 root_ = FakePictureLayer::Create(&client_); | 725 root_ = FakePictureLayer::Create(&client_); |
| 749 root_->SetBounds(gfx::Size(20, 20)); | 726 root_->SetBounds(gfx::Size(20, 20)); |
| 750 | 727 |
| 751 copy_layer_ = FakePictureLayer::Create(&client_); | 728 copy_layer_ = FakePictureLayer::Create(&client_); |
| 752 copy_layer_->SetBounds(gfx::Size(10, 10)); | 729 copy_layer_->SetBounds(gfx::Size(10, 10)); |
| 753 root_->AddChild(copy_layer_); | 730 root_->AddChild(copy_layer_); |
| 754 | 731 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 768 // Save the result for later. | 745 // Save the result for later. |
| 769 EXPECT_FALSE(result_); | 746 EXPECT_FALSE(result_); |
| 770 result_ = std::move(result); | 747 result_ = std::move(result); |
| 771 | 748 |
| 772 // Post a commit to lose the output surface. | 749 // Post a commit to lose the output surface. |
| 773 layer_tree_host()->SetNeedsCommit(); | 750 layer_tree_host()->SetNeedsCommit(); |
| 774 } | 751 } |
| 775 | 752 |
| 776 void InsertCopyRequest() { | 753 void InsertCopyRequest() { |
| 777 copy_layer_->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( | 754 copy_layer_->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 778 base::Bind(&LayerTreeHostCopyRequestTestDeleteTexture:: | 755 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface:: |
| 779 ReceiveCopyRequestOutputAndCommit, | 756 ReceiveCopyRequestOutputAndCommit, |
| 780 base::Unretained(this)))); | 757 base::Unretained(this)))); |
| 781 } | 758 } |
| 782 | 759 |
| 783 void DestroyCopyResultAndCheckNumTextures() { | 760 void DestroyCopyResultAndCheckNumTextures() { |
| 784 EXPECT_TRUE(result_); | 761 EXPECT_TRUE(result_); |
| 785 result_ = nullptr; | 762 result_ = nullptr; |
| 786 | 763 |
| 787 ImplThreadTaskRunner()->PostTask( | 764 ImplThreadTaskRunner()->PostTask( |
| 788 FROM_HERE, base::Bind(&LayerTreeHostCopyRequestTestDeleteTexture:: | 765 FROM_HERE, base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface:: |
| 789 CheckNumTexturesAfterReadbackDestroyed, | 766 CheckNumTexturesAfterReadbackDestroyed, |
| 790 base::Unretained(this))); | 767 base::Unretained(this))); |
| 791 } | 768 } |
| 792 | 769 |
| 793 void CheckNumTexturesAfterReadbackDestroyed() { | 770 void CheckNumTexturesAfterReadbackDestroyed() { |
| 794 // After the copy we had |num_textures_after_readback_| many textures, but | 771 // After the loss we had |num_textures_after_loss_| many textures, but |
| 795 // releasing the copy output request should cause the texture in the request | 772 // releasing the copy output request will cause the texture in the request |
| 796 // to be destroyed by the compositor, so we should have 1 less by now. | 773 // to be released, so we should have 1 less by now. |
| 797 EXPECT_EQ(num_textures_after_readback_ - 1, | 774 EXPECT_EQ(num_textures_after_loss_ - 1, |
| 798 display_context_provider_->TestContext3d()->NumTextures()); | 775 first_context_provider_->TestContext3d()->NumTextures()); |
| 799 EndTest(); | 776 EndTest(); |
| 800 } | 777 } |
| 801 | 778 |
| 802 void DisplayDidDrawAndSwapOnThread() override { | 779 void SwapBuffersCompleteOnThread() override { |
| 803 switch (num_swaps_++) { | 780 switch (num_swaps_++) { |
| 804 case 0: | 781 case 0: |
| 805 // The layers have been drawn, so any textures required for drawing have | 782 // The layers have been drawn, so their textures have been allocated. |
| 806 // been allocated. | |
| 807 EXPECT_FALSE(result_); | 783 EXPECT_FALSE(result_); |
| 808 num_textures_without_readback_ = | 784 num_textures_without_readback_ = |
| 809 display_context_provider_->TestContext3d()->NumTextures(); | 785 first_context_provider_->TestContext3d()->NumTextures(); |
| 810 | 786 |
| 811 // Request a copy of the layer. This will use another texture. | 787 // Request a copy of the layer. This will use another texture. |
| 812 MainThreadTaskRunner()->PostTask( | 788 MainThreadTaskRunner()->PostTask( |
| 813 FROM_HERE, | 789 FROM_HERE, |
| 814 base::Bind( | 790 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface:: |
| 815 &LayerTreeHostCopyRequestTestDeleteTexture::InsertCopyRequest, | 791 InsertCopyRequest, |
| 816 base::Unretained(this))); | 792 base::Unretained(this))); |
| 817 break; | 793 break; |
| 818 case 1: | 794 case 1: |
| 819 // We did a readback, so there will be a readback texture around now. | 795 // We did a readback, so there will be a readback texture around now. |
| 820 num_textures_after_readback_ = | 796 EXPECT_LT(num_textures_without_readback_, |
| 821 display_context_provider_->TestContext3d()->NumTextures(); | 797 first_context_provider_->TestContext3d()->NumTextures()); |
| 822 EXPECT_LT(num_textures_without_readback_, num_textures_after_readback_); | 798 |
| 799 // The copy request will be serviced and the result sent to |
| 800 // ReceiveCopyRequestOutputAndCommit, which posts a new commit causing |
| 801 // the test to advance to the next case. |
| 802 break; |
| 803 case 2: |
| 804 // The readback texture is collected. |
| 805 EXPECT_TRUE(result_); |
| 806 |
| 807 // Lose the output surface. |
| 808 first_context_provider_->TestContext3d()->loseContextCHROMIUM( |
| 809 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); |
| 810 break; |
| 811 case 3: |
| 812 // The output surface has been recreated. |
| 813 EXPECT_TRUE(second_context_provider_); |
| 814 |
| 815 num_textures_after_loss_ = |
| 816 first_context_provider_->TestContext3d()->NumTextures(); |
| 823 | 817 |
| 824 // Now destroy the CopyOutputResult, releasing the texture inside back | 818 // Now destroy the CopyOutputResult, releasing the texture inside back |
| 825 // to the compositor. Then check the resulting number of allocated | 819 // to the compositor. Then check the resulting number of allocated |
| 826 // textures. | 820 // textures. |
| 827 MainThreadTaskRunner()->PostTask( | 821 MainThreadTaskRunner()->PostTask( |
| 828 FROM_HERE, base::Bind(&LayerTreeHostCopyRequestTestDeleteTexture:: | 822 FROM_HERE, |
| 829 DestroyCopyResultAndCheckNumTextures, | 823 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface:: |
| 830 base::Unretained(this))); | 824 DestroyCopyResultAndCheckNumTextures, |
| 825 base::Unretained(this))); |
| 831 break; | 826 break; |
| 832 } | 827 } |
| 833 } | 828 } |
| 834 | 829 |
| 835 void AfterTest() override {} | 830 void AfterTest() override {} |
| 836 | 831 |
| 837 scoped_refptr<TestContextProvider> display_context_provider_; | 832 scoped_refptr<TestContextProvider> first_context_provider_; |
| 833 scoped_refptr<TestContextProvider> second_context_provider_; |
| 838 int num_swaps_ = 0; | 834 int num_swaps_ = 0; |
| 839 size_t num_textures_without_readback_ = 0; | 835 size_t num_textures_without_readback_ = 0; |
| 840 size_t num_textures_after_readback_ = 0; | 836 size_t num_textures_after_loss_ = 0; |
| 841 FakeContentLayerClient client_; | 837 FakeContentLayerClient client_; |
| 842 scoped_refptr<FakePictureLayer> root_; | 838 scoped_refptr<FakePictureLayer> root_; |
| 843 scoped_refptr<FakePictureLayer> copy_layer_; | 839 scoped_refptr<FakePictureLayer> copy_layer_; |
| 844 std::unique_ptr<CopyOutputResult> result_; | 840 std::unique_ptr<CopyOutputResult> result_; |
| 845 }; | 841 }; |
| 846 | 842 |
| 847 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 843 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 848 LayerTreeHostCopyRequestTestDeleteTexture); | 844 LayerTreeHostCopyRequestTestLostOutputSurface); |
| 849 | 845 |
| 850 class LayerTreeHostCopyRequestTestCountTextures | 846 class LayerTreeHostCopyRequestTestCountTextures |
| 851 : public LayerTreeHostCopyRequestTest { | 847 : public LayerTreeHostCopyRequestTest { |
| 852 protected: | 848 protected: |
| 853 void InitializeSettings(LayerTreeSettings* settings) override { | 849 std::unique_ptr<OutputSurface> CreateOutputSurface() override { |
| 854 // Always allocate only a single texture at a time through ResourceProvider. | 850 context_provider_ = TestContextProvider::Create(); |
| 855 settings->renderer_settings.texture_id_allocation_chunk_size = 1; | 851 return FakeOutputSurface::Create3d(context_provider_); |
| 856 } | |
| 857 | |
| 858 std::unique_ptr<OutputSurface> CreateDisplayOutputSurface( | |
| 859 scoped_refptr<ContextProvider> compositor_context_provider) override { | |
| 860 // These tests expect the LayerTreeHostImpl to share a context with | |
| 861 // the Display so that sync points are not needed and the texture counts | |
| 862 // are visible together. | |
| 863 // Since this test does not override CreateDelegatingOutputSurface, the | |
| 864 // |compositor_context_provider| will be a TestContextProvider. | |
| 865 display_context_provider_ = | |
| 866 static_cast<TestContextProvider*>(compositor_context_provider.get()); | |
| 867 return FakeOutputSurface::Create3d(std::move(compositor_context_provider)); | |
| 868 } | 852 } |
| 869 | 853 |
| 870 void SetupTree() override { | 854 void SetupTree() override { |
| 871 // The layers in this test have solid color content, so they don't | 855 client_.set_fill_with_nonsolid_color(true); |
| 872 // actually allocate any textures, making counting easier. | |
| 873 | 856 |
| 874 root_ = FakePictureLayer::Create(&root_client_); | 857 root_ = FakePictureLayer::Create(&client_); |
| 875 root_->SetBounds(gfx::Size(20, 20)); | 858 root_->SetBounds(gfx::Size(20, 20)); |
| 876 root_client_.set_bounds(root_->bounds()); | |
| 877 | 859 |
| 878 copy_layer_ = FakePictureLayer::Create(©_client_); | 860 copy_layer_ = FakePictureLayer::Create(&client_); |
| 879 copy_layer_->SetBounds(gfx::Size(10, 10)); | 861 copy_layer_->SetBounds(gfx::Size(10, 10)); |
| 880 copy_client_.set_bounds(copy_layer_->bounds()); | |
| 881 // Doing a copy makes the layer have a render surface which can cause | |
| 882 // texture allocations. So get those allocations out of the way in the | |
| 883 // first frame by forcing it to have a render surface. | |
| 884 copy_layer_->SetForceRenderSurfaceForTesting(true); | |
| 885 root_->AddChild(copy_layer_); | 862 root_->AddChild(copy_layer_); |
| 886 | 863 |
| 887 layer_tree_host()->SetRootLayer(root_); | 864 layer_tree_host()->SetRootLayer(root_); |
| 888 LayerTreeHostCopyRequestTest::SetupTree(); | 865 LayerTreeHostCopyRequestTest::SetupTree(); |
| 866 client_.set_bounds(root_->bounds()); |
| 889 } | 867 } |
| 890 | 868 |
| 891 void BeginTest() override { | 869 void BeginTest() override { |
| 892 waited_sync_token_after_readback_.Clear(); | 870 waited_sync_token_after_readback_.Clear(); |
| 893 PostSetNeedsCommitToMainThread(); | 871 PostSetNeedsCommitToMainThread(); |
| 894 } | 872 } |
| 895 | 873 |
| 896 virtual void RequestCopy(Layer* layer) = 0; | 874 virtual void RequestCopy(Layer* layer) = 0; |
| 897 | 875 |
| 898 void DidCommit() override { | 876 void DidCommit() override { |
| 899 switch (layer_tree_host()->source_frame_number()) { | 877 switch (layer_tree_host()->source_frame_number()) { |
| 900 case 1: | 878 case 1: |
| 901 // The layers have been pushed to the impl side and drawn. Any textures | 879 // The layers have been pushed to the impl side. The layer textures have |
| 902 // that are created in that process will have been allocated. | 880 // been allocated. |
| 903 RequestCopy(copy_layer_.get()); | 881 RequestCopy(copy_layer_.get()); |
| 904 break; | 882 break; |
| 905 } | 883 } |
| 906 } | 884 } |
| 907 | 885 |
| 908 void DisplayDidDrawAndSwapOnThread() override { | 886 void SwapBuffersCompleteOnThread() override { |
| 909 switch (num_swaps_++) { | 887 switch (num_swaps_++) { |
| 910 case 0: | 888 case 0: |
| 911 // The first frame has been drawn, so textures for drawing have been | 889 // The layers have been drawn, so their textures have been allocated. |
| 912 // allocated. | |
| 913 num_textures_without_readback_ = | 890 num_textures_without_readback_ = |
| 914 display_context_provider_->TestContext3d()->NumTextures(); | 891 context_provider_->TestContext3d()->NumTextures(); |
| 915 break; | 892 break; |
| 916 case 1: | 893 case 1: |
| 917 // We did a readback, so there will be a readback texture around now. | 894 // We did a readback, so there will be a readback texture around now. |
| 918 num_textures_with_readback_ = | 895 num_textures_with_readback_ = |
| 919 display_context_provider_->TestContext3d()->NumTextures(); | 896 context_provider_->TestContext3d()->NumTextures(); |
| 920 waited_sync_token_after_readback_ = | 897 waited_sync_token_after_readback_ = |
| 921 display_context_provider_->TestContext3d() | 898 context_provider_->TestContext3d()->last_waited_sync_token(); |
| 922 ->last_waited_sync_token(); | |
| 923 | 899 |
| 924 // End the test after main thread has a chance to hear about the | |
| 925 // readback. | |
| 926 MainThreadTaskRunner()->PostTask( | 900 MainThreadTaskRunner()->PostTask( |
| 927 FROM_HERE, | 901 FROM_HERE, |
| 928 base::Bind(&LayerTreeHostCopyRequestTestCountTextures::DoEndTest, | 902 base::Bind(&LayerTreeHostCopyRequestTestCountTextures::DoEndTest, |
| 929 base::Unretained(this))); | 903 base::Unretained(this))); |
| 930 break; | 904 break; |
| 931 } | 905 } |
| 932 } | 906 } |
| 933 | 907 |
| 934 virtual void DoEndTest() { EndTest(); } | 908 virtual void DoEndTest() { EndTest(); } |
| 935 | 909 |
| 936 scoped_refptr<TestContextProvider> display_context_provider_; | 910 scoped_refptr<TestContextProvider> context_provider_; |
| 937 int num_swaps_ = 0; | 911 int num_swaps_ = 0; |
| 938 size_t num_textures_without_readback_ = 0; | 912 size_t num_textures_without_readback_ = 0; |
| 939 size_t num_textures_with_readback_ = 0; | 913 size_t num_textures_with_readback_ = 0; |
| 940 gpu::SyncToken waited_sync_token_after_readback_; | 914 gpu::SyncToken waited_sync_token_after_readback_; |
| 941 FakeContentLayerClient root_client_; | 915 FakeContentLayerClient client_; |
| 942 FakeContentLayerClient copy_client_; | |
| 943 scoped_refptr<FakePictureLayer> root_; | 916 scoped_refptr<FakePictureLayer> root_; |
| 944 scoped_refptr<FakePictureLayer> copy_layer_; | 917 scoped_refptr<FakePictureLayer> copy_layer_; |
| 945 }; | 918 }; |
| 946 | 919 |
| 947 class LayerTreeHostCopyRequestTestCreatesTexture | 920 class LayerTreeHostCopyRequestTestCreatesTexture |
| 948 : public LayerTreeHostCopyRequestTestCountTextures { | 921 : public LayerTreeHostCopyRequestTestCountTextures { |
| 949 protected: | 922 protected: |
| 950 void RequestCopy(Layer* layer) override { | 923 void RequestCopy(Layer* layer) override { |
| 951 // Request a normal texture copy. This should create a new texture. | 924 // Request a normal texture copy. This should create a new texture. |
| 952 copy_layer_->RequestCopyOfOutput( | 925 copy_layer_->RequestCopyOfOutput( |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1297 int num_draws_; | 1270 int num_draws_; |
| 1298 bool copy_happened_; | 1271 bool copy_happened_; |
| 1299 bool draw_happened_; | 1272 bool draw_happened_; |
| 1300 }; | 1273 }; |
| 1301 | 1274 |
| 1302 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 1275 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 1303 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest); | 1276 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest); |
| 1304 | 1277 |
| 1305 } // namespace | 1278 } // namespace |
| 1306 } // namespace cc | 1279 } // namespace cc |
| OLD | NEW |