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

Unified Diff: cc/resources/resource_pool.cc

Issue 1139063002: cc: Partial tile update for one-copy raster. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: monocle: slightlylessstruct Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: cc/resources/resource_pool.cc
diff --git a/cc/resources/resource_pool.cc b/cc/resources/resource_pool.cc
index 22847809ba3c196f66df1112d978d56342665b3a..d4f428e05593848323dc0721b798d7b8c8c270f8 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.content_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,32 @@ 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::TryAcquireResourceWithContentId(
+ const gfx::Size& size,
+ ResourceFormat format,
+ uint64_t content_id) {
+ DCHECK(content_id);
+
+ auto it = std::find_if(unused_resources_.begin(), unused_resources_.end(),
+ [content_id](const PoolResource& pr) {
reveman 2015/05/28 05:07:25 nit: s/pr/pool_resource/
danakj 2015/05/28 18:54:47 Done.
+ return pr.content_id == content_id;
+ });
+ if (it == unused_resources_.end())
+ return nullptr;
+
+ ScopedResource* resource = it->resource;
+ DCHECK(resource_provider_->CanLockForWrite(resource->id()));
+ DCHECK_EQ(format, resource->format());
+ DCHECK_EQ(size.ToString(), resource->size().ToString());
reveman 2015/05/28 05:07:25 I don't think we should have parameters that are o
danakj 2015/05/28 18:54:47 Done.
+
+ unused_resources_.erase(it);
+ unused_memory_usage_bytes_ -= resource->bytes();
+ return make_scoped_ptr(resource);
+}
+
+void ResourcePool::ReleaseResource(scoped_ptr<ScopedResource> resource,
+ uint64_t content_id) {
+ busy_resources_.push_back(PoolResource(resource.release(), content_id));
}
void ResourcePool::SetResourceUsageLimits(size_t max_memory_usage_bytes,
@@ -85,7 +110,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 +133,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->content_id);
it = busy_resources_.erase(it);
} else {
++it;
@@ -122,9 +147,10 @@ void ResourcePool::CheckBusyResources(bool wait_if_needed) {
}
}
-void ResourcePool::DidFinishUsingResource(ScopedResource* resource) {
+void ResourcePool::DidFinishUsingResource(ScopedResource* resource,
+ uint64_t content_id) {
unused_memory_usage_bytes_ += resource->bytes();
- unused_resources_.push_back(resource);
+ unused_resources_.push_back(PoolResource(resource, content_id));
}
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698