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