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

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

Issue 1420433009: cc: Keep most recently used resources at the front of resource queue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments. 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
« cc/resources/resource_pool.h ('K') | « 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 SetResourceUsageLimits(0, 0); 85 SetResourceUsageLimits(0, 0);
86 DCHECK_EQ(0u, unused_resources_.size()); 86 DCHECK_EQ(0u, unused_resources_.size());
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 for (ResourceDeque::iterator it = unused_resources_.begin(); 94 // Traverse the |unused_resources_| from rear end as MRU resources are
95 it != unused_resources_.end(); ++it) { 95 // held at the rear end of the queue. This touches LRU resources only if
96 ScopedResource* resource = *it; 96 // needed, which inreases possibility of expiring more LRU resources
97 // within kResourceExpirationDelayMs.
98 for (ResourceDeque::reverse_iterator rit = unused_resources_.rbegin();
99 rit != unused_resources_.rend(); ++rit) {
100 ScopedResource* resource = *rit;
97 DCHECK(resource_provider_->CanLockForWrite(resource->id())); 101 DCHECK(resource_provider_->CanLockForWrite(resource->id()));
98 102
99 if (resource->format() != format) 103 if (resource->format() != format)
100 continue; 104 continue;
101 if (resource->size() != size) 105 if (resource->size() != size)
102 continue; 106 continue;
103 107
108 // Get iterator from reverse_iterator pointing to the same resource.
109 ResourceDeque::iterator it =
110 static_cast<ResourceDeque::iterator>(--rit.base());
reveman 2015/11/02 06:07:51 if we need this then can we add a base() function
prashant.n 2015/11/02 17:56:45 IMO, iterators are different, so typecast would be
104 // Transfer resource to |in_use_resources_|. 111 // Transfer resource to |in_use_resources_|.
105 in_use_resources_.set(resource->id(), unused_resources_.take(it)); 112 in_use_resources_.set(resource->id(), unused_resources_.take(it));
106 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( 113 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>(
107 resource->size(), resource->format()); 114 resource->size(), resource->format());
108 return resource; 115 return resource;
109 } 116 }
110 117
111 scoped_ptr<PoolResource> pool_resource = 118 scoped_ptr<PoolResource> pool_resource =
112 PoolResource::Create(resource_provider_); 119 PoolResource::Create(resource_provider_);
113 GLenum target = 120 GLenum target =
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 for (const auto& resource : busy_resources_) { 303 for (const auto& resource : busy_resources_) {
297 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); 304 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */);
298 } 305 }
299 for (const auto& entry : in_use_resources_) { 306 for (const auto& entry : in_use_resources_) {
300 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); 307 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */);
301 } 308 }
302 return true; 309 return true;
303 } 310 }
304 311
305 } // namespace cc 312 } // namespace cc
OLDNEW
« cc/resources/resource_pool.h ('K') | « cc/resources/resource_pool.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698