Commit: dab48e0ca796d2aa3db3d4858e1b8f29b516b10d
Author: Clément Foucault
Date:   Fri Feb 23 21:44:59 2018 +0100
Branches: temp-drawcontext
https://developer.blender.org/rBdab48e0ca796d2aa3db3d4858e1b8f29b516b10d

GHOST: Add a new routine to unbind an ogl context for multithreading.

===================================================================

M       intern/ghost/GHOST_C-api.h
M       intern/ghost/GHOST_IContext.h
M       intern/ghost/intern/GHOST_C-api.cpp
M       intern/ghost/intern/GHOST_Context.h
M       intern/ghost/intern/GHOST_ContextCGL.h
M       intern/ghost/intern/GHOST_ContextCGL.mm
M       intern/ghost/intern/GHOST_ContextEGL.cpp
M       intern/ghost/intern/GHOST_ContextEGL.h
M       intern/ghost/intern/GHOST_ContextGLX.cpp
M       intern/ghost/intern/GHOST_ContextGLX.h
M       intern/ghost/intern/GHOST_ContextNone.cpp
M       intern/ghost/intern/GHOST_ContextNone.h
M       intern/ghost/intern/GHOST_ContextSDL.cpp
M       intern/ghost/intern/GHOST_ContextSDL.h
M       intern/ghost/intern/GHOST_ContextWGL.cpp
M       intern/ghost/intern/GHOST_ContextWGL.h
M       source/blender/draw/intern/draw_manager.c
M       source/blender/windowmanager/WM_api.h
M       source/blender/windowmanager/intern/wm_window.c

===================================================================

diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index f743ceb0786..d5d8be7db8e 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -735,6 +735,13 @@ extern GHOST_TSuccess 
GHOST_InvalidateWindow(GHOST_WindowHandle windowhandle);
  */
 extern GHOST_TSuccess GHOST_ActivateOpenGLContext(GHOST_ContextHandle 
contexthandle);
 
+/**
+ * Release the drawing context bound to this thread.
+ * \param contexthandle The handle to the context
+ * \return A success indicator.
+ */
+extern GHOST_TSuccess GHOST_ReleaseOpenGLContext(GHOST_ContextHandle 
contexthandle);
+
 /**
  * Returns the status of the tablet
  * \param windowhandle The handle to the window
diff --git a/intern/ghost/GHOST_IContext.h b/intern/ghost/GHOST_IContext.h
index fd8647b6335..5b027a614ab 100644
--- a/intern/ghost/GHOST_IContext.h
+++ b/intern/ghost/GHOST_IContext.h
@@ -63,6 +63,12 @@ public:
         */
        virtual GHOST_TSuccess activateDrawingContext() = 0;
 
+       /**
+        * Release the drawing context of the calling thread.
+        * \return  A boolean success indicator.
+        */
+       virtual GHOST_TSuccess releaseDrawingContext() = 0;
+
 #ifdef WITH_CXX_GUARDEDALLOC
        MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_IContext")
 #endif
diff --git a/intern/ghost/intern/GHOST_C-api.cpp 
b/intern/ghost/intern/GHOST_C-api.cpp
index a16ffdfecfd..2fe94171cf8 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -736,6 +736,13 @@ GHOST_TSuccess 
GHOST_ActivateOpenGLContext(GHOST_ContextHandle contexthandle)
        return context->activateDrawingContext();
 }
 
