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

Side by Side Diff: cc/resource_provider.cc

Issue 12335088: Move sync point from TransferResourceList to individual TransferResources (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 7 years, 10 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 | 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 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 } 656 }
657 657
658 const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int child) const 658 const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int child) const
659 { 659 {
660 DCHECK(m_threadChecker.CalledOnValidThread()); 660 DCHECK(m_threadChecker.CalledOnValidThread());
661 ChildMap::const_iterator it = m_children.find(child); 661 ChildMap::const_iterator it = m_children.find(child);
662 DCHECK(it != m_children.end()); 662 DCHECK(it != m_children.end());
663 return it->second.childToParentMap; 663 return it->second.childToParentMap;
664 } 664 }
665 665
666 void ResourceProvider::prepareSendToParent(const ResourceIdArray& resources, Tra nsferableResourceList* list) 666 void ResourceProvider::prepareSendToParent(const ResourceIdArray& resources, Tra nsferableResourceArray* list)
667 { 667 {
668 DCHECK(m_threadChecker.CalledOnValidThread()); 668 DCHECK(m_threadChecker.CalledOnValidThread());
669 list->sync_point = 0; 669 list->clear();
670 list->resources.clear();
671 WebGraphicsContext3D* context3d = m_outputSurface->context3d(); 670 WebGraphicsContext3D* context3d = m_outputSurface->context3d();
672 if (!context3d || !context3d->makeContextCurrent()) { 671 if (!context3d || !context3d->makeContextCurrent()) {
673 // FIXME: Implement this path for software compositing. 672 // FIXME: Implement this path for software compositing.
674 return; 673 return;
675 } 674 }
675 bool needSyncPoint = false;
676 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources .end(); ++it) { 676 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources .end(); ++it) {
677 TransferableResource resource; 677 TransferableResource resource;
678 if (transferResource(context3d, *it, &resource)) { 678 if (transferResource(context3d, *it, &resource)) {
679 if (!resource.sync_point)
680 needSyncPoint = true;
679 m_resources.find(*it)->second.exported = true; 681 m_resources.find(*it)->second.exported = true;
680 list->resources.push_back(resource); 682 list->push_back(resource);
681 } 683 }
682 } 684 }
683 if (list->resources.size()) 685 if (needSyncPoint) {
684 list->sync_point = context3d->insertSyncPoint(); 686 unsigned int syncPoint = context3d->insertSyncPoint();
687 for (TransferableResourceArray::iterator it = list->begin(); it != list- >end(); ++it) {
688 if (!it->sync_point)
689 it->sync_point = syncPoint;
690 }
691 }
685 } 692 }
686 693
687 void ResourceProvider::prepareSendToChild(int child, const ResourceIdArray& reso urces, TransferableResourceList* list) 694 void ResourceProvider::prepareSendToChild(int child, const ResourceIdArray& reso urces, TransferableResourceArray* list)
688 { 695 {
689 DCHECK(m_threadChecker.CalledOnValidThread()); 696 DCHECK(m_threadChecker.CalledOnValidThread());
690 list->sync_point = 0; 697 list->clear();
691 list->resources.clear();
692 WebGraphicsContext3D* context3d = m_outputSurface->context3d(); 698 WebGraphicsContext3D* context3d = m_outputSurface->context3d();
693 if (!context3d || !context3d->makeContextCurrent()) { 699 if (!context3d || !context3d->makeContextCurrent()) {
694 // FIXME: Implement this path for software compositing. 700 // FIXME: Implement this path for software compositing.
695 return; 701 return;
696 } 702 }
697 Child& childInfo = m_children.find(child)->second; 703 Child& childInfo = m_children.find(child)->second;
704 bool needSyncPoint = false;
698 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources .end(); ++it) { 705 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources .end(); ++it) {
699 TransferableResource resource; 706 TransferableResource resource;
700 if (!transferResource(context3d, *it, &resource)) 707 if (!transferResource(context3d, *it, &resource))
701 NOTREACHED(); 708 NOTREACHED();
709 if (!resource.sync_point)
710 needSyncPoint = true;
702 DCHECK(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa p.end()); 711 DCHECK(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa p.end());
703 resource.id = childInfo.parentToChildMap[*it]; 712 resource.id = childInfo.parentToChildMap[*it];
704 childInfo.parentToChildMap.erase(*it); 713 childInfo.parentToChildMap.erase(*it);
705 childInfo.childToParentMap.erase(resource.id); 714 childInfo.childToParentMap.erase(resource.id);
706 list->resources.push_back(resource); 715 list->push_back(resource);
707 deleteResource(*it); 716 deleteResource(*it);
708 } 717 }
709 if (list->resources.size()) 718 if (needSyncPoint) {
710 list->sync_point = context3d->insertSyncPoint(); 719 unsigned int syncPoint = context3d->insertSyncPoint();
720 for (TransferableResourceArray::iterator it = list->begin(); it != list- >end(); ++it) {
721 if (!it->sync_point)
722 it->sync_point = syncPoint;
723 }
724 }
711 } 725 }
712 726
713 void ResourceProvider::receiveFromChild(int child, const TransferableResourceLis t& resources) 727 void ResourceProvider::receiveFromChild(int child, const TransferableResourceArr ay& resources)
714 { 728 {
715 DCHECK(m_threadChecker.CalledOnValidThread()); 729 DCHECK(m_threadChecker.CalledOnValidThread());
716 WebGraphicsContext3D* context3d = m_outputSurface->context3d(); 730 WebGraphicsContext3D* context3d = m_outputSurface->context3d();
717 if (!context3d || !context3d->makeContextCurrent()) { 731 if (!context3d || !context3d->makeContextCurrent()) {
718 // FIXME: Implement this path for software compositing. 732 // FIXME: Implement this path for software compositing.
719 return; 733 return;
720 } 734 }
721 if (resources.sync_point) { 735 Child& childInfo = m_children.find(child)->second;
736 for (TransferableResourceArray::const_iterator it = resources.begin(); it != resources.end(); ++it) {
737 unsigned textureId;
722 // NOTE: If the parent is a browser and the child a renderer, the parent 738 // NOTE: If the parent is a browser and the child a renderer, the parent
723 // is not supposed to have its context wait, because that could induce 739 // is not supposed to have its context wait, because that could induce
724 // deadlocks and/or security issues. The caller is responsible for 740 // deadlocks and/or security issues. The caller is responsible for
725 // waiting asynchronously, and resetting sync_point before calling this. 741 // waiting asynchronously, and resetting sync_point before calling this.
726 // However if the parent is a renderer (e.g. browser tag), it may be ok 742 // However if the parent is a renderer (e.g. browser tag), it may be ok
727 // (and is simpler) to wait. 743 // (and is simpler) to wait.
728 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); 744 if (it->sync_point)
729 } 745 GLC(context3d, context3d->waitSyncPoint(it->sync_point));
730 Child& childInfo = m_children.find(child)->second;
731 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) {
732 unsigned textureId;
733 GLC(context3d, textureId = context3d->createTexture()); 746 GLC(context3d, textureId = context3d->createTexture());
734 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); 747 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
735 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name)); 748 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name));
736 ResourceId id = m_nextId++; 749 ResourceId id = m_nextId++;
737 Resource resource(textureId, it->size, it->format, it->filter); 750 Resource resource(textureId, it->size, it->format, it->filter);
738 resource.mailbox.SetName(it->mailbox); 751 resource.mailbox.SetName(it->mailbox);
739 // Don't allocate a texture for a child. 752 // Don't allocate a texture for a child.
740 resource.allocated = true; 753 resource.allocated = true;
741 m_resources[id] = resource; 754 m_resources[id] = resource;
742 childInfo.parentToChildMap[id] = it->id; 755 childInfo.parentToChildMap[id] = it->id;
743 childInfo.childToParentMap[it->id] = id; 756 childInfo.childToParentMap[it->id] = id;
744 } 757 }
745 } 758 }
746 759
747 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es) 760 void ResourceProvider::receiveFromParent(const TransferableResourceArray& resour ces)
748 { 761 {
749 DCHECK(m_threadChecker.CalledOnValidThread()); 762 DCHECK(m_threadChecker.CalledOnValidThread());
750 WebGraphicsContext3D* context3d = m_outputSurface->context3d(); 763 WebGraphicsContext3D* context3d = m_outputSurface->context3d();
751 if (!context3d || !context3d->makeContextCurrent()) { 764 if (!context3d || !context3d->makeContextCurrent()) {
752 // FIXME: Implement this path for software compositing. 765 // FIXME: Implement this path for software compositing.
753 return; 766 return;
754 } 767 }
755 if (resources.sync_point) 768 for (TransferableResourceArray::const_iterator it = resources.begin(); it != resources.end(); ++it) {
756 GLC(context3d, context3d->waitSyncPoint(resources.sync_point));
757 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) {
758 ResourceMap::iterator mapIterator = m_resources.find(it->id); 769 ResourceMap::iterator mapIterator = m_resources.find(it->id);
759 DCHECK(mapIterator != m_resources.end()); 770 DCHECK(mapIterator != m_resources.end());
760 Resource* resource = &mapIterator->second; 771 Resource* resource = &mapIterator->second;
761 DCHECK(resource->exported); 772 DCHECK(resource->exported);
762 resource->exported = false; 773 resource->exported = false;
763 DCHECK(resource->mailbox.Equals(it->mailbox)); 774 DCHECK(resource->mailbox.Equals(it->mailbox));
764 if (resource->glId) { 775 if (resource->glId) {
776 if (it->sync_point)
777 GLC(context3d, context3d->waitSyncPoint(it->sync_point));
765 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); 778 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId));
766 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->ma ilbox.name)); 779 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->ma ilbox.name));
767 } else { 780 } else {
768 resource->mailbox = TextureMailbox(resource->mailbox.name(), resource- >mailbox.callback(), resources.sync_point); 781 resource->mailbox = TextureMailbox(resource->mailbox.name(), resource- >mailbox.callback(), it->sync_point);
769 } 782 }
770 if (resource->markedForDeletion) 783 if (resource->markedForDeletion)
771 deleteResourceInternal(mapIterator); 784 deleteResourceInternal(mapIterator);
772 } 785 }
773 } 786 }
774 787
775 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource) 788 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource)
776 { 789 {
777 DCHECK(m_threadChecker.CalledOnValidThread()); 790 DCHECK(m_threadChecker.CalledOnValidThread());
778 WebGraphicsContext3D* context3d = m_outputSurface->context3d(); 791 WebGraphicsContext3D* context3d = m_outputSurface->context3d();
(...skipping 13 matching lines...) Expand all
792 805
793 if (source->mailbox.IsEmpty()) { 806 if (source->mailbox.IsEmpty()) {
794 GLC(context3d, context3d->genMailboxCHROMIUM(resource->mailbox.name)); 807 GLC(context3d, context3d->genMailboxCHROMIUM(resource->mailbox.name));
795 source->mailbox.SetName(resource->mailbox); 808 source->mailbox.SetName(resource->mailbox);
796 } else 809 } else
797 resource->mailbox = source->mailbox.name(); 810 resource->mailbox = source->mailbox.name();
798 811
799 if (source->glId) { 812 if (source->glId) {
800 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->glId)); 813 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->glId));
801 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, resource->ma ilbox.name)); 814 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, resource->ma ilbox.name));
802 } else if (source->mailbox.sync_point()) { 815 } else {
803 GLC(context3d, context3d->waitSyncPoint(source->mailbox.sync_point())); 816 resource->sync_point = source->mailbox.sync_point();
804 source->mailbox.ResetSyncPoint(); 817 source->mailbox.ResetSyncPoint();
805 } 818 }
806 return true; 819 return true;
807 } 820 }
808 821
809 void ResourceProvider::acquirePixelBuffer(ResourceId id) 822 void ResourceProvider::acquirePixelBuffer(ResourceId id)
810 { 823 {
811 DCHECK(m_threadChecker.CalledOnValidThread()); 824 DCHECK(m_threadChecker.CalledOnValidThread());
812 ResourceMap::iterator it = m_resources.find(id); 825 ResourceMap::iterator it = m_resources.find(id);
813 CHECK(it != m_resources.end()); 826 CHECK(it != m_resources.end());
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 resource->enableReadLockFences = enable; 1147 resource->enableReadLockFences = enable;
1135 } 1148 }
1136 1149
1137 void ResourceProvider::setOffscreenContextProvider(scoped_refptr<cc::ContextProv ider> offscreenContextProvider) { 1150 void ResourceProvider::setOffscreenContextProvider(scoped_refptr<cc::ContextProv ider> offscreenContextProvider) {
1138 if (offscreenContextProvider) 1151 if (offscreenContextProvider)
1139 offscreenContextProvider->BindToCurrentThread(); 1152 offscreenContextProvider->BindToCurrentThread();
1140 m_offscreenContextProvider = offscreenContextProvider; 1153 m_offscreenContextProvider = offscreenContextProvider;
1141 } 1154 }
1142 1155
1143 } // namespace cc 1156 } // 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