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

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

Issue 43753002: cc: Keep track of busy resources in ResourcePool (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: cc: Keep track of busy resources in ResourcePool Created 7 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') | cc/resources/tile_manager.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 "cc/resources/resource_provider.h" 7 #include "cc/resources/resource_provider.h"
8 8
9 namespace cc { 9 namespace cc {
10 10
(...skipping 30 matching lines...) Expand all
41 ResourcePool::~ResourcePool() { 41 ResourcePool::~ResourcePool() {
42 SetResourceUsageLimits(0, 0, 0); 42 SetResourceUsageLimits(0, 0, 0);
43 } 43 }
44 44
45 scoped_ptr<ResourcePool::Resource> ResourcePool::AcquireResource( 45 scoped_ptr<ResourcePool::Resource> ResourcePool::AcquireResource(
46 gfx::Size size, ResourceFormat format) { 46 gfx::Size size, ResourceFormat format) {
47 for (ResourceList::iterator it = unused_resources_.begin(); 47 for (ResourceList::iterator it = unused_resources_.begin();
48 it != unused_resources_.end(); ++it) { 48 it != unused_resources_.end(); ++it) {
49 Resource* resource = *it; 49 Resource* resource = *it;
50 50
51 if (!resource_provider_->CanLockForWrite(resource->id()))
52 continue;
53 if (resource->size() != size) 51 if (resource->size() != size)
54 continue; 52 continue;
55 if (resource->format() != format) 53 if (resource->format() != format)
56 continue; 54 continue;
57 55
58 unused_resources_.erase(it); 56 unused_resources_.erase(it);
59 unused_memory_usage_bytes_ -= resource->bytes(); 57 unused_memory_usage_bytes_ -= resource->bytes();
60 return make_scoped_ptr(resource); 58 return make_scoped_ptr(resource);
61 } 59 }
62 60
63 // Create new resource. 61 // Create new resource.
64 Resource* resource = new Resource(resource_provider_, size, format); 62 Resource* resource = new Resource(resource_provider_, size, format);
65 63
66 // Extend all read locks on all resources until the resource is 64 // Extend all read locks on all resources until the resource is
67 // finished being used, such that we know when resources are 65 // finished being used, such that we know when resources are
68 // truly safe to recycle. 66 // truly safe to recycle.
69 resource_provider_->EnableReadLockFences(resource->id(), true); 67 resource_provider_->EnableReadLockFences(resource->id(), true);
70 68
71 memory_usage_bytes_ += resource->bytes(); 69 memory_usage_bytes_ += resource->bytes();
72 ++resource_count_; 70 ++resource_count_;
73 return make_scoped_ptr(resource); 71 return make_scoped_ptr(resource);
74 } 72 }
75 73
76 void ResourcePool::ReleaseResource( 74 void ResourcePool::ReleaseResource(
77 scoped_ptr<ResourcePool::Resource> resource) { 75 scoped_ptr<ResourcePool::Resource> resource) {
78 if (ResourceUsageTooHigh()) {
79 memory_usage_bytes_ -= resource->bytes();
80 --resource_count_;
81 return;
82 }
83
84 unused_memory_usage_bytes_ += resource->bytes(); 76 unused_memory_usage_bytes_ += resource->bytes();
85 unused_resources_.push_back(resource.release()); 77 busy_resources_.push_back(resource.release());
86 } 78 }
87 79
88 void ResourcePool::SetResourceUsageLimits( 80 void ResourcePool::SetResourceUsageLimits(
89 size_t max_memory_usage_bytes, 81 size_t max_memory_usage_bytes,
90 size_t max_unused_memory_usage_bytes, 82 size_t max_unused_memory_usage_bytes,
91 size_t max_resource_count) { 83 size_t max_resource_count) {
92 max_memory_usage_bytes_ = max_memory_usage_bytes; 84 max_memory_usage_bytes_ = max_memory_usage_bytes;
93 max_unused_memory_usage_bytes_ = max_unused_memory_usage_bytes; 85 max_unused_memory_usage_bytes_ = max_unused_memory_usage_bytes;
94 max_resource_count_ = max_resource_count; 86 max_resource_count_ = max_resource_count;
95 87
(...skipping 24 matching lines...) Expand all
120 bool ResourcePool::ResourceUsageTooHigh() { 112 bool ResourcePool::ResourceUsageTooHigh() {
121 if (resource_count_ > max_resource_count_) 113 if (resource_count_ > max_resource_count_)
122 return true; 114 return true;
123 if (memory_usage_bytes_ > max_memory_usage_bytes_) 115 if (memory_usage_bytes_ > max_memory_usage_bytes_)
124 return true; 116 return true;
125 if (unused_memory_usage_bytes_ > max_unused_memory_usage_bytes_) 117 if (unused_memory_usage_bytes_ > max_unused_memory_usage_bytes_)
126 return true; 118 return true;
127 return false; 119 return false;
128 } 120 }
129 121
122 void ResourcePool::CheckBusyResources() {
123 ResourceList::iterator it = busy_resources_.begin();
124
125 while (it != busy_resources_.end()) {
126 Resource* resource = *it;
127
128 if (resource_provider_->CanLockForWrite(resource->id())) {
129 unused_resources_.push_back(resource);
130 it = busy_resources_.erase(it);
131 } else {
132 ++it;
133 }
134 }
135
136 ReduceResourceUsage();
reveman 2013/11/01 15:59:40 nit: I don't think we need to call ReduceResourceU
137 }
138
130 } // namespace cc 139 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_pool.h ('k') | cc/resources/tile_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698