| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 129 } |
| 130 | 130 |
| 131 void ResourcePool::DeleteResource(ScopedResource* resource) { | 131 void ResourcePool::DeleteResource(ScopedResource* resource) { |
| 132 size_t resource_bytes = | 132 size_t resource_bytes = |
| 133 Resource::UncheckedMemorySizeBytes(resource->size(), resource->format()); | 133 Resource::UncheckedMemorySizeBytes(resource->size(), resource->format()); |
| 134 memory_usage_bytes_ -= resource_bytes; | 134 memory_usage_bytes_ -= resource_bytes; |
| 135 --resource_count_; | 135 --resource_count_; |
| 136 delete resource; | 136 delete resource; |
| 137 } | 137 } |
| 138 | 138 |
| 139 void ResourcePool::CheckBusyResources(bool wait_if_needed) { | 139 void ResourcePool::CheckBusyResources() { |
| 140 ResourceList::iterator it = busy_resources_.begin(); | 140 ResourceList::iterator it = busy_resources_.begin(); |
| 141 | 141 |
| 142 while (it != busy_resources_.end()) { | 142 while (it != busy_resources_.end()) { |
| 143 ScopedResource* resource = it->resource; | 143 ScopedResource* resource = it->resource; |
| 144 | 144 |
| 145 if (wait_if_needed) | |
| 146 resource_provider_->WaitReadLockIfNeeded(resource->id()); | |
| 147 | |
| 148 if (resource_provider_->CanLockForWrite(resource->id())) { | 145 if (resource_provider_->CanLockForWrite(resource->id())) { |
| 149 DidFinishUsingResource(resource, it->content_id); | 146 DidFinishUsingResource(resource, it->content_id); |
| 150 it = busy_resources_.erase(it); | 147 it = busy_resources_.erase(it); |
| 151 } else if (resource_provider_->IsLost(resource->id())) { | 148 } else if (resource_provider_->IsLost(resource->id())) { |
| 152 // Remove lost resources from pool. | 149 // Remove lost resources from pool. |
| 153 DeleteResource(resource); | 150 DeleteResource(resource); |
| 154 it = busy_resources_.erase(it); | 151 it = busy_resources_.erase(it); |
| 155 } else { | 152 } else { |
| 156 ++it; | 153 ++it; |
| 157 } | 154 } |
| 158 } | 155 } |
| 159 } | 156 } |
| 160 | 157 |
| 161 void ResourcePool::DidFinishUsingResource(ScopedResource* resource, | 158 void ResourcePool::DidFinishUsingResource(ScopedResource* resource, |
| 162 uint64_t content_id) { | 159 uint64_t content_id) { |
| 163 unused_memory_usage_bytes_ += | 160 unused_memory_usage_bytes_ += |
| 164 Resource::UncheckedMemorySizeBytes(resource->size(), resource->format()); | 161 Resource::UncheckedMemorySizeBytes(resource->size(), resource->format()); |
| 165 unused_resources_.push_back(PoolResource(resource, content_id)); | 162 unused_resources_.push_back(PoolResource(resource, content_id)); |
| 166 } | 163 } |
| 167 | 164 |
| 168 } // namespace cc | 165 } // namespace cc |
| OLD | NEW |