summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2015-08-20 17:03:30 +0100
committerMichael Meeks <michael.meeks@collabora.com>2015-08-21 06:43:48 +0000
commitd20e7e38641868bf14041f090b3668e0148904c7 (patch)
tree591de5cf0e45281ac1eb02b516ed29f578312012
parent5a2d6bf3a94f127307d6a9464033b2226508ff38 (diff)
tdf#93547 - Disable OpenGL if we have a SEGV on windows in that code.
Annotate when we are in an OpenGL rendering zone. Check for this in the VCL signal handler, and force OpenGL off here if exception occurred inside an OpenGL code-path. Change-Id: I85a4b3d4a374593dc55d01a39ec4c7c3c262c332 Reviewed-on: https://gerrit.libreoffice.org/17881 Reviewed-by: Michael Meeks <michael.meeks@collabora.com> Tested-by: Michael Meeks <michael.meeks@collabora.com>
-rw-r--r--vcl/inc/opengl/zone.hxx34
-rw-r--r--vcl/opengl/gdiimpl.cxx42
-rw-r--r--vcl/opengl/salbmp.cxx15
-rw-r--r--vcl/opengl/scale.cxx3
-rw-r--r--vcl/source/app/svmain.cxx6
-rw-r--r--vcl/source/opengl/OpenGLContext.cxx54
-rw-r--r--vcl/source/opengl/OpenGLHelper.cxx48
7 files changed, 202 insertions, 0 deletions
diff --git a/vcl/inc/opengl/zone.hxx b/vcl/inc/opengl/zone.hxx
new file mode 100644
index 000000000000..c251c4fa85d8
--- /dev/null
+++ b/vcl/inc/opengl/zone.hxx
@@ -0,0 +1,34 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_GUARD_H
+#define INCLUDED_VCL_INC_OPENGL_GUARD_H
+
+#include <sal/config.h>
+
+/**
+ * We want to be able to detect if a given crash came
+ * from the OpenGL code, so use this helper to track that.
+ */
+class OpenGLSalGraphicsImpl;
+class OpenGLZone {
+ static int gnInOpenGLZone;
+ friend class OpenGLSalGraphicsImpl;
+ static void enter() { gnInOpenGLZone++; }
+ static void leave() { gnInOpenGLZone--; }
+public:
+ OpenGLZone() { enter(); }
+ ~OpenGLZone() { leave(); }
+ static bool isInZone() { return gnInOpenGLZone > 0; }
+ static void hardDisable();
+};
+
+#endif // INCLUDED_VCL_INC_OPENGL_PROGRAM_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index 02c69fa99e06..6a8c58881893 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -32,6 +32,7 @@
#include <vcl/opengl/OpenGLHelper.hxx>
#include "salgdi.hxx"
#include "svdata.hxx"
+#include "opengl/zone.hxx"
#include "opengl/salbmp.hxx"
#include <vector>
@@ -150,6 +151,8 @@ void OpenGLSalGraphicsImpl::Init()
void OpenGLSalGraphicsImpl::PreDraw()
{
+ OpenGLZone::enter();
+
if( !AcquireContext() )
{
SAL_WARN( "vcl.opengl", "Couldn't acquire context" );
@@ -189,6 +192,7 @@ void OpenGLSalGraphicsImpl::PostDraw()
}
CHECK_GL_ERROR();
+ OpenGLZone::leave();
}
void OpenGLSalGraphicsImpl::ApplyProgramMatrices(float fPixelOffset)
@@ -445,6 +449,8 @@ bool OpenGLSalGraphicsImpl::UseSolidAA( SalColor nColor )
bool OpenGLSalGraphicsImpl::UseInvert()
{
+ OpenGLZone aZone;
+
if( !UseSolid( MAKE_SALCOLOR( 255, 255, 255 ) ) )
return false;
mpProgram->SetBlendMode( GL_ONE_MINUS_DST_COLOR, GL_ZERO );
@@ -453,6 +459,8 @@ bool OpenGLSalGraphicsImpl::UseInvert()
void OpenGLSalGraphicsImpl::DrawPoint( long nX, long nY )
{
+ OpenGLZone aZone;
+
GLfloat pPoint[2];
pPoint[0] = GLfloat(nX);
@@ -467,6 +475,8 @@ void OpenGLSalGraphicsImpl::DrawPoint( long nX, long nY )
void OpenGLSalGraphicsImpl::DrawLine( double nX1, double nY1, double nX2, double nY2 )
{
+ OpenGLZone aZone;
+
GLfloat pPoints[4];
pPoints[0] = GLfloat(nX1);
@@ -483,6 +493,8 @@ void OpenGLSalGraphicsImpl::DrawLine( double nX1, double nY1, double nX2, double
void OpenGLSalGraphicsImpl::DrawLineAA( double nX1, double nY1, double nX2, double nY2 )
{
+ OpenGLZone aZone;
+
if( !mrParent.getAntiAliasB2DDraw())
return DrawLine( nX1, nY1, nX2, nY2 );
@@ -658,6 +670,8 @@ void OpenGLSalGraphicsImpl::DrawEdgeAA( double nX1, double nY1, double nX2, doub
void OpenGLSalGraphicsImpl::DrawConvexPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry, bool blockAA )
{
+ OpenGLZone aZone;
+
std::vector<GLfloat> aVertices(nPoints * 2);
sal_uInt32 i, j;
@@ -699,6 +713,8 @@ void OpenGLSalGraphicsImpl::DrawConvexPolygon( sal_uInt32 nPoints, const SalPoin
void OpenGLSalGraphicsImpl::DrawConvexPolygon( const tools::Polygon& rPolygon, bool blockAA )
{
+ OpenGLZone aZone;
+
sal_uInt16 nPoints = rPolygon.GetSize() - 1;
std::vector<GLfloat> aVertices(nPoints * 2);
sal_uInt32 i, j;
@@ -742,6 +758,8 @@ void OpenGLSalGraphicsImpl::DrawConvexPolygon( const tools::Polygon& rPolygon, b
void OpenGLSalGraphicsImpl::DrawTrapezoid( const basegfx::B2DTrapezoid& trapezoid, bool blockAA )
{
+ OpenGLZone aZone;
+
const basegfx::B2DPolygon& rPolygon = trapezoid.getB2DPolygon();
sal_uInt16 nPoints = rPolygon.count();
std::vector<GLfloat> aVertices(nPoints * 2);
@@ -843,6 +861,8 @@ void OpenGLSalGraphicsImpl::DrawPolyPolygon( const basegfx::B2DPolyPolygon& rPol
void OpenGLSalGraphicsImpl::DrawRegionBand( const RegionBand& rRegion )
{
+ OpenGLZone aZone;
+
RectangleVector aRects;
std::vector<GLfloat> aVertices;
rRegion.GetRegionRectangles( aRects );
@@ -876,6 +896,8 @@ void OpenGLSalGraphicsImpl::DrawRegionBand( const RegionBand& rRegion )
void OpenGLSalGraphicsImpl::DrawTextureRect( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted )
{
+ OpenGLZone aZone;
+
GLfloat aTexCoord[8];
rTexture.GetCoord( aTexCoord, rPosAry, bInverted );
mpProgram->SetTextureCoord( aTexCoord );
@@ -884,6 +906,8 @@ void OpenGLSalGraphicsImpl::DrawTextureRect( OpenGLTexture& rTexture, const SalT
void OpenGLSalGraphicsImpl::DrawTexture( OpenGLTexture& rTexture, const SalTwoRect& pPosAry, bool bInverted )
{
+ OpenGLZone aZone;
+
if( !UseProgram( "textureVertexShader", "textureFragmentShader" ) )
return;
mpProgram->SetTexture( "sampler", rTexture );
@@ -898,6 +922,8 @@ void OpenGLSalGraphicsImpl::DrawTransformedTexture(
const basegfx::B2DPoint& rX,
const basegfx::B2DPoint& rY )
{
+ OpenGLZone aZone;
+
GLfloat aVertices[8] = {
0, (float) rTexture.GetHeight(), 0, 0,
(float) rTexture.GetWidth(), 0, (float) rTexture.GetWidth(), (float) rTexture.GetHeight() };
@@ -986,6 +1012,8 @@ void OpenGLSalGraphicsImpl::DrawTransformedTexture(
void OpenGLSalGraphicsImpl::DrawAlphaTexture( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted, bool bPremultiplied )
{
+ OpenGLZone aZone;
+
if( !UseProgram( "textureVertexShader", "textureFragmentShader" ) )
return;
mpProgram->SetTexture( "sampler", rTexture );
@@ -997,6 +1025,8 @@ void OpenGLSalGraphicsImpl::DrawAlphaTexture( OpenGLTexture& rTexture, const Sal
void OpenGLSalGraphicsImpl::DrawTextureDiff( OpenGLTexture& rTexture, OpenGLTexture& rMask, const SalTwoRect& rPosAry, bool bInverted )
{
+ OpenGLZone aZone;
+
if( !UseProgram( "textureVertexShader", "diffTextureFragmentShader" ) )
return;
mpProgram->SetTexture( "texture", rTexture );
@@ -1008,6 +1038,8 @@ void OpenGLSalGraphicsImpl::DrawTextureDiff( OpenGLTexture& rTexture, OpenGLText
void OpenGLSalGraphicsImpl::DrawTextureWithMask( OpenGLTexture& rTexture, OpenGLTexture& rMask, const SalTwoRect& pPosAry )
{
+ OpenGLZone aZone;
+
if( !UseProgram( "textureVertexShader", "maskedTextureFragmentShader" ) )
return;
mpProgram->SetTexture( "sampler", rTexture );
@@ -1019,6 +1051,8 @@ void OpenGLSalGraphicsImpl::DrawTextureWithMask( OpenGLTexture& rTexture, OpenGL
void OpenGLSalGraphicsImpl::DrawBlendedTexture( OpenGLTexture& rTexture, OpenGLTexture& rMask, OpenGLTexture& rAlpha, const SalTwoRect& rPosAry )
{
+ OpenGLZone aZone;
+
GLfloat aTexCoord[8];
if( !UseProgram( "blendedTextureVertexShader", "blendedTextureFragmentShader" ) )
return;
@@ -1034,6 +1068,8 @@ void OpenGLSalGraphicsImpl::DrawBlendedTexture( OpenGLTexture& rTexture, OpenGLT
void OpenGLSalGraphicsImpl::DrawMask( OpenGLTexture& rMask, SalColor nMaskColor, const SalTwoRect& pPosAry )
{
+ OpenGLZone aZone;
+
if( !UseProgram( "textureVertexShader", "maskFragmentShader" ) )
return;
mpProgram->SetColor( "color", nMaskColor, 0 );
@@ -1045,6 +1081,8 @@ void OpenGLSalGraphicsImpl::DrawMask( OpenGLTexture& rMask, SalColor nMaskColor,
void OpenGLSalGraphicsImpl::DrawLinearGradient( const Gradient& rGradient, const Rectangle& rRect )
{
+ OpenGLZone aZone;
+
if( !UseProgram( "textureVertexShader", "linearGradientFragmentShader" ) )
return;
Color aStartCol = rGradient.GetStartColor();
@@ -1069,6 +1107,8 @@ void OpenGLSalGraphicsImpl::DrawLinearGradient( const Gradient& rGradient, const
void OpenGLSalGraphicsImpl::DrawAxialGradient( const Gradient& rGradient, const Rectangle& rRect )
{
+ OpenGLZone aZone;
+
if( !UseProgram( "textureVertexShader", "linearGradientFragmentShader" ) )
return;
Color aStartCol = rGradient.GetStartColor();
@@ -1119,6 +1159,8 @@ void OpenGLSalGraphicsImpl::DrawAxialGradient( const Gradient& rGradient, const
void OpenGLSalGraphicsImpl::DrawRadialGradient( const Gradient& rGradient, const Rectangle& rRect )
{
+ OpenGLZone aZone;
+
if( !UseProgram( "textureVertexShader", "radialGradientFragmentShader" ) )
return;
Color aStartCol = rGradient.GetStartColor();
diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx
index 6b6f7bc09ed2..b5e515418ac8 100644
--- a/vcl/opengl/salbmp.cxx
+++ b/vcl/opengl/salbmp.cxx
@@ -27,6 +27,7 @@
#include "svdata.hxx"
#include "salgdi.hxx"
+#include "opengl/zone.hxx"
#include "opengl/program.hxx"
#include "opengl/salbmp.hxx"
@@ -56,6 +57,7 @@ OpenGLSalBitmap::~OpenGLSalBitmap()
bool OpenGLSalBitmap::Create( const OpenGLTexture& rTex, long nX, long nY, long nWidth, long nHeight )
{
static const BitmapPalette aEmptyPalette;
+ OpenGLZone aZone;
Destroy();
SAL_INFO( "vcl.opengl", "OpenGLSalBitmap::Create from FBO: [" << nX << ", " << nY << "] " << nWidth << "x" << nHeight );
@@ -81,6 +83,8 @@ bool OpenGLSalBitmap::Create( const OpenGLTexture& rTex, long nX, long nY, long
bool OpenGLSalBitmap::Create( const Size& rSize, sal_uInt16 nBits, const BitmapPalette& rBitmapPalette )
{
+ OpenGLZone aZone;
+
Destroy();
SAL_INFO( "vcl.opengl", "OpenGLSalBitmap::Create with size: " << rSize );
@@ -105,6 +109,8 @@ bool OpenGLSalBitmap::Create( const SalBitmap& rSalBmp, SalGraphics* pGraphics )
bool OpenGLSalBitmap::Create( const SalBitmap& rSalBmp, sal_uInt16 nNewBitCount )
{
+ OpenGLZone aZone;
+
// check that carefully only in the debug mode
assert(dynamic_cast<const OpenGLSalBitmap*>(&rSalBmp));
@@ -152,6 +158,8 @@ OpenGLTexture& OpenGLSalBitmap::GetTexture() const
void OpenGLSalBitmap::Destroy()
{
+ OpenGLZone aZone;
+
SAL_INFO( "vcl.opengl", "Destroy OpenGLSalBitmap" );
maPendingOps.clear();
maTexture = OpenGLTexture();
@@ -310,6 +318,8 @@ ImplPixelFormat* ImplPixelFormat::GetFormat( sal_uInt16 nBits, const BitmapPalet
Size OpenGLSalBitmap::GetSize() const
{
+ OpenGLZone aZone;
+
std::deque< OpenGLSalBitmapOp* >::const_iterator it = maPendingOps.begin();
Size aSize( mnWidth, mnHeight );
@@ -484,6 +494,7 @@ void OpenGLSalBitmap::makeCurrent()
BitmapBuffer* OpenGLSalBitmap::AcquireBuffer( BitmapAccessMode nMode )
{
+ OpenGLZone aZone;
if( nMode != BITMAP_INFO_ACCESS )
{
@@ -529,6 +540,8 @@ BitmapBuffer* OpenGLSalBitmap::AcquireBuffer( BitmapAccessMode nMode )
void OpenGLSalBitmap::ReleaseBuffer( BitmapBuffer* pBuffer, BitmapAccessMode nMode )
{
+ OpenGLZone aZone;
+
if( nMode == BITMAP_WRITE_ACCESS )
{
maTexture = OpenGLTexture();
@@ -581,6 +594,8 @@ bool OpenGLSalBitmap::GetSystemData( BitmapSystemData& /*rData*/ )
bool OpenGLSalBitmap::Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol )
{
+ OpenGLZone aZone;
+
OpenGLFramebuffer* pFramebuffer;
OpenGLProgram* pProgram;
diff --git a/vcl/opengl/scale.cxx b/vcl/opengl/scale.cxx
index 0b2d5cf3b2a8..93a3eee2dea3 100644
--- a/vcl/opengl/scale.cxx
+++ b/vcl/opengl/scale.cxx
@@ -23,6 +23,7 @@
#include "vcl/bitmap.hxx"
+#include "opengl/zone.hxx"
#include "opengl/bmpop.hxx"
#include "opengl/salbmp.hxx"
#include "opengl/program.hxx"
@@ -373,6 +374,8 @@ void ScaleOp::GetSize( Size& rSize ) const
bool OpenGLSalBitmap::Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag )
{
+ OpenGLZone aZone;
+
SAL_INFO("vcl.opengl", "::Scale " << int(nScaleFlag)
<< " from " << mnWidth << "x" << mnHeight
<< " to " << (mnWidth * rScaleX) << "x" << (mnHeight * rScaleY) );
diff --git a/vcl/source/app/svmain.cxx b/vcl/source/app/svmain.cxx
index 3f9026ed976e..7b6c778f3972 100644
--- a/vcl/source/app/svmain.cxx
+++ b/vcl/source/app/svmain.cxx
@@ -81,6 +81,8 @@
#include "cppuhelper/implbase1.hxx"
#include "uno/current_context.hxx"
+#include "opengl/zone.hxx"
+
#if OSL_DEBUG_LEVEL > 0
#include <typeinfo>
#include "rtl/strbuf.hxx"
@@ -102,7 +104,11 @@ oslSignalAction SAL_CALL VCLExceptionSignal_impl( void* /*pData*/, oslSignalInfo
(pInfo->Signal == osl_Signal_IntegerDivideByZero) ||
(pInfo->Signal == osl_Signal_FloatDivideByZero) ||
(pInfo->Signal == osl_Signal_DebugBreak) )
+ {
nVCLException = EXC_SYSTEM;
+ if (OpenGLZone::isInZone())
+ OpenGLZone::hardDisable();
+ }
// RC
if ((pInfo->Signal == osl_Signal_User) &&
diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx
index 051b151e8cef..6cc7aed60587 100644
--- a/vcl/source/opengl/OpenGLContext.cxx
+++ b/vcl/source/opengl/OpenGLContext.cxx
@@ -34,6 +34,7 @@
#include <opengl/framebuffer.hxx>
#include <opengl/program.hxx>
#include <opengl/texture.hxx>
+#include <opengl/zone.hxx>
using namespace com::sun::star;
@@ -70,6 +71,7 @@ OpenGLContext::OpenGLContext():
mpNextContext(NULL)
{
SAL_INFO("vcl.opengl", "new context: " << this);
+
#if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID && !defined(LIBO_HEADLESS)
mbPixmap = false;
#endif
@@ -180,6 +182,8 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM l
int InitTempWindow(HWND *hwnd, int width, int height, const PIXELFORMATDESCRIPTOR& inPfd, GLWindow& glWin)
{
+ OpenGLZone aZone;
+
PIXELFORMATDESCRIPTOR pfd = inPfd;
int pfmt;
int ret;
@@ -223,6 +227,8 @@ int InitTempWindow(HWND *hwnd, int width, int height, const PIXELFORMATDESCRIPTO
bool WGLisExtensionSupported(const char *extension)
{
+ OpenGLZone aZone;
+
const size_t extlen = strlen(extension);
const char *supported = NULL;
@@ -261,6 +267,8 @@ bool WGLisExtensionSupported(const char *extension)
bool InitMultisample(const PIXELFORMATDESCRIPTOR& pfd, int& rPixelFormat,
bool bUseDoubleBufferedRendering, bool bRequestVirtualDevice)
{
+ OpenGLZone aZone;
+
HWND hWnd = NULL;
GLWindow glWin;
// Create a temp window to check whether support multi-sample, if support, get the format
@@ -509,6 +517,8 @@ int oglErrorHandler( Display* /*dpy*/, XErrorEvent* /*evnt*/ )
GLXFBConfig* getFBConfig(Display* dpy, Window win, int& nBestFBC, bool bUseDoubleBufferedRendering, bool bWithSameVisualID)
{
+ OpenGLZone aZone;
+
if( dpy == 0 || !glXQueryExtension( dpy, NULL, NULL ) )
return NULL;
@@ -589,6 +599,8 @@ void initOpenGLFunctionPointers()
Visual* getVisual(Display* dpy, Window win)
{
+ OpenGLZone aZone;
+
initOpenGLFunctionPointers();
XWindowAttributes xattr;
@@ -610,6 +622,8 @@ bool OpenGLContext::init( vcl::Window* pParent )
if(mbInitialized)
return true;
+ OpenGLZone aZone;
+
m_xWindow.reset(pParent ? nullptr : VclPtr<vcl::Window>::Create(nullptr, WB_NOBORDER|WB_NODIALOGCONTROL));
mpWindow = pParent ? pParent : m_xWindow.get();
if(m_xWindow)
@@ -627,6 +641,8 @@ bool OpenGLContext::init(SystemChildWindow* pChildWindow)
if( !pChildWindow )
return false;
+ OpenGLZone aZone;
+
mpWindow = pChildWindow->GetParent();
m_pChildWindow = pChildWindow;
initWindow();
@@ -642,6 +658,8 @@ bool OpenGLContext::init(Display* dpy, Window win, int screen)
if (!dpy)
return false;
+ OpenGLZone aZone;
+
m_aGLWin.dpy = dpy;
m_aGLWin.win = win;
m_aGLWin.screen = screen;
@@ -662,6 +680,8 @@ bool OpenGLContext::ImplInit()
return false;
}
+ OpenGLZone aZone;
+
GLXContext pSharedCtx( NULL );
#ifdef DBG_UTIL
TempErrorHandler aErrorHandler(m_aGLWin.dpy, unxErrorHandler);
@@ -790,6 +810,8 @@ bool OpenGLContext::init(HDC hDC, HWND hWnd)
bool OpenGLContext::ImplInit()
{
+ OpenGLZone aZone;
+
SAL_INFO("vcl.opengl", "OpenGLContext::ImplInit----start");
// PixelFormat tells Windows how we want things to be
PIXELFORMATDESCRIPTOR PixelFormatFront =
@@ -917,6 +939,8 @@ bool OpenGLContext::ImplInit()
bool OpenGLContext::ImplInit()
{
+ OpenGLZone aZone;
+
SAL_INFO("vcl.opengl", "OpenGLContext::ImplInit----start");
NSOpenGLView* pView = getOpenGLView();
OpenGLWrapper::makeCurrent(pView);
@@ -941,6 +965,8 @@ bool OpenGLContext::InitGLEW()
static bool bGlewInit = false;
if(!bGlewInit)
{
+ OpenGLZone aZone;
+
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (err != GLEW_OK)
@@ -963,6 +989,8 @@ void OpenGLContext::InitGLEWDebugging()
// only enable debug output in dbgutil build
if( GLEW_ARB_debug_output)
{
+ OpenGLZone aZone;
+
if (glDebugMessageCallbackARB)
{
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
@@ -1096,6 +1124,8 @@ bool OpenGLContext::initWindow()
void OpenGLContext::initGLWindow(Visual* pVisual)
{
+ OpenGLZone aZone;
+
// Get visual info
{
XVisualInfo aTemplate;
@@ -1126,6 +1156,8 @@ void OpenGLContext::reset()
if( !mbInitialized )
return;
+ OpenGLZone aZone;
+
// reset the clip region
maClipRegion.SetEmpty();
@@ -1212,6 +1244,8 @@ SystemWindowData OpenGLContext::generateWinData(vcl::Window* /*pParent*/, bool b
SystemWindowData OpenGLContext::generateWinData(vcl::Window* pParent, bool)
{
+ OpenGLZone aZone;
+
SystemWindowData aWinData;
aWinData.nSize = sizeof(aWinData);
aWinData.pVisual = NULL;
@@ -1253,6 +1287,8 @@ SystemWindowData OpenGLContext::generateWinData(vcl::Window* pParent, bool)
bool OpenGLContext::isCurrent()
{
+ OpenGLZone aZone;
+
#if defined( WNT )
return (wglGetCurrentContext() == m_aGLWin.hRC &&
wglGetCurrentDC() == m_aGLWin.hDC);
@@ -1286,6 +1322,8 @@ void OpenGLContext::makeCurrent()
if (isCurrent())
return;
+ OpenGLZone aZone;
+
clearCurrent();
#if defined( WNT )
@@ -1334,6 +1372,8 @@ void OpenGLContext::resetCurrent()
{
clearCurrent();
+ OpenGLZone aZone;
+
#if defined( WNT )
wglMakeCurrent( m_aGLWin.hDC, 0 );
#elif defined( MACOSX )
@@ -1348,6 +1388,8 @@ void OpenGLContext::resetCurrent()
void OpenGLContext::swapBuffers()
{
+ OpenGLZone aZone;
+
#if defined( WNT )
SwapBuffers(m_aGLWin.hDC);
#elif defined( MACOSX )
@@ -1362,6 +1404,8 @@ void OpenGLContext::swapBuffers()
void OpenGLContext::sync()
{
+ OpenGLZone aZone;
+
#if defined( WNT )
// nothing
#elif defined( MACOSX ) || defined( IOS ) || defined( ANDROID ) || defined(LIBO_HEADLESS)
@@ -1405,6 +1449,8 @@ NSOpenGLView* OpenGLContext::getOpenGLView()
bool OpenGLContext::BindFramebuffer( OpenGLFramebuffer* pFramebuffer )
{
+ OpenGLZone aZone;
+
if( pFramebuffer != mpCurrentFramebuffer )
{
if( pFramebuffer )
@@ -1424,6 +1470,8 @@ bool OpenGLContext::AcquireDefaultFramebuffer()
OpenGLFramebuffer* OpenGLContext::AcquireFramebuffer( const OpenGLTexture& rTexture )
{
+ OpenGLZone aZone;
+
OpenGLFramebuffer* pFramebuffer = NULL;
OpenGLFramebuffer* pFreeFbo = NULL;
OpenGLFramebuffer* pSameSizeFbo = NULL;
@@ -1490,6 +1538,7 @@ void OpenGLContext::ReleaseFramebuffer( OpenGLFramebuffer* pFramebuffer )
void OpenGLContext::ReleaseFramebuffer( const OpenGLTexture& rTexture )
{
+ OpenGLZone aZone;
OpenGLFramebuffer* pFramebuffer = mpLastFramebuffer;
while( pFramebuffer )
@@ -1505,6 +1554,7 @@ void OpenGLContext::ReleaseFramebuffer( const OpenGLTexture& rTexture )
void OpenGLContext::ReleaseFramebuffers()
{
+ OpenGLZone aZone;
OpenGLFramebuffer* pFramebuffer = mpLastFramebuffer;
while( pFramebuffer )
{
@@ -1519,6 +1569,8 @@ void OpenGLContext::ReleaseFramebuffers()
OpenGLProgram* OpenGLContext::GetProgram( const OUString& rVertexShader, const OUString& rFragmentShader, const OString& preamble )
{
+ OpenGLZone aZone;
+
ProgramKey aKey( rVertexShader, rFragmentShader, preamble );
std::map< ProgramKey, boost::shared_ptr<OpenGLProgram> >::iterator
@@ -1536,6 +1588,8 @@ OpenGLProgram* OpenGLContext::GetProgram( const OUString& rVertexShader, const O
OpenGLProgram* OpenGLContext::UseProgram( const OUString& rVertexShader, const OUString& rFragmentShader, const OString& preamble )
{
+ OpenGLZone aZone;
+
OpenGLProgram* pProgram = GetProgram( rVertexShader, rFragmentShader, preamble );
if( pProgram == mpCurrentProgram )
diff --git a/vcl/source/opengl/OpenGLHelper.cxx b/vcl/source/opengl/OpenGLHelper.cxx
index 628409a65c03..49bff4923813 100644
--- a/vcl/source/opengl/OpenGLHelper.cxx
+++ b/vcl/source/opengl/OpenGLHelper.cxx
@@ -20,9 +20,13 @@
#include <vcl/graph.hxx>
#include <vcl/svapp.hxx>
#include <officecfg/Office/Common.hxx>
+#include <com/sun/star/util/XFlushable.hpp>
+#include <com/sun/star/configuration/theDefaultProvider.hpp>
#include <vector>
+#include "opengl/zone.hxx"
+
#if defined UNX && !defined MACOSX && !defined IOS && !defined ANDROID
#include "opengl/x11/X11DeviceInfo.hxx"
#elif defined (_WIN32)
@@ -68,6 +72,8 @@ namespace {
int LogCompilerError(GLuint nId, const rtl::OUString &rDetail,
const rtl::OUString &rName, bool bShaderNotProgram)
{
+ OpenGLZone aZone;
+
int InfoLogLength = 0;
CHECK_GL_ERROR();
@@ -127,6 +133,8 @@ static void addPreamble(OString& rShaderSource, const OString& rPreamble)
GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName,const OUString& rFragmentShaderName, const OString& preamble)
{
+ OpenGLZone aZone;
+
// Create the shaders
GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
@@ -205,6 +213,8 @@ void OpenGLHelper::ConvertBitmapExToRGBATextureBuffer(const BitmapEx& rBitmapEx,
void OpenGLHelper::renderToFile(long nWidth, long nHeight, const OUString& rFileName)
{
+ OpenGLZone aZone;
+
std::unique_ptr<sal_uInt8[]> pBuffer(new sal_uInt8[nWidth*nHeight*4]);
glReadPixels(0, 0, nWidth, nHeight, GL_BGRA, GL_UNSIGNED_BYTE, pBuffer.get());
BitmapEx aBitmap = ConvertBGRABufferToBitmapEx(pBuffer.get(), nWidth, nHeight);
@@ -312,6 +322,8 @@ std::ostream& operator<<(std::ostream& rStrm, const glm::mat4& rMatrix)
void OpenGLHelper::createFramebuffer(long nWidth, long nHeight, GLuint& nFramebufferId,
GLuint& nRenderbufferDepthId, GLuint& nRenderbufferColorId, bool bRenderbuffer)
{
+ OpenGLZone aZone;
+
// create a renderbuffer for depth attachment
glGenRenderbuffers(1, &nRenderbufferDepthId);
glBindRenderbuffer(GL_RENDERBUFFER, nRenderbufferDepthId);
@@ -383,6 +395,8 @@ float OpenGLHelper::getGLVersion()
void OpenGLHelper::checkGLError(const char* pFile, size_t nLine)
{
+ OpenGLZone aZone;
+
GLenum glErr = glGetError();
if (glErr != GL_NO_ERROR)
{
@@ -403,6 +417,8 @@ bool OpenGLHelper::isDeviceBlacklisted()
static bool bBlacklisted = true; // assume the worst
if (!bSet)
{
+ OpenGLZone aZone;
+
#if defined UNX && !defined MACOSX && !defined IOS && !defined ANDROID
X11OpenGLDeviceInfo aInfo;
bBlacklisted = aInfo.isDeviceBlocked();
@@ -430,6 +446,34 @@ bool OpenGLHelper::supportsVCLOpenGL()
return true;
}
+/// How many nested OpenGL code-paths are we inside ?
+int OpenGLZone::gnInOpenGLZone = 0;
+
+/**
+ * Called from a signal handler if we get a crash in some GL code
+ */
+void OpenGLZone::hardDisable()
+{
+ // protect ourselves from double calling etc.
+ static bool bDisabled = false;
+ if (!bDisabled)
+ {
+ bDisabled = true;
+
+ // Disable the OpenGL support
+ std::shared_ptr<comphelper::ConfigurationChanges> xChanges(
+ comphelper::ConfigurationChanges::create());
+ officecfg::Office::Common::VCL::UseOpenGL::set(false, xChanges);
+ xChanges->commit();
+
+ // Force synchronous config write
+ css::uno::Reference< css::util::XFlushable >(
+ css::configuration::theDefaultProvider::get(
+ comphelper::getProcessComponentContext()),
+ css::uno::UNO_QUERY_THROW)->flush();
+ }
+}
+
bool OpenGLHelper::isVCLOpenGLEnabled()
{
/**
@@ -483,6 +527,8 @@ bool OpenGLHelper::isVCLOpenGLEnabled()
bool OpenGLHelper::GetVisualInfo(Display* pDisplay, int nScreen, XVisualInfo& rVI)
{
+ OpenGLZone aZone;
+
XVisualInfo* pVI;
int aAttrib[] = { GLX_RGBA,
GLX_RED_SIZE, 8,
@@ -505,6 +551,8 @@ bool OpenGLHelper::GetVisualInfo(Display* pDisplay, int nScreen, XVisualInfo& rV
GLXFBConfig OpenGLHelper::GetPixmapFBConfig( Display* pDisplay, bool& bInverted )
{
+ OpenGLZone aZone;
+
int nScreen = DefaultScreen( pDisplay );
GLXFBConfig *aFbConfigs;
int i, nFbConfigs, nValue;