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

Side by Side Diff: cc/resource_provider.cc

Issue 11888010: Cosmetic cleanup to texture_layer mailboxes. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: 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/texture_layer.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/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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); 234 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE));
235 235
236 ResourceId id = m_nextId++; 236 ResourceId id = m_nextId++;
237 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR); 237 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR);
238 resource.external = true; 238 resource.external = true;
239 resource.allocated = true; 239 resource.allocated = true;
240 m_resources[id] = resource; 240 m_resources[id] = resource;
241 return id; 241 return id;
242 } 242 }
243 243
244 ResourceProvider::ResourceId ResourceProvider::createResourceFromTextureMailbox( const std::string& mailbox, const base::Callback<void(unsigned)>& releaseCallbac k) 244 ResourceProvider::ResourceId ResourceProvider::createResourceFromTextureMailbox( const TextureMailbox& mailbox)
245 { 245 {
246 DCHECK(m_threadChecker.CalledOnValidThread()); 246 DCHECK(m_threadChecker.CalledOnValidThread());
247 // Just store the information. Mailbox will be consumed in lockForRead(). 247 // Just store the information. Mailbox will be consumed in lockForRead().
248 ResourceId id = m_nextId++; 248 ResourceId id = m_nextId++;
249 unsigned textureId = 0; 249 unsigned textureId = 0;
250 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR); 250 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR);
251 resource.external = true; 251 resource.external = true;
252 resource.allocated = true; 252 resource.allocated = true;
253 resource.mailbox.setName(reinterpret_cast<const int8*>(mailbox.data())); 253 resource.mailbox = mailbox;
254 resource.mailboxReleaseCallback = releaseCallback;
255 m_resources[id] = resource; 254 m_resources[id] = resource;
256 return id; 255 return id;
257 } 256 }
258 257
259 void ResourceProvider::deleteResource(ResourceId id) 258 void ResourceProvider::deleteResource(ResourceId id)
260 { 259 {
261 DCHECK(m_threadChecker.CalledOnValidThread()); 260 DCHECK(m_threadChecker.CalledOnValidThread());
262 ResourceMap::iterator it = m_resources.find(id); 261 ResourceMap::iterator it = m_resources.find(id);
263 CHECK(it != m_resources.end()); 262 CHECK(it != m_resources.end());
264 Resource* resource = &it->second; 263 Resource* resource = &it->second;
(...skipping 19 matching lines...) Expand all
284 if (resource->glUploadQueryId) { 283 if (resource->glUploadQueryId) {
285 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 284 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
286 DCHECK(context3d); 285 DCHECK(context3d);
287 GLC(context3d, context3d->deleteQueryEXT(resource->glUploadQueryId)); 286 GLC(context3d, context3d->deleteQueryEXT(resource->glUploadQueryId));
288 } 287 }
289 if (resource->glPixelBufferId) { 288 if (resource->glPixelBufferId) {
290 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 289 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
291 DCHECK(context3d); 290 DCHECK(context3d);
292 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId)); 291 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId));
293 } 292 }
294 if (!resource->mailbox.isZero() && resource->external) { 293 if (!resource->mailbox.IsEmpty() && resource->external) {
295 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 294 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
296 DCHECK(context3d); 295 DCHECK(context3d);
297 unsigned syncPoint = 0; 296 unsigned syncPoint = 0;
298 if (resource->glId) { 297 if (resource->glId) {
299 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId) ); 298 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId) );
300 GLC(context3d, context3d->produceTextureCHROMIUM(GL_TEXTURE_2D, reso urce->mailbox.name)); 299 GLC(context3d, context3d->produceTextureCHROMIUM(GL_TEXTURE_2D, reso urce->mailbox.data()));
301 GLC(context3d, context3d->deleteTexture(resource->glId)); 300 GLC(context3d, context3d->deleteTexture(resource->glId));
302 syncPoint = context3d->insertSyncPoint(); 301 syncPoint = context3d->insertSyncPoint();
303 } 302 }
304 if (!resource->mailboxReleaseCallback.is_null()) 303 resource->mailbox.RunReleaseCallback(syncPoint);
305 resource->mailboxReleaseCallback.Run(syncPoint);
306 } 304 }
307 if (resource->pixels) 305 if (resource->pixels)
308 delete[] resource->pixels; 306 delete[] resource->pixels;
309 if (resource->pixelBuffer) 307 if (resource->pixelBuffer)
310 delete[] resource->pixelBuffer; 308 delete[] resource->pixelBuffer;
311 309
312 m_resources.erase(it); 310 m_resources.erase(it);
313 } 311 }
314 312
315 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id) 313 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id)
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) 415 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id)
418 { 416 {
419 DCHECK(m_threadChecker.CalledOnValidThread()); 417 DCHECK(m_threadChecker.CalledOnValidThread());
420 ResourceMap::iterator it = m_resources.find(id); 418 ResourceMap::iterator it = m_resources.find(id);
421 CHECK(it != m_resources.end()); 419 CHECK(it != m_resources.end());
422 Resource* resource = &it->second; 420 Resource* resource = &it->second;
423 DCHECK(!resource->lockedForWrite); 421 DCHECK(!resource->lockedForWrite);
424 DCHECK(!resource->exported); 422 DCHECK(!resource->exported);
425 DCHECK(resource->allocated); // Uninitialized! Call setPixels or lockForWrit e first. 423 DCHECK(resource->allocated); // Uninitialized! Call setPixels or lockForWrit e first.
426 424
427 if (!resource->glId && resource->external && !resource->mailbox.isZero()) { 425 if (!resource->glId && resource->external && !resource->mailbox.IsEmpty()) {
428 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 426 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
429 DCHECK(context3d); 427 DCHECK(context3d);
430 resource->glId = context3d->createTexture(); 428 resource->glId = context3d->createTexture();
431 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); 429 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId));
432 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, resource ->mailbox.name)); 430 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, resource ->mailbox.data()));
433 } 431 }
434 432
435 resource->lockForReadCount++; 433 resource->lockForReadCount++;
436 return resource; 434 return resource;
437 } 435 }
438 436
439 void ResourceProvider::unlockForRead(ResourceId id) 437 void ResourceProvider::unlockForRead(ResourceId id)
440 { 438 {
441 DCHECK(m_threadChecker.CalledOnValidThread()); 439 DCHECK(m_threadChecker.CalledOnValidThread());
442 ResourceMap::iterator it = m_resources.find(id); 440 ResourceMap::iterator it = m_resources.find(id);
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); 685 GLC(context3d, context3d->waitSyncPoint(resources.sync_point));
688 } 686 }
689 Child& childInfo = m_children.find(child)->second; 687 Child& childInfo = m_children.find(child)->second;
690 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) { 688 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) {
691 unsigned textureId; 689 unsigned textureId;
692 GLC(context3d, textureId = context3d->createTexture()); 690 GLC(context3d, textureId = context3d->createTexture());
693 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); 691 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
694 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name)); 692 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name));
695 ResourceId id = m_nextId++; 693 ResourceId id = m_nextId++;
696 Resource resource(textureId, it->size, it->format, it->filter); 694 Resource resource(textureId, it->size, it->format, it->filter);
697 resource.mailbox.setName(it->mailbox.name); 695 resource.mailbox.SetName(it->mailbox);
698 // Don't allocate a texture for a child. 696 // Don't allocate a texture for a child.
699 resource.allocated = true; 697 resource.allocated = true;
700 m_resources[id] = resource; 698 m_resources[id] = resource;
701 childInfo.parentToChildMap[id] = it->id; 699 childInfo.parentToChildMap[id] = it->id;
702 childInfo.childToParentMap[it->id] = id; 700 childInfo.childToParentMap[it->id] = id;
703 } 701 }
704 } 702 }
705 703
706 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es) 704 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es)
707 { 705 {
708 DCHECK(m_threadChecker.CalledOnValidThread()); 706 DCHECK(m_threadChecker.CalledOnValidThread());
709 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 707 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
710 if (!context3d || !context3d->makeContextCurrent()) { 708 if (!context3d || !context3d->makeContextCurrent()) {
711 // FIXME: Implement this path for software compositing. 709 // FIXME: Implement this path for software compositing.
712 return; 710 return;
713 } 711 }
714 if (resources.sync_point) 712 if (resources.sync_point)
715 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); 713 GLC(context3d, context3d->waitSyncPoint(resources.sync_point));
716 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) { 714 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) {
717 ResourceMap::iterator mapIterator = m_resources.find(it->id); 715 ResourceMap::iterator mapIterator = m_resources.find(it->id);
718 DCHECK(mapIterator != m_resources.end()); 716 DCHECK(mapIterator != m_resources.end());
719 Resource* resource = &mapIterator->second; 717 Resource* resource = &mapIterator->second;
720 DCHECK(resource->exported); 718 DCHECK(resource->exported);
721 resource->exported = false; 719 resource->exported = false;
722 resource->mailbox.setName(it->mailbox.name); 720 resource->mailbox.SetName(it->mailbox);
723 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); 721 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId));
724 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name)); 722 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name));
725 if (resource->markedForDeletion) 723 if (resource->markedForDeletion)
726 deleteResourceInternal(mapIterator); 724 deleteResourceInternal(mapIterator);
727 } 725 }
728 } 726 }
729 727
730 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource) 728 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource)
731 { 729 {
732 DCHECK(m_threadChecker.CalledOnValidThread()); 730 DCHECK(m_threadChecker.CalledOnValidThread());
733 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 731 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
734 ResourceMap::iterator it = m_resources.find(id); 732 ResourceMap::iterator it = m_resources.find(id);
735 CHECK(it != m_resources.end()); 733 CHECK(it != m_resources.end());
736 Resource* source = &it->second; 734 Resource* source = &it->second;
737 DCHECK(!source->lockedForWrite); 735 DCHECK(!source->lockedForWrite);
738 DCHECK(!source->lockForReadCount); 736 DCHECK(!source->lockForReadCount);
739 DCHECK(!source->external || (source->external && !source->mailbox.isZero())) ; 737 DCHECK(!source->external || (source->external && !source->mailbox.IsEmpty()) );
740 DCHECK(source->allocated); 738 DCHECK(source->allocated);
741 if (source->exported) 739 if (source->exported)
742 return false; 740 return false;
743 resource->id = id; 741 resource->id = id;
744 resource->format = source->format; 742 resource->format = source->format;
745 resource->filter = source->filter; 743 resource->filter = source->filter;
746 resource->size = source->size; 744 resource->size = source->size;
747 745
748 if (source->mailbox.isZero()) { 746 if (source->mailbox.IsEmpty()) {
749 GLbyte name[GL_MAILBOX_SIZE_CHROMIUM]; 747 GLbyte name[GL_MAILBOX_SIZE_CHROMIUM];
750 GLC(context3d, context3d->genMailboxCHROMIUM(name)); 748 GLC(context3d, context3d->genMailboxCHROMIUM(name));
751 source->mailbox.setName(name); 749 resource->mailbox.setName(name);
piman 2013/01/17 22:20:42 nit: I think you can simplify the 3 above lines to
alexst (slow to review) 2013/01/17 23:50:38 Done. I was wondering if GLbyte name[GL_MAILBOX_SI
752 } 750 source->mailbox.SetName(resource->mailbox);
751 } else
752 resource->mailbox = source->mailbox.name();
753 753
754 resource->mailbox = source->mailbox;
755 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->glId)); 754 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->glId));
756 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, resource->mailbo x.name)); 755 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, resource->mailbo x.name));
757 return true; 756 return true;
758 } 757 }
759 758
760 void ResourceProvider::acquirePixelBuffer(ResourceId id) 759 void ResourceProvider::acquirePixelBuffer(ResourceId id)
761 { 760 {
762 DCHECK(m_threadChecker.CalledOnValidThread()); 761 DCHECK(m_threadChecker.CalledOnValidThread());
763 ResourceMap::iterator it = m_resources.find(id); 762 ResourceMap::iterator it = m_resources.find(id);
764 CHECK(it != m_resources.end()); 763 CHECK(it != m_resources.end());
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); 1044 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId));
1046 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { 1045 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) {
1047 GLenum storageFormat = textureToStorageFormat(format); 1046 GLenum storageFormat = textureToStorageFormat(format);
1048 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma t, size.width(), size.height())); 1047 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma t, size.width(), size.height()));
1049 } else 1048 } else
1050 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); 1049 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0));
1051 } 1050 }
1052 1051
1053 1052
1054 } // namespace cc 1053 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resource_provider.h ('k') | cc/texture_layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698