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

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

Issue 53633003: Do not give GPU memory to backgrounded compositors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove test Created 7 years, 1 month 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 | Annotate | Revision Log
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.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 1885 matching lines...) Expand 10 before | Expand all | Expand 10 after
1896 case 0: 1896 case 0:
1897 EXPECT_TRUE(renderer->HasAllocatedResourcesForTesting( 1897 EXPECT_TRUE(renderer->HasAllocatedResourcesForTesting(
1898 surface1_render_pass_id)); 1898 surface1_render_pass_id));
1899 EXPECT_TRUE(renderer->HasAllocatedResourcesForTesting( 1899 EXPECT_TRUE(renderer->HasAllocatedResourcesForTesting(
1900 surface2_render_pass_id)); 1900 surface2_render_pass_id));
1901 1901
1902 // Reduce the memory limit to only fit the root layer and one render 1902 // Reduce the memory limit to only fit the root layer and one render
1903 // surface. This prevents any contents drawing into surfaces 1903 // surface. This prevents any contents drawing into surfaces
1904 // from being allocated. 1904 // from being allocated.
1905 host_impl->SetMemoryPolicy(ManagedMemoryPolicy(100 * 100 * 4 * 2)); 1905 host_impl->SetMemoryPolicy(ManagedMemoryPolicy(100 * 100 * 4 * 2));
1906 host_impl->SetDiscardBackBufferWhenNotVisible(true);
1907 break; 1906 break;
1908 case 1: 1907 case 1:
1909 EXPECT_FALSE(renderer->HasAllocatedResourcesForTesting( 1908 EXPECT_FALSE(renderer->HasAllocatedResourcesForTesting(
1910 surface1_render_pass_id)); 1909 surface1_render_pass_id));
1911 EXPECT_FALSE(renderer->HasAllocatedResourcesForTesting( 1910 EXPECT_FALSE(renderer->HasAllocatedResourcesForTesting(
1912 surface2_render_pass_id)); 1911 surface2_render_pass_id));
1913 1912
1914 EndTest(); 1913 EndTest();
1915 break; 1914 break;
1916 } 1915 }
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
2424 child_layer1_->SetBounds(gfx::Size(100, 100)); 2423 child_layer1_->SetBounds(gfx::Size(100, 100));
2425 child_layer2_->SetBounds(gfx::Size(100, 100)); 2424 child_layer2_->SetBounds(gfx::Size(100, 100));
2426 root_layer_->AddChild(child_layer1_); 2425 root_layer_->AddChild(child_layer1_);
2427 root_layer_->AddChild(child_layer2_); 2426 root_layer_->AddChild(child_layer2_);
2428 layer_tree_host()->SetRootLayer(root_layer_); 2427 layer_tree_host()->SetRootLayer(root_layer_);
2429 PostSetNeedsCommitToMainThread(); 2428 PostSetNeedsCommitToMainThread();
2430 } 2429 }
2431 2430
2432 virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl, 2431 virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl,
2433 bool visible) OVERRIDE { 2432 bool visible) OVERRIDE {
2434 // One backing should remain unevicted. 2433 if (visible) {
2435 EXPECT_EQ(100u * 100u * 4u * 1u, 2434 // One backing should remain unevicted.
2436 layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); 2435 EXPECT_EQ(
2436 100u * 100u * 4u * 1u,
2437 layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
2438 } else {
2439 EXPECT_EQ(
2440 0u,
2441 layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
2442 }
2443
2437 // Make sure that contents textures are marked as having been 2444 // Make sure that contents textures are marked as having been
2438 // purged. 2445 // purged.
2439 EXPECT_TRUE(host_impl->active_tree()->ContentsTexturesPurged()); 2446 EXPECT_TRUE(host_impl->active_tree()->ContentsTexturesPurged());
2440 // End the test in this state. 2447 // End the test in this state.
2441 EndTest(); 2448 EndTest();
2442 } 2449 }
2443 2450
2444 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 2451 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
2445 ++num_commits_; 2452 ++num_commits_;
2446 switch (num_commits_) { 2453 switch (num_commits_) {
2447 case 1: 2454 case 1:
2448 // All three backings should have memory. 2455 // All three backings should have memory.
2449 EXPECT_EQ( 2456 EXPECT_EQ(
2450 100u * 100u * 4u * 3u, 2457 100u * 100u * 4u * 3u,
2451 layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); 2458 layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
2452 // Set a new policy that will kick out 1 of the 3 resources. 2459 // Set a new policy that will kick out 1 of the 3 resources.
2453 // Because a resource was evicted, a commit will be kicked off. 2460 // Because a resource was evicted, a commit will be kicked off.
2454 host_impl->SetMemoryPolicy( 2461 host_impl->SetMemoryPolicy(
2455 ManagedMemoryPolicy(100 * 100 * 4 * 2, 2462 ManagedMemoryPolicy(100 * 100 * 4 * 2,
2456 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, 2463 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING,
2457 100 * 100 * 4 * 1,
2458 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING,
2459 1000)); 2464 1000));
2460 host_impl->SetDiscardBackBufferWhenNotVisible(true);
2461 break; 2465 break;
2462 case 2: 2466 case 2:
2463 // Only two backings should have memory. 2467 // Only two backings should have memory.
2464 EXPECT_EQ( 2468 EXPECT_EQ(
2465 100u * 100u * 4u * 2u, 2469 100u * 100u * 4u * 2u,
2466 layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); 2470 layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
2467 // Become backgrounded, which will cause 1 more resource to be 2471 // Become backgrounded, which will cause 1 more resource to be
2468 // evicted. 2472 // evicted.
2469 PostSetVisibleToMainThread(false); 2473 PostSetVisibleToMainThread(false);
2470 break; 2474 break;
(...skipping 2500 matching lines...) Expand 10 before | Expand all | Expand 10 after
4971 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { 4975 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
4972 int frame = num_commits_; 4976 int frame = num_commits_;
4973 switch (frame) { 4977 switch (frame) {
4974 case 0: 4978 case 0:
4975 break; 4979 break;
4976 case 1: 4980 case 1:
4977 // This will trigger a commit because the priority cutoff has changed. 4981 // This will trigger a commit because the priority cutoff has changed.
4978 impl->SetMemoryPolicy(ManagedMemoryPolicy( 4982 impl->SetMemoryPolicy(ManagedMemoryPolicy(
4979 16u*1024u*1024u, 4983 16u*1024u*1024u,
4980 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, 4984 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
4981 0,
4982 gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING,
4983 1000)); 4985 1000));
4984 break; 4986 break;
4985 case 2: 4987 case 2:
4986 // This will not trigger a commit because the priority cutoff has not 4988 // This will not trigger a commit because the priority cutoff has not
4987 // changed, and there is already enough memory for all allocations. 4989 // changed, and there is already enough memory for all allocations.
4988 impl->SetMemoryPolicy(ManagedMemoryPolicy( 4990 impl->SetMemoryPolicy(ManagedMemoryPolicy(
4989 32u*1024u*1024u, 4991 32u*1024u*1024u,
4990 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, 4992 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
4991 0,
4992 gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING,
4993 1000)); 4993 1000));
4994 break; 4994 break;
4995 case 3: 4995 case 3:
4996 NOTREACHED(); 4996 NOTREACHED();
4997 break; 4997 break;
4998 } 4998 }
4999 } 4999 }
5000 5000
5001 virtual void AfterTest() OVERRIDE {} 5001 virtual void AfterTest() OVERRIDE {}
5002 5002
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
5135 FakeOutputSurface::Create3d( 5135 FakeOutputSurface::Create3d(
5136 second_context_provider_ ? 5136 second_context_provider_ ?
5137 second_context_provider_ : 5137 second_context_provider_ :
5138 first_context_provider_)); 5138 first_context_provider_));
5139 output_surface->SetMemoryPolicyToSetAtBind(make_scoped_ptr( 5139 output_surface->SetMemoryPolicyToSetAtBind(make_scoped_ptr(
5140 new ManagedMemoryPolicy( 5140 new ManagedMemoryPolicy(
5141 second_context_provider_ ? 5141 second_context_provider_ ?
5142 second_output_surface_memory_limit_ : 5142 second_output_surface_memory_limit_ :
5143 first_output_surface_memory_limit_, 5143 first_output_surface_memory_limit_,
5144 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, 5144 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
5145 0,
5146 gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING,
5147 ManagedMemoryPolicy::kDefaultNumResourcesLimit))); 5145 ManagedMemoryPolicy::kDefaultNumResourcesLimit)));
5148 return output_surface.PassAs<OutputSurface>(); 5146 return output_surface.PassAs<OutputSurface>();
5149 } 5147 }
5150 5148
5151 virtual void SetupTree() OVERRIDE { 5149 virtual void SetupTree() OVERRIDE {
5152 root_ = FakeContentLayer::Create(&client_); 5150 root_ = FakeContentLayer::Create(&client_);
5153 root_->SetBounds(gfx::Size(20, 20)); 5151 root_->SetBounds(gfx::Size(20, 20));
5154 layer_tree_host()->SetRootLayer(root_); 5152 layer_tree_host()->SetRootLayer(root_);
5155 LayerTreeHostTest::SetupTree(); 5153 LayerTreeHostTest::SetupTree();
5156 } 5154 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
5196 size_t second_output_surface_memory_limit_; 5194 size_t second_output_surface_memory_limit_;
5197 FakeContentLayerClient client_; 5195 FakeContentLayerClient client_;
5198 scoped_refptr<FakeContentLayer> root_; 5196 scoped_refptr<FakeContentLayer> root_;
5199 }; 5197 };
5200 5198
5201 // No output to copy for delegated renderers. 5199 // No output to copy for delegated renderers.
5202 SINGLE_AND_MULTI_THREAD_TEST_F( 5200 SINGLE_AND_MULTI_THREAD_TEST_F(
5203 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface); 5201 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface);
5204 5202
5205 } // namespace cc 5203 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_pixeltest_on_demand_raster.cc ('k') | cc/trees/layer_tree_host_unittest_damage.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698