Browse Source

OpenGL thread-safety fix.

tags/2021-05-28
jules 11 years ago
parent
commit
6cd4bb5448
1 changed files with 22 additions and 8 deletions
  1. +22
    -8
      modules/juce_opengl/opengl/juce_OpenGLContext.cpp

+ 22
- 8
modules/juce_opengl/opengl/juce_OpenGLContext.cpp View File

@@ -145,11 +145,6 @@ public:
{ {
ScopedPointer<MessageManagerLock> mmLock; ScopedPointer<MessageManagerLock> mmLock;
const Rectangle<int> screenBounds (component.getTopLevelComponent()->getScreenBounds());
if (lastScreenBounds != screenBounds)
updateViewportSize (false);
const bool isUpdating = needsUpdate.compareAndSetBool (0, 1); const bool isUpdating = needsUpdate.compareAndSetBool (0, 1);
if (context.renderComponents && isUpdating) if (context.renderComponents && isUpdating)
@@ -161,6 +156,8 @@ public:
mmLock = new MessageManagerLock (this); // need to acquire this before locking the context. mmLock = new MessageManagerLock (this); // need to acquire this before locking the context.
if (! mmLock->lockWasGained()) if (! mmLock->lockWasGained())
return false; return false;
updateViewportSize (false);
} }
if (! context.makeActive()) if (! context.makeActive())
@@ -219,13 +216,19 @@ public:
} }
} }
void checkViewportBounds()
{
const Rectangle<int> screenBounds (component.getTopLevelComponent()->getScreenBounds());
if (lastScreenBounds != screenBounds)
updateViewportSize (true);
}
void paintComponent() void paintComponent()
{ {
// you mustn't set your own cached image object when attaching a GL context! // you mustn't set your own cached image object when attaching a GL context!
jassert (get (component) == this); jassert (get (component) == this);
updateViewportSize (false);
if (! ensureFrameBufferSize()) if (! ensureFrameBufferSize())
return; return;
@@ -463,7 +466,8 @@ void OpenGLContext::NativeContext::renderCallback()
#endif #endif
//============================================================================== //==============================================================================
class OpenGLContext::Attachment : public ComponentMovementWatcher
class OpenGLContext::Attachment : public ComponentMovementWatcher,
private Timer
{ {
public: public:
Attachment (OpenGLContext& c, Component& comp) Attachment (OpenGLContext& c, Component& comp)
@@ -564,10 +568,14 @@ private:
comp.setCachedComponentImage (newCachedImage); comp.setCachedComponentImage (newCachedImage);
newCachedImage->start(); // (must wait until this is attached before starting its thread) newCachedImage->start(); // (must wait until this is attached before starting its thread)
newCachedImage->updateViewportSize (true); newCachedImage->updateViewportSize (true);
startTimer (400);
} }
void detach() void detach()
{ {
stopTimer();
Component& comp = *getComponent(); Component& comp = *getComponent();
#if JUCE_MAC #if JUCE_MAC
@@ -580,6 +588,12 @@ private:
comp.setCachedComponentImage (nullptr); comp.setCachedComponentImage (nullptr);
context.nativeContext = nullptr; context.nativeContext = nullptr;
} }
void timerCallback() override
{
if (CachedImage* const cachedImage = CachedImage::get (*getComponent()))
cachedImage->checkViewportBounds();
}
}; };
//============================================================================== //==============================================================================


Loading…
Cancel
Save