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

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

Issue 1410833005: Test multideque (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@resource_evict_fix
Patch Set: Erased resource once found and updated test littlebit. Created 5 years 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 | « no previous file | cc/resources/resource_pool_unittest.cc » ('j') | 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 DCHECK_EQ(0u, in_use_memory_usage_bytes_); 87 DCHECK_EQ(0u, in_use_memory_usage_bytes_);
88 DCHECK_EQ(0u, total_memory_usage_bytes_); 88 DCHECK_EQ(0u, total_memory_usage_bytes_);
89 DCHECK_EQ(0u, total_resource_count_); 89 DCHECK_EQ(0u, total_resource_count_);
90 } 90 }
91 91
92 Resource* ResourcePool::AcquireResource(const gfx::Size& size, 92 Resource* ResourcePool::AcquireResource(const gfx::Size& size,
93 ResourceFormat format) { 93 ResourceFormat format) {
94 // Finding resources in |unused_resources_| from MRU to LRU direction, touches 94 // Finding resources in |unused_resources_| from MRU to LRU direction, touches
95 // LRU resources only if needed, which increases possibility of expiring more 95 // LRU resources only if needed, which increases possibility of expiring more
96 // LRU resources within kResourceExpirationDelayMs. 96 // LRU resources within kResourceExpirationDelayMs.
97 for (ResourceDeque::iterator it = unused_resources_.begin(); 97 {
98 it != unused_resources_.end(); ++it) { 98 TRACE_EVENT1("cc, pras", "ResourcePool::AcquireResource", "total_unused",
99 ScopedResource* resource = *it; 99 unused_resources_.size());
100 DCHECK(resource_provider_->CanLockForWrite(resource->id()));
101 100
102 if (resource->format() != format) 101 for (ResourceDeque::iterator it = unused_resources_.begin();
103 continue; 102 it != unused_resources_.end(); ++it) {
104 if (resource->size() != size) 103 ScopedResource* resource = *it;
105 continue; 104 DCHECK(resource_provider_->CanLockForWrite(resource->id()));
106 105
107 // Transfer resource to |in_use_resources_|. 106 if (resource->format() != format)
108 in_use_resources_.set(resource->id(), unused_resources_.take(it)); 107 continue;
109 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( 108 if (resource->size() != size)
110 resource->size(), resource->format()); 109 continue;
111 return resource; 110
111 // Transfer resource to |in_use_resources_|.
112 in_use_resources_.set(resource->id(), unused_resources_.take(it));
113 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>(
114 resource->size(), resource->format());
115 return resource;
116 }
112 } 117 }
113 118
114 scoped_ptr<PoolResource> pool_resource = 119 scoped_ptr<PoolResource> pool_resource =
115 PoolResource::Create(resource_provider_); 120 PoolResource::Create(resource_provider_);
116 GLenum target = 121 GLenum target =
117 target_ ? target_ : resource_provider_->GetImageTextureTarget(format); 122 target_ ? target_ : resource_provider_->GetImageTextureTarget(format);
118 pool_resource->AllocateManaged(size, target, format); 123 pool_resource->AllocateManaged(size, target, format);
119 124
120 DCHECK(ResourceUtil::VerifySizeInBytes<size_t>(pool_resource->size(), 125 DCHECK(ResourceUtil::VerifySizeInBytes<size_t>(pool_resource->size(),
121 pool_resource->format())); 126 pool_resource->format()));
122 total_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( 127 total_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>(
123 pool_resource->size(), pool_resource->format()); 128 pool_resource->size(), pool_resource->format());
124 ++total_resource_count_; 129 ++total_resource_count_;
125 130
126 Resource* resource = pool_resource.get(); 131 Resource* resource = pool_resource.get();
127 in_use_resources_.set(resource->id(), pool_resource.Pass()); 132 in_use_resources_.set(resource->id(), pool_resource.Pass());
128 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( 133 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>(
129 resource->size(), resource->format()); 134 resource->size(), resource->format());
130 return resource; 135 return resource;
131 } 136 }
132 137
133 Resource* ResourcePool::TryAcquireResourceWithContentId(uint64_t content_id) { 138 Resource* ResourcePool::TryAcquireResourceWithContentId(uint64_t content_id) {
134 DCHECK(content_id); 139 DCHECK(content_id);
135 140
141 TRACE_EVENT_BEGIN1("cc, pras", "ResourcePool::TryAcquireResource",
142 "total_unused", unused_resources_.size());
143
136 auto it = std::find_if(unused_resources_.begin(), unused_resources_.end(), 144 auto it = std::find_if(unused_resources_.begin(), unused_resources_.end(),
137 [content_id](const PoolResource* pool_resource) { 145 [content_id](const PoolResource* pool_resource) {
138 return pool_resource->content_id() == content_id; 146 return pool_resource->content_id() == content_id;
139 }); 147 });
148
149 TRACE_EVENT_END0("cc, pras", "ResourcePool::TryAcquireResource");
150
140 if (it == unused_resources_.end()) 151 if (it == unused_resources_.end())
141 return nullptr; 152 return nullptr;
142 153
143 Resource* resource = *it; 154 Resource* resource = *it;
144 DCHECK(resource_provider_->CanLockForWrite(resource->id())); 155 DCHECK(resource_provider_->CanLockForWrite(resource->id()));
145 156
146 // Transfer resource to |in_use_resources_|. 157 // Transfer resource to |in_use_resources_|.
147 in_use_resources_.set(resource->id(), unused_resources_.take(it)); 158 in_use_resources_.set(resource->id(), unused_resources_.take(it));
148 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( 159 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>(
149 resource->size(), resource->format()); 160 resource->size(), resource->format());
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } else if (resource_provider_->IsLost(resource->id())) { 228 } else if (resource_provider_->IsLost(resource->id())) {
218 // Remove lost resources from pool. 229 // Remove lost resources from pool.
219 DeleteResource(busy_resources_.take(it)); 230 DeleteResource(busy_resources_.take(it));
220 } else { 231 } else {
221 ++i; 232 ++i;
222 } 233 }
223 } 234 }
224 } 235 }
225 236
226 void ResourcePool::DidFinishUsingResource(scoped_ptr<PoolResource> resource) { 237 void ResourcePool::DidFinishUsingResource(scoped_ptr<PoolResource> resource) {
238 TRACE_EVENT0("cc, pras", "ResourcePool::DidFinishUsingResource");
227 unused_resources_.push_front(resource.Pass()); 239 unused_resources_.push_front(resource.Pass());
228 } 240 }
229 241
230 void ResourcePool::ScheduleEvictExpiredResourcesIn( 242 void ResourcePool::ScheduleEvictExpiredResourcesIn(
231 base::TimeDelta time_from_now) { 243 base::TimeDelta time_from_now) {
232 if (evict_expired_resources_pending_) 244 if (evict_expired_resources_pending_)
233 return; 245 return;
234 246
235 evict_expired_resources_pending_ = true; 247 evict_expired_resources_pending_ = true;
236 248
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 for (const auto& resource : busy_resources_) { 311 for (const auto& resource : busy_resources_) {
300 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); 312 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */);
301 } 313 }
302 for (const auto& entry : in_use_resources_) { 314 for (const auto& entry : in_use_resources_) {
303 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); 315 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */);
304 } 316 }
305 return true; 317 return true;
306 } 318 }
307 319
308 } // namespace cc 320 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/resources/resource_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698