| Index: cc/trees/layer_tree_host_unittest_copyrequest.cc
|
| diff --git a/cc/trees/layer_tree_host_unittest_copyrequest.cc b/cc/trees/layer_tree_host_unittest_copyrequest.cc
|
| index 623d4034fcc0b642917723d5110b2e29ce139880..7177580cf5b4254cd8dece4853a2db6defa86ba7 100644
|
| --- a/cc/trees/layer_tree_host_unittest_copyrequest.cc
|
| +++ b/cc/trees/layer_tree_host_unittest_copyrequest.cc
|
| @@ -11,10 +11,13 @@
|
| #include "cc/layers/layer_iterator.h"
|
| #include "cc/output/copy_output_request.h"
|
| #include "cc/output/copy_output_result.h"
|
| +#include "cc/output/direct_renderer.h"
|
| +#include "cc/surfaces/display.h"
|
| #include "cc/test/fake_content_layer_client.h"
|
| #include "cc/test/fake_output_surface.h"
|
| #include "cc/test/fake_picture_layer.h"
|
| #include "cc/test/layer_tree_test.h"
|
| +#include "cc/test/test_delegating_output_surface.h"
|
| #include "cc/trees/layer_tree_impl.h"
|
| #include "gpu/GLES2/gl2extchromium.h"
|
|
|
| @@ -126,19 +129,19 @@ class LayerTreeHostCopyRequestTestMultipleRequests
|
|
|
| void AfterTest() override { EXPECT_EQ(4u, callbacks_.size()); }
|
|
|
| - std::unique_ptr<OutputSurface> CreateOutputSurface() override {
|
| + std::unique_ptr<OutputSurface> CreateDisplayOutputSurface(
|
| + scoped_refptr<ContextProvider> compositor_context_provider) override {
|
| if (!use_gl_renderer_) {
|
| return FakeOutputSurface::CreateSoftware(
|
| base::WrapUnique(new SoftwareOutputDevice));
|
| }
|
|
|
| - std::unique_ptr<FakeOutputSurface> output_surface =
|
| - FakeOutputSurface::Create3d(TestContextProvider::Create(),
|
| - TestContextProvider::CreateWorker());
|
| - TestContextSupport* context_support = static_cast<TestContextSupport*>(
|
| - output_surface->context_provider()->ContextSupport());
|
| + scoped_refptr<TestContextProvider> display_context_provider =
|
| + TestContextProvider::Create();
|
| + TestContextSupport* context_support = display_context_provider->support();
|
| context_support->set_out_of_order_callbacks(out_of_order_callbacks_);
|
| - return std::move(output_surface);
|
| +
|
| + return FakeOutputSurface::Create3d(std::move(display_context_provider));
|
| }
|
|
|
| bool use_gl_renderer_;
|
| @@ -463,8 +466,17 @@ class LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest
|
| client_.set_bounds(root_->bounds());
|
| }
|
|
|
| + std::unique_ptr<TestDelegatingOutputSurface> CreateDelegatingOutputSurface(
|
| + scoped_refptr<ContextProvider> compositor_context_provider,
|
| + scoped_refptr<ContextProvider> worker_context_provider) override {
|
| + auto surface = LayerTreeHostCopyRequestTest::CreateDelegatingOutputSurface(
|
| + std::move(compositor_context_provider),
|
| + std::move(worker_context_provider));
|
| + display_ = surface->display();
|
| + return surface;
|
| + }
|
| +
|
| void BeginTest() override {
|
| - did_draw_ = false;
|
| PostSetNeedsCommitToMainThread();
|
|
|
| copy_layer_->RequestCopyOfOutput(
|
| @@ -480,37 +492,53 @@ class LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest
|
| EndTest();
|
| }
|
|
|
| - void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
|
| - Renderer* renderer = host_impl->renderer();
|
| + void DisplayWillDrawAndSwapOnThread(
|
| + bool will_draw_and_swap,
|
| + const RenderPassList& render_passes) override {
|
| + EXPECT_TRUE(will_draw_and_swap) << did_swap_;
|
| + if (did_swap_) {
|
| + // TODO(crbug.com/564832): Ignore the extra frame that occurs due to copy
|
| + // completion. This can be removed when the extra commit is removed.
|
| + EXPECT_EQ(1u, render_passes.size());
|
| + return;
|
| + }
|
| +
|
| + EXPECT_EQ(2u, render_passes.size());
|
| + // The root pass is the back of the list.
|
| + copy_layer_render_pass_id = render_passes[0]->id;
|
| + parent_render_pass_id = render_passes[1]->id;
|
| + }
|
|
|
| - LayerImpl* parent =
|
| - host_impl->active_tree()->LayerById(parent_layer_->id());
|
| - LayerImpl* copy_layer =
|
| - host_impl->active_tree()->LayerById(copy_layer_->id());
|
| + void DisplayDidDrawAndSwapOnThread() override {
|
| + DirectRenderer* renderer = display_->renderer_for_testing();
|
|
|
| // |parent| owns a surface, but it was hidden and not part of the copy
|
| // request so it should not allocate any resource.
|
| - EXPECT_FALSE(renderer->HasAllocatedResourcesForTesting(
|
| - parent->render_surface()->GetRenderPassId()));
|
| -
|
| - // |copy_layer| should have been rendered to a texture since it was needed
|
| - // for a copy request.
|
| - if (did_draw_) {
|
| - // TODO(crbug.com/564832): Ignore the extra frame that occurs due to copy
|
| - // completion. This can be removed when the extra commit is removed.
|
| - EXPECT_FALSE(copy_layer->render_surface());
|
| + EXPECT_FALSE(
|
| + renderer->HasAllocatedResourcesForTesting(parent_render_pass_id));
|
| +
|
| + // TODO(crbug.com/564832): Ignore the extra frame that occurs due to copy
|
| + // completion. This can be removed when the extra commit is removed.
|
| + if (did_swap_) {
|
| + EXPECT_FALSE(
|
| + renderer->HasAllocatedResourcesForTesting(copy_layer_render_pass_id));
|
| } else {
|
| - EXPECT_TRUE(renderer->HasAllocatedResourcesForTesting(
|
| - copy_layer->render_surface()->GetRenderPassId()));
|
| + // |copy_layer| should have been rendered to a texture since it was needed
|
| + // for a copy request.
|
| + EXPECT_TRUE(
|
| + renderer->HasAllocatedResourcesForTesting(copy_layer_render_pass_id));
|
| }
|
|
|
| - did_draw_ = true;
|
| + did_swap_ = true;
|
| }
|
|
|
| - void AfterTest() override { EXPECT_TRUE(did_draw_); }
|
| + void AfterTest() override { EXPECT_TRUE(did_swap_); }
|
|
|
| + RenderPassId parent_render_pass_id;
|
| + RenderPassId copy_layer_render_pass_id;
|
| + Display* display_ = nullptr;
|
| + bool did_swap_ = false;
|
| FakeContentLayerClient client_;
|
| - bool did_draw_;
|
| scoped_refptr<FakePictureLayer> root_;
|
| scoped_refptr<FakePictureLayer> grand_parent_layer_;
|
| scoped_refptr<FakePictureLayer> parent_layer_;
|
| @@ -707,18 +735,13 @@ class LayerTreeHostTestAsyncTwoReadbacksWithoutDraw
|
| SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
|
| LayerTreeHostTestAsyncTwoReadbacksWithoutDraw);
|
|
|
| -class LayerTreeHostCopyRequestTestLostOutputSurface
|
| +class LayerTreeHostCopyRequestTestDeleteTexture
|
| : public LayerTreeHostCopyRequestTest {
|
| protected:
|
| - std::unique_ptr<OutputSurface> CreateOutputSurface() override {
|
| - if (!first_context_provider_) {
|
| - first_context_provider_ = TestContextProvider::Create();
|
| - return FakeOutputSurface::Create3d(first_context_provider_);
|
| - }
|
| -
|
| - EXPECT_FALSE(second_context_provider_);
|
| - second_context_provider_ = TestContextProvider::Create();
|
| - return FakeOutputSurface::Create3d(second_context_provider_);
|
| + std::unique_ptr<OutputSurface> CreateDisplayOutputSurface(
|
| + scoped_refptr<ContextProvider> compositor_context_provider) override {
|
| + display_context_provider_ = TestContextProvider::Create();
|
| + return FakeOutputSurface::Create3d(display_context_provider_);
|
| }
|
|
|
| void SetupTree() override {
|
| @@ -752,7 +775,7 @@ class LayerTreeHostCopyRequestTestLostOutputSurface
|
|
|
| void InsertCopyRequest() {
|
| copy_layer_->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
|
| - base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface::
|
| + base::Bind(&LayerTreeHostCopyRequestTestDeleteTexture::
|
| ReceiveCopyRequestOutputAndCommit,
|
| base::Unretained(this))));
|
| }
|
| @@ -762,78 +785,59 @@ class LayerTreeHostCopyRequestTestLostOutputSurface
|
| result_ = nullptr;
|
|
|
| ImplThreadTaskRunner()->PostTask(
|
| - FROM_HERE, base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface::
|
| + FROM_HERE, base::Bind(&LayerTreeHostCopyRequestTestDeleteTexture::
|
| CheckNumTexturesAfterReadbackDestroyed,
|
| base::Unretained(this)));
|
| }
|
|
|
| void CheckNumTexturesAfterReadbackDestroyed() {
|
| - // After the loss we had |num_textures_after_loss_| many textures, but
|
| - // releasing the copy output request will cause the texture in the request
|
| - // to be released, so we should have 1 less by now.
|
| - EXPECT_EQ(num_textures_after_loss_ - 1,
|
| - first_context_provider_->TestContext3d()->NumTextures());
|
| + // After the copy we had |num_textures_after_readback_| many textures, but
|
| + // releasing the copy output request should cause the texture in the request
|
| + // to be destroyed by the compositor, so we should have 1 less by now.
|
| + EXPECT_EQ(num_textures_after_readback_ - 1,
|
| + display_context_provider_->TestContext3d()->NumTextures());
|
| EndTest();
|
| }
|
|
|
| - void SwapBuffersCompleteOnThread() override {
|
| + void DisplayDidDrawAndSwapOnThread() override {
|
| switch (num_swaps_++) {
|
| case 0:
|
| - // The layers have been drawn, so their textures have been allocated.
|
| + // The layers have been drawn, so any textures required for drawing have
|
| + // been allocated.
|
| EXPECT_FALSE(result_);
|
| num_textures_without_readback_ =
|
| - first_context_provider_->TestContext3d()->NumTextures();
|
| + display_context_provider_->TestContext3d()->NumTextures();
|
|
|
| // Request a copy of the layer. This will use another texture.
|
| MainThreadTaskRunner()->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface::
|
| - InsertCopyRequest,
|
| - base::Unretained(this)));
|
| + base::Bind(
|
| + &LayerTreeHostCopyRequestTestDeleteTexture::InsertCopyRequest,
|
| + base::Unretained(this)));
|
| break;
|
| case 1:
|
| // We did a readback, so there will be a readback texture around now.
|
| - EXPECT_LT(num_textures_without_readback_,
|
| - first_context_provider_->TestContext3d()->NumTextures());
|
| -
|
| - // The copy request will be serviced and the result sent to
|
| - // ReceiveCopyRequestOutputAndCommit, which posts a new commit causing
|
| - // the test to advance to the next case.
|
| - break;
|
| - case 2:
|
| - // The readback texture is collected.
|
| - EXPECT_TRUE(result_);
|
| -
|
| - // Lose the output surface.
|
| - first_context_provider_->TestContext3d()->loseContextCHROMIUM(
|
| - GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
|
| - break;
|
| - case 3:
|
| - // The output surface has been recreated.
|
| - EXPECT_TRUE(second_context_provider_);
|
| -
|
| - num_textures_after_loss_ =
|
| - first_context_provider_->TestContext3d()->NumTextures();
|
| + num_textures_after_readback_ =
|
| + display_context_provider_->TestContext3d()->NumTextures();
|
| + EXPECT_LT(num_textures_without_readback_, num_textures_after_readback_);
|
|
|
| // Now destroy the CopyOutputResult, releasing the texture inside back
|
| // to the compositor. Then check the resulting number of allocated
|
| // textures.
|
| MainThreadTaskRunner()->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface::
|
| - DestroyCopyResultAndCheckNumTextures,
|
| - base::Unretained(this)));
|
| + FROM_HERE, base::Bind(&LayerTreeHostCopyRequestTestDeleteTexture::
|
| + DestroyCopyResultAndCheckNumTextures,
|
| + base::Unretained(this)));
|
| break;
|
| }
|
| }
|
|
|
| void AfterTest() override {}
|
|
|
| - scoped_refptr<TestContextProvider> first_context_provider_;
|
| - scoped_refptr<TestContextProvider> second_context_provider_;
|
| + scoped_refptr<TestContextProvider> display_context_provider_;
|
| int num_swaps_ = 0;
|
| size_t num_textures_without_readback_ = 0;
|
| - size_t num_textures_after_loss_ = 0;
|
| + size_t num_textures_after_readback_ = 0;
|
| FakeContentLayerClient client_;
|
| scoped_refptr<FakePictureLayer> root_;
|
| scoped_refptr<FakePictureLayer> copy_layer_;
|
| @@ -841,29 +845,47 @@ class LayerTreeHostCopyRequestTestLostOutputSurface
|
| };
|
|
|
| SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
|
| - LayerTreeHostCopyRequestTestLostOutputSurface);
|
| + LayerTreeHostCopyRequestTestDeleteTexture);
|
|
|
| class LayerTreeHostCopyRequestTestCountTextures
|
| : public LayerTreeHostCopyRequestTest {
|
| protected:
|
| - std::unique_ptr<OutputSurface> CreateOutputSurface() override {
|
| - context_provider_ = TestContextProvider::Create();
|
| - return FakeOutputSurface::Create3d(context_provider_);
|
| + void InitializeSettings(LayerTreeSettings* settings) override {
|
| + // Always allocate only a single texture at a time through ResourceProvider.
|
| + settings->renderer_settings.texture_id_allocation_chunk_size = 1;
|
| + }
|
| +
|
| + std::unique_ptr<OutputSurface> CreateDisplayOutputSurface(
|
| + scoped_refptr<ContextProvider> compositor_context_provider) override {
|
| + // These tests expect the LayerTreeHostImpl to share a context with
|
| + // the Display so that sync points are not needed and the texture counts
|
| + // are visible together.
|
| + // Since this test does not override CreateDelegatingOutputSurface, the
|
| + // |compositor_context_provider| will be a TestContextProvider.
|
| + display_context_provider_ =
|
| + static_cast<TestContextProvider*>(compositor_context_provider.get());
|
| + return FakeOutputSurface::Create3d(std::move(compositor_context_provider));
|
| }
|
|
|
| void SetupTree() override {
|
| - client_.set_fill_with_nonsolid_color(true);
|
| + // The layers in this test have solid color content, so they don't
|
| + // actually allocate any textures, making counting easier.
|
|
|
| - root_ = FakePictureLayer::Create(&client_);
|
| + root_ = FakePictureLayer::Create(&root_client_);
|
| root_->SetBounds(gfx::Size(20, 20));
|
| + root_client_.set_bounds(root_->bounds());
|
|
|
| - copy_layer_ = FakePictureLayer::Create(&client_);
|
| + copy_layer_ = FakePictureLayer::Create(©_client_);
|
| copy_layer_->SetBounds(gfx::Size(10, 10));
|
| + copy_client_.set_bounds(copy_layer_->bounds());
|
| + // Doing a copy makes the layer have a render surface which can cause
|
| + // texture allocations. So get those allocations out of the way in the
|
| + // first frame by forcing it to have a render surface.
|
| + copy_layer_->SetForceRenderSurfaceForTesting(true);
|
| root_->AddChild(copy_layer_);
|
|
|
| layer_tree_host()->SetRootLayer(root_);
|
| LayerTreeHostCopyRequestTest::SetupTree();
|
| - client_.set_bounds(root_->bounds());
|
| }
|
|
|
| void BeginTest() override {
|
| @@ -876,27 +898,31 @@ class LayerTreeHostCopyRequestTestCountTextures
|
| void DidCommit() override {
|
| switch (layer_tree_host()->source_frame_number()) {
|
| case 1:
|
| - // The layers have been pushed to the impl side. The layer textures have
|
| - // been allocated.
|
| + // The layers have been pushed to the impl side and drawn. Any textures
|
| + // that are created in that process will have been allocated.
|
| RequestCopy(copy_layer_.get());
|
| break;
|
| }
|
| }
|
|
|
| - void SwapBuffersCompleteOnThread() override {
|
| + void DisplayDidDrawAndSwapOnThread() override {
|
| switch (num_swaps_++) {
|
| case 0:
|
| - // The layers have been drawn, so their textures have been allocated.
|
| + // The first frame has been drawn, so textures for drawing have been
|
| + // allocated.
|
| num_textures_without_readback_ =
|
| - context_provider_->TestContext3d()->NumTextures();
|
| + display_context_provider_->TestContext3d()->NumTextures();
|
| break;
|
| case 1:
|
| // We did a readback, so there will be a readback texture around now.
|
| num_textures_with_readback_ =
|
| - context_provider_->TestContext3d()->NumTextures();
|
| + display_context_provider_->TestContext3d()->NumTextures();
|
| waited_sync_token_after_readback_ =
|
| - context_provider_->TestContext3d()->last_waited_sync_token();
|
| + display_context_provider_->TestContext3d()
|
| + ->last_waited_sync_token();
|
|
|
| + // End the test after main thread has a chance to hear about the
|
| + // readback.
|
| MainThreadTaskRunner()->PostTask(
|
| FROM_HERE,
|
| base::Bind(&LayerTreeHostCopyRequestTestCountTextures::DoEndTest,
|
| @@ -907,12 +933,13 @@ class LayerTreeHostCopyRequestTestCountTextures
|
|
|
| virtual void DoEndTest() { EndTest(); }
|
|
|
| - scoped_refptr<TestContextProvider> context_provider_;
|
| + scoped_refptr<TestContextProvider> display_context_provider_;
|
| int num_swaps_ = 0;
|
| size_t num_textures_without_readback_ = 0;
|
| size_t num_textures_with_readback_ = 0;
|
| gpu::SyncToken waited_sync_token_after_readback_;
|
| - FakeContentLayerClient client_;
|
| + FakeContentLayerClient root_client_;
|
| + FakeContentLayerClient copy_client_;
|
| scoped_refptr<FakePictureLayer> root_;
|
| scoped_refptr<FakePictureLayer> copy_layer_;
|
| };
|
|
|