+GHOST_TSuccess GHOST_ReleaseOpenGLContext(GHOST_ContextHandle contexthandle)
+{
+       GHOST_IContext *context = (GHOST_IContext *) contexthandle;
+
+       return context->releaseDrawingContext();
+}
+
 GHOST_TSuccess GHOST_InvalidateWindow(GHOST_WindowHandle windowhandle)
 {
        GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
diff --git a/intern/ghost/intern/GHOST_Context.h 
b/intern/ghost/intern/GHOST_Context.h
index 632240e48f0..670b86d456f 100644
--- a/intern/ghost/intern/GHOST_Context.h
+++ b/intern/ghost/intern/GHOST_Context.h
@@ -72,6 +72,12 @@ public:
         */
        virtual GHOST_TSuccess activateDrawingContext() = 0;
 
+       /**
+        * Release the drawing context of the calling thread.
+        * \return  A boolean success indicator.
+        */
+       virtual GHOST_TSuccess releaseDrawingContext()= 0;
+
        /**
         * Call immediately after new to initialize.  If this fails then 
immediately delete the object.
         * \return Indication as to whether initialization has succeeded.
diff --git a/intern/ghost/intern/GHOST_ContextCGL.h 
b/intern/ghost/intern/GHOST_ContextCGL.h
index 6dcc4da0f0a..ea6eb485ce2 100644
--- a/intern/ghost/intern/GHOST_ContextCGL.h
+++ b/intern/ghost/intern/GHOST_ContextCGL.h
@@ -82,6 +82,12 @@ public:
         */
        GHOST_TSuccess activateDrawingContext();
 
+       /**
+        * Release the drawing context of the calling thread.
+        * \return  A boolean success indicator.
+        */
+       GHOST_TSuccess releaseDrawingContext();
+
        /**
         * Call immediately after new to initialize.  If this fails then 
immediately delete the object.
         * \return Indication as to whether initialization has succeeded.
diff --git a/intern/ghost/intern/GHOST_ContextCGL.mm 
b/intern/ghost/intern/GHOST_ContextCGL.mm
index 88aba680f91..56d1c66e0e5 100644
--- a/intern/ghost/intern/GHOST_ContextCGL.mm
+++ b/intern/ghost/intern/GHOST_ContextCGL.mm
@@ -168,6 +168,18 @@ GHOST_TSuccess GHOST_ContextCGL::activateDrawingContext()
        }
 }
 
+GHOST_TSuccess GHOST_ContextCGL::releaseDrawingContext()
+{
+       if (m_openGLContext != nil) {
+               NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+               [m_openGLContext clearCurrentContext];
+               [pool drain];
+               return GHOST_kSuccess;
+       }
+       else {
+               return GHOST_kFailure;
+       }
+}
 
 GHOST_TSuccess GHOST_ContextCGL::updateDrawingContext()
 {
diff --git a/intern/ghost/intern/GHOST_ContextEGL.cpp 
b/intern/ghost/intern/GHOST_ContextEGL.cpp
index a591d9b7583..56962d24939 100644
--- a/intern/ghost/intern/GHOST_ContextEGL.cpp
+++ b/intern/ghost/intern/GHOST_ContextEGL.cpp
@@ -312,6 +312,17 @@ GHOST_TSuccess GHOST_ContextEGL::activateDrawingContext()
        }
 }
 
+GHOST_TSuccess GHOST_ContextEGL::releaseDrawingContext()
+{
+       if (m_display) {
+               bindAPI(m_api);
+
+               return EGL_CHK(::eglMakeCurrent(m_display, None, None, NULL)) ? 
GHOST_kSuccess : GHOST_kFailure;
+       }
+       else {
+               return GHOST_kFailure;
+       }
+}
 
 void GHOST_ContextEGL::initContextEGLEW()
 {
diff --git a/intern/ghost/intern/GHOST_ContextEGL.h 
b/intern/ghost/intern/GHOST_ContextEGL.h
index 6dfb177f26d..83415f6be54 100644
--- a/intern/ghost/intern/GHOST_ContextEGL.h
+++ b/intern/ghost/intern/GHOST_ContextEGL.h
@@ -80,6 +80,12 @@ public:
         */
        GHOST_TSuccess activateDrawingContext();
 
+       /**
+        * Release the drawing context of the calling thread.
+        * \return  A boolean success indicator.
+        */
+       GHOST_TSuccess releaseDrawingContext();
+
        /**
         * Call immediately after new to initialize.  If this fails then 
immediately delete the object.
         * \return Indication as to whether initialization has succeeded.
diff --git a/intern/ghost/intern/GHOST_ContextGLX.cpp 
b/intern/ghost/intern/GHOST_ContextGLX.cpp
index 65f285a64b0..04096af306d 100644
--- a/intern/ghost/intern/GHOST_ContextGLX.cpp
+++ b/intern/ghost/intern/GHOST_ContextGLX.cpp
@@ -118,6 +118,16 @@ GHOST_TSuccess GHOST_ContextGLX::activateDrawingContext()
        }
 }
 
+GHOST_TSuccess GHOST_ContextGLX::releaseDrawingContext()
+{
+       if (m_display) {
+               return ::glXMakeCurrent(m_display, None, NULL) ? GHOST_kSuccess 
: GHOST_kFailure;
+       }
+       else {
+               return GHOST_kFailure;
+       }
+}
+
 void GHOST_ContextGLX::initContextGLXEW()
 {
        initContextGLEW();
diff --git a/intern/ghost/intern/GHOST_ContextGLX.h 
b/intern/ghost/intern/GHOST_ContextGLX.h
index 51fb1dd57dc..ded1b293659 100644
--- a/intern/ghost/intern/GHOST_ContextGLX.h
+++ b/intern/ghost/intern/GHOST_ContextGLX.h
@@ -81,6 +81,12 @@ public:
         */
        GHOST_TSuccess activateDrawingContext();
 
+       /**
+        * Release the drawing context of the calling thread.
+        * \return  A boolean success indicator.
+        */
+       GHOST_TSuccess releaseDrawingContext();
+
        /**
         * Call immediately after new to initialize.  If this fails then 
immediately delete the object.
         * \return Indication as to whether initialization has succeeded.
diff --git a/intern/ghost/intern/GHOST_ContextNone.cpp 
b/intern/ghost/intern/GHOST_ContextNone.cpp
index 380ab532f7a..89bdf6b89fa 100644
--- a/intern/ghost/intern/GHOST_ContextNone.cpp
+++ b/intern/ghost/intern/GHOST_ContextNone.cpp
@@ -46,6 +46,12 @@ GHOST_TSuccess GHOST_ContextNone::activateDrawingContext()
 }
 
 
+GHOST_TSuccess GHOST_ContextNone::releaseDrawingContext()
+{
+       return GHOST_kSuccess;
+}
+
+
 GHOST_TSuccess GHOST_ContextNone::updateDrawingContext()
 {
        return GHOST_kSuccess;
diff --git a/intern/ghost/intern/GHOST_ContextNone.h 
b/intern/ghost/intern/GHOST_ContextNone.h
index 80cce76190d..9f2af4ae235 100644
--- a/intern/ghost/intern/GHOST_ContextNone.h
+++ b/intern/ghost/intern/GHOST_ContextNone.h
@@ -59,6 +59,12 @@ public:
         */
        GHOST_TSuccess activateDrawingContext();
 
+       /**
+        * Dummy function
+        * \return  Always succeeds
+        */
+       GHOST_TSuccess releaseDrawingContext();
+
        /**
         * Dummy function
         * \return Always succeeds
diff --git a/intern/ghost/intern/GHOST_ContextSDL.cpp 
b/intern/ghost/intern/GHOST_ContextSDL.cpp
index 7a02e9743c3..1ba591bd0b2 100644
--- a/intern/ghost/intern/GHOST_ContextSDL.cpp
+++ b/intern/ghost/intern/GHOST_ContextSDL.cpp
@@ -105,6 +105,18 @@ GHOST_TSuccess GHOST_ContextSDL::activateDrawingContext()
 }
 
 
+GHOST_TSuccess GHOST_ContextSDL::releaseDrawingContext()
+{
+       if (m_context) {
+               /* Untested, may not work */
+               return SDL_GL_MakeCurrent(NULL, NULL) ? GHOST_kSuccess : 
GHOST_kFailure;
+       }
+       else {
+               return GHOST_kFailure;
+       }
+}
+
+
 GHOST_TSuccess GHOST_ContextSDL::initializeDrawingContext()
 {
 #ifdef GHOST_OPENGL_ALPHA
diff --git a/intern/ghost/intern/GHOST_ContextSDL.h 
b/intern/ghost/intern/GHOST_ContextSDL.h
index 61f339c1bc2..681d24bb7c6 100644
--- a/intern/ghost/intern/GHOST_ContextSDL.h
+++ b/intern/ghost/intern/GHOST_ContextSDL.h
@@ -85,6 +85,12 @@ public:
         */
        GHOST_TSuccess activateDrawingContext();
 
+       /**
+        * Release the drawing context of the calling thread.
+        * \return  A boolean success indicator.
+        */
+       GHOST_TSuccess releaseDrawingContext();
+
        /**
         * Call immediately after new to initialize.  If this fails then 
immediately delete the object.
         * \return Indication as to whether initialization has succeeded.
diff --git a/intern/ghost/intern/GHOST_ContextWGL.cpp 
b/intern/ghost/intern/GHOST_ContextWGL.cpp
index 249723a9722..a23c0b0b26c 100644
--- a/intern/ghost/intern/GHOST_ContextWGL.cpp
+++ b/intern/ghost/intern/GHOST_ContextWGL.cpp
@@ -154,6 +154,16 @@ GHOST_TSuccess GHOST_ContextWGL::activateDrawingContext()
 }
 
 
+GHOST_TSuccess GHOST_ContextWGL::releaseDrawingContext()
+{
+       if (WIN32_CHK(::wglMakeCurrent(NULL, NULL))) {
+               return GHOST_kSuccess;
+       }
+       else {
+               return GHOST_kFailure;
+       }
+}
+
 /* Ron Fosner's code for weighting pixel formats and forcing software.
  * See http://www.opengl.org/resources/faq/technical/weight.cpp
  */
diff --git a/intern/ghost/intern/GHOST_ContextWGL.h 
b/intern/ghost/intern/GHOST_ContextWGL.h
index 2ab85b60a88..b3b66c5f6e2 100644
--- a/intern/ghost/intern/GHOST_ContextWGL.h
+++ b/intern/ghost/intern/GHOST_ContextWGL.h
@@ -78,6 +78,12 @@ public:
         */
        GHOST_TSuccess activateDrawingContext();
 
+       /**
+        * Release the drawing context of the calling thread.
+        * \return  A boolean success indicator.
+        */
+       GHOST_TSuccess releaseDrawingContext();
+
        /**
         * Call immediately after new to initialize.  If this fails then 
immediately delete the object.
         * \return Indication as to whether initialization has succeeded.
diff --git a/source/blender/draw/intern/draw_manager.c 
b/source/blender/draw/intern/draw_manager.c
index 0226a55088e..678f86ca469 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -4351,7 +4351,13 @@ void DRW_opengl_context_enable(void)
 void DRW_opengl_context_disable(void)
 {
        if (g_ogl_context != NULL) {
-               wm_window_reset_drawable();
+               if (BLI_thread_is_main()) {
+                       wm_window_rese

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to