Bug 604101 - Part 3 - Use UploadSurfaceToTexture in CanvasLayerOGL. r=joe a=blocking2.0

This commit is contained in:
Matt Woodrow 2010-12-16 23:28:30 -08:00
Родитель f60965ddb0
Коммит 95faf2267a
2 изменённых файлов: 23 добавлений и 88 удалений

Просмотреть файл

@ -157,84 +157,30 @@ CanvasLayerOGL::Updated(const nsIntRect& aRect)
MakeTexture(); MakeTexture();
} }
} else { } else {
PRBool newTexture = mTexture == 0; if (!mTexture) {
if (newTexture) {
MakeTexture();
mUpdatedRect = mBounds; mUpdatedRect = mBounds;
} else {
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
} }
nsRefPtr<gfxImageSurface> updatedAreaImageSurface; nsRefPtr<gfxASurface> updatedAreaSurface;
if (mCanvasSurface) { if (mCanvasSurface) {
nsRefPtr<gfxASurface> sourceSurface = mCanvasSurface; updatedAreaSurface = mCanvasSurface;
#ifdef XP_WIN
if (sourceSurface->GetType() == gfxASurface::SurfaceTypeWin32) {
sourceSurface = sourceSurface->GetAsImageSurface();
if (!sourceSurface)
sourceSurface = mCanvasSurface;
}
#endif
#if 0
// XXX don't copy, blah.
// but need to deal with stride on the gl side; do this later.
if (mCanvasSurface->GetType() == gfxASurface::SurfaceTypeImage) {
gfxImageSurface *s = static_cast<gfxImageSurface*>(mCanvasSurface.get());
if (s->Format() == gfxASurface::ImageFormatARGB32 ||
s->Format() == gfxASurface::ImageFormatRGB24)
{
updatedAreaImageSurface = ...;
} else {
NS_WARNING("surface with format that we can't handle");
return;
}
} else
#endif
{
updatedAreaImageSurface =
new gfxImageSurface(gfxIntSize(mUpdatedRect.width, mUpdatedRect.height),
gfxASurface::ImageFormatARGB32);
nsRefPtr<gfxContext> ctx = new gfxContext(updatedAreaImageSurface);
ctx->Translate(gfxPoint(-mUpdatedRect.x, -mUpdatedRect.y));
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
ctx->SetSource(sourceSurface);
ctx->Paint();
}
} else if (mCanvasGLContext) { } else if (mCanvasGLContext) {
updatedAreaImageSurface = nsRefPtr<gfxImageSurface> updatedAreaImageSurface =
new gfxImageSurface(gfxIntSize(mUpdatedRect.width, mUpdatedRect.height), new gfxImageSurface(gfxIntSize(mUpdatedRect.width, mUpdatedRect.height),
gfxASurface::ImageFormatARGB32); gfxASurface::ImageFormatARGB32);
mCanvasGLContext->ReadPixelsIntoImageSurface(mUpdatedRect.x, mUpdatedRect.y, mCanvasGLContext->ReadPixelsIntoImageSurface(mUpdatedRect.x, mUpdatedRect.y,
mUpdatedRect.width, mUpdatedRect.width,
mUpdatedRect.height, mUpdatedRect.height,
updatedAreaImageSurface); updatedAreaImageSurface);
updatedAreaSurface = updatedAreaImageSurface;
} }
if (newTexture) { mLayerProgram =
gl()->UploadSurfaceToTexture(updatedAreaSurface,
gl()->fTexImage2D(LOCAL_GL_TEXTURE_2D, mUpdatedRect,
0, mTexture,
LOCAL_GL_RGBA, false,
mUpdatedRect.width, mUpdatedRect.TopLeft());
mUpdatedRect.height,
0,
LOCAL_GL_RGBA,
LOCAL_GL_UNSIGNED_BYTE,
updatedAreaImageSurface->Data());
} else {
gl()->fTexSubImage2D(LOCAL_GL_TEXTURE_2D,
0,
mUpdatedRect.x,
mUpdatedRect.y,
mUpdatedRect.width,
mUpdatedRect.height,
LOCAL_GL_RGBA,
LOCAL_GL_UNSIGNED_BYTE,
updatedAreaImageSurface->Data());
}
} }
// sanity // sanity
@ -252,14 +198,14 @@ CanvasLayerOGL::RenderLayer(int aPreviousDestination,
// mGLBufferIsPremultiplied is TRUE or not. The RGBLayerProgram // mGLBufferIsPremultiplied is TRUE or not. The RGBLayerProgram
// assumes that it's true. // assumes that it's true.
ColorTextureLayerProgram *program = nsnull;
gl()->fActiveTexture(LOCAL_GL_TEXTURE0); gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
if (mTexture) { if (mTexture) {
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture); gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
} }
ColorTextureLayerProgram *program = nsnull;
bool useGLContext = mCanvasGLContext && bool useGLContext = mCanvasGLContext &&
mCanvasGLContext->GetContextType() == gl()->GetContextType(); mCanvasGLContext->GetContextType() == gl()->GetContextType();
@ -272,33 +218,21 @@ CanvasLayerOGL::RenderLayer(int aPreviousDestination,
gl()->MakeCurrent(); gl()->MakeCurrent();
gl()->BindTex2DOffscreen(mCanvasGLContext); gl()->BindTex2DOffscreen(mCanvasGLContext);
DEBUG_GL_ERROR_CHECK(gl()); DEBUG_GL_ERROR_CHECK(gl());
program = mOGLManager->GetBasicLayerProgram(CanUseOpaqueSurface(), PR_TRUE);
} else if (mDelayedUpdates) { } else if (mDelayedUpdates) {
NS_ABORT_IF_FALSE(mCanvasSurface, "WebGL canvases should always be using full texture upload"); NS_ABORT_IF_FALSE(mCanvasSurface, "WebGL canvases should always be using full texture upload");
drawRect.IntersectRect(drawRect, GetEffectiveVisibleRegion().GetBounds()); drawRect.IntersectRect(drawRect, GetEffectiveVisibleRegion().GetBounds());
nsRefPtr<gfxImageSurface> imageSurface = mLayerProgram =
new gfxImageSurface(gfxIntSize(drawRect.width, drawRect.height), gl()->UploadSurfaceToTexture(mCanvasSurface,
gfxASurface::ImageFormatARGB32); drawRect,
nsRefPtr<gfxContext> ctx = new gfxContext(imageSurface); mTexture,
ctx->Translate(gfxPoint(-drawRect.x, -drawRect.y)); true);
ctx->SetOperator(gfxContext::OPERATOR_SOURCE); }
ctx->SetSource(mCanvasSurface); if (!program) {
ctx->Paint(); program = mOGLManager->GetColorTextureLayerProgram(mLayerProgram);
gl()->fTexImage2D(LOCAL_GL_TEXTURE_2D,
0,
LOCAL_GL_RGBA,
drawRect.width,
drawRect.height,
0,
LOCAL_GL_RGBA,
LOCAL_GL_UNSIGNED_BYTE,
imageSurface->Data());
} }
program =
mOGLManager->GetBasicLayerProgram(CanUseOpaqueSurface(),
useGLContext != 0);
ApplyFilter(mFilter); ApplyFilter(mFilter);

Просмотреть файл

@ -77,6 +77,7 @@ public:
protected: protected:
nsRefPtr<gfxASurface> mCanvasSurface; nsRefPtr<gfxASurface> mCanvasSurface;
nsRefPtr<GLContext> mCanvasGLContext; nsRefPtr<GLContext> mCanvasGLContext;
gl::ShaderProgramType mLayerProgram;
void MakeTexture(); void MakeTexture();
GLuint mTexture; GLuint mTexture;