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 <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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 host_impl_->SetViewportSize(gfx::Size(100, 100)); | 314 host_impl_->SetViewportSize(gfx::Size(100, 100)); |
315 EXPECT_TRUE(host_impl_->CanDraw()); | 315 EXPECT_TRUE(host_impl_->CanDraw()); |
316 EXPECT_TRUE(on_can_draw_state_changed_called_); | 316 EXPECT_TRUE(on_can_draw_state_changed_called_); |
317 on_can_draw_state_changed_called_ = false; | 317 on_can_draw_state_changed_called_ = false; |
318 | 318 |
319 // Toggle contents textures purged without causing any evictions, | 319 // Toggle contents textures purged without causing any evictions, |
320 // and make sure that it does not change can_draw. | 320 // and make sure that it does not change can_draw. |
321 set_reduce_memory_result(false); | 321 set_reduce_memory_result(false); |
322 host_impl_->SetMemoryPolicy(ManagedMemoryPolicy( | 322 host_impl_->SetMemoryPolicy(ManagedMemoryPolicy( |
323 host_impl_->memory_allocation_limit_bytes() - 1)); | 323 host_impl_->memory_allocation_limit_bytes() - 1)); |
324 host_impl_->SetDiscardBackBufferWhenNotVisible(true); | |
325 EXPECT_TRUE(host_impl_->CanDraw()); | 324 EXPECT_TRUE(host_impl_->CanDraw()); |
326 EXPECT_FALSE(on_can_draw_state_changed_called_); | 325 EXPECT_FALSE(on_can_draw_state_changed_called_); |
327 on_can_draw_state_changed_called_ = false; | 326 on_can_draw_state_changed_called_ = false; |
328 | 327 |
329 // Toggle contents textures purged to make sure it toggles can_draw. | 328 // Toggle contents textures purged to make sure it toggles can_draw. |
330 set_reduce_memory_result(true); | 329 set_reduce_memory_result(true); |
331 host_impl_->SetMemoryPolicy(ManagedMemoryPolicy( | 330 host_impl_->SetMemoryPolicy(ManagedMemoryPolicy( |
332 host_impl_->memory_allocation_limit_bytes() - 1)); | 331 host_impl_->memory_allocation_limit_bytes() - 1)); |
333 host_impl_->SetDiscardBackBufferWhenNotVisible(true); | |
334 if (always_draw) { | 332 if (always_draw) { |
335 EXPECT_TRUE(host_impl_->CanDraw()); | 333 EXPECT_TRUE(host_impl_->CanDraw()); |
336 } else { | 334 } else { |
337 EXPECT_FALSE(host_impl_->CanDraw()); | 335 EXPECT_FALSE(host_impl_->CanDraw()); |
338 } | 336 } |
339 EXPECT_TRUE(on_can_draw_state_changed_called_); | 337 EXPECT_TRUE(on_can_draw_state_changed_called_); |
340 on_can_draw_state_changed_called_ = false; | 338 on_can_draw_state_changed_called_ = false; |
341 | 339 |
342 host_impl_->active_tree()->ResetContentsTexturesPurged(); | 340 host_impl_->active_tree()->ResetContentsTexturesPurged(); |
343 EXPECT_TRUE(host_impl_->CanDraw()); | 341 EXPECT_TRUE(host_impl_->CanDraw()); |
(...skipping 3731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4075 TEST_F(LayerTreeHostImplTest, ReleaseContentsTextureShouldTriggerCommit) { | 4073 TEST_F(LayerTreeHostImplTest, ReleaseContentsTextureShouldTriggerCommit) { |
4076 set_reduce_memory_result(false); | 4074 set_reduce_memory_result(false); |
4077 | 4075 |
4078 // If changing the memory limit wouldn't result in changing what was | 4076 // If changing the memory limit wouldn't result in changing what was |
4079 // committed, then no commit should be requested. | 4077 // committed, then no commit should be requested. |
4080 set_reduce_memory_result(false); | 4078 set_reduce_memory_result(false); |
4081 host_impl_->set_max_memory_needed_bytes( | 4079 host_impl_->set_max_memory_needed_bytes( |
4082 host_impl_->memory_allocation_limit_bytes() - 1); | 4080 host_impl_->memory_allocation_limit_bytes() - 1); |
4083 host_impl_->SetMemoryPolicy(ManagedMemoryPolicy( | 4081 host_impl_->SetMemoryPolicy(ManagedMemoryPolicy( |
4084 host_impl_->memory_allocation_limit_bytes() - 1)); | 4082 host_impl_->memory_allocation_limit_bytes() - 1)); |
4085 host_impl_->SetDiscardBackBufferWhenNotVisible(true); | |
4086 EXPECT_FALSE(did_request_commit_); | 4083 EXPECT_FALSE(did_request_commit_); |
4087 did_request_commit_ = false; | 4084 did_request_commit_ = false; |
4088 | 4085 |
4089 // If changing the memory limit would result in changing what was | 4086 // If changing the memory limit would result in changing what was |
4090 // committed, then a commit should be requested, even though nothing was | 4087 // committed, then a commit should be requested, even though nothing was |
4091 // evicted. | 4088 // evicted. |
4092 set_reduce_memory_result(false); | 4089 set_reduce_memory_result(false); |
4093 host_impl_->set_max_memory_needed_bytes( | 4090 host_impl_->set_max_memory_needed_bytes( |
4094 host_impl_->memory_allocation_limit_bytes()); | 4091 host_impl_->memory_allocation_limit_bytes()); |
4095 host_impl_->SetMemoryPolicy(ManagedMemoryPolicy( | 4092 host_impl_->SetMemoryPolicy(ManagedMemoryPolicy( |
4096 host_impl_->memory_allocation_limit_bytes() - 1)); | 4093 host_impl_->memory_allocation_limit_bytes() - 1)); |
4097 host_impl_->SetDiscardBackBufferWhenNotVisible(true); | |
4098 EXPECT_TRUE(did_request_commit_); | 4094 EXPECT_TRUE(did_request_commit_); |
4099 did_request_commit_ = false; | 4095 did_request_commit_ = false; |
4100 | 4096 |
4101 // Especially if changing the memory limit caused evictions, we need | 4097 // Especially if changing the memory limit caused evictions, we need |
4102 // to re-commit. | 4098 // to re-commit. |
4103 set_reduce_memory_result(true); | 4099 set_reduce_memory_result(true); |
4104 host_impl_->set_max_memory_needed_bytes(1); | 4100 host_impl_->set_max_memory_needed_bytes(1); |
4105 host_impl_->SetMemoryPolicy(ManagedMemoryPolicy( | 4101 host_impl_->SetMemoryPolicy(ManagedMemoryPolicy( |
4106 host_impl_->memory_allocation_limit_bytes() - 1)); | 4102 host_impl_->memory_allocation_limit_bytes() - 1)); |
4107 host_impl_->SetDiscardBackBufferWhenNotVisible(true); | |
4108 EXPECT_TRUE(did_request_commit_); | 4103 EXPECT_TRUE(did_request_commit_); |
4109 did_request_commit_ = false; | 4104 did_request_commit_ = false; |
4110 | 4105 |
4111 // But if we set it to the same value that it was before, we shouldn't | 4106 // But if we set it to the same value that it was before, we shouldn't |
4112 // re-commit. | 4107 // re-commit. |
4113 host_impl_->SetMemoryPolicy(ManagedMemoryPolicy( | 4108 host_impl_->SetMemoryPolicy(ManagedMemoryPolicy( |
4114 host_impl_->memory_allocation_limit_bytes())); | 4109 host_impl_->memory_allocation_limit_bytes())); |
4115 host_impl_->SetDiscardBackBufferWhenNotVisible(true); | |
4116 EXPECT_FALSE(did_request_commit_); | 4110 EXPECT_FALSE(did_request_commit_); |
4117 } | 4111 } |
4118 | 4112 |
4119 class LayerTreeHostImplTestWithDelegatingRenderer | 4113 class LayerTreeHostImplTestWithDelegatingRenderer |
4120 : public LayerTreeHostImplTest { | 4114 : public LayerTreeHostImplTest { |
4121 protected: | 4115 protected: |
4122 virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE { | 4116 virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE { |
4123 return FakeOutputSurface::CreateDelegating3d().PassAs<OutputSurface>(); | 4117 return FakeOutputSurface::CreateDelegating3d().PassAs<OutputSurface>(); |
4124 } | 4118 } |
4125 | 4119 |
(...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5208 settings, this, &proxy_, &stats_instrumentation_, NULL); | 5202 settings, this, &proxy_, &stats_instrumentation_, NULL); |
5209 | 5203 |
5210 scoped_ptr<OutputSurface> output_surface( | 5204 scoped_ptr<OutputSurface> output_surface( |
5211 FakeOutputSurface::Create3d(TestWebGraphicsContext3D::Create())); | 5205 FakeOutputSurface::Create3d(TestWebGraphicsContext3D::Create())); |
5212 host_impl_->InitializeRenderer(output_surface.Pass()); | 5206 host_impl_->InitializeRenderer(output_surface.Pass()); |
5213 EXPECT_LT(0ul, host_impl_->memory_allocation_limit_bytes()); | 5207 EXPECT_LT(0ul, host_impl_->memory_allocation_limit_bytes()); |
5214 } | 5208 } |
5215 | 5209 |
5216 TEST_F(LayerTreeHostImplTest, MemoryPolicy) { | 5210 TEST_F(LayerTreeHostImplTest, MemoryPolicy) { |
5217 ManagedMemoryPolicy policy1( | 5211 ManagedMemoryPolicy policy1( |
5218 456, gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, | 5212 456, gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, 1000); |
5219 123, gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, 1000); | 5213 int everything_cutoff_value = ManagedMemoryPolicy::PriorityCutoffToValue( |
5220 int visible_cutoff_value = ManagedMemoryPolicy::PriorityCutoffToValue( | 5214 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING); |
5221 policy1.priority_cutoff_when_visible); | 5215 int nothing_cutoff_value = ManagedMemoryPolicy::PriorityCutoffToValue( |
5222 int not_visible_cutoff_value = ManagedMemoryPolicy::PriorityCutoffToValue( | 5216 gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING); |
5223 policy1.priority_cutoff_when_not_visible); | |
5224 | 5217 |
5225 host_impl_->SetVisible(true); | 5218 host_impl_->SetVisible(true); |
5226 host_impl_->SetMemoryPolicy(policy1); | 5219 host_impl_->SetMemoryPolicy(policy1); |
5227 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); | 5220 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); |
5228 EXPECT_EQ(visible_cutoff_value, current_priority_cutoff_value_); | 5221 EXPECT_EQ(everything_cutoff_value, current_priority_cutoff_value_); |
5229 | 5222 |
5230 host_impl_->SetVisible(false); | 5223 host_impl_->SetVisible(false); |
5231 EXPECT_EQ(policy1.bytes_limit_when_not_visible, current_limit_bytes_); | 5224 EXPECT_EQ(0u, current_limit_bytes_); |
5232 EXPECT_EQ(not_visible_cutoff_value, current_priority_cutoff_value_); | 5225 EXPECT_EQ(nothing_cutoff_value, current_priority_cutoff_value_); |
5233 | 5226 |
5234 host_impl_->SetVisible(true); | 5227 host_impl_->SetVisible(true); |
5235 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); | 5228 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); |
5236 EXPECT_EQ(visible_cutoff_value, current_priority_cutoff_value_); | 5229 EXPECT_EQ(everything_cutoff_value, current_priority_cutoff_value_); |
5237 } | 5230 } |
5238 | 5231 |
5239 class LayerTreeHostImplTestManageTiles : public LayerTreeHostImplTest { | 5232 class LayerTreeHostImplTestManageTiles : public LayerTreeHostImplTest { |
5240 public: | 5233 public: |
5241 virtual void SetUp() OVERRIDE { | 5234 virtual void SetUp() OVERRIDE { |
5242 LayerTreeSettings settings; | 5235 LayerTreeSettings settings; |
5243 settings.impl_side_painting = true; | 5236 settings.impl_side_painting = true; |
5244 | 5237 |
5245 fake_host_impl_ = new FakeLayerTreeHostImpl(settings, &proxy_); | 5238 fake_host_impl_ = new FakeLayerTreeHostImpl(settings, &proxy_); |
5246 host_impl_.reset(fake_host_impl_); | 5239 host_impl_.reset(fake_host_impl_); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5465 // The root should have scrolled. | 5458 // The root should have scrolled. |
5466 ASSERT_EQ(2u, scroll_info->scrolls.size()); | 5459 ASSERT_EQ(2u, scroll_info->scrolls.size()); |
5467 ExpectContains(*scroll_info.get(), | 5460 ExpectContains(*scroll_info.get(), |
5468 host_impl_->active_tree()->root_layer()->id(), | 5461 host_impl_->active_tree()->root_layer()->id(), |
5469 gfx::Vector2d(0, 10)); | 5462 gfx::Vector2d(0, 10)); |
5470 } | 5463 } |
5471 } | 5464 } |
5472 | 5465 |
5473 } // namespace | 5466 } // namespace |
5474 } // namespace cc | 5467 } // namespace cc |
OLD | NEW |