Bug 604101 - Part 6 - Add TextureImage::DirectUpload for faster texture uploads. r=jrmuizel a=blocking2.0

This commit is contained in:
Matt Woodrow 2010-12-16 23:50:26 -08:00
parent 47294e7de3
commit a2e7cac831
6 changed files with 49 additions and 20 deletions

View File

@ -285,13 +285,7 @@ ShadowCanvasLayerOGL::Swap(gfxSharedImageSurface* aNewFront)
gfxSize sz = aNewFront->GetSize();
nsIntRegion updateRegion(nsIntRect(0, 0, sz.width, sz.height));
// NB: this gfxContext must not escape EndUpdate() below
nsRefPtr<gfxContext> dest = mTexImage->BeginUpdate(updateRegion);
dest->SetOperator(gfxContext::OPERATOR_SOURCE);
dest->DrawSurface(aNewFront, aNewFront->GetSize());
mTexImage->EndUpdate();
mTexImage->DirectUpdate(aNewFront, updateRegion);
}
return aNewFront;

View File

@ -735,13 +735,7 @@ ShadowImageLayerOGL::Swap(gfxSharedImageSurface* aNewFront)
gfxSize sz = aNewFront->GetSize();
nsIntRegion updateRegion(nsIntRect(0, 0, sz.width, sz.height));
// NB: this gfxContext must not escape EndUpdate() below
nsRefPtr<gfxContext> dest = mTexImage->BeginUpdate(updateRegion);
dest->SetOperator(gfxContext::OPERATOR_SOURCE);
dest->DrawSurface(aNewFront, aNewFront->GetSize());
mTexImage->EndUpdate();
mTexImage->DirectUpdate(aNewFront, updateRegion);
}
return aNewFront;

View File

@ -641,12 +641,7 @@ ShadowBufferOGL::Upload(gfxASurface* aUpdate, const nsIntRegion& aUpdated,
// NB: this gfxContext must not escape EndUpdate() below
nsIntRegion scaledDestRegion(nsIntRect(destRect.pos.x, destRect.pos.y,
destRect.size.width, destRect.size.height));
nsRefPtr<gfxContext> dest = mTexImage->BeginUpdate(scaledDestRegion);
dest->SetOperator(gfxContext::OPERATOR_SOURCE);
dest->DrawSurface(aUpdate, aUpdate->GetSize());
mTexImage->EndUpdate();
mTexImage->DirectUpdate(aUpdate, scaledDestRegion);
mBufferRect = aRect;
mBufferRotation = aRotation;

View File

@ -645,6 +645,25 @@ BasicTextureImage::FinishedSurfaceUpload()
{
}
bool
BasicTextureImage::DirectUpdate(gfxASurface *aSurf, const nsIntRegion& aRegion)
{
nsIntRect bounds = aRegion.GetBounds();
if (!mTextureInited) {
bounds = nsIntRect(0, 0, mSize.width, mSize.height);
}
mShaderType =
mGLContext->UploadSurfaceToTexture(aSurf,
bounds,
mTexture,
!mTextureInited,
bounds.TopLeft(),
PR_FALSE);
mTextureInited = PR_TRUE;
return true;
}
void
BasicTextureImage::Resize(const nsIntSize& aSize)
{

View File

@ -202,6 +202,8 @@ public:
EndUpdate();
}
virtual bool DirectUpdate(gfxASurface *aSurf, const nsIntRegion& aRegion) =0;
/**
* Return this TextureImage's texture ID for use with GL APIs.
* Callers are responsible for properly binding the texture etc.
@ -295,6 +297,7 @@ public:
virtual gfxContext* BeginUpdate(nsIntRegion& aRegion);
virtual PRBool EndUpdate();
virtual bool DirectUpdate(gfxASurface *aSurf, const nsIntRegion& aRegion);
// Returns a surface to draw into
virtual already_AddRefed<gfxASurface>

View File

@ -1132,6 +1132,30 @@ public:
return PR_TRUE; // mTexture is bound
}
virtual bool DirectUpdate(gfxASurface *aSurf, const nsIntRegion& aRegion)
{
nsIntRect bounds = aRegion.GetBounds();
nsIntPoint dest = bounds.TopLeft();
// Bounds is the destination rect, it will be at 0,0 on the source
bounds.x = 0;
bounds.y = 0;
if (!mCreated) {
bounds = nsIntRect(0, 0, mSize.width, mSize.height);
}
mShaderType =
mGLContext->UploadSurfaceToTexture(aSurf,
bounds,
mTexture,
!mCreated,
dest,
PR_FALSE);
mCreated = PR_TRUE;
return true;
}
virtual PRBool InUpdate() const { return !!mUpdateContext; }
virtual void Resize(const nsIntSize& aSize)