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
3 // found in the LICENSE file.
7 #include "CCResourceProvider.h"
14 #include "base/debug/alias.h"
15 #include "base/hash_tables.h"
16 #include "base/stl_util.h"
17 #include "base/string_split.h"
18 #include "base/string_util.h"
20 #include "CCRendererGL.h" // For the GLC() macro.
21 #include "Extensions3DChromium.h"
23 #include "LayerTextureSubImage.h"
24 #include "ThrottledTextureUploader.h"
25 #include "UnthrottledTextureUploader.h"
26 #include <public/WebGraphicsContext3D.h>
28 using WebKit::WebGraphicsContext3D
;
32 static GC3Denum
textureToStorageFormat(GC3Denum textureFormat
)
34 GC3Denum storageFormat
= Extensions3D::RGBA8_OES
;
35 switch (textureFormat
) {
36 case GraphicsContext3D::RGBA
:
38 case Extensions3D::BGRA_EXT
:
39 storageFormat
= Extensions3DChromium::BGRA8_EXT
;
49 static bool isTextureFormatSupportedForStorage(GC3Denum format
)
51 return (format
== GraphicsContext3D::RGBA
|| format
== Extensions3D::BGRA_EXT
);
54 CCResourceProvider::TransferableResourceList::TransferableResourceList()
58 CCResourceProvider::TransferableResourceList::~TransferableResourceList()
62 CCResourceProvider::Resource::Resource()
67 , lockedForWrite(false)
72 , type(static_cast<ResourceType
>(0))
76 CCResourceProvider::Resource::Resource(unsigned textureId
, int pool
, const IntSize
& size
, GC3Denum format
)
81 , lockedForWrite(false)
90 CCResourceProvider::Resource::Resource(uint8_t* pixels
, int pool
, const IntSize
& size
, GC3Denum format
)
95 , lockedForWrite(false)
104 CCResourceProvider::Child::Child()
108 CCResourceProvider::Child::~Child()
112 PassOwnPtr
<CCResourceProvider
> CCResourceProvider::create(CCGraphicsContext
* context
)
114 OwnPtr
<CCResourceProvider
> resourceProvider(adoptPtr(new CCResourceProvider(context
)));
115 if (!resourceProvider
->initialize())
117 return resourceProvider
.release();
120 CCResourceProvider::~CCResourceProvider()
122 WebGraphicsContext3D
* context3d
= m_context
->context3D();
123 if (!context3d
|| !context3d
->makeContextCurrent())
125 m_textureUploader
.clear();
126 m_textureCopier
.clear();
129 WebGraphicsContext3D
* CCResourceProvider::graphicsContext3D()
131 ASSERT(CCProxy::isImplThread());
132 return m_context
->context3D();
135 bool CCResourceProvider::inUseByConsumer(ResourceId id
)
137 ASSERT(CCProxy::isImplThread());
138 ResourceMap::iterator it
= m_resources
.find(id
);
139 CHECK(it
!= m_resources
.end());
140 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
141 Resource
* resource
= &it
->value
;
143 Resource
* resource
= &it
->second
;
145 return !!resource
->lockForReadCount
|| resource
->exported
;
148 CCResourceProvider::ResourceId
CCResourceProvider::createResource(int pool
, const IntSize
& size
, GC3Denum format
, TextureUsageHint hint
)
150 switch (m_defaultResourceType
) {
152 return createGLTexture(pool
, size
, format
, hint
);
154 ASSERT(format
== GraphicsContext3D::RGBA
);
155 return createBitmap(pool
, size
);
162 CCResourceProvider::ResourceId
CCResourceProvider::createGLTexture(int pool
, const IntSize
& size
, GC3Denum format
, TextureUsageHint hint
)
164 ASSERT(CCProxy::isImplThread());
165 unsigned textureId
= 0;
166 WebGraphicsContext3D
* context3d
= m_context
->context3D();
168 GLC(context3d
, textureId
= context3d
->createTexture());
169 GLC(context3d
, context3d
->bindTexture(GraphicsContext3D::TEXTURE_2D
, textureId
));
170 GLC(context3d
, context3d
->texParameteri(GraphicsContext3D::TEXTURE_2D
, GraphicsContext3D::TEXTURE_MIN_FILTER
, GraphicsContext3D::LINEAR
));
171 GLC(context3d
, context3d
->texParameteri(GraphicsContext3D::TEXTURE_2D
, GraphicsContext3D::TEXTURE_MAG_FILTER
, GraphicsContext3D::LINEAR
));
172 GLC(context3d
, context3d
->texParameteri(GraphicsContext3D::TEXTURE_2D
, GraphicsContext3D::TEXTURE_WRAP_S
, GraphicsContext3D::CLAMP_TO_EDGE
));
173 GLC(context3d
, context3d
->texParameteri(GraphicsContext3D::TEXTURE_2D
, GraphicsContext3D::TEXTURE_WRAP_T
, GraphicsContext3D::CLAMP_TO_EDGE
));
175 if (m_useTextureUsageHint
&& hint
== TextureUsageFramebuffer
)
176 GLC(context3d
, context3d
->texParameteri(GraphicsContext3D::TEXTURE_2D
, Extensions3DChromium::GL_TEXTURE_USAGE_ANGLE
, Extensions3DChromium::GL_FRAMEBUFFER_ATTACHMENT_ANGLE
));
177 if (m_useTextureStorageExt
&& isTextureFormatSupportedForStorage(format
)) {
178 GC3Denum storageFormat
= textureToStorageFormat(format
);
179 GLC(context3d
, context3d
->texStorage2DEXT(GraphicsContext3D::TEXTURE_2D
, 1, storageFormat
, size
.width(), size
.height()));
181 GLC(context3d
, context3d
->texImage2D(GraphicsContext3D::TEXTURE_2D
, 0, format
, size
.width(), size
.height(), 0, format
, GraphicsContext3D::UNSIGNED_BYTE
, 0));
182 ResourceId id
= m_nextId
++;
183 Resource
resource(textureId
, pool
, size
, format
);
184 m_resources
.add(id
, resource
);
188 CCResourceProvider::ResourceId
CCResourceProvider::createBitmap(int pool
, const IntSize
& size
)
190 ASSERT(CCProxy::isImplThread());
192 uint8_t* pixels
= new uint8_t[size
.width() * size
.height() * 4];
194 ResourceId id
= m_nextId
++;
195 Resource
resource(pixels
, pool
, size
, GraphicsContext3D::RGBA
);
196 m_resources
.add(id
, resource
);
200 CCResourceProvider::ResourceId
CCResourceProvider::createResourceFromExternalTexture(unsigned textureId
)
202 ASSERT(CCProxy::isImplThread());
203 ASSERT(m_context
->context3D());
204 ResourceId id
= m_nextId
++;
205 Resource
resource(textureId
, 0, IntSize(), 0);
206 resource
.external
= true;
207 m_resources
.add(id
, resource
);
211 void CCResourceProvider::deleteResource(ResourceId id
)
213 ASSERT(CCProxy::isImplThread());
214 ResourceMap::iterator it
= m_resources
.find(id
);
215 CHECK(it
!= m_resources
.end());
216 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
217 Resource
* resource
= &it
->value
;
219 Resource
* resource
= &it
->second
;
221 ASSERT(!resource
->lockedForWrite
);
222 ASSERT(!resource
->lockForReadCount
);
224 if (resource
->glId
&& !resource
->external
) {
225 WebGraphicsContext3D
* context3d
= m_context
->context3D();
227 GLC(context3d
, context3d
->deleteTexture(resource
->glId
));
229 if (resource
->pixels
)
230 delete resource
->pixels
;
232 m_resources
.remove(it
);
235 void CCResourceProvider::deleteOwnedResources(int pool
)
237 ASSERT(CCProxy::isImplThread());
238 ResourceIdArray toDelete
;
239 for (ResourceMap::iterator it
= m_resources
.begin(); it
!= m_resources
.end(); ++it
) {
240 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
241 if (it
->value
.pool
== pool
&& !it
->value
.external
)
242 toDelete
.append(it
->key
);
244 if (it
->second
.pool
== pool
&& !it
->second
.external
)
245 toDelete
.append(it
->first
);
248 for (ResourceIdArray::iterator it
= toDelete
.begin(); it
!= toDelete
.end(); ++it
)
252 CCResourceProvider::ResourceType
CCResourceProvider::resourceType(ResourceId id
)
254 ResourceMap::iterator it
= m_resources
.find(id
);
255 CHECK(it
!= m_resources
.end());
256 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
257 Resource
* resource
= &it
->value
;
259 Resource
* resource
= &it
->second
;
261 return resource
->type
;
264 void CCResourceProvider::upload(ResourceId id
, const uint8_t* image
, const IntRect
& imageRect
, const IntRect
& sourceRect
, const IntSize
& destOffset
)
266 ASSERT(CCProxy::isImplThread());
267 ResourceMap::iterator it
= m_resources
.find(id
);
268 CHECK(it
!= m_resources
.end());
269 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
270 Resource
* resource
= &it
->value
;
272 Resource
* resource
= &it
->second
;
274 ASSERT(!resource
->lockedForWrite
);
275 ASSERT(!resource
->lockForReadCount
);
276 ASSERT(!resource
->external
);
278 if (resource
->glId
) {
279 WebGraphicsContext3D
* context3d
= m_context
->context3D();
281 ASSERT(m_texSubImage
.get());
282 context3d
->bindTexture(GraphicsContext3D::TEXTURE_2D
, resource
->glId
);
283 m_texSubImage
->upload(image
, imageRect
, sourceRect
, destOffset
, resource
->format
, context3d
);
286 if (resource
->pixels
) {
288 srcFull
.setConfig(SkBitmap::kARGB_8888_Config
, imageRect
.width(), imageRect
.height());
289 srcFull
.setPixels(const_cast<uint8_t*>(image
));
291 SkIRect skSourceRect
= SkIRect::MakeXYWH(sourceRect
.x(), sourceRect
.y(), sourceRect
.width(), sourceRect
.height());
292 skSourceRect
.offset(-imageRect
.x(), -imageRect
.y());
293 srcFull
.extractSubset(&srcSubset
, skSourceRect
);
295 ScopedWriteLockSoftware
lock(this, id
);
296 SkCanvas
* dest
= lock
.skCanvas();
297 dest
->writePixels(srcSubset
, destOffset
.width(), destOffset
.height());
301 void CCResourceProvider::flush()
303 ASSERT(CCProxy::isImplThread());
304 WebGraphicsContext3D
* context3d
= m_context
->context3D();
309 bool CCResourceProvider::shallowFlushIfSupported()
311 ASSERT(CCProxy::isImplThread());
312 WebGraphicsContext3D
* context3d
= m_context
->context3D();
313 if (!context3d
|| !m_useShallowFlush
)
316 context3d
->shallowFlushCHROMIUM();
320 const CCResourceProvider::Resource
* CCResourceProvider::lockForRead(ResourceId id
)
322 ASSERT(CCProxy::isImplThread());
323 ResourceMap::iterator it
= m_resources
.find(id
);
324 CHECK(it
!= m_resources
.end());
326 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
327 Resource
* resource
= &it
->value
;
329 Resource
* resource
= &it
->second
;
331 ASSERT(!resource
->lockedForWrite
);
332 resource
->lockForReadCount
++;
336 void CCResourceProvider::unlockForRead(ResourceId id
)
338 ASSERT(CCProxy::isImplThread());
339 ResourceMap::iterator it
= m_resources
.find(id
);
340 CHECK(it
!= m_resources
.end());
341 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
342 Resource
* resource
= &it
->value
;
344 Resource
* resource
= &it
->second
;
346 ASSERT(resource
->lockForReadCount
> 0);
347 resource
->lockForReadCount
--;
350 const CCResourceProvider::Resource
* CCResourceProvider::lockForWrite(ResourceId id
)
352 ASSERT(CCProxy::isImplThread());
353 ResourceMap::iterator it
= m_resources
.find(id
);
354 CHECK(it
!= m_resources
.end());
355 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
356 Resource
* resource
= &it
->value
;
358 Resource
* resource
= &it
->second
;
360 ASSERT(!resource
->lockedForWrite
);
361 ASSERT(!resource
->lockForReadCount
);
362 ASSERT(!resource
->external
);
363 resource
->lockedForWrite
= true;
367 void CCResourceProvider::unlockForWrite(ResourceId id
)
369 ASSERT(CCProxy::isImplThread());
370 ResourceMap::iterator it
= m_resources
.find(id
);
371 CHECK(it
!= m_resources
.end());
372 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
373 Resource
* resource
= &it
->value
;
375 Resource
* resource
= &it
->second
;
377 ASSERT(resource
->lockedForWrite
);
378 ASSERT(!resource
->external
);
379 resource
->lockedForWrite
= false;
382 CCResourceProvider::ScopedReadLockGL::ScopedReadLockGL(CCResourceProvider
* resourceProvider
, CCResourceProvider::ResourceId resourceId
)
383 : m_resourceProvider(resourceProvider
)
384 , m_resourceId(resourceId
)
385 , m_textureId(resourceProvider
->lockForRead(resourceId
)->glId
)
390 CCResourceProvider::ScopedReadLockGL::~ScopedReadLockGL()
392 m_resourceProvider
->unlockForRead(m_resourceId
);
395 CCResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL(CCResourceProvider
* resourceProvider
, CCResourceProvider::ResourceId resourceId
)
396 : m_resourceProvider(resourceProvider
)
397 , m_resourceId(resourceId
)
398 , m_textureId(resourceProvider
->lockForWrite(resourceId
)->glId
)
403 CCResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL()
405 m_resourceProvider
->unlockForWrite(m_resourceId
);
408 void CCResourceProvider::populateSkBitmapWithResource(SkBitmap
* skBitmap
, const Resource
* resource
)
410 ASSERT(resource
->pixels
);
411 ASSERT(resource
->format
== GraphicsContext3D::RGBA
);
412 skBitmap
->setConfig(SkBitmap::kARGB_8888_Config
, resource
->size
.width(), resource
->size
.height());
413 skBitmap
->setPixels(resource
->pixels
);
416 CCResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware(CCResourceProvider
* resourceProvider
, CCResourceProvider::ResourceId resourceId
)
417 : m_resourceProvider(resourceProvider
)
418 , m_resourceId(resourceId
)
420 CCResourceProvider::populateSkBitmapWithResource(&m_skBitmap
, resourceProvider
->lockForRead(resourceId
));
423 CCResourceProvider::ScopedReadLockSoftware::~ScopedReadLockSoftware()
425 m_resourceProvider
->unlockForRead(m_resourceId
);
428 CCResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware(CCResourceProvider
* resourceProvider
, CCResourceProvider::ResourceId resourceId
)
429 : m_resourceProvider(resourceProvider
)
430 , m_resourceId(resourceId
)
432 CCResourceProvider::populateSkBitmapWithResource(&m_skBitmap
, resourceProvider
->lockForWrite(resourceId
));
433 m_skCanvas
= adoptPtr(new SkCanvas(m_skBitmap
));
436 CCResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware()
438 m_resourceProvider
->unlockForWrite(m_resourceId
);
441 CCResourceProvider::CCResourceProvider(CCGraphicsContext
* context
)
445 , m_defaultResourceType(GLTexture
)
446 , m_useTextureStorageExt(false)
447 , m_useTextureUsageHint(false)
448 , m_useShallowFlush(false)
449 , m_maxTextureSize(0)
453 bool CCResourceProvider::initialize()
455 ASSERT(CCProxy::isImplThread());
456 WebGraphicsContext3D
* context3d
= m_context
->context3D();
458 m_maxTextureSize
= INT_MAX
/ 2;
459 m_textureUploader
= UnthrottledTextureUploader::create();
462 if (!context3d
->makeContextCurrent())
465 std::string extensionsString
= UTF16ToASCII(context3d
->getString(GraphicsContext3D::EXTENSIONS
));
466 std::vector
<std::string
> extensions
;
467 base::SplitString(extensionsString
, ' ', &extensions
);
468 bool useMapSub
= false;
469 bool useBindUniform
= false;
470 for (size_t i
= 0; i
< extensions
.size(); ++i
) {
471 if (extensions
[i
] == "GL_EXT_texture_storage")
472 m_useTextureStorageExt
= true;
473 else if (extensions
[i
] == "GL_ANGLE_texture_usage")
474 m_useTextureUsageHint
= true;
475 else if (extensions
[i
] == "GL_CHROMIUM_map_sub")
477 else if (extensions
[i
] == "GL_CHROMIUM_shallow_flush")
478 m_useShallowFlush
= true;
479 else if (extensions
[i
] == "GL_CHROMIUM_bind_uniform_location")
480 useBindUniform
= true;
483 m_texSubImage
= adoptPtr(new LayerTextureSubImage(useMapSub
));
484 m_textureCopier
= AcceleratedTextureCopier::create(context3d
, useBindUniform
);
486 m_textureUploader
= ThrottledTextureUploader::create(context3d
);
487 GLC(context3d
, context3d
->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE
, &m_maxTextureSize
));
491 int CCResourceProvider::createChild(int pool
)
493 ASSERT(CCProxy::isImplThread());
495 childInfo
.pool
= pool
;
496 int child
= m_nextChild
++;
497 m_children
.add(child
, childInfo
);
501 void CCResourceProvider::destroyChild(int child
)
503 ASSERT(CCProxy::isImplThread());
504 ChildMap::iterator it
= m_children
.find(child
);
505 ASSERT(it
!= m_children
.end());
506 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
507 deleteOwnedResources(it
->value
.pool
);
509 deleteOwnedResources(it
->second
.pool
);
511 m_children
.remove(it
);
515 const CCResourceProvider::ResourceIdMap
& CCResourceProvider::getChildToParentMap(int child
) const
517 ASSERT(CCProxy::isImplThread());
518 ChildMap::const_iterator it
= m_children
.find(child
);
519 ASSERT(it
!= m_children
.end());
520 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
521 return it
->value
.childToParentMap
;
523 return it
->second
.childToParentMap
;
527 CCResourceProvider::TransferableResourceList
CCResourceProvider::prepareSendToParent(const ResourceIdArray
& resources
)
529 ASSERT(CCProxy::isImplThread());
530 TransferableResourceList list
;
532 WebGraphicsContext3D
* context3d
= m_context
->context3D();
533 if (!context3d
|| !context3d
->makeContextCurrent()) {
534 // FIXME: Implement this path for software compositing.
537 for (ResourceIdArray::const_iterator it
= resources
.begin(); it
!= resources
.end(); ++it
) {
538 TransferableResource resource
;
539 if (transferResource(context3d
, *it
, &resource
)) {
540 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
541 m_resources
.find(*it
)->value
.exported
= true;
543 m_resources
.find(*it
)->second
.exported
= true;
545 list
.resources
.append(resource
);
548 if (list
.resources
.size())
549 list
.syncPoint
= context3d
->insertSyncPoint();
553 CCResourceProvider::TransferableResourceList
CCResourceProvider::prepareSendToChild(int child
, const ResourceIdArray
& resources
)
555 ASSERT(CCProxy::isImplThread());
556 TransferableResourceList list
;
558 WebGraphicsContext3D
* context3d
= m_context
->context3D();
559 if (!context3d
|| !context3d
->makeContextCurrent()) {
560 // FIXME: Implement this path for software compositing.
563 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
564 Child
& childInfo
= m_children
.find(child
)->value
;
566 Child
& childInfo
= m_children
.find(child
)->second
;
568 for (ResourceIdArray::const_iterator it
= resources
.begin(); it
!= resources
.end(); ++it
) {
569 TransferableResource resource
;
570 if (!transferResource(context3d
, *it
, &resource
))
571 ASSERT_NOT_REACHED();
572 resource
.id
= childInfo
.parentToChildMap
.get(*it
);
573 childInfo
.parentToChildMap
.remove(*it
);
574 childInfo
.childToParentMap
.remove(resource
.id
);
575 list
.resources
.append(resource
);
578 if (list
.resources
.size())
579 list
.syncPoint
= context3d
->insertSyncPoint();
583 void CCResourceProvider::receiveFromChild(int child
, const TransferableResourceList
& resources
)
585 ASSERT(CCProxy::isImplThread());
586 WebGraphicsContext3D
* context3d
= m_context
->context3D();
587 if (!context3d
|| !context3d
->makeContextCurrent()) {
588 // FIXME: Implement this path for software compositing.
591 if (resources
.syncPoint
) {
592 // NOTE: If the parent is a browser and the child a renderer, the parent
593 // is not supposed to have its context wait, because that could induce
594 // deadlocks and/or security issues. The caller is responsible for
595 // waiting asynchronously, and resetting syncPoint before calling this.
596 // However if the parent is a renderer (e.g. browser tag), it may be ok
597 // (and is simpler) to wait.
598 GLC(context3d
, context3d
->waitSyncPoint(resources
.syncPoint
));
600 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
601 Child
& childInfo
= m_children
.find(child
)->value
;
603 Child
& childInfo
= m_children
.find(child
)->second
;
605 for (Vector
<TransferableResource
>::const_iterator it
= resources
.resources
.begin(); it
!= resources
.resources
.end(); ++it
) {
607 GLC(context3d
, textureId
= context3d
->createTexture());
608 GLC(context3d
, context3d
->bindTexture(GraphicsContext3D::TEXTURE_2D
, textureId
));
609 GLC(context3d
, context3d
->consumeTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D
, it
->mailbox
.name
));
610 ResourceId id
= m_nextId
++;
611 Resource
resource(textureId
, childInfo
.pool
, it
->size
, it
->format
);
612 m_resources
.add(id
, resource
);
613 m_mailboxes
.append(it
->mailbox
);
614 childInfo
.parentToChildMap
.add(id
, it
->id
);
615 childInfo
.childToParentMap
.add(it
->id
, id
);
619 void CCResourceProvider::receiveFromParent(const TransferableResourceList
& resources
)
621 ASSERT(CCProxy::isImplThread());
622 WebGraphicsContext3D
* context3d
= m_context
->context3D();
623 if (!context3d
|| !context3d
->makeContextCurrent()) {
624 // FIXME: Implement this path for software compositing.
627 if (resources
.syncPoint
)
628 GLC(context3d
, context3d
->waitSyncPoint(resources
.syncPoint
));
629 for (Vector
<TransferableResource
>::const_iterator it
= resources
.resources
.begin(); it
!= resources
.resources
.end(); ++it
) {
630 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
631 Resource
* resource
= &m_resources
.find(it
->id
)->value
;
633 Resource
* resource
= &m_resources
.find(it
->id
)->second
;
635 ASSERT(resource
->exported
);
636 resource
->exported
= false;
637 GLC(context3d
, context3d
->bindTexture(GraphicsContext3D::TEXTURE_2D
, resource
->glId
));
638 GLC(context3d
, context3d
->consumeTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D
, it
->mailbox
.name
));
639 m_mailboxes
.append(it
->mailbox
);
643 bool CCResourceProvider::transferResource(WebGraphicsContext3D
* context
, ResourceId id
, TransferableResource
* resource
)
645 ASSERT(CCProxy::isImplThread());
646 ResourceMap::const_iterator it
= m_resources
.find(id
);
647 CHECK(it
!= m_resources
.end());
648 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
649 const Resource
* source
= &it
->value
;
651 const Resource
* source
= &it
->second
;
653 ASSERT(!source
->lockedForWrite
);
654 ASSERT(!source
->lockForReadCount
);
655 ASSERT(!source
->external
);
656 if (source
->exported
)
659 resource
->format
= source
->format
;
660 resource
->size
= source
->size
;
661 if (!m_mailboxes
.isEmpty())
662 resource
->mailbox
= m_mailboxes
.takeFirst();
664 GLC(context
, context
->genMailboxCHROMIUM(resource
->mailbox
.name
));
665 GLC(context
, context
->bindTexture(GraphicsContext3D::TEXTURE_2D
, source
->glId
));
666 GLC(context
, context
->produceTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D
, resource
->mailbox
.name
));
670 void CCResourceProvider::trimMailboxDeque()
672 // Trim the mailbox deque to the maximum number of resources we may need to
674 // If we have a parent, any non-external resource not already transfered is
675 // eligible to be sent to the parent. Otherwise, all resources belonging to
676 // a child might need to be sent back to the child.
677 size_t maxMailboxCount
= 0;
678 if (m_context
->capabilities().hasParentCompositor
) {
679 for (ResourceMap::iterator it
= m_resources
.begin(); it
!= m_resources
.end(); ++it
) {
680 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
681 if (!it
->value
.exported
&& !it
->value
.external
)
683 if (!it
->second
.exported
&& !it
->second
.external
)
688 base::hash_set
<int> childPoolSet
;
689 for (ChildMap::iterator it
= m_children
.begin(); it
!= m_children
.end(); ++it
)
690 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
691 childPoolSet
.insert(it
->value
.pool
);
693 childPoolSet
.insert(it
->second
.pool
);
695 for (ResourceMap::iterator it
= m_resources
.begin(); it
!= m_resources
.end(); ++it
) {
696 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
697 if (ContainsKey(childPoolSet
, it
->value
.pool
))
699 if (ContainsKey(childPoolSet
, it
->second
.pool
))
704 while (m_mailboxes
.size() > maxMailboxCount
)
705 m_mailboxes
.removeFirst();