| 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;
|
|
|
|
|