From bfceb557efcd607ef018ae35fc73f8d61a9b9a4e Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Wed, 16 Sep 2015 09:17:37 +0100 Subject: GL paint-flushing guard re-work. Unfortunately, since we can have 2x SalGraphics' on a OutputDevice, and one of these can be a printer - things got very confused around which context to glFlush. This de-tangles the various reference-counts. Change-Id: I1062be0b02a91fc9009deaa3ec29c5dbb227df20 Reviewed-on: https://gerrit.libreoffice.org/18604 Reviewed-by: Michael Meeks Tested-by: Michael Meeks --- vcl/source/opengl/OpenGLHelper.cxx | 46 +++++++++++++++++++++++++++++++++++++- vcl/source/outdev/outdev.cxx | 12 ---------- vcl/source/window/paint.cxx | 16 ++++--------- 3 files changed, 49 insertions(+), 25 deletions(-) (limited to 'vcl/source') diff --git a/vcl/source/opengl/OpenGLHelper.cxx b/vcl/source/opengl/OpenGLHelper.cxx index 5d4b8f77a9c1..114251ce24f4 100644 --- a/vcl/source/opengl/OpenGLHelper.cxx +++ b/vcl/source/opengl/OpenGLHelper.cxx @@ -32,7 +32,7 @@ #include #include "svdata.hxx" - +#include "salgdi.hxx" #include "salinst.hxx" #include "opengl/zone.hxx" #include "opengl/watchdog.hxx" @@ -1070,4 +1070,48 @@ GLXFBConfig OpenGLHelper::GetPixmapFBConfig( Display* pDisplay, bool& bInverted #endif +OutputDevice::PaintScope::PaintScope(OutputDevice *pDev) + : pHandle( NULL ) +{ + if( pDev->mpGraphics || pDev->AcquireGraphics() ) + { + OpenGLContext *pContext = pDev->mpGraphics->BeginPaint(); + if( pContext ) + { + assert( pContext->mnPainting >= 0 ); + pContext->mnPainting++; + pContext->acquire(); + pHandle = static_cast( pContext ); + } + } +} + +/** + * Flush all the queued rendering commands to the screen for this context. + */ +void OutputDevice::PaintScope::flush() +{ + if( pHandle ) + { + OpenGLContext *pContext = static_cast( pHandle ); + pHandle = NULL; + pContext->mnPainting--; + assert( pContext->mnPainting >= 0 ); + if( pContext->mnPainting == 0 ) + { + pContext->makeCurrent(); + pContext->AcquireDefaultFramebuffer(); + glFlush(); + pContext->swapBuffers(); + CHECK_GL_ERROR(); + } + pContext->release(); + } +} + +OutputDevice::PaintScope::~PaintScope() +{ + flush(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/outdev/outdev.cxx b/vcl/source/outdev/outdev.cxx index 17fa19607647..4f13a3d86902 100644 --- a/vcl/source/outdev/outdev.cxx +++ b/vcl/source/outdev/outdev.cxx @@ -845,16 +845,4 @@ bool OutputDevice::DrawEPS( const Point& rPoint, const Size& rSize, return bDrawn; } -void OutputDevice::BeginPaint() -{ - if( mpGraphics || AcquireGraphics() ) - mpGraphics->BeginPaint(); -} - -void OutputDevice::EndPaint() -{ - if( mpGraphics || AcquireGraphics() ) - mpGraphics->EndPaint(); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/window/paint.cxx b/vcl/source/window/paint.cxx index 429711ee7ab9..af1422756a7c 100644 --- a/vcl/source/window/paint.cxx +++ b/vcl/source/window/paint.cxx @@ -276,7 +276,7 @@ void PaintHelper::DoPaint(const vcl::Region* pRegion) VCL_GL_INFO("vcl.opengl", "PaintHelper::DoPaint on " << typeid( *m_pWindow ).name() << " '" << m_pWindow->GetText() << "' begin"); - m_pWindow->BeginPaint(); + OutputDevice::PaintScope aScope( m_pWindow ); // double-buffering: setup the buffer if it does not exist if (!pFrameData->mbInBufferedPaint && m_pWindow->SupportsDoubleBuffering()) @@ -306,8 +306,6 @@ void PaintHelper::DoPaint(const vcl::Region* pRegion) m_pWindow->Paint(*m_pWindow, m_aPaintRect); } - m_pWindow->EndPaint(); - VCL_GL_INFO("vcl.opengl", "PaintHelper::DoPaint end on " << typeid( *m_pWindow ).name() << " '" << m_pWindow->GetText() << "'"); } @@ -629,10 +627,8 @@ void Window::ImplCallOverlapPaint() { // - RTL - notify ImplCallPaint to check for re-mirroring (CHECKRTL) // because we were called from the Sal layer - OutputDevice *pOutDev = GetOutDev(); - pOutDev->BeginPaint(); + OutputDevice::PaintScope aScope( GetOutDev() ); ImplCallPaint(NULL, mpWindowImpl->mnPaintFlags /*| IMPL_PAINT_CHECKRTL */); - pOutDev->EndPaint(); } } @@ -651,7 +647,7 @@ IMPL_LINK_NOARG_TYPED(Window, ImplHandlePaintHdl, Idle *, void) return; } - BeginPaint(); + OutputDevice::PaintScope aScope(this); // save paint events until resizing or initial sizing done if (!ImplDoTiledRendering() && mpWindowImpl->mbFrame && @@ -664,15 +660,13 @@ IMPL_LINK_NOARG_TYPED(Window, ImplHandlePaintHdl, Idle *, void) { ImplCallOverlapPaint(); } - - EndPaint(); } IMPL_LINK_NOARG_TYPED(Window, ImplHandleResizeTimerHdl, Idle *, void) { if( mpWindowImpl->mbReallyVisible ) { - BeginPaint(); + OutputDevice::PaintScope aScope(this); ImplCallResize(); if( ImplDoTiledRendering() ) @@ -684,8 +678,6 @@ IMPL_LINK_NOARG_TYPED(Window, ImplHandleResizeTimerHdl, Idle *, void) mpWindowImpl->mpFrameData->maPaintIdle.Stop(); mpWindowImpl->mpFrameData->maPaintIdle.GetIdleHdl().Call( NULL ); } - - EndPaint(); } } -- cgit v1.2.3