Bug 758844 - Disable debug output unless MOZ_GL_DEBUG is defined. r=jgilbert
authorJohn Drinkwater <john@nextraweb.com>
Mon, 11 Jun 2012 08:25:06 -0700
changeset 96392 29d9f71b24acc147bd350d2fa6588656d5e0fff2
parent 96391 c21a2f60c06833d3684e138745a8089f94841d52
child 96393 68c6b4ab58212a6d05d7c446212961d559d8e4ca
push id10507
push userjruderman@mozilla.com
push dateMon, 11 Jun 2012 15:25:21 +0000
treeherdermozilla-inbound@29d9f71b24ac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs758844
milestone16.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 758844 - Disable debug output unless MOZ_GL_DEBUG is defined. r=jgilbert
content/canvas/src/WebGLContext.cpp
gfx/gl/GLContext.cpp
gfx/gl/GLContextProviderGLX.cpp
--- a/content/canvas/src/WebGLContext.cpp
+++ b/content/canvas/src/WebGLContext.cpp
@@ -222,17 +222,19 @@ WebGLContext::DestroyResourcesAndContext
 
     if (mFakeVertexAttrib0BufferObject) {
         gl->fDeleteBuffers(1, &mFakeVertexAttrib0BufferObject);
     }
 
     // We just got rid of everything, so the context had better
     // have been going away.
 #ifdef DEBUG
