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

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

Issue 2726263003: cc::ResourcePool - Re-use larger resources for smaller requests (Closed)
Patch Set: Base re-use threshold on pixel area, not individual dimensions. Created 3 years, 9 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
« cc/resources/resource_pool.cc ('K') | « cc/resources/resource_pool.cc ('k') | no next file » | 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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 ResourceFormat format = RGBA_8888; 317 ResourceFormat format = RGBA_8888;
318 gfx::ColorSpace color_space = gfx::ColorSpace::CreateSRGB(); 318 gfx::ColorSpace color_space = gfx::ColorSpace::CreateSRGB();
319 319
320 // Create unused resources with sizes close to 100, 100. 320 // Create unused resources with sizes close to 100, 100.
321 resource_pool_->ReleaseResource( 321 resource_pool_->ReleaseResource(
322 resource_pool_->CreateResource(gfx::Size(99, 100), format, color_space)); 322 resource_pool_->CreateResource(gfx::Size(99, 100), format, color_space));
323 resource_pool_->ReleaseResource( 323 resource_pool_->ReleaseResource(
324 resource_pool_->CreateResource(gfx::Size(99, 99), format, color_space)); 324 resource_pool_->CreateResource(gfx::Size(99, 99), format, color_space));
325 resource_pool_->ReleaseResource( 325 resource_pool_->ReleaseResource(
326 resource_pool_->CreateResource(gfx::Size(100, 99), format, color_space)); 326 resource_pool_->CreateResource(gfx::Size(100, 99), format, color_space));
327 resource_pool_->ReleaseResource(
328 resource_pool_->CreateResource(gfx::Size(101, 101), format, color_space));
329 resource_pool_->CheckBusyResources(); 327 resource_pool_->CheckBusyResources();
330 328
331 gfx::Size size(100, 100); 329 // 100, 100 is too large, not in our pool.
332 Resource* resource = resource_pool_->ReuseResource(size, format, color_space); 330 EXPECT_EQ(nullptr, resource_pool_->ReuseResource(gfx::Size(100, 100), format,
333 EXPECT_EQ(nullptr, resource); 331 color_space));
334 size = gfx::Size(100, 99); 332
335 resource = resource_pool_->ReuseResource(size, format, color_space); 333 // 45, 99 is too small, shouldn't match.
334 EXPECT_EQ(nullptr, resource_pool_->ReuseResource(gfx::Size(45, 99), format,
danakj 2017/03/10 18:55:40 Can you test the boundary cases a bit more to esta
ericrk 2017/03/10 20:04:07 Done.
335 color_space));
336
337 // 100, 99 is an exact match
338 auto* resource =
339 resource_pool_->ReuseResource(gfx::Size(100, 99), format, color_space);
336 EXPECT_NE(nullptr, resource); 340 EXPECT_NE(nullptr, resource);
337 ASSERT_EQ(nullptr, resource_pool_->ReuseResource(size, format, color_space)); 341 EXPECT_EQ(nullptr, resource_pool_->ReuseResource(gfx::Size(100, 99), format,
342 color_space));
343 resource_pool_->ReleaseResource(resource);
344
345 // 98, 98 should match a larger resource size.
346 resource =
347 resource_pool_->ReuseResource(gfx::Size(98, 98), format, color_space);
348 EXPECT_NE(nullptr, resource);
338 resource_pool_->ReleaseResource(resource); 349 resource_pool_->ReleaseResource(resource);
339 } 350 }
340 351
341 TEST_F(ResourcePoolTest, MemoryStateSuspended) { 352 TEST_F(ResourcePoolTest, MemoryStateSuspended) {
342 // Limits high enough to not be hit by this test. 353 // Limits high enough to not be hit by this test.
343 size_t bytes_limit = 10 * 1024 * 1024; 354 size_t bytes_limit = 10 * 1024 * 1024;
344 size_t count_limit = 100; 355 size_t count_limit = 100;
345 resource_pool_->SetResourceUsageLimits(bytes_limit, count_limit); 356 resource_pool_->SetResourceUsageLimits(bytes_limit, count_limit);
346 357
347 gfx::Size size(100, 100); 358 gfx::Size size(100, 100);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 resource_pool_ = 400 resource_pool_ =
390 ResourcePool::Create(resource_provider_.get(), task_runner_.get(), 401 ResourcePool::Create(resource_provider_.get(), task_runner_.get(),
391 ResourceProvider::TEXTURE_HINT_DEFAULT, 402 ResourceProvider::TEXTURE_HINT_DEFAULT,
392 base::TimeDelta::FromMilliseconds(100)); 403 base::TimeDelta::FromMilliseconds(100));
393 resource = resource_pool_->AcquireResource(size, format, color_space); 404 resource = resource_pool_->AcquireResource(size, format, color_space);
394 EXPECT_FALSE(resource_provider_->IsImmutable(resource->id())); 405 EXPECT_FALSE(resource_provider_->IsImmutable(resource->id()));
395 resource_pool_->ReleaseResource(resource); 406 resource_pool_->ReleaseResource(resource);
396 } 407 }
397 408
398 } // namespace cc 409 } // namespace cc
OLDNEW
« cc/resources/resource_pool.cc ('K') | « cc/resources/resource_pool.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698