[Libreoffice-commits] core.git: Branch 'feature/fixes7' - 4 commits - vcl/inc vcl/Library_vcl.mk vcl/opengl vcl/Package_opengl.mk vcl/source
Tomaž Vajngerl
tomaz.vajngerl at collabora.co.uk
Mon Aug 24 03:33:49 PDT 2015
vcl/Library_vcl.mk | 1
vcl/Package_opengl.mk | 1
vcl/inc/opengl/FixedTextureAtlas.hxx | 39 +++++++++
vcl/inc/opengl/program.hxx | 2
vcl/inc/opengl/texture.hxx | 43 ++++++++++
vcl/inc/opengl/zone.hxx | 34 ++++++++
vcl/opengl/FixedTextureAtlas.cxx | 71 +++++++++++++++++
vcl/opengl/areaScaleFastFragmentShader.glsl | 3
vcl/opengl/areaScaleFragmentShader.glsl | 1
vcl/opengl/blendedTextureFragmentShader.glsl | 8 +-
vcl/opengl/blendedTextureVertexShader.glsl | 3
vcl/opengl/diffTextureFragmentShader.glsl | 6 +
vcl/opengl/gdiimpl.cxx | 79 ++++++++++++++++++-
vcl/opengl/maskedTextureFragmentShader.glsl | 6 +
vcl/opengl/maskedTextureVertexShader.glsl | 24 ++++++
vcl/opengl/program.cxx | 6 +
vcl/opengl/salbmp.cxx | 52 ++++++++++++-
vcl/opengl/scale.cxx | 3
vcl/opengl/texture.cxx | 100 ++++++++++++++++++++-----
vcl/opengl/transformedTextureVertexShader.glsl | 3
vcl/source/app/svmain.cxx | 6 +
vcl/source/opengl/OpenGLContext.cxx | 54 +++++++++++++
vcl/source/opengl/OpenGLHelper.cxx | 48 ++++++++++++
23 files changed, 557 insertions(+), 36 deletions(-)
New commits:
commit cc0527ebed88f23d9e780836923ee92fd7f11dc1
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date: Wed Aug 19 12:31:25 2015 +0900
Use texture atlas for images 16, 24, 32, 48, 64 px width images
Change-Id: Ie95c36fe3705e2645a59cac117d99d7b85388ce1
diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx
index 30bbdb2..f67b113 100644
--- a/vcl/opengl/salbmp.cxx
+++ b/vcl/opengl/salbmp.cxx
@@ -31,11 +31,20 @@
#include "opengl/program.hxx"
#include "opengl/salbmp.hxx"
+#include "opengl/FixedTextureAtlas.hxx"
+
+namespace
+{
+
static bool isValidBitCount( sal_uInt16 nBitCount )
{
return (nBitCount == 1) || (nBitCount == 4) || (nBitCount == 8) || (nBitCount == 16) || (nBitCount == 24) || (nBitCount == 32);
}
+static std::vector<std::unique_ptr<FixedTextureAtlasManager>> sTextureAtlases;
+
+}
+
OpenGLSalBitmap::OpenGLSalBitmap()
: mpContext(NULL)
, mbDirtyTexture(true)
@@ -314,6 +323,31 @@ ImplPixelFormat* ImplPixelFormat::GetFormat( sal_uInt16 nBits, const BitmapPalet
return 0;
}
+void lclInstantiateTexture(OpenGLTexture& rTexture, const int nWidth, const int nHeight,
+ const GLenum nFormat, const GLenum nType, sal_uInt8* pData)
+{
+ if (nWidth == nHeight)
+ {
+ if (sTextureAtlases.empty())
+ {
+ sTextureAtlases.push_back(std::move(std::unique_ptr<FixedTextureAtlasManager>(new FixedTextureAtlasManager(8, 8, 16))));
+ sTextureAtlases.push_back(std::move(std::unique_ptr<FixedTextureAtlasManager>(new FixedTextureAtlasManager(8, 8, 24))));
+ sTextureAtlases.push_back(std::move(std::unique_ptr<FixedTextureAtlasManager>(new FixedTextureAtlasManager(8, 8, 32))));
+ sTextureAtlases.push_back(std::move(std::unique_ptr<FixedTextureAtlasManager>(new FixedTextureAtlasManager(8, 8, 48))));
+ sTextureAtlases.push_back(std::move(std::unique_ptr<FixedTextureAtlasManager>(new FixedTextureAtlasManager(8, 8, 64))));
+ }
+ for (size_t i = 0; i < sTextureAtlases.size(); i++)
+ {
+ if (nWidth == sTextureAtlases[i]->GetSubtextureSize())
+ {
+ rTexture = sTextureAtlases[i]->InsertBuffer(nWidth, nHeight, nFormat, nType, pData);
+ return;
+ }
+ }
+ }
+ rTexture = OpenGLTexture (nWidth, nHeight, nFormat, nType, pData);
+}
+
}
Size OpenGLSalBitmap::GetSize() const
@@ -410,7 +444,8 @@ GLuint OpenGLSalBitmap::CreateTexture()
makeCurrent();
- maTexture = OpenGLTexture (mnBufWidth, mnBufHeight, nFormat, nType, pData );
+ lclInstantiateTexture(maTexture, mnBufWidth, mnBufHeight, nFormat, nType, pData);
+
SAL_INFO( "vcl.opengl", "Created texture " << maTexture.Id() );
if( bAllocated )
commit 965ee610f7f8fb082e859e939ff29d4433597651
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date: Mon Aug 24 15:00:26 2015 +0900
opengl: push mask coords to the shaders along the image coords
If using the same texture to store the image and mask data (for
example when using texture atlas) the mask and image (RGB) coords
aren't the same anymore. With this commit we always define the mask
coords separately.
(cherry picked from commit bdce4e29191aa5bd029efa242e094aba45c44869)
Conflicts:
vcl/opengl/program.cxx
Change-Id: Ie33f87a6e9ab398972c6a3d5938e5f1364c82d36
diff --git a/vcl/Package_opengl.mk b/vcl/Package_opengl.mk
index 0a54ad6..2628dcd 100644
--- a/vcl/Package_opengl.mk
+++ b/vcl/Package_opengl.mk
@@ -19,6 +19,7 @@ $(eval $(call gb_Package_add_files,vcl_opengl_shader,$(LIBO_ETC_FOLDER)/opengl,\
convolutionFragmentShader.glsl \
linearGradientFragmentShader.glsl \
maskFragmentShader.glsl \
+ maskedTextureVertexShader.glsl \
maskedTextureFragmentShader.glsl \
radialGradientFragmentShader.glsl \
replaceColorFragmentShader.glsl \
diff --git a/vcl/inc/opengl/program.hxx b/vcl/inc/opengl/program.hxx
index 0f0f9a5..8289a56 100644
--- a/vcl/inc/opengl/program.hxx
+++ b/vcl/inc/opengl/program.hxx
@@ -36,6 +36,7 @@ private:
GLuint mnPositionAttrib;
GLuint mnTexCoordAttrib;
GLuint mnAlphaCoordAttrib;
+ GLuint mnMaskCoordAttrib;
TextureList maTextures;
bool mbBlending;
@@ -56,6 +57,7 @@ public:
void SetVertices( const GLvoid* pData );
void SetTextureCoord( const GLvoid* pData );
void SetAlphaCoord( const GLvoid* pData );
+ void SetMaskCoord(const GLvoid* pData);
void SetUniform1f( const OString& rName, GLfloat v1 );
void SetUniform2f( const OString& rName, GLfloat v1, GLfloat v2 );
diff --git a/vcl/opengl/areaScaleFastFragmentShader.glsl b/vcl/opengl/areaScaleFastFragmentShader.glsl
index 10ce9f5..f74397b 100644
--- a/vcl/opengl/areaScaleFastFragmentShader.glsl
+++ b/vcl/opengl/areaScaleFastFragmentShader.glsl
@@ -21,6 +21,7 @@ varying vec2 tex_coord;
// This mode makes the scaling work like maskedTextureFragmentShader.glsl
// (instead of like plain textureVertexShader.glsl).
#ifdef MASKED
+varying vec2 mask_coord;
uniform sampler2D mask;
#endif
@@ -41,7 +42,7 @@ void main(void)
#else
vec4 texel;
texel = texture2D( sampler, tex_coord.st + offset );
- texel.a = 1.0 - texture2D( mask, tex_coord.st + offset ).r;
+ texel.a = 1.0 - texture2D( mask, mask_coord.st + offset ).r;
sum += texel;
#endif
offset.x += xstep;
diff --git a/vcl/opengl/areaScaleFragmentShader.glsl b/vcl/opengl/areaScaleFragmentShader.glsl
index d72184c..b95b869 100644
--- a/vcl/opengl/areaScaleFragmentShader.glsl
+++ b/vcl/opengl/areaScaleFragmentShader.glsl
@@ -30,6 +30,7 @@ varying vec2 tex_coord;
// This mode makes the scaling work like maskedTextureFragmentShader.glsl
// (instead of like plain textureVertexShader.glsl).
#ifdef MASKED
+varying vec2 mask_coord;
uniform sampler2D mask;
#endif
diff --git a/vcl/opengl/blendedTextureFragmentShader.glsl b/vcl/opengl/blendedTextureFragmentShader.glsl
index b46f6ce..d823079 100644
--- a/vcl/opengl/blendedTextureFragmentShader.glsl
+++ b/vcl/opengl/blendedTextureFragmentShader.glsl
@@ -9,14 +9,18 @@
varying vec2 tex_coord;
varying vec2 alpha_coord;
+varying vec2 mask_coord;
+
uniform sampler2D sampler;
uniform sampler2D mask;
uniform sampler2D alpha;
-void main() {
+void main()
+{
vec4 texel0, texel1, texel2;
+
texel0 = texture2D(sampler, tex_coord);
- texel1 = texture2D(mask, tex_coord);
+ texel1 = texture2D(mask, mask_coord);
texel2 = texture2D(alpha, alpha_coord);
gl_FragColor = texel0;
diff --git a/vcl/opengl/blendedTextureVertexShader.glsl b/vcl/opengl/blendedTextureVertexShader.glsl
index 3a9b827..64bae78 100644
--- a/vcl/opengl/blendedTextureVertexShader.glsl
+++ b/vcl/opengl/blendedTextureVertexShader.glsl
@@ -10,14 +10,17 @@
attribute vec4 position;
attribute vec2 tex_coord_in;
attribute vec2 alpha_coord_in;
+attribute vec2 mask_coord_in;
varying vec2 tex_coord;
varying vec2 alpha_coord;
+varying vec2 mask_coord;
uniform mat4 mvp;
void main() {
gl_Position = mvp * position;
tex_coord = tex_coord_in;
alpha_coord = alpha_coord_in;
+ mask_coord = mask_coord_in;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/opengl/diffTextureFragmentShader.glsl b/vcl/opengl/diffTextureFragmentShader.glsl
index c0a982d..af9a1dc 100644
--- a/vcl/opengl/diffTextureFragmentShader.glsl
+++ b/vcl/opengl/diffTextureFragmentShader.glsl
@@ -9,14 +9,16 @@
/*precision mediump float;*/
varying vec2 tex_coord;
+varying vec2 mask_coord;
uniform sampler2D texture; /* white background */
uniform sampler2D mask; /* black background */
-void main() {
+void main()
+{
float alpha;
vec4 texel0, texel1;
texel0 = texture2D(texture, tex_coord);
- texel1 = texture2D(mask, tex_coord);
+ texel1 = texture2D(mask, mask_coord);
alpha = 1.0 - abs(texel0.r - texel1.r);
if(alpha > 0.0)
gl_FragColor = texel1 / alpha;
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index f7261b2..c612be9 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -955,6 +955,9 @@ void OpenGLSalGraphicsImpl::DrawTransformedTexture(
"#define MASKED" ) )
return;
mpProgram->SetTexture( "mask", rMask );
+ GLfloat aMaskCoord[8];
+ rMask.GetWholeCoord(aMaskCoord);
+ mpProgram->SetMaskCoord(aMaskCoord);
rMask.SetFilter( GL_LINEAR );
mpProgram->SetBlendMode( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
}
@@ -1023,25 +1026,39 @@ void OpenGLSalGraphicsImpl::DrawTextureDiff( OpenGLTexture& rTexture, OpenGLText
{
OpenGLZone aZone;
- if( !UseProgram( "textureVertexShader", "diffTextureFragmentShader" ) )
+ if( !UseProgram( "maskedTextureVertexShader", "diffTextureFragmentShader" ) )
return;
mpProgram->SetTexture( "texture", rTexture );
mpProgram->SetTexture( "mask", rMask );
mpProgram->SetBlendMode( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
+
+ GLfloat aMaskCoord[8];
+ rMask.GetCoord(aMaskCoord, rPosAry, bInverted);
+ mpProgram->SetMaskCoord(aMaskCoord);
+
DrawTextureRect( rTexture, rPosAry, bInverted );
mpProgram->Clean();
}
-void OpenGLSalGraphicsImpl::DrawTextureWithMask( OpenGLTexture& rTexture, OpenGLTexture& rMask, const SalTwoRect& pPosAry )
+void OpenGLSalGraphicsImpl::DrawTextureWithMask( OpenGLTexture& rTexture, OpenGLTexture& rMask, const SalTwoRect& rPosAry )
{
OpenGLZone aZone;
- if( !UseProgram( "textureVertexShader", "maskedTextureFragmentShader" ) )
+ if( !UseProgram( "maskedTextureVertexShader", "maskedTextureFragmentShader" ) )
return;
mpProgram->SetTexture( "sampler", rTexture );
mpProgram->SetTexture( "mask", rMask );
mpProgram->SetBlendMode( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
- DrawTextureRect( rTexture, pPosAry );
+
+ GLfloat aTexCoord[8];
+ rTexture.GetCoord(aTexCoord, rPosAry);
+ mpProgram->SetTextureCoord(aTexCoord);
+
+ GLfloat aMaskCoord[8];
+ rMask.GetCoord(aMaskCoord, rPosAry);
+ mpProgram->SetMaskCoord(aMaskCoord);
+
+ DrawRect(rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth, rPosAry.mnDestHeight);
mpProgram->Clean();
}
@@ -1049,14 +1066,20 @@ void OpenGLSalGraphicsImpl::DrawBlendedTexture( OpenGLTexture& rTexture, OpenGLT
{
OpenGLZone aZone;
- GLfloat aTexCoord[8];
if( !UseProgram( "blendedTextureVertexShader", "blendedTextureFragmentShader" ) )
return;
mpProgram->SetTexture( "sampler", rTexture );
mpProgram->SetTexture( "mask", rMask );
mpProgram->SetTexture( "alpha", rAlpha );
- rAlpha.GetCoord( aTexCoord, rPosAry );
- mpProgram->SetAlphaCoord( aTexCoord );
+
+ GLfloat aAlphaCoord[8];
+ rAlpha.GetCoord(aAlphaCoord, rPosAry);
+ mpProgram->SetAlphaCoord(aAlphaCoord);
+
+ GLfloat aMaskCoord[8];
+ rMask.GetCoord(aMaskCoord, rPosAry);
+ mpProgram->SetMaskCoord(aMaskCoord);
+
mpProgram->SetBlendMode( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
DrawTextureRect( rTexture, rPosAry );
mpProgram->Clean();
diff --git a/vcl/opengl/maskedTextureFragmentShader.glsl b/vcl/opengl/maskedTextureFragmentShader.glsl
index 4d79ae9..75ce4ae 100644
--- a/vcl/opengl/maskedTextureFragmentShader.glsl
+++ b/vcl/opengl/maskedTextureFragmentShader.glsl
@@ -9,13 +9,15 @@
/*precision mediump float;*/
varying vec2 tex_coord;
+varying vec2 mask_coord;
uniform sampler2D sampler;
uniform sampler2D mask;
-void main() {
+void main()
+{
vec4 texel0, texel1;
texel0 = texture2D(sampler, tex_coord);
- texel1 = texture2D(mask, tex_coord);
+ texel1 = texture2D(mask, mask_coord);
gl_FragColor = texel0;
gl_FragColor.a = 1.0 - texel1.r;
}
diff --git a/vcl/opengl/maskedTextureVertexShader.glsl b/vcl/opengl/maskedTextureVertexShader.glsl
new file mode 100644
index 0000000..ab225a8
--- /dev/null
+++ b/vcl/opengl/maskedTextureVertexShader.glsl
@@ -0,0 +1,24 @@
+/* -*- 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/.
+ */
+
+attribute vec4 position;
+attribute vec2 tex_coord_in;
+attribute vec2 mask_coord_in;
+varying vec2 tex_coord;
+varying vec2 mask_coord;
+uniform mat4 mvp;
+
+void main()
+{
+ gl_Position = mvp * position;
+ tex_coord = tex_coord_in;
+ mask_coord = mask_coord_in;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/opengl/program.cxx b/vcl/opengl/program.cxx
index 5f9d276..b1d3cfe 100644
--- a/vcl/opengl/program.cxx
+++ b/vcl/opengl/program.cxx
@@ -21,6 +21,7 @@ OpenGLProgram::OpenGLProgram() :
mnPositionAttrib( SAL_MAX_UINT32 ),
mnTexCoordAttrib( SAL_MAX_UINT32 ),
mnAlphaCoordAttrib( SAL_MAX_UINT32 ),
+ mnMaskCoordAttrib( SAL_MAX_UINT32 ),
mbBlending( false ),
mfLastWidth(0.0),
mfLastHeight(0.0),
@@ -115,6 +116,11 @@ void OpenGLProgram::SetAlphaCoord( const GLvoid* pData )
SetVertexAttrib( mnAlphaCoordAttrib, "alpha_coord_in", pData );
}
+void OpenGLProgram::SetMaskCoord(const GLvoid* pData)
+{
+ SetVertexAttrib(mnMaskCoordAttrib, "mask_coord_in", pData);
+}
+
GLuint OpenGLProgram::GetUniformLocation( const OString& rName )
{
auto it = maUniformLocations.find( rName );
diff --git a/vcl/opengl/transformedTextureVertexShader.glsl b/vcl/opengl/transformedTextureVertexShader.glsl
index 3a64fd0..6f8d5f3 100644
--- a/vcl/opengl/transformedTextureVertexShader.glsl
+++ b/vcl/opengl/transformedTextureVertexShader.glsl
@@ -9,15 +9,18 @@
attribute vec4 position;
attribute vec2 tex_coord_in;
+attribute vec2 mask_coord_in;
uniform vec2 viewport;
uniform mat4 transform;
uniform mat4 mvp;
varying vec2 tex_coord;
+varying vec2 mask_coord;
void main() {
vec4 pos = mvp * transform * position;
gl_Position = pos;
tex_coord = tex_coord_in;
+ mask_coord = mask_coord_in;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit d261d8670ad613679591d3ea93a29de45d0d7128
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Thu Aug 20 17:03:30 2015 +0100
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.
Reviewed-on: https://gerrit.libreoffice.org/17881
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
Tested-by: Michael Meeks <michael.meeks at collabora.com>
(cherry picked from commit d20e7e38641868bf14041f090b3668e0148904c7)
Conflicts:
vcl/source/opengl/OpenGLHelper.cxx
Change-Id: I85a4b3d4a374593dc55d01a39ec4c7c3c262c332
diff --git a/vcl/inc/opengl/zone.hxx b/vcl/inc/opengl/zone.hxx
new file mode 100644
index 0000000..c251c4f
--- /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 23398bc..f7261b2 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" );
@@ -186,6 +189,7 @@ void OpenGLSalGraphicsImpl::PostDraw()
}
CHECK_GL_ERROR();
+ OpenGLZone::leave();
}
void OpenGLSalGraphicsImpl::ApplyProgramMatrices(float fPixelOffset)
@@ -434,6 +438,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 );
@@ -442,6 +448,8 @@ bool OpenGLSalGraphicsImpl::UseInvert()
void OpenGLSalGraphicsImpl::DrawPoint( long nX, long nY )
{
+ OpenGLZone aZone;
+
GLfloat pPoint[2];
pPoint[0] = GLfloat(nX);
@@ -456,6 +464,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);
@@ -472,6 +482,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 );
@@ -654,6 +666,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;
@@ -695,6 +709,8 @@ void OpenGLSalGraphicsImpl::DrawConvexPolygon( sal_uInt32 nPoints, const SalPoin
void OpenGLSalGraphicsImpl::DrawConvexPolygon( const Polygon& rPolygon, bool blockAA )
{
+ OpenGLZone aZone;
+
sal_uInt16 nPoints = rPolygon.GetSize() - 1;
std::vector<GLfloat> aVertices(nPoints * 2);
sal_uInt32 i, j;
@@ -738,6 +754,8 @@ void OpenGLSalGraphicsImpl::DrawConvexPolygon( const Polygon& rPolygon, bool blo
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);
@@ -839,6 +857,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 );
@@ -872,6 +892,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 );
@@ -880,6 +902,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 );
@@ -894,6 +918,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() };
@@ -982,6 +1008,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 );
@@ -993,6 +1021,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 );
@@ -1004,6 +1034,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 );
@@ -1015,6 +1047,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;
@@ -1030,6 +1064,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 );
@@ -1041,6 +1077,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();
@@ -1065,6 +1103,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();
@@ -1115,6 +1155,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 7b7f674..30bbdb2 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();
@@ -591,6 +604,8 @@ bool OpenGLSalBitmap::Erase( const ::Color& /*rFillColor*/ )
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 fcb4273..6d9a4d1 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"
@@ -365,6 +366,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 fce2961..4c3ef9a 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 9beed93..e76002c 100644
--- a/vcl/source/opengl/OpenGLContext.cxx
+++ b/vcl/source/opengl/OpenGLContext.cxx
@@ -33,6 +33,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
@@ -185,6 +187,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;
@@ -228,6 +232,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;
@@ -266,6 +272,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 windwo to check whether support multi-sample, if support, get the format
@@ -558,6 +566,8 @@ GLXFBConfig* getFBConfigForPixmap(Display* dpy, int& nBestFBC, bool bUseDoubleBu
GLXFBConfig* getFBConfig(Display* dpy, Window win, int& nBestFBC, bool bUseDoubleBufferedRendering, bool bWithSameVisualID)
{
+ OpenGLZone aZone;
+
if( dpy == 0 || !glXQueryExtension( dpy, NULL, NULL ) )
return NULL;
@@ -638,6 +648,8 @@ void initOpenGLFunctionPointers()
Visual* getVisual(Display* dpy, Window win)
{
+ OpenGLZone aZone;
+
initOpenGLFunctionPointers();
XWindowAttributes xattr;
@@ -659,6 +671,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)
@@ -676,6 +690,8 @@ bool OpenGLContext::init(SystemChildWindow* pChildWindow)
if( !pChildWindow )
return false;
+ OpenGLZone aZone;
+
mpWindow = pChildWindow->GetParent();
m_pChildWindow = pChildWindow;
initWindow();
@@ -691,6 +707,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;
@@ -740,6 +758,8 @@ bool OpenGLContext::ImplInit()
return false;
}
+ OpenGLZone aZone;
+
GLXContext pSharedCtx( NULL );
#ifdef DBG_UTIL
TempErrorHandler aErrorHandler(m_aGLWin.dpy, unxErrorHandler);
@@ -866,6 +886,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 =
@@ -988,6 +1010,8 @@ bool OpenGLContext::ImplInit()
bool OpenGLContext::ImplInit()
{
+ OpenGLZone aZone;
+
SAL_INFO("vcl.opengl", "OpenGLContext::ImplInit----start");
NSOpenGLView* pView = getOpenGLView();
OpenGLWrapper::makeCurrent(pView);
@@ -1010,6 +1034,8 @@ bool OpenGLContext::InitGLEW()
static bool bGlewInit = false;
if(!bGlewInit)
{
+ OpenGLZone aZone;
+
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (err != GLEW_OK)
@@ -1025,6 +1051,8 @@ bool OpenGLContext::InitGLEW()
// only enable debug output in dbgutil build
if( GLEW_ARB_debug_output)
{
+ OpenGLZone aZone;
+
if (glDebugMessageCallbackARB)
{
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
@@ -1169,6 +1197,8 @@ bool OpenGLContext::initWindow()
void OpenGLContext::initGLWindow(Visual* pVisual)
{
+ OpenGLZone aZone;
+
// Get visual info
{
XVisualInfo aTemplate;
@@ -1199,6 +1229,8 @@ void OpenGLContext::reset()
if( !mbInitialized )
return;
+ OpenGLZone aZone;
+
// reset the clip region
maClipRegion.SetEmpty();
@@ -1285,6 +1317,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;
@@ -1326,6 +1360,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);
@@ -1359,6 +1395,8 @@ void OpenGLContext::makeCurrent()
if (isCurrent())
return;
+ OpenGLZone aZone;
+
clearCurrent();
#if defined( WNT )
@@ -1407,6 +1445,8 @@ void OpenGLContext::resetCurrent()
{
clearCurrent();
+ OpenGLZone aZone;
+
#if defined( WNT )
wglMakeCurrent( m_aGLWin.hDC, 0 );
#elif defined( MACOSX )
@@ -1421,6 +1461,8 @@ void OpenGLContext::resetCurrent()
void OpenGLContext::swapBuffers()
{
+ OpenGLZone aZone;
+
#if defined( WNT )
SwapBuffers(m_aGLWin.hDC);
#elif defined( MACOSX )
@@ -1435,6 +1477,8 @@ void OpenGLContext::swapBuffers()
void OpenGLContext::sync()
{
+ OpenGLZone aZone;
+
#if defined( WNT )
// nothing
#elif defined( MACOSX ) || defined( IOS ) || defined( ANDROID ) || defined(LIBO_HEADLESS)
@@ -1478,6 +1522,8 @@ NSOpenGLView* OpenGLContext::getOpenGLView()
bool OpenGLContext::BindFramebuffer( OpenGLFramebuffer* pFramebuffer )
{
+ OpenGLZone aZone;
+
if( pFramebuffer != mpCurrentFramebuffer )
{
if( pFramebuffer )
@@ -1497,6 +1543,8 @@ bool OpenGLContext::AcquireDefaultFramebuffer()
OpenGLFramebuffer* OpenGLContext::AcquireFramebuffer( const OpenGLTexture& rTexture )
{
+ OpenGLZone aZone;
+
OpenGLFramebuffer* pFramebuffer = NULL;
OpenGLFramebuffer* pFreeFbo = NULL;
OpenGLFramebuffer* pSameSizeFbo = NULL;
@@ -1563,6 +1611,7 @@ void OpenGLContext::ReleaseFramebuffer( OpenGLFramebuffer* pFramebuffer )
void OpenGLContext::ReleaseFramebuffer( const OpenGLTexture& rTexture )
{
+ OpenGLZone aZone;
OpenGLFramebuffer* pFramebuffer = mpLastFramebuffer;
while( pFramebuffer )
@@ -1578,6 +1627,7 @@ void OpenGLContext::ReleaseFramebuffer( const OpenGLTexture& rTexture )
void OpenGLContext::ReleaseFramebuffers()
{
+ OpenGLZone aZone;
OpenGLFramebuffer* pFramebuffer = mpLastFramebuffer;
while( pFramebuffer )
{
@@ -1589,6 +1639,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
@@ -1606,6 +1658,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 41881da..967d4c5 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;
+
boost::scoped_array<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;
commit 0057c6c8fc73138128f1be4b64f43f048b840a41
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date: Wed Aug 19 11:51:15 2015 +0900
Fixed (fixed size) texture atlas for "caching" OpenGL texures
Change-Id: I7fe90c0a0033b4d9a341a4f0b8356d7f7133e93e
(cherry picked from commit b26ba85d04e81f48622dfdbb71d9d80b54dacc40)
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 542c8f52..56231d0 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -132,6 +132,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/opengl/framebuffer \
vcl/opengl/program \
vcl/opengl/texture \
+ vcl/opengl/FixedTextureAtlas \
vcl/source/opengl/OpenGLContext \
vcl/source/opengl/OpenGLHelper \
vcl/source/window/cairo_cairo \
diff --git a/vcl/inc/opengl/FixedTextureAtlas.hxx b/vcl/inc/opengl/FixedTextureAtlas.hxx
new file mode 100644
index 0000000..c4f5d60
--- /dev/null
+++ b/vcl/inc/opengl/FixedTextureAtlas.hxx
@@ -0,0 +1,39 @@
+/* -*- 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_FIXED_TEXTURE_ATLAS_H
+#define INCLUDED_VCL_INC_OPENGL_FIXED_TEXTURE_ATLAS_H
+
+#include "opengl/texture.hxx"
+
+
+class VCL_PLUGIN_PUBLIC FixedTextureAtlasManager
+{
+ std::vector<std::unique_ptr<ImplOpenGLTexture>> mpTextures;
+
+ int mWidthFactor;
+ int mHeightFactor;
+ int mSubTextureSize;
+
+ void CreateNewTexture();
+
+public:
+ FixedTextureAtlasManager(int nWidthFactor, int nHeightFactor, int nTextureSize);
+ OpenGLTexture InsertBuffer(int nWidth, int nHeight, int nFormat, int nType, sal_uInt8* pData);
+
+ int GetSubtextureSize()
+ {
+ return mSubTextureSize;
+ }
+};
+
+#endif // INCLUDED_VCL_INC_OPENGL_FIXED_TEXTURE_ATLAS_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/texture.hxx b/vcl/inc/opengl/texture.hxx
index 3d99526..41353e2 100644
--- a/vcl/inc/opengl/texture.hxx
+++ b/vcl/inc/opengl/texture.hxx
@@ -26,6 +26,8 @@
#include <tools/gen.hxx>
+#include <memory>
+
class ImplOpenGLTexture
{
public:
@@ -35,10 +37,45 @@ public:
int mnHeight;
GLenum mnFilter;
+ std::unique_ptr<std::vector<int>> mpSlotReferences;
+ int mnFreeSlots;
+
ImplOpenGLTexture( int nWidth, int nHeight, bool bAllocate );
ImplOpenGLTexture( int nWidth, int nHeight, int nFormat, int nType, sal_uInt8* pData );
ImplOpenGLTexture( int nX, int nY, int nWidth, int nHeight );
~ImplOpenGLTexture();
+
+ bool InsertBuffer(int nX, int nY, int nWidth, int nHeight, int nFormat, int nType, sal_uInt8* pData);
+
+ void IncreaseRefCount(int nSlotNumber)
+ {
+ mnRefCount++;
+ if (mpSlotReferences && nSlotNumber >= 0)
+ {
+ if (mpSlotReferences->at(nSlotNumber) == 0)
+ mnFreeSlots--;
+ mpSlotReferences->at(nSlotNumber)++;
+ }
+ }
+
+ void DecreaseRefCount(int nSlotNumber)
+ {
+ mnRefCount--;
+ if (mpSlotReferences && nSlotNumber >= 0)
+ {
+ mpSlotReferences->at(nSlotNumber)--;
+ if (mpSlotReferences->at(nSlotNumber) == 0)
+ mnFreeSlots++;
+ }
+ }
+
+ bool ExistRefs()
+ {
+ return mnRefCount > 0;
+ }
+
+ bool InitializeSlots(int nSlotSize);
+ int FindFreeSlot();
};
class VCL_PLUGIN_PUBLIC OpenGLTexture
@@ -46,12 +83,14 @@ class VCL_PLUGIN_PUBLIC OpenGLTexture
private:
// if the rect size doesn't match the mpImpl one, this instance
// is a sub-area from the real OpenGL texture
- Rectangle maRect;
-
+ Rectangle maRect;
ImplOpenGLTexture* mpImpl;
+ int mnSlotNumber;
public:
OpenGLTexture();
+ OpenGLTexture(ImplOpenGLTexture* pImpl, Rectangle aRectangle, int nSlotNumber = 0);
+
OpenGLTexture( int nWidth, int nHeight, bool bAllocate = true );
OpenGLTexture( int nWidth, int nHeight, int nFormat, int nType, sal_uInt8* pData );
OpenGLTexture( int nX, int nY, int nWidth, int nHeight );
diff --git a/vcl/opengl/FixedTextureAtlas.cxx b/vcl/opengl/FixedTextureAtlas.cxx
new file mode 100644
index 0000000..c8ca508
--- /dev/null
+++ b/vcl/opengl/FixedTextureAtlas.cxx
@@ -0,0 +1,71 @@
+/* -*- 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/.
+ *
+ */
+
+#include <sal/config.h>
+#include <vcl/opengl/OpenGLContext.hxx>
+#include <vcl/opengl/OpenGLHelper.hxx>
+
+#include "opengl/framebuffer.hxx"
+#include "opengl/texture.hxx"
+
+#include "opengl/FixedTextureAtlas.hxx"
+
+FixedTextureAtlasManager::FixedTextureAtlasManager(int nWidthFactor, int nHeightFactor, int nSubTextureSize)
+ : mWidthFactor(nWidthFactor)
+ , mHeightFactor(nHeightFactor)
+ , mSubTextureSize(nSubTextureSize)
+{
+}
+
+void FixedTextureAtlasManager::CreateNewTexture()
+{
+ int nTextureWidth = mWidthFactor * mSubTextureSize;
+ int nTextureHeight = mHeightFactor * mSubTextureSize;
+ mpTextures.push_back(std::move(std::unique_ptr<ImplOpenGLTexture>(new ImplOpenGLTexture(nTextureWidth, nTextureHeight, true))));
+ mpTextures.back()->InitializeSlots(mWidthFactor * mHeightFactor);
+}
+
+OpenGLTexture FixedTextureAtlasManager::InsertBuffer(int nWidth, int nHeight, int nFormat, int nType, sal_uInt8* pData)
+{
+ ImplOpenGLTexture* pTexture = nullptr;
+
+ for (size_t i = 0; i < mpTextures.size(); i++)
+ {
+ if (mpTextures[i]->mnFreeSlots > 0)
+ {
+ pTexture = mpTextures[i].get();
+ }
+ }
+
+ if (!pTexture)
+ {
+ CreateNewTexture();
+ pTexture = mpTextures.back().get();
+ }
+
+ int nSlot = pTexture->FindFreeSlot();
+
+ // Calculate coordinates in texture
+ int nX = (nSlot % mWidthFactor) * mSubTextureSize;
+ int nY = (nSlot / mWidthFactor) * mSubTextureSize;
+
+ Rectangle aRectangle(Point(nX, nY), Size(nWidth, nHeight));
+
+ // If available, copy the image data to the texture
+ if (pData)
+ {
+ if (!pTexture->InsertBuffer(nX, nY, nWidth, nHeight, nFormat, nType, pData))
+ return OpenGLTexture();
+ }
+
+ return OpenGLTexture(pTexture, aRectangle, nSlot);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/opengl/texture.cxx b/vcl/opengl/texture.cxx
index 732830b..6d2bbb2 100644
--- a/vcl/opengl/texture.cxx
+++ b/vcl/opengl/texture.cxx
@@ -33,7 +33,8 @@ ImplOpenGLTexture::ImplOpenGLTexture( int nWidth, int nHeight, bool bAllocate )
mnRefCount( 1 ),
mnWidth( nWidth ),
mnHeight( nHeight ),
- mnFilter( GL_NEAREST )
+ mnFilter( GL_NEAREST ),
+ mnFreeSlots(-1)
{
glGenTextures( 1, &mnTexture );
glBindTexture( GL_TEXTURE_2D, mnTexture );
@@ -56,7 +57,8 @@ ImplOpenGLTexture::ImplOpenGLTexture( int nX, int nY, int nWidth, int nHeight )
mnTexture( 0 ),
mnWidth( nWidth ),
mnHeight( nHeight ),
- mnFilter( GL_NEAREST )
+ mnFilter( GL_NEAREST ),
+ mnFreeSlots(-1)
{
// FIXME We need the window height here
// nY = GetHeight() - nHeight - nY;
@@ -82,7 +84,8 @@ ImplOpenGLTexture::ImplOpenGLTexture( int nWidth, int nHeight, int nFormat, int
mnTexture( 0 ),
mnWidth( nWidth ),
mnHeight( nHeight ),
- mnFilter( GL_NEAREST )
+ mnFilter( GL_NEAREST ),
+ mnFreeSlots(-1)
{
if( !mnTexture )
glGenTextures( 1, &mnTexture );
@@ -107,12 +110,64 @@ ImplOpenGLTexture::~ImplOpenGLTexture()
glDeleteTextures( 1, &mnTexture );
}
+bool ImplOpenGLTexture::InsertBuffer(int nX, int nY, int nWidth, int nHeight, int nFormat, int nType, sal_uInt8* pData)
+{
+ if (!pData || mnTexture == 0)
+ return false;
+ glBindTexture(GL_TEXTURE_2D, mnTexture);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, nX, mnHeight - nY - nHeight, nWidth, nHeight, nFormat, nType, pData);
+ glBindTexture(GL_TEXTURE_2D, 0);
+
+ SAL_INFO( "vcl.opengl", "OpenGLTexture " << mnTexture << " Insert buff. to " << nX << " " << nY
+ << " size " << nWidth << "x" << nHeight << " from data" );
+ CHECK_GL_ERROR();
+
+ return true;
+}
+
+bool ImplOpenGLTexture::InitializeSlots(int nSlotSize)
+{
+ if (mpSlotReferences)
+ return false;
+
+ mpSlotReferences.reset(new std::vector<int>(nSlotSize, 0));
+ mnFreeSlots = nSlotSize;
+
+ return true;
+}
+
+int ImplOpenGLTexture::FindFreeSlot()
+{
+ if (mnFreeSlots > 0 && mpSlotReferences)
+ {
+ for (size_t i = 0; i < mpSlotReferences->size(); i++)
+ {
+ if (mpSlotReferences->at(i) <= 0)
+ {
+ return i;
+ }
+ }
+ }
+ return -1;
+}
+
OpenGLTexture::OpenGLTexture() :
maRect( 0, 0, 0, 0 ),
- mpImpl( NULL )
+ mpImpl(NULL),
+ mnSlotNumber(-1)
{
}
+OpenGLTexture::OpenGLTexture(ImplOpenGLTexture* pImpl, Rectangle aRectangle, int nSlotNumber)
+ : maRect(aRectangle)
+ , mpImpl(pImpl)
+ , mnSlotNumber(nSlotNumber)
+{
+ if (mpImpl)
+ mpImpl->IncreaseRefCount(nSlotNumber);
+}
+
OpenGLTexture::OpenGLTexture( int nWidth, int nHeight, bool bAllocate ) :
maRect( Point( 0, 0 ), Size( nWidth, nHeight ) )
{
@@ -135,8 +190,10 @@ OpenGLTexture::OpenGLTexture( const OpenGLTexture& rTexture )
{
maRect = rTexture.maRect;
mpImpl = rTexture.mpImpl;
- if( mpImpl )
- mpImpl->mnRefCount++;
+ mnSlotNumber = rTexture.mnSlotNumber;
+
+ if (mpImpl)
+ mpImpl->IncreaseRefCount(mnSlotNumber);
}
OpenGLTexture::OpenGLTexture( const OpenGLTexture& rTexture,
@@ -145,19 +202,19 @@ OpenGLTexture::OpenGLTexture( const OpenGLTexture& rTexture,
maRect = Rectangle( Point( rTexture.maRect.Left() + nX, rTexture.maRect.Top() + nY ),
Size( nWidth, nHeight ) );
mpImpl = rTexture.mpImpl;
- if( mpImpl )
- mpImpl->mnRefCount++;
+ mnSlotNumber = rTexture.mnSlotNumber;
+ if (mpImpl)
+ mpImpl->IncreaseRefCount(mnSlotNumber);
SAL_INFO( "vcl.opengl", "Copying texture " << Id() << " [" << maRect.Left() << "," << maRect.Top() << "] " << GetWidth() << "x" << GetHeight() );
}
OpenGLTexture::~OpenGLTexture()
{
- if( mpImpl )
+ if (mpImpl)
{
- if( mpImpl->mnRefCount == 1 )
+ mpImpl->DecreaseRefCount(mnSlotNumber);
+ if (!mpImpl->ExistRefs())
delete mpImpl;
- else
- mpImpl->mnRefCount--;
}
}
@@ -333,25 +390,30 @@ OpenGLTexture::operator bool() const
OpenGLTexture& OpenGLTexture::operator=( const OpenGLTexture& rTexture )
{
- if( rTexture.mpImpl )
- rTexture.mpImpl->mnRefCount++;
- if( mpImpl )
+ if (rTexture.mpImpl)
+ {
+ rTexture.mpImpl->IncreaseRefCount(rTexture.mnSlotNumber);
+ }
+
+ if (mpImpl)
{
- if( mpImpl->mnRefCount == 1 )
+ mpImpl->DecreaseRefCount(mnSlotNumber);
+ if (!mpImpl->ExistRefs())
delete mpImpl;
- else
- mpImpl->mnRefCount--;
}
maRect = rTexture.maRect;
mpImpl = rTexture.mpImpl;
+ mnSlotNumber = rTexture.mnSlotNumber;
return *this;
}
bool OpenGLTexture::operator==( const OpenGLTexture& rTexture ) const
{
- return (mpImpl == rTexture.mpImpl && maRect == rTexture.maRect );
+ return (mpImpl == rTexture.mpImpl
+ && maRect == rTexture.maRect
+ && mnSlotNumber == rTexture.mnSlotNumber);
}
bool OpenGLTexture::operator!=( const OpenGLTexture& rTexture ) const
More information about the Libreoffice-commits
mailing list