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

Side by Side Diff: cc/resource_provider.cc

Issue 11622008: cc: Defer texture allocation (to allow async allocations). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase. Rebase test fixes. Created 7 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
« 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 , glPixelBufferId(0) 52 , glPixelBufferId(0)
53 , glUploadQueryId(0) 53 , glUploadQueryId(0)
54 , pixels(0) 54 , pixels(0)
55 , pixelBuffer(0) 55 , pixelBuffer(0)
56 , lockForReadCount(0) 56 , lockForReadCount(0)
57 , lockedForWrite(false) 57 , lockedForWrite(false)
58 , external(false) 58 , external(false)
59 , exported(false) 59 , exported(false)
60 , markedForDeletion(false) 60 , markedForDeletion(false)
61 , pendingSetPixels(false) 61 , pendingSetPixels(false)
62 , allocated(false)
62 , size() 63 , size()
63 , format(0) 64 , format(0)
64 , filter(0) 65 , filter(0)
65 , type(static_cast<ResourceType>(0)) 66 , type(static_cast<ResourceType>(0))
66 { 67 {
67 } 68 }
68 69
69 ResourceProvider::Resource::~Resource() 70 ResourceProvider::Resource::~Resource()
70 { 71 {
71 } 72 }
72 73
73 ResourceProvider::Resource::Resource(unsigned textureId, const gfx::Size& size, GLenum format, GLenum filter) 74 ResourceProvider::Resource::Resource(unsigned textureId, const gfx::Size& size, GLenum format, GLenum filter)
74 : glId(textureId) 75 : glId(textureId)
75 , glPixelBufferId(0) 76 , glPixelBufferId(0)
76 , glUploadQueryId(0) 77 , glUploadQueryId(0)
77 , pixels(0) 78 , pixels(0)
78 , pixelBuffer(0) 79 , pixelBuffer(0)
79 , lockForReadCount(0) 80 , lockForReadCount(0)
80 , lockedForWrite(false) 81 , lockedForWrite(false)
81 , external(false) 82 , external(false)
82 , exported(false) 83 , exported(false)
83 , markedForDeletion(false) 84 , markedForDeletion(false)
84 , pendingSetPixels(false) 85 , pendingSetPixels(false)
86 , allocated(false)
85 , size(size) 87 , size(size)
86 , format(format) 88 , format(format)
87 , filter(filter) 89 , filter(filter)
88 , type(GLTexture) 90 , type(GLTexture)
89 { 91 {
90 } 92 }
91 93
92 ResourceProvider::Resource::Resource(uint8_t* pixels, const gfx::Size& size, GLe num format, GLenum filter) 94 ResourceProvider::Resource::Resource(uint8_t* pixels, const gfx::Size& size, GLe num format, GLenum filter)
93 : glId(0) 95 : glId(0)
94 , glPixelBufferId(0) 96 , glPixelBufferId(0)
95 , glUploadQueryId(0) 97 , glUploadQueryId(0)
96 , pixels(pixels) 98 , pixels(pixels)
97 , pixelBuffer(0) 99 , pixelBuffer(0)
98 , lockForReadCount(0) 100 , lockForReadCount(0)
99 , lockedForWrite(false) 101 , lockedForWrite(false)
100 , external(false) 102 , external(false)
101 , exported(false) 103 , exported(false)
102 , markedForDeletion(false) 104 , markedForDeletion(false)
103 , pendingSetPixels(false) 105 , pendingSetPixels(false)
106 , allocated(false)
104 , size(size) 107 , size(size)
105 , format(format) 108 , format(format)
106 , filter(filter) 109 , filter(filter)
107 , type(Bitmap) 110 , type(Bitmap)
108 { 111 {
109 } 112 }
110 113
111 ResourceProvider::Child::Child() 114 ResourceProvider::Child::Child()
112 { 115 {
113 } 116 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 { 183 {
181 DCHECK_LE(size.width(), m_maxTextureSize); 184 DCHECK_LE(size.width(), m_maxTextureSize);
182 DCHECK_LE(size.height(), m_maxTextureSize); 185 DCHECK_LE(size.height(), m_maxTextureSize);
183 186
184 DCHECK(m_threadChecker.CalledOnValidThread()); 187 DCHECK(m_threadChecker.CalledOnValidThread());
185 unsigned textureId = 0; 188 unsigned textureId = 0;
186 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 189 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
187 DCHECK(context3d); 190 DCHECK(context3d);
188 GLC(context3d, textureId = context3d->createTexture()); 191 GLC(context3d, textureId = context3d->createTexture());
189 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); 192 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
193
194 // Set texture properties. Allocation is delayed until needed.
190 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR)); 195 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR));
191 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR)); 196 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR));
192 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); 197 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE));
193 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); 198 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE));
194 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROM IUM, texturePool)); 199 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROM IUM, texturePool));
195
196 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) 200 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer)
197 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); 201 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE));
198 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) {
199 GLenum storageFormat = textureToStorageFormat(format);
200 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma t, size.width(), size.height()));
201 } else
202 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0));
203 202
204 ResourceId id = m_nextId++; 203 ResourceId id = m_nextId++;
205 Resource resource(textureId, size, format, GL_LINEAR); 204 Resource resource(textureId, size, format, GL_LINEAR);
205 resource.allocated = false;
206 m_resources[id] = resource; 206 m_resources[id] = resource;
207 return id; 207 return id;
208 } 208 }
209 209
210 ResourceProvider::ResourceId ResourceProvider::createBitmap(const gfx::Size& siz e) 210 ResourceProvider::ResourceId ResourceProvider::createBitmap(const gfx::Size& siz e)
211 { 211 {
212 DCHECK(m_threadChecker.CalledOnValidThread()); 212 DCHECK(m_threadChecker.CalledOnValidThread());
213 213
214 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; 214 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4];
215 215
216 ResourceId id = m_nextId++; 216 ResourceId id = m_nextId++;
217 Resource resource(pixels, size, GL_RGBA, GL_LINEAR); 217 Resource resource(pixels, size, GL_RGBA, GL_LINEAR);
218 resource.allocated = true;
218 m_resources[id] = resource; 219 m_resources[id] = resource;
219 return id; 220 return id;
220 } 221 }
221 222
222 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture (unsigned textureId) 223 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture (unsigned textureId)
223 { 224 {
224 DCHECK(m_threadChecker.CalledOnValidThread()); 225 DCHECK(m_threadChecker.CalledOnValidThread());
225 226
226 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 227 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
227 DCHECK(context3d); 228 DCHECK(context3d);
228 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); 229 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
229 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR)); 230 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR));
230 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR)); 231 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR));
231 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); 232 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE));
232 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); 233 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE));
233 234
234 ResourceId id = m_nextId++; 235 ResourceId id = m_nextId++;
235 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR); 236 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR);
236 resource.external = true; 237 resource.external = true;
238 resource.allocated = true;
237 m_resources[id] = resource; 239 m_resources[id] = resource;
238 return id; 240 return id;
239 } 241 }
240 242
241 ResourceProvider::ResourceId ResourceProvider::createResourceFromTextureMailbox( const std::string& mailbox, const base::Callback<void(unsigned)>& releaseCallbac k) 243 ResourceProvider::ResourceId ResourceProvider::createResourceFromTextureMailbox( const std::string& mailbox, const base::Callback<void(unsigned)>& releaseCallbac k)
242 { 244 {
243 DCHECK(m_threadChecker.CalledOnValidThread()); 245 DCHECK(m_threadChecker.CalledOnValidThread());
244 246
245 // FIXME: As an optimization, delay consuming the mailbox 247 // FIXME: As an optimization, delay consuming the mailbox
246 // and creating the texture ID until lockForRead. 248 // and creating the texture ID until lockForRead.
(...skipping 12 matching lines...) Expand all
259 m_resources[id] = resource; 261 m_resources[id] = resource;
260 return id; 262 return id;
261 } 263 }
262 264
263 void ResourceProvider::deleteResource(ResourceId id) 265 void ResourceProvider::deleteResource(ResourceId id)
264 { 266 {
265 DCHECK(m_threadChecker.CalledOnValidThread()); 267 DCHECK(m_threadChecker.CalledOnValidThread());
266 ResourceMap::iterator it = m_resources.find(id); 268 ResourceMap::iterator it = m_resources.find(id);
267 CHECK(it != m_resources.end()); 269 CHECK(it != m_resources.end());
268 Resource* resource = &it->second; 270 Resource* resource = &it->second;
269 DCHECK(!resource->lockedForWrite);
270 DCHECK(!resource->lockForReadCount); 271 DCHECK(!resource->lockForReadCount);
271 DCHECK(!resource->markedForDeletion); 272 DCHECK(!resource->markedForDeletion);
273 DCHECK(resource->pendingSetPixels || !resource->lockedForWrite);
272 274
273 if (resource->exported) { 275 if (resource->exported) {
274 resource->markedForDeletion = true; 276 resource->markedForDeletion = true;
275 return; 277 return;
276 } else 278 } else
277 deleteResourceInternal(it); 279 deleteResourceInternal(it);
278 } 280 }
279 281
280 void ResourceProvider::deleteResourceInternal(ResourceMap::iterator it) 282 void ResourceProvider::deleteResourceInternal(ResourceMap::iterator it)
281 { 283 {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 void ResourceProvider::setPixels(ResourceId id, const uint8_t* image, const gfx: :Rect& imageRect, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset) 327 void ResourceProvider::setPixels(ResourceId id, const uint8_t* image, const gfx: :Rect& imageRect, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset)
326 { 328 {
327 DCHECK(m_threadChecker.CalledOnValidThread()); 329 DCHECK(m_threadChecker.CalledOnValidThread());
328 ResourceMap::iterator it = m_resources.find(id); 330 ResourceMap::iterator it = m_resources.find(id);
329 CHECK(it != m_resources.end()); 331 CHECK(it != m_resources.end());
330 Resource* resource = &it->second; 332 Resource* resource = &it->second;
331 DCHECK(!resource->lockedForWrite); 333 DCHECK(!resource->lockedForWrite);
332 DCHECK(!resource->lockForReadCount); 334 DCHECK(!resource->lockForReadCount);
333 DCHECK(!resource->external); 335 DCHECK(!resource->external);
334 DCHECK(!resource->exported); 336 DCHECK(!resource->exported);
337 lazyAllocate(resource);
335 338
336 if (resource->glId) { 339 if (resource->glId) {
340 DCHECK(!resource->pendingSetPixels);
337 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 341 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
338 DCHECK(context3d); 342 DCHECK(context3d);
339 DCHECK(m_textureUploader.get()); 343 DCHECK(m_textureUploader.get());
340 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); 344 context3d->bindTexture(GL_TEXTURE_2D, resource->glId);
341 m_textureUploader->upload(image, 345 m_textureUploader->upload(image,
342 imageRect, 346 imageRect,
343 sourceRect, 347 sourceRect,
344 destOffset, 348 destOffset,
345 resource->format, 349 resource->format,
346 resource->size); 350 resource->size);
347 } 351 }
348 352
349 if (resource->pixels) { 353 if (resource->pixels) {
354 DCHECK(resource->allocated);
350 DCHECK(resource->format == GL_RGBA); 355 DCHECK(resource->format == GL_RGBA);
351 SkBitmap srcFull; 356 SkBitmap srcFull;
352 srcFull.setConfig(SkBitmap::kARGB_8888_Config, imageRect.width(), imageR ect.height()); 357 srcFull.setConfig(SkBitmap::kARGB_8888_Config, imageRect.width(), imageR ect.height());
353 srcFull.setPixels(const_cast<uint8_t*>(image)); 358 srcFull.setPixels(const_cast<uint8_t*>(image));
354 SkBitmap srcSubset; 359 SkBitmap srcSubset;
355 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(), sourceRect.width(), sourceRect.height()); 360 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(), sourceRect.width(), sourceRect.height());
356 skSourceRect.offset(-imageRect.x(), -imageRect.y()); 361 skSourceRect.offset(-imageRect.x(), -imageRect.y());
357 srcFull.extractSubset(&srcSubset, skSourceRect); 362 srcFull.extractSubset(&srcSubset, skSourceRect);
358 363
359 ScopedWriteLockSoftware lock(this, id); 364 ScopedWriteLockSoftware lock(this, id);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } 419 }
415 420
416 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) 421 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id)
417 { 422 {
418 DCHECK(m_threadChecker.CalledOnValidThread()); 423 DCHECK(m_threadChecker.CalledOnValidThread());
419 ResourceMap::iterator it = m_resources.find(id); 424 ResourceMap::iterator it = m_resources.find(id);
420 CHECK(it != m_resources.end()); 425 CHECK(it != m_resources.end());
421 Resource* resource = &it->second; 426 Resource* resource = &it->second;
422 DCHECK(!resource->lockedForWrite); 427 DCHECK(!resource->lockedForWrite);
423 DCHECK(!resource->exported); 428 DCHECK(!resource->exported);
429 DCHECK(resource->allocated); // Uninitialized! Call setPixels or lockForWrit e first.
430
424 resource->lockForReadCount++; 431 resource->lockForReadCount++;
425 return resource; 432 return resource;
426 } 433 }
427 434
428 void ResourceProvider::unlockForRead(ResourceId id) 435 void ResourceProvider::unlockForRead(ResourceId id)
429 { 436 {
430 DCHECK(m_threadChecker.CalledOnValidThread()); 437 DCHECK(m_threadChecker.CalledOnValidThread());
431 ResourceMap::iterator it = m_resources.find(id); 438 ResourceMap::iterator it = m_resources.find(id);
432 CHECK(it != m_resources.end()); 439 CHECK(it != m_resources.end());
433 Resource* resource = &it->second; 440 Resource* resource = &it->second;
434 DCHECK(resource->lockForReadCount > 0); 441 DCHECK(resource->lockForReadCount > 0);
435 DCHECK(!resource->exported); 442 DCHECK(!resource->exported);
436 resource->lockForReadCount--; 443 resource->lockForReadCount--;
437 } 444 }
438 445
439 const ResourceProvider::Resource* ResourceProvider::lockForWrite(ResourceId id) 446 const ResourceProvider::Resource* ResourceProvider::lockForWrite(ResourceId id)
440 { 447 {
441 DCHECK(m_threadChecker.CalledOnValidThread()); 448 DCHECK(m_threadChecker.CalledOnValidThread());
442 ResourceMap::iterator it = m_resources.find(id); 449 ResourceMap::iterator it = m_resources.find(id);
443 CHECK(it != m_resources.end()); 450 CHECK(it != m_resources.end());
444 Resource* resource = &it->second; 451 Resource* resource = &it->second;
445 DCHECK(!resource->lockedForWrite); 452 DCHECK(!resource->lockedForWrite);
446 DCHECK(!resource->lockForReadCount); 453 DCHECK(!resource->lockForReadCount);
447 DCHECK(!resource->exported); 454 DCHECK(!resource->exported);
448 DCHECK(!resource->external); 455 DCHECK(!resource->external);
456 lazyAllocate(resource);
457
449 resource->lockedForWrite = true; 458 resource->lockedForWrite = true;
450 return resource; 459 return resource;
451 } 460 }
452 461
453 void ResourceProvider::unlockForWrite(ResourceId id) 462 void ResourceProvider::unlockForWrite(ResourceId id)
454 { 463 {
455 DCHECK(m_threadChecker.CalledOnValidThread()); 464 DCHECK(m_threadChecker.CalledOnValidThread());
456 ResourceMap::iterator it = m_resources.find(id); 465 ResourceMap::iterator it = m_resources.find(id);
457 CHECK(it != m_resources.end()); 466 CHECK(it != m_resources.end());
458 Resource* resource = &it->second; 467 Resource* resource = &it->second;
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 } 684 }
676 Child& childInfo = m_children.find(child)->second; 685 Child& childInfo = m_children.find(child)->second;
677 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) { 686 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) {
678 unsigned textureId; 687 unsigned textureId;
679 GLC(context3d, textureId = context3d->createTexture()); 688 GLC(context3d, textureId = context3d->createTexture());
680 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); 689 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
681 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name)); 690 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name));
682 ResourceId id = m_nextId++; 691 ResourceId id = m_nextId++;
683 Resource resource(textureId, it->size, it->format, it->filter); 692 Resource resource(textureId, it->size, it->format, it->filter);
684 resource.mailbox.setName(it->mailbox.name); 693 resource.mailbox.setName(it->mailbox.name);
694 // Don't allocate a texture for a child.
695 resource.allocated = true;
685 m_resources[id] = resource; 696 m_resources[id] = resource;
686 childInfo.parentToChildMap[id] = it->id; 697 childInfo.parentToChildMap[id] = it->id;
687 childInfo.childToParentMap[it->id] = id; 698 childInfo.childToParentMap[it->id] = id;
688 } 699 }
689 } 700 }
690 701
691 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es) 702 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es)
692 { 703 {
693 DCHECK(m_threadChecker.CalledOnValidThread()); 704 DCHECK(m_threadChecker.CalledOnValidThread());
694 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 705 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
(...skipping 20 matching lines...) Expand all
715 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource) 726 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource)
716 { 727 {
717 DCHECK(m_threadChecker.CalledOnValidThread()); 728 DCHECK(m_threadChecker.CalledOnValidThread());
718 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 729 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
719 ResourceMap::iterator it = m_resources.find(id); 730 ResourceMap::iterator it = m_resources.find(id);
720 CHECK(it != m_resources.end()); 731 CHECK(it != m_resources.end());
721 Resource* source = &it->second; 732 Resource* source = &it->second;
722 DCHECK(!source->lockedForWrite); 733 DCHECK(!source->lockedForWrite);
723 DCHECK(!source->lockForReadCount); 734 DCHECK(!source->lockForReadCount);
724 DCHECK(!source->external || (source->external && !source->mailbox.isZero())) ; 735 DCHECK(!source->external || (source->external && !source->mailbox.isZero())) ;
736 DCHECK(source->allocated);
725 if (source->exported) 737 if (source->exported)
726 return false; 738 return false;
727 resource->id = id; 739 resource->id = id;
728 resource->format = source->format; 740 resource->format = source->format;
729 resource->filter = source->filter; 741 resource->filter = source->filter;
730 resource->size = source->size; 742 resource->size = source->size;
731 743
732 if (source->mailbox.isZero()) { 744 if (source->mailbox.isZero()) {
733 GLbyte name[GL_MAILBOX_SIZE_CHROMIUM]; 745 GLbyte name[GL_MAILBOX_SIZE_CHROMIUM];
734 GLC(context3d, context3d->genMailboxCHROMIUM(name)); 746 GLC(context3d, context3d->genMailboxCHROMIUM(name));
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 void ResourceProvider::setPixelsFromBuffer(ResourceId id) 874 void ResourceProvider::setPixelsFromBuffer(ResourceId id)
863 { 875 {
864 DCHECK(m_threadChecker.CalledOnValidThread()); 876 DCHECK(m_threadChecker.CalledOnValidThread());
865 ResourceMap::iterator it = m_resources.find(id); 877 ResourceMap::iterator it = m_resources.find(id);
866 CHECK(it != m_resources.end()); 878 CHECK(it != m_resources.end());
867 Resource* resource = &it->second; 879 Resource* resource = &it->second;
868 DCHECK(!resource->lockedForWrite); 880 DCHECK(!resource->lockedForWrite);
869 DCHECK(!resource->lockForReadCount); 881 DCHECK(!resource->lockForReadCount);
870 DCHECK(!resource->external); 882 DCHECK(!resource->external);
871 DCHECK(!resource->exported); 883 DCHECK(!resource->exported);
884 lazyAllocate(resource);
872 885
873 if (resource->glId) { 886 if (resource->glId) {
874 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 887 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
875 DCHECK(context3d); 888 DCHECK(context3d);
876 DCHECK(resource->glPixelBufferId); 889 DCHECK(resource->glPixelBufferId);
877 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); 890 context3d->bindTexture(GL_TEXTURE_2D, resource->glId);
878 context3d->bindBuffer( 891 context3d->bindBuffer(
879 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 892 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
880 resource->glPixelBufferId); 893 resource->glPixelBufferId);
881 context3d->texSubImage2D(GL_TEXTURE_2D, 894 context3d->texSubImage2D(GL_TEXTURE_2D,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 } 936 }
924 } 937 }
925 938
926 void ResourceProvider::beginSetPixels(ResourceId id) 939 void ResourceProvider::beginSetPixels(ResourceId id)
927 { 940 {
928 DCHECK(m_threadChecker.CalledOnValidThread()); 941 DCHECK(m_threadChecker.CalledOnValidThread());
929 ResourceMap::iterator it = m_resources.find(id); 942 ResourceMap::iterator it = m_resources.find(id);
930 CHECK(it != m_resources.end()); 943 CHECK(it != m_resources.end());
931 Resource* resource = &it->second; 944 Resource* resource = &it->second;
932 DCHECK(!resource->pendingSetPixels); 945 DCHECK(!resource->pendingSetPixels);
946 DCHECK(resource->glId || resource->allocated);
933 947
948 bool allocate = !resource->allocated;
949 resource->allocated = true;
934 lockForWrite(id); 950 lockForWrite(id);
935 951
936 if (resource->glId) { 952 if (resource->glId) {
937 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 953 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
938 DCHECK(context3d); 954 DCHECK(context3d);
939 DCHECK(resource->glPixelBufferId); 955 DCHECK(resource->glPixelBufferId);
940 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); 956 context3d->bindTexture(GL_TEXTURE_2D, resource->glId);
941 context3d->bindBuffer( 957 context3d->bindBuffer(
942 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 958 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
943 resource->glPixelBufferId); 959 resource->glPixelBufferId);
944 if (!resource->glUploadQueryId) 960 if (!resource->glUploadQueryId)
945 resource->glUploadQueryId = context3d->createQueryEXT(); 961 resource->glUploadQueryId = context3d->createQueryEXT();
946 context3d->beginQueryEXT( 962 context3d->beginQueryEXT(
947 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM, 963 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM,
948 resource->glUploadQueryId); 964 resource->glUploadQueryId);
949 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, 965 if (allocate) {
950 0, /* level */ 966 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D,
951 0, /* x */ 967 0, /* level */
952 0, /* y */ 968 resource->format,
953 resource->size.width(), 969 resource->size.width(),
954 resource->size.height(), 970 resource->size.height(),
955 resource->format, 971 0, /* border */
956 GL_UNSIGNED_BYTE, 972 resource->format,
957 NULL); 973 GL_UNSIGNED_BYTE,
974 NULL);
975 } else {
976 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D,
977 0, /* level */
978 0, /* x */
979 0, /* y */
980 resource->size.width(),
981 resource->size.height(),
982 resource->format,
983 GL_UNSIGNED_BYTE,
984 NULL);
985 }
958 context3d->endQueryEXT(GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM); 986 context3d->endQueryEXT(GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM);
959 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 987 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
960 } 988 }
961 989
962 if (resource->pixels) 990 if (resource->pixels)
963 setPixelsFromBuffer(id); 991 setPixelsFromBuffer(id);
964 992
965 resource->pendingSetPixels = true; 993 resource->pendingSetPixels = true;
966 } 994 }
967 995
(...skipping 17 matching lines...) Expand all
985 if (!complete) 1013 if (!complete)
986 return false; 1014 return false;
987 } 1015 }
988 1016
989 resource->pendingSetPixels = false; 1017 resource->pendingSetPixels = false;
990 unlockForWrite(id); 1018 unlockForWrite(id);
991 1019
992 return true; 1020 return true;
993 } 1021 }
994 1022
1023 void ResourceProvider::allocateForTesting(ResourceId id) {
1024 ResourceMap::iterator it = m_resources.find(id);
1025 CHECK(it != m_resources.end());
1026 Resource* resource = &it->second;
1027 lazyAllocate(resource);
1028 }
1029
1030 void ResourceProvider::lazyAllocate(Resource* resource) {
1031 DCHECK(resource);
1032 DCHECK(resource->glId || resource->allocated);
1033
1034 if (resource->allocated || !resource->glId)
1035 return;
1036
1037 resource->allocated = true;
1038 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
1039 gfx::Size& size = resource->size;
1040 GLenum format = resource->format;
1041 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId));
1042 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) {
1043 GLenum storageFormat = textureToStorageFormat(format);
1044 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma t, size.width(), size.height()));
1045 } else
1046 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0));
1047 }
1048
1049
995 } // namespace cc 1050 } // 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