Backout 0bf0007285f7 (bug 730079) for warnings as errors build failures
authorEd Morley <bmo@edmorley.co.uk>
Thu, 23 Feb 2012 22:14:41 +0000
changeset 87577 9304fda5ddc7118d308bb1d612f19d17ec534433
parent 87576 c18ad658c0242552309616d218859d9a92f47120
child 87578 512df80d7ca4d0ce2dd9c2128bd8a6f5c2661f83
push id22133
push usermak77@bonardo.net
push dateFri, 24 Feb 2012 10:23:30 +0000
treeherdermozilla-central@fbcdc2c87df8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs730079
milestone13.0a1
backs out0bf0007285f78dcc7bbb3275a8a116d99d0410f7
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
Backout 0bf0007285f7 (bug 730079) for warnings as errors build failures
gfx/gl/GLContext.cpp
gfx/gl/GLContext.h
gfx/gl/GLContextProviderEGL.cpp
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -55,18 +55,18 @@
 #include "gfxUtils.h"
 
 #include "mozilla/Util.h" // for DebugOnly
 
 namespace mozilla {
 namespace gl {
 
 #ifdef DEBUG
-Monitor GLContext::sCurrentGLContextMonitor("sCurrentGLContext_monitor");
-PRUintn GLContext::sCurrentGLContextTLS = -1;
+// see comment near declaration in GLContext.h. Should be thread-local.
+GLContext* GLContext::sCurrentGLContext = nsnull;
 #endif
 
 PRUint32 GLContext::sDebugMode = 0;
 
 // define this here since it's global to GLContextProvider, not any
 // specific implementation
 const ContextFormat ContextFormat::BasicRGBA32Format(ContextFormat::BasicRGBA32);
 
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -47,20 +47,16 @@
 #endif
 #include <string.h>
 #include <ctype.h>
 
 #ifdef WIN32
 #include <windows.h>
 #endif
 
-#ifdef DEBUG
-#include "mozilla/Monitor.h"
-#endif
-
 #include "GLDefs.h"
 #include "gfxASurface.h"
 #include "gfxImageSurface.h"
 #include "gfxContext.h"
 #include "gfxRect.h"
 #include "nsISupportsImpl.h"
 #include "prlink.h"
 
@@ -603,23 +599,17 @@ public:
     };
 
     virtual GLContextType GetContextType() { return ContextTypeUnknown; }
 
     virtual bool MakeCurrentImpl(bool aForce = false) = 0;
 
     bool MakeCurrent(bool aForce = false) {
 #ifdef DEBUG
-        MonitorAutoLock lock(sCurrentGLContextMonitor);
-        GLContext *currentGLContext = NULL;
-
-        if (sCurrentGLContextTLS == -1)
-            PR_NewThreadPrivateIndex(&sCurrentGLContextTLS, NULL);
-
-        PR_SetThreadPrivate(sCurrentGLContextTLS, this);
+        sCurrentGLContext = this;
 #endif
         return MakeCurrentImpl(aForce);
     }
 
     bool IsContextLost() { return mContextLost; }
 
     virtual bool SetupLookupFunction() = 0;
 
@@ -1510,23 +1500,20 @@ public:
 protected:
 
     ContextFormat mCreationFormat;
     nsRefPtr<GLContext> mSharedContext;
 
     GLContextSymbols mSymbols;
 
 #ifdef DEBUG
-    // GLDebugMode will check that we don't send call
-    // to a GLContext that isn't current on the current
-    // thread.
-    // Store the current context when binding to thread local
-    // storage to support DebugMode on an arbitrary thread.
-    static Monitor sCurrentGLContextMonitor;
-    static PRUintn sCurrentGLContextTLS;
+    // this should be thread-local, but that is slightly annoying to implement because on Mac
+    // we don't have any __thread-like keyword. So for now, MOZ_GL_DEBUG assumes (and asserts)
+    // that only the main thread is doing OpenGL calls.
+    static THEBES_API GLContext* sCurrentGLContext;
 #endif
 
     void UpdateActualFormat();
     ContextFormat mActualFormat;
 
     gfxIntSize mOffscreenSize;
     gfxIntSize mOffscreenActualSize;
     GLuint mOffscreenTexture;
@@ -1640,28 +1627,31 @@ public:
 
 protected:
     GLenum mGLError;
 
 public:
 
     void BeforeGLCall(const char* glFunction) {
         if (DebugMode()) {
-            MonitorAutoLock lock(sCurrentGLContextMonitor);
-            GLContext *currentGLContext = NULL;
-
-            if (sCurrentGLContextTLS != -1)
-                currentGLContext = (GLContext*)PR_GetThreadPrivate(sCurrentGLContextTLS);
-
+            // since the static member variable sCurrentGLContext is not thread-local as it should,
+            // we have to assert that we're in the main thread. Note that sCurrentGLContext is only used
+            // for the OpenGL debug mode.
+            if (!NS_IsMainThread()) {
+                NS_ERROR("OpenGL call from non-main thread. While this is fine in itself, "
+                         "the OpenGL debug mode, which is currently enabled, doesn't support this. "
+                         "It needs to be patched by making GLContext::sCurrentGLContext be thread-local.\n");
+                NS_ABORT();
+            }
             if (DebugMode() & DebugTrace)
                 printf_stderr("[gl:%p] > %s\n", this, glFunction);
-            if (this != currentGLContext) {
+            if (this != sCurrentGLContext) {
                 printf_stderr("Fatal: %s called on non-current context %p. "
                               "The current context for this thread is %p.\n",
-                               glFunction, this, currentGLContext);
+                               glFunction, this, sCurrentGLContext);
                 NS_ABORT();
             }
         }
     }
 
     void AfterGLCall(const char* glFunction) {
         if (DebugMode()) {
             // calling fFinish() immediately after every GL call makes sure that if this GL command crashes,
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -262,16 +262,25 @@ is_power_of_two(int v)
 
 #define AFTER_GL_CALL do {           \
     AfterGLCall(MOZ_FUNCTION_NAME);  \
 } while (0)
 
 static void BeforeGLCall(const char* glFunction)
 {
     if (GLContext::DebugMode()) {
+        // since the static member variable sCurrentGLContext is not thread-local as it should,
+        // we have to assert that we're in the main thread. Note that sCurrentGLContext is only used
+        // for the OpenGL debug mode.
+        if (!NS_IsMainThread()) {
+            NS_ERROR("OpenGL call from non-main thread. While this is fine in itself, "
+                     "the OpenGL debug mode, which is currently enabled, doesn't support this. "
+                     "It needs to be patched by making GLContext::sCurrentGLContext be thread-local.\n");
+            NS_ABORT();
+        }
         if (GLContext::DebugMode() & GLContext::DebugTrace)
             printf_stderr("[egl] > %s\n", glFunction);
     }
 }
 
 static void AfterGLCall(const char* glFunction)
 {
     if (GLContext::DebugMode() & GLContext::DebugTrace) {