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() { | 141 void ResourcePool::CheckBusyResources(bool wait_if_needed) { |
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 |
147 if (resource_provider_->CanLockForWrite(resource->id())) { | 150 if (resource_provider_->CanLockForWrite(resource->id())) { |
148 DidFinishUsingResource(resource, it->content_id); | 151 DidFinishUsingResource(resource, it->content_id); |
149 it = busy_resources_.erase(it); | 152 it = busy_resources_.erase(it); |
150 } else if (resource_provider_->IsLost(resource->id())) { | 153 } else if (resource_provider_->IsLost(resource->id())) { |
151 // Remove lost resources from pool. | 154 // Remove lost resources from pool. |
152 DeleteResource(resource); | 155 DeleteResource(resource); |
153 it = busy_resources_.erase(it); | 156 it = busy_resources_.erase(it); |
154 } else { | 157 } else { |
155 ++it; | 158 ++it; |
156 } | 159 } |
157 } | 160 } |
158 } | 161 } |
159 | 162 |
160 void ResourcePool::DidFinishUsingResource(ScopedResource* resource, | 163 void ResourcePool::DidFinishUsingResource(ScopedResource* resource, |
161 uint64_t content_id) { | 164 uint64_t content_id) { |
162 unused_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( | 165 unused_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( |
163 resource->size(), resource->format()); | 166 resource->size(), resource->format()); |
164 unused_resources_.push_back(PoolResource(resource, content_id)); | 167 unused_resources_.push_back(PoolResource(resource, content_id)); |
165 } | 168 } |
166 | 169 |
167 } // namespace cc | 170 } // namespace cc |
OLD | NEW |