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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 bool ResourcePool::ResourceUsageTooHigh() { | 98 bool ResourcePool::ResourceUsageTooHigh() { |
99 if (resource_count_ > max_resource_count_) | 99 if (resource_count_ > max_resource_count_) |
100 return true; | 100 return true; |
101 if (memory_usage_bytes_ > max_memory_usage_bytes_) | 101 if (memory_usage_bytes_ > max_memory_usage_bytes_) |
102 return true; | 102 return true; |
103 if (unused_memory_usage_bytes_ > max_unused_memory_usage_bytes_) | 103 if (unused_memory_usage_bytes_ > max_unused_memory_usage_bytes_) |
104 return true; | 104 return true; |
105 return false; | 105 return false; |
106 } | 106 } |
107 | 107 |
108 void ResourcePool::CheckBusyResources() { | 108 void ResourcePool::CheckBusyResources(bool wait_if_needed) { |
109 ResourceList::iterator it = busy_resources_.begin(); | 109 ResourceList::iterator it = busy_resources_.begin(); |
110 | 110 |
111 while (it != busy_resources_.end()) { | 111 while (it != busy_resources_.end()) { |
112 ScopedResource* resource = *it; | 112 ScopedResource* resource = *it; |
113 | 113 |
| 114 if (wait_if_needed) |
| 115 resource_provider_->WaitReadLockIfNeeded(resource->id()); |
| 116 |
114 if (resource_provider_->CanLockForWrite(resource->id())) { | 117 if (resource_provider_->CanLockForWrite(resource->id())) { |
115 DidFinishUsingResource(resource); | 118 DidFinishUsingResource(resource); |
116 it = busy_resources_.erase(it); | 119 it = busy_resources_.erase(it); |
117 } else { | 120 } else { |
118 ++it; | 121 ++it; |
119 } | 122 } |
120 } | 123 } |
121 } | 124 } |
122 | 125 |
123 void ResourcePool::DidFinishUsingResource(ScopedResource* resource) { | 126 void ResourcePool::DidFinishUsingResource(ScopedResource* resource) { |
124 unused_memory_usage_bytes_ += resource->bytes(); | 127 unused_memory_usage_bytes_ += resource->bytes(); |
125 unused_resources_.push_back(resource); | 128 unused_resources_.push_back(resource); |
126 } | 129 } |
127 | 130 |
128 } // namespace cc | 131 } // namespace cc |
OLD | NEW |