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

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

Issue 1202843008: cc: Fix BytesPerPixel issue and refactor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Corrected comments. Created 5 years, 5 months 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
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 #include "cc/resources/resource_util.h"
8 #include "cc/resources/scoped_resource.h" 9 #include "cc/resources/scoped_resource.h"
9 10
10 namespace cc { 11 namespace cc {
11 12
12 ResourcePool::ResourcePool(ResourceProvider* resource_provider, GLenum target) 13 ResourcePool::ResourcePool(ResourceProvider* resource_provider, GLenum target)
13 : resource_provider_(resource_provider), 14 : resource_provider_(resource_provider),
14 target_(target), 15 target_(target),
15 max_memory_usage_bytes_(0), 16 max_memory_usage_bytes_(0),
16 max_unused_memory_usage_bytes_(0), 17 max_unused_memory_usage_bytes_(0),
17 max_resource_count_(0), 18 max_resource_count_(0),
(...skipping 23 matching lines...) Expand all
41 ScopedResource* resource = it->resource; 42 ScopedResource* resource = it->resource;
42 DCHECK(resource_provider_->CanLockForWrite(resource->id())); 43 DCHECK(resource_provider_->CanLockForWrite(resource->id()));
43 44
44 if (resource->format() != format) 45 if (resource->format() != format)
45 continue; 46 continue;
46 if (resource->size() != size) 47 if (resource->size() != size)
47 continue; 48 continue;
48 49
49 unused_resources_.erase(it); 50 unused_resources_.erase(it);
50 unused_memory_usage_bytes_ -= 51 unused_memory_usage_bytes_ -=
51 Resource::UncheckedMemorySizeBytes(size, format); 52 ResourceUtil::UncheckedSizeInBytes(size, format);
52 return make_scoped_ptr(resource); 53 return make_scoped_ptr(resource);
53 } 54 }
54 55
55 scoped_ptr<ScopedResource> resource = 56 scoped_ptr<ScopedResource> resource =
56 ScopedResource::Create(resource_provider_); 57 ScopedResource::Create(resource_provider_);
57 resource->AllocateManaged(size, target_, format); 58 resource->AllocateManaged(size, target_, format);
58 59
59 DCHECK(Resource::VerifySizeInBytes(resource->size(), resource->format())); 60 DCHECK(ResourceUtil::VerifySizeInBytes(resource->size(), resource->format()));
60 memory_usage_bytes_ += 61 memory_usage_bytes_ +=
61 Resource::UncheckedMemorySizeBytes(resource->size(), resource->format()); 62 ResourceUtil::UncheckedSizeInBytes(resource->size(), resource->format());
62 ++resource_count_; 63 ++resource_count_;
63 return resource.Pass(); 64 return resource.Pass();
64 } 65 }
65 66
66 scoped_ptr<ScopedResource> ResourcePool::TryAcquireResourceWithContentId( 67 scoped_ptr<ScopedResource> ResourcePool::TryAcquireResourceWithContentId(
67 uint64_t content_id) { 68 uint64_t content_id) {
68 DCHECK(content_id); 69 DCHECK(content_id);
69 70
70 auto it = std::find_if(unused_resources_.begin(), unused_resources_.end(), 71 auto it = std::find_if(unused_resources_.begin(), unused_resources_.end(),
71 [content_id](const PoolResource& pool_resource) { 72 [content_id](const PoolResource& pool_resource) {
72 return pool_resource.content_id == content_id; 73 return pool_resource.content_id == content_id;
73 }); 74 });
74 if (it == unused_resources_.end()) 75 if (it == unused_resources_.end())
75 return nullptr; 76 return nullptr;
76 77
77 ScopedResource* resource = it->resource; 78 ScopedResource* resource = it->resource;
78 DCHECK(resource_provider_->CanLockForWrite(resource->id())); 79 DCHECK(resource_provider_->CanLockForWrite(resource->id()));
79 80
80 unused_resources_.erase(it); 81 unused_resources_.erase(it);
81 unused_memory_usage_bytes_ -= 82 unused_memory_usage_bytes_ -=
82 Resource::UncheckedMemorySizeBytes(resource->size(), resource->format()); 83 ResourceUtil::UncheckedSizeInBytes(resource->size(), resource->format());
83 return make_scoped_ptr(resource); 84 return make_scoped_ptr(resource);
84 } 85 }
85 86
86 void ResourcePool::ReleaseResource(scoped_ptr<ScopedResource> resource, 87 void ResourcePool::ReleaseResource(scoped_ptr<ScopedResource> resource,
87 uint64_t content_id) { 88 uint64_t content_id) {
88 busy_resources_.push_back(PoolResource(resource.release(), content_id)); 89 busy_resources_.push_back(PoolResource(resource.release(), content_id));
89 } 90 }
90 91
91 void ResourcePool::SetResourceUsageLimits(size_t max_memory_usage_bytes, 92 void ResourcePool::SetResourceUsageLimits(size_t max_memory_usage_bytes,
92 size_t max_unused_memory_usage_bytes, 93 size_t max_unused_memory_usage_bytes,
(...skipping 12 matching lines...) Expand all
105 106
106 // LRU eviction pattern. Most recently used might be blocked by 107 // LRU eviction pattern. Most recently used might be blocked by
107 // a read lock fence but it's still better to evict the least 108 // a read lock fence but it's still better to evict the least
108 // recently used as it prevents a resource that is hard to reuse 109 // recently used as it prevents a resource that is hard to reuse
109 // because of unique size from being kept around. Resources that 110 // because of unique size from being kept around. Resources that
110 // can't be locked for write might also not be truly free-able. 111 // can't be locked for write might also not be truly free-able.
111 // We can free the resource here but it doesn't mean that the 112 // We can free the resource here but it doesn't mean that the
112 // memory is necessarily returned to the OS. 113 // memory is necessarily returned to the OS.
113 ScopedResource* resource = unused_resources_.front().resource; 114 ScopedResource* resource = unused_resources_.front().resource;
114 unused_resources_.pop_front(); 115 unused_resources_.pop_front();
115 size_t resource_bytes = Resource::UncheckedMemorySizeBytes( 116 size_t resource_bytes = ResourceUtil::UncheckedSizeInBytes(
116 resource->size(), resource->format()); 117 resource->size(), resource->format());
117 memory_usage_bytes_ -= resource_bytes; 118 memory_usage_bytes_ -= resource_bytes;
118 unused_memory_usage_bytes_ -= resource_bytes; 119 unused_memory_usage_bytes_ -= resource_bytes;
119 --resource_count_; 120 --resource_count_;
120 delete resource; 121 delete resource;
121 } 122 }
122 } 123 }
123 124
124 bool ResourcePool::ResourceUsageTooHigh() { 125 bool ResourcePool::ResourceUsageTooHigh() {
125 if (resource_count_ > max_resource_count_) 126 if (resource_count_ > max_resource_count_)
(...skipping 19 matching lines...) Expand all
145 it = busy_resources_.erase(it); 146 it = busy_resources_.erase(it);
146 } else { 147 } else {
147 ++it; 148 ++it;
148 } 149 }
149 } 150 }
150 } 151 }
151 152
152 void ResourcePool::DidFinishUsingResource(ScopedResource* resource, 153 void ResourcePool::DidFinishUsingResource(ScopedResource* resource,
153 uint64_t content_id) { 154 uint64_t content_id) {
154 unused_memory_usage_bytes_ += 155 unused_memory_usage_bytes_ +=
155 Resource::UncheckedMemorySizeBytes(resource->size(), resource->format()); 156 ResourceUtil::UncheckedSizeInBytes(resource->size(), resource->format());
156 unused_resources_.push_back(PoolResource(resource, content_id)); 157 unused_resources_.push_back(PoolResource(resource, content_id));
157 } 158 }
158 159
159 } // namespace cc 160 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698