Chromium Code Reviews| Index: cc/resources/resource_pool.cc |
| diff --git a/cc/resources/resource_pool.cc b/cc/resources/resource_pool.cc |
| index 22847809ba3c196f66df1112d978d56342665b3a..6add111927cb178cc1eff7f69c436d17086c00fa 100644 |
| --- a/cc/resources/resource_pool.cc |
| +++ b/cc/resources/resource_pool.cc |
| @@ -21,7 +21,8 @@ ResourcePool::ResourcePool(ResourceProvider* resource_provider, GLenum target) |
| ResourcePool::~ResourcePool() { |
| while (!busy_resources_.empty()) { |
| - DidFinishUsingResource(busy_resources_.front()); |
| + auto const& front = busy_resources_.front(); |
| + DidFinishUsingResource(front.resource, front.id); |
| busy_resources_.pop_front(); |
| } |
| @@ -37,7 +38,7 @@ scoped_ptr<ScopedResource> ResourcePool::AcquireResource( |
| for (ResourceList::iterator it = unused_resources_.begin(); |
| it != unused_resources_.end(); |
| ++it) { |
| - ScopedResource* resource = *it; |
| + ScopedResource* resource = it->resource; |
| DCHECK(resource_provider_->CanLockForWrite(resource->id())); |
| if (resource->format() != format) |
| @@ -59,8 +60,56 @@ scoped_ptr<ScopedResource> ResourcePool::AcquireResource( |
| return resource.Pass(); |
| } |
| -void ResourcePool::ReleaseResource(scoped_ptr<ScopedResource> resource) { |
| - busy_resources_.push_back(resource.release()); |
| +scoped_ptr<ScopedResource> ResourcePool::TryAcquireOldResource( |
| + const gfx::Size& size, |
| + ResourceFormat format, |
| + uint64_t id) { |
| + if (!id) |
| + return nullptr; |
| + |
| + for (auto it = unused_resources_.begin(); it != unused_resources_.end(); |
| + ++it) { |
| + const PoolResource& pr = *it; |
| + if (pr.id != id) |
|
vmpstr
2015/05/14 23:11:46
If this id is going to be unique, (and I think it
danakj
2015/05/14 23:22:42
Ya good plan! Done.
|
| + continue; |
| + ScopedResource* resource = pr.resource; |
| + DCHECK(resource_provider_->CanLockForWrite(resource->id())); |
| + if (resource->format() != format || resource->size() != size) |
| + break; |
| + |
| + unused_resources_.erase(it); |
| + unused_memory_usage_bytes_ -= resource->bytes(); |
| + return make_scoped_ptr(resource); |
| + } |
| + |
| + return nullptr; |
| +} |
| + |
| +scoped_ptr<ScopedResource> ResourcePool::TryAcquireOldBusyResource( |
| + const gfx::Size& size, |
| + ResourceFormat format, |
| + uint64_t id) { |
| + if (!id) |
| + return nullptr; |
| + |
| + for (auto it = busy_resources_.begin(); it != busy_resources_.end(); ++it) { |
| + const PoolResource& pr = *it; |
| + if (pr.id != id) |
|
vmpstr
2015/05/14 23:11:46
Same here.
danakj
2015/05/14 23:22:42
Done.
|
| + continue; |
| + ScopedResource* resource = pr.resource; |
| + if (resource->format() != format || resource->size() != size) |
| + break; |
| + |
| + busy_resources_.erase(it); |
| + return make_scoped_ptr(resource); |
| + } |
| + |
| + return nullptr; |
| +} |
| + |
| +void ResourcePool::ReleaseResource(scoped_ptr<ScopedResource> resource, |
| + uint64_t id) { |
| + busy_resources_.push_back(PoolResource(resource.release(), id)); |
| } |
| void ResourcePool::SetResourceUsageLimits(size_t max_memory_usage_bytes, |
| @@ -85,7 +134,7 @@ void ResourcePool::ReduceResourceUsage() { |
| // can't be locked for write might also not be truly free-able. |
| // We can free the resource here but it doesn't mean that the |
| // memory is necessarily returned to the OS. |
| - ScopedResource* resource = unused_resources_.front(); |
| + ScopedResource* resource = unused_resources_.front().resource; |
| unused_resources_.pop_front(); |
| memory_usage_bytes_ -= resource->bytes(); |
| unused_memory_usage_bytes_ -= resource->bytes(); |
| @@ -108,13 +157,13 @@ void ResourcePool::CheckBusyResources(bool wait_if_needed) { |
| ResourceList::iterator it = busy_resources_.begin(); |
| while (it != busy_resources_.end()) { |
| - ScopedResource* resource = *it; |
| + ScopedResource* resource = it->resource; |
| if (wait_if_needed) |
| resource_provider_->WaitReadLockIfNeeded(resource->id()); |
| if (resource_provider_->CanLockForWrite(resource->id())) { |
| - DidFinishUsingResource(resource); |
| + DidFinishUsingResource(resource, it->id); |
| it = busy_resources_.erase(it); |
| } else { |
| ++it; |
| @@ -122,9 +171,10 @@ void ResourcePool::CheckBusyResources(bool wait_if_needed) { |
| } |
| } |
| -void ResourcePool::DidFinishUsingResource(ScopedResource* resource) { |
| +void ResourcePool::DidFinishUsingResource(ScopedResource* resource, |
| + uint64_t id) { |
| unused_memory_usage_bytes_ += resource->bytes(); |
| - unused_resources_.push_back(resource); |
| + unused_resources_.push_back(PoolResource(resource, id)); |
| } |
| } // namespace cc |