Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: cc/resources/resource_pool.cc

Issue 1462763002: Remove ScopedPtrMap from /cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Matt's review Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/resources/resource_pool.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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()] = std::move(*it);
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()] = std::move(*it);
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(std::move(it->second));
171 in_use_resources_.erase(it);
171 in_use_memory_usage_bytes_ -= ResourceUtil::UncheckedSizeInBytes<size_t>( 172 in_use_memory_usage_bytes_ -= ResourceUtil::UncheckedSizeInBytes<size_t>(
172 pool_resource->size(), pool_resource->format()); 173 pool_resource->size(), pool_resource->format());
173 174
174 // Now that we have evictable resources, schedule an eviction call for this 175 // Now that we have evictable resources, schedule an eviction call for this
175 // resource if necessary. 176 // resource if necessary.
176 ScheduleEvictExpiredResourcesIn(resource_expiration_delay_); 177 ScheduleEvictExpiredResourcesIn(resource_expiration_delay_);
177 } 178 }
178 179
179 void ResourcePool::SetResourceUsageLimits(size_t max_memory_usage_bytes, 180 void ResourcePool::SetResourceUsageLimits(size_t max_memory_usage_bytes,
180 size_t max_resource_count) { 181 size_t max_resource_count) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 for (const auto& resource : busy_resources_) { 310 for (const auto& resource : busy_resources_) {
310 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); 311 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */);
311 } 312 }
312 for (const auto& entry : in_use_resources_) { 313 for (const auto& entry : in_use_resources_) {
313 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); 314 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */);
314 } 315 }
315 return true; 316 return true;
316 } 317 }
317 318
318 } // namespace cc 319 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_pool.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698