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

Unified Diff: cc/resources/resource_pool.cc

Issue 817133006: Support different formats in the same resource pool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 45f36e27816d04451e1f92e786dcf21911fd3f34..8061270ef88e8797df1f14fca9b004dc89dbcaec 100644
--- a/cc/resources/resource_pool.cc
+++ b/cc/resources/resource_pool.cc
@@ -11,10 +11,10 @@ namespace cc {
ResourcePool::ResourcePool(ResourceProvider* resource_provider,
GLenum target,
- ResourceFormat format)
+ bool use_memory_efficient_format)
: resource_provider_(resource_provider),
target_(target),
- format_(format),
+ use_memory_efficient_format_(use_memory_efficient_format),
max_memory_usage_bytes_(0),
max_unused_memory_usage_bytes_(0),
max_resource_count_(0),
@@ -29,37 +29,45 @@ ResourcePool::~ResourcePool() {
}
SetResourceUsageLimits(0, 0, 0);
- DCHECK_EQ(0u, unused_resources_.size());
+ for (UnusedMap::const_iterator it = unused_resources_.begin();
+ it != unused_resources_.end();
+ ++it) {
+ DCHECK_EQ(0u, it->second.size());
+ }
DCHECK_EQ(0u, memory_usage_bytes_);
DCHECK_EQ(0u, unused_memory_usage_bytes_);
DCHECK_EQ(0u, resource_count_);
}
scoped_ptr<ScopedResource> ResourcePool::AcquireResource(
- const gfx::Size& size) {
- for (ResourceList::iterator it = unused_resources_.begin();
- it != unused_resources_.end();
- ++it) {
+ const gfx::Size& size, ResourceFormat format) {
+ ResourceList& unused = unused_resources_[format];
+ for (ResourceList::iterator it = unused.begin(); it != unused.end(); ++it) {
ScopedResource* resource = *it;
DCHECK(resource_provider_->CanLockForWrite(resource->id()));
if (resource->size() != size)
continue;
- unused_resources_.erase(it);
+ unused.erase(it);
unused_memory_usage_bytes_ -= resource->bytes();
return make_scoped_ptr(resource);
}
scoped_ptr<ScopedResource> resource =
ScopedResource::Create(resource_provider_);
- resource->AllocateManaged(size, target_, format_);
+ resource->AllocateManaged(size, target_, format);
memory_usage_bytes_ += resource->bytes();
++resource_count_;
return resource.Pass();
}
+scoped_ptr<ScopedResource> ResourcePool::AcquireResource(
+ const gfx::Size& size, ResourceFormatUsage usage) {
+ return AcquireResource(size, resource_format(usage));
+}
+
void ResourcePool::ReleaseResource(scoped_ptr<ScopedResource> resource) {
busy_resources_.push_back(resource.release());
}
@@ -75,23 +83,28 @@ void ResourcePool::SetResourceUsageLimits(size_t max_memory_usage_bytes,
}
void ResourcePool::ReduceResourceUsage() {
- while (!unused_resources_.empty()) {
- if (!ResourceUsageTooHigh())
- break;
-
- // LRU eviction pattern. Most recently used might be blocked by
- // a read lock fence but it's still better to evict the least
- // recently used as it prevents a resource that is hard to reuse
- // because of unique size from being kept around. Resources that
- // 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();
- unused_resources_.pop_front();
- memory_usage_bytes_ -= resource->bytes();
- unused_memory_usage_bytes_ -= resource->bytes();
- --resource_count_;
- delete resource;
+ for (UnusedMap::iterator it = unused_resources_.begin();
+ it != unused_resources_.end();
+ ++it) {
+ ResourceList& unused = it->second;
+ while (!unused.empty()) {
+ if (!ResourceUsageTooHigh())
+ break;
+
+ // LRU eviction pattern. Most recently used might be blocked by
+ // a read lock fence but it's still better to evict the least
+ // recently used as it prevents a resource that is hard to reuse
+ // because of unique size from being kept around. Resources that
+ // 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.front();
+ unused.pop_front();
+ memory_usage_bytes_ -= resource->bytes();
+ unused_memory_usage_bytes_ -= resource->bytes();
+ --resource_count_;
+ delete resource;
+ }
}
}
@@ -105,6 +118,23 @@ bool ResourcePool::ResourceUsageTooHigh() {
return false;
}
+ResourceFormat ResourcePool::resource_format(ResourceFormatUsage usage) const {
+ if (use_memory_efficient_format_) {
+ return resource_provider_->memory_efficient_texture_format(usage);
+ } else {
+ return resource_provider_->best_texture_format();
+ }
+}
+
+size_t ResourcePool::acquired_resource_count() const {
+ size_t result = resource_count_;
+ for (UnusedMap::const_iterator it = unused_resources_.begin();
+ it != unused_resources_.end(); ++it) {
+ result -= it->second.size();
+ }
+ return result;
+}
+
void ResourcePool::CheckBusyResources(bool wait_if_needed) {
ResourceList::iterator it = busy_resources_.begin();
@@ -125,7 +155,7 @@ void ResourcePool::CheckBusyResources(bool wait_if_needed) {
void ResourcePool::DidFinishUsingResource(ScopedResource* resource) {
unused_memory_usage_bytes_ += resource->bytes();
- unused_resources_.push_back(resource);
+ unused_resources_[resource->format()].push_back(resource);
}
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698