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

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

Issue 465853004: Moving RenderSurface creation outside of CalcDrawProps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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 <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 30 matching lines...) Expand all
41 #include "cc/test/fake_layer_tree_host_impl.h" 41 #include "cc/test/fake_layer_tree_host_impl.h"
42 #include "cc/test/fake_output_surface.h" 42 #include "cc/test/fake_output_surface.h"
43 #include "cc/test/fake_output_surface_client.h" 43 #include "cc/test/fake_output_surface_client.h"
44 #include "cc/test/fake_picture_layer_impl.h" 44 #include "cc/test/fake_picture_layer_impl.h"
45 #include "cc/test/fake_picture_pile_impl.h" 45 #include "cc/test/fake_picture_pile_impl.h"
46 #include "cc/test/fake_proxy.h" 46 #include "cc/test/fake_proxy.h"
47 #include "cc/test/fake_rendering_stats_instrumentation.h" 47 #include "cc/test/fake_rendering_stats_instrumentation.h"
48 #include "cc/test/fake_video_frame_provider.h" 48 #include "cc/test/fake_video_frame_provider.h"
49 #include "cc/test/geometry_test_utils.h" 49 #include "cc/test/geometry_test_utils.h"
50 #include "cc/test/layer_test_common.h" 50 #include "cc/test/layer_test_common.h"
51 #include "cc/test/layer_tree_test.h"
51 #include "cc/test/render_pass_test_common.h" 52 #include "cc/test/render_pass_test_common.h"
52 #include "cc/test/test_shared_bitmap_manager.h" 53 #include "cc/test/test_shared_bitmap_manager.h"
53 #include "cc/test/test_web_graphics_context_3d.h" 54 #include "cc/test/test_web_graphics_context_3d.h"
54 #include "cc/trees/layer_tree_impl.h" 55 #include "cc/trees/layer_tree_impl.h"
55 #include "cc/trees/single_thread_proxy.h" 56 #include "cc/trees/single_thread_proxy.h"
56 #include "media/base/media.h" 57 #include "media/base/media.h"
57 #include "testing/gmock/include/gmock/gmock.h" 58 #include "testing/gmock/include/gmock/gmock.h"
58 #include "testing/gtest/include/gtest/gtest.h" 59 #include "testing/gtest/include/gtest/gtest.h"
59 #include "third_party/skia/include/core/SkMallocPixelRef.h" 60 #include "third_party/skia/include/core/SkMallocPixelRef.h"
60 #include "ui/gfx/frame_time.h" 61 #include "ui/gfx/frame_time.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 163 }
163 virtual void DidActivateSyncTree() OVERRIDE {} 164 virtual void DidActivateSyncTree() OVERRIDE {}
164 virtual void DidManageTiles() OVERRIDE {} 165 virtual void DidManageTiles() OVERRIDE {}
165 166
166 void set_reduce_memory_result(bool reduce_memory_result) { 167 void set_reduce_memory_result(bool reduce_memory_result) {
167 reduce_memory_result_ = reduce_memory_result; 168 reduce_memory_result_ = reduce_memory_result;
168 } 169 }
169 170
170 bool CreateHostImpl(const LayerTreeSettings& settings, 171 bool CreateHostImpl(const LayerTreeSettings& settings,
171 scoped_ptr<OutputSurface> output_surface) { 172 scoped_ptr<OutputSurface> output_surface) {
172 host_impl_ = LayerTreeHostImpl::Create(settings, 173 host_impl_ =
173 this, 174 PseudoSyncingLayerTreeHostImpl::Create(settings,
174 &proxy_, 175 this,
175 &stats_instrumentation_, 176 &proxy_,
176 shared_bitmap_manager_.get(), 177 &stats_instrumentation_,
177 0); 178 shared_bitmap_manager_.get(),
179 0);
178 bool init = host_impl_->InitializeRenderer(output_surface.Pass()); 180 bool init = host_impl_->InitializeRenderer(output_surface.Pass());
179 host_impl_->SetViewportSize(gfx::Size(10, 10)); 181 host_impl_->SetViewportSize(gfx::Size(10, 10));
180 return init; 182 return init;
181 } 183 }
182 184
183 void SetupRootLayerImpl(scoped_ptr<LayerImpl> root) { 185 void SetupRootLayerImpl(scoped_ptr<LayerImpl> root) {
184 root->SetPosition(gfx::PointF()); 186 root->SetPosition(gfx::PointF());
185 root->SetBounds(gfx::Size(10, 10)); 187 root->SetBounds(gfx::Size(10, 10));
186 root->SetContentBounds(gfx::Size(10, 10)); 188 root->SetContentBounds(gfx::Size(10, 10));
187 root->SetDrawsContent(true); 189 root->SetDrawsContent(true);
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 host_impl_->Animate(end_time); 1310 host_impl_->Animate(end_time);
1309 EXPECT_TRUE(did_request_commit_); 1311 EXPECT_TRUE(did_request_commit_);
1310 1312
1311 scoped_ptr<ScrollAndScaleSet> scroll_info = 1313 scoped_ptr<ScrollAndScaleSet> scroll_info =
1312 host_impl_->ProcessScrollDeltas(); 1314 host_impl_->ProcessScrollDeltas();
1313 EXPECT_EQ(scroll_info->page_scale_delta, 1); 1315 EXPECT_EQ(scroll_info->page_scale_delta, 1);
1314 ExpectNone(*scroll_info, scroll_layer->id()); 1316 ExpectNone(*scroll_info, scroll_layer->id());
1315 } 1317 }
1316 } 1318 }
1317 1319
1318 class LayerTreeHostImplOverridePhysicalTime : public LayerTreeHostImpl { 1320 class LayerTreeHostImplOverridePhysicalTime
1321 : public PseudoSyncingLayerTreeHostImpl {
1319 public: 1322 public:
1320 LayerTreeHostImplOverridePhysicalTime( 1323 LayerTreeHostImplOverridePhysicalTime(
1321 const LayerTreeSettings& settings, 1324 const LayerTreeSettings& settings,
1322 LayerTreeHostImplClient* client, 1325 LayerTreeHostImplClient* client,
1323 Proxy* proxy, 1326 Proxy* proxy,
1324 SharedBitmapManager* manager, 1327 SharedBitmapManager* manager,
1325 RenderingStatsInstrumentation* rendering_stats_instrumentation) 1328 RenderingStatsInstrumentation* rendering_stats_instrumentation)
1326 : LayerTreeHostImpl(settings, 1329 : PseudoSyncingLayerTreeHostImpl(settings,
1327 client, 1330 client,
1328 proxy, 1331 proxy,
1329 rendering_stats_instrumentation, 1332 rendering_stats_instrumentation,
1330 manager, 1333 manager,
1331 0) {} 1334 0) {}
1332 1335
1333 virtual base::TimeTicks CurrentFrameTimeTicks() OVERRIDE { 1336 virtual base::TimeTicks CurrentFrameTimeTicks() OVERRIDE {
1334 return fake_current_physical_time_; 1337 return fake_current_physical_time_;
1335 } 1338 }
1336 1339
1337 void SetCurrentPhysicalTimeTicksForTest(base::TimeTicks fake_now) { 1340 void SetCurrentPhysicalTimeTicksForTest(base::TimeTicks fake_now) {
1338 fake_current_physical_time_ = fake_now; 1341 fake_current_physical_time_ = fake_now;
1339 } 1342 }
1340 1343
1341 private: 1344 private:
(...skipping 2819 matching lines...) Expand 10 before | Expand all | Expand 10 after
4161 scoped_ptr<OutputSurface> output_surface( 4164 scoped_ptr<OutputSurface> output_surface(
4162 FakeOutputSurface::Create3d(context_provider)); 4165 FakeOutputSurface::Create3d(context_provider));
4163 4166
4164 // This test creates its own LayerTreeHostImpl, so 4167 // This test creates its own LayerTreeHostImpl, so
4165 // that we can force partial swap enabled. 4168 // that we can force partial swap enabled.
4166 LayerTreeSettings settings; 4169 LayerTreeSettings settings;
4167 settings.partial_swap_enabled = true; 4170 settings.partial_swap_enabled = true;
4168 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( 4171 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
4169 new TestSharedBitmapManager()); 4172 new TestSharedBitmapManager());
4170 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl = 4173 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl =
4171 LayerTreeHostImpl::Create(settings, 4174 PseudoSyncingLayerTreeHostImpl::Create(settings,
4172 this, 4175 this,
4173 &proxy_, 4176 &proxy_,
4174 &stats_instrumentation_, 4177 &stats_instrumentation_,
4175 shared_bitmap_manager.get(), 4178 shared_bitmap_manager.get(),
4176 0); 4179 0);
4177 layer_tree_host_impl->InitializeRenderer(output_surface.Pass()); 4180 layer_tree_host_impl->InitializeRenderer(output_surface.Pass());
4178 layer_tree_host_impl->SetViewportSize(gfx::Size(500, 500)); 4181 layer_tree_host_impl->SetViewportSize(gfx::Size(500, 500));
4179 4182
4180 scoped_ptr<LayerImpl> root = 4183 scoped_ptr<LayerImpl> root =
4181 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 1); 4184 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 1);
4182 scoped_ptr<LayerImpl> child = 4185 scoped_ptr<LayerImpl> child =
4183 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 2); 4186 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 2);
4184 child->SetPosition(gfx::PointF(12.f, 13.f)); 4187 child->SetPosition(gfx::PointF(12.f, 13.f));
4185 child->SetBounds(gfx::Size(14, 15)); 4188 child->SetBounds(gfx::Size(14, 15));
4186 child->SetContentBounds(gfx::Size(14, 15)); 4189 child->SetContentBounds(gfx::Size(14, 15));
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
4458 SharedBitmapManager* manager, 4461 SharedBitmapManager* manager,
4459 RenderingStatsInstrumentation* stats_instrumentation) { 4462 RenderingStatsInstrumentation* stats_instrumentation) {
4460 scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); 4463 scoped_refptr<TestContextProvider> provider(TestContextProvider::Create());
4461 scoped_ptr<OutputSurface> output_surface( 4464 scoped_ptr<OutputSurface> output_surface(
4462 FakeOutputSurface::Create3d(provider)); 4465 FakeOutputSurface::Create3d(provider));
4463 provider->BindToCurrentThread(); 4466 provider->BindToCurrentThread();
4464 provider->TestContext3d()->set_have_post_sub_buffer(true); 4467 provider->TestContext3d()->set_have_post_sub_buffer(true);
4465 4468
4466 LayerTreeSettings settings; 4469 LayerTreeSettings settings;
4467 settings.partial_swap_enabled = partial_swap; 4470 settings.partial_swap_enabled = partial_swap;
4468 scoped_ptr<LayerTreeHostImpl> my_host_impl = LayerTreeHostImpl::Create( 4471 scoped_ptr<LayerTreeHostImpl> my_host_impl =
4469 settings, client, proxy, stats_instrumentation, manager, 0); 4472 PseudoSyncingLayerTreeHostImpl::Create(
4473 settings, client, proxy, stats_instrumentation, manager, 0);
4470 my_host_impl->InitializeRenderer(output_surface.Pass()); 4474 my_host_impl->InitializeRenderer(output_surface.Pass());
4471 my_host_impl->SetViewportSize(gfx::Size(100, 100)); 4475 my_host_impl->SetViewportSize(gfx::Size(100, 100));
4472 4476
4473 /* 4477 /*
4474 Layers are created as follows: 4478 Layers are created as follows:
4475 4479
4476 +--------------------+ 4480 +--------------------+
4477 | 1 | 4481 | 1 |
4478 | +-----------+ | 4482 | +-----------+ |
4479 | | 2 | | 4483 | | 2 | |
(...skipping 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after
5731 EXPECT_FALSE(did_update_renderer_capabilities_); 5735 EXPECT_FALSE(did_update_renderer_capabilities_);
5732 5736
5733 // Software draw again. 5737 // Software draw again.
5734 DrawFrame(); 5738 DrawFrame();
5735 } 5739 }
5736 5740
5737 // Checks that we have a non-0 default allocation if we pass a context that 5741 // Checks that we have a non-0 default allocation if we pass a context that
5738 // doesn't support memory management extensions. 5742 // doesn't support memory management extensions.
5739 TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) { 5743 TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) {
5740 LayerTreeSettings settings; 5744 LayerTreeSettings settings;
5741 host_impl_ = LayerTreeHostImpl::Create(settings, 5745 host_impl_ =
5742 this, 5746 PseudoSyncingLayerTreeHostImpl::Create(settings,
5743 &proxy_, 5747 this,
5744 &stats_instrumentation_, 5748 &proxy_,
5745 shared_bitmap_manager_.get(), 5749 &stats_instrumentation_,
5746 0); 5750 shared_bitmap_manager_.get(),
5751 0);
5747 5752
5748 scoped_ptr<OutputSurface> output_surface( 5753 scoped_ptr<OutputSurface> output_surface(
5749 FakeOutputSurface::Create3d(TestWebGraphicsContext3D::Create())); 5754 FakeOutputSurface::Create3d(TestWebGraphicsContext3D::Create()));
5750 host_impl_->InitializeRenderer(output_surface.Pass()); 5755 host_impl_->InitializeRenderer(output_surface.Pass());
5751 EXPECT_LT(0ul, host_impl_->memory_allocation_limit_bytes()); 5756 EXPECT_LT(0ul, host_impl_->memory_allocation_limit_bytes());
5752 } 5757 }
5753 5758
5754 TEST_F(LayerTreeHostImplTest, MemoryPolicy) { 5759 TEST_F(LayerTreeHostImplTest, MemoryPolicy) {
5755 ManagedMemoryPolicy policy1( 5760 ManagedMemoryPolicy policy1(
5756 456, gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, 1000); 5761 456, gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, 1000);
(...skipping 19 matching lines...) Expand all
5776 EXPECT_EQ(nothing_cutoff_value, current_priority_cutoff_value_); 5781 EXPECT_EQ(nothing_cutoff_value, current_priority_cutoff_value_);
5777 5782
5778 host_impl_->SetVisible(true); 5783 host_impl_->SetVisible(true);
5779 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); 5784 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_);
5780 EXPECT_EQ(everything_cutoff_value, current_priority_cutoff_value_); 5785 EXPECT_EQ(everything_cutoff_value, current_priority_cutoff_value_);
5781 5786
5782 // Now enable GPU rasterization and test if we get nice to have cutoff, 5787 // Now enable GPU rasterization and test if we get nice to have cutoff,
5783 // when visible. 5788 // when visible.
5784 LayerTreeSettings settings; 5789 LayerTreeSettings settings;
5785 settings.gpu_rasterization_enabled = true; 5790 settings.gpu_rasterization_enabled = true;
5786 host_impl_ = LayerTreeHostImpl::Create( 5791 host_impl_ = PseudoSyncingLayerTreeHostImpl::Create(
5787 settings, this, &proxy_, &stats_instrumentation_, NULL, 0); 5792 settings, this, &proxy_, &stats_instrumentation_, NULL, 0);
5788 host_impl_->SetUseGpuRasterization(true); 5793 host_impl_->SetUseGpuRasterization(true);
5789 host_impl_->SetVisible(true); 5794 host_impl_->SetVisible(true);
5790 host_impl_->SetMemoryPolicy(policy1); 5795 host_impl_->SetMemoryPolicy(policy1);
5791 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); 5796 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_);
5792 EXPECT_EQ(allow_nice_to_have_cutoff_value, current_priority_cutoff_value_); 5797 EXPECT_EQ(allow_nice_to_have_cutoff_value, current_priority_cutoff_value_);
5793 5798
5794 host_impl_->SetVisible(false); 5799 host_impl_->SetVisible(false);
5795 EXPECT_EQ(0u, current_limit_bytes_); 5800 EXPECT_EQ(0u, current_limit_bytes_);
5796 EXPECT_EQ(nothing_cutoff_value, current_priority_cutoff_value_); 5801 EXPECT_EQ(nothing_cutoff_value, current_priority_cutoff_value_);
(...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after
7024 host_impl_->DidLoseOutputSurface(); 7029 host_impl_->DidLoseOutputSurface();
7025 EXPECT_TRUE(host_impl_->IsContextLost()); 7030 EXPECT_TRUE(host_impl_->IsContextLost());
7026 EXPECT_EQ(1, num_lost_surfaces_); 7031 EXPECT_EQ(1, num_lost_surfaces_);
7027 host_impl_->DidLoseOutputSurface(); 7032 host_impl_->DidLoseOutputSurface();
7028 EXPECT_TRUE(host_impl_->IsContextLost()); 7033 EXPECT_TRUE(host_impl_->IsContextLost());
7029 EXPECT_EQ(1, num_lost_surfaces_); 7034 EXPECT_EQ(1, num_lost_surfaces_);
7030 } 7035 }
7031 7036
7032 } // namespace 7037 } // namespace
7033 } // namespace cc 7038 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698