Bug 1297315 - Fix Wmaybe-uninitialized warning and get rid of goto statement in GLContextProviderGLX.cpp and GfxTexturesReporter.cpp. r?jgilbert draft
authorJames Cheng <jacheng@mozilla.com>
Tue, 23 Aug 2016 14:30:37 +0800
changeset 405914 8b1988596c67698cf10e42596956e4f68b581258
parent 405855 a551f534773cf2d6933f78ce7d82a7a33a99643e
child 529537 45ac12765f43d9f4736e70abf2733a6ef7ab052d
push id27596
push userbmo:jacheng@mozilla.com
push dateFri, 26 Aug 2016 03:22:02 +0000
reviewersjgilbert
bugs1297315
milestone51.0a1
Bug 1297315 - Fix Wmaybe-uninitialized warning and get rid of goto statement in GLContextProviderGLX.cpp and GfxTexturesReporter.cpp. r?jgilbert MozReview-Commit-ID: AUjK7HhatX6
gfx/gl/GLContextProviderGLX.cpp
gfx/gl/GfxTexturesReporter.cpp
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -817,79 +817,79 @@ GLContextGLX::CreateGLContext(CreateCont
     }
 
     GLXContext context;
     RefPtr<GLContextGLX> glContext;
     bool error;
 
     ScopedXErrorHandler xErrorHandler;
 
