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

Unified Diff: cc/resources/resource_pool.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | cc/resources/resource_pool_unittest.cc » ('j') | cc/resources/resource_pool_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « no previous file | cc/resources/resource_pool_unittest.cc » ('j') | cc/resources/resource_pool_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698