Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: cc/trees/layer_tree_host_impl_unittest.cc

Issue 1985973002: Defer compositor context creation to the thread. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: contextfactory: . Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 TEST_F(LayerTreeHostImplTest, ScrollWithoutRootLayer) { 704 TEST_F(LayerTreeHostImplTest, ScrollWithoutRootLayer) {
705 // We should not crash when trying to scroll an empty layer tree. 705 // We should not crash when trying to scroll an empty layer tree.
706 InputHandler::ScrollStatus status = host_impl_->ScrollBegin( 706 InputHandler::ScrollStatus status = host_impl_->ScrollBegin(
707 BeginState(gfx::Point()).get(), InputHandler::WHEEL); 707 BeginState(gfx::Point()).get(), InputHandler::WHEEL);
708 EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); 708 EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread);
709 EXPECT_EQ(MainThreadScrollingReason::kNoScrollingLayer, 709 EXPECT_EQ(MainThreadScrollingReason::kNoScrollingLayer,
710 status.main_thread_scrolling_reasons); 710 status.main_thread_scrolling_reasons);
711 } 711 }
712 712
713 TEST_F(LayerTreeHostImplTest, ScrollWithoutRenderer) { 713 TEST_F(LayerTreeHostImplTest, ScrollWithoutRenderer) {
714 std::unique_ptr<TestWebGraphicsContext3D> context_owned =
715 TestWebGraphicsContext3D::Create();
716 context_owned->set_context_lost(true);
717
718 // Initialization will fail. 714 // Initialization will fail.
719 EXPECT_FALSE( 715 EXPECT_FALSE(CreateHostImpl(
720 CreateHostImpl(DefaultSettings(), 716 DefaultSettings(), FakeOutputSurface::Create3d(
721 FakeOutputSurface::Create3d(std::move(context_owned)))); 717 base::MakeUnique<TestContextProvider::Factory>(
718 TestContextProvider::Factory::kFailCreate))));
722 719
723 SetupScrollAndContentsLayers(gfx::Size(100, 100)); 720 SetupScrollAndContentsLayers(gfx::Size(100, 100));
724 721
725 // We should not crash when trying to scroll after the renderer initialization 722 // We should not crash when trying to scroll after the renderer initialization
726 // fails. 723 // fails.
727 InputHandler::ScrollStatus status = host_impl_->ScrollBegin( 724 InputHandler::ScrollStatus status = host_impl_->ScrollBegin(
728 BeginState(gfx::Point()).get(), InputHandler::WHEEL); 725 BeginState(gfx::Point()).get(), InputHandler::WHEEL);
729 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); 726 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread);
730 EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, 727 EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain,
731 status.main_thread_scrolling_reasons); 728 status.main_thread_scrolling_reasons);
(...skipping 6025 matching lines...) Expand 10 before | Expand all | Expand 10 after
6757 } 6754 }
6758 protected: 6755 protected:
6759 FakeDrawableLayerImpl(LayerTreeImpl* tree_impl, int id) 6756 FakeDrawableLayerImpl(LayerTreeImpl* tree_impl, int id)
6760 : LayerImpl(tree_impl, id) {} 6757 : LayerImpl(tree_impl, id) {}
6761 }; 6758 };
6762 6759
6763 // Only reshape when we know we are going to draw. Otherwise, the reshape 6760 // Only reshape when we know we are going to draw. Otherwise, the reshape
6764 // can leave the window at the wrong size if we never draw and the proper 6761 // can leave the window at the wrong size if we never draw and the proper
6765 // viewport size is never set. 6762 // viewport size is never set.
6766 TEST_F(LayerTreeHostImplTest, ReshapeNotCalledUntilDraw) { 6763 TEST_F(LayerTreeHostImplTest, ReshapeNotCalledUntilDraw) {
6767 scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); 6764 std::unique_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
6768 std::unique_ptr<OutputSurface> output_surface( 6765 base::MakeUnique<TestContextProvider::Factory>()));
6769 FakeOutputSurface::Create3d(provider));
6770 CreateHostImpl(DefaultSettings(), std::move(output_surface)); 6766 CreateHostImpl(DefaultSettings(), std::move(output_surface));
6767 auto* provider = static_cast<TestContextProvider*>(
6768 host_impl_->output_surface()->context_provider());
6771 6769
6772 std::unique_ptr<LayerImpl> root = 6770 std::unique_ptr<LayerImpl> root =
6773 FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 1); 6771 FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 1);
6774 root->SetBounds(gfx::Size(10, 10)); 6772 root->SetBounds(gfx::Size(10, 10));
6775 root->SetDrawsContent(true); 6773 root->SetDrawsContent(true);
6776 root->test_properties()->force_render_surface = true; 6774 root->test_properties()->force_render_surface = true;
6777 host_impl_->active_tree()->SetRootLayer(std::move(root)); 6775 host_impl_->active_tree()->SetRootLayer(std::move(root));
6778 EXPECT_FALSE(provider->TestContext3d()->reshape_called()); 6776 EXPECT_FALSE(provider->TestContext3d()->reshape_called());
6779 provider->TestContext3d()->clear_reshape_called(); 6777 provider->TestContext3d()->clear_reshape_called();
6780 6778
(...skipping 26 matching lines...) Expand all
6807 EXPECT_EQ(provider->TestContext3d()->width(), 20); 6805 EXPECT_EQ(provider->TestContext3d()->width(), 20);
6808 EXPECT_EQ(provider->TestContext3d()->height(), 30); 6806 EXPECT_EQ(provider->TestContext3d()->height(), 30);
6809 EXPECT_EQ(provider->TestContext3d()->scale_factor(), 2.f); 6807 EXPECT_EQ(provider->TestContext3d()->scale_factor(), 2.f);
6810 host_impl_->DidDrawAllLayers(frame); 6808 host_impl_->DidDrawAllLayers(frame);
6811 provider->TestContext3d()->clear_reshape_called(); 6809 provider->TestContext3d()->clear_reshape_called();
6812 } 6810 }
6813 6811
6814 // Make sure damage tracking propagates all the way to the graphics context, 6812 // Make sure damage tracking propagates all the way to the graphics context,
6815 // where it should request to swap only the sub-buffer that is damaged. 6813 // where it should request to swap only the sub-buffer that is damaged.
6816 TEST_F(LayerTreeHostImplTest, PartialSwapReceivesDamageRect) { 6814 TEST_F(LayerTreeHostImplTest, PartialSwapReceivesDamageRect) {
6817 scoped_refptr<TestContextProvider> context_provider( 6815 gpu::Capabilities capabilities;
6818 TestContextProvider::Create()); 6816 capabilities.post_sub_buffer = true;
6819 context_provider->BindToCurrentThread(); 6817 std::unique_ptr<FakeOutputSurface> output_surface(FakeOutputSurface::Create3d(
6820 context_provider->TestContext3d()->set_have_post_sub_buffer(true); 6818 base::MakeUnique<TestContextProvider::Factory>(capabilities)));
6821
6822 std::unique_ptr<FakeOutputSurface> output_surface(
6823 FakeOutputSurface::Create3d(context_provider));
6824 FakeOutputSurface* fake_output_surface = output_surface.get(); 6819 FakeOutputSurface* fake_output_surface = output_surface.get();
6825 6820
6826 // This test creates its own LayerTreeHostImpl, so 6821 // This test creates its own LayerTreeHostImpl, so
6827 // that we can force partial swap enabled. 6822 // that we can force partial swap enabled.
6828 LayerTreeSettings settings = DefaultSettings(); 6823 LayerTreeSettings settings = DefaultSettings();
6829 settings.renderer_settings.partial_swap_enabled = true; 6824 settings.renderer_settings.partial_swap_enabled = true;
6830 std::unique_ptr<LayerTreeHostImpl> layer_tree_host_impl = 6825 std::unique_ptr<LayerTreeHostImpl> layer_tree_host_impl =
6831 LayerTreeHostImpl::Create( 6826 LayerTreeHostImpl::Create(
6832 settings, this, &task_runner_provider_, &stats_instrumentation_, 6827 settings, this, &task_runner_provider_, &stats_instrumentation_,
6833 &shared_bitmap_manager_, NULL, &task_graph_runner_, 0); 6828 &shared_bitmap_manager_, NULL, &task_graph_runner_, 0);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
6972 GLsizei height)); 6967 GLsizei height));
6973 }; 6968 };
6974 6969
6975 class MockContextHarness { 6970 class MockContextHarness {
6976 private: 6971 private:
6977 MockContext* context_; 6972 MockContext* context_;
6978 6973
6979 public: 6974 public:
6980 explicit MockContextHarness(MockContext* context) 6975 explicit MockContextHarness(MockContext* context)
6981 : context_(context) { 6976 : context_(context) {
6982 context_->set_have_post_sub_buffer(true);
6983
6984 // Catch "uninteresting" calls 6977 // Catch "uninteresting" calls
6985 EXPECT_CALL(*context_, useProgram(_)) 6978 EXPECT_CALL(*context_, useProgram(_))
6986 .Times(0); 6979 .Times(0);
6987 6980
6988 EXPECT_CALL(*context_, drawElements(_, _, _, _)) 6981 EXPECT_CALL(*context_, drawElements(_, _, _, _))
6989 .Times(0); 6982 .Times(0);
6990 6983
6991 // These are not asserted 6984 // These are not asserted
6992 EXPECT_CALL(*context_, uniformMatrix4fv(_, _, _, _)) 6985 EXPECT_CALL(*context_, uniformMatrix4fv(_, _, _, _))
6993 .WillRepeatedly(Return()); 6986 .WillRepeatedly(Return());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
7033 EXPECT_CALL(*context_, scissor(_, _, _, _)) 7026 EXPECT_CALL(*context_, scissor(_, _, _, _))
7034 .Times(0); 7027 .Times(0);
7035 } 7028 }
7036 }; 7029 };
7037 7030
7038 TEST_F(LayerTreeHostImplTest, NoPartialSwap) { 7031 TEST_F(LayerTreeHostImplTest, NoPartialSwap) {
7039 std::unique_ptr<MockContext> mock_context_owned(new MockContext); 7032 std::unique_ptr<MockContext> mock_context_owned(new MockContext);
7040 MockContext* mock_context = mock_context_owned.get(); 7033 MockContext* mock_context = mock_context_owned.get();
7041 MockContextHarness harness(mock_context); 7034 MockContextHarness harness(mock_context);
7042 7035
7036 mock_context->set_have_post_sub_buffer(true);
7037
7043 // Run test case 7038 // Run test case
7044 LayerTreeSettings settings = DefaultSettings(); 7039 LayerTreeSettings settings = DefaultSettings();
7045 settings.renderer_settings.partial_swap_enabled = false; 7040 settings.renderer_settings.partial_swap_enabled = false;
7046 CreateHostImpl(settings, 7041 CreateHostImpl(settings, FakeOutputSurface::Create3d(
7047 FakeOutputSurface::Create3d(std::move(mock_context_owned))); 7042 base::MakeUnique<TestContextProvider::Factory>(
7043 std::move(mock_context_owned))));
7048 SetupRootLayerImpl(FakeLayerWithQuads::Create(host_impl_->active_tree(), 1)); 7044 SetupRootLayerImpl(FakeLayerWithQuads::Create(host_impl_->active_tree(), 1));
7049 7045
7050 // Without partial swap, and no clipping, no scissor is set. 7046 // Without partial swap, and no clipping, no scissor is set.
7051 harness.MustDrawSolidQuad(); 7047 harness.MustDrawSolidQuad();
7052 harness.MustSetNoScissor(); 7048 harness.MustSetNoScissor();
7053 { 7049 {
7054 LayerTreeHostImpl::FrameData frame; 7050 LayerTreeHostImpl::FrameData frame;
7055 SetNeedsRebuildPropertyTrees(); 7051 SetNeedsRebuildPropertyTrees();
7056 EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); 7052 EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame));
7057 host_impl_->DrawLayers(&frame); 7053 host_impl_->DrawLayers(&frame);
(...skipping 11 matching lines...) Expand all
7069 LayerTreeHostImpl::FrameData frame; 7065 LayerTreeHostImpl::FrameData frame;
7070 SetNeedsRebuildPropertyTrees(); 7066 SetNeedsRebuildPropertyTrees();
7071 EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); 7067 EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame));
7072 host_impl_->DrawLayers(&frame); 7068 host_impl_->DrawLayers(&frame);
7073 host_impl_->DidDrawAllLayers(frame); 7069 host_impl_->DidDrawAllLayers(frame);
7074 } 7070 }
7075 Mock::VerifyAndClearExpectations(&mock_context); 7071 Mock::VerifyAndClearExpectations(&mock_context);
7076 } 7072 }
7077 7073
7078 TEST_F(LayerTreeHostImplTest, PartialSwap) { 7074 TEST_F(LayerTreeHostImplTest, PartialSwap) {
7079 std::unique_ptr<MockContext> context_owned(new MockContext); 7075 std::unique_ptr<MockContext> mock_context_owned(new MockContext);
7080 MockContext* mock_context = context_owned.get(); 7076 MockContext* mock_context = mock_context_owned.get();
7081 MockContextHarness harness(mock_context); 7077 MockContextHarness harness(mock_context);
7082 7078
7079 mock_context->set_have_post_sub_buffer(true);
7080
7083 LayerTreeSettings settings = DefaultSettings(); 7081 LayerTreeSettings settings = DefaultSettings();
7084 settings.renderer_settings.partial_swap_enabled = true; 7082 settings.renderer_settings.partial_swap_enabled = true;
7085 CreateHostImpl(settings, 7083 CreateHostImpl(settings, FakeOutputSurface::Create3d(
7086 FakeOutputSurface::Create3d(std::move(context_owned))); 7084 base::MakeUnique<TestContextProvider::Factory>(
7085 std::move(mock_context_owned))));
7087 SetupRootLayerImpl(FakeLayerWithQuads::Create(host_impl_->active_tree(), 1)); 7086 SetupRootLayerImpl(FakeLayerWithQuads::Create(host_impl_->active_tree(), 1));
7088 7087
7089 // The first frame is not a partially-swapped one. No scissor should be set. 7088 // The first frame is not a partially-swapped one. No scissor should be set.
7090 harness.MustSetNoScissor(); 7089 harness.MustSetNoScissor();
7091 harness.MustDrawSolidQuad(); 7090 harness.MustDrawSolidQuad();
7092 { 7091 {
7093 LayerTreeHostImpl::FrameData frame; 7092 LayerTreeHostImpl::FrameData frame;
7094 EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); 7093 EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame));
7095 host_impl_->DrawLayers(&frame); 7094 host_impl_->DrawLayers(&frame);
7096 host_impl_->DidDrawAllLayers(frame); 7095 host_impl_->DidDrawAllLayers(frame);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
7183 root->AddChild(std::move(child)); 7182 root->AddChild(std::move(child));
7184 7183
7185 my_host_impl->active_tree()->SetRootLayer(std::move(root)); 7184 my_host_impl->active_tree()->SetRootLayer(std::move(root));
7186 my_host_impl->active_tree()->BuildPropertyTreesForTesting(); 7185 my_host_impl->active_tree()->BuildPropertyTreesForTesting();
7187 return my_host_impl; 7186 return my_host_impl;
7188 } 7187 }
7189 7188
7190 TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorPartialSwap) { 7189 TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorPartialSwap) {
7191 TestSharedBitmapManager shared_bitmap_manager; 7190 TestSharedBitmapManager shared_bitmap_manager;
7192 TestTaskGraphRunner task_graph_runner; 7191 TestTaskGraphRunner task_graph_runner;
7193 scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); 7192 gpu::Capabilities capabilities;
7194 provider->BindToCurrentThread(); 7193 capabilities.post_sub_buffer = true;
7195 provider->TestContext3d()->set_have_post_sub_buffer(true); 7194 std::unique_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
7196 std::unique_ptr<OutputSurface> output_surface( 7195 base::MakeUnique<TestContextProvider::Factory>(capabilities)));
7197 FakeOutputSurface::Create3d(provider));
7198 std::unique_ptr<LayerTreeHostImpl> my_host_impl = SetupLayersForOpacity( 7196 std::unique_ptr<LayerTreeHostImpl> my_host_impl = SetupLayersForOpacity(
7199 DefaultSettings(), true, this, &task_runner_provider_, 7197 DefaultSettings(), true, this, &task_runner_provider_,
7200 &shared_bitmap_manager, &task_graph_runner, &stats_instrumentation_, 7198 &shared_bitmap_manager, &task_graph_runner, &stats_instrumentation_,
7201 output_surface.get()); 7199 output_surface.get());
7202 { 7200 {
7203 LayerTreeHostImpl::FrameData frame; 7201 LayerTreeHostImpl::FrameData frame;
7204 EXPECT_EQ(DRAW_SUCCESS, my_host_impl->PrepareToDraw(&frame)); 7202 EXPECT_EQ(DRAW_SUCCESS, my_host_impl->PrepareToDraw(&frame));
7205 7203
7206 // Verify all quads have been computed 7204 // Verify all quads have been computed
7207 ASSERT_EQ(2U, frame.render_passes.size()); 7205 ASSERT_EQ(2U, frame.render_passes.size());
7208 ASSERT_EQ(1U, frame.render_passes[0]->quad_list.size()); 7206 ASSERT_EQ(1U, frame.render_passes[0]->quad_list.size());
7209 ASSERT_EQ(1U, frame.render_passes[1]->quad_list.size()); 7207 ASSERT_EQ(1U, frame.render_passes[1]->quad_list.size());
7210 EXPECT_EQ(DrawQuad::SOLID_COLOR, 7208 EXPECT_EQ(DrawQuad::SOLID_COLOR,
7211 frame.render_passes[0]->quad_list.front()->material); 7209 frame.render_passes[0]->quad_list.front()->material);
7212 EXPECT_EQ(DrawQuad::RENDER_PASS, 7210 EXPECT_EQ(DrawQuad::RENDER_PASS,
7213 frame.render_passes[1]->quad_list.front()->material); 7211 frame.render_passes[1]->quad_list.front()->material);
7214 7212
7215 my_host_impl->DrawLayers(&frame); 7213 my_host_impl->DrawLayers(&frame);
7216 my_host_impl->DidDrawAllLayers(frame); 7214 my_host_impl->DidDrawAllLayers(frame);
7217 } 7215 }
7218 } 7216 }
7219 7217
7220 TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorNoPartialSwap) { 7218 TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorNoPartialSwap) {
7221 TestSharedBitmapManager shared_bitmap_manager; 7219 TestSharedBitmapManager shared_bitmap_manager;
7222 TestTaskGraphRunner task_graph_runner; 7220 TestTaskGraphRunner task_graph_runner;
7223 scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); 7221 gpu::Capabilities capabilities;
7224 provider->BindToCurrentThread(); 7222 capabilities.post_sub_buffer = true;
7225 provider->TestContext3d()->set_have_post_sub_buffer(true); 7223 std::unique_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
7226 std::unique_ptr<OutputSurface> output_surface( 7224 base::MakeUnique<TestContextProvider::Factory>(capabilities)));
7227 FakeOutputSurface::Create3d(provider));
7228 std::unique_ptr<LayerTreeHostImpl> my_host_impl = SetupLayersForOpacity( 7225 std::unique_ptr<LayerTreeHostImpl> my_host_impl = SetupLayersForOpacity(
7229 DefaultSettings(), false, this, &task_runner_provider_, 7226 DefaultSettings(), false, this, &task_runner_provider_,
7230 &shared_bitmap_manager, &task_graph_runner, &stats_instrumentation_, 7227 &shared_bitmap_manager, &task_graph_runner, &stats_instrumentation_,
7231 output_surface.get()); 7228 output_surface.get());
7232 { 7229 {
7233 LayerTreeHostImpl::FrameData frame; 7230 LayerTreeHostImpl::FrameData frame;
7234 EXPECT_EQ(DRAW_SUCCESS, my_host_impl->PrepareToDraw(&frame)); 7231 EXPECT_EQ(DRAW_SUCCESS, my_host_impl->PrepareToDraw(&frame));
7235 7232
7236 // Verify all quads have been computed 7233 // Verify all quads have been computed
7237 ASSERT_EQ(2U, frame.render_passes.size()); 7234 ASSERT_EQ(2U, frame.render_passes.size());
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
7765 host_impl_->CreateUIResource(ui_resource_id, bitmap); 7762 host_impl_->CreateUIResource(ui_resource_id, bitmap);
7766 EXPECT_EQ(1u, context3d->NumTextures()); 7763 EXPECT_EQ(1u, context3d->NumTextures());
7767 ResourceId id1 = host_impl_->ResourceIdForUIResource(ui_resource_id); 7764 ResourceId id1 = host_impl_->ResourceIdForUIResource(ui_resource_id);
7768 EXPECT_NE(0u, id1); 7765 EXPECT_NE(0u, id1);
7769 } 7766 }
7770 7767
7771 void ShutdownReleasesContext_Callback( 7768 void ShutdownReleasesContext_Callback(
7772 std::unique_ptr<CopyOutputResult> result) {} 7769 std::unique_ptr<CopyOutputResult> result) {}
7773 7770
7774 TEST_F(LayerTreeHostImplTest, ShutdownReleasesContext) { 7771 TEST_F(LayerTreeHostImplTest, ShutdownReleasesContext) {
7775 scoped_refptr<TestContextProvider> context_provider =
7776 TestContextProvider::Create();
7777
7778 CreateHostImpl(DefaultSettings(), 7772 CreateHostImpl(DefaultSettings(),
7779 FakeOutputSurface::Create3d(context_provider)); 7773 FakeOutputSurface::Create3d(
7774 base::MakeUnique<TestContextProvider::Factory>()));
7775 auto* provider = static_cast<TestContextProvider*>(
7776 host_impl_->output_surface()->context_provider());
7780 7777
7781 SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); 7778 SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1));
7782 7779
7783 std::vector<std::unique_ptr<CopyOutputRequest>> requests; 7780 std::vector<std::unique_ptr<CopyOutputRequest>> requests;
7784 requests.push_back(CopyOutputRequest::CreateRequest( 7781 requests.push_back(CopyOutputRequest::CreateRequest(
7785 base::Bind(&ShutdownReleasesContext_Callback))); 7782 base::Bind(&ShutdownReleasesContext_Callback)));
7786 7783
7787 LayerImpl* root = host_impl_->active_tree()->root_layer(); 7784 LayerImpl* root = host_impl_->active_tree()->root_layer();
7788 root->PassCopyRequests(&requests); 7785 root->PassCopyRequests(&requests);
7789 7786
7790 LayerTreeHostImpl::FrameData frame; 7787 LayerTreeHostImpl::FrameData frame;
7791 EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); 7788 EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame));
7792 host_impl_->DrawLayers(&frame); 7789 host_impl_->DrawLayers(&frame);
7793 host_impl_->DidDrawAllLayers(frame); 7790 host_impl_->DidDrawAllLayers(frame);
7794 7791
7792 scoped_refptr<TestContextProvider> saved_context_provider(provider);
7793
7795 // The CopyOutputResult's callback has a ref on the ContextProvider and a 7794 // The CopyOutputResult's callback has a ref on the ContextProvider and a
7796 // texture in a texture mailbox. 7795 // texture in a texture mailbox.
7797 EXPECT_FALSE(context_provider->HasOneRef()); 7796 EXPECT_FALSE(saved_context_provider->HasOneRef());
7798 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); 7797 EXPECT_EQ(1u, saved_context_provider->TestContext3d()->NumTextures());
7799 7798
7800 host_impl_ = nullptr; 7799 host_impl_ = nullptr;
7801 7800
7802 // The CopyOutputResult's callback was cancelled, the CopyOutputResult 7801 // The CopyOutputResult's callback was cancelled, the CopyOutputResult
7803 // released, and the texture deleted. 7802 // released, and the texture deleted.
7804 EXPECT_TRUE(context_provider->HasOneRef()); 7803 EXPECT_TRUE(saved_context_provider->HasOneRef());
7805 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); 7804 EXPECT_EQ(0u, saved_context_provider->TestContext3d()->NumTextures());
7806 } 7805 }
7807 7806
7808 TEST_F(LayerTreeHostImplTest, TouchFlingShouldNotBubble) { 7807 TEST_F(LayerTreeHostImplTest, TouchFlingShouldNotBubble) {
7809 // When flinging via touch, only the child should scroll (we should not 7808 // When flinging via touch, only the child should scroll (we should not
7810 // bubble). 7809 // bubble).
7811 gfx::Size surface_size(10, 10); 7810 gfx::Size surface_size(10, 10);
7812 gfx::Size content_size(20, 20); 7811 gfx::Size content_size(20, 20);
7813 std::unique_ptr<LayerImpl> root_ptr = 7812 std::unique_ptr<LayerImpl> root_ptr =
7814 LayerImpl::Create(host_impl_->active_tree(), 4); 7813 LayerImpl::Create(host_impl_->active_tree(), 4);
7815 std::unique_ptr<LayerImpl> root_clip = 7814 std::unique_ptr<LayerImpl> root_clip =
(...skipping 2661 matching lines...) Expand 10 before | Expand all | Expand 10 after
10477 host_impl_->gpu_rasterization_status()); 10476 host_impl_->gpu_rasterization_status());
10478 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); 10477 EXPECT_FALSE(host_impl_->use_gpu_rasterization());
10479 10478
10480 host_impl_->SetHasGpuRasterizationTrigger(true); 10479 host_impl_->SetHasGpuRasterizationTrigger(true);
10481 host_impl_->SetContentIsSuitableForGpuRasterization(false); 10480 host_impl_->SetContentIsSuitableForGpuRasterization(false);
10482 EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT, 10481 EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT,
10483 host_impl_->gpu_rasterization_status()); 10482 host_impl_->gpu_rasterization_status());
10484 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); 10483 EXPECT_FALSE(host_impl_->use_gpu_rasterization());
10485 EXPECT_FALSE(host_impl_->use_msaa()); 10484 EXPECT_FALSE(host_impl_->use_msaa());
10486 10485
10487 std::unique_ptr<TestWebGraphicsContext3D> context_with_msaa = 10486 gpu::Capabilities capabilities_with_msaa;
10488 TestWebGraphicsContext3D::Create(); 10487 capabilities_with_msaa.max_samples = 8;
10489 context_with_msaa->SetMaxSamples(8); 10488 LayerTreeSettings msaa_settings = GpuRasterizationEnabledSettings();
10490 10489 msaa_settings.gpu_rasterization_msaa_sample_count = 4;
10491 LayerTreeSettings msaaSettings = GpuRasterizationEnabledSettings(); 10490 EXPECT_TRUE(CreateHostImpl(msaa_settings,
10492 msaaSettings.gpu_rasterization_msaa_sample_count = 4; 10491 FakeOutputSurface::Create3d(
10493 EXPECT_TRUE(CreateHostImpl( 10492 base::MakeUnique<TestContextProvider::Factory>(
10494 msaaSettings, FakeOutputSurface::Create3d(std::move(context_with_msaa)))); 10493 capabilities_with_msaa))));
10495 host_impl_->SetHasGpuRasterizationTrigger(true); 10494 host_impl_->SetHasGpuRasterizationTrigger(true);
10496 host_impl_->SetContentIsSuitableForGpuRasterization(false); 10495 host_impl_->SetContentIsSuitableForGpuRasterization(false);
10497 EXPECT_EQ(GpuRasterizationStatus::MSAA_CONTENT, 10496 EXPECT_EQ(GpuRasterizationStatus::MSAA_CONTENT,
10498 host_impl_->gpu_rasterization_status()); 10497 host_impl_->gpu_rasterization_status());
10499 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); 10498 EXPECT_TRUE(host_impl_->use_gpu_rasterization());
10500 EXPECT_TRUE(host_impl_->use_msaa()); 10499 EXPECT_TRUE(host_impl_->use_msaa());
10501 10500
10502 LayerTreeSettings settings = DefaultSettings(); 10501 LayerTreeSettings settings = DefaultSettings();
10503 settings.gpu_rasterization_enabled = false; 10502 settings.gpu_rasterization_enabled = false;
10504 EXPECT_TRUE(CreateHostImpl(settings, FakeOutputSurface::Create3d())); 10503 EXPECT_TRUE(CreateHostImpl(settings, FakeOutputSurface::Create3d()));
(...skipping 12 matching lines...) Expand all
10517 host_impl_->gpu_rasterization_status()); 10516 host_impl_->gpu_rasterization_status());
10518 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); 10517 EXPECT_TRUE(host_impl_->use_gpu_rasterization());
10519 } 10518 }
10520 10519
10521 class MsaaIsSlowLayerTreeHostImplTest : public LayerTreeHostImplTest { 10520 class MsaaIsSlowLayerTreeHostImplTest : public LayerTreeHostImplTest {
10522 public: 10521 public:
10523 void CreateHostImplWithMsaaIsSlow(bool msaa_is_slow) { 10522 void CreateHostImplWithMsaaIsSlow(bool msaa_is_slow) {
10524 LayerTreeSettings settings = DefaultSettings(); 10523 LayerTreeSettings settings = DefaultSettings();
10525 settings.gpu_rasterization_enabled = true; 10524 settings.gpu_rasterization_enabled = true;
10526 settings.gpu_rasterization_msaa_sample_count = 4; 10525 settings.gpu_rasterization_msaa_sample_count = 4;
10527 auto context_provider = TestContextProvider::Create(); 10526 gpu::Capabilities capabilities_with_msaa;
10528 context_provider->UnboundTestContext3d()->SetMaxSamples(4); 10527 capabilities_with_msaa.max_samples = 4;
10529 context_provider->UnboundTestContext3d()->set_msaa_is_slow(msaa_is_slow); 10528 capabilities_with_msaa.msaa_is_slow = msaa_is_slow;
10530 auto msaa_is_normal_output_surface = 10529 auto msaa_is_normal_output_surface = FakeOutputSurface::Create3d(
10531 FakeOutputSurface::Create3d(context_provider); 10530 base::MakeUnique<TestContextProvider::Factory>(capabilities_with_msaa));
10532 EXPECT_TRUE( 10531 EXPECT_TRUE(
10533 CreateHostImpl(settings, std::move(msaa_is_normal_output_surface))); 10532 CreateHostImpl(settings, std::move(msaa_is_normal_output_surface)));
10534 } 10533 }
10535 }; 10534 };
10536 10535
10537 TEST_F(MsaaIsSlowLayerTreeHostImplTest, GpuRasterizationStatusMsaaIsSlow) { 10536 TEST_F(MsaaIsSlowLayerTreeHostImplTest, GpuRasterizationStatusMsaaIsSlow) {
10538 // Ensure that without the msaa_is_slow cap we raster unsuitable content with 10537 // Ensure that without the msaa_is_slow cap we raster unsuitable content with
10539 // msaa. 10538 // msaa.
10540 CreateHostImplWithMsaaIsSlow(false); 10539 CreateHostImplWithMsaaIsSlow(false);
10541 host_impl_->SetHasGpuRasterizationTrigger(true); 10540 host_impl_->SetHasGpuRasterizationTrigger(true);
10542 host_impl_->SetContentIsSuitableForGpuRasterization(false); 10541 host_impl_->SetContentIsSuitableForGpuRasterization(false);
10543 EXPECT_EQ(GpuRasterizationStatus::MSAA_CONTENT, 10542 EXPECT_EQ(GpuRasterizationStatus::MSAA_CONTENT,
10544 host_impl_->gpu_rasterization_status()); 10543 host_impl_->gpu_rasterization_status());
10545 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); 10544 EXPECT_TRUE(host_impl_->use_gpu_rasterization());
10546 10545
10547 // Ensure that with the msaa_is_slow cap we don't raster unsuitable content 10546 // Ensure that with the msaa_is_slow cap we don't raster unsuitable content
10548 // with msaa. 10547 // with msaa.
10549 CreateHostImplWithMsaaIsSlow(true); 10548 CreateHostImplWithMsaaIsSlow(true);
10550 host_impl_->SetHasGpuRasterizationTrigger(true); 10549 host_impl_->SetHasGpuRasterizationTrigger(true);
10551 host_impl_->SetContentIsSuitableForGpuRasterization(false); 10550 host_impl_->SetContentIsSuitableForGpuRasterization(false);
10552 EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT, 10551 EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT,
10553 host_impl_->gpu_rasterization_status()); 10552 host_impl_->gpu_rasterization_status());
10554 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); 10553 EXPECT_FALSE(host_impl_->use_gpu_rasterization());
10555 } 10554 }
10556 10555
10557 // A mock output surface which lets us detect calls to ForceReclaimResources. 10556 // A mock output surface which lets us detect calls to ForceReclaimResources.
10558 class MockReclaimResourcesOutputSurface : public FakeOutputSurface { 10557 class MockReclaimResourcesOutputSurface : public FakeOutputSurface {
10559 public: 10558 public:
10560 static std::unique_ptr<MockReclaimResourcesOutputSurface> Create3d() { 10559 MockReclaimResourcesOutputSurface()
10561 return base::WrapUnique(new MockReclaimResourcesOutputSurface( 10560 : FakeOutputSurface(base::MakeUnique<TestContextProvider::Factory>(),
10562 TestContextProvider::Create(), TestContextProvider::CreateWorker(), 10561 TestContextProvider::Create(),
10563 false)); 10562 false /* delegated rendering */) {}
10564 }
10565 10563
10566 MOCK_METHOD0(ForceReclaimResources, void()); 10564 MOCK_METHOD0(ForceReclaimResources, void());
10567 10565
10568 protected: 10566 protected:
10569 MockReclaimResourcesOutputSurface( 10567 MockReclaimResourcesOutputSurface(
10570 scoped_refptr<ContextProvider> context_provider, 10568 std::unique_ptr<ContextProvider::Factory> compositor_context_factory,
10571 scoped_refptr<ContextProvider> worker_context_provider, 10569 scoped_refptr<ContextProvider> worker_context_provider,
10572 bool delegated_rendering) 10570 bool delegated_rendering)
10573 : FakeOutputSurface(context_provider, 10571 : FakeOutputSurface(std::move(compositor_context_factory),
10574 worker_context_provider, 10572 std::move(worker_context_provider),
10575 delegated_rendering) {} 10573 delegated_rendering) {}
10576 }; 10574 };
10577 10575
10578 // Display::Draw (and the planned Display Scheduler) currently rely on resources 10576 // Display::Draw (and the planned Display Scheduler) currently rely on resources
10579 // being reclaimed to block drawing between BeginCommit / Swap. This test 10577 // being reclaimed to block drawing between BeginCommit / Swap. This test
10580 // ensures that BeginCommit triggers ForceReclaimResources. See 10578 // ensures that BeginCommit triggers ForceReclaimResources. See
10581 // crbug.com/489515. 10579 // crbug.com/489515.
10582 TEST_F(LayerTreeHostImplTest, BeginCommitReclaimsResources) { 10580 TEST_F(LayerTreeHostImplTest, BeginCommitReclaimsResources) {
10583 std::unique_ptr<MockReclaimResourcesOutputSurface> output_surface( 10581 std::unique_ptr<MockReclaimResourcesOutputSurface> output_surface(
10584 MockReclaimResourcesOutputSurface::Create3d()); 10582 new MockReclaimResourcesOutputSurface);
10585 // Hold an unowned pointer to the output surface to use for mock expectations. 10583 // Hold an unowned pointer to the output surface to use for mock expectations.
10586 MockReclaimResourcesOutputSurface* mock_output_surface = output_surface.get(); 10584 MockReclaimResourcesOutputSurface* mock_output_surface = output_surface.get();
10587 10585
10588 CreateHostImpl(DefaultSettings(), std::move(output_surface)); 10586 CreateHostImpl(DefaultSettings(), std::move(output_surface));
10589 EXPECT_CALL(*mock_output_surface, ForceReclaimResources()).Times(1); 10587 EXPECT_CALL(*mock_output_surface, ForceReclaimResources()).Times(1);
10590 host_impl_->BeginCommit(); 10588 host_impl_->BeginCommit();
10591 } 10589 }
10592 10590
10593 TEST_F(LayerTreeHostImplTest, UpdatePageScaleFactorOnActiveTree) { 10591 TEST_F(LayerTreeHostImplTest, UpdatePageScaleFactorOnActiveTree) {
10594 // Check page scale factor update in property trees when an update is made 10592 // Check page scale factor update in property trees when an update is made
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
10747 10745
10748 // Re-initialize with a software output surface. 10746 // Re-initialize with a software output surface.
10749 output_surface_ = FakeOutputSurface::CreateSoftware( 10747 output_surface_ = FakeOutputSurface::CreateSoftware(
10750 base::WrapUnique(new SoftwareOutputDevice)); 10748 base::WrapUnique(new SoftwareOutputDevice));
10751 host_impl_->InitializeRenderer(output_surface_.get()); 10749 host_impl_->InitializeRenderer(output_surface_.get());
10752 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); 10750 EXPECT_FALSE(host_impl_->use_gpu_rasterization());
10753 } 10751 }
10754 10752
10755 } // namespace 10753 } // namespace
10756 } // namespace cc 10754 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698