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 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 } | 105 } |
106 | 106 |
107 CCResourceProvider::Child::Child() | 107 CCResourceProvider::Child::Child() |
108 { | 108 { |
109 } | 109 } |
110 | 110 |
111 CCResourceProvider::Child::~Child() | 111 CCResourceProvider::Child::~Child() |
112 { | 112 { |
113 } | 113 } |
114 | 114 |
115 PassOwnPtr<CCResourceProvider> CCResourceProvider::create(CCGraphicsContext* con
text) | 115 scoped_ptr<CCResourceProvider> CCResourceProvider::create(CCGraphicsContext* con
text) |
116 { | 116 { |
117 OwnPtr<CCResourceProvider> resourceProvider(adoptPtr(new CCResourceProvider(
context))); | 117 scoped_ptr<CCResourceProvider> resourceProvider(new CCResourceProvider(conte
xt)); |
118 if (!resourceProvider->initialize()) | 118 if (!resourceProvider->initialize()) |
119 return nullptr; | 119 return scoped_ptr<CCResourceProvider>(); |
120 return resourceProvider.release(); | 120 return resourceProvider.Pass(); |
121 } | 121 } |
122 | 122 |
123 CCResourceProvider::~CCResourceProvider() | 123 CCResourceProvider::~CCResourceProvider() |
124 { | 124 { |
125 WebGraphicsContext3D* context3d = m_context->context3D(); | 125 WebGraphicsContext3D* context3d = m_context->context3D(); |
126 if (!context3d || !context3d->makeContextCurrent()) | 126 if (!context3d || !context3d->makeContextCurrent()) |
127 return; | 127 return; |
128 m_textureUploader.clear(); | 128 m_textureUploader.reset(); |
129 m_textureCopier.clear(); | 129 m_textureCopier.reset(); |
130 } | 130 } |
131 | 131 |
132 WebGraphicsContext3D* CCResourceProvider::graphicsContext3D() | 132 WebGraphicsContext3D* CCResourceProvider::graphicsContext3D() |
133 { | 133 { |
134 ASSERT(CCProxy::isImplThread()); | 134 ASSERT(CCProxy::isImplThread()); |
135 return m_context->context3D(); | 135 return m_context->context3D(); |
136 } | 136 } |
137 | 137 |
138 bool CCResourceProvider::inUseByConsumer(ResourceId id) | 138 bool CCResourceProvider::inUseByConsumer(ResourceId id) |
139 { | 139 { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 237 |
238 m_resources.erase(it); | 238 m_resources.erase(it); |
239 } | 239 } |
240 | 240 |
241 void CCResourceProvider::deleteOwnedResources(int pool) | 241 void CCResourceProvider::deleteOwnedResources(int pool) |
242 { | 242 { |
243 ASSERT(CCProxy::isImplThread()); | 243 ASSERT(CCProxy::isImplThread()); |
244 ResourceIdArray toDelete; | 244 ResourceIdArray toDelete; |
245 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end()
; ++it) { | 245 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end()
; ++it) { |
246 if (it->second.pool == pool && !it->second.external && !it->second.marke
dForDeletion) | 246 if (it->second.pool == pool && !it->second.external && !it->second.marke
dForDeletion) |
247 toDelete.append(it->first); | 247 toDelete.push_back(it->first); |
248 } | 248 } |
249 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end();
++it) | 249 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end();
++it) |
250 deleteResource(*it); | 250 deleteResource(*it); |
251 } | 251 } |
252 | 252 |
253 CCResourceProvider::ResourceType CCResourceProvider::resourceType(ResourceId id) | 253 CCResourceProvider::ResourceType CCResourceProvider::resourceType(ResourceId id) |
254 { | 254 { |
255 ResourceMap::iterator it = m_resources.find(id); | 255 ResourceMap::iterator it = m_resources.find(id); |
256 CHECK(it != m_resources.end()); | 256 CHECK(it != m_resources.end()); |
257 Resource* resource = &it->second; | 257 Resource* resource = &it->second; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 CCResourceProvider::ScopedReadLockSoftware::~ScopedReadLockSoftware() | 405 CCResourceProvider::ScopedReadLockSoftware::~ScopedReadLockSoftware() |
406 { | 406 { |
407 m_resourceProvider->unlockForRead(m_resourceId); | 407 m_resourceProvider->unlockForRead(m_resourceId); |
408 } | 408 } |
409 | 409 |
410 CCResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware(CCResourceP
rovider* resourceProvider, CCResourceProvider::ResourceId resourceId) | 410 CCResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware(CCResourceP
rovider* resourceProvider, CCResourceProvider::ResourceId resourceId) |
411 : m_resourceProvider(resourceProvider) | 411 : m_resourceProvider(resourceProvider) |
412 , m_resourceId(resourceId) | 412 , m_resourceId(resourceId) |
413 { | 413 { |
414 CCResourceProvider::populateSkBitmapWithResource(&m_skBitmap, resourceProvid
er->lockForWrite(resourceId)); | 414 CCResourceProvider::populateSkBitmapWithResource(&m_skBitmap, resourceProvid
er->lockForWrite(resourceId)); |
415 m_skCanvas = adoptPtr(new SkCanvas(m_skBitmap)); | 415 m_skCanvas.reset(new SkCanvas(m_skBitmap)); |
416 } | 416 } |
417 | 417 |
418 CCResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() | 418 CCResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() |
419 { | 419 { |
420 m_resourceProvider->unlockForWrite(m_resourceId); | 420 m_resourceProvider->unlockForWrite(m_resourceId); |
421 } | 421 } |
422 | 422 |
423 CCResourceProvider::CCResourceProvider(CCGraphicsContext* context) | 423 CCResourceProvider::CCResourceProvider(CCGraphicsContext* context) |
424 : m_context(context) | 424 : m_context(context) |
425 , m_nextId(1) | 425 , m_nextId(1) |
(...skipping 29 matching lines...) Expand all Loading... |
455 else if (extensions[i] == "GL_ANGLE_texture_usage") | 455 else if (extensions[i] == "GL_ANGLE_texture_usage") |
456 m_useTextureUsageHint = true; | 456 m_useTextureUsageHint = true; |
457 else if (extensions[i] == "GL_CHROMIUM_map_sub") | 457 else if (extensions[i] == "GL_CHROMIUM_map_sub") |
458 useMapSub = true; | 458 useMapSub = true; |
459 else if (extensions[i] == "GL_CHROMIUM_shallow_flush") | 459 else if (extensions[i] == "GL_CHROMIUM_shallow_flush") |
460 m_useShallowFlush = true; | 460 m_useShallowFlush = true; |
461 else if (extensions[i] == "GL_CHROMIUM_bind_uniform_location") | 461 else if (extensions[i] == "GL_CHROMIUM_bind_uniform_location") |
462 useBindUniform = true; | 462 useBindUniform = true; |
463 } | 463 } |
464 | 464 |
465 m_texSubImage = adoptPtr(new LayerTextureSubImage(useMapSub)); | 465 m_texSubImage.reset(new LayerTextureSubImage(useMapSub)); |
466 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform
); | 466 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform
); |
467 | 467 |
468 m_textureUploader = ThrottledTextureUploader::create(context3d); | 468 m_textureUploader = ThrottledTextureUploader::create(context3d); |
469 GLC(context3d, context3d->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &
m_maxTextureSize)); | 469 GLC(context3d, context3d->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &
m_maxTextureSize)); |
470 return true; | 470 return true; |
471 } | 471 } |
472 | 472 |
473 int CCResourceProvider::createChild(int pool) | 473 int CCResourceProvider::createChild(int pool) |
474 { | 474 { |
475 ASSERT(CCProxy::isImplThread()); | 475 ASSERT(CCProxy::isImplThread()); |
(...skipping 29 matching lines...) Expand all Loading... |
505 list.syncPoint = 0; | 505 list.syncPoint = 0; |
506 WebGraphicsContext3D* context3d = m_context->context3D(); | 506 WebGraphicsContext3D* context3d = m_context->context3D(); |
507 if (!context3d || !context3d->makeContextCurrent()) { | 507 if (!context3d || !context3d->makeContextCurrent()) { |
508 // FIXME: Implement this path for software compositing. | 508 // FIXME: Implement this path for software compositing. |
509 return list; | 509 return list; |
510 } | 510 } |
511 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 511 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
512 TransferableResource resource; | 512 TransferableResource resource; |
513 if (transferResource(context3d, *it, &resource)) { | 513 if (transferResource(context3d, *it, &resource)) { |
514 m_resources.find(*it)->second.exported = true; | 514 m_resources.find(*it)->second.exported = true; |
515 list.resources.append(resource); | 515 list.resources.push_back(resource); |
516 } | 516 } |
517 } | 517 } |
518 if (list.resources.size()) | 518 if (list.resources.size()) |
519 list.syncPoint = context3d->insertSyncPoint(); | 519 list.syncPoint = context3d->insertSyncPoint(); |
520 return list; | 520 return list; |
521 } | 521 } |
522 | 522 |
523 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToCh
ild(int child, const ResourceIdArray& resources) | 523 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToCh
ild(int child, const ResourceIdArray& resources) |
524 { | 524 { |
525 ASSERT(CCProxy::isImplThread()); | 525 ASSERT(CCProxy::isImplThread()); |
526 TransferableResourceList list; | 526 TransferableResourceList list; |
527 list.syncPoint = 0; | 527 list.syncPoint = 0; |
528 WebGraphicsContext3D* context3d = m_context->context3D(); | 528 WebGraphicsContext3D* context3d = m_context->context3D(); |
529 if (!context3d || !context3d->makeContextCurrent()) { | 529 if (!context3d || !context3d->makeContextCurrent()) { |
530 // FIXME: Implement this path for software compositing. | 530 // FIXME: Implement this path for software compositing. |
531 return list; | 531 return list; |
532 } | 532 } |
533 Child& childInfo = m_children.find(child)->second; | 533 Child& childInfo = m_children.find(child)->second; |
534 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 534 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
535 TransferableResource resource; | 535 TransferableResource resource; |
536 if (!transferResource(context3d, *it, &resource)) | 536 if (!transferResource(context3d, *it, &resource)) |
537 ASSERT_NOT_REACHED(); | 537 ASSERT_NOT_REACHED(); |
538 ASSERT(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa
p.end()); | 538 ASSERT(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa
p.end()); |
539 resource.id = childInfo.parentToChildMap[*it]; | 539 resource.id = childInfo.parentToChildMap[*it]; |
540 childInfo.parentToChildMap.erase(*it); | 540 childInfo.parentToChildMap.erase(*it); |
541 childInfo.childToParentMap.erase(resource.id); | 541 childInfo.childToParentMap.erase(resource.id); |
542 list.resources.append(resource); | 542 list.resources.push_back(resource); |
543 deleteResource(*it); | 543 deleteResource(*it); |
544 } | 544 } |
545 if (list.resources.size()) | 545 if (list.resources.size()) |
546 list.syncPoint = context3d->insertSyncPoint(); | 546 list.syncPoint = context3d->insertSyncPoint(); |
547 return list; | 547 return list; |
548 } | 548 } |
549 | 549 |
550 void CCResourceProvider::receiveFromChild(int child, const TransferableResourceL
ist& resources) | 550 void CCResourceProvider::receiveFromChild(int child, const TransferableResourceL
ist& resources) |
551 { | 551 { |
552 ASSERT(CCProxy::isImplThread()); | 552 ASSERT(CCProxy::isImplThread()); |
553 WebGraphicsContext3D* context3d = m_context->context3D(); | 553 WebGraphicsContext3D* context3d = m_context->context3D(); |
554 if (!context3d || !context3d->makeContextCurrent()) { | 554 if (!context3d || !context3d->makeContextCurrent()) { |
555 // FIXME: Implement this path for software compositing. | 555 // FIXME: Implement this path for software compositing. |
556 return; | 556 return; |
557 } | 557 } |
558 if (resources.syncPoint) { | 558 if (resources.syncPoint) { |
559 // NOTE: If the parent is a browser and the child a renderer, the parent | 559 // NOTE: If the parent is a browser and the child a renderer, the parent |
560 // is not supposed to have its context wait, because that could induce | 560 // is not supposed to have its context wait, because that could induce |
561 // deadlocks and/or security issues. The caller is responsible for | 561 // deadlocks and/or security issues. The caller is responsible for |
562 // waiting asynchronously, and resetting syncPoint before calling this. | 562 // waiting asynchronously, and resetting syncPoint before calling this. |
563 // However if the parent is a renderer (e.g. browser tag), it may be ok | 563 // However if the parent is a renderer (e.g. browser tag), it may be ok |
564 // (and is simpler) to wait. | 564 // (and is simpler) to wait. |
565 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); | 565 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); |
566 } | 566 } |
567 Child& childInfo = m_children.find(child)->second; | 567 Child& childInfo = m_children.find(child)->second; |
568 for (Vector<TransferableResource>::const_iterator it = resources.resources.b
egin(); it != resources.resources.end(); ++it) { | 568 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { |
569 unsigned textureId; | 569 unsigned textureId; |
570 GLC(context3d, textureId = context3d->createTexture()); | 570 GLC(context3d, textureId = context3d->createTexture()); |
571 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, tex
tureId)); | 571 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, tex
tureId)); |
572 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); | 572 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); |
573 ResourceId id = m_nextId++; | 573 ResourceId id = m_nextId++; |
574 Resource resource(textureId, childInfo.pool, it->size, it->format); | 574 Resource resource(textureId, childInfo.pool, it->size, it->format); |
575 m_resources[id] = resource; | 575 m_resources[id] = resource; |
576 m_mailboxes.append(it->mailbox); | 576 m_mailboxes.push_back(it->mailbox); |
577 childInfo.parentToChildMap[id] = it->id; | 577 childInfo.parentToChildMap[id] = it->id; |
578 childInfo.childToParentMap[it->id] = id; | 578 childInfo.childToParentMap[it->id] = id; |
579 } | 579 } |
580 } | 580 } |
581 | 581 |
582 void CCResourceProvider::receiveFromParent(const TransferableResourceList& resou
rces) | 582 void CCResourceProvider::receiveFromParent(const TransferableResourceList& resou
rces) |
583 { | 583 { |
584 ASSERT(CCProxy::isImplThread()); | 584 ASSERT(CCProxy::isImplThread()); |
585 WebGraphicsContext3D* context3d = m_context->context3D(); | 585 WebGraphicsContext3D* context3d = m_context->context3D(); |
586 if (!context3d || !context3d->makeContextCurrent()) { | 586 if (!context3d || !context3d->makeContextCurrent()) { |
587 // FIXME: Implement this path for software compositing. | 587 // FIXME: Implement this path for software compositing. |
588 return; | 588 return; |
589 } | 589 } |
590 if (resources.syncPoint) | 590 if (resources.syncPoint) |
591 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); | 591 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); |
592 for (Vector<TransferableResource>::const_iterator it = resources.resources.b
egin(); it != resources.resources.end(); ++it) { | 592 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { |
593 ResourceMap::iterator mapIterator = m_resources.find(it->id); | 593 ResourceMap::iterator mapIterator = m_resources.find(it->id); |
594 ASSERT(mapIterator != m_resources.end()); | 594 ASSERT(mapIterator != m_resources.end()); |
595 Resource* resource = &mapIterator->second; | 595 Resource* resource = &mapIterator->second; |
596 ASSERT(resource->exported); | 596 ASSERT(resource->exported); |
597 resource->exported = false; | 597 resource->exported = false; |
598 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, res
ource->glId)); | 598 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, res
ource->glId)); |
599 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); | 599 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); |
600 m_mailboxes.append(it->mailbox); | 600 m_mailboxes.push_back(it->mailbox); |
601 if (resource->markedForDeletion) | 601 if (resource->markedForDeletion) |
602 deleteResourceInternal(mapIterator); | 602 deleteResourceInternal(mapIterator); |
603 } | 603 } |
604 } | 604 } |
605 | 605 |
606 bool CCResourceProvider::transferResource(WebGraphicsContext3D* context, Resourc
eId id, TransferableResource* resource) | 606 bool CCResourceProvider::transferResource(WebGraphicsContext3D* context, Resourc
eId id, TransferableResource* resource) |
607 { | 607 { |
608 ASSERT(CCProxy::isImplThread()); | 608 ASSERT(CCProxy::isImplThread()); |
609 ResourceMap::const_iterator it = m_resources.find(id); | 609 ResourceMap::const_iterator it = m_resources.find(id); |
610 CHECK(it != m_resources.end()); | 610 CHECK(it != m_resources.end()); |
611 const Resource* source = &it->second; | 611 const Resource* source = &it->second; |
612 ASSERT(!source->lockedForWrite); | 612 ASSERT(!source->lockedForWrite); |
613 ASSERT(!source->lockForReadCount); | 613 ASSERT(!source->lockForReadCount); |
614 ASSERT(!source->external); | 614 ASSERT(!source->external); |
615 if (source->exported) | 615 if (source->exported) |
616 return false; | 616 return false; |
617 resource->id = id; | 617 resource->id = id; |
618 resource->format = source->format; | 618 resource->format = source->format; |
619 resource->size = source->size; | 619 resource->size = source->size; |
620 if (!m_mailboxes.isEmpty()) | 620 if (m_mailboxes.size()) { |
621 resource->mailbox = m_mailboxes.takeFirst(); | 621 resource->mailbox = m_mailboxes.front(); |
| 622 m_mailboxes.pop_front(); |
| 623 } |
622 else | 624 else |
623 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); | 625 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); |
624 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, source->glI
d)); | 626 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, source->glI
d)); |
625 GLC(context, context->produceTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D,
resource->mailbox.name)); | 627 GLC(context, context->produceTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D,
resource->mailbox.name)); |
626 return true; | 628 return true; |
627 } | 629 } |
628 | 630 |
629 void CCResourceProvider::trimMailboxDeque() | 631 void CCResourceProvider::trimMailboxDeque() |
630 { | 632 { |
631 // Trim the mailbox deque to the maximum number of resources we may need to | 633 // Trim the mailbox deque to the maximum number of resources we may need to |
(...skipping 10 matching lines...) Expand all Loading... |
642 } else { | 644 } else { |
643 base::hash_set<int> childPoolSet; | 645 base::hash_set<int> childPoolSet; |
644 for (ChildMap::iterator it = m_children.begin(); it != m_children.end();
++it) | 646 for (ChildMap::iterator it = m_children.begin(); it != m_children.end();
++it) |
645 childPoolSet.insert(it->second.pool); | 647 childPoolSet.insert(it->second.pool); |
646 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e
nd(); ++it) { | 648 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e
nd(); ++it) { |
647 if (ContainsKey(childPoolSet, it->second.pool)) | 649 if (ContainsKey(childPoolSet, it->second.pool)) |
648 ++maxMailboxCount; | 650 ++maxMailboxCount; |
649 } | 651 } |
650 } | 652 } |
651 while (m_mailboxes.size() > maxMailboxCount) | 653 while (m_mailboxes.size() > maxMailboxCount) |
652 m_mailboxes.removeFirst(); | 654 m_mailboxes.pop_front(); |
653 } | 655 } |
654 | 656 |
655 } | 657 } |
OLD | NEW |