| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 } | 180 } |
| 181 | 181 |
| 182 void ResourcePool::DeleteResource(ScopedResource* resource) { | 182 void ResourcePool::DeleteResource(ScopedResource* resource) { |
| 183 size_t resource_bytes = ResourceUtil::UncheckedSizeInBytes<size_t>( | 183 size_t resource_bytes = ResourceUtil::UncheckedSizeInBytes<size_t>( |
| 184 resource->size(), resource->format()); | 184 resource->size(), resource->format()); |
| 185 memory_usage_bytes_ -= resource_bytes; | 185 memory_usage_bytes_ -= resource_bytes; |
| 186 --resource_count_; | 186 --resource_count_; |
| 187 delete resource; | 187 delete resource; |
| 188 } | 188 } |
| 189 | 189 |
| 190 void ResourcePool::CheckBusyResources() { | 190 void ResourcePool::CheckBusyResources(bool wait_if_needed) { |
| 191 ResourceList::iterator it = busy_resources_.begin(); | 191 ResourceList::iterator it = busy_resources_.begin(); |
| 192 | 192 |
| 193 while (it != busy_resources_.end()) { | 193 while (it != busy_resources_.end()) { |
| 194 ScopedResource* resource = it->resource; | 194 ScopedResource* resource = it->resource; |
| 195 | 195 |
| 196 if (wait_if_needed) |
| 197 resource_provider_->WaitReadLockIfNeeded(resource->id()); |
| 198 |
| 196 if (resource_provider_->CanLockForWrite(resource->id())) { | 199 if (resource_provider_->CanLockForWrite(resource->id())) { |
| 197 DidFinishUsingResource(resource, it->content_id); | 200 DidFinishUsingResource(resource, it->content_id); |
| 198 it = busy_resources_.erase(it); | 201 it = busy_resources_.erase(it); |
| 199 } else if (resource_provider_->IsLost(resource->id())) { | 202 } else if (resource_provider_->IsLost(resource->id())) { |
| 200 // Remove lost resources from pool. | 203 // Remove lost resources from pool. |
| 201 DeleteResource(resource); | 204 DeleteResource(resource); |
| 202 it = busy_resources_.erase(it); | 205 it = busy_resources_.erase(it); |
| 203 } else { | 206 } else { |
| 204 ++it; | 207 ++it; |
| 205 } | 208 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 220 } | 223 } |
| 221 for (const auto& resource : busy_resources_) { | 224 for (const auto& resource : busy_resources_) { |
| 222 resource.OnMemoryDump(pmd, false /* is_free */); | 225 resource.OnMemoryDump(pmd, false /* is_free */); |
| 223 } | 226 } |
| 224 // TODO(ericrk): Dump vended out resources once that data is available. | 227 // TODO(ericrk): Dump vended out resources once that data is available. |
| 225 // crbug.com/516541 | 228 // crbug.com/516541 |
| 226 return true; | 229 return true; |
| 227 } | 230 } |
| 228 | 231 |
| 229 } // namespace cc | 232 } // namespace cc |
| OLD | NEW |