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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 95 } |
96 | 96 |
97 Resource* ResourcePool::AcquireResource(const gfx::Size& size, | 97 Resource* ResourcePool::AcquireResource(const gfx::Size& size, |
98 ResourceFormat format) { | 98 ResourceFormat format) { |
99 // Finding resources in |unused_resources_| from MRU to LRU direction, touches | 99 // Finding resources in |unused_resources_| from MRU to LRU direction, touches |
100 // LRU resources only if needed, which increases possibility of expiring more | 100 // LRU resources only if needed, which increases possibility of expiring more |
101 // LRU resources within kResourceExpirationDelayMs. | 101 // LRU resources within kResourceExpirationDelayMs. |
102 for (ResourceDeque::iterator it = unused_resources_.begin(); | 102 for (ResourceDeque::iterator it = unused_resources_.begin(); |
103 it != unused_resources_.end(); ++it) { | 103 it != unused_resources_.end(); ++it) { |
104 ScopedResource* resource = it->get(); | 104 ScopedResource* resource = it->get(); |
105 // TODO(ccameron): Investigate why this fails (http://crbug.com/577121). | 105 // TODO(ccameron): The allowance for IsInUseByMacOSWindowServer should not |
106 // DCHECK(resource_provider_->CanLockForWrite(resource->id())); | 106 // be needed. |
| 107 // http://crbug.com/577121 |
| 108 DCHECK(resource_provider_->CanLockForWrite(resource->id()) || |
| 109 resource_provider_->IsInUseByMacOSWindowServer(resource->id())); |
107 | 110 |
108 if (resource->format() != format) | 111 if (resource->format() != format) |
109 continue; | 112 continue; |
110 if (resource->size() != size) | 113 if (resource->size() != size) |
111 continue; | 114 continue; |
112 | 115 |
113 // Transfer resource to |in_use_resources_|. | 116 // Transfer resource to |in_use_resources_|. |
114 in_use_resources_[resource->id()] = std::move(*it); | 117 in_use_resources_[resource->id()] = std::move(*it); |
115 unused_resources_.erase(it); | 118 unused_resources_.erase(it); |
116 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( | 119 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( |
(...skipping 29 matching lines...) Expand all Loading... |
146 | 149 |
147 auto it = | 150 auto it = |
148 std::find_if(unused_resources_.begin(), unused_resources_.end(), | 151 std::find_if(unused_resources_.begin(), unused_resources_.end(), |
149 [content_id](const scoped_ptr<PoolResource>& pool_resource) { | 152 [content_id](const scoped_ptr<PoolResource>& pool_resource) { |
150 return pool_resource->content_id() == content_id; | 153 return pool_resource->content_id() == content_id; |
151 }); | 154 }); |
152 if (it == unused_resources_.end()) | 155 if (it == unused_resources_.end()) |
153 return nullptr; | 156 return nullptr; |
154 | 157 |
155 Resource* resource = it->get(); | 158 Resource* resource = it->get(); |
156 DCHECK(resource_provider_->CanLockForWrite(resource->id())); | 159 // TODO(ccameron): The allowance for IsInUseByMacOSWindowServer should not |
| 160 // be needed. |
| 161 // http://crbug.com/577121 |
| 162 DCHECK(resource_provider_->CanLockForWrite(resource->id()) || |
| 163 resource_provider_->IsInUseByMacOSWindowServer(resource->id())); |
157 | 164 |
158 // Transfer resource to |in_use_resources_|. | 165 // Transfer resource to |in_use_resources_|. |
159 in_use_resources_[resource->id()] = std::move(*it); | 166 in_use_resources_[resource->id()] = std::move(*it); |
160 unused_resources_.erase(it); | 167 unused_resources_.erase(it); |
161 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( | 168 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( |
162 resource->size(), resource->format()); | 169 resource->size(), resource->format()); |
163 return resource; | 170 return resource; |
164 } | 171 } |
165 | 172 |
166 void ResourcePool::ReleaseResource(Resource* resource, uint64_t content_id) { | 173 void ResourcePool::ReleaseResource(Resource* resource, uint64_t content_id) { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 for (const auto& resource : busy_resources_) { | 322 for (const auto& resource : busy_resources_) { |
316 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); | 323 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); |
317 } | 324 } |
318 for (const auto& entry : in_use_resources_) { | 325 for (const auto& entry : in_use_resources_) { |
319 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); | 326 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); |
320 } | 327 } |
321 return true; | 328 return true; |
322 } | 329 } |
323 | 330 |
324 } // namespace cc | 331 } // namespace cc |
OLD | NEW |