Kaydet (Commit) 3538e039 authored tarafından Michael Meeks's avatar Michael Meeks

vcl: always re-use context from default window.

This avoids problems with the initial default context getting destroyed.

Change-Id: If465dfcd185a3336036b98cb2a205e0502d3f80b
Reviewed-on: https://gerrit.libreoffice.org/20796Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
Tested-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst 3119440a
...@@ -357,6 +357,7 @@ struct ImplSVData ...@@ -357,6 +357,7 @@ struct ImplSVData
void ImplDeInitSVData(); void ImplDeInitSVData();
VCL_PLUGIN_PUBLIC vcl::Window* ImplGetDefaultWindow(); VCL_PLUGIN_PUBLIC vcl::Window* ImplGetDefaultWindow();
VCL_PLUGIN_PUBLIC vcl::Window* ImplGetDefaultContextWindow();
VCL_PLUGIN_PUBLIC ResMgr* ImplGetResMgr(); VCL_PLUGIN_PUBLIC ResMgr* ImplGetResMgr();
VCL_PLUGIN_PUBLIC ResId VclResId( sal_Int32 nId ); // throws std::bad_alloc if no res mgr VCL_PLUGIN_PUBLIC ResId VclResId( sal_Int32 nId ); // throws std::bad_alloc if no res mgr
DockingManager* ImplGetDockingManager(); DockingManager* ImplGetDockingManager();
......
...@@ -121,6 +121,8 @@ bool OpenGLSalGraphicsImpl::AcquireContext( bool bForceCreate ) ...@@ -121,6 +121,8 @@ bool OpenGLSalGraphicsImpl::AcquireContext( bool bForceCreate )
mpContext.clear(); mpContext.clear();
} }
// We don't care what context we have - but not switching context
// is rather useful from a performance perspective.
OpenGLContext *pContext = pSVData->maGDIData.mpLastContext; OpenGLContext *pContext = pSVData->maGDIData.mpLastContext;
while( pContext ) while( pContext )
{ {
...@@ -181,7 +183,10 @@ void OpenGLSalGraphicsImpl::Init() ...@@ -181,7 +183,10 @@ void OpenGLSalGraphicsImpl::Init()
} }
if( mpWindowContext.is() ) if( mpWindowContext.is() )
{
mpWindowContext->reset(); mpWindowContext->reset();
mpWindowContext.clear();
}
} }
// Currently only used to get windows ordering right. // Currently only used to get windows ordering right.
...@@ -193,8 +198,11 @@ void OpenGLSalGraphicsImpl::DeInit() ...@@ -193,8 +198,11 @@ void OpenGLSalGraphicsImpl::DeInit()
// let it know. Other eg. VirtualDevice contexts which have // let it know. Other eg. VirtualDevice contexts which have
// references on and rely on this context continuing to work will // references on and rely on this context continuing to work will
// get a shiny new context in AcquireContext:: next PreDraw. // get a shiny new context in AcquireContext:: next PreDraw.
if( mpContext.is() && !IsOffscreen() ) if( mpWindowContext.is() )
mpContext->reset(); {
mpWindowContext->reset();
mpWindowContext.clear();
}
mpContext.clear(); mpContext.clear();
} }
......
...@@ -113,23 +113,25 @@ void ImplDeInitSVData() ...@@ -113,23 +113,25 @@ void ImplDeInitSVData()
delete pSVData->mpPaperNames, pSVData->mpPaperNames = nullptr; delete pSVData->mpPaperNames, pSVData->mpPaperNames = nullptr;
} }
/// Returns either the application window, or the default GL context window
vcl::Window* ImplGetDefaultWindow() vcl::Window* ImplGetDefaultWindow()
{ {
ImplSVData* pSVData = ImplGetSVData(); ImplSVData* pSVData = ImplGetSVData();
if ( pSVData->maWinData.mpAppWin ) if ( pSVData->maWinData.mpAppWin )
return pSVData->maWinData.mpAppWin; return pSVData->maWinData.mpAppWin;
else
return ImplGetDefaultContextWindow();
}
// First test if we already have a default window. /// returns the default window created to hold the persistent VCL GL context.
// Don't only place a single if..else inside solar mutex lockframe vcl::Window *ImplGetDefaultContextWindow()
// because then we might have to wait for the solar mutex what is not necessary {
// if we already have a default window. ImplSVData* pSVData = ImplGetSVData();
// Double check locking on mpDefaultWin.
if ( !pSVData->mpDefaultWin ) if ( !pSVData->mpDefaultWin )
{ {
Application::GetSolarMutex().acquire(); SolarMutexGuard aGuard;
// Test again because the thread who released the solar mutex could have called
// the same method
if ( !pSVData->mpDefaultWin && !pSVData->mbDeInit ) if ( !pSVData->mpDefaultWin && !pSVData->mbDeInit )
{ {
...@@ -142,7 +144,6 @@ vcl::Window* ImplGetDefaultWindow() ...@@ -142,7 +144,6 @@ vcl::Window* ImplGetDefaultWindow()
if( pContext.is() ) if( pContext.is() )
pContext->acquire(); pContext->acquire();
} }
Application::GetSolarMutex().release();
} }
return pSVData->mpDefaultWin; return pSVData->mpDefaultWin;
......
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