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

Side by Side Diff: cc/resources/resource_pool_unittest.cc

Issue 1230203007: Re-land: cc: Use worker context for one-copy tile initialization. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 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
« no previous file with comments | « cc/resources/resource_pool.cc ('k') | cc/resources/resource_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/resources/resource_pool.h" 5 #include "cc/resources/resource_pool.h"
6 6
7 #include "cc/resources/resource_util.h" 7 #include "cc/resources/resource_util.h"
8 #include "cc/resources/scoped_resource.h" 8 #include "cc/resources/scoped_resource.h"
9 #include "cc/test/fake_output_surface.h" 9 #include "cc/test/fake_output_surface.h"
10 #include "cc/test/fake_output_surface_client.h" 10 #include "cc/test/fake_output_surface_client.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 EXPECT_EQ(resource_bytes, resource_pool_->acquired_memory_usage_bytes()); 62 EXPECT_EQ(resource_bytes, resource_pool_->acquired_memory_usage_bytes());
63 EXPECT_EQ(1u, resource_pool_->total_resource_count()); 63 EXPECT_EQ(1u, resource_pool_->total_resource_count());
64 EXPECT_EQ(1u, resource_pool_->acquired_resource_count()); 64 EXPECT_EQ(1u, resource_pool_->acquired_resource_count());
65 EXPECT_EQ(0u, resource_pool_->busy_resource_count()); 65 EXPECT_EQ(0u, resource_pool_->busy_resource_count());
66 66
67 resource_pool_->ReleaseResource(resource, 0u); 67 resource_pool_->ReleaseResource(resource, 0u);
68 EXPECT_EQ(resource_bytes, resource_pool_->total_memory_usage_bytes()); 68 EXPECT_EQ(resource_bytes, resource_pool_->total_memory_usage_bytes());
69 EXPECT_EQ(1u, resource_pool_->total_resource_count()); 69 EXPECT_EQ(1u, resource_pool_->total_resource_count());
70 EXPECT_EQ(1u, resource_pool_->busy_resource_count()); 70 EXPECT_EQ(1u, resource_pool_->busy_resource_count());
71 71
72 bool wait_if_needed = false; 72 resource_pool_->CheckBusyResources();
73 resource_pool_->CheckBusyResources(wait_if_needed);
74 EXPECT_EQ(resource_bytes, resource_pool_->total_memory_usage_bytes()); 73 EXPECT_EQ(resource_bytes, resource_pool_->total_memory_usage_bytes());
75 EXPECT_EQ(0u, resource_pool_->acquired_memory_usage_bytes()); 74 EXPECT_EQ(0u, resource_pool_->acquired_memory_usage_bytes());
76 EXPECT_EQ(1u, resource_pool_->total_resource_count()); 75 EXPECT_EQ(1u, resource_pool_->total_resource_count());
77 EXPECT_EQ(0u, resource_pool_->acquired_resource_count()); 76 EXPECT_EQ(0u, resource_pool_->acquired_resource_count());
78 EXPECT_EQ(0u, resource_pool_->busy_resource_count()); 77 EXPECT_EQ(0u, resource_pool_->busy_resource_count());
79 78
80 resource_pool_->SetResourceUsageLimits(0u, 0u, 0u); 79 resource_pool_->SetResourceUsageLimits(0u, 0u, 0u);
81 resource_pool_->ReduceResourceUsage(); 80 resource_pool_->ReduceResourceUsage();
82 EXPECT_EQ(0u, resource_pool_->total_memory_usage_bytes()); 81 EXPECT_EQ(0u, resource_pool_->total_memory_usage_bytes());
83 EXPECT_EQ(0u, resource_pool_->acquired_memory_usage_bytes()); 82 EXPECT_EQ(0u, resource_pool_->acquired_memory_usage_bytes());
84 EXPECT_EQ(0u, resource_pool_->total_resource_count()); 83 EXPECT_EQ(0u, resource_pool_->total_resource_count());
85 EXPECT_EQ(0u, resource_pool_->acquired_resource_count()); 84 EXPECT_EQ(0u, resource_pool_->acquired_resource_count());
86 EXPECT_EQ(0u, resource_pool_->busy_resource_count()); 85 EXPECT_EQ(0u, resource_pool_->busy_resource_count());
87 } 86 }
88 87
89 TEST_F(ResourcePoolTest, SimpleResourceReuse) { 88 TEST_F(ResourcePoolTest, SimpleResourceReuse) {
90 // Limits high enough to not be hit by this test. 89 // Limits high enough to not be hit by this test.
91 size_t bytes_limit = 10 * 1024 * 1024; 90 size_t bytes_limit = 10 * 1024 * 1024;
92 size_t count_limit = 100; 91 size_t count_limit = 100;
93 resource_pool_->SetResourceUsageLimits(bytes_limit, bytes_limit, count_limit); 92 resource_pool_->SetResourceUsageLimits(bytes_limit, bytes_limit, count_limit);
94 93
95 gfx::Size size(100, 100); 94 gfx::Size size(100, 100);
96 ResourceFormat format = RGBA_8888; 95 ResourceFormat format = RGBA_8888;
97 bool wait_if_needed = false;
98 96
99 Resource* resource = resource_pool_->AcquireResource(size, format); 97 Resource* resource = resource_pool_->AcquireResource(size, format);
100 resource_pool_->ReleaseResource(resource, 0u); 98 resource_pool_->ReleaseResource(resource, 0u);
101 resource_pool_->CheckBusyResources(wait_if_needed); 99 resource_pool_->CheckBusyResources();
102 EXPECT_EQ(1u, resource_provider_->num_resources()); 100 EXPECT_EQ(1u, resource_provider_->num_resources());
103 101
104 // Same size/format should re-use resource. 102 // Same size/format should re-use resource.
105 resource = resource_pool_->AcquireResource(size, format); 103 resource = resource_pool_->AcquireResource(size, format);
106 EXPECT_EQ(1u, resource_provider_->num_resources()); 104 EXPECT_EQ(1u, resource_provider_->num_resources());
107 resource_pool_->ReleaseResource(resource, 0u); 105 resource_pool_->ReleaseResource(resource, 0u);
108 resource_pool_->CheckBusyResources(wait_if_needed); 106 resource_pool_->CheckBusyResources();
109 EXPECT_EQ(1u, resource_provider_->num_resources()); 107 EXPECT_EQ(1u, resource_provider_->num_resources());
110 108
111 // Different size/format should alloate new resource. 109 // Different size/format should alloate new resource.
112 resource = resource_pool_->AcquireResource(gfx::Size(50, 50), LUMINANCE_8); 110 resource = resource_pool_->AcquireResource(gfx::Size(50, 50), LUMINANCE_8);
113 EXPECT_EQ(2u, resource_provider_->num_resources()); 111 EXPECT_EQ(2u, resource_provider_->num_resources());
114 resource_pool_->ReleaseResource(resource, 0u); 112 resource_pool_->ReleaseResource(resource, 0u);
115 resource_pool_->CheckBusyResources(wait_if_needed); 113 resource_pool_->CheckBusyResources();
116 EXPECT_EQ(2u, resource_provider_->num_resources()); 114 EXPECT_EQ(2u, resource_provider_->num_resources());
117 } 115 }
118 116
119 TEST_F(ResourcePoolTest, LostResource) { 117 TEST_F(ResourcePoolTest, LostResource) {
120 // Limits high enough to not be hit by this test. 118 // Limits high enough to not be hit by this test.
121 size_t bytes_limit = 10 * 1024 * 1024; 119 size_t bytes_limit = 10 * 1024 * 1024;
122 size_t count_limit = 100; 120 size_t count_limit = 100;
123 resource_pool_->SetResourceUsageLimits(bytes_limit, bytes_limit, count_limit); 121 resource_pool_->SetResourceUsageLimits(bytes_limit, bytes_limit, count_limit);
124 122
125 gfx::Size size(100, 100); 123 gfx::Size size(100, 100);
126 ResourceFormat format = RGBA_8888; 124 ResourceFormat format = RGBA_8888;
127 bool wait_if_needed = false;
128 125
129 Resource* resource = resource_pool_->AcquireResource(size, format); 126 Resource* resource = resource_pool_->AcquireResource(size, format);
130 EXPECT_EQ(1u, resource_provider_->num_resources()); 127 EXPECT_EQ(1u, resource_provider_->num_resources());
131 128
132 resource_provider_->LoseResourceForTesting(resource->id()); 129 resource_provider_->LoseResourceForTesting(resource->id());
133 resource_pool_->ReleaseResource(resource, 0u); 130 resource_pool_->ReleaseResource(resource, 0u);
134 resource_pool_->CheckBusyResources(wait_if_needed); 131 resource_pool_->CheckBusyResources();
135 EXPECT_EQ(0u, resource_provider_->num_resources()); 132 EXPECT_EQ(0u, resource_provider_->num_resources());
136 } 133 }
137 134
138 } // namespace 135 } // namespace
139 } // namespace cc 136 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_pool.cc ('k') | cc/resources/resource_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698