Chromium Code Reviews| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 it != unused_resources_.end(); ++it) { | 99 it != unused_resources_.end(); ++it) { |
| 100 ScopedResource* resource = it->get(); | 100 ScopedResource* resource = it->get(); |
| 101 DCHECK(resource_provider_->CanLockForWrite(resource->id())); | 101 DCHECK(resource_provider_->CanLockForWrite(resource->id())); |
| 102 | 102 |
| 103 if (resource->format() != format) | 103 if (resource->format() != format) |
| 104 continue; | 104 continue; |
| 105 if (resource->size() != size) | 105 if (resource->size() != size) |
| 106 continue; | 106 continue; |
| 107 | 107 |
| 108 // Transfer resource to |in_use_resources_|. | 108 // Transfer resource to |in_use_resources_|. |
| 109 in_use_resources_.set(resource->id(), it->Pass()); | 109 in_use_resources_[resource->id()] = it->Pass(); |
|
Matt Giuca
2015/11/19 23:42:26
nit: It seems that std::move is allowed now. I'm n
Matt Giuca
2015/11/19 23:42:26
nit: There is a trailing space at the end of this
limasdf
2015/11/20 15:20:04
Done.
| |
| 110 unused_resources_.erase(it); | 110 unused_resources_.erase(it); |
| 111 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( | 111 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( |
| 112 resource->size(), resource->format()); | 112 resource->size(), resource->format()); |
| 113 return resource; | 113 return resource; |
| 114 } | 114 } |
| 115 | 115 |
| 116 scoped_ptr<PoolResource> pool_resource = | 116 scoped_ptr<PoolResource> pool_resource = |
| 117 PoolResource::Create(resource_provider_); | 117 PoolResource::Create(resource_provider_); |
| 118 | 118 |
| 119 if (use_gpu_memory_buffers_) { | 119 if (use_gpu_memory_buffers_) { |
| 120 pool_resource->AllocateWithGpuMemoryBuffer(size, format); | 120 pool_resource->AllocateWithGpuMemoryBuffer(size, format); |
| 121 } else { | 121 } else { |
| 122 pool_resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 122 pool_resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
| 123 format); | 123 format); |
| 124 } | 124 } |
| 125 | 125 |
| 126 DCHECK(ResourceUtil::VerifySizeInBytes<size_t>(pool_resource->size(), | 126 DCHECK(ResourceUtil::VerifySizeInBytes<size_t>(pool_resource->size(), |
| 127 pool_resource->format())); | 127 pool_resource->format())); |
| 128 total_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( | 128 total_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( |
| 129 pool_resource->size(), pool_resource->format()); | 129 pool_resource->size(), pool_resource->format()); |
| 130 ++total_resource_count_; | 130 ++total_resource_count_; |
| 131 | 131 |
| 132 Resource* resource = pool_resource.get(); | 132 Resource* resource = pool_resource.get(); |
| 133 in_use_resources_.set(resource->id(), std::move(pool_resource)); | 133 in_use_resources_[resource->id()] = std::move(pool_resource); |
| 134 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( | 134 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( |
| 135 resource->size(), resource->format()); | 135 resource->size(), resource->format()); |
| 136 return resource; | 136 return resource; |
| 137 } | 137 } |
| 138 | 138 |
| 139 Resource* ResourcePool::TryAcquireResourceWithContentId(uint64_t content_id) { | 139 Resource* ResourcePool::TryAcquireResourceWithContentId(uint64_t content_id) { |
| 140 DCHECK(content_id); | 140 DCHECK(content_id); |
| 141 | 141 |
| 142 auto it = | 142 auto it = |
| 143 std::find_if(unused_resources_.begin(), unused_resources_.end(), | 143 std::find_if(unused_resources_.begin(), unused_resources_.end(), |
| 144 [content_id](const scoped_ptr<PoolResource>& pool_resource) { | 144 [content_id](const scoped_ptr<PoolResource>& pool_resource) { |
| 145 return pool_resource->content_id() == content_id; | 145 return pool_resource->content_id() == content_id; |
| 146 }); | 146 }); |
| 147 if (it == unused_resources_.end()) | 147 if (it == unused_resources_.end()) |
| 148 return nullptr; | 148 return nullptr; |
| 149 | 149 |
| 150 Resource* resource = it->get(); | 150 Resource* resource = it->get(); |
| 151 DCHECK(resource_provider_->CanLockForWrite(resource->id())); | 151 DCHECK(resource_provider_->CanLockForWrite(resource->id())); |
| 152 | 152 |
| 153 // Transfer resource to |in_use_resources_|. | 153 // Transfer resource to |in_use_resources_|. |
| 154 in_use_resources_.set(resource->id(), it->Pass()); | 154 in_use_resources_[resource->id()] = it->Pass(); |
| 155 unused_resources_.erase(it); | 155 unused_resources_.erase(it); |
| 156 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( | 156 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( |
| 157 resource->size(), resource->format()); | 157 resource->size(), resource->format()); |
| 158 return resource; | 158 return resource; |
| 159 } | 159 } |
| 160 | 160 |
| 161 void ResourcePool::ReleaseResource(Resource* resource, uint64_t content_id) { | 161 void ResourcePool::ReleaseResource(Resource* resource, uint64_t content_id) { |
| 162 auto it = in_use_resources_.find(resource->id()); | 162 auto it = in_use_resources_.find(resource->id()); |
| 163 DCHECK(it != in_use_resources_.end()); | 163 DCHECK(it != in_use_resources_.end()); |
| 164 | 164 |
| 165 PoolResource* pool_resource = it->second; | 165 PoolResource* pool_resource = it->second.get(); |
| 166 pool_resource->set_content_id(content_id); | 166 pool_resource->set_content_id(content_id); |
| 167 pool_resource->set_last_usage(base::TimeTicks::Now()); | 167 pool_resource->set_last_usage(base::TimeTicks::Now()); |
| 168 | 168 |
| 169 // Transfer resource to |busy_resources_|. | 169 // Transfer resource to |busy_resources_|. |
| 170 busy_resources_.push_front(in_use_resources_.take_and_erase(it)); | 170 //busy_resources_.push_front(in_use_resources_.take_and_erase(it)); |
| 171 scoped_ptr<PoolResource> my_resource = it->second.Pass(); | |
|
limasdf
2015/11/19 13:48:51
take_and_erase() returns scoped_ptr and erase iter
Matt Giuca
2015/11/19 23:42:26
This code can be simplified. The above code gets a
Matt Giuca
2015/11/19 23:42:26
What do you mean it doesn't work? (I patched your
limasdf
2015/11/20 15:20:04
Sorry. Because of trybot fail, I was thinking ther
limasdf
2015/11/20 15:20:05
On line#175, |pool_resource| is being used, so kee
Matt Giuca
2015/11/23 02:17:49
Acknowledged.
| |
| 172 in_use_resources_.erase(it); | |
| 173 busy_resources_.push_front(std::move(my_resource)); | |
| 171 in_use_memory_usage_bytes_ -= ResourceUtil::UncheckedSizeInBytes<size_t>( | 174 in_use_memory_usage_bytes_ -= ResourceUtil::UncheckedSizeInBytes<size_t>( |
| 172 pool_resource->size(), pool_resource->format()); | 175 pool_resource->size(), pool_resource->format()); |
| 173 | 176 |
| 174 // Now that we have evictable resources, schedule an eviction call for this | 177 // Now that we have evictable resources, schedule an eviction call for this |
| 175 // resource if necessary. | 178 // resource if necessary. |
| 176 ScheduleEvictExpiredResourcesIn(resource_expiration_delay_); | 179 ScheduleEvictExpiredResourcesIn(resource_expiration_delay_); |
| 177 } | 180 } |
| 178 | 181 |
| 179 void ResourcePool::SetResourceUsageLimits(size_t max_memory_usage_bytes, | 182 void ResourcePool::SetResourceUsageLimits(size_t max_memory_usage_bytes, |
| 180 size_t max_resource_count) { | 183 size_t max_resource_count) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 for (const auto& resource : busy_resources_) { | 312 for (const auto& resource : busy_resources_) { |
| 310 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); | 313 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); |
| 311 } | 314 } |
| 312 for (const auto& entry : in_use_resources_) { | 315 for (const auto& entry : in_use_resources_) { |
| 313 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); | 316 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); |
| 314 } | 317 } |
| 315 return true; | 318 return true; |
| 316 } | 319 } |
| 317 | 320 |
| 318 } // namespace cc | 321 } // namespace cc |
| OLD | NEW |