| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 102 } |
| 103 | 103 |
| 104 ResourceProvider::Child::Child() | 104 ResourceProvider::Child::Child() |
| 105 { | 105 { |
| 106 } | 106 } |
| 107 | 107 |
| 108 ResourceProvider::Child::~Child() | 108 ResourceProvider::Child::~Child() |
| 109 { | 109 { |
| 110 } | 110 } |
| 111 | 111 |
| 112 scoped_ptr<ResourceProvider> ResourceProvider::create(GraphicsContext* context) | 112 scoped_ptr<ResourceProvider> ResourceProvider::create(OutputSurface* context) |
| 113 { | 113 { |
| 114 scoped_ptr<ResourceProvider> resourceProvider(new ResourceProvider(context))
; | 114 scoped_ptr<ResourceProvider> resourceProvider(new ResourceProvider(context))
; |
| 115 if (!resourceProvider->initialize()) | 115 if (!resourceProvider->initialize()) |
| 116 return scoped_ptr<ResourceProvider>(); | 116 return scoped_ptr<ResourceProvider>(); |
| 117 return resourceProvider.Pass(); | 117 return resourceProvider.Pass(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 ResourceProvider::~ResourceProvider() | 120 ResourceProvider::~ResourceProvider() |
| 121 { | 121 { |
| 122 WebGraphicsContext3D* context3d = m_context->context3D(); | 122 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 123 if (!context3d || !context3d->makeContextCurrent()) | 123 if (!context3d || !context3d->makeContextCurrent()) |
| 124 return; | 124 return; |
| 125 m_textureUploader.reset(); | 125 m_textureUploader.reset(); |
| 126 m_textureCopier.reset(); | 126 m_textureCopier.reset(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 WebGraphicsContext3D* ResourceProvider::graphicsContext3D() | 129 WebGraphicsContext3D* ResourceProvider::graphicsContext3D() |
| 130 { | 130 { |
| 131 DCHECK(m_threadChecker.CalledOnValidThread()); | 131 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 132 return m_context->context3D(); | 132 return m_outputSurface->context3D(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 bool ResourceProvider::inUseByConsumer(ResourceId id) | 135 bool ResourceProvider::inUseByConsumer(ResourceId id) |
| 136 { | 136 { |
| 137 DCHECK(m_threadChecker.CalledOnValidThread()); | 137 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 138 ResourceMap::iterator it = m_resources.find(id); | 138 ResourceMap::iterator it = m_resources.find(id); |
| 139 CHECK(it != m_resources.end()); | 139 CHECK(it != m_resources.end()); |
| 140 Resource* resource = &it->second; | 140 Resource* resource = &it->second; |
| 141 return !!resource->lockForReadCount || resource->exported; | 141 return !!resource->lockForReadCount || resource->exported; |
| 142 } | 142 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 155 return 0; | 155 return 0; |
| 156 } | 156 } |
| 157 | 157 |
| 158 ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const g
fx::Size& size, GLenum format, TextureUsageHint hint) | 158 ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const g
fx::Size& size, GLenum format, TextureUsageHint hint) |
| 159 { | 159 { |
| 160 DCHECK_LE(size.width(), m_maxTextureSize); | 160 DCHECK_LE(size.width(), m_maxTextureSize); |
| 161 DCHECK_LE(size.height(), m_maxTextureSize); | 161 DCHECK_LE(size.height(), m_maxTextureSize); |
| 162 | 162 |
| 163 DCHECK(m_threadChecker.CalledOnValidThread()); | 163 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 164 unsigned textureId = 0; | 164 unsigned textureId = 0; |
| 165 WebGraphicsContext3D* context3d = m_context->context3D(); | 165 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 166 DCHECK(context3d); | 166 DCHECK(context3d); |
| 167 GLC(context3d, textureId = context3d->createTexture()); | 167 GLC(context3d, textureId = context3d->createTexture()); |
| 168 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | 168 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); |
| 169 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); | 169 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); |
| 170 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); | 170 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); |
| 171 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); | 171 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); |
| 172 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); | 172 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); |
| 173 | 173 |
| 174 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) | 174 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) |
| 175 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_
ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); | 175 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_
ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 194 ResourceId id = m_nextId++; | 194 ResourceId id = m_nextId++; |
| 195 Resource resource(pixels, pool, size, GL_RGBA, GL_LINEAR); | 195 Resource resource(pixels, pool, size, GL_RGBA, GL_LINEAR); |
| 196 m_resources[id] = resource; | 196 m_resources[id] = resource; |
| 197 return id; | 197 return id; |
| 198 } | 198 } |
| 199 | 199 |
| 200 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture
(unsigned textureId) | 200 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture
(unsigned textureId) |
| 201 { | 201 { |
| 202 DCHECK(m_threadChecker.CalledOnValidThread()); | 202 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 203 | 203 |
| 204 WebGraphicsContext3D* context3d = m_context->context3D(); | 204 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 205 DCHECK(context3d); | 205 DCHECK(context3d); |
| 206 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | 206 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); |
| 207 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); | 207 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); |
| 208 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); | 208 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); |
| 209 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); | 209 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); |
| 210 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); | 210 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); |
| 211 | 211 |
| 212 ResourceId id = m_nextId++; | 212 ResourceId id = m_nextId++; |
| 213 Resource resource(textureId, 0, gfx::Size(), 0, GL_LINEAR); | 213 Resource resource(textureId, 0, gfx::Size(), 0, GL_LINEAR); |
| 214 resource.external = true; | 214 resource.external = true; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 230 resource->markedForDeletion = true; | 230 resource->markedForDeletion = true; |
| 231 return; | 231 return; |
| 232 } else | 232 } else |
| 233 deleteResourceInternal(it); | 233 deleteResourceInternal(it); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void ResourceProvider::deleteResourceInternal(ResourceMap::iterator it) | 236 void ResourceProvider::deleteResourceInternal(ResourceMap::iterator it) |
| 237 { | 237 { |
| 238 Resource* resource = &it->second; | 238 Resource* resource = &it->second; |
| 239 if (resource->glId && !resource->external) { | 239 if (resource->glId && !resource->external) { |
| 240 WebGraphicsContext3D* context3d = m_context->context3D(); | 240 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 241 DCHECK(context3d); | 241 DCHECK(context3d); |
| 242 GLC(context3d, context3d->deleteTexture(resource->glId)); | 242 GLC(context3d, context3d->deleteTexture(resource->glId)); |
| 243 } | 243 } |
| 244 if (resource->glPixelBufferId) { | 244 if (resource->glPixelBufferId) { |
| 245 WebGraphicsContext3D* context3d = m_context->context3D(); | 245 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 246 DCHECK(context3d); | 246 DCHECK(context3d); |
| 247 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId)); | 247 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId)); |
| 248 } | 248 } |
| 249 if (resource->pixels) | 249 if (resource->pixels) |
| 250 delete[] resource->pixels; | 250 delete[] resource->pixels; |
| 251 if (resource->pixelBuffer) | 251 if (resource->pixelBuffer) |
| 252 delete[] resource->pixelBuffer; | 252 delete[] resource->pixelBuffer; |
| 253 | 253 |
| 254 m_resources.erase(it); | 254 m_resources.erase(it); |
| 255 } | 255 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 279 DCHECK(m_threadChecker.CalledOnValidThread()); | 279 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 280 ResourceMap::iterator it = m_resources.find(id); | 280 ResourceMap::iterator it = m_resources.find(id); |
| 281 CHECK(it != m_resources.end()); | 281 CHECK(it != m_resources.end()); |
| 282 Resource* resource = &it->second; | 282 Resource* resource = &it->second; |
| 283 DCHECK(!resource->lockedForWrite); | 283 DCHECK(!resource->lockedForWrite); |
| 284 DCHECK(!resource->lockForReadCount); | 284 DCHECK(!resource->lockForReadCount); |
| 285 DCHECK(!resource->external); | 285 DCHECK(!resource->external); |
| 286 DCHECK(!resource->exported); | 286 DCHECK(!resource->exported); |
| 287 | 287 |
| 288 if (resource->glId) { | 288 if (resource->glId) { |
| 289 WebGraphicsContext3D* context3d = m_context->context3D(); | 289 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 290 DCHECK(context3d); | 290 DCHECK(context3d); |
| 291 DCHECK(m_textureUploader.get()); | 291 DCHECK(m_textureUploader.get()); |
| 292 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); | 292 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); |
| 293 m_textureUploader->upload(image, | 293 m_textureUploader->upload(image, |
| 294 imageRect, | 294 imageRect, |
| 295 sourceRect, | 295 sourceRect, |
| 296 destOffset, | 296 destOffset, |
| 297 resource->format, | 297 resource->format, |
| 298 resource->size); | 298 resource->size); |
| 299 } | 299 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 { | 342 { |
| 343 if (!m_textureUploader) | 343 if (!m_textureUploader) |
| 344 return; | 344 return; |
| 345 | 345 |
| 346 m_textureUploader->flush(); | 346 m_textureUploader->flush(); |
| 347 } | 347 } |
| 348 | 348 |
| 349 void ResourceProvider::flush() | 349 void ResourceProvider::flush() |
| 350 { | 350 { |
| 351 DCHECK(m_threadChecker.CalledOnValidThread()); | 351 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 352 WebGraphicsContext3D* context3d = m_context->context3D(); | 352 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 353 if (context3d) | 353 if (context3d) |
| 354 context3d->flush(); | 354 context3d->flush(); |
| 355 } | 355 } |
| 356 | 356 |
| 357 bool ResourceProvider::shallowFlushIfSupported() | 357 bool ResourceProvider::shallowFlushIfSupported() |
| 358 { | 358 { |
| 359 DCHECK(m_threadChecker.CalledOnValidThread()); | 359 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 360 WebGraphicsContext3D* context3d = m_context->context3D(); | 360 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 361 if (!context3d || !m_useShallowFlush) | 361 if (!context3d || !m_useShallowFlush) |
| 362 return false; | 362 return false; |
| 363 | 363 |
| 364 context3d->shallowFlushCHROMIUM(); | 364 context3d->shallowFlushCHROMIUM(); |
| 365 return true; | 365 return true; |
| 366 } | 366 } |
| 367 | 367 |
| 368 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) | 368 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) |
| 369 { | 369 { |
| 370 DCHECK(m_threadChecker.CalledOnValidThread()); | 370 DCHECK(m_threadChecker.CalledOnValidThread()); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 { | 472 { |
| 473 ResourceProvider::populateSkBitmapWithResource(&m_skBitmap, resourceProvider
->lockForWrite(resourceId)); | 473 ResourceProvider::populateSkBitmapWithResource(&m_skBitmap, resourceProvider
->lockForWrite(resourceId)); |
| 474 m_skCanvas.reset(new SkCanvas(m_skBitmap)); | 474 m_skCanvas.reset(new SkCanvas(m_skBitmap)); |
| 475 } | 475 } |
| 476 | 476 |
| 477 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() | 477 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() |
| 478 { | 478 { |
| 479 m_resourceProvider->unlockForWrite(m_resourceId); | 479 m_resourceProvider->unlockForWrite(m_resourceId); |
| 480 } | 480 } |
| 481 | 481 |
| 482 ResourceProvider::ResourceProvider(GraphicsContext* context) | 482 ResourceProvider::ResourceProvider(OutputSurface* context) |
| 483 : m_context(context) | 483 : m_outputSurface(context) |
| 484 , m_nextId(1) | 484 , m_nextId(1) |
| 485 , m_nextChild(1) | 485 , m_nextChild(1) |
| 486 , m_defaultResourceType(GLTexture) | 486 , m_defaultResourceType(GLTexture) |
| 487 , m_useTextureStorageExt(false) | 487 , m_useTextureStorageExt(false) |
| 488 , m_useTextureUsageHint(false) | 488 , m_useTextureUsageHint(false) |
| 489 , m_useShallowFlush(false) | 489 , m_useShallowFlush(false) |
| 490 , m_maxTextureSize(0) | 490 , m_maxTextureSize(0) |
| 491 { | 491 { |
| 492 } | 492 } |
| 493 | 493 |
| 494 bool ResourceProvider::initialize() | 494 bool ResourceProvider::initialize() |
| 495 { | 495 { |
| 496 DCHECK(m_threadChecker.CalledOnValidThread()); | 496 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 497 WebGraphicsContext3D* context3d = m_context->context3D(); | 497 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 498 if (!context3d) { | 498 if (!context3d) { |
| 499 m_maxTextureSize = INT_MAX / 2; | 499 m_maxTextureSize = INT_MAX / 2; |
| 500 return true; | 500 return true; |
| 501 } | 501 } |
| 502 if (!context3d->makeContextCurrent()) | 502 if (!context3d->makeContextCurrent()) |
| 503 return false; | 503 return false; |
| 504 | 504 |
| 505 std::string extensionsString = UTF16ToASCII(context3d->getString(GL_EXTENSIO
NS)); | 505 std::string extensionsString = UTF16ToASCII(context3d->getString(GL_EXTENSIO
NS)); |
| 506 std::vector<std::string> extensions; | 506 std::vector<std::string> extensions; |
| 507 base::SplitString(extensionsString, ' ', &extensions); | 507 base::SplitString(extensionsString, ' ', &extensions); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 ChildMap::const_iterator it = m_children.find(child); | 552 ChildMap::const_iterator it = m_children.find(child); |
| 553 DCHECK(it != m_children.end()); | 553 DCHECK(it != m_children.end()); |
| 554 return it->second.childToParentMap; | 554 return it->second.childToParentMap; |
| 555 } | 555 } |
| 556 | 556 |
| 557 void ResourceProvider::prepareSendToParent(const ResourceIdArray& resources, Tra
nsferableResourceList* list) | 557 void ResourceProvider::prepareSendToParent(const ResourceIdArray& resources, Tra
nsferableResourceList* list) |
| 558 { | 558 { |
| 559 DCHECK(m_threadChecker.CalledOnValidThread()); | 559 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 560 list->sync_point = 0; | 560 list->sync_point = 0; |
| 561 list->resources.clear(); | 561 list->resources.clear(); |
| 562 WebGraphicsContext3D* context3d = m_context->context3D(); | 562 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 563 if (!context3d || !context3d->makeContextCurrent()) { | 563 if (!context3d || !context3d->makeContextCurrent()) { |
| 564 // FIXME: Implement this path for software compositing. | 564 // FIXME: Implement this path for software compositing. |
| 565 return; | 565 return; |
| 566 } | 566 } |
| 567 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 567 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
| 568 TransferableResource resource; | 568 TransferableResource resource; |
| 569 if (transferResource(context3d, *it, &resource)) { | 569 if (transferResource(context3d, *it, &resource)) { |
| 570 m_resources.find(*it)->second.exported = true; | 570 m_resources.find(*it)->second.exported = true; |
| 571 list->resources.push_back(resource); | 571 list->resources.push_back(resource); |
| 572 } | 572 } |
| 573 } | 573 } |
| 574 if (list->resources.size()) | 574 if (list->resources.size()) |
| 575 list->sync_point = context3d->insertSyncPoint(); | 575 list->sync_point = context3d->insertSyncPoint(); |
| 576 } | 576 } |
| 577 | 577 |
| 578 void ResourceProvider::prepareSendToChild(int child, const ResourceIdArray& reso
urces, TransferableResourceList* list) | 578 void ResourceProvider::prepareSendToChild(int child, const ResourceIdArray& reso
urces, TransferableResourceList* list) |
| 579 { | 579 { |
| 580 DCHECK(m_threadChecker.CalledOnValidThread()); | 580 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 581 list->sync_point = 0; | 581 list->sync_point = 0; |
| 582 list->resources.clear(); | 582 list->resources.clear(); |
| 583 WebGraphicsContext3D* context3d = m_context->context3D(); | 583 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 584 if (!context3d || !context3d->makeContextCurrent()) { | 584 if (!context3d || !context3d->makeContextCurrent()) { |
| 585 // FIXME: Implement this path for software compositing. | 585 // FIXME: Implement this path for software compositing. |
| 586 return; | 586 return; |
| 587 } | 587 } |
| 588 Child& childInfo = m_children.find(child)->second; | 588 Child& childInfo = m_children.find(child)->second; |
| 589 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 589 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
| 590 TransferableResource resource; | 590 TransferableResource resource; |
| 591 if (!transferResource(context3d, *it, &resource)) | 591 if (!transferResource(context3d, *it, &resource)) |
| 592 NOTREACHED(); | 592 NOTREACHED(); |
| 593 DCHECK(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa
p.end()); | 593 DCHECK(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa
p.end()); |
| 594 resource.id = childInfo.parentToChildMap[*it]; | 594 resource.id = childInfo.parentToChildMap[*it]; |
| 595 childInfo.parentToChildMap.erase(*it); | 595 childInfo.parentToChildMap.erase(*it); |
| 596 childInfo.childToParentMap.erase(resource.id); | 596 childInfo.childToParentMap.erase(resource.id); |
| 597 list->resources.push_back(resource); | 597 list->resources.push_back(resource); |
| 598 deleteResource(*it); | 598 deleteResource(*it); |
| 599 } | 599 } |
| 600 if (list->resources.size()) | 600 if (list->resources.size()) |
| 601 list->sync_point = context3d->insertSyncPoint(); | 601 list->sync_point = context3d->insertSyncPoint(); |
| 602 } | 602 } |
| 603 | 603 |
| 604 void ResourceProvider::receiveFromChild(int child, const TransferableResourceLis
t& resources) | 604 void ResourceProvider::receiveFromChild(int child, const TransferableResourceLis
t& resources) |
| 605 { | 605 { |
| 606 DCHECK(m_threadChecker.CalledOnValidThread()); | 606 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 607 WebGraphicsContext3D* context3d = m_context->context3D(); | 607 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 608 if (!context3d || !context3d->makeContextCurrent()) { | 608 if (!context3d || !context3d->makeContextCurrent()) { |
| 609 // FIXME: Implement this path for software compositing. | 609 // FIXME: Implement this path for software compositing. |
| 610 return; | 610 return; |
| 611 } | 611 } |
| 612 if (resources.sync_point) { | 612 if (resources.sync_point) { |
| 613 // NOTE: If the parent is a browser and the child a renderer, the parent | 613 // NOTE: If the parent is a browser and the child a renderer, the parent |
| 614 // is not supposed to have its context wait, because that could induce | 614 // is not supposed to have its context wait, because that could induce |
| 615 // deadlocks and/or security issues. The caller is responsible for | 615 // deadlocks and/or security issues. The caller is responsible for |
| 616 // waiting asynchronously, and resetting sync_point before calling this. | 616 // waiting asynchronously, and resetting sync_point before calling this. |
| 617 // However if the parent is a renderer (e.g. browser tag), it may be ok | 617 // However if the parent is a renderer (e.g. browser tag), it may be ok |
| (...skipping 11 matching lines...) Expand all Loading... |
| 629 resource.mailbox.setName(it->mailbox.name); | 629 resource.mailbox.setName(it->mailbox.name); |
| 630 m_resources[id] = resource; | 630 m_resources[id] = resource; |
| 631 childInfo.parentToChildMap[id] = it->id; | 631 childInfo.parentToChildMap[id] = it->id; |
| 632 childInfo.childToParentMap[it->id] = id; | 632 childInfo.childToParentMap[it->id] = id; |
| 633 } | 633 } |
| 634 } | 634 } |
| 635 | 635 |
| 636 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc
es) | 636 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc
es) |
| 637 { | 637 { |
| 638 DCHECK(m_threadChecker.CalledOnValidThread()); | 638 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 639 WebGraphicsContext3D* context3d = m_context->context3D(); | 639 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 640 if (!context3d || !context3d->makeContextCurrent()) { | 640 if (!context3d || !context3d->makeContextCurrent()) { |
| 641 // FIXME: Implement this path for software compositing. | 641 // FIXME: Implement this path for software compositing. |
| 642 return; | 642 return; |
| 643 } | 643 } |
| 644 if (resources.sync_point) | 644 if (resources.sync_point) |
| 645 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); | 645 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); |
| 646 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { | 646 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { |
| 647 ResourceMap::iterator mapIterator = m_resources.find(it->id); | 647 ResourceMap::iterator mapIterator = m_resources.find(it->id); |
| 648 DCHECK(mapIterator != m_resources.end()); | 648 DCHECK(mapIterator != m_resources.end()); |
| 649 Resource* resource = &mapIterator->second; | 649 Resource* resource = &mapIterator->second; |
| 650 DCHECK(resource->exported); | 650 DCHECK(resource->exported); |
| 651 resource->exported = false; | 651 resource->exported = false; |
| 652 resource->mailbox.setName(it->mailbox.name); | 652 resource->mailbox.setName(it->mailbox.name); |
| 653 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); | 653 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); |
| 654 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail
box.name)); | 654 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail
box.name)); |
| 655 if (resource->markedForDeletion) | 655 if (resource->markedForDeletion) |
| 656 deleteResourceInternal(mapIterator); | 656 deleteResourceInternal(mapIterator); |
| 657 } | 657 } |
| 658 } | 658 } |
| 659 | 659 |
| 660 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI
d id, TransferableResource* resource) | 660 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI
d id, TransferableResource* resource) |
| 661 { | 661 { |
| 662 DCHECK(m_threadChecker.CalledOnValidThread()); | 662 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 663 WebGraphicsContext3D* context3d = m_context->context3D(); | 663 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 664 ResourceMap::iterator it = m_resources.find(id); | 664 ResourceMap::iterator it = m_resources.find(id); |
| 665 CHECK(it != m_resources.end()); | 665 CHECK(it != m_resources.end()); |
| 666 Resource* source = &it->second; | 666 Resource* source = &it->second; |
| 667 DCHECK(!source->lockedForWrite); | 667 DCHECK(!source->lockedForWrite); |
| 668 DCHECK(!source->lockForReadCount); | 668 DCHECK(!source->lockForReadCount); |
| 669 DCHECK(!source->external); | 669 DCHECK(!source->external); |
| 670 if (source->exported) | 670 if (source->exported) |
| 671 return false; | 671 return false; |
| 672 resource->id = id; | 672 resource->id = id; |
| 673 resource->format = source->format; | 673 resource->format = source->format; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 689 void ResourceProvider::acquirePixelBuffer(ResourceId id) | 689 void ResourceProvider::acquirePixelBuffer(ResourceId id) |
| 690 { | 690 { |
| 691 DCHECK(m_threadChecker.CalledOnValidThread()); | 691 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 692 ResourceMap::iterator it = m_resources.find(id); | 692 ResourceMap::iterator it = m_resources.find(id); |
| 693 CHECK(it != m_resources.end()); | 693 CHECK(it != m_resources.end()); |
| 694 Resource* resource = &it->second; | 694 Resource* resource = &it->second; |
| 695 DCHECK(!resource->external); | 695 DCHECK(!resource->external); |
| 696 DCHECK(!resource->exported); | 696 DCHECK(!resource->exported); |
| 697 | 697 |
| 698 if (resource->glId) { | 698 if (resource->glId) { |
| 699 WebGraphicsContext3D* context3d = m_context->context3D(); | 699 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 700 DCHECK(context3d); | 700 DCHECK(context3d); |
| 701 if (!resource->glPixelBufferId) | 701 if (!resource->glPixelBufferId) |
| 702 resource->glPixelBufferId = context3d->createBuffer(); | 702 resource->glPixelBufferId = context3d->createBuffer(); |
| 703 context3d->bindBuffer( | 703 context3d->bindBuffer( |
| 704 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 704 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 705 resource->glPixelBufferId); | 705 resource->glPixelBufferId); |
| 706 context3d->bufferData( | 706 context3d->bufferData( |
| 707 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 707 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 708 resource->size.width() * resource->size.height() * 4, | 708 resource->size.width() * resource->size.height() * 4, |
| 709 NULL, | 709 NULL, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 724 { | 724 { |
| 725 DCHECK(m_threadChecker.CalledOnValidThread()); | 725 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 726 ResourceMap::iterator it = m_resources.find(id); | 726 ResourceMap::iterator it = m_resources.find(id); |
| 727 CHECK(it != m_resources.end()); | 727 CHECK(it != m_resources.end()); |
| 728 Resource* resource = &it->second; | 728 Resource* resource = &it->second; |
| 729 DCHECK(!resource->external); | 729 DCHECK(!resource->external); |
| 730 DCHECK(!resource->exported); | 730 DCHECK(!resource->exported); |
| 731 | 731 |
| 732 if (resource->glId) { | 732 if (resource->glId) { |
| 733 DCHECK(resource->glPixelBufferId); | 733 DCHECK(resource->glPixelBufferId); |
| 734 WebGraphicsContext3D* context3d = m_context->context3D(); | 734 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 735 DCHECK(context3d); | 735 DCHECK(context3d); |
| 736 context3d->bindBuffer( | 736 context3d->bindBuffer( |
| 737 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 737 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 738 resource->glPixelBufferId); | 738 resource->glPixelBufferId); |
| 739 context3d->bufferData( | 739 context3d->bufferData( |
| 740 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 740 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 741 0, | 741 0, |
| 742 NULL, | 742 NULL, |
| 743 GL_DYNAMIC_DRAW); | 743 GL_DYNAMIC_DRAW); |
| 744 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 744 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 755 uint8_t* ResourceProvider::mapPixelBuffer(ResourceId id) | 755 uint8_t* ResourceProvider::mapPixelBuffer(ResourceId id) |
| 756 { | 756 { |
| 757 DCHECK(m_threadChecker.CalledOnValidThread()); | 757 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 758 ResourceMap::iterator it = m_resources.find(id); | 758 ResourceMap::iterator it = m_resources.find(id); |
| 759 CHECK(it != m_resources.end()); | 759 CHECK(it != m_resources.end()); |
| 760 Resource* resource = &it->second; | 760 Resource* resource = &it->second; |
| 761 DCHECK(!resource->external); | 761 DCHECK(!resource->external); |
| 762 DCHECK(!resource->exported); | 762 DCHECK(!resource->exported); |
| 763 | 763 |
| 764 if (resource->glId) { | 764 if (resource->glId) { |
| 765 WebGraphicsContext3D* context3d = m_context->context3D(); | 765 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 766 DCHECK(context3d); | 766 DCHECK(context3d); |
| 767 DCHECK(resource->glPixelBufferId); | 767 DCHECK(resource->glPixelBufferId); |
| 768 context3d->bindBuffer( | 768 context3d->bindBuffer( |
| 769 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 769 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 770 resource->glPixelBufferId); | 770 resource->glPixelBufferId); |
| 771 uint8_t* image = static_cast<uint8_t*>( | 771 uint8_t* image = static_cast<uint8_t*>( |
| 772 context3d->mapBufferCHROMIUM( | 772 context3d->mapBufferCHROMIUM( |
| 773 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); | 773 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); |
| 774 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 774 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 775 DCHECK(image); | 775 DCHECK(image); |
| 776 return image; | 776 return image; |
| 777 } | 777 } |
| 778 | 778 |
| 779 if (resource->pixels) | 779 if (resource->pixels) |
| 780 return resource->pixelBuffer; | 780 return resource->pixelBuffer; |
| 781 | 781 |
| 782 return NULL; | 782 return NULL; |
| 783 } | 783 } |
| 784 | 784 |
| 785 void ResourceProvider::unmapPixelBuffer(ResourceId id) | 785 void ResourceProvider::unmapPixelBuffer(ResourceId id) |
| 786 { | 786 { |
| 787 DCHECK(m_threadChecker.CalledOnValidThread()); | 787 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 788 ResourceMap::iterator it = m_resources.find(id); | 788 ResourceMap::iterator it = m_resources.find(id); |
| 789 CHECK(it != m_resources.end()); | 789 CHECK(it != m_resources.end()); |
| 790 Resource* resource = &it->second; | 790 Resource* resource = &it->second; |
| 791 DCHECK(!resource->external); | 791 DCHECK(!resource->external); |
| 792 DCHECK(!resource->exported); | 792 DCHECK(!resource->exported); |
| 793 | 793 |
| 794 if (resource->glId) { | 794 if (resource->glId) { |
| 795 WebGraphicsContext3D* context3d = m_context->context3D(); | 795 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 796 DCHECK(context3d); | 796 DCHECK(context3d); |
| 797 DCHECK(resource->glPixelBufferId); | 797 DCHECK(resource->glPixelBufferId); |
| 798 context3d->bindBuffer( | 798 context3d->bindBuffer( |
| 799 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 799 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 800 resource->glPixelBufferId); | 800 resource->glPixelBufferId); |
| 801 context3d->unmapBufferCHROMIUM( | 801 context3d->unmapBufferCHROMIUM( |
| 802 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); | 802 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); |
| 803 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 803 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 804 } | 804 } |
| 805 } | 805 } |
| 806 | 806 |
| 807 void ResourceProvider::setPixelsFromBuffer(ResourceId id) | 807 void ResourceProvider::setPixelsFromBuffer(ResourceId id) |
| 808 { | 808 { |
| 809 DCHECK(m_threadChecker.CalledOnValidThread()); | 809 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 810 ResourceMap::iterator it = m_resources.find(id); | 810 ResourceMap::iterator it = m_resources.find(id); |
| 811 CHECK(it != m_resources.end()); | 811 CHECK(it != m_resources.end()); |
| 812 Resource* resource = &it->second; | 812 Resource* resource = &it->second; |
| 813 DCHECK(!resource->lockedForWrite); | 813 DCHECK(!resource->lockedForWrite); |
| 814 DCHECK(!resource->lockForReadCount); | 814 DCHECK(!resource->lockForReadCount); |
| 815 DCHECK(!resource->external); | 815 DCHECK(!resource->external); |
| 816 DCHECK(!resource->exported); | 816 DCHECK(!resource->exported); |
| 817 | 817 |
| 818 if (resource->glId) { | 818 if (resource->glId) { |
| 819 WebGraphicsContext3D* context3d = m_context->context3D(); | 819 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 820 DCHECK(context3d); | 820 DCHECK(context3d); |
| 821 DCHECK(resource->glPixelBufferId); | 821 DCHECK(resource->glPixelBufferId); |
| 822 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); | 822 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); |
| 823 context3d->bindBuffer( | 823 context3d->bindBuffer( |
| 824 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 824 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 825 resource->glPixelBufferId); | 825 resource->glPixelBufferId); |
| 826 context3d->texSubImage2D(GL_TEXTURE_2D, | 826 context3d->texSubImage2D(GL_TEXTURE_2D, |
| 827 0, /* level */ | 827 0, /* level */ |
| 828 0, /* x */ | 828 0, /* x */ |
| 829 0, /* y */ | 829 0, /* y */ |
| (...skipping 16 matching lines...) Expand all Loading... |
| 846 | 846 |
| 847 ScopedWriteLockSoftware lock(this, id); | 847 ScopedWriteLockSoftware lock(this, id); |
| 848 SkCanvas* dest = lock.skCanvas(); | 848 SkCanvas* dest = lock.skCanvas(); |
| 849 dest->writePixels(src, 0, 0); | 849 dest->writePixels(src, 0, 0); |
| 850 } | 850 } |
| 851 } | 851 } |
| 852 | 852 |
| 853 void ResourceProvider::bindForSampling(ResourceProvider::ResourceId resourceId,
GLenum target, GLenum filter) | 853 void ResourceProvider::bindForSampling(ResourceProvider::ResourceId resourceId,
GLenum target, GLenum filter) |
| 854 { | 854 { |
| 855 DCHECK(m_threadChecker.CalledOnValidThread()); | 855 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 856 WebGraphicsContext3D* context3d = m_context->context3D(); | 856 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 857 ResourceMap::iterator it = m_resources.find(resourceId); | 857 ResourceMap::iterator it = m_resources.find(resourceId); |
| 858 DCHECK(it != m_resources.end()); | 858 DCHECK(it != m_resources.end()); |
| 859 Resource* resource = &it->second; | 859 Resource* resource = &it->second; |
| 860 DCHECK(resource->lockForReadCount); | 860 DCHECK(resource->lockForReadCount); |
| 861 DCHECK(!resource->lockedForWrite); | 861 DCHECK(!resource->lockedForWrite); |
| 862 | 862 |
| 863 GLC(context3d, context3d->bindTexture(target, resource->glId)); | 863 GLC(context3d, context3d->bindTexture(target, resource->glId)); |
| 864 if (filter != resource->filter) { | 864 if (filter != resource->filter) { |
| 865 GLC(context3d, context3d->texParameteri(target, GL_TEXTURE_MIN_FILTER, f
ilter)); | 865 GLC(context3d, context3d->texParameteri(target, GL_TEXTURE_MIN_FILTER, f
ilter)); |
| 866 GLC(context3d, context3d->texParameteri(target, GL_TEXTURE_MAG_FILTER, f
ilter)); | 866 GLC(context3d, context3d->texParameteri(target, GL_TEXTURE_MAG_FILTER, f
ilter)); |
| 867 resource->filter = filter; | 867 resource->filter = filter; |
| 868 } | 868 } |
| 869 } | 869 } |
| 870 | 870 |
| 871 } // namespace cc | 871 } // namespace cc |
| OLD | NEW |