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

Side by Side Diff: cc/resources/resource_pool.cc

Issue 1866203004: Convert //cc from scoped_ptr to std::unique_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptrcc: rebase Created 4 years, 8 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 continue; 114 continue;
115 115
116 // Transfer resource to |in_use_resources_|. 116 // Transfer resource to |in_use_resources_|.
117 in_use_resources_[resource->id()] = std::move(*it); 117 in_use_resources_[resource->id()] = std::move(*it);
118 unused_resources_.erase(it); 118 unused_resources_.erase(it);
119 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( 119 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>(
120 resource->size(), resource->format()); 120 resource->size(), resource->format());
121 return resource; 121 return resource;
122 } 122 }
123 123
124 scoped_ptr<PoolResource> pool_resource = 124 std::unique_ptr<PoolResource> pool_resource =
125 PoolResource::Create(resource_provider_); 125 PoolResource::Create(resource_provider_);
126 126
127 if (use_gpu_memory_buffers_) { 127 if (use_gpu_memory_buffers_) {
128 pool_resource->AllocateWithGpuMemoryBuffer(size, format); 128 pool_resource->AllocateWithGpuMemoryBuffer(size, format);
129 } else { 129 } else {
130 pool_resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, 130 pool_resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE,
131 format); 131 format);
132 } 132 }
133 133
134 DCHECK(ResourceUtil::VerifySizeInBytes<size_t>(pool_resource->size(), 134 DCHECK(ResourceUtil::VerifySizeInBytes<size_t>(pool_resource->size(),
135 pool_resource->format())); 135 pool_resource->format()));
136 total_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( 136 total_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>(
137 pool_resource->size(), pool_resource->format()); 137 pool_resource->size(), pool_resource->format());
138 ++total_resource_count_; 138 ++total_resource_count_;
139 139
140 Resource* resource = pool_resource.get(); 140 Resource* resource = pool_resource.get();
141 in_use_resources_[resource->id()] = std::move(pool_resource); 141 in_use_resources_[resource->id()] = std::move(pool_resource);
142 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( 142 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>(
143 resource->size(), resource->format()); 143 resource->size(), resource->format());
144 return resource; 144 return resource;
145 } 145 }
146 146
147 Resource* ResourcePool::TryAcquireResourceWithContentId(uint64_t content_id) { 147 Resource* ResourcePool::TryAcquireResourceWithContentId(uint64_t content_id) {
148 DCHECK(content_id); 148 DCHECK(content_id);
149 149
150 auto it = 150 auto it = std::find_if(
151 std::find_if(unused_resources_.begin(), unused_resources_.end(), 151 unused_resources_.begin(), unused_resources_.end(),
152 [content_id](const scoped_ptr<PoolResource>& pool_resource) { 152 [content_id](const std::unique_ptr<PoolResource>& pool_resource) {
153 return pool_resource->content_id() == content_id; 153 return pool_resource->content_id() == content_id;
154 }); 154 });
155 if (it == unused_resources_.end()) 155 if (it == unused_resources_.end())
156 return nullptr; 156 return nullptr;
157 157
158 Resource* resource = it->get(); 158 Resource* resource = it->get();
159 // TODO(ccameron): The allowance for IsInUseByMacOSWindowServer should not 159 // TODO(ccameron): The allowance for IsInUseByMacOSWindowServer should not
160 // be needed. 160 // be needed.
161 // http://crbug.com/577121 161 // http://crbug.com/577121
162 DCHECK(resource_provider_->CanLockForWrite(resource->id()) || 162 DCHECK(resource_provider_->CanLockForWrite(resource->id()) ||
163 resource_provider_->IsInUseByMacOSWindowServer(resource->id())); 163 resource_provider_->IsInUseByMacOSWindowServer(resource->id()));
164 164
(...skipping 13 matching lines...) Expand all
178 CHECK(resource->id()); 178 CHECK(resource->id());
179 179
180 auto it = in_use_resources_.find(resource->id()); 180 auto it = in_use_resources_.find(resource->id());
181 if (it == in_use_resources_.end()) { 181 if (it == in_use_resources_.end()) {
182 // We should never hit this. Do some digging to try to determine the cause. 182 // We should never hit this. Do some digging to try to determine the cause.
183 // TODO(ericrk): Remove this once we've investigated further. 183 // TODO(ericrk): Remove this once we've investigated further.
184 // crbug.com/598286. 184 // crbug.com/598286.
185 185
186 // Maybe this is a double free - see if the resource exists in our busy 186 // Maybe this is a double free - see if the resource exists in our busy
187 // list. 187 // list.
188 auto found_busy = 188 auto found_busy = std::find_if(
189 std::find_if(busy_resources_.begin(), busy_resources_.end(), 189 busy_resources_.begin(), busy_resources_.end(),
190 [resource](const scoped_ptr<PoolResource>& busy_resource) { 190 [resource](const std::unique_ptr<PoolResource>& busy_resource) {
191 return busy_resource->id() == resource->id(); 191 return busy_resource->id() == resource->id();
192 }); 192 });
193 CHECK(found_busy == busy_resources_.end()); 193 CHECK(found_busy == busy_resources_.end());
194 194
195 // Also check if the resource exists in our unused resources list. 195 // Also check if the resource exists in our unused resources list.
196 auto found_unused = 196 auto found_unused = std::find_if(
197 std::find_if(unused_resources_.begin(), unused_resources_.end(), 197 unused_resources_.begin(), unused_resources_.end(),
198 [resource](const scoped_ptr<PoolResource>& pool_resource) { 198 [resource](const std::unique_ptr<PoolResource>& pool_resource) {
199 return pool_resource->id() == resource->id(); 199 return pool_resource->id() == resource->id();
200 }); 200 });
201 CHECK(found_unused == unused_resources_.end()); 201 CHECK(found_unused == unused_resources_.end());
202 202
203 // Resource doesn't exist in any of our lists. CHECK. 203 // Resource doesn't exist in any of our lists. CHECK.
204 CHECK(false); 204 CHECK(false);
205 } 205 }
206 206
207 // Also ensure that the resource wasn't null in our list. 207 // Also ensure that the resource wasn't null in our list.
208 // TODO(ericrk): Remove this once we've investigated further. 208 // TODO(ericrk): Remove this once we've investigated further.
209 // crbug.com/598286. 209 // crbug.com/598286.
210 CHECK(it->second.get()); 210 CHECK(it->second.get());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 } 249 }
250 250
251 bool ResourcePool::ResourceUsageTooHigh() { 251 bool ResourcePool::ResourceUsageTooHigh() {
252 if (total_resource_count_ > max_resource_count_) 252 if (total_resource_count_ > max_resource_count_)
253 return true; 253 return true;
254 if (total_memory_usage_bytes_ > max_memory_usage_bytes_) 254 if (total_memory_usage_bytes_ > max_memory_usage_bytes_)
255 return true; 255 return true;
256 return false; 256 return false;
257 } 257 }
258 258
259 void ResourcePool::DeleteResource(scoped_ptr<PoolResource> resource) { 259 void ResourcePool::DeleteResource(std::unique_ptr<PoolResource> resource) {
260 size_t resource_bytes = ResourceUtil::UncheckedSizeInBytes<size_t>( 260 size_t resource_bytes = ResourceUtil::UncheckedSizeInBytes<size_t>(
261 resource->size(), resource->format()); 261 resource->size(), resource->format());
262 total_memory_usage_bytes_ -= resource_bytes; 262 total_memory_usage_bytes_ -= resource_bytes;
263 --total_resource_count_; 263 --total_resource_count_;
264 } 264 }
265 265
266 void ResourcePool::CheckBusyResources() { 266 void ResourcePool::CheckBusyResources() {
267 for (size_t i = 0; i < busy_resources_.size();) { 267 for (size_t i = 0; i < busy_resources_.size();) {
268 ResourceDeque::iterator it(busy_resources_.begin() + i); 268 ResourceDeque::iterator it(busy_resources_.begin() + i);
269 PoolResource* resource = it->get(); 269 PoolResource* resource = it->get();
270 270
271 if (resource_provider_->CanLockForWrite(resource->id())) { 271 if (resource_provider_->CanLockForWrite(resource->id())) {
272 DidFinishUsingResource(std::move(*it)); 272 DidFinishUsingResource(std::move(*it));
273 busy_resources_.erase(it); 273 busy_resources_.erase(it);
274 } else if (resource_provider_->IsLost(resource->id())) { 274 } else if (resource_provider_->IsLost(resource->id())) {
275 // Remove lost resources from pool. 275 // Remove lost resources from pool.
276 DeleteResource(std::move(*it)); 276 DeleteResource(std::move(*it));
277 busy_resources_.erase(it); 277 busy_resources_.erase(it);
278 } else { 278 } else {
279 ++i; 279 ++i;
280 } 280 }
281 } 281 }
282 } 282 }
283 283
284 void ResourcePool::DidFinishUsingResource(scoped_ptr<PoolResource> resource) { 284 void ResourcePool::DidFinishUsingResource(
285 std::unique_ptr<PoolResource> resource) {
285 unused_resources_.push_front(std::move(resource)); 286 unused_resources_.push_front(std::move(resource));
286 } 287 }
287 288
288 void ResourcePool::ScheduleEvictExpiredResourcesIn( 289 void ResourcePool::ScheduleEvictExpiredResourcesIn(
289 base::TimeDelta time_from_now) { 290 base::TimeDelta time_from_now) {
290 if (evict_expired_resources_pending_) 291 if (evict_expired_resources_pending_)
291 return; 292 return;
292 293
293 evict_expired_resources_pending_ = true; 294 evict_expired_resources_pending_ = true;
294 295
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 for (const auto& resource : busy_resources_) { 358 for (const auto& resource : busy_resources_) {
358 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); 359 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */);
359 } 360 }
360 for (const auto& entry : in_use_resources_) { 361 for (const auto& entry : in_use_resources_) {
361 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); 362 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */);
362 } 363 }
363 return true; 364 return true;
364 } 365 }
365 366
366 } // namespace cc 367 } // 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