Chromium Code Reviews| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 , glPixelBufferId(0) | 53 , glPixelBufferId(0) |
| 54 , glUploadQueryId(0) | 54 , glUploadQueryId(0) |
| 55 , pixels(0) | 55 , pixels(0) |
| 56 , pixelBuffer(0) | 56 , pixelBuffer(0) |
| 57 , lockForReadCount(0) | 57 , lockForReadCount(0) |
| 58 , lockedForWrite(false) | 58 , lockedForWrite(false) |
| 59 , external(false) | 59 , external(false) |
| 60 , exported(false) | 60 , exported(false) |
| 61 , markedForDeletion(false) | 61 , markedForDeletion(false) |
| 62 , pendingSetPixels(false) | 62 , pendingSetPixels(false) |
| 63 , allocated(false) | |
| 63 , size() | 64 , size() |
| 64 , format(0) | 65 , format(0) |
| 65 , filter(0) | 66 , filter(0) |
| 66 , type(static_cast<ResourceType>(0)) | 67 , type(static_cast<ResourceType>(0)) |
| 67 { | 68 { |
| 68 } | 69 } |
| 69 | 70 |
| 70 ResourceProvider::Resource::Resource(unsigned textureId, const gfx::Size& size, GLenum format, GLenum filter) | 71 ResourceProvider::Resource::Resource(unsigned textureId, const gfx::Size& size, GLenum format, GLenum filter) |
| 71 : glId(textureId) | 72 : glId(textureId) |
| 72 , glPixelBufferId(0) | 73 , glPixelBufferId(0) |
| 73 , glUploadQueryId(0) | 74 , glUploadQueryId(0) |
| 74 , pixels(0) | 75 , pixels(0) |
| 75 , pixelBuffer(0) | 76 , pixelBuffer(0) |
| 76 , lockForReadCount(0) | 77 , lockForReadCount(0) |
| 77 , lockedForWrite(false) | 78 , lockedForWrite(false) |
| 78 , external(false) | 79 , external(false) |
| 79 , exported(false) | 80 , exported(false) |
| 80 , markedForDeletion(false) | 81 , markedForDeletion(false) |
| 81 , pendingSetPixels(false) | 82 , pendingSetPixels(false) |
| 83 , allocated(false) | |
| 82 , size(size) | 84 , size(size) |
| 83 , format(format) | 85 , format(format) |
| 84 , filter(filter) | 86 , filter(filter) |
| 85 , type(GLTexture) | 87 , type(GLTexture) |
| 86 { | 88 { |
| 87 } | 89 } |
| 88 | 90 |
| 89 ResourceProvider::Resource::Resource(uint8_t* pixels, const gfx::Size& size, GLe num format, GLenum filter) | 91 ResourceProvider::Resource::Resource(uint8_t* pixels, const gfx::Size& size, GLe num format, GLenum filter) |
| 90 : glId(0) | 92 : glId(0) |
| 91 , glPixelBufferId(0) | 93 , glPixelBufferId(0) |
| 92 , glUploadQueryId(0) | 94 , glUploadQueryId(0) |
| 93 , pixels(pixels) | 95 , pixels(pixels) |
| 94 , pixelBuffer(0) | 96 , pixelBuffer(0) |
| 95 , lockForReadCount(0) | 97 , lockForReadCount(0) |
| 96 , lockedForWrite(false) | 98 , lockedForWrite(false) |
| 97 , external(false) | 99 , external(false) |
| 98 , exported(false) | 100 , exported(false) |
| 99 , markedForDeletion(false) | 101 , markedForDeletion(false) |
| 100 , pendingSetPixels(false) | 102 , pendingSetPixels(false) |
| 103 , allocated(false) | |
| 101 , size(size) | 104 , size(size) |
| 102 , format(format) | 105 , format(format) |
| 103 , filter(filter) | 106 , filter(filter) |
| 104 , type(Bitmap) | 107 , type(Bitmap) |
| 105 { | 108 { |
| 106 } | 109 } |
| 107 | 110 |
| 108 ResourceProvider::Child::Child() | 111 ResourceProvider::Child::Child() |
| 109 { | 112 { |
| 110 } | 113 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 { | 180 { |
| 178 DCHECK_LE(size.width(), m_maxTextureSize); | 181 DCHECK_LE(size.width(), m_maxTextureSize); |
| 179 DCHECK_LE(size.height(), m_maxTextureSize); | 182 DCHECK_LE(size.height(), m_maxTextureSize); |
| 180 | 183 |
| 181 DCHECK(m_threadChecker.CalledOnValidThread()); | 184 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 182 unsigned textureId = 0; | 185 unsigned textureId = 0; |
| 183 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 186 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
| 184 DCHECK(context3d); | 187 DCHECK(context3d); |
| 185 GLC(context3d, textureId = context3d->createTexture()); | 188 GLC(context3d, textureId = context3d->createTexture()); |
| 186 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | 189 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); |
| 190 | |
| 191 // Set texture properties. Allocation is delayed until needed. | |
| 187 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR)); | 192 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR)); |
| 188 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR)); | 193 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR)); |
| 189 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); | 194 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); |
| 190 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); | 195 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); |
| 191 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROM IUM, texturePool)); | 196 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROM IUM, texturePool)); |
| 192 | |
| 193 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) | 197 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) |
| 194 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); | 198 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); |
| 195 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { | |
| 196 GLenum storageFormat = textureToStorageFormat(format); | |
| 197 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma t, size.width(), size.height())); | |
| 198 } else | |
| 199 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); | |
| 200 | 199 |
| 201 ResourceId id = m_nextId++; | 200 ResourceId id = m_nextId++; |
| 202 Resource resource(textureId, size, format, GL_LINEAR); | 201 Resource resource(textureId, size, format, GL_LINEAR); |
| 202 resource.allocated = false; | |
| 203 m_resources[id] = resource; | 203 m_resources[id] = resource; |
| 204 return id; | 204 return id; |
| 205 } | 205 } |
| 206 | 206 |
| 207 ResourceProvider::ResourceId ResourceProvider::createBitmap(const gfx::Size& siz e) | 207 ResourceProvider::ResourceId ResourceProvider::createBitmap(const gfx::Size& siz e) |
| 208 { | 208 { |
| 209 DCHECK(m_threadChecker.CalledOnValidThread()); | 209 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 210 | 210 |
| 211 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; | 211 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; |
| 212 | 212 |
| 213 ResourceId id = m_nextId++; | 213 ResourceId id = m_nextId++; |
| 214 Resource resource(pixels, size, GL_RGBA, GL_LINEAR); | 214 Resource resource(pixels, size, GL_RGBA, GL_LINEAR); |
| 215 resource.allocated = true; | |
| 215 m_resources[id] = resource; | 216 m_resources[id] = resource; |
| 216 return id; | 217 return id; |
| 217 } | 218 } |
| 218 | 219 |
| 219 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture (unsigned textureId) | 220 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture (unsigned textureId) |
| 220 { | 221 { |
| 221 DCHECK(m_threadChecker.CalledOnValidThread()); | 222 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 222 | 223 |
| 223 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 224 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
| 224 DCHECK(context3d); | 225 DCHECK(context3d); |
| 225 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | 226 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); |
| 226 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR)); | 227 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR)); |
| 227 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR)); | 228 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR)); |
| 228 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); | 229 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); |
| 229 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); | 230 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); |
| 230 | 231 |
| 231 ResourceId id = m_nextId++; | 232 ResourceId id = m_nextId++; |
| 232 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR); | 233 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR); |
| 233 resource.external = true; | 234 resource.external = true; |
| 235 resource.allocated = true; | |
| 234 m_resources[id] = resource; | 236 m_resources[id] = resource; |
| 235 return id; | 237 return id; |
| 236 } | 238 } |
| 237 | 239 |
| 238 void ResourceProvider::deleteResource(ResourceId id) | 240 void ResourceProvider::deleteResource(ResourceId id) |
| 239 { | 241 { |
| 240 DCHECK(m_threadChecker.CalledOnValidThread()); | 242 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 241 ResourceMap::iterator it = m_resources.find(id); | 243 ResourceMap::iterator it = m_resources.find(id); |
| 242 CHECK(it != m_resources.end()); | 244 CHECK(it != m_resources.end()); |
| 243 Resource* resource = &it->second; | 245 Resource* resource = &it->second; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 DCHECK(m_threadChecker.CalledOnValidThread()); | 293 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 292 ResourceMap::iterator it = m_resources.find(id); | 294 ResourceMap::iterator it = m_resources.find(id); |
| 293 CHECK(it != m_resources.end()); | 295 CHECK(it != m_resources.end()); |
| 294 Resource* resource = &it->second; | 296 Resource* resource = &it->second; |
| 295 DCHECK(!resource->lockedForWrite); | 297 DCHECK(!resource->lockedForWrite); |
| 296 DCHECK(!resource->lockForReadCount); | 298 DCHECK(!resource->lockForReadCount); |
| 297 DCHECK(!resource->external); | 299 DCHECK(!resource->external); |
| 298 DCHECK(!resource->exported); | 300 DCHECK(!resource->exported); |
| 299 | 301 |
| 300 if (resource->glId) { | 302 if (resource->glId) { |
| 303 DCHECK(!resource->pendingSetPixels); | |
| 301 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 304 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
| 302 DCHECK(context3d); | 305 DCHECK(context3d); |
| 303 DCHECK(m_textureUploader.get()); | 306 DCHECK(m_textureUploader.get()); |
| 304 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); | 307 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); |
| 308 lazyAllocateTexture(context3d, resource); | |
| 305 m_textureUploader->upload(image, | 309 m_textureUploader->upload(image, |
| 306 imageRect, | 310 imageRect, |
| 307 sourceRect, | 311 sourceRect, |
| 308 destOffset, | 312 destOffset, |
| 309 resource->format, | 313 resource->format, |
| 310 resource->size); | 314 resource->size); |
| 311 } | 315 } |
| 312 | 316 |
| 313 if (resource->pixels) { | 317 if (resource->pixels) { |
| 318 DCHECK(resource->allocated); | |
| 314 DCHECK(resource->format == GL_RGBA); | 319 DCHECK(resource->format == GL_RGBA); |
| 315 SkBitmap srcFull; | 320 SkBitmap srcFull; |
| 316 srcFull.setConfig(SkBitmap::kARGB_8888_Config, imageRect.width(), imageR ect.height()); | 321 srcFull.setConfig(SkBitmap::kARGB_8888_Config, imageRect.width(), imageR ect.height()); |
| 317 srcFull.setPixels(const_cast<uint8_t*>(image)); | 322 srcFull.setPixels(const_cast<uint8_t*>(image)); |
| 318 SkBitmap srcSubset; | 323 SkBitmap srcSubset; |
| 319 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(), sourceRect.width(), sourceRect.height()); | 324 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(), sourceRect.width(), sourceRect.height()); |
| 320 skSourceRect.offset(-imageRect.x(), -imageRect.y()); | 325 skSourceRect.offset(-imageRect.x(), -imageRect.y()); |
| 321 srcFull.extractSubset(&srcSubset, skSourceRect); | 326 srcFull.extractSubset(&srcSubset, skSourceRect); |
| 322 | 327 |
| 323 ScopedWriteLockSoftware lock(this, id); | 328 ScopedWriteLockSoftware lock(this, id); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 } | 383 } |
| 379 | 384 |
| 380 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) | 385 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) |
| 381 { | 386 { |
| 382 DCHECK(m_threadChecker.CalledOnValidThread()); | 387 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 383 ResourceMap::iterator it = m_resources.find(id); | 388 ResourceMap::iterator it = m_resources.find(id); |
| 384 CHECK(it != m_resources.end()); | 389 CHECK(it != m_resources.end()); |
| 385 Resource* resource = &it->second; | 390 Resource* resource = &it->second; |
| 386 DCHECK(!resource->lockedForWrite); | 391 DCHECK(!resource->lockedForWrite); |
| 387 DCHECK(!resource->exported); | 392 DCHECK(!resource->exported); |
| 393 DCHECK(resource->allocated); | |
| 388 resource->lockForReadCount++; | 394 resource->lockForReadCount++; |
| 389 return resource; | 395 return resource; |
| 390 } | 396 } |
| 391 | 397 |
| 392 void ResourceProvider::unlockForRead(ResourceId id) | 398 void ResourceProvider::unlockForRead(ResourceId id) |
| 393 { | 399 { |
| 394 DCHECK(m_threadChecker.CalledOnValidThread()); | 400 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 395 ResourceMap::iterator it = m_resources.find(id); | 401 ResourceMap::iterator it = m_resources.find(id); |
| 396 CHECK(it != m_resources.end()); | 402 CHECK(it != m_resources.end()); |
| 397 Resource* resource = &it->second; | 403 Resource* resource = &it->second; |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 639 } | 645 } |
| 640 Child& childInfo = m_children.find(child)->second; | 646 Child& childInfo = m_children.find(child)->second; |
| 641 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) { | 647 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) { |
| 642 unsigned textureId; | 648 unsigned textureId; |
| 643 GLC(context3d, textureId = context3d->createTexture()); | 649 GLC(context3d, textureId = context3d->createTexture()); |
| 644 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | 650 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); |
| 645 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name)); | 651 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name)); |
| 646 ResourceId id = m_nextId++; | 652 ResourceId id = m_nextId++; |
| 647 Resource resource(textureId, it->size, it->format, it->filter); | 653 Resource resource(textureId, it->size, it->format, it->filter); |
| 648 resource.mailbox.setName(it->mailbox.name); | 654 resource.mailbox.setName(it->mailbox.name); |
| 655 // Don't allocate a texture for a child. | |
| 656 resource.allocated = true; | |
| 649 m_resources[id] = resource; | 657 m_resources[id] = resource; |
| 650 childInfo.parentToChildMap[id] = it->id; | 658 childInfo.parentToChildMap[id] = it->id; |
| 651 childInfo.childToParentMap[it->id] = id; | 659 childInfo.childToParentMap[it->id] = id; |
| 652 } | 660 } |
| 653 } | 661 } |
| 654 | 662 |
| 655 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es) | 663 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es) |
| 656 { | 664 { |
| 657 DCHECK(m_threadChecker.CalledOnValidThread()); | 665 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 658 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 666 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 679 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource) | 687 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource) |
| 680 { | 688 { |
| 681 DCHECK(m_threadChecker.CalledOnValidThread()); | 689 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 682 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 690 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
| 683 ResourceMap::iterator it = m_resources.find(id); | 691 ResourceMap::iterator it = m_resources.find(id); |
| 684 CHECK(it != m_resources.end()); | 692 CHECK(it != m_resources.end()); |
| 685 Resource* source = &it->second; | 693 Resource* source = &it->second; |
| 686 DCHECK(!source->lockedForWrite); | 694 DCHECK(!source->lockedForWrite); |
| 687 DCHECK(!source->lockForReadCount); | 695 DCHECK(!source->lockForReadCount); |
| 688 DCHECK(!source->external); | 696 DCHECK(!source->external); |
| 697 DCHECK(source->allocated); | |
| 689 if (source->exported) | 698 if (source->exported) |
| 690 return false; | 699 return false; |
| 691 resource->id = id; | 700 resource->id = id; |
| 692 resource->format = source->format; | 701 resource->format = source->format; |
| 693 resource->filter = source->filter; | 702 resource->filter = source->filter; |
| 694 resource->size = source->size; | 703 resource->size = source->size; |
| 695 | 704 |
| 696 if (source->mailbox.isZero()) { | 705 if (source->mailbox.isZero()) { |
| 697 GLbyte name[GL_MAILBOX_SIZE_CHROMIUM]; | 706 GLbyte name[GL_MAILBOX_SIZE_CHROMIUM]; |
| 698 GLC(context3d, context3d->genMailboxCHROMIUM(name)); | 707 GLC(context3d, context3d->genMailboxCHROMIUM(name)); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 832 DCHECK(!resource->lockedForWrite); | 841 DCHECK(!resource->lockedForWrite); |
| 833 DCHECK(!resource->lockForReadCount); | 842 DCHECK(!resource->lockForReadCount); |
| 834 DCHECK(!resource->external); | 843 DCHECK(!resource->external); |
| 835 DCHECK(!resource->exported); | 844 DCHECK(!resource->exported); |
| 836 | 845 |
| 837 if (resource->glId) { | 846 if (resource->glId) { |
| 838 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 847 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
| 839 DCHECK(context3d); | 848 DCHECK(context3d); |
| 840 DCHECK(resource->glPixelBufferId); | 849 DCHECK(resource->glPixelBufferId); |
| 841 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); | 850 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); |
| 851 lazyAllocateTexture(context3d, resource); | |
| 852 | |
| 842 context3d->bindBuffer( | 853 context3d->bindBuffer( |
| 843 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 854 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 844 resource->glPixelBufferId); | 855 resource->glPixelBufferId); |
| 845 context3d->texSubImage2D(GL_TEXTURE_2D, | 856 context3d->texSubImage2D(GL_TEXTURE_2D, |
| 846 0, /* level */ | 857 0, /* level */ |
| 847 0, /* x */ | 858 0, /* x */ |
| 848 0, /* y */ | 859 0, /* y */ |
| 849 resource->size.width(), | 860 resource->size.width(), |
| 850 resource->size.height(), | 861 resource->size.height(), |
| 851 resource->format, | 862 resource->format, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 903 DCHECK(resource->glPixelBufferId); | 914 DCHECK(resource->glPixelBufferId); |
| 904 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); | 915 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); |
| 905 context3d->bindBuffer( | 916 context3d->bindBuffer( |
| 906 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 917 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 907 resource->glPixelBufferId); | 918 resource->glPixelBufferId); |
| 908 if (!resource->glUploadQueryId) | 919 if (!resource->glUploadQueryId) |
| 909 resource->glUploadQueryId = context3d->createQueryEXT(); | 920 resource->glUploadQueryId = context3d->createQueryEXT(); |
| 910 context3d->beginQueryEXT( | 921 context3d->beginQueryEXT( |
| 911 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM, | 922 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM, |
| 912 resource->glUploadQueryId); | 923 resource->glUploadQueryId); |
| 913 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | 924 if (!resource->allocated) { |
| 914 0, /* level */ | 925 resource->allocated = true; |
| 915 0, /* x */ | 926 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, |
| 916 0, /* y */ | 927 0, /* level */ |
| 917 resource->size.width(), | 928 resource->format, |
| 918 resource->size.height(), | 929 resource->size.width(), |
| 919 resource->format, | 930 resource->size.height(), |
| 920 GL_UNSIGNED_BYTE, | 931 0, /* border */ |
| 921 NULL); | 932 resource->format, |
| 933 GL_UNSIGNED_BYTE, | |
| 934 NULL); | |
| 935 } else { | |
| 936 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | |
| 937 0, /* level */ | |
| 938 0, /* x */ | |
| 939 0, /* y */ | |
| 940 resource->size.width(), | |
| 941 resource->size.height(), | |
| 942 resource->format, | |
| 943 GL_UNSIGNED_BYTE, | |
| 944 NULL); | |
| 945 } | |
| 922 context3d->endQueryEXT(GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM); | 946 context3d->endQueryEXT(GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM); |
| 923 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 947 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 924 } | 948 } |
| 925 | 949 |
| 926 if (resource->pixels) | 950 if (resource->pixels) |
| 927 setPixelsFromBuffer(id); | 951 setPixelsFromBuffer(id); |
| 928 | 952 |
| 929 resource->pendingSetPixels = true; | 953 resource->pendingSetPixels = true; |
| 930 } | 954 } |
| 931 | 955 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 949 if (!complete) | 973 if (!complete) |
| 950 return false; | 974 return false; |
| 951 } | 975 } |
| 952 | 976 |
| 953 resource->pendingSetPixels = false; | 977 resource->pendingSetPixels = false; |
| 954 unlockForWrite(id); | 978 unlockForWrite(id); |
| 955 | 979 |
| 956 return true; | 980 return true; |
| 957 } | 981 } |
| 958 | 982 |
| 983 void ResourceProvider::lazyAllocateTexture(WebGraphicsContext3D* context3d, Reso urce* resource) { | |
| 984 DCHECK(context3d); | |
| 985 DCHECK(resource); | |
| 986 DCHECK(resource->glId); | |
| 987 if (!resource->allocated) { | |
|
piman
2012/12/18 04:12:34
nit:
if (resource->allocated)
return;
saves i
epenner
2012/12/18 04:23:52
Good point. Didn't double-check my cut/paste.
Don
| |
| 988 resource->allocated = true; | |
| 989 gfx::Size& size = resource->size; | |
| 990 GLenum format = resource->format; | |
| 991 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format) ) { | |
| 992 GLenum storageFormat = textureToStorageFormat(format); | |
| 993 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageF ormat, size.width(), size.height())); | |
| 994 } else | |
| 995 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size. width(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); | |
| 996 } | |
| 997 } | |
| 998 | |
| 999 | |
| 959 } // namespace cc | 1000 } // namespace cc |
| OLD | NEW |