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

Unified Diff: cc/resources/resource_pool.cc

Issue 23231002: cc: Prevent the tile manager from allocating more memory than allowed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: s/resources_/unused_resources_/ Created 7 years, 4 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 5835db565d31ec048c44d252a38421722cb1b1c8..db47b41e19d8aef9decf99c68e15e6ac3feb6e6a 100644
--- a/cc/resources/resource_pool.cc
+++ b/cc/resources/resource_pool.cc
@@ -31,9 +31,10 @@ ResourcePool::ResourcePool(ResourceProvider* resource_provider)
: resource_provider_(resource_provider),
max_memory_usage_bytes_(0),
max_unused_memory_usage_bytes_(0),
+ max_resource_count_(0),
memory_usage_bytes_(0),
unused_memory_usage_bytes_(0),
- num_resources_limit_(0) {
+ resource_count_(0) {
}
ResourcePool::~ResourcePool() {
@@ -42,8 +43,8 @@ ResourcePool::~ResourcePool() {
scoped_ptr<ResourcePool::Resource> ResourcePool::AcquireResource(
gfx::Size size, GLenum format) {
- for (ResourceList::iterator it = resources_.begin();
- it != resources_.end(); ++it) {
+ for (ResourceList::iterator it = unused_resources_.begin();
+ it != unused_resources_.end(); ++it) {
Resource* resource = *it;
// TODO(epenner): It would be nice to DCHECK that this
@@ -57,14 +58,13 @@ scoped_ptr<ResourcePool::Resource> ResourcePool::AcquireResource(
if (resource->format() != format)
continue;
- resources_.erase(it);
+ unused_resources_.erase(it);
unused_memory_usage_bytes_ -= resource->bytes();
return make_scoped_ptr(resource);
}
// Create new resource.
- Resource* resource = new Resource(
- resource_provider_, size, format);
+ Resource* resource = new Resource(resource_provider_, size, format);
// Extend all read locks on all resources until the resource is
// finished being used, such that we know when resources are
@@ -72,6 +72,7 @@ scoped_ptr<ResourcePool::Resource> ResourcePool::AcquireResource(
resource_provider_->EnableReadLockFences(resource->id(), true);
memory_usage_bytes_ += resource->bytes();
+ ++resource_count_;
return make_scoped_ptr(resource);
}
@@ -79,37 +80,43 @@ void ResourcePool::ReleaseResource(
scoped_ptr<ResourcePool::Resource> resource) {
if (MemoryUsageTooHigh()) {
memory_usage_bytes_ -= resource->bytes();
+ --resource_count_;
return;
}
unused_memory_usage_bytes_ += resource->bytes();
- resources_.push_back(resource.release());
+ unused_resources_.push_back(resource.release());
}
void ResourcePool::SetMemoryUsageLimits(
size_t max_memory_usage_bytes,
size_t max_unused_memory_usage_bytes,
- size_t num_resources_limit) {
+ size_t max_resource_count) {
max_memory_usage_bytes_ = max_memory_usage_bytes;
max_unused_memory_usage_bytes_ = max_unused_memory_usage_bytes;
- num_resources_limit_ = num_resources_limit;
+ max_resource_count_ = max_resource_count;
- while (!resources_.empty()) {
+ ReduceMemoryUsage();
+}
+
+void ResourcePool::ReduceMemoryUsage() {
+ while (!unused_resources_.empty()) {
if (!MemoryUsageTooHigh())
break;
// MRU eviction pattern as least recently used is less likely to
// be blocked by read lock fence.
- Resource* resource = resources_.back();
- resources_.pop_back();
+ Resource* resource = unused_resources_.back();
+ unused_resources_.pop_back();
memory_usage_bytes_ -= resource->bytes();
unused_memory_usage_bytes_ -= resource->bytes();
+ --resource_count_;
delete resource;
}
}
bool ResourcePool::MemoryUsageTooHigh() {
vmpstr 2013/08/15 18:26:37 nit: This should probably be ResourceUsageTooHigh
reveman 2013/08/15 19:13:55 Done. Together with other usage of "MemoryUsage" i
- if (resources_.size() > num_resources_limit_)
+ if (resource_count_ > max_resource_count_)
return true;
if (memory_usage_bytes_ > max_memory_usage_bytes_)
return true;

Powered by Google App Engine
This is Rietveld 408576698