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

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

Issue 83883002: cc: Allow TEXTURE_RECTANGLE_ARB to be used for tile textures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review feedback 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 | Annotate | Revision Log
« no previous file with comments | « cc/resources/resource_pool.h ('k') | cc/resources/resource_provider.h » ('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
11 ResourcePool::Resource::Resource(cc::ResourceProvider* resource_provider, 11 ResourcePool::Resource::Resource(cc::ResourceProvider* resource_provider,
12 gfx::Size size, 12 gfx::Size size,
13 GLenum target,
13 ResourceFormat format) 14 ResourceFormat format)
14 : cc::Resource(resource_provider->CreateManagedResource( 15 : cc::Resource(resource_provider->CreateManagedResource(
15 size, 16 size,
17 target,
16 GL_CLAMP_TO_EDGE, 18 GL_CLAMP_TO_EDGE,
17 ResourceProvider::TextureUsageAny, 19 ResourceProvider::TextureUsageAny,
18 format), 20 format),
19 size, 21 size,
20 format), 22 format),
21 resource_provider_(resource_provider) { 23 resource_provider_(resource_provider) {
22 DCHECK(id()); 24 DCHECK(id());
23 } 25 }
24 26
25 ResourcePool::Resource::~Resource() { 27 ResourcePool::Resource::~Resource() {
26 DCHECK(id()); 28 DCHECK(id());
27 DCHECK(resource_provider_); 29 DCHECK(resource_provider_);
28 resource_provider_->DeleteResource(id()); 30 resource_provider_->DeleteResource(id());
29 } 31 }
30 32
31 ResourcePool::ResourcePool(ResourceProvider* resource_provider) 33 ResourcePool::ResourcePool(ResourceProvider* resource_provider,
34 GLenum target,
35 ResourceFormat format)
32 : resource_provider_(resource_provider), 36 : resource_provider_(resource_provider),
37 target_(target),
38 format_(format),
33 max_memory_usage_bytes_(0), 39 max_memory_usage_bytes_(0),
34 max_unused_memory_usage_bytes_(0), 40 max_unused_memory_usage_bytes_(0),
35 max_resource_count_(0), 41 max_resource_count_(0),
36 memory_usage_bytes_(0), 42 memory_usage_bytes_(0),
37 unused_memory_usage_bytes_(0), 43 unused_memory_usage_bytes_(0),
38 resource_count_(0) { 44 resource_count_(0) {
39 } 45 }
40 46
41 ResourcePool::~ResourcePool() { 47 ResourcePool::~ResourcePool() {
42 while (!busy_resources_.empty()) { 48 while (!busy_resources_.empty()) {
43 DidFinishUsingResource(busy_resources_.front()); 49 DidFinishUsingResource(busy_resources_.front());
44 busy_resources_.pop_front(); 50 busy_resources_.pop_front();
45 } 51 }
46 52
47 SetResourceUsageLimits(0, 0, 0); 53 SetResourceUsageLimits(0, 0, 0);
48 DCHECK_EQ(0u, unused_resources_.size()); 54 DCHECK_EQ(0u, unused_resources_.size());
49 DCHECK_EQ(0u, memory_usage_bytes_); 55 DCHECK_EQ(0u, memory_usage_bytes_);
50 DCHECK_EQ(0u, unused_memory_usage_bytes_); 56 DCHECK_EQ(0u, unused_memory_usage_bytes_);
51 DCHECK_EQ(0u, resource_count_); 57 DCHECK_EQ(0u, resource_count_);
52 } 58 }
53 59
54 scoped_ptr<ResourcePool::Resource> ResourcePool::AcquireResource( 60 scoped_ptr<ResourcePool::Resource> ResourcePool::AcquireResource(
55 gfx::Size size, ResourceFormat format) { 61 gfx::Size size) {
56 for (ResourceList::iterator it = unused_resources_.begin(); 62 for (ResourceList::iterator it = unused_resources_.begin();
57 it != unused_resources_.end(); ++it) { 63 it != unused_resources_.end(); ++it) {
58 Resource* resource = *it; 64 Resource* resource = *it;
59 DCHECK(resource_provider_->CanLockForWrite(resource->id())); 65 DCHECK(resource_provider_->CanLockForWrite(resource->id()));
60 66
61 if (resource->size() != size) 67 if (resource->size() != size)
62 continue; 68 continue;
63 if (resource->format() != format)
64 continue;
65 69
66 unused_resources_.erase(it); 70 unused_resources_.erase(it);
67 unused_memory_usage_bytes_ -= resource->bytes(); 71 unused_memory_usage_bytes_ -= resource->bytes();
68 return make_scoped_ptr(resource); 72 return make_scoped_ptr(resource);
69 } 73 }
70 74
71 // Create new resource. 75 // Create new resource.
72 Resource* resource = new Resource(resource_provider_, size, format); 76 Resource* resource = new Resource(
77 resource_provider_, size, target_, format_);
73 78
74 // Extend all read locks on all resources until the resource is 79 // Extend all read locks on all resources until the resource is
75 // finished being used, such that we know when resources are 80 // finished being used, such that we know when resources are
76 // truly safe to recycle. 81 // truly safe to recycle.
77 resource_provider_->EnableReadLockFences(resource->id(), true); 82 resource_provider_->EnableReadLockFences(resource->id(), true);
78 83
79 memory_usage_bytes_ += resource->bytes(); 84 memory_usage_bytes_ += resource->bytes();
80 ++resource_count_; 85 ++resource_count_;
81 return make_scoped_ptr(resource); 86 return make_scoped_ptr(resource);
82 } 87 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 147 }
143 } 148 }
144 } 149 }
145 150
146 void ResourcePool::DidFinishUsingResource(ResourcePool::Resource* resource) { 151 void ResourcePool::DidFinishUsingResource(ResourcePool::Resource* resource) {
147 unused_memory_usage_bytes_ += resource->bytes(); 152 unused_memory_usage_bytes_ += resource->bytes();
148 unused_resources_.push_back(resource); 153 unused_resources_.push_back(resource);
149 } 154 }
150 155
151 } // namespace cc 156 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_pool.h ('k') | cc/resources/resource_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698