| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 reduce_memory_result_(true), | 94 reduce_memory_result_(true), |
| 95 current_limit_bytes_(0), | 95 current_limit_bytes_(0), |
| 96 current_priority_cutoff_value_(0) { | 96 current_priority_cutoff_value_(0) { |
| 97 media::InitializeMediaLibraryForTesting(); | 97 media::InitializeMediaLibraryForTesting(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 LayerTreeSettings DefaultSettings() { | 100 LayerTreeSettings DefaultSettings() { |
| 101 LayerTreeSettings settings; | 101 LayerTreeSettings settings; |
| 102 settings.minimum_occlusion_tracking_size = gfx::Size(); | 102 settings.minimum_occlusion_tracking_size = gfx::Size(); |
| 103 settings.impl_side_painting = true; | 103 settings.impl_side_painting = true; |
| 104 settings.texture_id_allocation_chunk_size = 1; | 104 settings.renderer_settings.texture_id_allocation_chunk_size = 1; |
| 105 settings.report_overscroll_only_for_scrollable_axes = true; | 105 settings.report_overscroll_only_for_scrollable_axes = true; |
| 106 settings.use_pinch_virtual_viewport = true; | 106 settings.use_pinch_virtual_viewport = true; |
| 107 return settings; | 107 return settings; |
| 108 } | 108 } |
| 109 | 109 |
| 110 void SetUp() override { | 110 void SetUp() override { |
| 111 CreateHostImpl(DefaultSettings(), CreateOutputSurface()); | 111 CreateHostImpl(DefaultSettings(), CreateOutputSurface()); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void TearDown() override {} | 114 void TearDown() override {} |
| (...skipping 4678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4793 context_provider->BindToCurrentThread(); | 4793 context_provider->BindToCurrentThread(); |
| 4794 context_provider->TestContext3d()->set_have_post_sub_buffer(true); | 4794 context_provider->TestContext3d()->set_have_post_sub_buffer(true); |
| 4795 | 4795 |
| 4796 scoped_ptr<FakeOutputSurface> output_surface( | 4796 scoped_ptr<FakeOutputSurface> output_surface( |
| 4797 FakeOutputSurface::Create3d(context_provider)); | 4797 FakeOutputSurface::Create3d(context_provider)); |
| 4798 FakeOutputSurface* fake_output_surface = output_surface.get(); | 4798 FakeOutputSurface* fake_output_surface = output_surface.get(); |
| 4799 | 4799 |
| 4800 // This test creates its own LayerTreeHostImpl, so | 4800 // This test creates its own LayerTreeHostImpl, so |
| 4801 // that we can force partial swap enabled. | 4801 // that we can force partial swap enabled. |
| 4802 LayerTreeSettings settings; | 4802 LayerTreeSettings settings; |
| 4803 settings.partial_swap_enabled = true; | 4803 settings.renderer_settings.partial_swap_enabled = true; |
| 4804 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 4804 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( |
| 4805 new TestSharedBitmapManager()); | 4805 new TestSharedBitmapManager()); |
| 4806 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl = | 4806 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl = |
| 4807 LayerTreeHostImpl::Create(settings, | 4807 LayerTreeHostImpl::Create(settings, |
| 4808 this, | 4808 this, |
| 4809 &proxy_, | 4809 &proxy_, |
| 4810 &stats_instrumentation_, | 4810 &stats_instrumentation_, |
| 4811 shared_bitmap_manager.get(), | 4811 shared_bitmap_manager.get(), |
| 4812 NULL, | 4812 NULL, |
| 4813 0); | 4813 0); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5009 } | 5009 } |
| 5010 }; | 5010 }; |
| 5011 | 5011 |
| 5012 TEST_F(LayerTreeHostImplTest, NoPartialSwap) { | 5012 TEST_F(LayerTreeHostImplTest, NoPartialSwap) { |
| 5013 scoped_ptr<MockContext> mock_context_owned(new MockContext); | 5013 scoped_ptr<MockContext> mock_context_owned(new MockContext); |
| 5014 MockContext* mock_context = mock_context_owned.get(); | 5014 MockContext* mock_context = mock_context_owned.get(); |
| 5015 MockContextHarness harness(mock_context); | 5015 MockContextHarness harness(mock_context); |
| 5016 | 5016 |
| 5017 // Run test case | 5017 // Run test case |
| 5018 LayerTreeSettings settings = DefaultSettings(); | 5018 LayerTreeSettings settings = DefaultSettings(); |
| 5019 settings.partial_swap_enabled = false; | 5019 settings.renderer_settings.partial_swap_enabled = false; |
| 5020 CreateHostImpl(settings, | 5020 CreateHostImpl(settings, |
| 5021 FakeOutputSurface::Create3d(mock_context_owned.Pass())); | 5021 FakeOutputSurface::Create3d(mock_context_owned.Pass())); |
| 5022 SetupRootLayerImpl(FakeLayerWithQuads::Create(host_impl_->active_tree(), 1)); | 5022 SetupRootLayerImpl(FakeLayerWithQuads::Create(host_impl_->active_tree(), 1)); |
| 5023 | 5023 |
| 5024 // Without partial swap, and no clipping, no scissor is set. | 5024 // Without partial swap, and no clipping, no scissor is set. |
| 5025 harness.MustDrawSolidQuad(); | 5025 harness.MustDrawSolidQuad(); |
| 5026 harness.MustSetNoScissor(); | 5026 harness.MustSetNoScissor(); |
| 5027 { | 5027 { |
| 5028 LayerTreeHostImpl::FrameData frame; | 5028 LayerTreeHostImpl::FrameData frame; |
| 5029 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); | 5029 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 5045 } | 5045 } |
| 5046 Mock::VerifyAndClearExpectations(&mock_context); | 5046 Mock::VerifyAndClearExpectations(&mock_context); |
| 5047 } | 5047 } |
| 5048 | 5048 |
| 5049 TEST_F(LayerTreeHostImplTest, PartialSwap) { | 5049 TEST_F(LayerTreeHostImplTest, PartialSwap) { |
| 5050 scoped_ptr<MockContext> context_owned(new MockContext); | 5050 scoped_ptr<MockContext> context_owned(new MockContext); |
| 5051 MockContext* mock_context = context_owned.get(); | 5051 MockContext* mock_context = context_owned.get(); |
| 5052 MockContextHarness harness(mock_context); | 5052 MockContextHarness harness(mock_context); |
| 5053 | 5053 |
| 5054 LayerTreeSettings settings = DefaultSettings(); | 5054 LayerTreeSettings settings = DefaultSettings(); |
| 5055 settings.partial_swap_enabled = true; | 5055 settings.renderer_settings.partial_swap_enabled = true; |
| 5056 CreateHostImpl(settings, FakeOutputSurface::Create3d(context_owned.Pass())); | 5056 CreateHostImpl(settings, FakeOutputSurface::Create3d(context_owned.Pass())); |
| 5057 SetupRootLayerImpl(FakeLayerWithQuads::Create(host_impl_->active_tree(), 1)); | 5057 SetupRootLayerImpl(FakeLayerWithQuads::Create(host_impl_->active_tree(), 1)); |
| 5058 | 5058 |
| 5059 // The first frame is not a partially-swapped one. | 5059 // The first frame is not a partially-swapped one. |
| 5060 harness.MustSetScissor(0, 0, 10, 10); | 5060 harness.MustSetScissor(0, 0, 10, 10); |
| 5061 harness.MustDrawSolidQuad(); | 5061 harness.MustDrawSolidQuad(); |
| 5062 { | 5062 { |
| 5063 LayerTreeHostImpl::FrameData frame; | 5063 LayerTreeHostImpl::FrameData frame; |
| 5064 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); | 5064 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
| 5065 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); | 5065 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 5089 Proxy* proxy, | 5089 Proxy* proxy, |
| 5090 SharedBitmapManager* manager, | 5090 SharedBitmapManager* manager, |
| 5091 RenderingStatsInstrumentation* stats_instrumentation) { | 5091 RenderingStatsInstrumentation* stats_instrumentation) { |
| 5092 scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); | 5092 scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); |
| 5093 scoped_ptr<OutputSurface> output_surface( | 5093 scoped_ptr<OutputSurface> output_surface( |
| 5094 FakeOutputSurface::Create3d(provider)); | 5094 FakeOutputSurface::Create3d(provider)); |
| 5095 provider->BindToCurrentThread(); | 5095 provider->BindToCurrentThread(); |
| 5096 provider->TestContext3d()->set_have_post_sub_buffer(true); | 5096 provider->TestContext3d()->set_have_post_sub_buffer(true); |
| 5097 | 5097 |
| 5098 LayerTreeSettings settings; | 5098 LayerTreeSettings settings; |
| 5099 settings.partial_swap_enabled = partial_swap; | 5099 settings.renderer_settings.partial_swap_enabled = partial_swap; |
| 5100 scoped_ptr<LayerTreeHostImpl> my_host_impl = LayerTreeHostImpl::Create( | 5100 scoped_ptr<LayerTreeHostImpl> my_host_impl = LayerTreeHostImpl::Create( |
| 5101 settings, client, proxy, stats_instrumentation, manager, NULL, 0); | 5101 settings, client, proxy, stats_instrumentation, manager, NULL, 0); |
| 5102 my_host_impl->InitializeRenderer(output_surface.Pass()); | 5102 my_host_impl->InitializeRenderer(output_surface.Pass()); |
| 5103 my_host_impl->SetViewportSize(gfx::Size(100, 100)); | 5103 my_host_impl->SetViewportSize(gfx::Size(100, 100)); |
| 5104 | 5104 |
| 5105 /* | 5105 /* |
| 5106 Layers are created as follows: | 5106 Layers are created as follows: |
| 5107 | 5107 |
| 5108 +--------------------+ | 5108 +--------------------+ |
| 5109 | 1 | | 5109 | 1 | |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5274 GLintptr offset)); | 5274 GLintptr offset)); |
| 5275 }; | 5275 }; |
| 5276 | 5276 |
| 5277 TEST_F(LayerTreeHostImplTest, HasTransparentBackground) { | 5277 TEST_F(LayerTreeHostImplTest, HasTransparentBackground) { |
| 5278 scoped_ptr<MockDrawQuadsToFillScreenContext> mock_context_owned( | 5278 scoped_ptr<MockDrawQuadsToFillScreenContext> mock_context_owned( |
| 5279 new MockDrawQuadsToFillScreenContext); | 5279 new MockDrawQuadsToFillScreenContext); |
| 5280 MockDrawQuadsToFillScreenContext* mock_context = mock_context_owned.get(); | 5280 MockDrawQuadsToFillScreenContext* mock_context = mock_context_owned.get(); |
| 5281 | 5281 |
| 5282 // Run test case | 5282 // Run test case |
| 5283 LayerTreeSettings settings = DefaultSettings(); | 5283 LayerTreeSettings settings = DefaultSettings(); |
| 5284 settings.partial_swap_enabled = false; | 5284 settings.renderer_settings.partial_swap_enabled = false; |
| 5285 CreateHostImpl(settings, | 5285 CreateHostImpl(settings, |
| 5286 FakeOutputSurface::Create3d(mock_context_owned.Pass())); | 5286 FakeOutputSurface::Create3d(mock_context_owned.Pass())); |
| 5287 SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); | 5287 SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); |
| 5288 host_impl_->active_tree()->set_background_color(SK_ColorWHITE); | 5288 host_impl_->active_tree()->set_background_color(SK_ColorWHITE); |
| 5289 | 5289 |
| 5290 // Verify one quad is drawn when transparent background set is not set. | 5290 // Verify one quad is drawn when transparent background set is not set. |
| 5291 host_impl_->active_tree()->set_has_transparent_background(false); | 5291 host_impl_->active_tree()->set_has_transparent_background(false); |
| 5292 EXPECT_CALL(*mock_context, useProgram(_)) | 5292 EXPECT_CALL(*mock_context, useProgram(_)) |
| 5293 .Times(1); | 5293 .Times(1); |
| 5294 EXPECT_CALL(*mock_context, drawElements(_, _, _, _)) | 5294 EXPECT_CALL(*mock_context, drawElements(_, _, _, _)) |
| (...skipping 2481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7776 // surface. | 7776 // surface. |
| 7777 EXPECT_EQ(0, num_lost_surfaces_); | 7777 EXPECT_EQ(0, num_lost_surfaces_); |
| 7778 host_impl_->DidLoseOutputSurface(); | 7778 host_impl_->DidLoseOutputSurface(); |
| 7779 EXPECT_EQ(1, num_lost_surfaces_); | 7779 EXPECT_EQ(1, num_lost_surfaces_); |
| 7780 host_impl_->DidLoseOutputSurface(); | 7780 host_impl_->DidLoseOutputSurface(); |
| 7781 EXPECT_LE(1, num_lost_surfaces_); | 7781 EXPECT_LE(1, num_lost_surfaces_); |
| 7782 } | 7782 } |
| 7783 | 7783 |
| 7784 } // namespace | 7784 } // namespace |
| 7785 } // namespace cc | 7785 } // namespace cc |
| OLD | NEW |