Index: cc/resource_provider.cc |
diff --git a/cc/resource_provider.cc b/cc/resource_provider.cc |
index 2759d1aae6ccc35f1d86a820bf440b7477d9ccd8..49c8d1b214bd0e084a308a1b23deacfeb012a20f 100644 |
--- a/cc/resource_provider.cc |
+++ b/cc/resource_provider.cc |
@@ -47,9 +47,32 @@ static bool isTextureFormatSupportedForStorage(GLenum format) |
return (format == GL_RGBA || format == GL_BGRA_EXT); |
} |
+static void texImage2D(WebGraphicsContext3D* context3d, |
+ const gfx::Size& size, |
+ GLenum format, |
+ bool useTextureStorageExt) |
+{ |
+ if (useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { |
+ GLenum storageFormat = textureToStorageFormat(format); |
+ context3d->texStorage2DEXT( |
+ GL_TEXTURE_2D, 1, storageFormat, size.width(), size.height()); |
+ } else { |
+ context3d->texImage2D(GL_TEXTURE_2D, |
+ 0, |
+ format, |
+ size.width(), |
+ size.height(), |
+ 0, |
+ format, |
+ GL_UNSIGNED_BYTE, |
+ 0); |
+ } |
+} |
+ |
ResourceProvider::Resource::Resource() |
: glId(0) |
, glPixelBufferId(0) |
+ , glUploadQueryId(0) |
, pixels(0) |
, pixelBuffer(0) |
, pool(0) |
@@ -67,6 +90,7 @@ ResourceProvider::Resource::Resource() |
ResourceProvider::Resource::Resource(unsigned textureId, int pool, const gfx::Size& size, GLenum format) |
: glId(textureId) |
, glPixelBufferId(0) |
+ , glUploadQueryId(0) |
, pixels(0) |
, pixelBuffer(0) |
, pool(pool) |
@@ -84,6 +108,7 @@ ResourceProvider::Resource::Resource(unsigned textureId, int pool, const gfx::Si |
ResourceProvider::Resource::Resource(uint8_t* pixels, int pool, const gfx::Size& size, GLenum format) |
: glId(0) |
, glPixelBufferId(0) |
+ , glUploadQueryId(0) |
, pixels(pixels) |
, pixelBuffer(0) |
, pool(pool) |
@@ -167,11 +192,8 @@ ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const g |
if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) |
GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); |
- if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { |
- GLenum storageFormat = textureToStorageFormat(format); |
- GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageFormat, size.width(), size.height())); |
- } else |
- GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.width(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); |
+ |
+ texImage2D(context3d, size, format, m_useTextureStorageExt); |
ResourceId id = m_nextId++; |
Resource resource(textureId, pool, size, format); |
@@ -235,6 +257,11 @@ void ResourceProvider::deleteResourceInternal(ResourceMap::iterator it) |
DCHECK(context3d); |
GLC(context3d, context3d->deleteTexture(resource->glId)); |
} |
+ if (resource->glUploadQueryId) { |
+ WebGraphicsContext3D* context3d = m_context->context3D(); |
+ DCHECK(context3d); |
+ GLC(context3d, context3d->deleteQueryEXT(resource->glUploadQueryId)); |
+ } |
if (resource->glPixelBufferId) { |
WebGraphicsContext3D* context3d = m_context->context3D(); |
DCHECK(context3d); |
@@ -832,4 +859,91 @@ void ResourceProvider::setPixelsFromBuffer(ResourceId id) |
} |
} |
+void ResourceProvider::beginSetPixels(ResourceId id) |
+{ |
+ DCHECK(m_threadChecker.CalledOnValidThread()); |
+ ResourceMap::iterator it = m_resources.find(id); |
+ CHECK(it != m_resources.end()); |
+ Resource* resource = &it->second; |
+ DCHECK(!resource->lockedForWrite); |
+ DCHECK(!resource->lockForReadCount); |
+ DCHECK(!resource->external); |
+ DCHECK(!resource->exported); |
+ |
+ if (resource->glId) { |
+ WebGraphicsContext3D* context3d = m_context->context3D(); |
+ DCHECK(context3d); |
+ DCHECK(resource->glPixelBufferId); |
+ lockForWrite(id); |
piman
2012/11/27 00:40:01
We should do this for both software and GL. All it
reveman
2012/11/27 03:22:48
Done.
|
+ context3d->bindTexture(GL_TEXTURE_2D, resource->glId); |
+ context3d->bindBuffer( |
+ GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
+ resource->glPixelBufferId); |
+ if (!resource->glUploadQueryId) |
+ resource->glUploadQueryId = context3d->createQueryEXT(); |
+ context3d->beginQueryEXT( |
+ GL_ASYNC_TEXTURES_UPLOADED_CHROMIUM, resource->glUploadQueryId); |
+ context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, |
+ 0, /* level */ |
+ 0, /* x */ |
+ 0, /* y */ |
+ resource->size.width(), |
+ resource->size.height(), |
+ resource->format, |
+ GL_UNSIGNED_BYTE, |
+ NULL); |
+ context3d->endQueryEXT(GL_ASYNC_TEXTURES_UPLOADED_CHROMIUM); |
+ context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
+ } |
+ |
+ if (resource->pixels) |
+ setPixelsFromBuffer(id); |
+} |
+ |
+bool ResourceProvider::didSetPixelsComplete(ResourceId id) { |
+ DCHECK(m_threadChecker.CalledOnValidThread()); |
+ ResourceMap::iterator it = m_resources.find(id); |
+ CHECK(it != m_resources.end()); |
+ Resource* resource = &it->second; |
+ |
+ if (resource->glId) { |
+ WebGraphicsContext3D* context3d = m_context->context3D(); |
+ DCHECK(context3d); |
+ DCHECK(resource->glUploadQueryId); |
+ DCHECK(resource->lockedForWrite); |
+ unsigned complete = 1; |
+ context3d->getQueryObjectuivEXT( |
+ resource->glUploadQueryId, |
+ GL_QUERY_RESULT_AVAILABLE_EXT, |
+ &complete); |
+ if (!complete) |
+ return false; |
+ |
+ unlockForWrite(id); |
piman
2012/11/27 00:40:01
It would be useful I think to add some state on th
reveman
2012/11/27 03:22:48
Done.
|
+ } |
+ |
+ return true; |
+} |
+ |
+void ResourceProvider::abortSetPixels(ResourceId id) { |
+ DCHECK(m_threadChecker.CalledOnValidThread()); |
+ ResourceMap::iterator it = m_resources.find(id); |
+ CHECK(it != m_resources.end()); |
+ Resource* resource = &it->second; |
+ |
+ if (resource->glId) { |
+ WebGraphicsContext3D* context3d = m_context->context3D(); |
+ DCHECK(context3d); |
+ DCHECK(resource->glUploadQueryId); |
+ DCHECK(resource->lockedForWrite); |
+ context3d->bindTexture(GL_TEXTURE_2D, resource->glId); |
+ texImage2D(context3d, |
+ resource->size, |
+ resource->format, |
+ m_useTextureStorageExt); |
+ |
+ unlockForWrite(id); |
+ } |
+} |
+ |
} // namespace cc |