Index: cc/resources/resource_pool.cc |
diff --git a/cc/resources/resource_pool.cc b/cc/resources/resource_pool.cc |
index c2003758c4ba65ef0348e1988699c79f41dfb1b6..03779f823b3a4f102aac5108b302ae18968e6479 100644 |
--- a/cc/resources/resource_pool.cc |
+++ b/cc/resources/resource_pool.cc |
@@ -24,8 +24,30 @@ 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 kReuseScaleThreshold = 2.0f; |
danakj
2017/03/10 16:32:12
driveby constant suggestion of something <= sqrt(2
ericrk
2017/03/10 18:44:20
I like limiting to 2x memory, but decided to go wi
|
+ |
+ // 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 |kReuseScaleThreshold| times |
+ // the requested size, as we want to free unnecessarily large resources. |
+ if (actual_size.width() > requested_size.width() * kReuseScaleThreshold || |
+ actual_size.height() > requested_size.height() * kReuseScaleThreshold) |
+ return false; |
+ |
+ return true; |
+} |
+ |
+} // namespace |
+ |
base::TimeDelta ResourcePool::kDefaultExpirationDelay = |
- base::TimeDelta::FromSeconds(1); |
+ base::TimeDelta::FromSeconds(5); |
ericrk
2017/03/10 01:51:14
Any number here is just a heuristic. 1 seemed to b
|
void ResourcePool::PoolResource::OnMemoryDump( |
base::trace_event::ProcessMemoryDump* pmd, |
@@ -119,7 +141,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; |