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

Side by Side Diff: cc/CCResourceProvider.cpp

Issue 11122003: [cc] Rename all cc/ filenames to Chromium style (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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/CCResourceProvider.h ('k') | cc/CCScheduler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "config.h"
6
7 #include "CCResourceProvider.h"
8 #ifdef LOG
9 #undef LOG
10 #endif
11
12 #include <limits.h>
13
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"
19 #include "CCProxy.h"
20 #include "CCRendererGL.h" // For the GLC() macro.
21 #include "Extensions3DChromium.h"
22 #include "IntRect.h"
23 #include "LayerTextureSubImage.h"
24 #include "ThrottledTextureUploader.h"
25 #include "UnthrottledTextureUploader.h"
26 #include <public/WebGraphicsContext3D.h>
27
28 using WebKit::WebGraphicsContext3D;
29
30 namespace cc {
31
32 static GC3Denum textureToStorageFormat(GC3Denum textureFormat)
33 {
34 GC3Denum storageFormat = Extensions3D::RGBA8_OES;
35 switch (textureFormat) {
36 case GraphicsContext3D::RGBA:
37 break;
38 case Extensions3D::BGRA_EXT:
39 storageFormat = Extensions3DChromium::BGRA8_EXT;
40 break;
41 default:
42 ASSERT_NOT_REACHED();
43 break;
44 }
45
46 return storageFormat;
47 }
48
49 static bool isTextureFormatSupportedForStorage(GC3Denum format)
50 {
51 return (format == GraphicsContext3D::RGBA || format == Extensions3D::BGRA_EX T);
52 }
53
54 CCResourceProvider::TransferableResourceList::TransferableResourceList()
55 {
56 }
57
58 CCResourceProvider::TransferableResourceList::~TransferableResourceList()
59 {
60 }
61
62 CCResourceProvider::Resource::Resource()
63 : glId(0)
64 , pixels(0)
65 , pool(0)
66 , lockForReadCount(0)
67 , lockedForWrite(false)
68 , external(false)
69 , exported(false)
70 , size()
71 , format(0)
72 , type(static_cast<ResourceType>(0))
73 {
74 }
75
76 CCResourceProvider::Resource::Resource(unsigned textureId, int pool, const IntSi ze& size, GC3Denum format)
77 : glId(textureId)
78 , pixels(0)
79 , pool(pool)
80 , lockForReadCount(0)
81 , lockedForWrite(false)
82 , external(false)
83 , exported(false)
84 , size(size)
85 , format(format)
86 , type(GLTexture)
87 {
88 }
89
90 CCResourceProvider::Resource::Resource(uint8_t* pixels, int pool, const IntSize& size, GC3Denum format)
91 : glId(0)
92 , pixels(pixels)
93 , pool(pool)
94 , lockForReadCount(0)
95 , lockedForWrite(false)
96 , external(false)
97 , exported(false)
98 , size(size)
99 , format(format)
100 , type(Bitmap)
101 {
102 }
103
104 CCResourceProvider::Child::Child()
105 {
106 }
107
108 CCResourceProvider::Child::~Child()
109 {
110 }
111
112 PassOwnPtr<CCResourceProvider> CCResourceProvider::create(CCGraphicsContext* con text)
113 {
114 OwnPtr<CCResourceProvider> resourceProvider(adoptPtr(new CCResourceProvider( context)));
115 if (!resourceProvider->initialize())
116 return nullptr;
117 return resourceProvider.release();
118 }
119
120 CCResourceProvider::~CCResourceProvider()
121 {
122 WebGraphicsContext3D* context3d = m_context->context3D();
123 if (!context3d || !context3d->makeContextCurrent())
124 return;
125 m_textureUploader.clear();
126 m_textureCopier.clear();
127 }
128
129 WebGraphicsContext3D* CCResourceProvider::graphicsContext3D()
130 {
131 ASSERT(CCProxy::isImplThread());
132 return m_context->context3D();
133 }
134
135 bool CCResourceProvider::inUseByConsumer(ResourceId id)
136 {
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;
142 #else
143 Resource* resource = &it->second;
144 #endif
145 return !!resource->lockForReadCount || resource->exported;
146 }
147
148 CCResourceProvider::ResourceId CCResourceProvider::createResource(int pool, cons t IntSize& size, GC3Denum format, TextureUsageHint hint)
149 {
150 switch (m_defaultResourceType) {
151 case GLTexture:
152 return createGLTexture(pool, size, format, hint);
153 case Bitmap:
154 ASSERT(format == GraphicsContext3D::RGBA);
155 return createBitmap(pool, size);
156 }
157
158 CRASH();
159 return 0;
160 }
161
162 CCResourceProvider::ResourceId CCResourceProvider::createGLTexture(int pool, con st IntSize& size, GC3Denum format, TextureUsageHint hint)
163 {
164 ASSERT(CCProxy::isImplThread());
165 unsigned textureId = 0;
166 WebGraphicsContext3D* context3d = m_context->context3D();
167 ASSERT(context3d);
168 GLC(context3d, textureId = context3d->createTexture());
169 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, texture Id));
170 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph icsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR));
171 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph icsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR));
172 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph icsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE));
173 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph icsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE));
174
175 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer)
176 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, E xtensions3DChromium::GL_TEXTURE_USAGE_ANGLE, Extensions3DChromium::GL_FRAMEBUFFE R_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()));
180 } else
181 GLC(context3d, context3d->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, f ormat, 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);
185 return id;
186 }
187
188 CCResourceProvider::ResourceId CCResourceProvider::createBitmap(int pool, const IntSize& size)
189 {
190 ASSERT(CCProxy::isImplThread());
191
192 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4];
193
194 ResourceId id = m_nextId++;
195 Resource resource(pixels, pool, size, GraphicsContext3D::RGBA);
196 m_resources.add(id, resource);
197 return id;
198 }
199
200 CCResourceProvider::ResourceId CCResourceProvider::createResourceFromExternalTex ture(unsigned textureId)
201 {
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);
208 return id;
209 }
210
211 void CCResourceProvider::deleteResource(ResourceId id)
212 {
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;
218 #else
219 Resource* resource = &it->second;
220 #endif
221 ASSERT(!resource->lockedForWrite);
222 ASSERT(!resource->lockForReadCount);
223
224 if (resource->glId && !resource->external) {
225 WebGraphicsContext3D* context3d = m_context->context3D();
226 ASSERT(context3d);
227 GLC(context3d, context3d->deleteTexture(resource->glId));
228 }
229 if (resource->pixels)
230 delete resource->pixels;
231
232 m_resources.remove(it);
233 }
234
235 void CCResourceProvider::deleteOwnedResources(int pool)
236 {
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);
243 #else
244 if (it->second.pool == pool && !it->second.external)
245 toDelete.append(it->first);
246 #endif
247 }
248 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end(); ++it)
249 deleteResource(*it);
250 }
251
252 CCResourceProvider::ResourceType CCResourceProvider::resourceType(ResourceId id)
253 {
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;
258 #else
259 Resource* resource = &it->second;
260 #endif
261 return resource->type;
262 }
263
264 void CCResourceProvider::upload(ResourceId id, const uint8_t* image, const IntRe ct& imageRect, const IntRect& sourceRect, const IntSize& destOffset)
265 {
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;
271 #else
272 Resource* resource = &it->second;
273 #endif
274 ASSERT(!resource->lockedForWrite);
275 ASSERT(!resource->lockForReadCount);
276 ASSERT(!resource->external);
277
278 if (resource->glId) {
279 WebGraphicsContext3D* context3d = m_context->context3D();
280 ASSERT(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);
284 }
285
286 if (resource->pixels) {
287 SkBitmap srcFull;
288 srcFull.setConfig(SkBitmap::kARGB_8888_Config, imageRect.width(), imageR ect.height());
289 srcFull.setPixels(const_cast<uint8_t*>(image));
290 SkBitmap srcSubset;
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);
294
295 ScopedWriteLockSoftware lock(this, id);
296 SkCanvas* dest = lock.skCanvas();
297 dest->writePixels(srcSubset, destOffset.width(), destOffset.height());
298 }
299 }
300
301 void CCResourceProvider::flush()
302 {
303 ASSERT(CCProxy::isImplThread());
304 WebGraphicsContext3D* context3d = m_context->context3D();
305 if (context3d)
306 context3d->flush();
307 }
308
309 bool CCResourceProvider::shallowFlushIfSupported()
310 {
311 ASSERT(CCProxy::isImplThread());
312 WebGraphicsContext3D* context3d = m_context->context3D();
313 if (!context3d || !m_useShallowFlush)
314 return false;
315
316 context3d->shallowFlushCHROMIUM();
317 return true;
318 }
319
320 const CCResourceProvider::Resource* CCResourceProvider::lockForRead(ResourceId i d)
321 {
322 ASSERT(CCProxy::isImplThread());
323 ResourceMap::iterator it = m_resources.find(id);
324 CHECK(it != m_resources.end());
325
326 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
327 Resource* resource = &it->value;
328 #else
329 Resource* resource = &it->second;
330 #endif
331 ASSERT(!resource->lockedForWrite);
332 resource->lockForReadCount++;
333 return resource;
334 }
335
336 void CCResourceProvider::unlockForRead(ResourceId id)
337 {
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;
343 #else
344 Resource* resource = &it->second;
345 #endif
346 ASSERT(resource->lockForReadCount > 0);
347 resource->lockForReadCount--;
348 }
349
350 const CCResourceProvider::Resource* CCResourceProvider::lockForWrite(ResourceId id)
351 {
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;
357 #else
358 Resource* resource = &it->second;
359 #endif
360 ASSERT(!resource->lockedForWrite);
361 ASSERT(!resource->lockForReadCount);
362 ASSERT(!resource->external);
363 resource->lockedForWrite = true;
364 return resource;
365 }
366
367 void CCResourceProvider::unlockForWrite(ResourceId id)
368 {
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;
374 #else
375 Resource* resource = &it->second;
376 #endif
377 ASSERT(resource->lockedForWrite);
378 ASSERT(!resource->external);
379 resource->lockedForWrite = false;
380 }
381
382 CCResourceProvider::ScopedReadLockGL::ScopedReadLockGL(CCResourceProvider* resou rceProvider, CCResourceProvider::ResourceId resourceId)
383 : m_resourceProvider(resourceProvider)
384 , m_resourceId(resourceId)
385 , m_textureId(resourceProvider->lockForRead(resourceId)->glId)
386 {
387 ASSERT(m_textureId);
388 }
389
390 CCResourceProvider::ScopedReadLockGL::~ScopedReadLockGL()
391 {
392 m_resourceProvider->unlockForRead(m_resourceId);
393 }
394
395 CCResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL(CCResourceProvider* res ourceProvider, CCResourceProvider::ResourceId resourceId)
396 : m_resourceProvider(resourceProvider)
397 , m_resourceId(resourceId)
398 , m_textureId(resourceProvider->lockForWrite(resourceId)->glId)
399 {
400 ASSERT(m_textureId);
401 }
402
403 CCResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL()
404 {
405 m_resourceProvider->unlockForWrite(m_resourceId);
406 }
407
408 void CCResourceProvider::populateSkBitmapWithResource(SkBitmap* skBitmap, const Resource* resource)
409 {
410 ASSERT(resource->pixels);
411 ASSERT(resource->format == GraphicsContext3D::RGBA);
412 skBitmap->setConfig(SkBitmap::kARGB_8888_Config, resource->size.width(), res ource->size.height());
413 skBitmap->setPixels(resource->pixels);
414 }
415
416 CCResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware(CCResourcePro vider* resourceProvider, CCResourceProvider::ResourceId resourceId)
417 : m_resourceProvider(resourceProvider)
418 , m_resourceId(resourceId)
419 {
420 CCResourceProvider::populateSkBitmapWithResource(&m_skBitmap, resourceProvid er->lockForRead(resourceId));
421 }
422
423 CCResourceProvider::ScopedReadLockSoftware::~ScopedReadLockSoftware()
424 {
425 m_resourceProvider->unlockForRead(m_resourceId);
426 }
427
428 CCResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware(CCResourceP rovider* resourceProvider, CCResourceProvider::ResourceId resourceId)
429 : m_resourceProvider(resourceProvider)
430 , m_resourceId(resourceId)
431 {
432 CCResourceProvider::populateSkBitmapWithResource(&m_skBitmap, resourceProvid er->lockForWrite(resourceId));
433 m_skCanvas = adoptPtr(new SkCanvas(m_skBitmap));
434 }
435
436 CCResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware()
437 {
438 m_resourceProvider->unlockForWrite(m_resourceId);
439 }
440
441 CCResourceProvider::CCResourceProvider(CCGraphicsContext* context)
442 : m_context(context)
443 , m_nextId(1)
444 , m_nextChild(1)
445 , m_defaultResourceType(GLTexture)
446 , m_useTextureStorageExt(false)
447 , m_useTextureUsageHint(false)
448 , m_useShallowFlush(false)
449 , m_maxTextureSize(0)
450 {
451 }
452
453 bool CCResourceProvider::initialize()
454 {
455 ASSERT(CCProxy::isImplThread());
456 WebGraphicsContext3D* context3d = m_context->context3D();
457 if (!context3d) {
458 m_maxTextureSize = INT_MAX / 2;
459 m_textureUploader = UnthrottledTextureUploader::create();
460 return true;
461 }
462 if (!context3d->makeContextCurrent())
463 return false;
464
465 std::string extensionsString = UTF16ToASCII(context3d->getString(GraphicsCon text3D::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")
476 useMapSub = true;
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;
481 }
482
483 m_texSubImage = adoptPtr(new LayerTextureSubImage(useMapSub));
484 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform );
485
486 m_textureUploader = ThrottledTextureUploader::create(context3d);
487 GLC(context3d, context3d->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, & m_maxTextureSize));
488 return true;
489 }
490
491 int CCResourceProvider::createChild(int pool)
492 {
493 ASSERT(CCProxy::isImplThread());
494 Child childInfo;
495 childInfo.pool = pool;
496 int child = m_nextChild++;
497 m_children.add(child, childInfo);
498 return child;
499 }
500
501 void CCResourceProvider::destroyChild(int child)
502 {
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);
508 #else
509 deleteOwnedResources(it->second.pool);
510 #endif
511 m_children.remove(it);
512 trimMailboxDeque();
513 }
514
515 const CCResourceProvider::ResourceIdMap& CCResourceProvider::getChildToParentMap (int child) const
516 {
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;
522 #else
523 return it->second.childToParentMap;
524 #endif
525 }
526
527 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToPa rent(const ResourceIdArray& resources)
528 {
529 ASSERT(CCProxy::isImplThread());
530 TransferableResourceList list;
531 list.syncPoint = 0;
532 WebGraphicsContext3D* context3d = m_context->context3D();
533 if (!context3d || !context3d->makeContextCurrent()) {
534 // FIXME: Implement this path for software compositing.
535 return list;
536 }
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;
542 #else
543 m_resources.find(*it)->second.exported = true;
544 #endif
545 list.resources.append(resource);
546 }
547 }
548 if (list.resources.size())
549 list.syncPoint = context3d->insertSyncPoint();
550 return list;
551 }
552
553 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToCh ild(int child, const ResourceIdArray& resources)
554 {
555 ASSERT(CCProxy::isImplThread());
556 TransferableResourceList list;
557 list.syncPoint = 0;
558 WebGraphicsContext3D* context3d = m_context->context3D();
559 if (!context3d || !context3d->makeContextCurrent()) {
560 // FIXME: Implement this path for software compositing.
561 return list;
562 }
563 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
564 Child& childInfo = m_children.find(child)->value;
565 #else
566 Child& childInfo = m_children.find(child)->second;
567 #endif
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);
576 deleteResource(*it);
577 }
578 if (list.resources.size())
579 list.syncPoint = context3d->insertSyncPoint();
580 return list;
581 }
582
583 void CCResourceProvider::receiveFromChild(int child, const TransferableResourceL ist& resources)
584 {
585 ASSERT(CCProxy::isImplThread());
586 WebGraphicsContext3D* context3d = m_context->context3D();
587 if (!context3d || !context3d->makeContextCurrent()) {
588 // FIXME: Implement this path for software compositing.
589 return;
590 }
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));
599 }
600 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
601 Child& childInfo = m_children.find(child)->value;
602 #else
603 Child& childInfo = m_children.find(child)->second;
604 #endif
605 for (Vector<TransferableResource>::const_iterator it = resources.resources.b egin(); it != resources.resources.end(); ++it) {
606 unsigned textureId;
607 GLC(context3d, textureId = context3d->createTexture());
608 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, tex tureId));
609 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT URE_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);
616 }
617 }
618
619 void CCResourceProvider::receiveFromParent(const TransferableResourceList& resou rces)
620 {
621 ASSERT(CCProxy::isImplThread());
622 WebGraphicsContext3D* context3d = m_context->context3D();
623 if (!context3d || !context3d->makeContextCurrent()) {
624 // FIXME: Implement this path for software compositing.
625 return;
626 }
627 if (resources.syncPoint)
628 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint));
629 for (Vector<TransferableResource>::const_iterator it = resources.resources.b egin(); it != resources.resources.end(); ++it) {
630 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
631 Resource* resource = &m_resources.find(it->id)->value;
632 #else
633 Resource* resource = &m_resources.find(it->id)->second;
634 #endif
635 ASSERT(resource->exported);
636 resource->exported = false;
637 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, res ource->glId));
638 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT URE_2D, it->mailbox.name));
639 m_mailboxes.append(it->mailbox);
640 }
641 }
642
643 bool CCResourceProvider::transferResource(WebGraphicsContext3D* context, Resourc eId id, TransferableResource* resource)
644 {
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;
650 #else
651 const Resource* source = &it->second;
652 #endif
653 ASSERT(!source->lockedForWrite);
654 ASSERT(!source->lockForReadCount);
655 ASSERT(!source->external);
656 if (source->exported)
657 return false;
658 resource->id = id;
659 resource->format = source->format;
660 resource->size = source->size;
661 if (!m_mailboxes.isEmpty())
662 resource->mailbox = m_mailboxes.takeFirst();
663 else
664 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name));
665 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, source->glI d));
666 GLC(context, context->produceTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D, resource->mailbox.name));
667 return true;
668 }
669
670 void CCResourceProvider::trimMailboxDeque()
671 {
672 // Trim the mailbox deque to the maximum number of resources we may need to
673 // send.
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.e nd(); ++it) {
680 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
681 if (!it->value.exported && !it->value.external)
682 #else
683 if (!it->second.exported && !it->second.external)
684 #endif
685 ++maxMailboxCount;
686 }
687 } else {
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);
692 #else
693 childPoolSet.insert(it->second.pool);
694 #endif
695 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e nd(); ++it) {
696 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
697 if (ContainsKey(childPoolSet, it->value.pool))
698 #else
699 if (ContainsKey(childPoolSet, it->second.pool))
700 #endif
701 ++maxMailboxCount;
702 }
703 }
704 while (m_mailboxes.size() > maxMailboxCount)
705 m_mailboxes.removeFirst();
706 }
707
708 }
OLDNEW
« no previous file with comments | « cc/CCResourceProvider.h ('k') | cc/CCScheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698