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 "cc/resource_provider.h" | 5 #include "cc/resource_provider.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 | 8 |
9 #include "base/debug/alias.h" | 9 #include "base/debug/alias.h" |
10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 scoped_ptr<ResourceProvider> ResourceProvider::create(GraphicsContext* context) | 109 scoped_ptr<ResourceProvider> ResourceProvider::create(GraphicsContext* context) |
110 { | 110 { |
111 scoped_ptr<ResourceProvider> resourceProvider(new ResourceProvider(context))
; | 111 scoped_ptr<ResourceProvider> resourceProvider(new ResourceProvider(context))
; |
112 if (!resourceProvider->initialize()) | 112 if (!resourceProvider->initialize()) |
113 return scoped_ptr<ResourceProvider>(); | 113 return scoped_ptr<ResourceProvider>(); |
114 return resourceProvider.Pass(); | 114 return resourceProvider.Pass(); |
115 } | 115 } |
116 | 116 |
117 ResourceProvider::~ResourceProvider() | 117 ResourceProvider::~ResourceProvider() |
118 { | 118 { |
119 WebGraphicsContext3D* context3d = m_context->context3D(); | 119 WebGraphicsContext3D* context3d = m_context->Context3D(); |
120 if (!context3d || !context3d->makeContextCurrent()) | 120 if (!context3d || !context3d->makeContextCurrent()) |
121 return; | 121 return; |
122 m_textureUploader.reset(); | 122 m_textureUploader.reset(); |
123 m_textureCopier.reset(); | 123 m_textureCopier.reset(); |
124 } | 124 } |
125 | 125 |
126 WebGraphicsContext3D* ResourceProvider::graphicsContext3D() | 126 WebGraphicsContext3D* ResourceProvider::graphicsContext3D() |
127 { | 127 { |
128 DCHECK(m_threadChecker.CalledOnValidThread()); | 128 DCHECK(m_threadChecker.CalledOnValidThread()); |
129 return m_context->context3D(); | 129 return m_context->Context3D(); |
130 } | 130 } |
131 | 131 |
132 bool ResourceProvider::inUseByConsumer(ResourceId id) | 132 bool ResourceProvider::inUseByConsumer(ResourceId id) |
133 { | 133 { |
134 DCHECK(m_threadChecker.CalledOnValidThread()); | 134 DCHECK(m_threadChecker.CalledOnValidThread()); |
135 ResourceMap::iterator it = m_resources.find(id); | 135 ResourceMap::iterator it = m_resources.find(id); |
136 CHECK(it != m_resources.end()); | 136 CHECK(it != m_resources.end()); |
137 Resource* resource = &it->second; | 137 Resource* resource = &it->second; |
138 return !!resource->lockForReadCount || resource->exported; | 138 return !!resource->lockForReadCount || resource->exported; |
139 } | 139 } |
(...skipping 12 matching lines...) Expand all Loading... |
152 return 0; | 152 return 0; |
153 } | 153 } |
154 | 154 |
155 ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const g
fx::Size& size, GLenum format, TextureUsageHint hint) | 155 ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const g
fx::Size& size, GLenum format, TextureUsageHint hint) |
156 { | 156 { |
157 DCHECK_LE(size.width(), m_maxTextureSize); | 157 DCHECK_LE(size.width(), m_maxTextureSize); |
158 DCHECK_LE(size.height(), m_maxTextureSize); | 158 DCHECK_LE(size.height(), m_maxTextureSize); |
159 | 159 |
160 DCHECK(m_threadChecker.CalledOnValidThread()); | 160 DCHECK(m_threadChecker.CalledOnValidThread()); |
161 unsigned textureId = 0; | 161 unsigned textureId = 0; |
162 WebGraphicsContext3D* context3d = m_context->context3D(); | 162 WebGraphicsContext3D* context3d = m_context->Context3D(); |
163 DCHECK(context3d); | 163 DCHECK(context3d); |
164 GLC(context3d, textureId = context3d->createTexture()); | 164 GLC(context3d, textureId = context3d->createTexture()); |
165 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | 165 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); |
166 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); | 166 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); |
167 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); | 167 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); |
168 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); | 168 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); |
169 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); | 169 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); |
170 | 170 |
171 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) | 171 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) |
172 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_
ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); | 172 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_
ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); |
(...skipping 18 matching lines...) Expand all Loading... |
191 ResourceId id = m_nextId++; | 191 ResourceId id = m_nextId++; |
192 Resource resource(pixels, pool, size, GL_RGBA); | 192 Resource resource(pixels, pool, size, GL_RGBA); |
193 m_resources[id] = resource; | 193 m_resources[id] = resource; |
194 return id; | 194 return id; |
195 } | 195 } |
196 | 196 |
197 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture
(unsigned textureId) | 197 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture
(unsigned textureId) |
198 { | 198 { |
199 DCHECK(m_threadChecker.CalledOnValidThread()); | 199 DCHECK(m_threadChecker.CalledOnValidThread()); |
200 | 200 |
201 WebGraphicsContext3D* context3d = m_context->context3D(); | 201 WebGraphicsContext3D* context3d = m_context->Context3D(); |
202 DCHECK(context3d); | 202 DCHECK(context3d); |
203 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | 203 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); |
204 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); | 204 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); |
205 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); | 205 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); |
206 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); | 206 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); |
207 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); | 207 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); |
208 | 208 |
209 ResourceId id = m_nextId++; | 209 ResourceId id = m_nextId++; |
210 Resource resource(textureId, 0, gfx::Size(), 0); | 210 Resource resource(textureId, 0, gfx::Size(), 0); |
211 resource.external = true; | 211 resource.external = true; |
(...skipping 15 matching lines...) Expand all Loading... |
227 resource->markedForDeletion = true; | 227 resource->markedForDeletion = true; |
228 return; | 228 return; |
229 } else | 229 } else |
230 deleteResourceInternal(it); | 230 deleteResourceInternal(it); |
231 } | 231 } |
232 | 232 |
233 void ResourceProvider::deleteResourceInternal(ResourceMap::iterator it) | 233 void ResourceProvider::deleteResourceInternal(ResourceMap::iterator it) |
234 { | 234 { |
235 Resource* resource = &it->second; | 235 Resource* resource = &it->second; |
236 if (resource->glId && !resource->external) { | 236 if (resource->glId && !resource->external) { |
237 WebGraphicsContext3D* context3d = m_context->context3D(); | 237 WebGraphicsContext3D* context3d = m_context->Context3D(); |
238 DCHECK(context3d); | 238 DCHECK(context3d); |
239 GLC(context3d, context3d->deleteTexture(resource->glId)); | 239 GLC(context3d, context3d->deleteTexture(resource->glId)); |
240 } | 240 } |
241 if (resource->glPixelBufferId) { | 241 if (resource->glPixelBufferId) { |
242 WebGraphicsContext3D* context3d = m_context->context3D(); | 242 WebGraphicsContext3D* context3d = m_context->Context3D(); |
243 DCHECK(context3d); | 243 DCHECK(context3d); |
244 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId)); | 244 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId)); |
245 } | 245 } |
246 if (resource->pixels) | 246 if (resource->pixels) |
247 delete[] resource->pixels; | 247 delete[] resource->pixels; |
248 if (resource->pixelBuffer) | 248 if (resource->pixelBuffer) |
249 delete[] resource->pixelBuffer; | 249 delete[] resource->pixelBuffer; |
250 | 250 |
251 m_resources.erase(it); | 251 m_resources.erase(it); |
252 } | 252 } |
(...skipping 23 matching lines...) Expand all Loading... |
276 DCHECK(m_threadChecker.CalledOnValidThread()); | 276 DCHECK(m_threadChecker.CalledOnValidThread()); |
277 ResourceMap::iterator it = m_resources.find(id); | 277 ResourceMap::iterator it = m_resources.find(id); |
278 CHECK(it != m_resources.end()); | 278 CHECK(it != m_resources.end()); |
279 Resource* resource = &it->second; | 279 Resource* resource = &it->second; |
280 DCHECK(!resource->lockedForWrite); | 280 DCHECK(!resource->lockedForWrite); |
281 DCHECK(!resource->lockForReadCount); | 281 DCHECK(!resource->lockForReadCount); |
282 DCHECK(!resource->external); | 282 DCHECK(!resource->external); |
283 DCHECK(!resource->exported); | 283 DCHECK(!resource->exported); |
284 | 284 |
285 if (resource->glId) { | 285 if (resource->glId) { |
286 WebGraphicsContext3D* context3d = m_context->context3D(); | 286 WebGraphicsContext3D* context3d = m_context->Context3D(); |
287 DCHECK(context3d); | 287 DCHECK(context3d); |
288 DCHECK(m_textureUploader.get()); | 288 DCHECK(m_textureUploader.get()); |
289 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); | 289 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); |
290 m_textureUploader->upload(image, | 290 m_textureUploader->upload(image, |
291 imageRect, | 291 imageRect, |
292 sourceRect, | 292 sourceRect, |
293 destOffset, | 293 destOffset, |
294 resource->format, | 294 resource->format, |
295 resource->size); | 295 resource->size); |
296 } | 296 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 { | 339 { |
340 if (!m_textureUploader) | 340 if (!m_textureUploader) |
341 return; | 341 return; |
342 | 342 |
343 m_textureUploader->flush(); | 343 m_textureUploader->flush(); |
344 } | 344 } |
345 | 345 |
346 void ResourceProvider::flush() | 346 void ResourceProvider::flush() |
347 { | 347 { |
348 DCHECK(m_threadChecker.CalledOnValidThread()); | 348 DCHECK(m_threadChecker.CalledOnValidThread()); |
349 WebGraphicsContext3D* context3d = m_context->context3D(); | 349 WebGraphicsContext3D* context3d = m_context->Context3D(); |
350 if (context3d) | 350 if (context3d) |
351 context3d->flush(); | 351 context3d->flush(); |
352 } | 352 } |
353 | 353 |
354 bool ResourceProvider::shallowFlushIfSupported() | 354 bool ResourceProvider::shallowFlushIfSupported() |
355 { | 355 { |
356 DCHECK(m_threadChecker.CalledOnValidThread()); | 356 DCHECK(m_threadChecker.CalledOnValidThread()); |
357 WebGraphicsContext3D* context3d = m_context->context3D(); | 357 WebGraphicsContext3D* context3d = m_context->Context3D(); |
358 if (!context3d || !m_useShallowFlush) | 358 if (!context3d || !m_useShallowFlush) |
359 return false; | 359 return false; |
360 | 360 |
361 context3d->shallowFlushCHROMIUM(); | 361 context3d->shallowFlushCHROMIUM(); |
362 return true; | 362 return true; |
363 } | 363 } |
364 | 364 |
365 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) | 365 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) |
366 { | 366 { |
367 DCHECK(m_threadChecker.CalledOnValidThread()); | 367 DCHECK(m_threadChecker.CalledOnValidThread()); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 , m_useTextureStorageExt(false) | 478 , m_useTextureStorageExt(false) |
479 , m_useTextureUsageHint(false) | 479 , m_useTextureUsageHint(false) |
480 , m_useShallowFlush(false) | 480 , m_useShallowFlush(false) |
481 , m_maxTextureSize(0) | 481 , m_maxTextureSize(0) |
482 { | 482 { |
483 } | 483 } |
484 | 484 |
485 bool ResourceProvider::initialize() | 485 bool ResourceProvider::initialize() |
486 { | 486 { |
487 DCHECK(m_threadChecker.CalledOnValidThread()); | 487 DCHECK(m_threadChecker.CalledOnValidThread()); |
488 WebGraphicsContext3D* context3d = m_context->context3D(); | 488 WebGraphicsContext3D* context3d = m_context->Context3D(); |
489 if (!context3d) { | 489 if (!context3d) { |
490 m_maxTextureSize = INT_MAX / 2; | 490 m_maxTextureSize = INT_MAX / 2; |
491 return true; | 491 return true; |
492 } | 492 } |
493 if (!context3d->makeContextCurrent()) | 493 if (!context3d->makeContextCurrent()) |
494 return false; | 494 return false; |
495 | 495 |
496 std::string extensionsString = UTF16ToASCII(context3d->getString(GL_EXTENSIO
NS)); | 496 std::string extensionsString = UTF16ToASCII(context3d->getString(GL_EXTENSIO
NS)); |
497 std::vector<std::string> extensions; | 497 std::vector<std::string> extensions; |
498 base::SplitString(extensionsString, ' ', &extensions); | 498 base::SplitString(extensionsString, ' ', &extensions); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 ChildMap::const_iterator it = m_children.find(child); | 543 ChildMap::const_iterator it = m_children.find(child); |
544 DCHECK(it != m_children.end()); | 544 DCHECK(it != m_children.end()); |
545 return it->second.childToParentMap; | 545 return it->second.childToParentMap; |
546 } | 546 } |
547 | 547 |
548 void ResourceProvider::prepareSendToParent(const ResourceIdArray& resources, Tra
nsferableResourceList* list) | 548 void ResourceProvider::prepareSendToParent(const ResourceIdArray& resources, Tra
nsferableResourceList* list) |
549 { | 549 { |
550 DCHECK(m_threadChecker.CalledOnValidThread()); | 550 DCHECK(m_threadChecker.CalledOnValidThread()); |
551 list->sync_point = 0; | 551 list->sync_point = 0; |
552 list->resources.clear(); | 552 list->resources.clear(); |
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 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 558 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
559 TransferableResource resource; | 559 TransferableResource resource; |
560 if (transferResource(context3d, *it, &resource)) { | 560 if (transferResource(context3d, *it, &resource)) { |
561 m_resources.find(*it)->second.exported = true; | 561 m_resources.find(*it)->second.exported = true; |
562 list->resources.push_back(resource); | 562 list->resources.push_back(resource); |
563 } | 563 } |
564 } | 564 } |
565 if (list->resources.size()) | 565 if (list->resources.size()) |
566 list->sync_point = context3d->insertSyncPoint(); | 566 list->sync_point = context3d->insertSyncPoint(); |
567 } | 567 } |
568 | 568 |
569 void ResourceProvider::prepareSendToChild(int child, const ResourceIdArray& reso
urces, TransferableResourceList* list) | 569 void ResourceProvider::prepareSendToChild(int child, const ResourceIdArray& reso
urces, TransferableResourceList* list) |
570 { | 570 { |
571 DCHECK(m_threadChecker.CalledOnValidThread()); | 571 DCHECK(m_threadChecker.CalledOnValidThread()); |
572 list->sync_point = 0; | 572 list->sync_point = 0; |
573 list->resources.clear(); | 573 list->resources.clear(); |
574 WebGraphicsContext3D* context3d = m_context->context3D(); | 574 WebGraphicsContext3D* context3d = m_context->Context3D(); |
575 if (!context3d || !context3d->makeContextCurrent()) { | 575 if (!context3d || !context3d->makeContextCurrent()) { |
576 // FIXME: Implement this path for software compositing. | 576 // FIXME: Implement this path for software compositing. |
577 return; | 577 return; |
578 } | 578 } |
579 Child& childInfo = m_children.find(child)->second; | 579 Child& childInfo = m_children.find(child)->second; |
580 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 580 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
581 TransferableResource resource; | 581 TransferableResource resource; |
582 if (!transferResource(context3d, *it, &resource)) | 582 if (!transferResource(context3d, *it, &resource)) |
583 NOTREACHED(); | 583 NOTREACHED(); |
584 DCHECK(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa
p.end()); | 584 DCHECK(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa
p.end()); |
585 resource.id = childInfo.parentToChildMap[*it]; | 585 resource.id = childInfo.parentToChildMap[*it]; |
586 childInfo.parentToChildMap.erase(*it); | 586 childInfo.parentToChildMap.erase(*it); |
587 childInfo.childToParentMap.erase(resource.id); | 587 childInfo.childToParentMap.erase(resource.id); |
588 list->resources.push_back(resource); | 588 list->resources.push_back(resource); |
589 deleteResource(*it); | 589 deleteResource(*it); |
590 } | 590 } |
591 if (list->resources.size()) | 591 if (list->resources.size()) |
592 list->sync_point = context3d->insertSyncPoint(); | 592 list->sync_point = context3d->insertSyncPoint(); |
593 } | 593 } |
594 | 594 |
595 void ResourceProvider::receiveFromChild(int child, const TransferableResourceLis
t& resources) | 595 void ResourceProvider::receiveFromChild(int child, const TransferableResourceLis
t& resources) |
596 { | 596 { |
597 DCHECK(m_threadChecker.CalledOnValidThread()); | 597 DCHECK(m_threadChecker.CalledOnValidThread()); |
598 WebGraphicsContext3D* context3d = m_context->context3D(); | 598 WebGraphicsContext3D* context3d = m_context->Context3D(); |
599 if (!context3d || !context3d->makeContextCurrent()) { | 599 if (!context3d || !context3d->makeContextCurrent()) { |
600 // FIXME: Implement this path for software compositing. | 600 // FIXME: Implement this path for software compositing. |
601 return; | 601 return; |
602 } | 602 } |
603 if (resources.sync_point) { | 603 if (resources.sync_point) { |
604 // NOTE: If the parent is a browser and the child a renderer, the parent | 604 // NOTE: If the parent is a browser and the child a renderer, the parent |
605 // is not supposed to have its context wait, because that could induce | 605 // is not supposed to have its context wait, because that could induce |
606 // deadlocks and/or security issues. The caller is responsible for | 606 // deadlocks and/or security issues. The caller is responsible for |
607 // waiting asynchronously, and resetting sync_point before calling this. | 607 // waiting asynchronously, and resetting sync_point before calling this. |
608 // However if the parent is a renderer (e.g. browser tag), it may be ok | 608 // However if the parent is a renderer (e.g. browser tag), it may be ok |
(...skipping 11 matching lines...) Expand all Loading... |
620 resource.mailbox.setName(it->mailbox.name); | 620 resource.mailbox.setName(it->mailbox.name); |
621 m_resources[id] = resource; | 621 m_resources[id] = resource; |
622 childInfo.parentToChildMap[id] = it->id; | 622 childInfo.parentToChildMap[id] = it->id; |
623 childInfo.childToParentMap[it->id] = id; | 623 childInfo.childToParentMap[it->id] = id; |
624 } | 624 } |
625 } | 625 } |
626 | 626 |
627 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc
es) | 627 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc
es) |
628 { | 628 { |
629 DCHECK(m_threadChecker.CalledOnValidThread()); | 629 DCHECK(m_threadChecker.CalledOnValidThread()); |
630 WebGraphicsContext3D* context3d = m_context->context3D(); | 630 WebGraphicsContext3D* context3d = m_context->Context3D(); |
631 if (!context3d || !context3d->makeContextCurrent()) { | 631 if (!context3d || !context3d->makeContextCurrent()) { |
632 // FIXME: Implement this path for software compositing. | 632 // FIXME: Implement this path for software compositing. |
633 return; | 633 return; |
634 } | 634 } |
635 if (resources.sync_point) | 635 if (resources.sync_point) |
636 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); | 636 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); |
637 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { | 637 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { |
638 ResourceMap::iterator mapIterator = m_resources.find(it->id); | 638 ResourceMap::iterator mapIterator = m_resources.find(it->id); |
639 DCHECK(mapIterator != m_resources.end()); | 639 DCHECK(mapIterator != m_resources.end()); |
640 Resource* resource = &mapIterator->second; | 640 Resource* resource = &mapIterator->second; |
641 DCHECK(resource->exported); | 641 DCHECK(resource->exported); |
642 resource->exported = false; | 642 resource->exported = false; |
643 resource->mailbox.setName(it->mailbox.name); | 643 resource->mailbox.setName(it->mailbox.name); |
644 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); | 644 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); |
645 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail
box.name)); | 645 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail
box.name)); |
646 if (resource->markedForDeletion) | 646 if (resource->markedForDeletion) |
647 deleteResourceInternal(mapIterator); | 647 deleteResourceInternal(mapIterator); |
648 } | 648 } |
649 } | 649 } |
650 | 650 |
651 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI
d id, TransferableResource* resource) | 651 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI
d id, TransferableResource* resource) |
652 { | 652 { |
653 DCHECK(m_threadChecker.CalledOnValidThread()); | 653 DCHECK(m_threadChecker.CalledOnValidThread()); |
654 WebGraphicsContext3D* context3d = m_context->context3D(); | 654 WebGraphicsContext3D* context3d = m_context->Context3D(); |
655 ResourceMap::iterator it = m_resources.find(id); | 655 ResourceMap::iterator it = m_resources.find(id); |
656 CHECK(it != m_resources.end()); | 656 CHECK(it != m_resources.end()); |
657 Resource* source = &it->second; | 657 Resource* source = &it->second; |
658 DCHECK(!source->lockedForWrite); | 658 DCHECK(!source->lockedForWrite); |
659 DCHECK(!source->lockForReadCount); | 659 DCHECK(!source->lockForReadCount); |
660 DCHECK(!source->external); | 660 DCHECK(!source->external); |
661 if (source->exported) | 661 if (source->exported) |
662 return false; | 662 return false; |
663 resource->id = id; | 663 resource->id = id; |
664 resource->format = source->format; | 664 resource->format = source->format; |
(...skipping 14 matching lines...) Expand all Loading... |
679 void ResourceProvider::acquirePixelBuffer(ResourceId id) | 679 void ResourceProvider::acquirePixelBuffer(ResourceId id) |
680 { | 680 { |
681 DCHECK(m_threadChecker.CalledOnValidThread()); | 681 DCHECK(m_threadChecker.CalledOnValidThread()); |
682 ResourceMap::iterator it = m_resources.find(id); | 682 ResourceMap::iterator it = m_resources.find(id); |
683 CHECK(it != m_resources.end()); | 683 CHECK(it != m_resources.end()); |
684 Resource* resource = &it->second; | 684 Resource* resource = &it->second; |
685 DCHECK(!resource->external); | 685 DCHECK(!resource->external); |
686 DCHECK(!resource->exported); | 686 DCHECK(!resource->exported); |
687 | 687 |
688 if (resource->glId) { | 688 if (resource->glId) { |
689 WebGraphicsContext3D* context3d = m_context->context3D(); | 689 WebGraphicsContext3D* context3d = m_context->Context3D(); |
690 DCHECK(context3d); | 690 DCHECK(context3d); |
691 if (!resource->glPixelBufferId) | 691 if (!resource->glPixelBufferId) |
692 resource->glPixelBufferId = context3d->createBuffer(); | 692 resource->glPixelBufferId = context3d->createBuffer(); |
693 context3d->bindBuffer( | 693 context3d->bindBuffer( |
694 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 694 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
695 resource->glPixelBufferId); | 695 resource->glPixelBufferId); |
696 context3d->bufferData( | 696 context3d->bufferData( |
697 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 697 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
698 resource->size.width() * resource->size.height() * 4, | 698 resource->size.width() * resource->size.height() * 4, |
699 NULL, | 699 NULL, |
(...skipping 14 matching lines...) Expand all Loading... |
714 { | 714 { |
715 DCHECK(m_threadChecker.CalledOnValidThread()); | 715 DCHECK(m_threadChecker.CalledOnValidThread()); |
716 ResourceMap::iterator it = m_resources.find(id); | 716 ResourceMap::iterator it = m_resources.find(id); |
717 CHECK(it != m_resources.end()); | 717 CHECK(it != m_resources.end()); |
718 Resource* resource = &it->second; | 718 Resource* resource = &it->second; |
719 DCHECK(!resource->external); | 719 DCHECK(!resource->external); |
720 DCHECK(!resource->exported); | 720 DCHECK(!resource->exported); |
721 | 721 |
722 if (resource->glId) { | 722 if (resource->glId) { |
723 DCHECK(resource->glPixelBufferId); | 723 DCHECK(resource->glPixelBufferId); |
724 WebGraphicsContext3D* context3d = m_context->context3D(); | 724 WebGraphicsContext3D* context3d = m_context->Context3D(); |
725 DCHECK(context3d); | 725 DCHECK(context3d); |
726 context3d->bindBuffer( | 726 context3d->bindBuffer( |
727 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 727 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
728 resource->glPixelBufferId); | 728 resource->glPixelBufferId); |
729 context3d->bufferData( | 729 context3d->bufferData( |
730 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 730 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
731 0, | 731 0, |
732 NULL, | 732 NULL, |
733 GL_DYNAMIC_DRAW); | 733 GL_DYNAMIC_DRAW); |
734 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 734 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
(...skipping 10 matching lines...) Expand all Loading... |
745 uint8_t* ResourceProvider::mapPixelBuffer(ResourceId id) | 745 uint8_t* ResourceProvider::mapPixelBuffer(ResourceId id) |
746 { | 746 { |
747 DCHECK(m_threadChecker.CalledOnValidThread()); | 747 DCHECK(m_threadChecker.CalledOnValidThread()); |
748 ResourceMap::iterator it = m_resources.find(id); | 748 ResourceMap::iterator it = m_resources.find(id); |
749 CHECK(it != m_resources.end()); | 749 CHECK(it != m_resources.end()); |
750 Resource* resource = &it->second; | 750 Resource* resource = &it->second; |
751 DCHECK(!resource->external); | 751 DCHECK(!resource->external); |
752 DCHECK(!resource->exported); | 752 DCHECK(!resource->exported); |
753 | 753 |
754 if (resource->glId) { | 754 if (resource->glId) { |
755 WebGraphicsContext3D* context3d = m_context->context3D(); | 755 WebGraphicsContext3D* context3d = m_context->Context3D(); |
756 DCHECK(context3d); | 756 DCHECK(context3d); |
757 DCHECK(resource->glPixelBufferId); | 757 DCHECK(resource->glPixelBufferId); |
758 context3d->bindBuffer( | 758 context3d->bindBuffer( |
759 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 759 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
760 resource->glPixelBufferId); | 760 resource->glPixelBufferId); |
761 uint8_t* image = static_cast<uint8_t*>( | 761 uint8_t* image = static_cast<uint8_t*>( |
762 context3d->mapBufferCHROMIUM( | 762 context3d->mapBufferCHROMIUM( |
763 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); | 763 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); |
764 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 764 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
765 DCHECK(image); | 765 DCHECK(image); |
766 return image; | 766 return image; |
767 } | 767 } |
768 | 768 |
769 if (resource->pixels) | 769 if (resource->pixels) |
770 return resource->pixelBuffer; | 770 return resource->pixelBuffer; |
771 | 771 |
772 return NULL; | 772 return NULL; |
773 } | 773 } |
774 | 774 |
775 void ResourceProvider::unmapPixelBuffer(ResourceId id) | 775 void ResourceProvider::unmapPixelBuffer(ResourceId id) |
776 { | 776 { |
777 DCHECK(m_threadChecker.CalledOnValidThread()); | 777 DCHECK(m_threadChecker.CalledOnValidThread()); |
778 ResourceMap::iterator it = m_resources.find(id); | 778 ResourceMap::iterator it = m_resources.find(id); |
779 CHECK(it != m_resources.end()); | 779 CHECK(it != m_resources.end()); |
780 Resource* resource = &it->second; | 780 Resource* resource = &it->second; |
781 DCHECK(!resource->external); | 781 DCHECK(!resource->external); |
782 DCHECK(!resource->exported); | 782 DCHECK(!resource->exported); |
783 | 783 |
784 if (resource->glId) { | 784 if (resource->glId) { |
785 WebGraphicsContext3D* context3d = m_context->context3D(); | 785 WebGraphicsContext3D* context3d = m_context->Context3D(); |
786 DCHECK(context3d); | 786 DCHECK(context3d); |
787 DCHECK(resource->glPixelBufferId); | 787 DCHECK(resource->glPixelBufferId); |
788 context3d->bindBuffer( | 788 context3d->bindBuffer( |
789 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 789 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
790 resource->glPixelBufferId); | 790 resource->glPixelBufferId); |
791 context3d->unmapBufferCHROMIUM( | 791 context3d->unmapBufferCHROMIUM( |
792 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); | 792 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); |
793 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 793 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
794 } | 794 } |
795 } | 795 } |
796 | 796 |
797 void ResourceProvider::setPixelsFromBuffer(ResourceId id) | 797 void ResourceProvider::setPixelsFromBuffer(ResourceId id) |
798 { | 798 { |
799 DCHECK(m_threadChecker.CalledOnValidThread()); | 799 DCHECK(m_threadChecker.CalledOnValidThread()); |
800 ResourceMap::iterator it = m_resources.find(id); | 800 ResourceMap::iterator it = m_resources.find(id); |
801 CHECK(it != m_resources.end()); | 801 CHECK(it != m_resources.end()); |
802 Resource* resource = &it->second; | 802 Resource* resource = &it->second; |
803 DCHECK(!resource->lockedForWrite); | 803 DCHECK(!resource->lockedForWrite); |
804 DCHECK(!resource->lockForReadCount); | 804 DCHECK(!resource->lockForReadCount); |
805 DCHECK(!resource->external); | 805 DCHECK(!resource->external); |
806 DCHECK(!resource->exported); | 806 DCHECK(!resource->exported); |
807 | 807 |
808 if (resource->glId) { | 808 if (resource->glId) { |
809 WebGraphicsContext3D* context3d = m_context->context3D(); | 809 WebGraphicsContext3D* context3d = m_context->Context3D(); |
810 DCHECK(context3d); | 810 DCHECK(context3d); |
811 DCHECK(resource->glPixelBufferId); | 811 DCHECK(resource->glPixelBufferId); |
812 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); | 812 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); |
813 context3d->bindBuffer( | 813 context3d->bindBuffer( |
814 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 814 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
815 resource->glPixelBufferId); | 815 resource->glPixelBufferId); |
816 context3d->texSubImage2D(GL_TEXTURE_2D, | 816 context3d->texSubImage2D(GL_TEXTURE_2D, |
817 0, /* level */ | 817 0, /* level */ |
818 0, /* x */ | 818 0, /* x */ |
819 0, /* y */ | 819 0, /* y */ |
(...skipping 14 matching lines...) Expand all Loading... |
834 resource->size.height()); | 834 resource->size.height()); |
835 src.setPixels(resource->pixelBuffer); | 835 src.setPixels(resource->pixelBuffer); |
836 | 836 |
837 ScopedWriteLockSoftware lock(this, id); | 837 ScopedWriteLockSoftware lock(this, id); |
838 SkCanvas* dest = lock.skCanvas(); | 838 SkCanvas* dest = lock.skCanvas(); |
839 dest->writePixels(src, 0, 0); | 839 dest->writePixels(src, 0, 0); |
840 } | 840 } |
841 } | 841 } |
842 | 842 |
843 } // namespace cc | 843 } // namespace cc |
OLD | NEW |