-    printf_stderr("--- WebGL context destroyed: %p\n", gl.get());
+    if (gl->DebugMode()) {
+        printf_stderr("--- WebGL context destroyed: %p\n", gl.get());
+    }
 #endif
 
     gl = nsnull;
 }
 
 void
 WebGLContext::Invalidate()
 {
@@ -514,17 +516,19 @@ WebGLContext::SetDimensions(PRInt32 widt
     }
 
     if (!gl) {
         GenerateWarning("Can't get a usable WebGL context");
         return NS_ERROR_FAILURE;
     }
 
 #ifdef DEBUG
-    printf_stderr ("--- WebGL context created: %p\n", gl.get());
+    if (gl->DebugMode()) {
+        printf_stderr("--- WebGL context created: %p\n", gl.get());
+    }
 #endif
 
     mWidth = width;
     mHeight = height;
     mResetLayer = true;
     mOptionsFrozen = true;
 
     mHasRobustness = gl->HasRobustness();
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -306,20 +306,34 @@ GLContext::InitWithPrefix(const char *pr
         for (int i = 0; i < RendererOther; ++i) {
             if (DoesStringMatch(glRendererString, rendererMatchStrings[i])) {
                 mRenderer = i;
                 break;
             }
         }
     }
 
+#ifdef DEBUG
+    if (PR_GetEnv("MOZ_GL_DEBUG"))
+        sDebugMode |= DebugEnabled;
+
+    // enables extra verbose output, informing of the start and finish of every GL call.
+    // useful e.g. to record information to investigate graphics system crashes/lockups
+    if (PR_GetEnv("MOZ_GL_DEBUG_VERBOSE"))
+        sDebugMode |= DebugTrace;
+
+    // aborts on GL error. Can be useful to debug quicker code that is known not to generate any GL error in principle.
+    if (PR_GetEnv("MOZ_GL_DEBUG_ABORT_ON_ERROR"))
+        sDebugMode |= DebugAbortOnError;
+#endif
+
     if (mInitialized) {
 #ifdef DEBUG
         static bool once = false;
-        if (!once) {
+        if (DebugMode() && !once) {
             const char *vendors[VendorOther] = {
                 "Intel",
                 "NVIDIA",
                 "ATI",
                 "Qualcomm"
             };
 
             once = true;
@@ -481,30 +495,16 @@ GLContext::InitWithPrefix(const char *pr
         }
 #endif
 
         mMaxTextureImageSize = mMaxTextureSize;
 
         UpdateActualFormat();
     }
 
-#ifdef DEBUG
-    if (PR_GetEnv("MOZ_GL_DEBUG"))
-        sDebugMode |= DebugEnabled;
-
-    // enables extra verbose output, informing of the start and finish of every GL call.
-    // useful e.g. to record information to investigate graphics system crashes/lockups
-    if (PR_GetEnv("MOZ_GL_DEBUG_VERBOSE"))
-        sDebugMode |= DebugTrace;
-
-    // aborts on GL error. Can be useful to debug quicker code that is known not to generate any GL error in principle.
-    if (PR_GetEnv("MOZ_GL_DEBUG_ABORT_ON_ERROR"))
-        sDebugMode |= DebugAbortOnError;
-#endif
-
     if (mInitialized)
         reporter.SetSuccessful();
     else {
         // if initialization fails, ensure all symbols are zero, to avoid hard-to-understand bugs
         mSymbols.Zero();
         NS_WARNING("InitWithPrefix failed!");
     }
 
@@ -522,33 +522,33 @@ GLContext::InitExtensions()
     char *exts = strdup((char *)extensions);
 
 #ifdef DEBUG
     static bool once = false;
 #else
     const bool once = true;
 #endif
 
-    if (!once) {
+    if (DebugMode() && !once) {
         printf_stderr("GL extensions: %s\n", exts);
     }
 
     char *s = exts;
     bool done = false;
     while (!done) {
         char *space = strchr(s, ' ');
         if (space) {
             *space = '\0';
         } else {
             done = true;
         }
 
         for (int i = 0; sExtensionNames[i]; ++i) {
             if (strcmp(s, sExtensionNames[i]) == 0) {
-                if (!once) {
+                if (DebugMode() && !once) {
                     printf_stderr("Found extension %s\n", s);
                 }
                 mAvailableExtensions[i] = 1;
             }
         }
 
         s = space+1;
     }
@@ -1500,27 +1500,31 @@ GLContext::AssembleOffscreenFBOs(const G
     GLenum status;
     bool isComplete = true;
 
     BindInternalFBO(drawFBO);
     status = fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
     if (status != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
         NS_WARNING("DrawFBO: Incomplete");
   #ifdef DEBUG
-        printf_stderr("Framebuffer status: %X\n", status);
+        if (DebugMode()) {
+            printf_stderr("Framebuffer status: %X\n", status);
+        }
   #endif
         isComplete = false;
     }
 
     BindInternalFBO(readFBO);
     status = fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
     if (status != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
         NS_WARNING("ReadFBO: Incomplete");
   #ifdef DEBUG
-        printf_stderr("Framebuffer status: %X\n", status);
+        if (DebugMode()) {
+            printf_stderr("Framebuffer status: %X\n", status);
+        }
   #endif
         isComplete = false;
     }
 
     BindUserDrawFBO(boundDrawFBO);
     BindUserReadFBO(boundReadFBO);
 
     return isComplete;
@@ -3033,27 +3037,29 @@ ReportArrayContents(const nsTArray<GLCon
         printf_stderr("%d ", copy[i].name);
     }
     printf_stderr("\n");
 }
 
 void
 GLContext::ReportOutstandingNames()
 {
-    printf_stderr("== GLContext %p ==\n", this);
-    printf_stderr("Outstanding Textures:\n");
-    ReportArrayContents(mTrackedTextures);
-    printf_stderr("Outstanding Buffers:\n");
-    ReportArrayContents(mTrackedBuffers);
-    printf_stderr("Outstanding Programs:\n");
-    ReportArrayContents(mTrackedPrograms);
-    printf_stderr("Outstanding Shaders:\n");
-    ReportArrayContents(mTrackedShaders);
-    printf_stderr("Outstanding Framebuffers:\n");
-    ReportArrayContents(mTrackedFramebuffers);
-    printf_stderr("Outstanding Renderbuffers:\n");
-    ReportArrayContents(mTrackedRenderbuffers);
+    if (DebugMode()) {
+        printf_stderr("== GLContext %p ==\n", this);
+        printf_stderr("Outstanding Textures:\n");
+        ReportArrayContents(mTrackedTextures);
+        printf_stderr("Outstanding Buffers:\n");
+        ReportArrayContents(mTrackedBuffers);
+        printf_stderr("Outstanding Programs:\n");
+        ReportArrayContents(mTrackedPrograms);
+        printf_stderr("Outstanding Shaders:\n");
+        ReportArrayContents(mTrackedShaders);
+        printf_stderr("Outstanding Framebuffers:\n");
+        ReportArrayContents(mTrackedFramebuffers);
+        printf_stderr("Outstanding Renderbuffers:\n");
+        ReportArrayContents(mTrackedRenderbuffers);
+    }
 }
 
 #endif /* DEBUG */
 
 } /* namespace gl */
 } /* namespace mozilla */
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -653,17 +653,19 @@ public:
                     bool deleteDrawable,
                     gfxXlibSurface *pixmap = nsnull)
     {
         int db = 0, err;
         err = sGLXLibrary.xGetFBConfigAttrib(display, cfg,
                                              GLX_DOUBLEBUFFER, &db);
         if (GLX_BAD_ATTRIBUTE != err) {
 #ifdef DEBUG
-            printf("[GLX] FBConfig is %sdouble-buffered\n", db ? "" : "not ");
+            if (DebugMode()) {
+                printf("[GLX] FBConfig is %sdouble-buffered\n", db ? "" : "not ");
+            }
 #endif
         }
 
         GLXContext context;
         nsRefPtr<GLContextGLX> glContext;
         bool error;
 
         ScopedXErrorHandler xErrorHandler;