Bug 575521 - Use gfxASurface::GetAsImageSurface in TextureImageCGL to make it faster. r=jrmuizel

This commit is contained in:
Joe Drew 2010-11-11 15:31:23 -05:00
parent c001466571
commit 95cd602adf
2 changed files with 29 additions and 9 deletions

View File

@ -564,6 +564,13 @@ BasicTextureImage::EndUpdate()
return PR_FALSE; return PR_FALSE;
mGLContext->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture); mGLContext->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
// The images that come out of the cairo quartz surface are 16-byte aligned
// for performance. We know this is an RGBA surface, so we divide the
// stride by 4 to represent the number of elements long the row is.
mGLContext->fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH,
uploadImage->Stride() / 4);
if (!mTextureInited) if (!mTextureInited)
{ {
mGLContext->fTexImage2D(LOCAL_GL_TEXTURE_2D, mGLContext->fTexImage2D(LOCAL_GL_TEXTURE_2D,
@ -588,6 +595,10 @@ BasicTextureImage::EndUpdate()
uploadImage->Data()); uploadImage->Data());
} }
mUpdateContext = NULL; mUpdateContext = NULL;
// Reset row length to use the default.
mGLContext->fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH, 0);
return PR_TRUE; // mTexture is bound return PR_TRUE; // mTexture is bound
} }

View File

@ -42,6 +42,7 @@
#include <AppKit/NSOpenGL.h> #include <AppKit/NSOpenGL.h>
#include "gfxASurface.h" #include "gfxASurface.h"
#include "gfxImageSurface.h" #include "gfxImageSurface.h"
#include "gfxQuartzSurface.h"
#include "gfxPlatform.h" #include "gfxPlatform.h"
namespace mozilla { namespace mozilla {
@ -281,16 +282,24 @@ protected:
virtual already_AddRefed<gfxImageSurface> virtual already_AddRefed<gfxImageSurface>
GetImageForUpload(gfxASurface* aUpdateSurface) GetImageForUpload(gfxASurface* aUpdateSurface)
{ {
// FIXME/bug 575521: make me fast! nsRefPtr<gfxImageSurface> image = aUpdateSurface->GetAsImageSurface();
nsRefPtr<gfxImageSurface> image =
new gfxImageSurface(gfxIntSize(mUpdateRect.width,
mUpdateRect.height),
mUpdateFormat);
nsRefPtr<gfxContext> tmpContext = new gfxContext(image);
tmpContext->SetSource(aUpdateSurface); if (image && image->Format() != mUpdateFormat) {
tmpContext->SetOperator(gfxContext::OPERATOR_SOURCE); image = nsnull;
tmpContext->Paint(); }
// If we don't get an image directly from the quartz surface, we have
// to take the slow boat.
if (!image) {
image = new gfxImageSurface(gfxIntSize(mUpdateRect.width,
mUpdateRect.height),
mUpdateFormat);
nsRefPtr<gfxContext> tmpContext = new gfxContext(image);
tmpContext->SetSource(aUpdateSurface);
tmpContext->SetOperator(gfxContext::OPERATOR_SOURCE);
tmpContext->Paint();
}
return image.forget(); return image.forget();
} }