Kaydet (Commit) acbf98d6 authored tarafından Michael Meeks's avatar Michael Meeks Kaydeden (comit) Markus Mohrhard

tdf#93867 - clear current GL context before thread switch.

Fixes regression from otherwise a nice cleanup in:
    d2009225

Also get polarity of debug logging only with a context right.

Change-Id: Id322471f01e5656e758aefc57b0d4d5ad073ec54
Reviewed-on: https://gerrit.libreoffice.org/18282Reviewed-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
üst d55c97a5
...@@ -212,7 +212,10 @@ public: ...@@ -212,7 +212,10 @@ public:
/// Is this GL context the current context ? /// Is this GL context the current context ?
bool isCurrent(); bool isCurrent();
/// release bound resources from the current context
static void clearCurrent(); static void clearCurrent();
/// release contexts etc. before (potentially) allowing another thread run.
static void prepareForYield();
/// Is there a current GL context ? /// Is there a current GL context ?
static bool hasCurrent(); static bool hasCurrent();
/// make this GL context current - so it is implicit in subsequent GL calls /// make this GL context current - so it is implicit in subsequent GL calls
......
...@@ -55,7 +55,7 @@ void SalYieldMutex::release() ...@@ -55,7 +55,7 @@ void SalYieldMutex::release()
{ {
if ( mnCount == 1 ) if ( mnCount == 1 )
{ {
OpenGLContext::clearCurrent(); OpenGLContext::prepareForYield();
mnThreadId = 0; mnThreadId = 0;
} }
mnCount--; mnCount--;
......
...@@ -271,7 +271,7 @@ void SalYieldMutex::release() ...@@ -271,7 +271,7 @@ void SalYieldMutex::release()
{ {
if ( mnCount == 1 ) if ( mnCount == 1 )
{ {
// TODO: add OpenGLContext::clearCurrent with vcl OpenGL support // TODO: add OpenGLContext::prepareForYield with vcl OpenGL support
mnThreadId = 0; mnThreadId = 0;
} }
mnCount--; mnCount--;
......
...@@ -1424,6 +1424,20 @@ void OpenGLContext::clearCurrent() ...@@ -1424,6 +1424,20 @@ void OpenGLContext::clearCurrent()
pCurrentCtx->ReleaseFramebuffers(); pCurrentCtx->ReleaseFramebuffers();
} }
void OpenGLContext::prepareForYield()
{
ImplSVData* pSVData = ImplGetSVData();
SAL_INFO("vcl.opengl", "Unbinding contexts in preparation for yield");
// release all framebuffers from the old context so we can re-attach the
// texture in the new context
OpenGLContext* pCurrentCtx = pSVData->maGDIData.mpLastContext;
if( pCurrentCtx && pCurrentCtx->isCurrent() )
pCurrentCtx->resetCurrent();
assert (!hasCurrent());
}
void OpenGLContext::makeCurrent() void OpenGLContext::makeCurrent()
{ {
ImplSVData* pSVData = ImplGetSVData(); ImplSVData* pSVData = ImplGetSVData();
......
...@@ -698,7 +698,7 @@ void OpenGLHelper::debugMsgPrint(const char *pArea, const char *pFormat, ...) ...@@ -698,7 +698,7 @@ void OpenGLHelper::debugMsgPrint(const char *pArea, const char *pFormat, ...)
vsnprintf(pStr, sizeof(pStr), pFormat, aArgs); vsnprintf(pStr, sizeof(pStr), pFormat, aArgs);
pStr[sizeof(pStr)-20] = '\0'; pStr[sizeof(pStr)-20] = '\0';
bool bHasContext = !OpenGLContext::hasCurrent(); bool bHasContext = OpenGLContext::hasCurrent();
if (!bHasContext) if (!bHasContext)
strcat(pStr, "- no GL context"); strcat(pStr, "- no GL context");
......
...@@ -153,7 +153,7 @@ void SalYieldMutex::release() ...@@ -153,7 +153,7 @@ void SalYieldMutex::release()
{ {
if ( mnCount == 1 ) if ( mnCount == 1 )
{ {
OpenGLContext::clearCurrent(); OpenGLContext::prepareForYield();
// If we don't call these message, the Output from the // If we don't call these message, the Output from the
// Java clients doesn't come in the right order // Java clients doesn't come in the right order
...@@ -176,7 +176,10 @@ void SalYieldMutex::release() ...@@ -176,7 +176,10 @@ void SalYieldMutex::release()
else else
{ {
if ( mnCount == 1 ) if ( mnCount == 1 )
{
mnThreadId = 0; mnThreadId = 0;
OpenGLContext::prepareForYield();
}
mnCount--; mnCount--;
m_mutex.release(); m_mutex.release();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment