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

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

Issue 2162193002: Add logic to GLRenderer to support RenderPassDrawQuad copying. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup. Created 4 years, 5 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
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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 if (!found_resource->invalidated_rect().IsEmpty()) 204 if (!found_resource->invalidated_rect().IsEmpty())
205 updated_invalidated_rect.Union(found_resource->invalidated_rect()); 205 updated_invalidated_rect.Union(found_resource->invalidated_rect());
206 206
207 found_resource->set_content_id(new_content_id); 207 found_resource->set_content_id(new_content_id);
208 found_resource->set_invalidated_rect(updated_invalidated_rect); 208 found_resource->set_invalidated_rect(updated_invalidated_rect);
209 } 209 }
210 210
211 return nullptr; 211 return nullptr;
212 } 212 }
213 213
214 void ResourcePool::ReleaseResourceIfFound(ResourceId resource_id) {
215 auto it = in_use_resources_.find(resource_id);
216 if (it == in_use_resources_.end())
217 return;
218 ReleaseResource(resource_id);
219 }
220
214 void ResourcePool::ReleaseResource(Resource* resource) { 221 void ResourcePool::ReleaseResource(Resource* resource) {
215 // Ensure that the provided resource is valid. 222 // Ensure that the provided resource is valid.
216 // TODO(ericrk): Remove this once we've investigated further. 223 // TODO(ericrk): Remove this once we've investigated further.
217 // crbug.com/598286. 224 // crbug.com/598286.
218 CHECK(resource); 225 CHECK(resource);
219 CHECK(resource->id()); 226 ReleaseResource(resource->id());
227 }
220 228
221 auto it = in_use_resources_.find(resource->id()); 229 void ResourcePool::ReleaseResource(ResourceId resource_id) {
230 // Ensure that the provided resource is valid.
231 // TODO(ericrk): Remove this once we've investigated further.
232 // crbug.com/598286.
233 CHECK(resource_id);
234
235 auto it = in_use_resources_.find(resource_id);
222 if (it == in_use_resources_.end()) { 236 if (it == in_use_resources_.end()) {
223 // We should never hit this. Do some digging to try to determine the cause. 237 // We should never hit this. Do some digging to try to determine the cause.
224 // TODO(ericrk): Remove this once we've investigated further. 238 // TODO(ericrk): Remove this once we've investigated further.
225 // crbug.com/598286. 239 // crbug.com/598286.
226 240
227 // Maybe this is a double free - see if the resource exists in our busy 241 // Maybe this is a double free - see if the resource exists in our busy
228 // list. 242 // list.
229 auto found_busy = std::find_if( 243 auto found_busy = std::find_if(
230 busy_resources_.begin(), busy_resources_.end(), 244 busy_resources_.begin(), busy_resources_.end(),
231 [resource](const std::unique_ptr<PoolResource>& busy_resource) { 245 [resource_id](const std::unique_ptr<PoolResource>& busy_resource) {
232 return busy_resource->id() == resource->id(); 246 return busy_resource->id() == resource_id;
233 }); 247 });
234 CHECK(found_busy == busy_resources_.end()); 248 CHECK(found_busy == busy_resources_.end());
235 249
236 // Also check if the resource exists in our unused resources list. 250 // Also check if the resource exists in our unused resources list.
237 auto found_unused = std::find_if( 251 auto found_unused = std::find_if(
238 unused_resources_.begin(), unused_resources_.end(), 252 unused_resources_.begin(), unused_resources_.end(),
239 [resource](const std::unique_ptr<PoolResource>& pool_resource) { 253 [resource_id](const std::unique_ptr<PoolResource>& pool_resource) {
240 return pool_resource->id() == resource->id(); 254 return pool_resource->id() == resource_id;
241 }); 255 });
242 CHECK(found_unused == unused_resources_.end()); 256 CHECK(found_unused == unused_resources_.end());
243 257
244 // Resource doesn't exist in any of our lists. CHECK. 258 // Resource doesn't exist in any of our lists. CHECK.
245 CHECK(false); 259 CHECK(false);
246 } 260 }
247 261
248 // Also ensure that the resource wasn't null in our list. 262 // Also ensure that the resource wasn't null in our list.
249 // TODO(ericrk): Remove this once we've investigated further. 263 // TODO(ericrk): Remove this once we've investigated further.
250 // crbug.com/598286. 264 // crbug.com/598286.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 unused_resources_.push_front(std::move(resource)); 348 unused_resources_.push_front(std::move(resource));
335 } 349 }
336 350
337 void ResourcePool::ScheduleEvictExpiredResourcesIn( 351 void ResourcePool::ScheduleEvictExpiredResourcesIn(
338 base::TimeDelta time_from_now) { 352 base::TimeDelta time_from_now) {
339 if (evict_expired_resources_pending_) 353 if (evict_expired_resources_pending_)
340 return; 354 return;
341 355
342 evict_expired_resources_pending_ = true; 356 evict_expired_resources_pending_ = true;
343 357
344 task_runner_->PostDelayedTask(FROM_HERE, 358 task_runner_->PostDelayedTask(FROM_HERE,
ccameron 2016/07/20 22:13:53 |task_runner_| isn't optional, but I would suggest
erikchen 2016/07/20 23:40:39 Whoops, you're right. The method base::ThreadTaskR
345 base::Bind(&ResourcePool::EvictExpiredResources, 359 base::Bind(&ResourcePool::EvictExpiredResources,
346 weak_ptr_factory_.GetWeakPtr()), 360 weak_ptr_factory_.GetWeakPtr()),
347 time_from_now); 361 time_from_now);
348 } 362 }
349 363
350 void ResourcePool::EvictExpiredResources() { 364 void ResourcePool::EvictExpiredResources() {
351 evict_expired_resources_pending_ = false; 365 evict_expired_resources_pending_ = false;
352 base::TimeTicks current_time = base::TimeTicks::Now(); 366 base::TimeTicks current_time = base::TimeTicks::Now();
353 367
354 EvictResourcesNotUsedSince(current_time - resource_expiration_delay_); 368 EvictResourcesNotUsedSince(current_time - resource_expiration_delay_);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 for (const auto& resource : busy_resources_) { 420 for (const auto& resource : busy_resources_) {
407 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); 421 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */);
408 } 422 }
409 for (const auto& entry : in_use_resources_) { 423 for (const auto& entry : in_use_resources_) {
410 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); 424 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */);
411 } 425 }
412 return true; 426 return true;
413 } 427 }
414 428
415 } // namespace cc 429 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698