| 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_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 7554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7565 gfx::Rect small_damage = gfx::Rect(0, 0, 1, 1); | 7565 gfx::Rect small_damage = gfx::Rect(0, 0, 1, 1); |
| 7566 host_impl_->active_tree()->root_layer_for_testing()->SetUpdateRect( | 7566 host_impl_->active_tree()->root_layer_for_testing()->SetUpdateRect( |
| 7567 small_damage); | 7567 small_damage); |
| 7568 DrawFrameAndTestDamage(small_damage); | 7568 DrawFrameAndTestDamage(small_damage); |
| 7569 | 7569 |
| 7570 // The third frame should have no damage, so no quads should be generated. | 7570 // The third frame should have no damage, so no quads should be generated. |
| 7571 gfx::Rect no_damage; | 7571 gfx::Rect no_damage; |
| 7572 DrawFrameAndTestDamage(no_damage); | 7572 DrawFrameAndTestDamage(no_damage); |
| 7573 } | 7573 } |
| 7574 | 7574 |
| 7575 // TODO(reveman): Remove this test and the ability to prevent on demand raster | |
| 7576 // when delegating renderer supports PictureDrawQuads. crbug.com/342121 | |
| 7577 TEST_F(LayerTreeHostImplTestWithDelegatingRenderer, PreventRasterizeOnDemand) { | |
| 7578 LayerTreeSettings settings = DefaultSettings(); | |
| 7579 CreateHostImpl(settings, CreateOutputSurface()); | |
| 7580 EXPECT_FALSE(host_impl_->GetRendererCapabilities().allow_rasterize_on_demand); | |
| 7581 } | |
| 7582 | |
| 7583 class GLRendererWithSetupQuadForAntialiasing : public GLRenderer { | 7575 class GLRendererWithSetupQuadForAntialiasing : public GLRenderer { |
| 7584 public: | 7576 public: |
| 7585 using GLRenderer::ShouldAntialiasQuad; | 7577 using GLRenderer::ShouldAntialiasQuad; |
| 7586 }; | 7578 }; |
| 7587 | 7579 |
| 7588 TEST_F(LayerTreeHostImplTest, FarAwayQuadsDontNeedAA) { | 7580 TEST_F(LayerTreeHostImplTest, FarAwayQuadsDontNeedAA) { |
| 7589 // Due to precision issues (especially on Android), sometimes far | 7581 // Due to precision issues (especially on Android), sometimes far |
| 7590 // away quads can end up thinking they need AA. | 7582 // away quads can end up thinking they need AA. |
| 7591 float device_scale_factor = 4.f / 3.f; | 7583 float device_scale_factor = 4.f / 3.f; |
| 7592 gfx::Size root_size(2000, 1000); | 7584 gfx::Size root_size(2000, 1000); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7782 ASSERT_TRUE(host_impl_->active_tree()); | 7774 ASSERT_TRUE(host_impl_->active_tree()); |
| 7783 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); | 7775 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 7784 | 7776 |
| 7785 // RequiresHighResToDraw is set when new output surface is used. | 7777 // RequiresHighResToDraw is set when new output surface is used. |
| 7786 EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); | 7778 EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
| 7787 | 7779 |
| 7788 host_impl_->ResetRequiresHighResToDraw(); | 7780 host_impl_->ResetRequiresHighResToDraw(); |
| 7789 | 7781 |
| 7790 host_impl_->SetContentIsSuitableForGpuRasterization(true); | 7782 host_impl_->SetContentIsSuitableForGpuRasterization(true); |
| 7791 host_impl_->SetHasGpuRasterizationTrigger(false); | 7783 host_impl_->SetHasGpuRasterizationTrigger(false); |
| 7792 host_impl_->UpdateTreeResourcesForGpuRasterizationIfNeeded(); | 7784 host_impl_->CommitComplete(); |
| 7793 EXPECT_FALSE(host_impl_->RequiresHighResToDraw()); | 7785 EXPECT_FALSE(host_impl_->RequiresHighResToDraw()); |
| 7794 host_impl_->SetHasGpuRasterizationTrigger(true); | 7786 host_impl_->SetHasGpuRasterizationTrigger(true); |
| 7795 host_impl_->UpdateTreeResourcesForGpuRasterizationIfNeeded(); | 7787 host_impl_->CommitComplete(); |
| 7796 EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); | 7788 EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
| 7797 host_impl_->SetHasGpuRasterizationTrigger(false); | 7789 host_impl_->SetHasGpuRasterizationTrigger(false); |
| 7798 host_impl_->UpdateTreeResourcesForGpuRasterizationIfNeeded(); | 7790 host_impl_->CommitComplete(); |
| 7799 EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); | 7791 EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
| 7800 | 7792 |
| 7801 host_impl_->ResetRequiresHighResToDraw(); | 7793 host_impl_->ResetRequiresHighResToDraw(); |
| 7802 | 7794 |
| 7803 EXPECT_FALSE(host_impl_->RequiresHighResToDraw()); | 7795 EXPECT_FALSE(host_impl_->RequiresHighResToDraw()); |
| 7804 host_impl_->SetHasGpuRasterizationTrigger(true); | 7796 host_impl_->SetHasGpuRasterizationTrigger(true); |
| 7805 host_impl_->UpdateTreeResourcesForGpuRasterizationIfNeeded(); | 7797 host_impl_->CommitComplete(); |
| 7806 EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); | 7798 EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
| 7807 } | 7799 } |
| 7808 | 7800 |
| 7809 class LayerTreeHostImplTestPrepareTiles : public LayerTreeHostImplTest { | 7801 class LayerTreeHostImplTestPrepareTiles : public LayerTreeHostImplTest { |
| 7810 public: | 7802 public: |
| 7811 void SetUp() override { | 7803 void SetUp() override { |
| 7812 fake_host_impl_ = | 7804 fake_host_impl_ = |
| 7813 new FakeLayerTreeHostImpl(LayerTreeSettings(), &task_runner_provider_, | 7805 new FakeLayerTreeHostImpl(LayerTreeSettings(), &task_runner_provider_, |
| 7814 &shared_bitmap_manager_, &task_graph_runner_); | 7806 &shared_bitmap_manager_, &task_graph_runner_); |
| 7815 host_impl_.reset(fake_host_impl_); | 7807 host_impl_.reset(fake_host_impl_); |
| (...skipping 2792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10608 host_impl_->RemoveVideoFrameController(&controller); | 10600 host_impl_->RemoveVideoFrameController(&controller); |
| 10609 host_impl_->DidDrawAllLayers(frame); | 10601 host_impl_->DidDrawAllLayers(frame); |
| 10610 EXPECT_FALSE(controller.did_draw_frame()); | 10602 EXPECT_FALSE(controller.did_draw_frame()); |
| 10611 } | 10603 } |
| 10612 | 10604 |
| 10613 TEST_F(LayerTreeHostImplTest, GpuRasterizationStatusModes) { | 10605 TEST_F(LayerTreeHostImplTest, GpuRasterizationStatusModes) { |
| 10614 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); | 10606 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 10615 | 10607 |
| 10616 host_impl_->SetHasGpuRasterizationTrigger(true); | 10608 host_impl_->SetHasGpuRasterizationTrigger(true); |
| 10617 host_impl_->SetContentIsSuitableForGpuRasterization(true); | 10609 host_impl_->SetContentIsSuitableForGpuRasterization(true); |
| 10610 host_impl_->CommitComplete(); |
| 10618 EXPECT_EQ(GpuRasterizationStatus::ON, host_impl_->gpu_rasterization_status()); | 10611 EXPECT_EQ(GpuRasterizationStatus::ON, host_impl_->gpu_rasterization_status()); |
| 10619 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); | 10612 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); |
| 10620 | 10613 |
| 10621 host_impl_->SetHasGpuRasterizationTrigger(false); | 10614 host_impl_->SetHasGpuRasterizationTrigger(false); |
| 10622 host_impl_->SetContentIsSuitableForGpuRasterization(true); | 10615 host_impl_->SetContentIsSuitableForGpuRasterization(true); |
| 10616 host_impl_->CommitComplete(); |
| 10623 EXPECT_EQ(GpuRasterizationStatus::OFF_VIEWPORT, | 10617 EXPECT_EQ(GpuRasterizationStatus::OFF_VIEWPORT, |
| 10624 host_impl_->gpu_rasterization_status()); | 10618 host_impl_->gpu_rasterization_status()); |
| 10625 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); | 10619 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 10626 | 10620 |
| 10627 host_impl_->SetHasGpuRasterizationTrigger(true); | 10621 host_impl_->SetHasGpuRasterizationTrigger(true); |
| 10628 host_impl_->SetContentIsSuitableForGpuRasterization(false); | 10622 host_impl_->SetContentIsSuitableForGpuRasterization(false); |
| 10623 host_impl_->CommitComplete(); |
| 10629 EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT, | 10624 EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT, |
| 10630 host_impl_->gpu_rasterization_status()); | 10625 host_impl_->gpu_rasterization_status()); |
| 10631 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); | 10626 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 10632 EXPECT_FALSE(host_impl_->use_msaa()); | 10627 EXPECT_FALSE(host_impl_->use_msaa()); |
| 10633 | 10628 |
| 10634 std::unique_ptr<TestWebGraphicsContext3D> context_with_msaa = | 10629 std::unique_ptr<TestWebGraphicsContext3D> context_with_msaa = |
| 10635 TestWebGraphicsContext3D::Create(); | 10630 TestWebGraphicsContext3D::Create(); |
| 10636 context_with_msaa->SetMaxSamples(8); | 10631 context_with_msaa->SetMaxSamples(8); |
| 10637 | 10632 |
| 10638 LayerTreeSettings msaaSettings = GpuRasterizationEnabledSettings(); | 10633 LayerTreeSettings msaaSettings = GpuRasterizationEnabledSettings(); |
| 10639 msaaSettings.gpu_rasterization_msaa_sample_count = 4; | 10634 msaaSettings.gpu_rasterization_msaa_sample_count = 4; |
| 10640 EXPECT_TRUE(CreateHostImpl( | 10635 EXPECT_TRUE(CreateHostImpl( |
| 10641 msaaSettings, | 10636 msaaSettings, |
| 10642 FakeOutputSurface::CreateDelegating3d(std::move(context_with_msaa)))); | 10637 FakeOutputSurface::CreateDelegating3d(std::move(context_with_msaa)))); |
| 10643 host_impl_->SetHasGpuRasterizationTrigger(true); | 10638 host_impl_->SetHasGpuRasterizationTrigger(true); |
| 10644 host_impl_->SetContentIsSuitableForGpuRasterization(false); | 10639 host_impl_->SetContentIsSuitableForGpuRasterization(false); |
| 10640 host_impl_->CommitComplete(); |
| 10645 EXPECT_EQ(GpuRasterizationStatus::MSAA_CONTENT, | 10641 EXPECT_EQ(GpuRasterizationStatus::MSAA_CONTENT, |
| 10646 host_impl_->gpu_rasterization_status()); | 10642 host_impl_->gpu_rasterization_status()); |
| 10647 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); | 10643 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); |
| 10648 EXPECT_TRUE(host_impl_->use_msaa()); | 10644 EXPECT_TRUE(host_impl_->use_msaa()); |
| 10649 | 10645 |
| 10650 LayerTreeSettings settings = DefaultSettings(); | 10646 LayerTreeSettings settings = DefaultSettings(); |
| 10651 settings.gpu_rasterization_enabled = false; | 10647 settings.gpu_rasterization_enabled = false; |
| 10652 EXPECT_TRUE( | 10648 EXPECT_TRUE( |
| 10653 CreateHostImpl(settings, FakeOutputSurface::CreateDelegating3d())); | 10649 CreateHostImpl(settings, FakeOutputSurface::CreateDelegating3d())); |
| 10654 host_impl_->SetHasGpuRasterizationTrigger(true); | 10650 host_impl_->SetHasGpuRasterizationTrigger(true); |
| 10655 host_impl_->SetContentIsSuitableForGpuRasterization(true); | 10651 host_impl_->SetContentIsSuitableForGpuRasterization(true); |
| 10652 host_impl_->CommitComplete(); |
| 10656 EXPECT_EQ(GpuRasterizationStatus::OFF_DEVICE, | 10653 EXPECT_EQ(GpuRasterizationStatus::OFF_DEVICE, |
| 10657 host_impl_->gpu_rasterization_status()); | 10654 host_impl_->gpu_rasterization_status()); |
| 10658 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); | 10655 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 10659 | 10656 |
| 10660 settings.gpu_rasterization_forced = true; | 10657 settings.gpu_rasterization_forced = true; |
| 10661 EXPECT_TRUE( | 10658 EXPECT_TRUE( |
| 10662 CreateHostImpl(settings, FakeOutputSurface::CreateDelegating3d())); | 10659 CreateHostImpl(settings, FakeOutputSurface::CreateDelegating3d())); |
| 10663 | 10660 |
| 10664 host_impl_->SetHasGpuRasterizationTrigger(false); | 10661 host_impl_->SetHasGpuRasterizationTrigger(false); |
| 10665 host_impl_->SetContentIsSuitableForGpuRasterization(false); | 10662 host_impl_->SetContentIsSuitableForGpuRasterization(false); |
| 10663 host_impl_->CommitComplete(); |
| 10666 EXPECT_EQ(GpuRasterizationStatus::ON_FORCED, | 10664 EXPECT_EQ(GpuRasterizationStatus::ON_FORCED, |
| 10667 host_impl_->gpu_rasterization_status()); | 10665 host_impl_->gpu_rasterization_status()); |
| 10668 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); | 10666 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); |
| 10669 } | 10667 } |
| 10670 | 10668 |
| 10671 class MsaaIsSlowLayerTreeHostImplTest : public LayerTreeHostImplTest { | 10669 class MsaaIsSlowLayerTreeHostImplTest : public LayerTreeHostImplTest { |
| 10672 public: | 10670 public: |
| 10673 void CreateHostImplWithMsaaIsSlow(bool msaa_is_slow) { | 10671 void CreateHostImplWithMsaaIsSlow(bool msaa_is_slow) { |
| 10674 LayerTreeSettings settings = DefaultSettings(); | 10672 LayerTreeSettings settings = DefaultSettings(); |
| 10675 settings.gpu_rasterization_enabled = true; | 10673 settings.gpu_rasterization_enabled = true; |
| 10676 settings.gpu_rasterization_msaa_sample_count = 4; | 10674 settings.gpu_rasterization_msaa_sample_count = 4; |
| 10677 auto context_provider = TestContextProvider::Create(); | 10675 auto context_provider = TestContextProvider::Create(); |
| 10678 context_provider->UnboundTestContext3d()->SetMaxSamples(4); | 10676 context_provider->UnboundTestContext3d()->SetMaxSamples(4); |
| 10679 context_provider->UnboundTestContext3d()->set_msaa_is_slow(msaa_is_slow); | 10677 context_provider->UnboundTestContext3d()->set_msaa_is_slow(msaa_is_slow); |
| 10680 auto msaa_is_normal_output_surface = | 10678 auto msaa_is_normal_output_surface = |
| 10681 FakeOutputSurface::CreateDelegating3d(context_provider); | 10679 FakeOutputSurface::CreateDelegating3d(context_provider); |
| 10682 EXPECT_TRUE( | 10680 EXPECT_TRUE( |
| 10683 CreateHostImpl(settings, std::move(msaa_is_normal_output_surface))); | 10681 CreateHostImpl(settings, std::move(msaa_is_normal_output_surface))); |
| 10684 } | 10682 } |
| 10685 }; | 10683 }; |
| 10686 | 10684 |
| 10687 TEST_F(MsaaIsSlowLayerTreeHostImplTest, GpuRasterizationStatusMsaaIsSlow) { | 10685 TEST_F(MsaaIsSlowLayerTreeHostImplTest, GpuRasterizationStatusMsaaIsSlow) { |
| 10688 // Ensure that without the msaa_is_slow cap we raster unsuitable content with | 10686 // Ensure that without the msaa_is_slow cap we raster unsuitable content with |
| 10689 // msaa. | 10687 // msaa. |
| 10690 CreateHostImplWithMsaaIsSlow(false); | 10688 CreateHostImplWithMsaaIsSlow(false); |
| 10691 host_impl_->SetHasGpuRasterizationTrigger(true); | 10689 host_impl_->SetHasGpuRasterizationTrigger(true); |
| 10692 host_impl_->SetContentIsSuitableForGpuRasterization(false); | 10690 host_impl_->SetContentIsSuitableForGpuRasterization(false); |
| 10691 host_impl_->CommitComplete(); |
| 10693 EXPECT_EQ(GpuRasterizationStatus::MSAA_CONTENT, | 10692 EXPECT_EQ(GpuRasterizationStatus::MSAA_CONTENT, |
| 10694 host_impl_->gpu_rasterization_status()); | 10693 host_impl_->gpu_rasterization_status()); |
| 10695 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); | 10694 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); |
| 10696 | 10695 |
| 10697 // Ensure that with the msaa_is_slow cap we don't raster unsuitable content | 10696 // Ensure that with the msaa_is_slow cap we don't raster unsuitable content |
| 10698 // with msaa. | 10697 // with msaa. |
| 10699 CreateHostImplWithMsaaIsSlow(true); | 10698 CreateHostImplWithMsaaIsSlow(true); |
| 10700 host_impl_->SetHasGpuRasterizationTrigger(true); | 10699 host_impl_->SetHasGpuRasterizationTrigger(true); |
| 10701 host_impl_->SetContentIsSuitableForGpuRasterization(false); | 10700 host_impl_->SetContentIsSuitableForGpuRasterization(false); |
| 10701 host_impl_->CommitComplete(); |
| 10702 EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT, | 10702 EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT, |
| 10703 host_impl_->gpu_rasterization_status()); | 10703 host_impl_->gpu_rasterization_status()); |
| 10704 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); | 10704 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 10705 } | 10705 } |
| 10706 | 10706 |
| 10707 // A mock output surface which lets us detect calls to ForceReclaimResources. | 10707 // A mock output surface which lets us detect calls to ForceReclaimResources. |
| 10708 class MockReclaimResourcesOutputSurface : public FakeOutputSurface { | 10708 class MockReclaimResourcesOutputSurface : public FakeOutputSurface { |
| 10709 public: | 10709 public: |
| 10710 MockReclaimResourcesOutputSurface() | 10710 MockReclaimResourcesOutputSurface() |
| 10711 : FakeOutputSurface(TestContextProvider::Create(), | 10711 : FakeOutputSurface(TestContextProvider::Create(), |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10894 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); | 10894 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); |
| 10895 | 10895 |
| 10896 // Re-initialize with a software output surface. | 10896 // Re-initialize with a software output surface. |
| 10897 output_surface_ = FakeOutputSurface::CreateDelegatingSoftware(); | 10897 output_surface_ = FakeOutputSurface::CreateDelegatingSoftware(); |
| 10898 host_impl_->InitializeRenderer(output_surface_.get()); | 10898 host_impl_->InitializeRenderer(output_surface_.get()); |
| 10899 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); | 10899 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 10900 } | 10900 } |
| 10901 | 10901 |
| 10902 } // namespace | 10902 } // namespace |
| 10903 } // namespace cc | 10903 } // namespace cc |
| OLD | NEW |