From 4fa51050ec5c7bd3c1e1123a089acd5742a24044 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Mon, 14 Jun 2010 14:44:12 -0400 Subject: [PATCH] b=569236; better WebGL messages; r=vladimir --- content/canvas/src/WebGLContext.cpp | 50 +++------------------ content/canvas/src/WebGLContext.h | 2 +- content/canvas/src/WebGLContextValidate.cpp | 31 ++++++++++++- gfx/thebes/src/GLContextProviderOSMesa.cpp | 14 +++++- 4 files changed, 49 insertions(+), 48 deletions(-) diff --git a/content/canvas/src/WebGLContext.cpp b/content/canvas/src/WebGLContext.cpp index 663380f21a9..3ac451e67c6 100644 --- a/content/canvas/src/WebGLContext.cpp +++ b/content/canvas/src/WebGLContext.cpp @@ -168,61 +168,23 @@ WebGLContext::SetDimensions(PRInt32 width, PRInt32 height) } } - LogMessage("Canvas 3D: creating PBuffer..."); - GLContextProvider::ContextFormat format(GLContextProvider::ContextFormat::BasicRGBA32); format.depth = 16; format.minDepth = 1; gl = gl::sGLContextProvider.CreatePBuffer(gfxIntSize(width, height), format); - if (!gl) { - LogMessage("Canvas 3D: can't get a native PBuffer, trying OSMesa..."); + if (!InitAndValidateGL()) { gl = gl::GLContextProviderOSMesa::CreatePBuffer(gfxIntSize(width, height), format); - if (!gl) { - LogMessage("Canvas 3D: can't create a OSMesa pseudo-PBuffer."); + if (!InitAndValidateGL()) { + LogMessage("WebGL: Can't get a usable OpenGL context."); return NS_ERROR_FAILURE; } + else { + LogMessage("WebGL: Using software rendering via OSMesa"); + } } - // We just blew away all the resources by creating a new context; reset everything, - // and let ValidateGL set up the correct dimensions again. - - mActiveTexture = 0; - mSynthesizedGLError = LOCAL_GL_NO_ERROR; - - mAttribBuffers.Clear(); - - mUniformTextures.Clear(); - mBound2DTextures.Clear(); - mBoundCubeMapTextures.Clear(); - - mBoundArrayBuffer = nsnull; - mBoundElementArrayBuffer = nsnull; - mCurrentProgram = nsnull; - - mFramebufferColorAttachments.Clear(); - mFramebufferDepthAttachment = nsnull; - mFramebufferStencilAttachment = nsnull; - - mBoundFramebuffer = nsnull; - mBoundRenderbuffer = nsnull; - - mMapTextures.Clear(); - mMapBuffers.Clear(); - mMapPrograms.Clear(); - mMapShaders.Clear(); - mMapFramebuffers.Clear(); - mMapRenderbuffers.Clear(); - - // Now check the GL implementation, checking limits along the way - if (!ValidateGL()) { - LogMessage("Canvas 3D: Couldn't validate OpenGL implementation; is everything needed present?"); - return NS_ERROR_FAILURE; - } - - LogMessage("Canvas 3D: ready"); - mWidth = width; mHeight = height; diff --git a/content/canvas/src/WebGLContext.h b/content/canvas/src/WebGLContext.h index 8c13cbfb0b4..b4506eadcab 100644 --- a/content/canvas/src/WebGLContext.h +++ b/content/canvas/src/WebGLContext.h @@ -304,7 +304,7 @@ protected: WebGLenum mSynthesizedGLError; PRBool SafeToCreateCanvas3DContext(nsHTMLCanvasElement *canvasElement); - PRBool ValidateGL(); + PRBool InitAndValidateGL(); PRBool ValidateBuffers(PRUint32 count); static PRBool ValidateCapabilityEnum(WebGLenum cap); diff --git a/content/canvas/src/WebGLContextValidate.cpp b/content/canvas/src/WebGLContextValidate.cpp index d7156b3f6bc..6c8e4a3ca8c 100644 --- a/content/canvas/src/WebGLContextValidate.cpp +++ b/content/canvas/src/WebGLContextValidate.cpp @@ -144,8 +144,37 @@ PRBool WebGLContext::ValidateCapabilityEnum(WebGLenum cap) } PRBool -WebGLContext::ValidateGL() +WebGLContext::InitAndValidateGL() { + if (!gl) return PR_FALSE; + + mActiveTexture = 0; + mSynthesizedGLError = LOCAL_GL_NO_ERROR; + + mAttribBuffers.Clear(); + + mUniformTextures.Clear(); + mBound2DTextures.Clear(); + mBoundCubeMapTextures.Clear(); + + mBoundArrayBuffer = nsnull; + mBoundElementArrayBuffer = nsnull; + mCurrentProgram = nsnull; + + mFramebufferColorAttachments.Clear(); + mFramebufferDepthAttachment = nsnull; + mFramebufferStencilAttachment = nsnull; + + mBoundFramebuffer = nsnull; + mBoundRenderbuffer = nsnull; + + mMapTextures.Clear(); + mMapBuffers.Clear(); + mMapPrograms.Clear(); + mMapShaders.Clear(); + mMapFramebuffers.Clear(); + mMapRenderbuffers.Clear(); + // make sure that the opengl stuff that we need is supported GLint val = 0; diff --git a/gfx/thebes/src/GLContextProviderOSMesa.cpp b/gfx/thebes/src/GLContextProviderOSMesa.cpp index 69209a0bb0b..30a28e4b5f3 100644 --- a/gfx/thebes/src/GLContextProviderOSMesa.cpp +++ b/gfx/thebes/src/GLContextProviderOSMesa.cpp @@ -42,6 +42,7 @@ #include "nsIWidget.h" #include "nsDirectoryServiceUtils.h" #include "nsAppDirectoryServiceDefs.h" +#include "nsIConsoleService.h" #include "nsIPrefService.h" #include "gfxASurface.h" #include "gfxImageSurface.h" @@ -58,6 +59,15 @@ namespace mozilla { namespace gl { +static void LogMessage(const char *msg) +{ + nsCOMPtr console(do_GetService(NS_CONSOLESERVICE_CONTRACTID)); + if (console) { + console->LogStringMessage(NS_ConvertUTF8toUTF16(nsDependentCString(msg)).get()); + fprintf(stderr, "%s\n", msg); + } +} + typedef void* PrivateOSMesaContext; class OSMesaLibrary @@ -116,7 +126,7 @@ OSMesaLibrary::EnsureInitialized() mOSMesaLibrary = PR_LoadLibrary(osmesalib.get()); if (!mOSMesaLibrary) { - NS_WARNING("Canvas 3D: Couldn't open OSMesa lib -- webgl.osmesalib path is incorrect, or not a valid shared library"); + LogMessage("Couldn't open OSMesa lib for software rendering -- webgl.osmesalib path is incorrect, or not a valid shared library"); return PR_FALSE; } @@ -132,7 +142,7 @@ OSMesaLibrary::EnsureInitialized() }; if (!LibrarySymbolLoader::LoadSymbols(mOSMesaLibrary, &symbols[0])) { - NS_WARNING("Couldn't find required entry points in OSMesa libary"); + LogMessage("Couldn't find required entry points in OSMesa libary"); return PR_FALSE; }