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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 return false; | 198 return false; |
199 } | 199 } |
200 | 200 |
201 void ResourcePool::DeleteResource(scoped_ptr<PoolResource> resource) { | 201 void ResourcePool::DeleteResource(scoped_ptr<PoolResource> resource) { |
202 size_t resource_bytes = ResourceUtil::UncheckedSizeInBytes<size_t>( | 202 size_t resource_bytes = ResourceUtil::UncheckedSizeInBytes<size_t>( |
203 resource->size(), resource->format()); | 203 resource->size(), resource->format()); |
204 memory_usage_bytes_ -= resource_bytes; | 204 memory_usage_bytes_ -= resource_bytes; |
205 --resource_count_; | 205 --resource_count_; |
206 } | 206 } |
207 | 207 |
208 void ResourcePool::CheckBusyResources() { | 208 void ResourcePool::CheckBusyResources(bool wait_if_needed) { |
209 for (size_t i = 0; i < busy_resources_.size();) { | 209 for (size_t i = 0; i < busy_resources_.size();) { |
210 ResourceDeque::iterator it(busy_resources_.begin() + i); | 210 ResourceDeque::iterator it(busy_resources_.begin() + i); |
211 PoolResource* resource = *it; | 211 PoolResource* resource = *it; |
212 | 212 |
| 213 if (wait_if_needed) |
| 214 resource_provider_->WaitReadLockIfNeeded(resource->id()); |
| 215 |
213 if (resource_provider_->CanLockForWrite(resource->id())) { | 216 if (resource_provider_->CanLockForWrite(resource->id())) { |
214 DidFinishUsingResource(busy_resources_.take(it)); | 217 DidFinishUsingResource(busy_resources_.take(it)); |
215 } else if (resource_provider_->IsLost(resource->id())) { | 218 } else if (resource_provider_->IsLost(resource->id())) { |
216 // Remove lost resources from pool. | 219 // Remove lost resources from pool. |
217 DeleteResource(busy_resources_.take(it)); | 220 DeleteResource(busy_resources_.take(it)); |
218 } else { | 221 } else { |
219 ++i; | 222 ++i; |
220 } | 223 } |
221 } | 224 } |
222 } | 225 } |
(...skipping 12 matching lines...) Expand all Loading... |
235 for (const auto& resource : busy_resources_) { | 238 for (const auto& resource : busy_resources_) { |
236 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); | 239 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); |
237 } | 240 } |
238 for (const auto& entry : in_use_resources_) { | 241 for (const auto& entry : in_use_resources_) { |
239 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); | 242 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); |
240 } | 243 } |
241 return true; | 244 return true; |
242 } | 245 } |
243 | 246 |
244 } // namespace cc | 247 } // namespace cc |
OLD | NEW |