Bug 749678 - 4/5 - check owning thread in debug builds - r=bgirard
authorBenoit Jacob <bjacob@mozilla.com>
Tue, 08 May 2012 09:47:34 -0400
changeset 95765 0bd4182e0e61d0f4591a7dcd37391b88245ced60
parent 95764 d0c36963b5fc5302fc3607a643d9ce521fda17ce
child 95766 800b381a1638b17cff5925fac900371018aa9eda
push id1439
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 20:19:22 +0000
treeherdermozilla-aurora@ea74834dccd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgirard
bugs749678
milestone15.0a1
Bug 749678 - 4/5 - check owning thread in debug builds - r=bgirard
gfx/gl/GLContext.h
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -653,17 +653,40 @@ public:
         ContextTypeEGL,
         ContextTypeOSMesa
     };
 
     virtual GLContextType GetContextType() { return ContextTypeUnknown; }
 
     virtual bool MakeCurrentImpl() = 0;
 
+    void CheckOwningThreadInDebugMode() {
+#ifdef DEBUG
+        if (!NS_GetCurrentThread()) {
+            // happens during shutdown. Drop this check in that case.
+            return;
+        }
+        if (!IsOwningThreadCurrent())
+        {
+            printf_stderr(
+                "This GL context (%p) is owned by thread %p, but the current thread is %p. "
+                "That's fine by itself, but our current code in GLContext::MakeCurrent, checking "
+                "if the context is already current, relies on the assumption that GL calls on a given "
+                "GLContext are only made by the thread that created that GLContext. If you want to "
+                "start making GL calls from non-owning threads, you'll have to change a few things "
+                "around here, see Bug 749678 comments 13 and 15.\n",
+                this, mOwningThread.get(), NS_GetCurrentThread());
+            NS_ABORT();
+        }
+#endif
+    }
+
     bool MakeCurrent(bool aForce = false) {
+        CheckOwningThreadInDebugMode();
+
         if (!aForce &&
             this == CurrentGLContext())
         {
             return true;
         }
 
         bool success = MakeCurrentImpl();
         if (success) {
@@ -1874,16 +1897,17 @@ protected:
     GLenum mGLError;
 
 public:
 
     void BeforeGLCall(const char* glFunction) {
         if (DebugMode()) {
             if (DebugMode() & DebugTrace)
                 printf_stderr("[gl:%p] > %s\n", this, glFunction);
+            CheckOwningThreadInDebugMode();
             if (this != CurrentGLContext()) {
                 printf_stderr("Fatal: %s called on non-current context %p. "
                               "The current context for this thread is %p.\n",
                                glFunction, this, CurrentGLContext());
                 NS_ABORT();
             }
         }
     }