OLD | NEW |
---|---|
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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/resource_provider.h" | 7 #include "cc/resource_provider.h" |
8 | 8 |
9 #include <limits.h> | 9 #include <limits.h> |
10 | 10 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 , lockedForWrite(false) | 67 , lockedForWrite(false) |
68 , external(false) | 68 , external(false) |
69 , exported(false) | 69 , exported(false) |
70 , markedForDeletion(false) | 70 , markedForDeletion(false) |
71 , size() | 71 , size() |
72 , format(0) | 72 , format(0) |
73 , type(static_cast<ResourceType>(0)) | 73 , type(static_cast<ResourceType>(0)) |
74 { | 74 { |
75 } | 75 } |
76 | 76 |
77 ResourceProvider::Resource::Resource(unsigned textureId, int pool, const gfx::Si ze& size, GLenum format) | 77 ResourceProvider::Resource::Resource(unsigned textureId, const Mailbox& mailbox, int pool, const gfx::Size& size, GLenum format) |
78 : glId(textureId) | 78 : glId(textureId) |
79 , mailbox(mailbox) | |
79 , pixels(0) | 80 , pixels(0) |
80 , pool(pool) | 81 , pool(pool) |
81 , lockForReadCount(0) | 82 , lockForReadCount(0) |
82 , lockedForWrite(false) | 83 , lockedForWrite(false) |
83 , external(false) | 84 , external(false) |
84 , exported(false) | 85 , exported(false) |
85 , markedForDeletion(false) | 86 , markedForDeletion(false) |
86 , size(size) | 87 , size(size) |
87 , format(format) | 88 , format(format) |
88 , type(GLTexture) | 89 , type(GLTexture) |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); | 172 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); |
172 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); | 173 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); |
173 | 174 |
174 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) | 175 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) |
175 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); | 176 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); |
176 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { | 177 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { |
177 GLenum storageFormat = textureToStorageFormat(format); | 178 GLenum storageFormat = textureToStorageFormat(format); |
178 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma t, size.width(), size.height())); | 179 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma t, size.width(), size.height())); |
179 } else | 180 } else |
180 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); | 181 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); |
182 | |
183 Mailbox mailbox; | |
184 GLC(context3d, context3d->genMailboxCHROMIUM(mailbox.name)); | |
piman
2012/11/07 00:49:55
I've been thinking about this more, and I'm leanin
| |
185 | |
181 ResourceId id = m_nextId++; | 186 ResourceId id = m_nextId++; |
182 Resource resource(textureId, pool, size, format); | 187 Resource resource(textureId, mailbox, pool, size, format); |
183 m_resources[id] = resource; | 188 m_resources[id] = resource; |
184 return id; | 189 return id; |
185 } | 190 } |
186 | 191 |
187 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const gfx: :Size& size) | 192 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const gfx: :Size& size) |
188 { | 193 { |
189 DCHECK(Proxy::isImplThread()); | 194 DCHECK(Proxy::isImplThread()); |
190 | 195 |
191 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; | 196 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; |
192 | 197 |
193 ResourceId id = m_nextId++; | 198 ResourceId id = m_nextId++; |
194 Resource resource(pixels, pool, size, GL_RGBA); | 199 Resource resource(pixels, pool, size, GL_RGBA); |
195 m_resources[id] = resource; | 200 m_resources[id] = resource; |
196 return id; | 201 return id; |
197 } | 202 } |
198 | 203 |
199 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture (unsigned textureId) | 204 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture (unsigned textureId) |
200 { | 205 { |
201 DCHECK(Proxy::isImplThread()); | 206 DCHECK(Proxy::isImplThread()); |
202 DCHECK(m_context->context3D()); | 207 WebGraphicsContext3D* context3d = m_context->context3D(); |
208 DCHECK(context3d); | |
209 | |
210 Mailbox mailbox; | |
211 GLC(context3d, context3d->genMailboxCHROMIUM(mailbox.name)); | |
piman
2012/11/07 00:49:55
We don't have to do this at all here, since we won
| |
212 | |
203 ResourceId id = m_nextId++; | 213 ResourceId id = m_nextId++; |
204 Resource resource(textureId, 0, gfx::Size(), 0); | 214 Resource resource(textureId, mailbox, 0, gfx::Size(), 0); |
205 resource.external = true; | 215 resource.external = true; |
206 m_resources[id] = resource; | 216 m_resources[id] = resource; |
207 return id; | 217 return id; |
208 } | 218 } |
209 | 219 |
210 void ResourceProvider::deleteResource(ResourceId id) | 220 void ResourceProvider::deleteResource(ResourceId id) |
211 { | 221 { |
212 DCHECK(Proxy::isImplThread()); | 222 DCHECK(Proxy::isImplThread()); |
213 ResourceMap::iterator it = m_resources.find(id); | 223 ResourceMap::iterator it = m_resources.find(id); |
214 CHECK(it != m_resources.end()); | 224 CHECK(it != m_resources.end()); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
531 return child; | 541 return child; |
532 } | 542 } |
533 | 543 |
534 void ResourceProvider::destroyChild(int child) | 544 void ResourceProvider::destroyChild(int child) |
535 { | 545 { |
536 DCHECK(Proxy::isImplThread()); | 546 DCHECK(Proxy::isImplThread()); |
537 ChildMap::iterator it = m_children.find(child); | 547 ChildMap::iterator it = m_children.find(child); |
538 DCHECK(it != m_children.end()); | 548 DCHECK(it != m_children.end()); |
539 deleteOwnedResources(it->second.pool); | 549 deleteOwnedResources(it->second.pool); |
540 m_children.erase(it); | 550 m_children.erase(it); |
541 trimMailboxDeque(); | |
542 } | 551 } |
543 | 552 |
544 const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int child) const | 553 const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int child) const |
545 { | 554 { |
546 DCHECK(Proxy::isImplThread()); | 555 DCHECK(Proxy::isImplThread()); |
547 ChildMap::const_iterator it = m_children.find(child); | 556 ChildMap::const_iterator it = m_children.find(child); |
548 DCHECK(it != m_children.end()); | 557 DCHECK(it != m_children.end()); |
549 return it->second.childToParentMap; | 558 return it->second.childToParentMap; |
550 } | 559 } |
551 | 560 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
613 // (and is simpler) to wait. | 622 // (and is simpler) to wait. |
614 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); | 623 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); |
615 } | 624 } |
616 Child& childInfo = m_children.find(child)->second; | 625 Child& childInfo = m_children.find(child)->second; |
617 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) { |
618 unsigned textureId; | 627 unsigned textureId; |
619 GLC(context3d, textureId = context3d->createTexture()); | 628 GLC(context3d, textureId = context3d->createTexture()); |
620 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | 629 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); |
621 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name)); | 630 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name)); |
622 ResourceId id = m_nextId++; | 631 ResourceId id = m_nextId++; |
623 Resource resource(textureId, childInfo.pool, it->size, it->format); | 632 Resource resource(textureId, it->mailbox, childInfo.pool, it->size, it-> format); |
624 m_resources[id] = resource; | 633 m_resources[id] = resource; |
625 m_mailboxes.push_back(it->mailbox); | |
626 childInfo.parentToChildMap[id] = it->id; | 634 childInfo.parentToChildMap[id] = it->id; |
627 childInfo.childToParentMap[it->id] = id; | 635 childInfo.childToParentMap[it->id] = id; |
628 } | 636 } |
629 } | 637 } |
630 | 638 |
631 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es) | 639 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es) |
632 { | 640 { |
633 DCHECK(Proxy::isImplThread()); | 641 DCHECK(Proxy::isImplThread()); |
634 WebGraphicsContext3D* context3d = m_context->context3D(); | 642 WebGraphicsContext3D* context3d = m_context->context3D(); |
635 if (!context3d || !context3d->makeContextCurrent()) { | 643 if (!context3d || !context3d->makeContextCurrent()) { |
636 // FIXME: Implement this path for software compositing. | 644 // FIXME: Implement this path for software compositing. |
637 return; | 645 return; |
638 } | 646 } |
639 if (resources.sync_point) | 647 if (resources.sync_point) |
640 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); | 648 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); |
641 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) { | 649 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) { |
642 ResourceMap::iterator mapIterator = m_resources.find(it->id); | 650 ResourceMap::iterator mapIterator = m_resources.find(it->id); |
643 DCHECK(mapIterator != m_resources.end()); | 651 DCHECK(mapIterator != m_resources.end()); |
644 Resource* resource = &mapIterator->second; | 652 Resource* resource = &mapIterator->second; |
645 DCHECK(resource->exported); | 653 DCHECK(resource->exported); |
646 resource->exported = false; | 654 resource->exported = false; |
647 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); | 655 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); |
648 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name)); | 656 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name)); |
649 m_mailboxes.push_back(it->mailbox); | |
650 if (resource->markedForDeletion) | 657 if (resource->markedForDeletion) |
651 deleteResourceInternal(mapIterator); | 658 deleteResourceInternal(mapIterator); |
652 } | 659 } |
653 } | 660 } |
654 | 661 |
655 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource) | 662 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource) |
656 { | 663 { |
657 DCHECK(Proxy::isImplThread()); | 664 DCHECK(Proxy::isImplThread()); |
658 ResourceMap::const_iterator it = m_resources.find(id); | 665 ResourceMap::const_iterator it = m_resources.find(id); |
659 CHECK(it != m_resources.end()); | 666 CHECK(it != m_resources.end()); |
660 const Resource* source = &it->second; | 667 const Resource* source = &it->second; |
661 DCHECK(!source->lockedForWrite); | 668 DCHECK(!source->lockedForWrite); |
662 DCHECK(!source->lockForReadCount); | 669 DCHECK(!source->lockForReadCount); |
663 DCHECK(!source->external); | 670 DCHECK(!source->external); |
664 if (source->exported) | 671 if (source->exported) |
665 return false; | 672 return false; |
666 resource->id = id; | 673 resource->id = id; |
667 resource->format = source->format; | 674 resource->format = source->format; |
668 resource->size = source->size; | 675 resource->size = source->size; |
669 if (!m_mailboxes.empty()) { | 676 resource->mailbox = source->mailbox; |
670 resource->mailbox = m_mailboxes.front(); | |
671 m_mailboxes.pop_front(); | |
672 } | |
673 else | |
674 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); | |
675 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->glId)); | 677 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->glId)); |
676 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, resource->mailbo x.name)); | 678 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, resource->mailbo x.name)); |
677 return true; | 679 return true; |
678 } | 680 } |
679 | 681 |
680 void ResourceProvider::trimMailboxDeque() | |
681 { | |
682 // Trim the mailbox deque to the maximum number of resources we may need to | |
683 // send. | |
684 // If we have a parent, any non-external resource not already transfered is | |
685 // eligible to be sent to the parent. Otherwise, all resources belonging to | |
686 // a child might need to be sent back to the child. | |
687 size_t maxMailboxCount = 0; | |
688 if (m_context->capabilities().hasParentCompositor) { | |
689 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e nd(); ++it) { | |
690 if (!it->second.exported && !it->second.external) | |
691 ++maxMailboxCount; | |
692 } | |
693 } else { | |
694 base::hash_set<int> childPoolSet; | |
695 for (ChildMap::iterator it = m_children.begin(); it != m_children.end(); ++it) | |
696 childPoolSet.insert(it->second.pool); | |
697 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e nd(); ++it) { | |
698 if (ContainsKey(childPoolSet, it->second.pool)) | |
699 ++maxMailboxCount; | |
700 } | |
701 } | |
702 while (m_mailboxes.size() > maxMailboxCount) | |
703 m_mailboxes.pop_front(); | |
704 } | |
705 | |
706 void ResourceProvider::debugNotifyEnterZone(unsigned int zone) | 682 void ResourceProvider::debugNotifyEnterZone(unsigned int zone) |
707 { | 683 { |
708 g_debugZone = zone; | 684 g_debugZone = zone; |
709 } | 685 } |
710 | 686 |
711 void ResourceProvider::debugNotifyLeaveZone() | 687 void ResourceProvider::debugNotifyLeaveZone() |
712 { | 688 { |
713 g_debugZone = 0; | 689 g_debugZone = 0; |
714 } | 690 } |
715 | 691 |
716 | 692 |
717 } // namespace cc | 693 } // namespace cc |
OLD | NEW |