diff --git a/modules/juce_opengl/juce_opengl.h b/modules/juce_opengl/juce_opengl.h index 9f61cc2e99..eaf32cba6e 100644 --- a/modules/juce_opengl/juce_opengl.h +++ b/modules/juce_opengl/juce_opengl.h @@ -34,6 +34,10 @@ #define JUCE_OPENGL_ES 1 #endif +#if ! JUCE_ANDROID + #define JUCE_OPENGL_CREATE_JUCE_RENDER_THREAD 1 +#endif + #if JUCE_WINDOWS #ifndef APIENTRY #define APIENTRY __stdcall diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp index 60b25c1cf4..2c55c85911 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp @@ -22,13 +22,18 @@ ============================================================================== */ -class OpenGLContext::CachedImage : public CachedComponentImage, - public Thread +class OpenGLContext::CachedImage : public CachedComponentImage + #if JUCE_OPENGL_CREATE_JUCE_RENDER_THREAD + , private Thread + #endif { public: CachedImage (OpenGLContext& c, Component& comp, const OpenGLPixelFormat& pixFormat, void* contextToShare) - : Thread ("OpenGL Rendering"), + : + #if JUCE_OPENGL_CREATE_JUCE_RENDER_THREAD + Thread ("OpenGL Rendering"), + #endif context (c), component (comp), scale (1.0), #if JUCE_OPENGL3 @@ -58,7 +63,7 @@ public: void start() { - #if ! JUCE_ANDROID + #if JUCE_OPENGL_CREATE_JUCE_RENDER_THREAD if (nativeContext != nullptr) startThread (6); #endif @@ -66,7 +71,7 @@ public: void stop() { - #if ! JUCE_ANDROID + #if JUCE_OPENGL_CREATE_JUCE_RENDER_THREAD stopThread (10000); #endif hasInitialised = false; @@ -95,11 +100,11 @@ public: { needsUpdate = 1; - #if JUCE_ANDROID + #if JUCE_OPENGL_CREATE_JUCE_RENDER_THREAD + notify(); + #else if (nativeContext != nullptr) nativeContext->triggerRepaint(); - #else - notify(); #endif } @@ -151,9 +156,19 @@ public: { // This avoids hogging the message thread when doing intensive rendering. if (lastMMLockReleaseTime + 1 >= Time::getMillisecondCounter()) + { + #if JUCE_OPENGL_CREATE_JUCE_RENDER_THREAD wait (2); + #else + Thread::sleep (2); + #endif + } + #if JUCE_OPENGL_CREATE_JUCE_RENDER_THREAD mmLock = new MessageManagerLock (this); // need to acquire this before locking the context. + #else + mmLock = new MessageManagerLock (Thread::getCurrentThread()); + #endif if (! mmLock->lockWasGained()) return false; @@ -331,6 +346,7 @@ public: } //============================================================================== + #if JUCE_OPENGL_CREATE_JUCE_RENDER_THREAD void run() override { { @@ -364,6 +380,7 @@ public: shutdownOnThread(); } + #endif void initialiseOnThread() { @@ -444,36 +461,6 @@ public: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CachedImage) }; -//============================================================================== -#if JUCE_ANDROID -void OpenGLContext::NativeContext::contextCreatedCallback() -{ - isInsideGLCallback = true; - - if (CachedImage* const c = CachedImage::get (component)) - c->initialiseOnThread(); - else - jassertfalse; - - isInsideGLCallback = false; -} - -void OpenGLContext::NativeContext::renderCallback() -{ - isInsideGLCallback = true; - - if (CachedImage* const c = CachedImage::get (component)) - { - if (c->context.continuousRepaint) - c->context.triggerRepaint(); - - c->renderFrame(); - } - - isInsideGLCallback = false; -} -#endif - //============================================================================== class OpenGLContext::Attachment : public ComponentMovementWatcher, private Timer @@ -953,3 +940,33 @@ void OpenGLContext::copyTexture (const Rectangle& targetClipArea, JUCE_CHECK_OPENGL_ERROR } + +//============================================================================== +#if JUCE_ANDROID +void OpenGLContext::NativeContext::contextCreatedCallback() +{ + isInsideGLCallback = true; + + if (CachedImage* const c = CachedImage::get (component)) + c->initialiseOnThread(); + else + jassertfalse; + + isInsideGLCallback = false; +} + +void OpenGLContext::NativeContext::renderCallback() +{ + isInsideGLCallback = true; + + if (CachedImage* const c = CachedImage::get (component)) + { + if (c->context.continuousRepaint) + c->context.triggerRepaint(); + + c->renderFrame(); + } + + isInsideGLCallback = false; +} +#endif