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

Unified Diff: cc/resources/resource_pool.cc

Issue 2240993002: Change ResourcePool reuse to have looser size constraints. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp73_rp_refactor
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/resources/resource_pool.h ('k') | cc/resources/resource_pool_unittest.cc » ('j') | no next file with comments »
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 41358702b7cf56683ab88608a09bdd5c5beac64f..1f0891b1e63446a3f3f3b6af1614c9f6fbae25b0 100644
--- a/cc/resources/resource_pool.cc
+++ b/cc/resources/resource_pool.cc
@@ -94,32 +94,53 @@ ResourcePool::~ResourcePool() {
DCHECK_EQ(0u, total_resource_count_);
}
-Resource* ResourcePool::ReuseResource(const gfx::Size& size,
+Resource* ResourcePool::ReuseResource(const gfx::Size& min_size,
+ const gfx::Size& max_size,
ResourceFormat format,
const gfx::ColorSpace& color_space) {
// Finding resources in |unused_resources_| from MRU to LRU direction, touches
// LRU resources only if needed, which increases possibility of expiring more
// LRU resources within kResourceExpirationDelayMs.
+ ResourceDeque::iterator best_match = unused_resources_.end();
+ int64_t best_distance = std::numeric_limits<std::int64_t>::max();
for (ResourceDeque::iterator it = unused_resources_.begin();
it != unused_resources_.end(); ++it) {
ScopedResource* resource = it->get();
- DCHECK(resource_provider_->CanLockForWrite(resource->id()));
-
if (resource->format() != format)
continue;
- if (resource->size() != size)
- continue;
if (resource->color_space() != color_space)
continue;
+ if (resource->size() == min_size) {
+ best_match = it;
+ break;
+ }
- // Transfer resource to |in_use_resources_|.
- in_use_resources_[resource->id()] = std::move(*it);
- unused_resources_.erase(it);
- in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>(
- resource->size(), resource->format());
- return resource;
+ int32_t width = resource->size().width();
+ int32_t height = resource->size().height();
+ if (width < min_size.width() || width > max_size.width())
+ continue;
+ if (height < min_size.height() || height > max_size.height())
+ continue;
+
+ int64_t distance = width * height;
+ if (distance < best_distance) {
+ best_distance = distance;
+ best_match = it;
+ }
}
- return nullptr;
+
+ if (best_match == unused_resources_.end())
+ return nullptr;
+
+ ScopedResource* resource = best_match->get();
+ DCHECK(resource_provider_->CanLockForWrite(resource->id()));
+
+ // Transfer resource to |in_use_resources_|.
+ in_use_resources_[resource->id()] = std::move(*best_match);
+ unused_resources_.erase(best_match);
+ in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>(
+ resource->size(), resource->format());
+ return resource;
}
Resource* ResourcePool::CreateResource(const gfx::Size& size,
@@ -158,7 +179,7 @@ Resource* ResourcePool::CreateResource(const gfx::Size& size,
Resource* ResourcePool::AcquireResource(const gfx::Size& size,
ResourceFormat format,
const gfx::ColorSpace& color_space) {
- Resource* reused_resource = ReuseResource(size, format, color_space);
+ Resource* reused_resource = ReuseResource(size, size, format, color_space);
if (reused_resource)
return reused_resource;
« no previous file with comments | « cc/resources/resource_pool.h ('k') | cc/resources/resource_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698