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

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

Issue 2254033002: Encourage IOSurface reuse for CSS filter effects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from ericrk. Created 4 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/test/fake_picture_layer_tiling_client.cc » ('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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 10 matching lines...) Expand all
21 class ResourcePoolTest : public testing::Test { 21 class ResourcePoolTest : public testing::Test {
22 public: 22 public:
23 void SetUp() override { 23 void SetUp() override {
24 output_surface_ = FakeOutputSurface::CreateDelegating3d(); 24 output_surface_ = FakeOutputSurface::CreateDelegating3d();
25 ASSERT_TRUE(output_surface_->BindToClient(&output_surface_client_)); 25 ASSERT_TRUE(output_surface_->BindToClient(&output_surface_client_));
26 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); 26 shared_bitmap_manager_.reset(new TestSharedBitmapManager());
27 resource_provider_ = FakeResourceProvider::Create( 27 resource_provider_ = FakeResourceProvider::Create(
28 output_surface_.get(), shared_bitmap_manager_.get()); 28 output_surface_.get(), shared_bitmap_manager_.get());
29 task_runner_ = base::ThreadTaskRunnerHandle::Get(); 29 task_runner_ = base::ThreadTaskRunnerHandle::Get();
30 resource_pool_ = 30 resource_pool_ =
31 ResourcePool::Create(resource_provider_.get(), task_runner_.get()); 31 ResourcePool::Create(resource_provider_.get(), task_runner_.get(),
32 ResourcePool::kDefaultExpirationDelay);
32 } 33 }
33 34
34 protected: 35 protected:
35 FakeOutputSurfaceClient output_surface_client_; 36 FakeOutputSurfaceClient output_surface_client_;
36 std::unique_ptr<FakeOutputSurface> output_surface_; 37 std::unique_ptr<FakeOutputSurface> output_surface_;
37 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager_; 38 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager_;
38 std::unique_ptr<ResourceProvider> resource_provider_; 39 std::unique_ptr<ResourceProvider> resource_provider_;
39 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 40 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
40 std::unique_ptr<ResourcePool> resource_pool_; 41 std::unique_ptr<ResourcePool> resource_pool_;
41 }; 42 };
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 resource_pool_->AcquireResource(size, format, color_space); 149 resource_pool_->AcquireResource(size, format, color_space);
149 EXPECT_EQ(1u, resource_provider_->num_resources()); 150 EXPECT_EQ(1u, resource_provider_->num_resources());
150 151
151 resource_provider_->LoseResourceForTesting(resource->id()); 152 resource_provider_->LoseResourceForTesting(resource->id());
152 resource_pool_->ReleaseResource(resource); 153 resource_pool_->ReleaseResource(resource);
153 resource_pool_->CheckBusyResources(); 154 resource_pool_->CheckBusyResources();
154 EXPECT_EQ(0u, resource_provider_->num_resources()); 155 EXPECT_EQ(0u, resource_provider_->num_resources());
155 } 156 }
156 157
157 TEST_F(ResourcePoolTest, BusyResourcesEventuallyFreed) { 158 TEST_F(ResourcePoolTest, BusyResourcesEventuallyFreed) {
159 // Set a quick resource expiration delay so that this test doesn't take long
160 // to run.
161 resource_pool_ =
162 ResourcePool::Create(resource_provider_.get(), task_runner_.get(),
163 base::TimeDelta::FromMilliseconds(10));
164
158 // Limits high enough to not be hit by this test. 165 // Limits high enough to not be hit by this test.
159 size_t bytes_limit = 10 * 1024 * 1024; 166 size_t bytes_limit = 10 * 1024 * 1024;
160 size_t count_limit = 100; 167 size_t count_limit = 100;
161 resource_pool_->SetResourceUsageLimits(bytes_limit, count_limit); 168 resource_pool_->SetResourceUsageLimits(bytes_limit, count_limit);
162 169
163 // Set a quick resource expiration delay so that this test doesn't take long
164 // to run.
165 resource_pool_->SetResourceExpirationDelayForTesting(
166 base::TimeDelta::FromMilliseconds(10));
167
168 gfx::Size size(100, 100); 170 gfx::Size size(100, 100);
169 ResourceFormat format = RGBA_8888; 171 ResourceFormat format = RGBA_8888;
170 gfx::ColorSpace color_space; 172 gfx::ColorSpace color_space;
171 173
172 Resource* resource = 174 Resource* resource =
173 resource_pool_->AcquireResource(size, format, color_space); 175 resource_pool_->AcquireResource(size, format, color_space);
174 EXPECT_EQ(1u, resource_provider_->num_resources()); 176 EXPECT_EQ(1u, resource_provider_->num_resources());
175 EXPECT_EQ(40000u, resource_pool_->GetTotalMemoryUsageForTesting()); 177 EXPECT_EQ(40000u, resource_pool_->GetTotalMemoryUsageForTesting());
176 EXPECT_EQ(1u, resource_pool_->resource_count()); 178 EXPECT_EQ(1u, resource_pool_->resource_count());
177 179
178 resource_pool_->ReleaseResource(resource); 180 resource_pool_->ReleaseResource(resource);
179 EXPECT_EQ(1u, resource_provider_->num_resources()); 181 EXPECT_EQ(1u, resource_provider_->num_resources());
180 EXPECT_EQ(40000u, resource_pool_->GetTotalMemoryUsageForTesting()); 182 EXPECT_EQ(40000u, resource_pool_->GetTotalMemoryUsageForTesting());
181 EXPECT_EQ(0u, resource_pool_->memory_usage_bytes()); 183 EXPECT_EQ(0u, resource_pool_->memory_usage_bytes());
182 EXPECT_EQ(1u, resource_pool_->GetBusyResourceCountForTesting()); 184 EXPECT_EQ(1u, resource_pool_->GetBusyResourceCountForTesting());
183 185
184 // Wait for our resource pool to evict resources. We expect resources to be 186 // Wait for our resource pool to evict resources. We expect resources to be
185 // released within 10 ms, give the thread up to 200. 187 // released within 10 ms, give the thread up to 200.
186 base::RunLoop run_loop; 188 base::RunLoop run_loop;
187 task_runner_->PostDelayedTask(FROM_HERE, run_loop.QuitClosure(), 189 task_runner_->PostDelayedTask(FROM_HERE, run_loop.QuitClosure(),
188 base::TimeDelta::FromMillisecondsD(200)); 190 base::TimeDelta::FromMillisecondsD(200));
189 run_loop.Run(); 191 run_loop.Run();
190 192
191 EXPECT_EQ(0u, resource_provider_->num_resources()); 193 EXPECT_EQ(0u, resource_provider_->num_resources());
192 EXPECT_EQ(0u, resource_pool_->GetTotalMemoryUsageForTesting()); 194 EXPECT_EQ(0u, resource_pool_->GetTotalMemoryUsageForTesting());
193 EXPECT_EQ(0u, resource_pool_->memory_usage_bytes()); 195 EXPECT_EQ(0u, resource_pool_->memory_usage_bytes());
194 } 196 }
195 197
196 TEST_F(ResourcePoolTest, UnusedResourcesEventuallyFreed) { 198 TEST_F(ResourcePoolTest, UnusedResourcesEventuallyFreed) {
199 // Set a quick resource expiration delay so that this test doesn't take long
200 // to run.
201 resource_pool_ =
202 ResourcePool::Create(resource_provider_.get(), task_runner_.get(),
203 base::TimeDelta::FromMilliseconds(100));
204
197 // Limits high enough to not be hit by this test. 205 // Limits high enough to not be hit by this test.
198 size_t bytes_limit = 10 * 1024 * 1024; 206 size_t bytes_limit = 10 * 1024 * 1024;
199 size_t count_limit = 100; 207 size_t count_limit = 100;
200 resource_pool_->SetResourceUsageLimits(bytes_limit, count_limit); 208 resource_pool_->SetResourceUsageLimits(bytes_limit, count_limit);
201 209
202 // Set a quick resource expiration delay so that this test doesn't take long
203 // to run.
204 resource_pool_->SetResourceExpirationDelayForTesting(
205 base::TimeDelta::FromMilliseconds(100));
206
207 gfx::Size size(100, 100); 210 gfx::Size size(100, 100);
208 ResourceFormat format = RGBA_8888; 211 ResourceFormat format = RGBA_8888;
209 gfx::ColorSpace color_space; 212 gfx::ColorSpace color_space;
210 213
211 Resource* resource = 214 Resource* resource =
212 resource_pool_->AcquireResource(size, format, color_space); 215 resource_pool_->AcquireResource(size, format, color_space);
213 EXPECT_EQ(1u, resource_provider_->num_resources()); 216 EXPECT_EQ(1u, resource_provider_->num_resources());
214 EXPECT_EQ(40000u, resource_pool_->GetTotalMemoryUsageForTesting()); 217 EXPECT_EQ(40000u, resource_pool_->GetTotalMemoryUsageForTesting());
215 EXPECT_EQ(1u, resource_pool_->GetTotalResourceCountForTesting()); 218 EXPECT_EQ(1u, resource_pool_->GetTotalResourceCountForTesting());
216 EXPECT_EQ(1u, resource_pool_->resource_count()); 219 EXPECT_EQ(1u, resource_pool_->resource_count());
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 Resource* resource = resource_pool_->ReuseResource(size, format, color_space); 331 Resource* resource = resource_pool_->ReuseResource(size, format, color_space);
329 EXPECT_EQ(nullptr, resource); 332 EXPECT_EQ(nullptr, resource);
330 size = gfx::Size(100, 99); 333 size = gfx::Size(100, 99);
331 resource = resource_pool_->ReuseResource(size, format, color_space); 334 resource = resource_pool_->ReuseResource(size, format, color_space);
332 EXPECT_NE(nullptr, resource); 335 EXPECT_NE(nullptr, resource);
333 ASSERT_EQ(nullptr, resource_pool_->ReuseResource(size, format, color_space)); 336 ASSERT_EQ(nullptr, resource_pool_->ReuseResource(size, format, color_space));
334 resource_pool_->ReleaseResource(resource); 337 resource_pool_->ReleaseResource(resource);
335 } 338 }
336 339
337 } // namespace cc 340 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_pool.cc ('k') | cc/test/fake_picture_layer_tiling_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698