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

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

Issue 817133006: Support different formats in the same resource pool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove ResourceFormatUsage Created 5 years, 11 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/scoped_resource.h" 8 #include "cc/resources/scoped_resource.h"
9 9
10 namespace cc { 10 namespace cc {
11 11
12 ResourcePool::ResourcePool(ResourceProvider* resource_provider, 12 ResourcePool::ResourcePool(ResourceProvider* resource_provider,
13 GLenum target, 13 GLenum target,
14 ResourceFormat format) 14 bool use_memory_efficient_format)
15 : resource_provider_(resource_provider), 15 : resource_provider_(resource_provider),
16 target_(target), 16 target_(target),
17 format_(format), 17 use_memory_efficient_format_(use_memory_efficient_format),
18 max_memory_usage_bytes_(0), 18 max_memory_usage_bytes_(0),
19 max_unused_memory_usage_bytes_(0), 19 max_unused_memory_usage_bytes_(0),
20 max_resource_count_(0), 20 max_resource_count_(0),
21 memory_usage_bytes_(0), 21 memory_usage_bytes_(0),
22 unused_memory_usage_bytes_(0), 22 unused_memory_usage_bytes_(0),
23 resource_count_(0) {} 23 resource_count_(0) {}
24 24
25 ResourcePool::~ResourcePool() { 25 ResourcePool::~ResourcePool() {
26 while (!busy_resources_.empty()) { 26 while (!busy_resources_.empty()) {
27 DidFinishUsingResource(busy_resources_.front()); 27 DidFinishUsingResource(busy_resources_.front());
28 busy_resources_.pop_front(); 28 busy_resources_.pop_front();
29 } 29 }
30 30
31 SetResourceUsageLimits(0, 0, 0); 31 SetResourceUsageLimits(0, 0, 0);
32 DCHECK_EQ(0u, unused_resources_.size()); 32 DCHECK_EQ(0u, unused_resources_.size());
33 DCHECK_EQ(0u, memory_usage_bytes_); 33 DCHECK_EQ(0u, memory_usage_bytes_);
34 DCHECK_EQ(0u, unused_memory_usage_bytes_); 34 DCHECK_EQ(0u, unused_memory_usage_bytes_);
35 DCHECK_EQ(0u, resource_count_); 35 DCHECK_EQ(0u, resource_count_);
36 } 36 }
37 37
38 scoped_ptr<ScopedResource> ResourcePool::AcquireResource( 38 scoped_ptr<ScopedResource> ResourcePool::AcquireResource(
39 const gfx::Size& size) { 39 const gfx::Size& size, ResourceFormat format) {
40 for (ResourceList::iterator it = unused_resources_.begin(); 40 for (ResourceList::iterator it = unused_resources_.begin();
41 it != unused_resources_.end(); 41 it != unused_resources_.end();
42 ++it) { 42 ++it) {
43 ScopedResource* resource = *it; 43 ScopedResource* resource = *it;
44 DCHECK(resource_provider_->CanLockForWrite(resource->id())); 44 DCHECK(resource_provider_->CanLockForWrite(resource->id()));
45 45
46 if (resource->format() != format)
47 continue;
46 if (resource->size() != size) 48 if (resource->size() != size)
47 continue; 49 continue;
48 50
49 unused_resources_.erase(it); 51 unused_resources_.erase(it);
50 unused_memory_usage_bytes_ -= resource->bytes(); 52 unused_memory_usage_bytes_ -= resource->bytes();
51 return make_scoped_ptr(resource); 53 return make_scoped_ptr(resource);
52 } 54 }
53 55
54 scoped_ptr<ScopedResource> resource = 56 scoped_ptr<ScopedResource> resource =
55 ScopedResource::Create(resource_provider_); 57 ScopedResource::Create(resource_provider_);
56 resource->AllocateManaged(size, target_, format_); 58 resource->AllocateManaged(size, target_, format);
57 59
58 memory_usage_bytes_ += resource->bytes(); 60 memory_usage_bytes_ += resource->bytes();
59 ++resource_count_; 61 ++resource_count_;
60 return resource.Pass(); 62 return resource.Pass();
61 } 63 }
62 64
65 scoped_ptr<ScopedResource> ResourcePool::AcquireResource(
66 const gfx::Size& size) {
67 return AcquireResource(size, resource_format());
68 }
69
63 void ResourcePool::ReleaseResource(scoped_ptr<ScopedResource> resource) { 70 void ResourcePool::ReleaseResource(scoped_ptr<ScopedResource> resource) {
64 busy_resources_.push_back(resource.release()); 71 busy_resources_.push_back(resource.release());
65 } 72 }
66 73
67 void ResourcePool::SetResourceUsageLimits(size_t max_memory_usage_bytes, 74 void ResourcePool::SetResourceUsageLimits(size_t max_memory_usage_bytes,
68 size_t max_unused_memory_usage_bytes, 75 size_t max_unused_memory_usage_bytes,
69 size_t max_resource_count) { 76 size_t max_resource_count) {
70 max_memory_usage_bytes_ = max_memory_usage_bytes; 77 max_memory_usage_bytes_ = max_memory_usage_bytes;
71 max_unused_memory_usage_bytes_ = max_unused_memory_usage_bytes; 78 max_unused_memory_usage_bytes_ = max_unused_memory_usage_bytes;
72 max_resource_count_ = max_resource_count; 79 max_resource_count_ = max_resource_count;
(...skipping 25 matching lines...) Expand all
98 bool ResourcePool::ResourceUsageTooHigh() { 105 bool ResourcePool::ResourceUsageTooHigh() {
99 if (resource_count_ > max_resource_count_) 106 if (resource_count_ > max_resource_count_)
100 return true; 107 return true;
101 if (memory_usage_bytes_ > max_memory_usage_bytes_) 108 if (memory_usage_bytes_ > max_memory_usage_bytes_)
102 return true; 109 return true;
103 if (unused_memory_usage_bytes_ > max_unused_memory_usage_bytes_) 110 if (unused_memory_usage_bytes_ > max_unused_memory_usage_bytes_)
104 return true; 111 return true;
105 return false; 112 return false;
106 } 113 }
107 114
115 ResourceFormat ResourcePool::resource_format() const {
116 if (use_memory_efficient_format_) {
reveman 2015/01/15 16:33:11 I would prefer if all format decisions are made by
peterp 2015/01/16 12:10:11 Ok, I've removed this logic and changed the pool t
117 return resource_provider_->memory_efficient_texture_format();
118 } else {
119 return resource_provider_->best_texture_format();
120 }
121 }
122
108 void ResourcePool::CheckBusyResources(bool wait_if_needed) { 123 void ResourcePool::CheckBusyResources(bool wait_if_needed) {
109 ResourceList::iterator it = busy_resources_.begin(); 124 ResourceList::iterator it = busy_resources_.begin();
110 125
111 while (it != busy_resources_.end()) { 126 while (it != busy_resources_.end()) {
112 ScopedResource* resource = *it; 127 ScopedResource* resource = *it;
113 128
114 if (wait_if_needed) 129 if (wait_if_needed)
115 resource_provider_->WaitReadLockIfNeeded(resource->id()); 130 resource_provider_->WaitReadLockIfNeeded(resource->id());
116 131
117 if (resource_provider_->CanLockForWrite(resource->id())) { 132 if (resource_provider_->CanLockForWrite(resource->id())) {
118 DidFinishUsingResource(resource); 133 DidFinishUsingResource(resource);
119 it = busy_resources_.erase(it); 134 it = busy_resources_.erase(it);
120 } else { 135 } else {
121 ++it; 136 ++it;
122 } 137 }
123 } 138 }
124 } 139 }
125 140
126 void ResourcePool::DidFinishUsingResource(ScopedResource* resource) { 141 void ResourcePool::DidFinishUsingResource(ScopedResource* resource) {
127 unused_memory_usage_bytes_ += resource->bytes(); 142 unused_memory_usage_bytes_ += resource->bytes();
128 unused_resources_.push_back(resource); 143 unused_resources_.push_back(resource);
129 } 144 }
130 145
131 } // namespace cc 146 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698