| Index: cc/resources/resource_pool.cc | 
| diff --git a/cc/resources/resource_pool.cc b/cc/resources/resource_pool.cc | 
| index 45f36e27816d04451e1f92e786dcf21911fd3f34..51813b28557dc84b228b9fe3d4c4fdd63dd21ee0 100644 | 
| --- a/cc/resources/resource_pool.cc | 
| +++ b/cc/resources/resource_pool.cc | 
| @@ -11,16 +11,17 @@ 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), | 
| memory_usage_bytes_(0), | 
| unused_memory_usage_bytes_(0), | 
| -      resource_count_(0) {} | 
| +      resource_count_(0) { | 
| +} | 
|  | 
| ResourcePool::~ResourcePool() { | 
| while (!busy_resources_.empty()) { | 
| @@ -29,37 +30,46 @@ 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 +85,27 @@ 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; | 
| +    } | 
| } | 
| } | 
|  | 
| @@ -123,9 +137,26 @@ void ResourcePool::CheckBusyResources(bool wait_if_needed) { | 
| } | 
| } | 
|  | 
| +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 resource_count_; | 
| +} | 
| + | 
| 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 | 
|  |