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

Side by Side Diff: cc/resource_provider.cc

Issue 11578019: Remove the pools from the ResourceProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Re-resolve against HEAD Created 8 years 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/resource_provider.h ('k') | cc/resource_provider_unittest.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/resource_provider.h" 5 #include "cc/resource_provider.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 8
9 #include "base/debug/alias.h" 9 #include "base/debug/alias.h"
10 #include "base/hash_tables.h" 10 #include "base/hash_tables.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 { 47 {
48 return (format == GL_RGBA || format == GL_BGRA_EXT); 48 return (format == GL_RGBA || format == GL_BGRA_EXT);
49 } 49 }
50 50
51 ResourceProvider::Resource::Resource() 51 ResourceProvider::Resource::Resource()
52 : glId(0) 52 : glId(0)
53 , glPixelBufferId(0) 53 , glPixelBufferId(0)
54 , glUploadQueryId(0) 54 , glUploadQueryId(0)
55 , pixels(0) 55 , pixels(0)
56 , pixelBuffer(0) 56 , pixelBuffer(0)
57 , pool(0)
58 , lockForReadCount(0) 57 , lockForReadCount(0)
59 , lockedForWrite(false) 58 , lockedForWrite(false)
60 , external(false) 59 , external(false)
61 , exported(false) 60 , exported(false)
62 , markedForDeletion(false) 61 , markedForDeletion(false)
63 , pendingSetPixels(false) 62 , pendingSetPixels(false)
64 , size() 63 , size()
65 , format(0) 64 , format(0)
66 , filter(0) 65 , filter(0)
67 , type(static_cast<ResourceType>(0)) 66 , type(static_cast<ResourceType>(0))
68 { 67 {
69 } 68 }
70 69
71 ResourceProvider::Resource::Resource(unsigned textureId, int pool, const gfx::Si ze& size, GLenum format, GLenum filter) 70 ResourceProvider::Resource::Resource(unsigned textureId, const gfx::Size& size, GLenum format, GLenum filter)
72 : glId(textureId) 71 : glId(textureId)
73 , glPixelBufferId(0) 72 , glPixelBufferId(0)
74 , glUploadQueryId(0) 73 , glUploadQueryId(0)
75 , pixels(0) 74 , pixels(0)
76 , pixelBuffer(0) 75 , pixelBuffer(0)
77 , pool(pool)
78 , lockForReadCount(0) 76 , lockForReadCount(0)
79 , lockedForWrite(false) 77 , lockedForWrite(false)
80 , external(false) 78 , external(false)
81 , exported(false) 79 , exported(false)
82 , markedForDeletion(false) 80 , markedForDeletion(false)
83 , pendingSetPixels(false) 81 , pendingSetPixels(false)
84 , size(size) 82 , size(size)
85 , format(format) 83 , format(format)
86 , filter(filter) 84 , filter(filter)
87 , type(GLTexture) 85 , type(GLTexture)
88 { 86 {
89 } 87 }
90 88
91 ResourceProvider::Resource::Resource(uint8_t* pixels, int pool, const gfx::Size& size, GLenum format, GLenum filter) 89 ResourceProvider::Resource::Resource(uint8_t* pixels, const gfx::Size& size, GLe num format, GLenum filter)
92 : glId(0) 90 : glId(0)
93 , glPixelBufferId(0) 91 , glPixelBufferId(0)
94 , glUploadQueryId(0) 92 , glUploadQueryId(0)
95 , pixels(pixels) 93 , pixels(pixels)
96 , pixelBuffer(0) 94 , pixelBuffer(0)
97 , pool(pool)
98 , lockForReadCount(0) 95 , lockForReadCount(0)
99 , lockedForWrite(false) 96 , lockedForWrite(false)
100 , external(false) 97 , external(false)
101 , exported(false) 98 , exported(false)
102 , markedForDeletion(false) 99 , markedForDeletion(false)
103 , pendingSetPixels(false) 100 , pendingSetPixels(false)
104 , size(size) 101 , size(size)
105 , format(format) 102 , format(format)
106 , filter(filter) 103 , filter(filter)
107 , type(Bitmap) 104 , type(Bitmap)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 138
142 bool ResourceProvider::inUseByConsumer(ResourceId id) 139 bool ResourceProvider::inUseByConsumer(ResourceId id)
143 { 140 {
144 DCHECK(m_threadChecker.CalledOnValidThread()); 141 DCHECK(m_threadChecker.CalledOnValidThread());
145 ResourceMap::iterator it = m_resources.find(id); 142 ResourceMap::iterator it = m_resources.find(id);
146 CHECK(it != m_resources.end()); 143 CHECK(it != m_resources.end());
147 Resource* resource = &it->second; 144 Resource* resource = &it->second;
148 return !!resource->lockForReadCount || resource->exported; 145 return !!resource->lockForReadCount || resource->exported;
149 } 146 }
150 147
151 ResourceProvider::ResourceId ResourceProvider::createResource(int pool, const gf x::Size& size, GLenum format, TextureUsageHint hint) 148 ResourceProvider::ResourceId ResourceProvider::createResource(const gfx::Size& s ize, GLenum format, TextureUsageHint hint)
152 { 149 {
153 switch (m_defaultResourceType) { 150 switch (m_defaultResourceType) {
154 case GLTexture: 151 case GLTexture:
155 return createGLTexture(pool, size, format, hint); 152 return createGLTexture(size, format, hint);
156 case Bitmap: 153 case Bitmap:
157 DCHECK(format == GL_RGBA); 154 DCHECK(format == GL_RGBA);
158 return createBitmap(pool, size); 155 return createBitmap(size);
159 } 156 }
160 157
161 LOG(FATAL) << "Invalid default resource type."; 158 LOG(FATAL) << "Invalid default resource type.";
162 return 0; 159 return 0;
163 } 160 }
164 161
165 ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const g fx::Size& size, GLenum format, TextureUsageHint hint) 162 ResourceProvider::ResourceId ResourceProvider::createGLTexture(const gfx::Size& size, GLenum format, TextureUsageHint hint)
166 { 163 {
167 DCHECK_LE(size.width(), m_maxTextureSize); 164 DCHECK_LE(size.width(), m_maxTextureSize);
168 DCHECK_LE(size.height(), m_maxTextureSize); 165 DCHECK_LE(size.height(), m_maxTextureSize);
169 166
170 DCHECK(m_threadChecker.CalledOnValidThread()); 167 DCHECK(m_threadChecker.CalledOnValidThread());
171 unsigned textureId = 0; 168 unsigned textureId = 0;
172 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 169 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
173 DCHECK(context3d); 170 DCHECK(context3d);
174 GLC(context3d, textureId = context3d->createTexture()); 171 GLC(context3d, textureId = context3d->createTexture());
175 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); 172 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
176 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR)); 173 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR));
177 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR)); 174 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR));
178 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); 175 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE));
179 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); 176 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE));
180 177
181 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) 178 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer)
182 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); 179 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE));
183 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { 180 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) {
184 GLenum storageFormat = textureToStorageFormat(format); 181 GLenum storageFormat = textureToStorageFormat(format);
185 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma t, size.width(), size.height())); 182 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma t, size.width(), size.height()));
186 } else 183 } else
187 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); 184 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0));
188 185
189 ResourceId id = m_nextId++; 186 ResourceId id = m_nextId++;
190 Resource resource(textureId, pool, size, format, GL_LINEAR); 187 Resource resource(textureId, size, format, GL_LINEAR);
191 m_resources[id] = resource; 188 m_resources[id] = resource;
192 return id; 189 return id;
193 } 190 }
194 191
195 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const gfx: :Size& size) 192 ResourceProvider::ResourceId ResourceProvider::createBitmap(const gfx::Size& siz e)
196 { 193 {
197 DCHECK(m_threadChecker.CalledOnValidThread()); 194 DCHECK(m_threadChecker.CalledOnValidThread());
198 195
199 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; 196 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4];
200 197
201 ResourceId id = m_nextId++; 198 ResourceId id = m_nextId++;
202 Resource resource(pixels, pool, size, GL_RGBA, GL_LINEAR); 199 Resource resource(pixels, size, GL_RGBA, GL_LINEAR);
203 m_resources[id] = resource; 200 m_resources[id] = resource;
204 return id; 201 return id;
205 } 202 }
206 203
207 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture (unsigned textureId) 204 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture (unsigned textureId)
208 { 205 {
209 DCHECK(m_threadChecker.CalledOnValidThread()); 206 DCHECK(m_threadChecker.CalledOnValidThread());
210 207
211 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 208 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
212 DCHECK(context3d); 209 DCHECK(context3d);
213 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); 210 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
214 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR)); 211 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR));
215 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR)); 212 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR));
216 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); 213 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE));
217 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); 214 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE));
218 215
219 ResourceId id = m_nextId++; 216 ResourceId id = m_nextId++;
220 Resource resource(textureId, 0, gfx::Size(), 0, GL_LINEAR); 217 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR);
221 resource.external = true; 218 resource.external = true;
222 m_resources[id] = resource; 219 m_resources[id] = resource;
223 return id; 220 return id;
224 } 221 }
225 222
226 void ResourceProvider::deleteResource(ResourceId id) 223 void ResourceProvider::deleteResource(ResourceId id)
227 { 224 {
228 DCHECK(m_threadChecker.CalledOnValidThread()); 225 DCHECK(m_threadChecker.CalledOnValidThread());
229 ResourceMap::iterator it = m_resources.find(id); 226 ResourceMap::iterator it = m_resources.find(id);
230 CHECK(it != m_resources.end()); 227 CHECK(it != m_resources.end());
(...skipping 28 matching lines...) Expand all
259 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId)); 256 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId));
260 } 257 }
261 if (resource->pixels) 258 if (resource->pixels)
262 delete[] resource->pixels; 259 delete[] resource->pixels;
263 if (resource->pixelBuffer) 260 if (resource->pixelBuffer)
264 delete[] resource->pixelBuffer; 261 delete[] resource->pixelBuffer;
265 262
266 m_resources.erase(it); 263 m_resources.erase(it);
267 } 264 }
268 265
269 void ResourceProvider::deleteOwnedResources(int pool)
270 {
271 DCHECK(m_threadChecker.CalledOnValidThread());
272 ResourceIdArray toDelete;
273 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end() ; ++it) {
274 if (it->second.pool == pool && !it->second.external && !it->second.marke dForDeletion)
275 toDelete.push_back(it->first);
276 }
277 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end(); ++it)
278 deleteResource(*it);
279 }
280
281 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id) 266 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id)
282 { 267 {
283 ResourceMap::iterator it = m_resources.find(id); 268 ResourceMap::iterator it = m_resources.find(id);
284 CHECK(it != m_resources.end()); 269 CHECK(it != m_resources.end());
285 Resource* resource = &it->second; 270 Resource* resource = &it->second;
286 return resource->type; 271 return resource->type;
287 } 272 }
288 273
289 void ResourceProvider::setPixels(ResourceId id, const uint8_t* image, const gfx: :Rect& imageRect, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset) 274 void ResourceProvider::setPixels(ResourceId id, const uint8_t* image, const gfx: :Rect& imageRect, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset)
290 { 275 {
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 } 523 }
539 524
540 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform ); 525 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform );
541 526
542 m_textureUploader = TextureUploader::create(context3d, useMapSub, m_useShall owFlush); 527 m_textureUploader = TextureUploader::create(context3d, useMapSub, m_useShall owFlush);
543 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize )); 528 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize ));
544 m_bestTextureFormat = PlatformColor::bestTextureFormat(context3d, useBGRA); 529 m_bestTextureFormat = PlatformColor::bestTextureFormat(context3d, useBGRA);
545 return true; 530 return true;
546 } 531 }
547 532
548 int ResourceProvider::createChild(int pool) 533 int ResourceProvider::createChild()
549 { 534 {
550 DCHECK(m_threadChecker.CalledOnValidThread()); 535 DCHECK(m_threadChecker.CalledOnValidThread());
551 Child childInfo; 536 Child childInfo;
552 childInfo.pool = pool;
553 int child = m_nextChild++; 537 int child = m_nextChild++;
554 m_children[child] = childInfo; 538 m_children[child] = childInfo;
555 return child; 539 return child;
556 } 540 }
557 541
558 void ResourceProvider::destroyChild(int child) 542 void ResourceProvider::destroyChild(int child_id)
559 { 543 {
560 DCHECK(m_threadChecker.CalledOnValidThread()); 544 DCHECK(m_threadChecker.CalledOnValidThread());
561 ChildMap::iterator it = m_children.find(child); 545 ChildMap::iterator it = m_children.find(child_id);
562 DCHECK(it != m_children.end()); 546 DCHECK(it != m_children.end());
563 deleteOwnedResources(it->second.pool); 547 Child& child = it->second;
548 for (ResourceIdMap::iterator child_it = child.childToParentMap.begin(); chil d_it != child.childToParentMap.end(); ++child_it)
549 deleteResource(child_it->second);
564 m_children.erase(it); 550 m_children.erase(it);
565 } 551 }
566 552
567 const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int child) const 553 const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int child) const
568 { 554 {
569 DCHECK(m_threadChecker.CalledOnValidThread()); 555 DCHECK(m_threadChecker.CalledOnValidThread());
570 ChildMap::const_iterator it = m_children.find(child); 556 ChildMap::const_iterator it = m_children.find(child);
571 DCHECK(it != m_children.end()); 557 DCHECK(it != m_children.end());
572 return it->second.childToParentMap; 558 return it->second.childToParentMap;
573 } 559 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 // (and is simpler) to wait. 622 // (and is simpler) to wait.
637 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); 623 GLC(context3d, context3d->waitSyncPoint(resources.sync_point));
638 } 624 }
639 Child& childInfo = m_children.find(child)->second; 625 Child& childInfo = m_children.find(child)->second;
640 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) { 626 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) {
641 unsigned textureId; 627 unsigned textureId;
642 GLC(context3d, textureId = context3d->createTexture()); 628 GLC(context3d, textureId = context3d->createTexture());
643 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); 629 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
644 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name)); 630 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name));
645 ResourceId id = m_nextId++; 631 ResourceId id = m_nextId++;
646 Resource resource(textureId, childInfo.pool, it->size, it->format, it->f ilter); 632 Resource resource(textureId, it->size, it->format, it->filter);
647 resource.mailbox.setName(it->mailbox.name); 633 resource.mailbox.setName(it->mailbox.name);
648 m_resources[id] = resource; 634 m_resources[id] = resource;
649 childInfo.parentToChildMap[id] = it->id; 635 childInfo.parentToChildMap[id] = it->id;
650 childInfo.childToParentMap[it->id] = id; 636 childInfo.childToParentMap[it->id] = id;
651 } 637 }
652 } 638 }
653 639
654 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es) 640 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es)
655 { 641 {
656 DCHECK(m_threadChecker.CalledOnValidThread()); 642 DCHECK(m_threadChecker.CalledOnValidThread());
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 return false; 935 return false;
950 } 936 }
951 937
952 resource->pendingSetPixels = false; 938 resource->pendingSetPixels = false;
953 unlockForWrite(id); 939 unlockForWrite(id);
954 940
955 return true; 941 return true;
956 } 942 }
957 943
958 } // namespace cc 944 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resource_provider.h ('k') | cc/resource_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698