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 |
11 #include "base/debug/alias.h" | 11 #include "base/debug/alias.h" |
12 #include "base/hash_tables.h" | 12 #include "base/hash_tables.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/string_split.h" | 14 #include "base/string_split.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "cc/gl_renderer.h" // For the GLC() macro. | 16 #include "cc/gl_renderer.h" // For the GLC() macro. |
17 #include "cc/proxy.h" | 17 #include "cc/proxy.h" |
18 #include "cc/texture_uploader.h" | 18 #include "cc/texture_uploader.h" |
| 19 #include "cc/transferable_resource.h" |
19 #include "third_party/khronos/GLES2/gl2.h" | 20 #include "third_party/khronos/GLES2/gl2.h" |
20 #include "third_party/khronos/GLES2/gl2ext.h" | 21 #include "third_party/khronos/GLES2/gl2ext.h" |
21 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
22 #include "ui/gfx/vector2d.h" | 23 #include "ui/gfx/vector2d.h" |
23 | 24 |
24 #include <public/WebGraphicsContext3D.h> | 25 #include <public/WebGraphicsContext3D.h> |
25 | 26 |
26 using WebKit::WebGraphicsContext3D; | 27 using WebKit::WebGraphicsContext3D; |
27 | 28 |
28 namespace { | 29 namespace { |
(...skipping 22 matching lines...) Expand all Loading... |
51 } | 52 } |
52 | 53 |
53 return storageFormat; | 54 return storageFormat; |
54 } | 55 } |
55 | 56 |
56 static bool isTextureFormatSupportedForStorage(GLenum format) | 57 static bool isTextureFormatSupportedForStorage(GLenum format) |
57 { | 58 { |
58 return (format == GL_RGBA || format == GL_BGRA_EXT); | 59 return (format == GL_RGBA || format == GL_BGRA_EXT); |
59 } | 60 } |
60 | 61 |
61 ResourceProvider::TransferableResourceList::TransferableResourceList() | |
62 { | |
63 } | |
64 | |
65 ResourceProvider::TransferableResourceList::~TransferableResourceList() | |
66 { | |
67 } | |
68 | |
69 ResourceProvider::Resource::Resource() | 62 ResourceProvider::Resource::Resource() |
70 : glId(0) | 63 : glId(0) |
71 , pixels(0) | 64 , pixels(0) |
72 , pool(0) | 65 , pool(0) |
73 , lockForReadCount(0) | 66 , lockForReadCount(0) |
74 , lockedForWrite(false) | 67 , lockedForWrite(false) |
75 , external(false) | 68 , external(false) |
76 , exported(false) | 69 , exported(false) |
77 , markedForDeletion(false) | 70 , markedForDeletion(false) |
78 , size() | 71 , size() |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 } | 534 } |
542 | 535 |
543 const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int
child) const | 536 const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int
child) const |
544 { | 537 { |
545 DCHECK(Proxy::isImplThread()); | 538 DCHECK(Proxy::isImplThread()); |
546 ChildMap::const_iterator it = m_children.find(child); | 539 ChildMap::const_iterator it = m_children.find(child); |
547 DCHECK(it != m_children.end()); | 540 DCHECK(it != m_children.end()); |
548 return it->second.childToParentMap; | 541 return it->second.childToParentMap; |
549 } | 542 } |
550 | 543 |
551 ResourceProvider::TransferableResourceList ResourceProvider::prepareSendToParent
(const ResourceIdArray& resources) | 544 void ResourceProvider::prepareSendToParent(const ResourceIdArray& resources, Tra
nsferableResourceList* list) |
552 { | 545 { |
553 DCHECK(Proxy::isImplThread()); | 546 DCHECK(Proxy::isImplThread()); |
554 TransferableResourceList list; | 547 list->sync_point = 0; |
555 list.syncPoint = 0; | 548 list->resources.clear(); |
556 WebGraphicsContext3D* context3d = m_context->context3D(); | 549 WebGraphicsContext3D* context3d = m_context->context3D(); |
557 if (!context3d || !context3d->makeContextCurrent()) { | 550 if (!context3d || !context3d->makeContextCurrent()) { |
558 // FIXME: Implement this path for software compositing. | 551 // FIXME: Implement this path for software compositing. |
559 return list; | 552 return; |
560 } | 553 } |
561 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 554 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
562 TransferableResource resource; | 555 TransferableResource resource; |
563 if (transferResource(context3d, *it, &resource)) { | 556 if (transferResource(context3d, *it, &resource)) { |
564 m_resources.find(*it)->second.exported = true; | 557 m_resources.find(*it)->second.exported = true; |
565 list.resources.push_back(resource); | 558 list->resources.push_back(resource); |
566 } | 559 } |
567 } | 560 } |
568 if (list.resources.size()) | 561 if (list->resources.size()) |
569 list.syncPoint = context3d->insertSyncPoint(); | 562 list->sync_point = context3d->insertSyncPoint(); |
570 return list; | |
571 } | 563 } |
572 | 564 |
573 ResourceProvider::TransferableResourceList ResourceProvider::prepareSendToChild(
int child, const ResourceIdArray& resources) | 565 void ResourceProvider::prepareSendToChild(int child, const ResourceIdArray& reso
urces, TransferableResourceList* list) |
574 { | 566 { |
575 DCHECK(Proxy::isImplThread()); | 567 DCHECK(Proxy::isImplThread()); |
576 TransferableResourceList list; | 568 list->sync_point = 0; |
577 list.syncPoint = 0; | 569 list->resources.clear(); |
578 WebGraphicsContext3D* context3d = m_context->context3D(); | 570 WebGraphicsContext3D* context3d = m_context->context3D(); |
579 if (!context3d || !context3d->makeContextCurrent()) { | 571 if (!context3d || !context3d->makeContextCurrent()) { |
580 // FIXME: Implement this path for software compositing. | 572 // FIXME: Implement this path for software compositing. |
581 return list; | 573 return; |
582 } | 574 } |
583 Child& childInfo = m_children.find(child)->second; | 575 Child& childInfo = m_children.find(child)->second; |
584 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 576 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
585 TransferableResource resource; | 577 TransferableResource resource; |
586 if (!transferResource(context3d, *it, &resource)) | 578 if (!transferResource(context3d, *it, &resource)) |
587 NOTREACHED(); | 579 NOTREACHED(); |
588 DCHECK(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa
p.end()); | 580 DCHECK(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa
p.end()); |
589 resource.id = childInfo.parentToChildMap[*it]; | 581 resource.id = childInfo.parentToChildMap[*it]; |
590 childInfo.parentToChildMap.erase(*it); | 582 childInfo.parentToChildMap.erase(*it); |
591 childInfo.childToParentMap.erase(resource.id); | 583 childInfo.childToParentMap.erase(resource.id); |
592 list.resources.push_back(resource); | 584 list->resources.push_back(resource); |
593 deleteResource(*it); | 585 deleteResource(*it); |
594 } | 586 } |
595 if (list.resources.size()) | 587 if (list->resources.size()) |
596 list.syncPoint = context3d->insertSyncPoint(); | 588 list->sync_point = context3d->insertSyncPoint(); |
597 return list; | |
598 } | 589 } |
599 | 590 |
600 void ResourceProvider::receiveFromChild(int child, const TransferableResourceLis
t& resources) | 591 void ResourceProvider::receiveFromChild(int child, const TransferableResourceLis
t& resources) |
601 { | 592 { |
602 DCHECK(Proxy::isImplThread()); | 593 DCHECK(Proxy::isImplThread()); |
603 WebGraphicsContext3D* context3d = m_context->context3D(); | 594 WebGraphicsContext3D* context3d = m_context->context3D(); |
604 if (!context3d || !context3d->makeContextCurrent()) { | 595 if (!context3d || !context3d->makeContextCurrent()) { |
605 // FIXME: Implement this path for software compositing. | 596 // FIXME: Implement this path for software compositing. |
606 return; | 597 return; |
607 } | 598 } |
608 if (resources.syncPoint) { | 599 if (resources.sync_point) { |
609 // NOTE: If the parent is a browser and the child a renderer, the parent | 600 // NOTE: If the parent is a browser and the child a renderer, the parent |
610 // is not supposed to have its context wait, because that could induce | 601 // is not supposed to have its context wait, because that could induce |
611 // deadlocks and/or security issues. The caller is responsible for | 602 // deadlocks and/or security issues. The caller is responsible for |
612 // waiting asynchronously, and resetting syncPoint before calling this. | 603 // waiting asynchronously, and resetting sync_point before calling this. |
613 // However if the parent is a renderer (e.g. browser tag), it may be ok | 604 // However if the parent is a renderer (e.g. browser tag), it may be ok |
614 // (and is simpler) to wait. | 605 // (and is simpler) to wait. |
615 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); | 606 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); |
616 } | 607 } |
617 Child& childInfo = m_children.find(child)->second; | 608 Child& childInfo = m_children.find(child)->second; |
618 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { | 609 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { |
619 unsigned textureId; | 610 unsigned textureId; |
620 GLC(context3d, textureId = context3d->createTexture()); | 611 GLC(context3d, textureId = context3d->createTexture()); |
621 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | 612 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); |
622 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail
box.name)); | 613 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail
box.name)); |
623 ResourceId id = m_nextId++; | 614 ResourceId id = m_nextId++; |
624 Resource resource(textureId, childInfo.pool, it->size, it->format); | 615 Resource resource(textureId, childInfo.pool, it->size, it->format); |
625 m_resources[id] = resource; | 616 m_resources[id] = resource; |
626 m_mailboxes.push_back(it->mailbox); | 617 m_mailboxes.push_back(it->mailbox); |
627 childInfo.parentToChildMap[id] = it->id; | 618 childInfo.parentToChildMap[id] = it->id; |
628 childInfo.childToParentMap[it->id] = id; | 619 childInfo.childToParentMap[it->id] = id; |
629 } | 620 } |
630 } | 621 } |
631 | 622 |
632 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc
es) | 623 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc
es) |
633 { | 624 { |
634 DCHECK(Proxy::isImplThread()); | 625 DCHECK(Proxy::isImplThread()); |
635 WebGraphicsContext3D* context3d = m_context->context3D(); | 626 WebGraphicsContext3D* context3d = m_context->context3D(); |
636 if (!context3d || !context3d->makeContextCurrent()) { | 627 if (!context3d || !context3d->makeContextCurrent()) { |
637 // FIXME: Implement this path for software compositing. | 628 // FIXME: Implement this path for software compositing. |
638 return; | 629 return; |
639 } | 630 } |
640 if (resources.syncPoint) | 631 if (resources.sync_point) |
641 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); | 632 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); |
642 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { | 633 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { |
643 ResourceMap::iterator mapIterator = m_resources.find(it->id); | 634 ResourceMap::iterator mapIterator = m_resources.find(it->id); |
644 DCHECK(mapIterator != m_resources.end()); | 635 DCHECK(mapIterator != m_resources.end()); |
645 Resource* resource = &mapIterator->second; | 636 Resource* resource = &mapIterator->second; |
646 DCHECK(resource->exported); | 637 DCHECK(resource->exported); |
647 resource->exported = false; | 638 resource->exported = false; |
648 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); | 639 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); |
649 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail
box.name)); | 640 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail
box.name)); |
650 m_mailboxes.push_back(it->mailbox); | 641 m_mailboxes.push_back(it->mailbox); |
651 if (resource->markedForDeletion) | 642 if (resource->markedForDeletion) |
652 deleteResourceInternal(mapIterator); | 643 deleteResourceInternal(mapIterator); |
653 } | 644 } |
654 } | 645 } |
655 | 646 |
656 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI
d id, TransferableResource* resource) | 647 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI
d id, TransferableResource* resource) |
657 { | 648 { |
658 DCHECK(Proxy::isImplThread()); | 649 DCHECK(Proxy::isImplThread()); |
659 ResourceMap::const_iterator it = m_resources.find(id); | 650 ResourceMap::const_iterator it = m_resources.find(id); |
660 CHECK(it != m_resources.end()); | 651 CHECK(it != m_resources.end()); |
661 const Resource* source = &it->second; | 652 const Resource* source = &it->second; |
662 DCHECK(!source->lockedForWrite); | 653 DCHECK(!source->lockedForWrite); |
663 DCHECK(!source->lockForReadCount); | 654 DCHECK(!source->lockForReadCount); |
664 DCHECK(!source->external); | 655 DCHECK(!source->external); |
665 if (source->exported) | 656 if (source->exported) |
666 return false; | 657 return false; |
667 resource->id = id; | 658 resource->id = id; |
668 resource->format = source->format; | 659 resource->format = source->format; |
669 resource->size = source->size; | 660 resource->size = source->size; |
670 if (m_mailboxes.size()) { | 661 if (!m_mailboxes.empty()) { |
671 resource->mailbox = m_mailboxes.front(); | 662 resource->mailbox = m_mailboxes.front(); |
672 m_mailboxes.pop_front(); | 663 m_mailboxes.pop_front(); |
673 } | 664 } |
674 else | 665 else |
675 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); | 666 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); |
676 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->glId)); | 667 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->glId)); |
677 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, resource->mailbo
x.name)); | 668 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, resource->mailbo
x.name)); |
678 return true; | 669 return true; |
679 } | 670 } |
680 | 671 |
(...skipping 28 matching lines...) Expand all Loading... |
709 g_debugZone = zone; | 700 g_debugZone = zone; |
710 } | 701 } |
711 | 702 |
712 void ResourceProvider::debugNotifyLeaveZone() | 703 void ResourceProvider::debugNotifyLeaveZone() |
713 { | 704 { |
714 g_debugZone = 0; | 705 g_debugZone = 0; |
715 } | 706 } |
716 | 707 |
717 | 708 |
718 } | 709 } |
OLD | NEW |