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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/resources/resource_pool.h" 5 #include "cc/resources/resource_pool.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 DidFinishUsingResource(PopBack(&busy_resources_)); 87 DidFinishUsingResource(PopBack(&busy_resources_));
88 } 88 }
89 89
90 SetResourceUsageLimits(0, 0); 90 SetResourceUsageLimits(0, 0);
91 DCHECK_EQ(0u, unused_resources_.size()); 91 DCHECK_EQ(0u, unused_resources_.size());
92 DCHECK_EQ(0u, in_use_memory_usage_bytes_); 92 DCHECK_EQ(0u, in_use_memory_usage_bytes_);
93 DCHECK_EQ(0u, total_memory_usage_bytes_); 93 DCHECK_EQ(0u, total_memory_usage_bytes_);
94 DCHECK_EQ(0u, total_resource_count_); 94 DCHECK_EQ(0u, total_resource_count_);
95 } 95 }
96 96
97 Resource* ResourcePool::ReuseResource(const gfx::Size& size, 97 Resource* ResourcePool::ReuseResource(const gfx::Size& min_size,
98 const gfx::Size& max_size,
98 ResourceFormat format, 99 ResourceFormat format,
99 const gfx::ColorSpace& color_space) { 100 const gfx::ColorSpace& color_space) {
100 // Finding resources in |unused_resources_| from MRU to LRU direction, touches 101 // Finding resources in |unused_resources_| from MRU to LRU direction, touches
101 // LRU resources only if needed, which increases possibility of expiring more 102 // LRU resources only if needed, which increases possibility of expiring more
102 // LRU resources within kResourceExpirationDelayMs. 103 // LRU resources within kResourceExpirationDelayMs.
104 ResourceDeque::iterator best_match = unused_resources_.end();
105 int64_t best_distance = std::numeric_limits<std::int64_t>::max();
103 for (ResourceDeque::iterator it = unused_resources_.begin(); 106 for (ResourceDeque::iterator it = unused_resources_.begin();
104 it != unused_resources_.end(); ++it) { 107 it != unused_resources_.end(); ++it) {
105 ScopedResource* resource = it->get(); 108 ScopedResource* resource = it->get();
106 DCHECK(resource_provider_->CanLockForWrite(resource->id()));
107
108 if (resource->format() != format) 109 if (resource->format() != format)
109 continue; 110 continue;
110 if (resource->size() != size)
111 continue;
112 if (resource->color_space() != color_space) 111 if (resource->color_space() != color_space)
113 continue; 112 continue;
113 if (resource->size() == min_size) {
114 best_match = it;
115 break;
116 }
114 117
115 // Transfer resource to |in_use_resources_|. 118 int32_t width = resource->size().width();
116 in_use_resources_[resource->id()] = std::move(*it); 119 int32_t height = resource->size().height();
117 unused_resources_.erase(it); 120 if (width < min_size.width() || width > max_size.width())
118 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( 121 continue;
119 resource->size(), resource->format()); 122 if (height < min_size.height() || height > max_size.height())
120 return resource; 123 continue;
124
125 int64_t distance = width * height;
126 if (distance < best_distance) {
127 best_distance = distance;
128 best_match = it;
129 }
121 } 130 }
122 return nullptr; 131
132 if (best_match == unused_resources_.end())
133 return nullptr;
134
135 ScopedResource* resource = best_match->get();
136 DCHECK(resource_provider_->CanLockForWrite(resource->id()));
137
138 // Transfer resource to |in_use_resources_|.
139 in_use_resources_[resource->id()] = std::move(*best_match);
140 unused_resources_.erase(best_match);
141 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>(
142 resource->size(), resource->format());
143 return resource;
123 } 144 }
124 145
125 Resource* ResourcePool::CreateResource(const gfx::Size& size, 146 Resource* ResourcePool::CreateResource(const gfx::Size& size,
126 ResourceFormat format, 147 ResourceFormat format,
127 const gfx::ColorSpace& color_space) { 148 const gfx::ColorSpace& color_space) {
128 std::unique_ptr<PoolResource> pool_resource = 149 std::unique_ptr<PoolResource> pool_resource =
129 PoolResource::Create(resource_provider_); 150 PoolResource::Create(resource_provider_);
130 151
131 if (use_gpu_memory_buffers_) { 152 if (use_gpu_memory_buffers_) {
132 pool_resource->AllocateWithGpuMemoryBuffer(size, format, usage_, 153 pool_resource->AllocateWithGpuMemoryBuffer(size, format, usage_,
(...skipping 18 matching lines...) Expand all
151 in_use_resources_[resource->id()] = std::move(pool_resource); 172 in_use_resources_[resource->id()] = std::move(pool_resource);
152 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( 173 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>(
153 resource->size(), resource->format()); 174 resource->size(), resource->format());
154 175
155 return resource; 176 return resource;
156 } 177 }
157 178
158 Resource* ResourcePool::AcquireResource(const gfx::Size& size, 179 Resource* ResourcePool::AcquireResource(const gfx::Size& size,
159 ResourceFormat format, 180 ResourceFormat format,
160 const gfx::ColorSpace& color_space) { 181 const gfx::ColorSpace& color_space) {
161 Resource* reused_resource = ReuseResource(size, format, color_space); 182 Resource* reused_resource = ReuseResource(size, size, format, color_space);
162 if (reused_resource) 183 if (reused_resource)
163 return reused_resource; 184 return reused_resource;
164 185
165 return CreateResource(size, format, color_space); 186 return CreateResource(size, format, color_space);
166 } 187 }
167 188
168 // Iterate over all three resource lists (unused, in-use, and busy), updating 189 // Iterate over all three resource lists (unused, in-use, and busy), updating
169 // the invalidation and content IDs to allow for future partial raster. The 190 // the invalidation and content IDs to allow for future partial raster. The
170 // first unused resource found (if any) will be returned and used for partial 191 // first unused resource found (if any) will be returned and used for partial
171 // raster directly. 192 // raster directly.
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 for (const auto& resource : busy_resources_) { 472 for (const auto& resource : busy_resources_) {
452 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); 473 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */);
453 } 474 }
454 for (const auto& entry : in_use_resources_) { 475 for (const auto& entry : in_use_resources_) {
455 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); 476 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */);
456 } 477 }
457 return true; 478 return true;
458 } 479 }
459 480
460 } // namespace cc 481 } // namespace cc
OLDNEW
« 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