| 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" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread()); | 122 EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread()); |
| 123 EXPECT_TRUE(result->HasBitmap()); | 123 EXPECT_TRUE(result->HasBitmap()); |
| 124 std::unique_ptr<SkBitmap> bitmap = result->TakeBitmap(); | 124 std::unique_ptr<SkBitmap> bitmap = result->TakeBitmap(); |
| 125 EXPECT_EQ(result->size().ToString(), | 125 EXPECT_EQ(result->size().ToString(), |
| 126 gfx::Size(bitmap->width(), bitmap->height()).ToString()); | 126 gfx::Size(bitmap->width(), bitmap->height()).ToString()); |
| 127 callbacks_[id] = result->size(); | 127 callbacks_[id] = result->size(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void AfterTest() override { EXPECT_EQ(4u, callbacks_.size()); } | 130 void AfterTest() override { EXPECT_EQ(4u, callbacks_.size()); } |
| 131 | 131 |
| 132 std::unique_ptr<OutputSurface> CreateDisplayOutputSurface( | 132 std::unique_ptr<OutputSurface> CreateDisplayOutputSurfaceOnThread( |
| 133 scoped_refptr<ContextProvider> compositor_context_provider) override { | 133 scoped_refptr<ContextProvider> compositor_context_provider) override { |
| 134 if (!use_gl_renderer_) { | 134 if (!use_gl_renderer_) { |
| 135 return FakeOutputSurface::CreateSoftware( | 135 return FakeOutputSurface::CreateSoftware( |
| 136 base::WrapUnique(new SoftwareOutputDevice)); | 136 base::WrapUnique(new SoftwareOutputDevice)); |
| 137 } | 137 } |
| 138 | 138 |
| 139 scoped_refptr<TestContextProvider> display_context_provider = | 139 scoped_refptr<TestContextProvider> display_context_provider = |
| 140 TestContextProvider::Create(); | 140 TestContextProvider::Create(); |
| 141 TestContextSupport* context_support = display_context_provider->support(); | 141 TestContextSupport* context_support = display_context_provider->support(); |
| 142 context_support->set_out_of_order_callbacks(out_of_order_callbacks_); | 142 context_support->set_out_of_order_callbacks(out_of_order_callbacks_); |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 parent_layer_->AddChild(copy_layer_); | 459 parent_layer_->AddChild(copy_layer_); |
| 460 | 460 |
| 461 layer_tree()->SetRootLayer(root_); | 461 layer_tree()->SetRootLayer(root_); |
| 462 LayerTreeHostCopyRequestTest::SetupTree(); | 462 LayerTreeHostCopyRequestTest::SetupTree(); |
| 463 client_.set_bounds(root_->bounds()); | 463 client_.set_bounds(root_->bounds()); |
| 464 } | 464 } |
| 465 | 465 |
| 466 std::unique_ptr<TestCompositorFrameSink> CreateCompositorFrameSink( | 466 std::unique_ptr<TestCompositorFrameSink> CreateCompositorFrameSink( |
| 467 scoped_refptr<ContextProvider> compositor_context_provider, | 467 scoped_refptr<ContextProvider> compositor_context_provider, |
| 468 scoped_refptr<ContextProvider> worker_context_provider) override { | 468 scoped_refptr<ContextProvider> worker_context_provider) override { |
| 469 auto surface = LayerTreeHostCopyRequestTest::CreateCompositorFrameSink( | 469 auto frame_sink = LayerTreeHostCopyRequestTest::CreateCompositorFrameSink( |
| 470 std::move(compositor_context_provider), | 470 std::move(compositor_context_provider), |
| 471 std::move(worker_context_provider)); | 471 std::move(worker_context_provider)); |
| 472 display_ = surface->display(); | 472 frame_sink_ = frame_sink.get(); |
| 473 return surface; | 473 return frame_sink; |
| 474 } | 474 } |
| 475 | 475 |
| 476 void BeginTest() override { | 476 void BeginTest() override { |
| 477 PostSetNeedsCommitToMainThread(); | 477 PostSetNeedsCommitToMainThread(); |
| 478 | 478 |
| 479 copy_layer_->RequestCopyOfOutput( | 479 copy_layer_->RequestCopyOfOutput( |
| 480 CopyOutputRequest::CreateBitmapRequest(base::Bind( | 480 CopyOutputRequest::CreateBitmapRequest(base::Bind( |
| 481 &LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest:: | 481 &LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest:: |
| 482 CopyOutputCallback, | 482 CopyOutputCallback, |
| 483 base::Unretained(this)))); | 483 base::Unretained(this)))); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 500 return; | 500 return; |
| 501 } | 501 } |
| 502 | 502 |
| 503 EXPECT_EQ(2u, render_passes.size()); | 503 EXPECT_EQ(2u, render_passes.size()); |
| 504 // The root pass is the back of the list. | 504 // The root pass is the back of the list. |
| 505 copy_layer_render_pass_id = render_passes[0]->id; | 505 copy_layer_render_pass_id = render_passes[0]->id; |
| 506 parent_render_pass_id = render_passes[1]->id; | 506 parent_render_pass_id = render_passes[1]->id; |
| 507 } | 507 } |
| 508 | 508 |
| 509 void DisplayDidDrawAndSwapOnThread() override { | 509 void DisplayDidDrawAndSwapOnThread() override { |
| 510 DirectRenderer* renderer = display_->renderer_for_testing(); | 510 DirectRenderer* renderer = frame_sink_->display()->renderer_for_testing(); |
| 511 | 511 |
| 512 // |parent| owns a surface, but it was hidden and not part of the copy | 512 // |parent| owns a surface, but it was hidden and not part of the copy |
| 513 // request so it should not allocate any resource. | 513 // request so it should not allocate any resource. |
| 514 EXPECT_FALSE( | 514 EXPECT_FALSE( |
| 515 renderer->HasAllocatedResourcesForTesting(parent_render_pass_id)); | 515 renderer->HasAllocatedResourcesForTesting(parent_render_pass_id)); |
| 516 | 516 |
| 517 // TODO(crbug.com/564832): Ignore the extra frame that occurs due to copy | 517 // TODO(crbug.com/564832): Ignore the extra frame that occurs due to copy |
| 518 // completion. This can be removed when the extra commit is removed. | 518 // completion. This can be removed when the extra commit is removed. |
| 519 if (did_swap_) { | 519 if (did_swap_) { |
| 520 EXPECT_FALSE( | 520 EXPECT_FALSE( |
| 521 renderer->HasAllocatedResourcesForTesting(copy_layer_render_pass_id)); | 521 renderer->HasAllocatedResourcesForTesting(copy_layer_render_pass_id)); |
| 522 } else { | 522 } else { |
| 523 // |copy_layer| should have been rendered to a texture since it was needed | 523 // |copy_layer| should have been rendered to a texture since it was needed |
| 524 // for a copy request. | 524 // for a copy request. |
| 525 EXPECT_TRUE( | 525 EXPECT_TRUE( |
| 526 renderer->HasAllocatedResourcesForTesting(copy_layer_render_pass_id)); | 526 renderer->HasAllocatedResourcesForTesting(copy_layer_render_pass_id)); |
| 527 } | 527 } |
| 528 | 528 |
| 529 did_swap_ = true; | 529 did_swap_ = true; |
| 530 } | 530 } |
| 531 | 531 |
| 532 void AfterTest() override { EXPECT_TRUE(did_swap_); } | 532 void AfterTest() override { EXPECT_TRUE(did_swap_); } |
| 533 | 533 |
| 534 RenderPassId parent_render_pass_id; | 534 RenderPassId parent_render_pass_id; |
| 535 RenderPassId copy_layer_render_pass_id; | 535 RenderPassId copy_layer_render_pass_id; |
| 536 Display* display_ = nullptr; | 536 TestCompositorFrameSink* frame_sink_ = nullptr; |
| 537 bool did_swap_ = false; | 537 bool did_swap_ = false; |
| 538 FakeContentLayerClient client_; | 538 FakeContentLayerClient client_; |
| 539 scoped_refptr<FakePictureLayer> root_; | 539 scoped_refptr<FakePictureLayer> root_; |
| 540 scoped_refptr<FakePictureLayer> grand_parent_layer_; | 540 scoped_refptr<FakePictureLayer> grand_parent_layer_; |
| 541 scoped_refptr<FakePictureLayer> parent_layer_; | 541 scoped_refptr<FakePictureLayer> parent_layer_; |
| 542 scoped_refptr<FakePictureLayer> copy_layer_; | 542 scoped_refptr<FakePictureLayer> copy_layer_; |
| 543 }; | 543 }; |
| 544 | 544 |
| 545 SINGLE_AND_MULTI_THREAD_TEST_F( | 545 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 546 LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest); | 546 LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 FakeContentLayerClient client_; | 724 FakeContentLayerClient client_; |
| 725 scoped_refptr<FakePictureLayer> root_; | 725 scoped_refptr<FakePictureLayer> root_; |
| 726 scoped_refptr<FakePictureLayer> copy_layer_; | 726 scoped_refptr<FakePictureLayer> copy_layer_; |
| 727 }; | 727 }; |
| 728 | 728 |
| 729 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestAsyncTwoReadbacksWithoutDraw); | 729 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestAsyncTwoReadbacksWithoutDraw); |
| 730 | 730 |
| 731 class LayerTreeHostCopyRequestTestDeleteTexture | 731 class LayerTreeHostCopyRequestTestDeleteTexture |
| 732 : public LayerTreeHostCopyRequestTest { | 732 : public LayerTreeHostCopyRequestTest { |
| 733 protected: | 733 protected: |
| 734 std::unique_ptr<OutputSurface> CreateDisplayOutputSurface( | 734 std::unique_ptr<OutputSurface> CreateDisplayOutputSurfaceOnThread( |
| 735 scoped_refptr<ContextProvider> compositor_context_provider) override { | 735 scoped_refptr<ContextProvider> compositor_context_provider) override { |
| 736 display_context_provider_ = TestContextProvider::Create(); | 736 display_context_provider_ = TestContextProvider::Create(); |
| 737 return FakeOutputSurface::Create3d(display_context_provider_); | 737 return FakeOutputSurface::Create3d(display_context_provider_); |
| 738 } | 738 } |
| 739 | 739 |
| 740 void SetupTree() override { | 740 void SetupTree() override { |
| 741 root_ = FakePictureLayer::Create(&client_); | 741 root_ = FakePictureLayer::Create(&client_); |
| 742 root_->SetBounds(gfx::Size(20, 20)); | 742 root_->SetBounds(gfx::Size(20, 20)); |
| 743 | 743 |
| 744 copy_layer_ = FakePictureLayer::Create(&client_); | 744 copy_layer_ = FakePictureLayer::Create(&client_); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 CheckNumTexturesAfterReadbackDestroyed, | 782 CheckNumTexturesAfterReadbackDestroyed, |
| 783 base::Unretained(this))); | 783 base::Unretained(this))); |
| 784 } | 784 } |
| 785 | 785 |
| 786 void CheckNumTexturesAfterReadbackDestroyed() { | 786 void CheckNumTexturesAfterReadbackDestroyed() { |
| 787 // After the copy we had |num_textures_after_readback_| many textures, but | 787 // After the copy we had |num_textures_after_readback_| many textures, but |
| 788 // releasing the copy output request should cause the texture in the request | 788 // releasing the copy output request should cause the texture in the request |
| 789 // to be destroyed by the compositor, so we should have 1 less by now. | 789 // to be destroyed by the compositor, so we should have 1 less by now. |
| 790 EXPECT_EQ(num_textures_after_readback_ - 1, | 790 EXPECT_EQ(num_textures_after_readback_ - 1, |
| 791 display_context_provider_->TestContext3d()->NumTextures()); | 791 display_context_provider_->TestContext3d()->NumTextures()); |
| 792 |
| 793 // Drop the reference to the context provider on the compositor thread. |
| 794 display_context_provider_ = nullptr; |
| 792 EndTest(); | 795 EndTest(); |
| 793 } | 796 } |
| 794 | 797 |
| 795 void DisplayDidDrawAndSwapOnThread() override { | 798 void DisplayDidDrawAndSwapOnThread() override { |
| 796 switch (num_swaps_++) { | 799 switch (num_swaps_++) { |
| 797 case 0: | 800 case 0: |
| 798 // The layers have been drawn, so any textures required for drawing have | 801 // The layers have been drawn, so any textures required for drawing have |
| 799 // been allocated. | 802 // been allocated. |
| 800 EXPECT_FALSE(result_); | 803 EXPECT_FALSE(result_); |
| 801 num_textures_without_readback_ = | 804 num_textures_without_readback_ = |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostCopyRequestTestDeleteTexture); | 843 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostCopyRequestTestDeleteTexture); |
| 841 | 844 |
| 842 class LayerTreeHostCopyRequestTestCountTextures | 845 class LayerTreeHostCopyRequestTestCountTextures |
| 843 : public LayerTreeHostCopyRequestTest { | 846 : public LayerTreeHostCopyRequestTest { |
| 844 protected: | 847 protected: |
| 845 void InitializeSettings(LayerTreeSettings* settings) override { | 848 void InitializeSettings(LayerTreeSettings* settings) override { |
| 846 // Always allocate only a single texture at a time through ResourceProvider. | 849 // Always allocate only a single texture at a time through ResourceProvider. |
| 847 settings->renderer_settings.texture_id_allocation_chunk_size = 1; | 850 settings->renderer_settings.texture_id_allocation_chunk_size = 1; |
| 848 } | 851 } |
| 849 | 852 |
| 850 std::unique_ptr<OutputSurface> CreateDisplayOutputSurface( | 853 std::unique_ptr<OutputSurface> CreateDisplayOutputSurfaceOnThread( |
| 851 scoped_refptr<ContextProvider> compositor_context_provider) override { | 854 scoped_refptr<ContextProvider> compositor_context_provider) override { |
| 852 // These tests expect the LayerTreeHostImpl to share a context with | 855 // These tests expect the LayerTreeHostImpl to share a context with |
| 853 // the Display so that sync points are not needed and the texture counts | 856 // the Display so that sync points are not needed and the texture counts |
| 854 // are visible together. | 857 // are visible together. |
| 855 // Since this test does not override CreateCompositorFrameSink, the | 858 // Since this test does not override CreateCompositorFrameSink, the |
| 856 // |compositor_context_provider| will be a TestContextProvider. | 859 // |compositor_context_provider| will be a TestContextProvider. |
| 857 display_context_provider_ = | 860 display_context_provider_ = |
| 858 static_cast<TestContextProvider*>(compositor_context_provider.get()); | 861 static_cast<TestContextProvider*>(compositor_context_provider.get()); |
| 859 return FakeOutputSurface::Create3d(std::move(compositor_context_provider)); | 862 return FakeOutputSurface::Create3d(std::move(compositor_context_provider)); |
| 860 } | 863 } |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 int num_draws_; | 1288 int num_draws_; |
| 1286 bool copy_happened_; | 1289 bool copy_happened_; |
| 1287 bool draw_happened_; | 1290 bool draw_happened_; |
| 1288 }; | 1291 }; |
| 1289 | 1292 |
| 1290 SINGLE_AND_MULTI_THREAD_TEST_F( | 1293 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 1291 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest); | 1294 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest); |
| 1292 | 1295 |
| 1293 } // namespace | 1296 } // namespace |
| 1294 } // namespace cc | 1297 } // namespace cc |
| OLD | NEW |