-TRY_AGAIN_NO_SHARING:
-
-    error = false;
-
-    GLXContext glxContext = shareContext ? shareContext->mContext : nullptr;
-    if (glx.HasCreateContextAttribs()) {
-        AutoTArray<int, 11> attrib_list;
-        if (glx.HasRobustness()) {
-            int robust_attribs[] = {
-                LOCAL_GL_CONTEXT_FLAGS_ARB, LOCAL_GL_CONTEXT_ROBUST_ACCESS_BIT_ARB,
-                LOCAL_GL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, LOCAL_GL_LOSE_CONTEXT_ON_RESET_ARB,
-            };
-            attrib_list.AppendElements(robust_attribs, MOZ_ARRAY_LENGTH(robust_attribs));
-        }
-        if (profile == ContextProfile::OpenGLCore) {
-            int core_attribs[] = {
-                LOCAL_GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
-                LOCAL_GLX_CONTEXT_MINOR_VERSION_ARB, 2,
-                LOCAL_GLX_CONTEXT_FLAGS_ARB, LOCAL_GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
-            };
-            attrib_list.AppendElements(core_attribs, MOZ_ARRAY_LENGTH(core_attribs));
-        };
-        attrib_list.AppendElement(0);
+    do {
+        error = false;
 
-        context = glx.xCreateContextAttribs(
-            display,
-            cfg,
-            glxContext,
-            True,
-            attrib_list.Elements());
-    } else {
-        context = glx.xCreateNewContext(
-            display,
-            cfg,
-            LOCAL_GLX_RGBA_TYPE,
-            glxContext,
-            True);
-    }
+        GLXContext glxContext = shareContext ? shareContext->mContext : nullptr;
+        if (glx.HasCreateContextAttribs()) {
+            AutoTArray<int, 11> attrib_list;
+            if (glx.HasRobustness()) {
+                int robust_attribs[] = {
+                    LOCAL_GL_CONTEXT_FLAGS_ARB, LOCAL_GL_CONTEXT_ROBUST_ACCESS_BIT_ARB,
+                    LOCAL_GL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, LOCAL_GL_LOSE_CONTEXT_ON_RESET_ARB,
+                };
+                attrib_list.AppendElements(robust_attribs, MOZ_ARRAY_LENGTH(robust_attribs));
+            }
+            if (profile == ContextProfile::OpenGLCore) {
+                int core_attribs[] = {
+                    LOCAL_GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
+                    LOCAL_GLX_CONTEXT_MINOR_VERSION_ARB, 2,
+                    LOCAL_GLX_CONTEXT_FLAGS_ARB, LOCAL_GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
+                };
+                attrib_list.AppendElements(core_attribs, MOZ_ARRAY_LENGTH(core_attribs));
+            };
+            attrib_list.AppendElement(0);
 
-    if (context) {
-        glContext = new GLContextGLX(flags, caps, shareContext, isOffscreen, display,
-                                     drawable, context, deleteDrawable, db, pixmap,
-                                     profile);
-        if (!glContext->Init())
-            error = true;
-    } else {
-        error = true;
-    }
-
-    error |= xErrorHandler.SyncAndGetError(display);
-
-    if (error) {
-        if (shareContext) {
-            shareContext = nullptr;
-            goto TRY_AGAIN_NO_SHARING;
+            context = glx.xCreateContextAttribs(
+                display,
+                cfg,
+                glxContext,
+                True,
+                attrib_list.Elements());
+        } else {
+            context = glx.xCreateNewContext(
+                display,
+                cfg,
+                LOCAL_GLX_RGBA_TYPE,
+                glxContext,
+                True);
         }
 
-        NS_WARNING("Failed to create GLXContext!");
-        glContext = nullptr; // note: this must be done while the graceful X error handler is set,
-                            // because glxMakeCurrent can give a GLXBadDrawable error
-    }
+        if (context) {
+            glContext = new GLContextGLX(flags, caps, shareContext, isOffscreen, display,
+                                         drawable, context, deleteDrawable, db, pixmap,
+                                         profile);
+            if (!glContext->Init())
+                error = true;
+        } else {
+            error = true;
+        }
+
+        error |= xErrorHandler.SyncAndGetError(display);
 
-    return glContext.forget();
+        if (error) {
+            if (shareContext) {
+                shareContext = nullptr;
+                continue;
+            }
+
+            NS_WARNING("Failed to create GLXContext!");
+            glContext = nullptr; // note: this must be done while the graceful X error handler is set,
+                                // because glxMakeCurrent can give a GLXBadDrawable error
+        }
+
+        return glContext.forget();
+    } while (true);
 }
 
 GLContextGLX::~GLContextGLX()
 {
     MarkDestroyed();
 
     // Wrapped context should not destroy glxContext/Surface
     if (!mOwnsContext) {
@@ -1291,45 +1291,43 @@ CreateOffscreenPixmapContext(CreateConte
     }
 
     Visual* visual;
     int depth;
     FindVisualAndDepth(display, visid, &visual, &depth);
 
     ScopedXErrorHandler xErrorHandler;
     bool error = false;
-    // Must be declared before goto:
+
     Drawable drawable;
-    GLXPixmap pixmap;
+    GLXPixmap pixmap = 0;
 
     gfx::IntSize dummySize(16, 16);
     RefPtr<gfxXlibSurface> surface = gfxXlibSurface::Create(DefaultScreenOfDisplay(display),
                                                             visual,
                                                             dummySize);
     if (surface->CairoStatus() != 0) {
-        error = true;
-        goto DONE_CREATING_PIXMAP;
+        mozilla::Unused << xErrorHandler.SyncAndGetError(display);
+        return nullptr;
     }
 
     // Handle slightly different signature between glXCreatePixmap and
     // its pre-GLX-1.3 extension equivalent (though given the ABI, we
     // might not need to).
     drawable = surface->XDrawable();
     if (glx->GLXVersionCheck(1, 3)) {
         pixmap = glx->xCreatePixmap(display, config, drawable, nullptr);
     } else {
         pixmap = glx->xCreateGLXPixmapWithConfig(display, config, drawable);
     }
 
     if (pixmap == 0) {
         error = true;
     }
 
-DONE_CREATING_PIXMAP:
-
     bool serverError = xErrorHandler.SyncAndGetError(display);
     if (error || serverError)
         return nullptr;
 
     GLContextGLX* shareContext = GetGlobalContextGLX();
     return GLContextGLX::CreateGLContext(flags, minCaps, shareContext, true, display,
                                          pixmap, config, true, surface, profile);
 }
--- a/gfx/gl/GfxTexturesReporter.cpp
+++ b/gfx/gl/GfxTexturesReporter.cpp
@@ -42,16 +42,19 @@ FormatBytes(size_t amount)
       unit = "KB";
       break;
       case 2:
       unit = "MB";
       break;
       case 3:
       unit = "GB";
       break;
+      default:
+      unit = "";
+      break;
   }
 
   stream << val << " " << unit;
   return stream.str();
 }
 
 /* static */ void
 GfxTexturesReporter::UpdateAmount(MemoryUse action, size_t amount)