Kaydet (Commit) 52356d43 authored tarafından Miklos Vajna's avatar Miklos Vajna Kaydeden (comit) Andras Timar

windows opengl: make sure mpLastContext is indeed the current context

There were two problems here:

1) The OpenGLContext ctor registered the instance on the list of
contexts, but platform-specific call (e.g. wglMakeCurrent()) was only
made later. Add a registerAsCurrent() member function that helps
ensuring that the last item in the context list is indeed the current
context.

2) OpenGLContext::prepareForYield() is called without the solar mutex
being locked, but it still assumes that the last context in the context
list is the thread's current context, which may not be true.  The result
is that during JunitTest_sd_unoapi, we end up in a situation like:

debug:4640:5240: OpenGLContext::registerAsCurrent: wglGetCurrentContext() is 00010001, pSVData->maGDIData.mpLastContext is 00FA65F8
debug:4640:7944: OpenGLContext::registerAsCurrent: wglGetCurrentContext() is 000D0003, pSVData->maGDIData.mpLastContext is 00FA6C70
debug:4640:5240: OpenGLContext::prepareForYield: start, wglGetCurrentContext() is 00010001, pSVData->maGDIData.mpLastContext is 00FA6C70

I.e. one thread registers as current, an other registers as current, too (while
the other thread has the solar mutex), then once the original thread wants to
release the solar mutex, the real current context and the last item in the
context list won't match, so the assert at the end of prepareForYield() will
fail.

Fix this by releasing the GL context in WinSalInstance::DestroyFrame().

With this, JunitTest_sd_unoapi passes on Windows with GL enabled.

Change-Id: Icfb9c65c871586b5df69b5a2ab3aa91843dfc799
Reviewed-on: https://gerrit.libreoffice.org/18473Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
Tested-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
Signed-off-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/18488
üst dd40c79e
......@@ -219,6 +219,8 @@ public:
static bool hasCurrent();
/// make this GL context current - so it is implicit in subsequent GL calls
void makeCurrent();
/// Put this GL context to the end of the context list.
void registerAsCurrent();
/// reset the GL context so this context is not implicit in subsequent GL calls.
void resetCurrent();
void swapBuffers();
......
......@@ -861,6 +861,8 @@ bool OpenGLContext::ImplInit()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
registerAsCurrent();
return bRet;
}
......@@ -1005,6 +1007,8 @@ bool OpenGLContext::ImplInit()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
registerAsCurrent();
return true;
}
......@@ -1434,8 +1438,6 @@ void OpenGLContext::prepareForYield()
void OpenGLContext::makeCurrent()
{
ImplSVData* pSVData = ImplGetSVData();
if (isCurrent())
return;
......@@ -1470,6 +1472,13 @@ void OpenGLContext::makeCurrent()
}
#endif
registerAsCurrent();
}
void OpenGLContext::registerAsCurrent()
{
ImplSVData* pSVData = ImplGetSVData();
// move the context to the end of the contexts list
static int nSwitch = 0;
VCL_GL_INFO("vcl.opengl", "******* CONTEXT SWITCH " << ++nSwitch << " *********");
......
......@@ -921,6 +921,7 @@ SalFrame* WinSalInstance::CreateFrame( SalFrame* pParent, sal_uLong nSalFrameSty
void WinSalInstance::DestroyFrame( SalFrame* pFrame )
{
OpenGLContext::prepareForYield();
SendMessageW( mhComWnd, SAL_MSG_DESTROYFRAME, 0, (LPARAM)pFrame );
}
......
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