| @@ -88,7 +88,7 @@ public: | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| void initialiseOnRenderThread (OpenGLContext& aContext) | |||||
| bool initialiseOnRenderThread (OpenGLContext& aContext) | |||||
| { | { | ||||
| jassert (hasInitialised); | jassert (hasInitialised); | ||||
| @@ -100,9 +100,25 @@ public: | |||||
| // get a pointer to the native window | // get a pointer to the native window | ||||
| ANativeWindow* window = nullptr; | ANativeWindow* window = nullptr; | ||||
| if (jobject jSurface = env->CallObjectMethod (surfaceView.get(), NativeSurfaceView.getNativeSurface)) | if (jobject jSurface = env->CallObjectMethod (surfaceView.get(), NativeSurfaceView.getNativeSurface)) | ||||
| window = ANativeWindow_fromSurface (env, jSurface); | |||||
| { | |||||
| window = ANativeWindow_fromSurface(env, jSurface); | |||||
| // if we didn't succeed the first time, wait 25ms and try again | |||||
| if (window == nullptr) | |||||
| { | |||||
| Thread::sleep (25); | |||||
| window = ANativeWindow_fromSurface (env, jSurface); | |||||
| } | |||||
| } | |||||
| jassert (window != nullptr); | |||||
| if (window == nullptr) | |||||
| { | |||||
| // failed to get a pointer to the native window after second try so | |||||
| // bail out | |||||
| jassertfalse; | |||||
| return false; | |||||
| } | |||||
| // create the surface | // create the surface | ||||
| surface = eglCreateWindowSurface(display, config, window, 0); | surface = eglCreateWindowSurface(display, config, window, 0); | ||||
| @@ -116,6 +132,8 @@ public: | |||||
| jassert (context != EGL_NO_CONTEXT); | jassert (context != EGL_NO_CONTEXT); | ||||
| juceContext = &aContext; | juceContext = &aContext; | ||||
| return true; | |||||
| } | } | ||||
| void shutdownOnRenderThread() | void shutdownOnRenderThread() | ||||
| @@ -113,7 +113,7 @@ public: | |||||
| [view release]; | [view release]; | ||||
| } | } | ||||
| void initialiseOnRenderThread (OpenGLContext&) {} | |||||
| bool initialiseOnRenderThread (OpenGLContext&) { return true; } | |||||
| void shutdownOnRenderThread() | void shutdownOnRenderThread() | ||||
| { | { | ||||
| @@ -142,12 +142,14 @@ public: | |||||
| XWindowSystem::getInstance()->displayUnref(); | XWindowSystem::getInstance()->displayUnref(); | ||||
| } | } | ||||
| void initialiseOnRenderThread (OpenGLContext& c) | |||||
| bool initialiseOnRenderThread (OpenGLContext& c) | |||||
| { | { | ||||
| ScopedXLock xlock (display); | ScopedXLock xlock (display); | ||||
| renderContext = glXCreateContext (display, bestVisual, (GLXContext) contextToShareWith, GL_TRUE); | renderContext = glXCreateContext (display, bestVisual, (GLXContext) contextToShareWith, GL_TRUE); | ||||
| c.makeActive(); | c.makeActive(); | ||||
| context = &c; | context = &c; | ||||
| return true; | |||||
| } | } | ||||
| void shutdownOnRenderThread() | void shutdownOnRenderThread() | ||||
| @@ -111,12 +111,12 @@ public: | |||||
| } | } | ||||
| } | } | ||||
| void initialiseOnRenderThread (OpenGLContext&) {} | |||||
| void shutdownOnRenderThread() { deactivateCurrentContext(); } | |||||
| bool initialiseOnRenderThread (OpenGLContext&) { return true; } | |||||
| void shutdownOnRenderThread() { deactivateCurrentContext(); } | |||||
| bool createdOk() const noexcept { return getRawContext() != nullptr; } | |||||
| void* getRawContext() const noexcept { return static_cast<void*> (renderContext); } | |||||
| GLuint getFrameBufferID() const noexcept { return 0; } | |||||
| bool createdOk() const noexcept { return getRawContext() != nullptr; } | |||||
| void* getRawContext() const noexcept { return static_cast<void*> (renderContext); } | |||||
| GLuint getFrameBufferID() const noexcept { return 0; } | |||||
| bool makeActive() const noexcept | bool makeActive() const noexcept | ||||
| { | { | ||||
| @@ -89,7 +89,12 @@ public: | |||||
| releaseDC(); | releaseDC(); | ||||
| } | } | ||||
| void initialiseOnRenderThread (OpenGLContext& c) { context = &c; } | |||||
| bool initialiseOnRenderThread (OpenGLContext& c) | |||||
| { | |||||
| context = &c; | |||||
| return true; | |||||
| } | |||||
| void shutdownOnRenderThread() { deactivateCurrentContext(); context = nullptr; } | void shutdownOnRenderThread() { deactivateCurrentContext(); context = nullptr; } | ||||
| static void deactivateCurrentContext() { wglMakeCurrent (0, 0); } | static void deactivateCurrentContext() { wglMakeCurrent (0, 0); } | ||||
| @@ -438,7 +438,13 @@ public: | |||||
| } while (! mmLock.retryLock()); | } while (! mmLock.retryLock()); | ||||
| } | } | ||||
| initialiseOnThread(); | |||||
| if (! initialiseOnThread()) | |||||
| { | |||||
| hasInitialised = false; | |||||
| return ThreadPoolJob::jobHasFinished; | |||||
| } | |||||
| hasInitialised = true; | hasInitialised = true; | ||||
| while (! shouldExit()) | while (! shouldExit()) | ||||
| @@ -468,7 +474,7 @@ public: | |||||
| return ThreadPoolJob::jobHasFinished; | return ThreadPoolJob::jobHasFinished; | ||||
| } | } | ||||
| void initialiseOnThread() | |||||
| bool initialiseOnThread() | |||||
| { | { | ||||
| // On android, this can get called twice, so drop any previous state.. | // On android, this can get called twice, so drop any previous state.. | ||||
| associatedObjectNames.clear(); | associatedObjectNames.clear(); | ||||
| @@ -476,7 +482,9 @@ public: | |||||
| cachedImageFrameBuffer.release(); | cachedImageFrameBuffer.release(); | ||||
| context.makeActive(); | context.makeActive(); | ||||
| nativeContext->initialiseOnRenderThread (context); | |||||
| if (! nativeContext->initialiseOnRenderThread (context)) | |||||
| return false; | |||||
| #if JUCE_ANDROID | #if JUCE_ANDROID | ||||
| // On android the context may be created in initialiseOnRenderThread | // On android the context may be created in initialiseOnRenderThread | ||||
| @@ -506,6 +514,8 @@ public: | |||||
| if (context.renderer != nullptr) | if (context.renderer != nullptr) | ||||
| context.renderer->newOpenGLContextCreated(); | context.renderer->newOpenGLContextCreated(); | ||||
| return true; | |||||
| } | } | ||||
| void shutdownOnThread() | void shutdownOnThread() | ||||