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