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 "CCResourceProvider.h" | 7 #include "CCResourceProvider.h" |
8 #ifdef LOG | 8 #ifdef LOG |
9 #undef LOG | 9 #undef LOG |
10 #endif | 10 #endif |
11 | 11 |
12 #include <limits.h> | 12 #include <limits.h> |
13 | 13 |
14 #include "base/debug/alias.h" | 14 #include "base/debug/alias.h" |
15 #include "base/string_split.h" | 15 #include "base/string_split.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "cc/transferable_resource.h" |
17 #include "CCProxy.h" | 18 #include "CCProxy.h" |
18 #include "CCRendererGL.h" // For the GLC() macro. | 19 #include "CCRendererGL.h" // For the GLC() macro. |
19 #include "Extensions3DChromium.h" | 20 #include "Extensions3DChromium.h" |
20 #include "IntRect.h" | 21 #include "IntRect.h" |
21 #include "LayerTextureSubImage.h" | 22 #include "LayerTextureSubImage.h" |
22 #include "ThrottledTextureUploader.h" | 23 #include "ThrottledTextureUploader.h" |
23 #include "UnthrottledTextureUploader.h" | 24 #include "UnthrottledTextureUploader.h" |
24 #include <public/WebGraphicsContext3D.h> | 25 #include <public/WebGraphicsContext3D.h> |
25 #include <wtf/HashSet.h> | 26 #include <wtf/HashSet.h> |
26 | 27 |
(...skipping 16 matching lines...) Expand all Loading... |
43 } | 44 } |
44 | 45 |
45 return storageFormat; | 46 return storageFormat; |
46 } | 47 } |
47 | 48 |
48 static bool isTextureFormatSupportedForStorage(GC3Denum format) | 49 static bool isTextureFormatSupportedForStorage(GC3Denum format) |
49 { | 50 { |
50 return (format == GraphicsContext3D::RGBA || format == Extensions3D::BGRA_EX
T); | 51 return (format == GraphicsContext3D::RGBA || format == Extensions3D::BGRA_EX
T); |
51 } | 52 } |
52 | 53 |
53 CCResourceProvider::TransferableResourceList::TransferableResourceList() | |
54 { | |
55 } | |
56 | |
57 CCResourceProvider::TransferableResourceList::~TransferableResourceList() | |
58 { | |
59 } | |
60 | |
61 CCResourceProvider::Resource::Resource() | 54 CCResourceProvider::Resource::Resource() |
62 : glId(0) | 55 : glId(0) |
63 , pixels(0) | 56 , pixels(0) |
64 , pool(0) | 57 , pool(0) |
65 , lockForReadCount(0) | 58 , lockForReadCount(0) |
66 , lockedForWrite(false) | 59 , lockedForWrite(false) |
67 , external(false) | 60 , external(false) |
68 , exported(false) | 61 , exported(false) |
69 , deleted(false) | 62 , deleted(false) |
70 , size() | 63 , size() |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 ASSERT(CCProxy::isImplThread()); | 532 ASSERT(CCProxy::isImplThread()); |
540 ChildMap::const_iterator it = m_children.find(child); | 533 ChildMap::const_iterator it = m_children.find(child); |
541 ASSERT(it != m_children.end()); | 534 ASSERT(it != m_children.end()); |
542 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 535 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
543 return it->value.childToParentMap; | 536 return it->value.childToParentMap; |
544 #else | 537 #else |
545 return it->second.childToParentMap; | 538 return it->second.childToParentMap; |
546 #endif | 539 #endif |
547 } | 540 } |
548 | 541 |
549 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToPa
rent(const ResourceIdArray& resources) | 542 void CCResourceProvider::prepareSendToParent(const ResourceIdArray& resources, T
ransferableResourceList* list) |
550 { | 543 { |
551 ASSERT(CCProxy::isImplThread()); | 544 ASSERT(CCProxy::isImplThread()); |
552 TransferableResourceList list; | 545 list->sync_point = 0; |
553 list.syncPoint = 0; | 546 list->resources.clear(); |
554 WebGraphicsContext3D* context3d = m_context->context3D(); | 547 WebGraphicsContext3D* context3d = m_context->context3D(); |
555 if (!context3d || !context3d->makeContextCurrent()) { | 548 if (!context3d || !context3d->makeContextCurrent()) { |
556 // FIXME: Implement this path for software compositing. | 549 // FIXME: Implement this path for software compositing. |
557 return list; | 550 return; |
558 } | 551 } |
559 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 552 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
560 TransferableResource resource; | 553 TransferableResource resource; |
561 if (transferResource(context3d, *it, &resource)) { | 554 if (transferResource(context3d, *it, &resource)) { |
562 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 555 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
563 m_resources.find(*it)->value.exported = true; | 556 m_resources.find(*it)->value.exported = true; |
564 #else | 557 #else |
565 m_resources.find(*it)->second.exported = true; | 558 m_resources.find(*it)->second.exported = true; |
566 #endif | 559 #endif |
567 list.resources.append(resource); | 560 list->resources.push_back(resource); |
568 } | 561 } |
569 } | 562 } |
570 if (list.resources.size()) | 563 if (list->resources.size()) |
571 list.syncPoint = context3d->insertSyncPoint(); | 564 list->sync_point = context3d->insertSyncPoint(); |
572 return list; | |
573 } | 565 } |
574 | 566 |
575 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToCh
ild(int child, const ResourceIdArray& resources) | 567 void CCResourceProvider::prepareSendToChild(int child, const ResourceIdArray& re
sources, TransferableResourceList* list) |
576 { | 568 { |
577 ASSERT(CCProxy::isImplThread()); | 569 ASSERT(CCProxy::isImplThread()); |
578 TransferableResourceList list; | 570 list->sync_point = 0; |
579 list.syncPoint = 0; | 571 list->resources.clear(); |
580 WebGraphicsContext3D* context3d = m_context->context3D(); | 572 WebGraphicsContext3D* context3d = m_context->context3D(); |
581 if (!context3d || !context3d->makeContextCurrent()) { | 573 if (!context3d || !context3d->makeContextCurrent()) { |
582 // FIXME: Implement this path for software compositing. | 574 // FIXME: Implement this path for software compositing. |
583 return list; | 575 return; |
584 } | 576 } |
585 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 577 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
586 Child& childInfo = m_children.find(child)->value; | 578 Child& childInfo = m_children.find(child)->value; |
587 #else | 579 #else |
588 Child& childInfo = m_children.find(child)->second; | 580 Child& childInfo = m_children.find(child)->second; |
589 #endif | 581 #endif |
590 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 582 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
591 TransferableResource resource; | 583 TransferableResource resource; |
592 if (!transferResource(context3d, *it, &resource)) | 584 if (!transferResource(context3d, *it, &resource)) |
593 ASSERT_NOT_REACHED(); | 585 ASSERT_NOT_REACHED(); |
594 resource.id = childInfo.parentToChildMap.get(*it); | 586 resource.id = childInfo.parentToChildMap.get(*it); |
595 childInfo.parentToChildMap.remove(*it); | 587 childInfo.parentToChildMap.remove(*it); |
596 childInfo.childToParentMap.remove(resource.id); | 588 childInfo.childToParentMap.remove(resource.id); |
597 list.resources.append(resource); | 589 list->resources.push_back(resource); |
598 deleteResource(*it); | 590 deleteResource(*it); |
599 } | 591 } |
600 if (list.resources.size()) | 592 if (list->resources.size()) |
601 list.syncPoint = context3d->insertSyncPoint(); | 593 list->sync_point = context3d->insertSyncPoint(); |
602 return list; | |
603 } | 594 } |
604 | 595 |
605 void CCResourceProvider::receiveFromChild(int child, const TransferableResourceL
ist& resources) | 596 void CCResourceProvider::receiveFromChild(int child, const TransferableResourceL
ist& resources) |
606 { | 597 { |
607 ASSERT(CCProxy::isImplThread()); | 598 ASSERT(CCProxy::isImplThread()); |
608 WebGraphicsContext3D* context3d = m_context->context3D(); | 599 WebGraphicsContext3D* context3d = m_context->context3D(); |
609 if (!context3d || !context3d->makeContextCurrent()) { | 600 if (!context3d || !context3d->makeContextCurrent()) { |
610 // FIXME: Implement this path for software compositing. | 601 // FIXME: Implement this path for software compositing. |
611 return; | 602 return; |
612 } | 603 } |
613 if (resources.syncPoint) { | 604 if (resources.sync_point) { |
614 // NOTE: If the parent is a browser and the child a renderer, the parent | 605 // NOTE: If the parent is a browser and the child a renderer, the parent |
615 // is not supposed to have its context wait, because that could induce | 606 // is not supposed to have its context wait, because that could induce |
616 // deadlocks and/or security issues. The caller is responsible for | 607 // deadlocks and/or security issues. The caller is responsible for |
617 // waiting asynchronously, and resetting syncPoint before calling this. | 608 // waiting asynchronously, and resetting sync_point before calling this. |
618 // However if the parent is a renderer (e.g. browser tag), it may be ok | 609 // However if the parent is a renderer (e.g. browser tag), it may be ok |
619 // (and is simpler) to wait. | 610 // (and is simpler) to wait. |
620 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); | 611 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); |
621 } | 612 } |
622 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 613 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
623 Child& childInfo = m_children.find(child)->value; | 614 Child& childInfo = m_children.find(child)->value; |
624 #else | 615 #else |
625 Child& childInfo = m_children.find(child)->second; | 616 Child& childInfo = m_children.find(child)->second; |
626 #endif | 617 #endif |
627 for (Vector<TransferableResource>::const_iterator it = resources.resources.b
egin(); it != resources.resources.end(); ++it) { | 618 for (std::vector<TransferableResource>::const_iterator it = resources.resour
ces.begin(); it != resources.resources.end(); ++it) { |
628 unsigned textureId; | 619 unsigned textureId; |
629 GLC(context3d, textureId = context3d->createTexture()); | 620 GLC(context3d, textureId = context3d->createTexture()); |
630 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, tex
tureId)); | 621 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, tex
tureId)); |
631 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); | 622 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); |
632 ResourceId id = m_nextId++; | 623 ResourceId id = m_nextId++; |
633 Resource resource(textureId, childInfo.pool, it->size, it->format); | 624 Resource resource(textureId, childInfo.pool, IntSize(it->size.width(), i
t->size.height()), it->format); |
634 m_resources.add(id, resource); | 625 m_resources.add(id, resource); |
635 m_mailboxes.append(it->mailbox); | 626 m_mailboxes.append(it->mailbox); |
636 childInfo.parentToChildMap.add(id, it->id); | 627 childInfo.parentToChildMap.add(id, it->id); |
637 childInfo.childToParentMap.add(it->id, id); | 628 childInfo.childToParentMap.add(it->id, id); |
638 } | 629 } |
639 } | 630 } |
640 | 631 |
641 void CCResourceProvider::receiveFromParent(const TransferableResourceList& resou
rces) | 632 void CCResourceProvider::receiveFromParent(const TransferableResourceList& resou
rces) |
642 { | 633 { |
643 ASSERT(CCProxy::isImplThread()); | 634 ASSERT(CCProxy::isImplThread()); |
644 WebGraphicsContext3D* context3d = m_context->context3D(); | 635 WebGraphicsContext3D* context3d = m_context->context3D(); |
645 if (!context3d || !context3d->makeContextCurrent()) { | 636 if (!context3d || !context3d->makeContextCurrent()) { |
646 // FIXME: Implement this path for software compositing. | 637 // FIXME: Implement this path for software compositing. |
647 return; | 638 return; |
648 } | 639 } |
649 if (resources.syncPoint) | 640 if (resources.sync_point) |
650 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); | 641 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); |
651 for (Vector<TransferableResource>::const_iterator it = resources.resources.b
egin(); it != resources.resources.end(); ++it) { | 642 for (std::vector<TransferableResource>::const_iterator it = resources.resour
ces.begin(); it != resources.resources.end(); ++it) { |
652 ResourceMap::iterator mapIterator = m_resources.find(it->id); | 643 ResourceMap::iterator mapIterator = m_resources.find(it->id); |
653 ASSERT(mapIterator != m_resources.end()); | 644 ASSERT(mapIterator != m_resources.end()); |
654 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 645 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
655 Resource* resource = &mapIterator->value; | 646 Resource* resource = &mapIterator->value; |
656 #else | 647 #else |
657 Resource* resource = &mapIterator->second; | 648 Resource* resource = &mapIterator->second; |
658 #endif | 649 #endif |
659 ASSERT(resource->exported); | 650 ASSERT(resource->exported); |
660 resource->exported = false; | 651 resource->exported = false; |
661 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, res
ource->glId)); | 652 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, res
ource->glId)); |
(...skipping 14 matching lines...) Expand all Loading... |
676 #else | 667 #else |
677 const Resource* source = &it->second; | 668 const Resource* source = &it->second; |
678 #endif | 669 #endif |
679 ASSERT(!source->lockedForWrite); | 670 ASSERT(!source->lockedForWrite); |
680 ASSERT(!source->lockForReadCount); | 671 ASSERT(!source->lockForReadCount); |
681 ASSERT(!source->external); | 672 ASSERT(!source->external); |
682 if (source->exported) | 673 if (source->exported) |
683 return false; | 674 return false; |
684 resource->id = id; | 675 resource->id = id; |
685 resource->format = source->format; | 676 resource->format = source->format; |
686 resource->size = source->size; | 677 resource->size = gfx::Size(source->size.height(), source->size.width()); |
687 if (!m_mailboxes.isEmpty()) | 678 if (!m_mailboxes.isEmpty()) |
688 resource->mailbox = m_mailboxes.takeFirst(); | 679 resource->mailbox = m_mailboxes.takeFirst(); |
689 else | 680 else |
690 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); | 681 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); |
691 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, source->glI
d)); | 682 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, source->glI
d)); |
692 GLC(context, context->produceTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D,
resource->mailbox.name)); | 683 GLC(context, context->produceTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D,
resource->mailbox.name)); |
693 return true; | 684 return true; |
694 } | 685 } |
695 | 686 |
696 void CCResourceProvider::trimMailboxDeque() | 687 void CCResourceProvider::trimMailboxDeque() |
(...skipping 28 matching lines...) Expand all Loading... |
725 if (childPoolSet.contains(it->second.pool)) | 716 if (childPoolSet.contains(it->second.pool)) |
726 #endif | 717 #endif |
727 ++maxMailboxCount; | 718 ++maxMailboxCount; |
728 } | 719 } |
729 } | 720 } |
730 while (m_mailboxes.size() > maxMailboxCount) | 721 while (m_mailboxes.size() > maxMailboxCount) |
731 m_mailboxes.removeFirst(); | 722 m_mailboxes.removeFirst(); |
732 } | 723 } |
733 | 724 |
734 } | 725 } |
OLD | NEW |