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

Unified Diff: cc/resource_provider.cc

Issue 11622008: cc: Defer texture allocation (to allow async allocations). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/resource_provider.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resource_provider.cc
diff --git a/cc/resource_provider.cc b/cc/resource_provider.cc
index c2b44d28e8e0885674e6233fe0024ab0227616bd..ea374e72ba39f9b36edff0a75b0893868875d49d 100644
--- a/cc/resource_provider.cc
+++ b/cc/resource_provider.cc
@@ -60,6 +60,7 @@ ResourceProvider::Resource::Resource()
, exported(false)
, markedForDeletion(false)
, pendingSetPixels(false)
+ , allocated(false)
, size()
, format(0)
, filter(0)
@@ -79,6 +80,7 @@ ResourceProvider::Resource::Resource(unsigned textureId, const gfx::Size& size,
, exported(false)
, markedForDeletion(false)
, pendingSetPixels(false)
+ , allocated(false)
, size(size)
, format(format)
, filter(filter)
@@ -98,6 +100,7 @@ ResourceProvider::Resource::Resource(uint8_t* pixels, const gfx::Size& size, GLe
, exported(false)
, markedForDeletion(false)
, pendingSetPixels(false)
+ , allocated(false)
, size(size)
, format(format)
, filter(filter)
@@ -184,22 +187,19 @@ ResourceProvider::ResourceId ResourceProvider::createGLTexture(const gfx::Size&
DCHECK(context3d);
GLC(context3d, textureId = context3d->createTexture());
GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
+
+ // Set texture properties. Allocation is delayed until needed.
GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROMIUM, texturePool));
-
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));
ResourceId id = m_nextId++;
Resource resource(textureId, size, format, GL_LINEAR);
+ resource.allocated = false;
m_resources[id] = resource;
return id;
}
@@ -212,6 +212,7 @@ ResourceProvider::ResourceId ResourceProvider::createBitmap(const gfx::Size& siz
ResourceId id = m_nextId++;
Resource resource(pixels, size, GL_RGBA, GL_LINEAR);
+ resource.allocated = true;
m_resources[id] = resource;
return id;
}
@@ -231,6 +232,7 @@ ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture
ResourceId id = m_nextId++;
Resource resource(textureId, gfx::Size(), 0, GL_LINEAR);
resource.external = true;
+ resource.allocated = true;
m_resources[id] = resource;
return id;
}
@@ -298,10 +300,23 @@ void ResourceProvider::setPixels(ResourceId id, const uint8_t* image, const gfx:
DCHECK(!resource->exported);
if (resource->glId) {
+ DCHECK(!resource->pendingSetPixels);
WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
DCHECK(context3d);
DCHECK(m_textureUploader.get());
context3d->bindTexture(GL_TEXTURE_2D, resource->glId);
+
+ if (!resource->allocated) {
+ resource->allocated = true;
+ gfx::Size& size = resource->size;
+ GLenum format = resource->format;
+ 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));
+ }
+
m_textureUploader->upload(image,
imageRect,
sourceRect,
@@ -311,6 +326,7 @@ void ResourceProvider::setPixels(ResourceId id, const uint8_t* image, const gfx:
}
if (resource->pixels) {
+ DCHECK(resource->allocated);
DCHECK(resource->format == GL_RGBA);
SkBitmap srcFull;
srcFull.setConfig(SkBitmap::kARGB_8888_Config, imageRect.width(), imageRect.height());
@@ -910,15 +926,28 @@ void ResourceProvider::beginSetPixels(ResourceId id)
context3d->beginQueryEXT(
GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_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);
+ if (!resource->allocated) {
+ resource->allocated = true;
+ context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D,
+ 0, /* level */
+ resource->format,
+ resource->size.width(),
+ resource->size.height(),
+ 0, /* border */
+ resource->format,
+ GL_UNSIGNED_BYTE,
+ NULL);
+ } else {
reveman 2012/12/17 23:22:08 how about always using asyncTexImage2DCHROMIUM her
epennerAtGoogle 2012/12/17 23:35:26 Hmm, we could maybe change the internals to make t
+ 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_PIXEL_TRANSFERS_COMPLETED_CHROMIUM);
context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
}
« no previous file with comments | « cc/resource_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698