| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/resources/resource_pool.h" | 5 #include "cc/resources/resource_pool.h" |
| 6 | 6 |
| 7 #include "cc/resources/resource_provider.h" | 7 #include "cc/resources/resource_provider.h" |
| 8 #include "cc/resources/scoped_resource.h" | 8 #include "cc/resources/scoped_resource.h" |
| 9 | 9 |
| 10 namespace cc { | 10 namespace cc { |
| 11 | 11 |
| 12 ResourcePool::ResourcePool(ResourceProvider* resource_provider, | 12 ResourcePool::ResourcePool(ResourceProvider* resource_provider, |
| 13 GLenum target, | 13 GLenum target, |
| 14 ResourceFormat format) | 14 ResourceFormat default_format) |
| 15 : resource_provider_(resource_provider), | 15 : resource_provider_(resource_provider), |
| 16 target_(target), | 16 target_(target), |
| 17 format_(format), | 17 default_format_(default_format), |
| 18 max_memory_usage_bytes_(0), | 18 max_memory_usage_bytes_(0), |
| 19 max_unused_memory_usage_bytes_(0), | 19 max_unused_memory_usage_bytes_(0), |
| 20 max_resource_count_(0), | 20 max_resource_count_(0), |
| 21 memory_usage_bytes_(0), | 21 memory_usage_bytes_(0), |
| 22 unused_memory_usage_bytes_(0), | 22 unused_memory_usage_bytes_(0), |
| 23 resource_count_(0) {} | 23 resource_count_(0) {} |
| 24 | 24 |
| 25 ResourcePool::~ResourcePool() { | 25 ResourcePool::~ResourcePool() { |
| 26 while (!busy_resources_.empty()) { | 26 while (!busy_resources_.empty()) { |
| 27 DidFinishUsingResource(busy_resources_.front()); | 27 DidFinishUsingResource(busy_resources_.front()); |
| 28 busy_resources_.pop_front(); | 28 busy_resources_.pop_front(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 SetResourceUsageLimits(0, 0, 0); | 31 SetResourceUsageLimits(0, 0, 0); |
| 32 DCHECK_EQ(0u, unused_resources_.size()); | 32 DCHECK_EQ(0u, unused_resources_.size()); |
| 33 DCHECK_EQ(0u, memory_usage_bytes_); | 33 DCHECK_EQ(0u, memory_usage_bytes_); |
| 34 DCHECK_EQ(0u, unused_memory_usage_bytes_); | 34 DCHECK_EQ(0u, unused_memory_usage_bytes_); |
| 35 DCHECK_EQ(0u, resource_count_); | 35 DCHECK_EQ(0u, resource_count_); |
| 36 } | 36 } |
| 37 | 37 |
| 38 scoped_ptr<ScopedResource> ResourcePool::AcquireResource( | 38 scoped_ptr<ScopedResource> ResourcePool::AcquireResource( |
| 39 const gfx::Size& size) { | 39 const gfx::Size& size, ResourceFormat format) { |
| 40 for (ResourceList::iterator it = unused_resources_.begin(); | 40 for (ResourceList::iterator it = unused_resources_.begin(); |
| 41 it != unused_resources_.end(); | 41 it != unused_resources_.end(); |
| 42 ++it) { | 42 ++it) { |
| 43 ScopedResource* resource = *it; | 43 ScopedResource* resource = *it; |
| 44 DCHECK(resource_provider_->CanLockForWrite(resource->id())); | 44 DCHECK(resource_provider_->CanLockForWrite(resource->id())); |
| 45 | 45 |
| 46 if (resource->format() != format) |
| 47 continue; |
| 46 if (resource->size() != size) | 48 if (resource->size() != size) |
| 47 continue; | 49 continue; |
| 48 | 50 |
| 49 unused_resources_.erase(it); | 51 unused_resources_.erase(it); |
| 50 unused_memory_usage_bytes_ -= resource->bytes(); | 52 unused_memory_usage_bytes_ -= resource->bytes(); |
| 51 return make_scoped_ptr(resource); | 53 return make_scoped_ptr(resource); |
| 52 } | 54 } |
| 53 | 55 |
| 54 scoped_ptr<ScopedResource> resource = | 56 scoped_ptr<ScopedResource> resource = |
| 55 ScopedResource::Create(resource_provider_); | 57 ScopedResource::Create(resource_provider_); |
| 56 resource->AllocateManaged(size, target_, format_); | 58 resource->AllocateManaged(size, target_, format); |
| 57 | 59 |
| 58 memory_usage_bytes_ += resource->bytes(); | 60 memory_usage_bytes_ += resource->bytes(); |
| 59 ++resource_count_; | 61 ++resource_count_; |
| 60 return resource.Pass(); | 62 return resource.Pass(); |
| 61 } | 63 } |
| 62 | 64 |
| 63 void ResourcePool::ReleaseResource(scoped_ptr<ScopedResource> resource) { | 65 void ResourcePool::ReleaseResource(scoped_ptr<ScopedResource> resource) { |
| 64 busy_resources_.push_back(resource.release()); | 66 busy_resources_.push_back(resource.release()); |
| 65 } | 67 } |
| 66 | 68 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 124 } |
| 123 } | 125 } |
| 124 } | 126 } |
| 125 | 127 |
| 126 void ResourcePool::DidFinishUsingResource(ScopedResource* resource) { | 128 void ResourcePool::DidFinishUsingResource(ScopedResource* resource) { |
| 127 unused_memory_usage_bytes_ += resource->bytes(); | 129 unused_memory_usage_bytes_ += resource->bytes(); |
| 128 unused_resources_.push_back(resource); | 130 unused_resources_.push_back(resource); |
| 129 } | 131 } |
| 130 | 132 |
| 131 } // namespace cc | 133 } // namespace cc |
| OLD | NEW |