From 51835ef8a62bef94b87ce1b41606d3d197f7f9ec Mon Sep 17 00:00:00 2001 From: Vladimir Vukicevic Date: Fri, 6 Aug 2010 22:09:18 -0700 Subject: [PATCH] b=583838; add ANGLE/D3D WebGL support - part 4 - allow CanvasLayerOGL to work with different-type GL contexts; r=bas --- gfx/layers/opengl/CanvasLayerOGL.cpp | 76 ++++++++++++++++------------ 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/gfx/layers/opengl/CanvasLayerOGL.cpp b/gfx/layers/opengl/CanvasLayerOGL.cpp index 8c3c8c1f127..476605cb171 100644 --- a/gfx/layers/opengl/CanvasLayerOGL.cpp +++ b/gfx/layers/opengl/CanvasLayerOGL.cpp @@ -132,13 +132,15 @@ CanvasLayerOGL::Updated(const nsIntRect& aRect) mUpdatedRect.UnionRect(mUpdatedRect, aRect); - if (mCanvasGLContext) { + if (mCanvasGLContext && + mCanvasGLContext->GetContextType() == gl()->GetContextType()) + { if (gl()->BindOffscreenNeedsTexture(mCanvasGLContext) && mTexture == 0) { MakeTexture(); } - } else if (mCanvasSurface) { + } else { PRBool newTexture = mTexture == 0; if (newTexture) { MakeTexture(); @@ -149,40 +151,50 @@ CanvasLayerOGL::Updated(const nsIntRect& aRect) } nsRefPtr updatedAreaImageSurface; - nsRefPtr sourceSurface = mCanvasSurface; + if (mCanvasSurface) { + nsRefPtr sourceSurface = mCanvasSurface; #ifdef XP_WIN - if (sourceSurface->GetType() == gfxASurface::SurfaceTypeWin32) { - sourceSurface = static_cast(sourceSurface.get())->GetImageSurface(); - if (!sourceSurface) - sourceSurface = mCanvasSurface; - } + if (sourceSurface->GetType() == gfxASurface::SurfaceTypeWin32) { + sourceSurface = static_cast(sourceSurface.get())->GetImageSurface(); + 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(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 + // 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(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 ctx = new gfxContext(updatedAreaImageSurface); + ctx->Translate(gfxPoint(-mUpdatedRect.x, -mUpdatedRect.y)); + ctx->SetOperator(gfxContext::OPERATOR_SOURCE); + ctx->SetSource(sourceSurface); + ctx->Paint(); + } + } else if (mCanvasGLContext) { updatedAreaImageSurface = new gfxImageSurface(gfxIntSize(mUpdatedRect.width, mUpdatedRect.height), gfxASurface::ImageFormatARGB32); - nsRefPtr ctx = new gfxContext(updatedAreaImageSurface); - ctx->Translate(gfxPoint(-mUpdatedRect.x, -mUpdatedRect.y)); - ctx->SetOperator(gfxContext::OPERATOR_SOURCE); - ctx->SetSource(sourceSurface); - ctx->Paint(); + mCanvasGLContext->ReadPixelsIntoImageSurface(mUpdatedRect.x, mUpdatedRect.y, + mUpdatedRect.width, + mUpdatedRect.height, + updatedAreaImageSurface); } if (newTexture) { @@ -231,12 +243,12 @@ CanvasLayerOGL::RenderLayer(int aPreviousDestination, gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture); } - if (mCanvasGLContext) { + bool useGLContext = mCanvasGLContext && + mCanvasGLContext->GetContextType() == gl()->GetContextType(); + + if (useGLContext) { gl()->BindTex2DOffscreen(mCanvasGLContext); DEBUG_GL_ERROR_CHECK(gl()); - } - - if (mCanvasGLContext) { program = mOGLManager->GetRGBALayerProgram(); } else { program = mOGLManager->GetBGRALayerProgram(); @@ -253,7 +265,7 @@ CanvasLayerOGL::RenderLayer(int aPreviousDestination, DEBUG_GL_ERROR_CHECK(gl()); - if (mCanvasGLContext) { + if (useGLContext) { gl()->UnbindTex2DOffscreen(mCanvasGLContext); }