Chromium Code Reviews| Index: cc/resources/resource_pool.cc |
| diff --git a/cc/resources/resource_pool.cc b/cc/resources/resource_pool.cc |
| index c2003758c4ba65ef0348e1988699c79f41dfb1b6..ddef9402ca2917bffb08e6ca1df46d572e100848 100644 |
| --- a/cc/resources/resource_pool.cc |
| +++ b/cc/resources/resource_pool.cc |
| @@ -24,8 +24,31 @@ using base::trace_event::MemoryAllocatorDump; |
| using base::trace_event::MemoryDumpLevelOfDetail; |
| namespace cc { |
| +namespace { |
| +bool ResourceMeetsSizeRequirements(const gfx::Size& requested_size, |
| + const gfx::Size& actual_size) { |
| + const float kReuseThreshold = 2.0f; |
| + |
| + // Allocating new resources is expensive, and we'd like to re-use our |
| + // existing ones within reason. Allow a larger resource to be used for a |
| + // smaller request. |
| + if (actual_size.width() < requested_size.width() || |
| + actual_size.height() < requested_size.height()) |
| + return false; |
| + // But don't use a resource that is more than |kReuseThreshold| times the |
| + // requested pixel area, as we want to free unnecessarily large resources. |
| + float actual_area = actual_size.GetArea(); |
|
danakj
2017/03/10 18:55:40
This will crash if it overflows (GetArea uses safe
ericrk
2017/03/10 20:04:07
I'm assuming that this can't be a problem - the si
|
| + float requested_area = requested_size.GetArea(); |
| + if (actual_area / requested_area > kReuseThreshold) |
| + return false; |
| + |
| + return true; |
| +} |
| + |
| +} // namespace |
| + |
| base::TimeDelta ResourcePool::kDefaultExpirationDelay = |
| - base::TimeDelta::FromSeconds(1); |
| + base::TimeDelta::FromSeconds(5); |
| void ResourcePool::PoolResource::OnMemoryDump( |
| base::trace_event::ProcessMemoryDump* pmd, |
| @@ -119,7 +142,7 @@ Resource* ResourcePool::ReuseResource(const gfx::Size& size, |
| if (resource->format() != format) |
| continue; |
| - if (resource->size() != size) |
| + if (!ResourceMeetsSizeRequirements(size, resource->size())) |
| continue; |
| if (resource->color_space() != color_space) |
| continue; |