| 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 { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 bool ResourcePool::ResourceUsageTooHigh() { | 124 bool ResourcePool::ResourceUsageTooHigh() { |
| 125 if (resource_count_ > max_resource_count_) | 125 if (resource_count_ > max_resource_count_) |
| 126 return true; | 126 return true; |
| 127 if (memory_usage_bytes_ > max_memory_usage_bytes_) | 127 if (memory_usage_bytes_ > max_memory_usage_bytes_) |
| 128 return true; | 128 return true; |
| 129 if (unused_memory_usage_bytes_ > max_unused_memory_usage_bytes_) | 129 if (unused_memory_usage_bytes_ > max_unused_memory_usage_bytes_) |
| 130 return true; | 130 return true; |
| 131 return false; | 131 return false; |
| 132 } | 132 } |
| 133 | 133 |
| 134 void ResourcePool::CheckBusyResources(bool wait_if_needed) { | 134 void ResourcePool::CheckBusyResources() { |
| 135 ResourceList::iterator it = busy_resources_.begin(); | 135 ResourceList::iterator it = busy_resources_.begin(); |
| 136 | 136 |
| 137 while (it != busy_resources_.end()) { | 137 while (it != busy_resources_.end()) { |
| 138 ScopedResource* resource = it->resource; | 138 ScopedResource* resource = it->resource; |
| 139 | 139 |
| 140 if (wait_if_needed) | |
| 141 resource_provider_->WaitReadLockIfNeeded(resource->id()); | |
| 142 | |
| 143 if (resource_provider_->CanLockForWrite(resource->id())) { | 140 if (resource_provider_->CanLockForWrite(resource->id())) { |
| 144 DidFinishUsingResource(resource, it->content_id); | 141 DidFinishUsingResource(resource, it->content_id); |
| 145 it = busy_resources_.erase(it); | 142 it = busy_resources_.erase(it); |
| 146 } else { | 143 } else { |
| 147 ++it; | 144 ++it; |
| 148 } | 145 } |
| 149 } | 146 } |
| 150 } | 147 } |
| 151 | 148 |
| 152 void ResourcePool::DidFinishUsingResource(ScopedResource* resource, | 149 void ResourcePool::DidFinishUsingResource(ScopedResource* resource, |
| 153 uint64_t content_id) { | 150 uint64_t content_id) { |
| 154 unused_memory_usage_bytes_ += | 151 unused_memory_usage_bytes_ += |
| 155 Resource::UncheckedMemorySizeBytes(resource->size(), resource->format()); | 152 Resource::UncheckedMemorySizeBytes(resource->size(), resource->format()); |
| 156 unused_resources_.push_back(PoolResource(resource, content_id)); | 153 unused_resources_.push_back(PoolResource(resource, content_id)); |
| 157 } | 154 } |
| 158 | 155 |
| 159 } // namespace cc | 156 } // namespace cc |
| OLD | NEW |