| 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(bool wait_if_needed) { | 208 void ResourcePool::CheckBusyResources() { |
| 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 | |
| 216 if (resource_provider_->CanLockForWrite(resource->id())) { | 213 if (resource_provider_->CanLockForWrite(resource->id())) { |
| 217 DidFinishUsingResource(busy_resources_.take(it)); | 214 DidFinishUsingResource(busy_resources_.take(it)); |
| 218 } else if (resource_provider_->IsLost(resource->id())) { | 215 } else if (resource_provider_->IsLost(resource->id())) { |
| 219 // Remove lost resources from pool. | 216 // Remove lost resources from pool. |
| 220 DeleteResource(busy_resources_.take(it)); | 217 DeleteResource(busy_resources_.take(it)); |
| 221 } else { | 218 } else { |
| 222 ++i; | 219 ++i; |
| 223 } | 220 } |
| 224 } | 221 } |
| 225 } | 222 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 238 for (const auto& resource : busy_resources_) { | 235 for (const auto& resource : busy_resources_) { |
| 239 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); | 236 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); |
| 240 } | 237 } |
| 241 for (const auto& entry : in_use_resources_) { | 238 for (const auto& entry : in_use_resources_) { |
| 242 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); | 239 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); |
| 243 } | 240 } |
| 244 return true; | 241 return true; |
| 245 } | 242 } |
| 246 | 243 |
| 247 } // namespace cc | 244 } // namespace cc |
| OLD | NEW |