[Libreoffice-commits] core.git: Branch 'libreoffice-5-0-2' - include/vcl vcl/opengl vcl/source vcl/win
Miklos Vajna
vmiklos at collabora.co.uk
Fri Sep 11 02:44:55 PDT 2015
include/vcl/opengl/OpenGLContext.hxx | 2 ++
vcl/opengl/gdiimpl.cxx | 6 ++++++
vcl/source/opengl/OpenGLContext.cxx | 20 ++++++++++++++++++--
vcl/win/source/app/salinst.cxx | 1 +
4 files changed, 27 insertions(+), 2 deletions(-)
New commits:
commit 7886a031c407eb4fc1dc4072c73c33b1179e023f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Thu Sep 10 17:25:27 2015 +0200
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.
Signed-off-by: Michael Meeks <michael.meeks at collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/18488
(cherry picked from commits e576227d71788409110108281340005638f78bf1,
57fc41adc9292f8980bb8bbbb0d7983310fe6fe3 and
0e682d47a792497211d33779312ca2cad9874ffb)
Change-Id: Icfb9c65c871586b5df69b5a2ab3aa91843dfc799
Reviewed-on: https://gerrit.libreoffice.org/18492
Reviewed-by: Jan Holesovsky <kendy at collabora.com>
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/include/vcl/opengl/OpenGLContext.hxx b/include/vcl/opengl/OpenGLContext.hxx
index 259222a..dd96150 100644
--- a/include/vcl/opengl/OpenGLContext.hxx
+++ b/include/vcl/opengl/OpenGLContext.hxx
@@ -220,6 +220,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();
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index f8ccd93..4aee0f8 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -792,6 +792,12 @@ void OpenGLSalGraphicsImpl::DrawTrapezoid( const basegfx::B2DTrapezoid& trapezoi
aVertices[j+1] = GLfloat(rPt.getY());
}
+ if (!mpProgram)
+ {
+ SAL_WARN("vcl.opengl", "OpenGLSalGraphicsImpl::DrawTrapezoid: mpProgram is 0");
+ return;
+ }
+
ApplyProgramMatrices();
mpProgram->SetVertices( &aVertices[0] );
glDrawArrays( GL_TRIANGLE_FAN, 0, nPoints );
diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx
index ce09793..73ff51e 100644
--- a/vcl/source/opengl/OpenGLContext.cxx
+++ b/vcl/source/opengl/OpenGLContext.cxx
@@ -880,6 +880,8 @@ bool OpenGLContext::ImplInit()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+ registerAsCurrent();
+
return bRet;
}
@@ -1024,6 +1026,8 @@ bool OpenGLContext::ImplInit()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+ registerAsCurrent();
+
return true;
}
@@ -1446,8 +1450,6 @@ void OpenGLContext::prepareForYield()
void OpenGLContext::makeCurrent()
{
- ImplSVData* pSVData = ImplGetSVData();
-
if (isCurrent())
return;
@@ -1479,6 +1481,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 << " *********");
@@ -1751,6 +1760,13 @@ OpenGLProgram* OpenGLContext::UseProgram( const OUString& rVertexShader, const O
return pProgram;
mpCurrentProgram = pProgram;
+
+ if (!mpCurrentProgram)
+ {
+ SAL_WARN("vcl.opengl", "OpenGLContext::UseProgram: mpCurrentProgram is 0");
+ return 0;
+ }
+
mpCurrentProgram->Use();
return mpCurrentProgram;
diff --git a/vcl/win/source/app/salinst.cxx b/vcl/win/source/app/salinst.cxx
index d2fbb52..1c21246 100644
--- a/vcl/win/source/app/salinst.cxx
+++ b/vcl/win/source/app/salinst.cxx
@@ -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 );
}
More information about the Libreoffice-commits
mailing list