summaryrefslogtreecommitdiff
path: root/vcl/source/opengl/OpenGLHelper.cxx
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 /vcl/source/opengl/OpenGLHelper.cxx
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>
Diffstat (limited to 'vcl/source/opengl/OpenGLHelper.cxx')
-rw-r--r--vcl/source/opengl/OpenGLHelper.cxx48
1 files changed, 48 insertions, 0 deletions
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;