[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - vcl/inc vcl/opengl

2016-06-26 Thread Tomaž Vajngerl
 vcl/inc/openglgdiimpl.hxx |2 ++
 vcl/opengl/gdiimpl.cxx|   10 ++
 2 files changed, 12 insertions(+)

New commits:
commit 24c3838b5fd2005d9df902c9a7d03fcba78adbe4
Author: Tomaž Vajngerl 
Date:   Fri Jun 24 16:42:45 2016 +0800

tdf#100411 start the flush timer when batching (PostBatchDraw)

When we batch a draw command we need to start the flush timer
(if not already started) as otherwise it could happen that we
won't flush the offscreen texture at the correct time or at all.
This fixes a problem with drawing of pop-up "help" text.

(cherry picked from commit e1296e295e7d4f1104d2c90b1f51d52251358bea)

Change-Id: I6afcf173c3ac517ed0612cd413d95e28c19faa81
Reviewed-on: https://gerrit.libreoffice.org/26630
Tested-by: Jenkins 
Reviewed-by: Caolán McNamara 
Tested-by: Caolán McNamara 

diff --git a/vcl/inc/openglgdiimpl.hxx b/vcl/inc/openglgdiimpl.hxx
index df7b9e9..2037268 100644
--- a/vcl/inc/openglgdiimpl.hxx
+++ b/vcl/inc/openglgdiimpl.hxx
@@ -169,6 +169,8 @@ public:
 // operations to do after painting
 void PostDraw();
 
+void PostBatchDraw();
+
 protected:
 bool AcquireContext(bool bForceCreate = false);
 bool ReleaseContext();
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index 188db65..1422c6a 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -249,6 +249,15 @@ void OpenGLSalGraphicsImpl::PostDraw()
 OpenGLZone::leave();
 }
 
+void OpenGLSalGraphicsImpl::PostBatchDraw()
+{
+if (IsOffscreen())
+return;
+
+if (!mpFlush->IsActive())
+mpFlush->Start();
+}
+
 void OpenGLSalGraphicsImpl::ApplyProgramMatrices(float fPixelOffset)
 {
 mpProgram->ApplyMatrix(GetWidth(), GetHeight(), fPixelOffset);
@@ -1519,6 +1528,7 @@ void OpenGLSalGraphicsImpl::DrawMask( OpenGLTexture& 
rMask, SalColor nMaskColor,
 void OpenGLSalGraphicsImpl::DeferredTextDraw(OpenGLTexture& rTexture, SalColor 
aMaskColor, const SalTwoRect& rPosAry)
 {
 mpAccumulatedTextures->insert(rTexture, aMaskColor, rPosAry);
+PostBatchDraw();
 }
 
 void OpenGLSalGraphicsImpl::FlushDeferredDrawing()
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - vcl/inc vcl/opengl

2016-05-30 Thread Tomaž Vajngerl
 vcl/inc/opengl/program.hxx |1 
 vcl/inc/openglgdiimpl.hxx  |1 
 vcl/opengl/gdiimpl.cxx |   81 -
 vcl/opengl/program.cxx |   23 ++--
 4 files changed, 78 insertions(+), 28 deletions(-)

New commits:
commit 16f87e808942a88c935754c2aabef86ee379b9b7
Author: Tomaž Vajngerl 
Date:   Fri May 27 14:24:38 2016 +0900

tdf#100080 set unused shader attribs with values, fixes GL on AMD

AMD drivers don't work well if a shader has a defined but not
enabled shader attributes. For this reason we need to make sure
that all attributes are set to some value even if the shader
doesn't use that attribute. Intel drivers, on the other hand,
crash if you enable an attribute and don't set it (set it
to null) - so we can't use this workaround.

(cherry picked from commit fdcd13c1c2b8b9fbc3480c8fa92920d8c8d4e5a7)

Change-Id: If0abcfb664c3b71bb657b9a810d2d2a14fe5d9b4
Reviewed-on: https://gerrit.libreoffice.org/25592
Tested-by: Jenkins 
Reviewed-by: Miklos Vajna 

diff --git a/vcl/inc/opengl/program.hxx b/vcl/inc/opengl/program.hxx
index 2fab98c..3c194d8 100644
--- a/vcl/inc/opengl/program.hxx
+++ b/vcl/inc/opengl/program.hxx
@@ -106,6 +106,7 @@ public:
 void DrawArrays(GLenum GLenum, std::vector& aVertices);
 
 protected:
+bool EnableVertexAttrib(GLuint& rAttrib, const OString& rName);
 void SetVertexAttrib( GLuint& rAttrib, const OString& rName, const GLvoid* 
pData, GLint nSize = 2 );
 GLuint GetUniformLocation( const OString& rName );
 };
diff --git a/vcl/inc/openglgdiimpl.hxx b/vcl/inc/openglgdiimpl.hxx
index da0fe69..df7b9e9 100644
--- a/vcl/inc/openglgdiimpl.hxx
+++ b/vcl/inc/openglgdiimpl.hxx
@@ -119,7 +119,6 @@ public:
 bool UseInvert(SalInvert nFlags);
 
 void DrawPoint( long nX, long nY );
-void DrawLine( double nX1, double nY1, double nX2, double nY2 );
 void DrawConvexPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry, bool 
blockAA = false );
 void DrawConvexPolygon( const tools::Polygon& rPolygon, bool blockAA = 
false );
 void DrawTrapezoid( const basegfx::B2DTrapezoid& trapezoid, bool blockAA = 
false );
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index 40df037..39ae806 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -613,25 +613,13 @@ void OpenGLSalGraphicsImpl::DrawPoint( long nX, long nY )
 GLfloat(nX), GLfloat(nY)
 };
 
+std::vector aExtrusion(3, 0);
+mpProgram->SetExtrusionVectors(aExtrusion.data());
 ApplyProgramMatrices(0.5f);
 mpProgram->DrawArrays(GL_POINTS, pPoint);
 CHECK_GL_ERROR();
 }
 
-void OpenGLSalGraphicsImpl::DrawLine( double nX1, double nY1, double nX2, 
double nY2 )
-{
-OpenGLZone aZone;
-
-std::vector pPoint {
-GLfloat(nX1), GLfloat(nY1),
-GLfloat(nX2), GLfloat(nY2)
-};
-
-ApplyProgramMatrices(0.5f);
-mpProgram->DrawArrays(GL_LINES, pPoint);
-CHECK_GL_ERROR();
-}
-
 namespace
 {
 
@@ -959,6 +947,8 @@ void OpenGLSalGraphicsImpl::DrawConvexPolygon( sal_uInt32 
nPoints, const SalPoin
 }
 
 ApplyProgramMatrices();
+std::vector aExtrusion(nPoints * 3, 0);
+mpProgram->SetExtrusionVectors(aExtrusion.data());
 mpProgram->DrawArrays(GL_TRIANGLE_FAN, aVertices);
 CHECK_GL_ERROR();
 
@@ -1002,6 +992,8 @@ void OpenGLSalGraphicsImpl::DrawConvexPolygon( const 
tools::Polygon& rPolygon, b
 }
 
 ApplyProgramMatrices();
+std::vector aExtrusion(nPoints * 3, 0);
+mpProgram->SetExtrusionVectors(aExtrusion.data());
 mpProgram->DrawArrays(GL_TRIANGLE_FAN, aVertices);
 CHECK_GL_ERROR();
 
@@ -1051,6 +1043,8 @@ void OpenGLSalGraphicsImpl::DrawTrapezoid( const 
basegfx::B2DTrapezoid& trapezoi
 return;
 }
 
+std::vector aExtrusion(nPoints * 3, 0);
+mpProgram->SetExtrusionVectors(aExtrusion.data());
 ApplyProgramMatrices();
 mpProgram->DrawArrays(GL_TRIANGLE_FAN, aVertices);
 CHECK_GL_ERROR();
@@ -1164,24 +1158,23 @@ void OpenGLSalGraphicsImpl::DrawRegionBand( const 
RegionBand& rRegion )
 }
 #undef ADD_VERTICE
 
+std::vector aExtrusion(aRects.size() * 6 * 3, 0);
+mpProgram->SetExtrusionVectors(aExtrusion.data());
 ApplyProgramMatrices();
 mpProgram->DrawArrays(GL_TRIANGLES, aVertices);
 CHECK_GL_ERROR();
 }
 
-void OpenGLSalGraphicsImpl::DrawTextureRect( OpenGLTexture& rTexture, const 
SalTwoRect& rPosAry, bool bInverted )
+void OpenGLSalGraphicsImpl::DrawTextureRect( OpenGLTexture& /*rTexture*/, 
const SalTwoRect& rPosAry, bool /*bInverted*/ )
 {
 OpenGLZone aZone;
 
 SAL_INFO("vcl.opengl", "draw texture rect");
 
-GLfloat aTexCoord[8];
-rTexture.GetCoord( aTexCoord, rPosAry, bInverted );
-mpProgram->SetTextureCoord( aTexCoord );
 DrawRect( rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth, 
rPosAry.mnDestHeight );
 }
 
-void 

[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - vcl/inc vcl/opengl vcl/Package_opengl.mk

2016-05-25 Thread Tomaž Vajngerl
 vcl/Package_opengl.mk |4 
 vcl/inc/opengl/program.hxx|   19 +
 vcl/inc/openglgdiimpl.hxx |5 
 vcl/opengl/combinedFragmentShader.glsl|   45 +++
 vcl/opengl/combinedTextureFragmentShader.glsl |   64 
 vcl/opengl/combinedTextureVertexShader.glsl   |   32 ++
 vcl/opengl/combinedVertexShader.glsl  |   47 +++
 vcl/opengl/gdiimpl.cxx|  366 +-
 vcl/opengl/program.cxx|   18 +
 9 files changed, 306 insertions(+), 294 deletions(-)

New commits:
commit ccba183a785990d17252ba72a0f6ca88d108d7a5
Author: Tomaž Vajngerl 
Date:   Tue May 24 11:20:58 2016 +0900

opengl: use existing code for "legacy" polyline, polygon render.

Rendering polylines, polygons, polypolygons which take an array
as parameter ("legacy" code) can re-use the other, already
existing code paths (same thing as "headless" svp backend does).

(cherry picked from commit 6473093d4f6ee7d06905ddd71c90180fcffb0bef)

opengl: use line shader for all line drawing not just polylines

Line drawing using the line shader was used only when drawing
polylines. With this commit every line drawing is using the line
shader. This gives a marginal performance win and removes the old
code for doing anti-aliased line drawing.

(cherry picked from commit c8fc1f40ad8e20af32574e0aa73bdec51ae64e14)

opengl: combined shaders to reduce shader switching

Combine most common shaders for non-texture drawing and texture
drawing into two combined shaders. Inside the shader we switch
between the code paths with if statements.

Using if statements (or any other branching statements) is
discouraged inside shaders but on the other hand we reduce program
state changes if we have less shader changes - which is more
important for us as we want to push more work to the GPU.

(cherry picked from commit 3cac38b2311538a0aecca765eb62c30c5098a85c)

Change-Id: I19a486b6f65b1c4db0b15a54e5e4d12f42a9f6d5
Reviewed-on: https://gerrit.libreoffice.org/25382
Tested-by: Jenkins 
Reviewed-by: Caolán McNamara 
Tested-by: Caolán McNamara 

diff --git a/vcl/Package_opengl.mk b/vcl/Package_opengl.mk
index a0f6e9a..2fa917e 100644
--- a/vcl/Package_opengl.mk
+++ b/vcl/Package_opengl.mk
@@ -21,6 +21,10 @@ $(eval $(call 
gb_Package_add_files,vcl_opengl_shader,$(LIBO_ETC_FOLDER)/opengl,\
 invert50FragmentShader.glsl \
convolutionFragmentShader.glsl \
linearGradientFragmentShader.glsl \
+   combinedTextureFragmentShader.glsl \
+   combinedTextureVertexShader.glsl \
+   combinedFragmentShader.glsl \
+   combinedVertexShader.glsl \
lineFragmentShader.glsl \
lineVertexShader.glsl \
maskFragmentShader.glsl \
diff --git a/vcl/inc/opengl/program.hxx b/vcl/inc/opengl/program.hxx
index 5944c72..2fab98c 100644
--- a/vcl/inc/opengl/program.hxx
+++ b/vcl/inc/opengl/program.hxx
@@ -27,6 +27,21 @@
 typedef std::unordered_map< OString, GLuint, OStringHash > UniformCache;
 typedef std::list< OpenGLTexture > TextureList;
 
+enum class TextureShaderType
+{
+Normal = 0,
+Blend,
+Masked,
+Diff,
+MaskedColor
+};
+
+enum class DrawShaderType
+{
+Normal = 0,
+Line
+};
+
 class VCL_PLUGIN_PUBLIC OpenGLProgram
 {
 private:
@@ -78,6 +93,10 @@ public:
 void SetTransform( const OString& rName, const OpenGLTexture& rTexture,
const basegfx::B2DPoint& rNull, const 
basegfx::B2DPoint& rX,
const basegfx::B2DPoint& rY );
+void SetIdentityTransform(const OString& rName);
+void SetShaderType(TextureShaderType eTextureShaderType);
+void SetShaderType(DrawShaderType eDrawShaderType);
+
 void SetBlendMode( GLenum nSFactor, GLenum nDFactor );
 
 void ApplyMatrix(float fWidth, float fHeight, float fPixelOffset = 0.0f);
diff --git a/vcl/inc/openglgdiimpl.hxx b/vcl/inc/openglgdiimpl.hxx
index 6dfa73c..da0fe69 100644
--- a/vcl/inc/openglgdiimpl.hxx
+++ b/vcl/inc/openglgdiimpl.hxx
@@ -114,17 +114,12 @@ public:
 bool UseSolid( SalColor nColor, sal_uInt8 nTransparency );
 bool UseSolid( SalColor nColor, double fTransparency );
 bool UseSolid( SalColor nColor );
-bool UseSolidAA( SalColor nColor, double fTransparency );
-bool UseSolidAA( SalColor nColor );
 bool UseLine(SalColor nColor, double fTransparency, GLfloat fLineWidth, 
bool bUseAA);
 bool UseInvert50();
 bool UseInvert(SalInvert nFlags);
 
 void DrawPoint( long nX, long nY );
 void DrawLine( double nX1, double nY1, double nX2, double nY2 );
-void DrawLineAA( double nX1, double nY1, double nX2, double nY2 );
-void DrawLinesAA( sal_uInt32 nPoints, const SalPoint* pPtAry, bool bClose 
);
-void DrawEdgeAA( 

[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - vcl/inc vcl/opengl vcl/source

2016-05-25 Thread Tomaž Vajngerl
 vcl/inc/opengl/RenderState.hxx  |   27 
 vcl/inc/opengl/program.hxx  |5 +
 vcl/opengl/gdiimpl.cxx  |  116 +++-
 vcl/opengl/program.cxx  |   45 -
 vcl/source/opengl/OpenGLContext.cxx |6 +
 5 files changed, 115 insertions(+), 84 deletions(-)

New commits:
commit 28d2b668c0476bd8dc198656b46c01de6e8c9921
Author: Tomaž Vajngerl 
Date:   Thu May 12 13:37:11 2016 +0900

opengl: track the state of blend, DrawArrays on OpenGLProgram

This adds tracking of GL_BLEND and glBlendFunc which are usually
set when setting up the current draw call on OpenGLProgram with
SetBlendFunc method.

Until now the final draw call (glDrawArrays) was called outside
of OpenGLProgram. This is a problem because we need to know if
we did call SetBlendFunc or not between when we used or reused
the current program. So we added DrawArrays to OpenGLProgram and
refactored all draw calls in OpenGLSalGraphicsImpl to use this.

From now on glDrawArrays should not be called directly but always
through OpenGLProgram.

(cherry picked from commit e480b2cf3e362760de8e35cbb950104e47ebe7ec)

Change-Id: I530b4b948af8a962669a3751e1a95ff3986ffec9
Reviewed-on: https://gerrit.libreoffice.org/25359
Tested-by: Jenkins 
Reviewed-by: Caolán McNamara 
Tested-by: Caolán McNamara 

diff --git a/vcl/inc/opengl/RenderState.hxx b/vcl/inc/opengl/RenderState.hxx
index ac215a8..2930ff1 100644
--- a/vcl/inc/opengl/RenderState.hxx
+++ b/vcl/inc/opengl/RenderState.hxx
@@ -117,11 +117,36 @@ public:
 static std::string className() { return std::string("StencilState"); }
 };
 
+class BlendState : public GenericCapabilityState
+{
+GLenum mnSourceMode;
+GLenum mnDestinationMode;
+public:
+BlendState()
+: mnSourceMode(GL_ZERO)
+, mnDestinationMode(GL_ZERO)
+{}
+
+static std::string className() { return std::string("BlendState"); }
+
+void func(GLenum nSource, GLenum nDestination)
+{
+if (mnSourceMode != nSource || mnDestinationMode != nDestination)
+{
+glBlendFunc(nSource, nDestination);
+CHECK_GL_ERROR();
+mnSourceMode = nSource;
+mnDestinationMode = nDestination;
+}
+}
+};
+
 class RenderState
 {
 TextureState maTexture;
 ScissorState maScissor;
 StencilState maStencil;
+BlendState   maBlend;
 
 Rectangle maCurrentViewport;
 
@@ -142,12 +167,14 @@ public:
 TextureState& texture() { return maTexture; }
 ScissorState& scissor() { return maScissor; }
 StencilState& stencil() { return maStencil; }
+BlendState&   blend()   { return maBlend; }
 
 void sync()
 {
 VCL_GL_INFO("RenderState::sync");
 maScissor.sync();
 maStencil.sync();
+maBlend.sync();
 }
 };
 
diff --git a/vcl/inc/opengl/program.hxx b/vcl/inc/opengl/program.hxx
index 780cba7..5944c72 100644
--- a/vcl/inc/opengl/program.hxx
+++ b/vcl/inc/opengl/program.hxx
@@ -51,9 +51,12 @@ public:
 OpenGLProgram();
 ~OpenGLProgram();
 
+GLuint Id() { return mnId; }
+
 bool Load( const OUString& rVertexShader, const OUString& rFragmentShader,
const rtl::OString& preamble = "", const rtl::OString& rDigest 
= "" );
 bool Use();
+void Reuse();
 bool Clean();
 
 void SetVertices( const GLvoid* pData );
@@ -81,6 +84,8 @@ public:
 
 bool DrawTexture( const OpenGLTexture& rTexture );
 
+void DrawArrays(GLenum GLenum, std::vector& aVertices);
+
 protected:
 void SetVertexAttrib( GLuint& rAttrib, const OString& rName, const GLvoid* 
pData, GLint nSize = 2 );
 GLuint GetUniformLocation( const OString& rName );
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index c6139e8..424f4be 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -626,14 +626,12 @@ void OpenGLSalGraphicsImpl::DrawPoint( long nX, long nY )
 {
 OpenGLZone aZone;
 
-GLfloat pPoint[2];
-
-pPoint[0] = GLfloat(nX);
-pPoint[1] = GLfloat(nY);
+std::vector pPoint {
+GLfloat(nX), GLfloat(nY)
+};
 
 ApplyProgramMatrices(0.5f);
-mpProgram->SetVertices( pPoint );
-glDrawArrays( GL_POINTS, 0, 1 );
+mpProgram->DrawArrays(GL_POINTS, pPoint);
 CHECK_GL_ERROR();
 }
 
@@ -641,16 +639,13 @@ void OpenGLSalGraphicsImpl::DrawLine( double nX1, double 
nY1, double nX2, double
 {
 OpenGLZone aZone;
 
-GLfloat pPoints[4];
-
-pPoints[0] = GLfloat(nX1);
-pPoints[1] = GLfloat(nY1);
-pPoints[2] = GLfloat(nX2);
-pPoints[3] = GLfloat(nY2);
+std::vector pPoint {
+GLfloat(nX1), GLfloat(nY1),
+GLfloat(nX2), GLfloat(nY2)
+};
 
 ApplyProgramMatrices(0.5f);
-mpProgram->SetVertices( pPoints );
-glDrawArrays( GL_LINES, 

[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - vcl/inc vcl/opengl vcl/win

2016-05-11 Thread Tomaž Vajngerl
 vcl/inc/opengl/AccumulatedTextures.hxx |7 +
 vcl/opengl/PackedTextureAtlas.cxx  |8 +++---
 vcl/opengl/gdiimpl.cxx |7 -
 vcl/opengl/texture.cxx |   10 +---
 vcl/win/source/gdi/winlayout.cxx   |   39 +
 5 files changed, 46 insertions(+), 25 deletions(-)

New commits:
commit 5d7badd2f2341171733c5fabf111ecf9674bc3d4
Author: Tomaž Vajngerl 
Date:   Sat Apr 30 14:58:27 2016 +0900

tdf#99258 bail out if we fail to reserve the texture + more

(cherry picked from commit d22ca8d8cb050b9006720f39c612c5c32eab8795)

also includes coverity fixes from commits:

coverity#1358428 fix "Null pointer dereferences"
4e07c7e279b21c4ae93b832a65e221e2dab5391d

cid#1358836 reorganize to silence Resource leak in object
6e970c11645f1a05638e49da9e2911fe59628838

Check if we have an OpenGL context before using API that requires it
347e46da399b8cc96d9dd8dbfd62120db473b555

opengl: Check if texture is valid before asking for Id
0214aa8ce427905477602dbf1d55278c4959fcac

Change-Id: I830e313352b69a7665bff953aadb1334be0dc847
Reviewed-on: https://gerrit.libreoffice.org/24829
Tested-by: Jenkins 
Reviewed-by: Tor Lillqvist 
Tested-by: Tor Lillqvist 

diff --git a/vcl/inc/opengl/AccumulatedTextures.hxx 
b/vcl/inc/opengl/AccumulatedTextures.hxx
index e74c065..882a694 100644
--- a/vcl/inc/opengl/AccumulatedTextures.hxx
+++ b/vcl/inc/opengl/AccumulatedTextures.hxx
@@ -88,8 +88,11 @@ public:
 maEntries.clear();
 }
 
-void insert(OpenGLTexture& rTexture, const SalColor& aColor, const 
SalTwoRect& r2Rect)
+bool insert(OpenGLTexture& rTexture, const SalColor& aColor, const 
SalTwoRect& r2Rect)
 {
+if (!rTexture)
+return false;
+
 GLuint nTextureId = rTexture.Id();
 
 if (maEntries.find(nTextureId) == maEntries.end())
@@ -100,6 +103,8 @@ public:
 
 std::unique_ptr& rEntry = 
maEntries[nTextureId];
 rEntry->insert(rTexture, aColor, r2Rect);
+
+return true;
 }
 
 AccumulatedTexturesMap& getAccumulatedTexturesMap()
diff --git a/vcl/opengl/PackedTextureAtlas.cxx 
b/vcl/opengl/PackedTextureAtlas.cxx
index 0231cbd..c8e9c3f 100644
--- a/vcl/opengl/PackedTextureAtlas.cxx
+++ b/vcl/opengl/PackedTextureAtlas.cxx
@@ -110,7 +110,7 @@ Node* Node::insert(int nWidth, int nHeight, int nPadding)
 
 struct PackedTexture
 {
-ImplOpenGLTexture* mpTexture;
+std::unique_ptr mpTexture;
 std::unique_ptr mpRootNode;
 int mnDeallocatedArea;
 
@@ -132,7 +132,7 @@ PackedTextureAtlasManager::~PackedTextureAtlasManager()
 for (std::unique_ptr& pPackedTexture : maPackedTextures)
 {
 // Free texture early in VCL shutdown while we have a context.
-delete pPackedTexture->mpTexture;
+pPackedTexture->mpTexture.reset();
 }
 }
 
@@ -152,7 +152,7 @@ OpenGLTexture PackedTextureAtlasManager::Reserve(int 
nWidth, int nHeight)
 Node* pNode = pPackedTexture->mpRootNode->insert(nWidth, nHeight, 1);
 if (pNode != nullptr)
 {
-return OpenGLTexture(pPackedTexture->mpTexture, pNode->mRectangle, 
-1);
+return OpenGLTexture(pPackedTexture->mpTexture.get(), 
pNode->mRectangle, -1);
 }
 }
 CreateNewTexture();
@@ -160,7 +160,7 @@ OpenGLTexture PackedTextureAtlasManager::Reserve(int 
nWidth, int nHeight)
 Node* pNode = pPackedTexture->mpRootNode->insert(nWidth, nHeight, 1);
 if (pNode != nullptr)
 {
-return OpenGLTexture(pPackedTexture->mpTexture, pNode->mRectangle, -1);
+return OpenGLTexture(pPackedTexture->mpTexture.get(), 
pNode->mRectangle, -1);
 }
 return OpenGLTexture();
 }
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index d9640b9..c6139e8 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -2497,8 +2497,11 @@ void OpenGLSalGraphicsImpl::doFlush()
 {
 FlushDeferredDrawing();
 
-mpContext->state()->scissor().disable();
-mpContext->state()->stencil().disable();
+if (OpenGLContext::hasCurrent())
+{
+mpContext->state()->scissor().disable();
+mpContext->state()->stencil().disable();
+}
 
 if( IsOffscreen() )
 return;
diff --git a/vcl/opengl/texture.cxx b/vcl/opengl/texture.cxx
index 9f5f9a2..63e39b8 100644
--- a/vcl/opengl/texture.cxx
+++ b/vcl/opengl/texture.cxx
@@ -413,11 +413,11 @@ void 
OpenGLTexture::FillCoords(std::vector& aCoord, const
 GLfloat y1 = 0.0f;
 GLfloat y2 = 0.0f;
 
-double fTextureWidth(mpImpl->mnWidth);
-double fTextureHeight(mpImpl->mnHeight);
-
 if (mpImpl)
 {
+double fTextureWidth(mpImpl->mnWidth);
+double fTextureHeight(mpImpl->mnHeight);
+
 x1 = (maRect.Left() + rPosAry.mnSrcX) / fTextureWidth;
 x2 = (maRect.Left() + 

[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - vcl/inc vcl/opengl vcl/win

2016-04-18 Thread Tomaž Vajngerl
 vcl/inc/opengl/PackedTextureAtlas.hxx |6 +++
 vcl/opengl/PackedTextureAtlas.cxx |   44 ++
 vcl/win/source/gdi/winlayout.cxx  |   57 +++---
 3 files changed, 96 insertions(+), 11 deletions(-)

New commits:
commit f691a50a78c8f4f157fbb432efba059d723d
Author: Tomaž Vajngerl 
Date:   Mon Apr 11 18:23:18 2016 +0900

tdf#94682 limit the number of textures for the glyph texture atlas

Previously the number of textures in a packed texture atlas was
not limited. After some time the number of the textures could
grow quite a lot, however the first textures could contain very
little glyphs that are valid. In this commit we add a new method
ReduceTextureNumber which when called, reduces the number of
textures that are tracked by the texutre atlas to the specified
input number, and returnes the texture IDs that were removed so
the caller can now clean-up any invalid (OpenGLTexutre) objects.

Change-Id: I7790e8dddb4586167f860e0ecc81bda1f4dae21a
Reviewed-on: https://gerrit.libreoffice.org/24071
Tested-by: Jenkins 
Reviewed-by: Michael Meeks 

diff --git a/vcl/inc/opengl/PackedTextureAtlas.hxx 
b/vcl/inc/opengl/PackedTextureAtlas.hxx
index 17501f3..4d9015f 100644
--- a/vcl/inc/opengl/PackedTextureAtlas.hxx
+++ b/vcl/inc/opengl/PackedTextureAtlas.hxx
@@ -35,10 +35,16 @@ class VCL_PLUGIN_PUBLIC PackedTextureAtlasManager
 void CreateNewTexture();
 
 public:
+
+/**
+ * nTextureWidth and nTextureHeight are the dimensions of the common 
texture(s)
+ * nTextureLimit is the maximum limit of that a texture atlas can have (0 
or less - unlimited)
+ */
 PackedTextureAtlasManager(int nTextureWidth, int nTextureHeight);
 ~PackedTextureAtlasManager();
 OpenGLTexture InsertBuffer(int nWidth, int nHeight, int nFormat, int 
nType, sal_uInt8* pData);
 OpenGLTexture Reserve(int nWidth, int nHeight);
+std::vector ReduceTextureNumber(int nMaxNumberOfTextures);
 };
 
 #endif // INCLUDED_VCL_INC_OPENGL_PACKEDTEXTUREATLAS_HXX
diff --git a/vcl/opengl/PackedTextureAtlas.cxx 
b/vcl/opengl/PackedTextureAtlas.cxx
index 60fa1e9..0231cbd 100644
--- a/vcl/opengl/PackedTextureAtlas.cxx
+++ b/vcl/opengl/PackedTextureAtlas.cxx
@@ -24,12 +24,21 @@ struct Node
 std::unique_ptr mRightNode;
 bool mOccupied;
 
+Node(int nWidth, int nHeight);
+
 Node(Rectangle& aRectangle);
 
 bool isLeaf();
 Node* insert(int nWidth, int nHeight, int nPadding);
 };
 
+Node::Node(int nWidth, int nHeight)
+: mRectangle(Rectangle(Point(), Size(nWidth, nHeight)))
+, mLeftNode()
+, mRightNode()
+, mOccupied(false)
+{}
+
 Node::Node(Rectangle& aRectangle)
 : mRectangle(aRectangle)
 , mLeftNode()
@@ -101,8 +110,15 @@ Node* Node::insert(int nWidth, int nHeight, int nPadding)
 
 struct PackedTexture
 {
-std::unique_ptr mpRootNode;
 ImplOpenGLTexture* mpTexture;
+std::unique_ptr mpRootNode;
+int mnDeallocatedArea;
+
+PackedTexture(int nWidth, int nHeight)
+: mpTexture(new ImplOpenGLTexture(nWidth, nHeight, true))
+, mpRootNode(new Node(nWidth, nHeight))
+, mnDeallocatedArea(0)
+{}
 };
 
 PackedTextureAtlasManager::PackedTextureAtlasManager(int nTextureWidth, int 
nTextureHeight)
@@ -116,18 +132,17 @@ PackedTextureAtlasManager::~PackedTextureAtlasManager()
 for (std::unique_ptr& pPackedTexture : maPackedTextures)
 {
 // Free texture early in VCL shutdown while we have a context.
-pPackedTexture->mpTexture->Dispose();
-pPackedTexture->mpTexture->DecreaseRefCount(0);
+delete pPackedTexture->mpTexture;
 }
 }
 
 void PackedTextureAtlasManager::CreateNewTexture()
 {
-std::unique_ptr pPackedTexture(new PackedTexture);
-pPackedTexture->mpTexture = new ImplOpenGLTexture(mnTextureWidth, 
mnTextureHeight, true);
-Rectangle aInitialRect(Point(0, 0), Size(mnTextureWidth, mnTextureHeight));
-pPackedTexture->mpRootNode.reset(new Node(aInitialRect));
+std::unique_ptr pPackedTexture(new 
PackedTexture(mnTextureWidth, mnTextureHeight));
+GLuint nTextureID = pPackedTexture->mpTexture->mnTexture;
 maPackedTextures.push_back(std::move(pPackedTexture));
+VCL_GL_INFO("PackedTextureAtlas::CreateNewTexture adding texture: " << 
nTextureID <<
+" atlases: " << maPackedTextures.size());
 }
 
 OpenGLTexture PackedTextureAtlasManager::Reserve(int nWidth, int nHeight)
@@ -161,4 +176,19 @@ OpenGLTexture PackedTextureAtlasManager::InsertBuffer(int 
nWidth, int nHeight, i
 return aTexture;
 }
 
+std::vector PackedTextureAtlasManager::ReduceTextureNumber(int 
nMaxNumberOfTextures)
+{
+std::vector aTextureIDs;
+while (int(maPackedTextures.size()) > nMaxNumberOfTextures)
+{
+// Remove oldest created texture
+GLuint nTextureID = 

[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - vcl/inc vcl/opengl

2016-02-10 Thread Tomaž Vajngerl
 vcl/inc/opengl/salbmp.hxx |2 --
 vcl/opengl/salbmp.cxx |   23 ++-
 vcl/opengl/scale.cxx  |6 --
 3 files changed, 6 insertions(+), 25 deletions(-)

New commits:
commit 30e32035adfb053637ca68127bedd68a938e7332
Author: Tomaž Vajngerl 
Date:   Tue Feb 9 23:23:54 2016 +0100

opengl: remove unneeded mnBufWidth{Height} from OpenGLSalBitmap

Reviewed-on: https://gerrit.libreoffice.org/22258
Tested-by: Jenkins 
Reviewed-by: Michael Meeks 
(cherry picked from commit b4c6cf513c5bb0ed02b95bbdbb0879a78c1eca65)

Change-Id: Idf445b9f6b403a0d37650c14e17b7d754451edf1
Reviewed-on: https://gerrit.libreoffice.org/22264
Tested-by: Jenkins 
Reviewed-by: Michael Meeks 
Tested-by: Michael Meeks 

diff --git a/vcl/inc/opengl/salbmp.hxx b/vcl/inc/opengl/salbmp.hxx
index 4b34027..8917a5a 100644
--- a/vcl/inc/opengl/salbmp.hxx
+++ b/vcl/inc/opengl/salbmp.hxx
@@ -47,8 +47,6 @@ private:
 sal_uInt16  mnBytesPerRow;
 int mnWidth;
 int mnHeight;
-int mnBufWidth;
-int mnBufHeight;
 std::deque< OpenGLSalBitmapOp* >maPendingOps;
 
 virtual void updateChecksum() const override;
diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx
index 61d7575..e0205f0 100644
--- a/vcl/opengl/salbmp.cxx
+++ b/vcl/opengl/salbmp.cxx
@@ -113,8 +113,6 @@ OpenGLSalBitmap::OpenGLSalBitmap()
 , mnBytesPerRow(0)
 , mnWidth(0)
 , mnHeight(0)
-, mnBufWidth(0)
-, mnBufHeight(0)
 {
 }
 
@@ -135,8 +133,6 @@ bool OpenGLSalBitmap::Create( const OpenGLTexture& rTex, 
long nX, long nY, long
 
 mnWidth = nWidth;
 mnHeight = nHeight;
-mnBufWidth = 0;
-mnBufHeight = 0;
 
 // TODO Check the framebuffer configuration
 mnBits = 32;
@@ -166,8 +162,8 @@ bool OpenGLSalBitmap::Create( const Size& rSize, sal_uInt16 
nBits, const BitmapP
 return false;
 maPalette = rBitmapPalette;
 mnBits = nBits;
-mnWidth = mnBufWidth = rSize.Width();
-mnHeight = mnBufHeight = rSize.Height();
+mnWidth = rSize.Width();
+mnHeight = rSize.Height();
 return false;
 }
 
@@ -201,8 +197,6 @@ bool OpenGLSalBitmap::Create( const SalBitmap& rSalBmp, 
sal_uInt16 nNewBitCount
 mnBytesPerRow = rSourceBitmap.mnBytesPerRow;
 mnWidth = rSourceBitmap.mnWidth;
 mnHeight = rSourceBitmap.mnHeight;
-mnBufWidth = rSourceBitmap.mnBufWidth;
-mnBufHeight = rSourceBitmap.mnBufHeight;
 maPalette = rSourceBitmap.maPalette;
 // execute any pending operations on the source bitmap
 maTexture = rSourceBitmap.GetTexture();
@@ -472,7 +466,7 @@ GLuint OpenGLSalBitmap::CreateTexture()
 VCL_GL_INFO( "::CreateTexture - convert from " << mnBits << " to 
24 bits" );
 
 // convert to 24 bits RGB using palette
-pData = new sal_uInt8[mnBufHeight * mnBufWidth * 3];
+pData = new sal_uInt8[mnHeight * mnWidth * 3];
 bAllocated = true;
 determineTextureFormat(24, nFormat, nType);
 
@@ -481,12 +475,12 @@ GLuint OpenGLSalBitmap::CreateTexture()
 sal_uInt8* pSrcData = maUserBuffer.get();
 sal_uInt8* pDstData = pData;
 
-sal_uInt32 nY = mnBufHeight;
+sal_uInt32 nY = mnHeight;
 while( nY-- )
 {
 pSrcFormat->StartLine( pSrcData );
 
-sal_uInt32 nX = mnBufWidth;
+sal_uInt32 nX = mnWidth;
 if (nFormat == GL_BGR)
 {
 while( nX-- )
@@ -515,7 +509,7 @@ GLuint OpenGLSalBitmap::CreateTexture()
 
 OpenGLVCLContextZone aContextZone;
 
-lclInstantiateTexture(maTexture, mnBufWidth, mnBufHeight, nFormat, nType, 
pData);
+lclInstantiateTexture(maTexture, mnWidth, mnHeight, nFormat, nType, pData);
 
 VCL_GL_INFO("Created texture " << maTexture.Id() << " bits: " << mnBits);
 
@@ -559,9 +553,6 @@ bool OpenGLSalBitmap::ReadTexture()
 size_t nCanary = static_cast(mnBytesPerRow) * mnHeight;
 assert(!memcmp(pData + nCanary, CANARY, sizeof (CANARY)));
 #endif
-
-mnBufWidth = mnWidth;
-mnBufHeight = mnHeight;
 return true;
 }
 else if (mnBits == 1)
@@ -602,8 +593,6 @@ bool OpenGLSalBitmap::ReadTexture()
 nIndex++;
 pData[nIndex] = 0;
 }
-mnBufWidth = mnWidth;
-mnBufHeight = mnHeight;
 return true;
 }
 
diff --git a/vcl/opengl/scale.cxx b/vcl/opengl/scale.cxx
index a971b15e..80bbdd6 100644
--- a/vcl/opengl/scale.cxx
+++ b/vcl/opengl/scale.cxx
@@ -68,8 +68,6 @@ bool OpenGLSalBitmap::ImplScaleFilter(
 
 mnWidth = nNewWidth;
 mnHeight = nNewHeight;
-

[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - vcl/inc vcl/opengl vcl/Package_opengl.mk vcl/source vcl/workben

2016-02-09 Thread Tomaž Vajngerl
 vcl/Package_opengl.mk   |1 
 vcl/inc/impbmp.hxx  |1 
 vcl/inc/opengl/salbmp.hxx   |1 
 vcl/inc/salbmp.hxx  |4 +++
 vcl/opengl/greyscaleFragmentShader.glsl |   18 
 vcl/opengl/salbmp.cxx   |   36 
 vcl/source/gdi/bitmap3.cxx  |   17 +++
 vcl/source/gdi/impbmp.cxx   |   10 
 vcl/workben/vcldemo.cxx |   13 +++
 9 files changed, 101 insertions(+)

New commits:
commit bf546575116f7f67fe12a735bf8c8689a65bfdc1
Author: Tomaž Vajngerl 
Date:   Mon Feb 8 22:25:59 2016 +0100

tdf#97666 - opengl: convert the bitmap to 8bit grays using GL shader

Change-Id: I4d48d29ab752814f71c697a201e70a26ae937775
Reviewed-on: https://gerrit.libreoffice.org/3
Reviewed-by: Tor Lillqvist 
Tested-by: Tor Lillqvist 
Signed-off-by: Michael Meeks 

diff --git a/vcl/Package_opengl.mk b/vcl/Package_opengl.mk
index 9d42502..b8851df 100644
--- a/vcl/Package_opengl.mk
+++ b/vcl/Package_opengl.mk
@@ -17,6 +17,7 @@ $(eval $(call 
gb_Package_add_files,vcl_opengl_shader,$(LIBO_ETC_FOLDER)/opengl,\
blendedTextureVertexShader.glsl \
dumbVertexShader.glsl \
diffTextureFragmentShader.glsl \
+   greyscaleFragmentShader.glsl \
 invert50FragmentShader.glsl \
convolutionFragmentShader.glsl \
linearGradientFragmentShader.glsl \
diff --git a/vcl/inc/impbmp.hxx b/vcl/inc/impbmp.hxx
index f2bd27d..9527c5d 100644
--- a/vcl/inc/impbmp.hxx
+++ b/vcl/inc/impbmp.hxx
@@ -74,6 +74,7 @@ public:
 
 boolImplScale( const double& rScaleX, const double& 
rScaleY, BmpScaleFlag nScaleFlag );
 boolImplReplace( const Color& rSearchColor, const Color& 
rReplaceColor, sal_uLong nTol );
+boolImplConvert( BmpConversion eConversion );
 };
 
 #endif // INCLUDED_VCL_INC_IMPBMP_HXX
diff --git a/vcl/inc/opengl/salbmp.hxx b/vcl/inc/opengl/salbmp.hxx
index 7d1efa3..4b34027 100644
--- a/vcl/inc/opengl/salbmp.hxx
+++ b/vcl/inc/opengl/salbmp.hxx
@@ -82,6 +82,7 @@ public:
 
 boolScale( const double& rScaleX, const double& rScaleY, 
BmpScaleFlag nScaleFlag ) override;
 boolReplace( const Color& rSearchColor, const Color& 
rReplaceColor, sal_uLong nTol ) override;
+boolConvertToGreyscale() override;
 
 public:
 
diff --git a/vcl/inc/salbmp.hxx b/vcl/inc/salbmp.hxx
index 49d2657..49b8319 100644
--- a/vcl/inc/salbmp.hxx
+++ b/vcl/inc/salbmp.hxx
@@ -71,6 +71,10 @@ public:
 virtual boolScale( const double& rScaleX, const double& 
rScaleY, BmpScaleFlag nScaleFlag ) = 0;
 virtual boolReplace( const Color& rSearchColor, const Color& 
rReplaceColor, sal_uLong nTol ) = 0;
 
+virtual boolConvertToGreyscale()
+{
+return false;
+}
 
 bool GetChecksum(ChecksumType& rChecksum) const
 {
diff --git a/vcl/opengl/greyscaleFragmentShader.glsl 
b/vcl/opengl/greyscaleFragmentShader.glsl
new file mode 100644
index 000..758109e
--- /dev/null
+++ b/vcl/opengl/greyscaleFragmentShader.glsl
@@ -0,0 +1,18 @@
+/* -*- 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/.
+ */
+
+varying vec2 tex_coord;
+uniform sampler2D sampler;
+
+void main() {
+vec4 texel = texture2D(sampler, tex_coord);
+gl_FragColor = vec4(vec3(dot(texel.rgb, vec3(0.301, 0.591, 0.108))), 1.0);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx
index 03497dc..7f0d66b 100644
--- a/vcl/opengl/salbmp.cxx
+++ b/vcl/opengl/salbmp.cxx
@@ -900,4 +900,40 @@ bool OpenGLSalBitmap::Replace( const Color& rSearchColor, 
const Color& rReplaceC
 return true;
 }
 
+// Convert texture to greyscale and adjust bitmap metadata
+bool OpenGLSalBitmap::ConvertToGreyscale()
+{
+VCL_GL_INFO("::ConvertToGreyscale");
+
+// avoid re-converting to 8bits.
+if ( mnBits == 8 && maPalette == Bitmap::GetGreyPalette(256) )
+return false;
+
+OpenGLZone aZone;
+rtl::Reference xContext = OpenGLContext::getVCLContext();
+
+OpenGLFramebuffer* pFramebuffer;
+OpenGLProgram* pProgram;
+
+GetTexture();
+pProgram = xContext->UseProgram("textureVertexShader", 
"greyscaleFragmentShader");
+
+if (!pProgram)
+return false;
+
+OpenGLTexture aNewTex(mnWidth, mnHeight);
+pFramebuffer = xContext->AcquireFramebuffer(aNewTex);
+pProgram->SetTexture("sampler", maTexture);
+pProgram->DrawTexture(maTexture);
+

[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - vcl/inc vcl/opengl

2016-02-08 Thread Michael Meeks
 vcl/inc/opengl/win/WinDeviceInfo.hxx |1 -
 vcl/opengl/win/WinDeviceInfo.cxx |   33 -
 2 files changed, 34 deletions(-)

New commits:
commit 22b852788d94ecacde533e3961a3535ef2a89f7d
Author: Michael Meeks 
Date:   Mon Feb 8 17:11:28 2016 +

tdf#97458 - remove unused intel opengl driver version special-casing.

Change-Id: I938bcab02edb37a5e7d72f1551867e0f5a4dd89b
Reviewed-on: https://gerrit.libreoffice.org/22215
Tested-by: Jenkins 
Reviewed-by: Bryan Quigley 
Reviewed-by: Michael Meeks 
Reviewed-on: https://gerrit.libreoffice.org/22217
Reviewed-by: Tor Lillqvist 
Tested-by: Tor Lillqvist 

diff --git a/vcl/inc/opengl/win/WinDeviceInfo.hxx 
b/vcl/inc/opengl/win/WinDeviceInfo.hxx
index 9954983..974d6b3 100644
--- a/vcl/inc/opengl/win/WinDeviceInfo.hxx
+++ b/vcl/inc/opengl/win/WinDeviceInfo.hxx
@@ -143,7 +143,6 @@ private:
 uint32_t mnWindowsVersion;
 
 bool mbHasDualGPU;
-bool mbHasDriverVersionMismatch;
 bool mbRDP;
 
 void GetData();
diff --git a/vcl/opengl/win/WinDeviceInfo.cxx b/vcl/opengl/win/WinDeviceInfo.cxx
index 81e8d68..3f226c3 100644
--- a/vcl/opengl/win/WinDeviceInfo.cxx
+++ b/vcl/opengl/win/WinDeviceInfo.cxx
@@ -421,7 +421,6 @@ DriverInfo::~DriverInfo()
 
 WinOpenGLDeviceInfo::WinOpenGLDeviceInfo():
 mbHasDualGPU(false),
-mbHasDriverVersionMismatch(false),
 mbRDP(false)
 {
 GetData();
@@ -851,38 +850,6 @@ void WinOpenGLDeviceInfo::GetData()
 SetupDiDestroyDeviceInfoList(devinfo);
 }
 }
-
-mbHasDriverVersionMismatch = false;
-if (maAdapterVendorID == GetDeviceVendor(wgl::VendorIntel))
-{
-// we've had big crashes (moz#590373 and moz#595364) apparently 
correlated
-// with bad Intel driver installations where the DriverVersion reported
-// by the registry was not the version of the DLL.
-OUString aDLLFileName("igd10umd32.dll");
-OUString aDLLFileName2("igd10iumd32.dll");
-OUString aDLLVersion, aDLLVersion2;
-GetDLLVersion(aDLLFileName.getStr(), aDLLVersion);
-GetDLLVersion(aDLLFileName2.getStr(), aDLLVersion2);
-
-uint64_t dllNumericVersion = 0, dllNumericVersion2 = 0,
- driverNumericVersion = 0, knownSafeMismatchVersion = 0;
-wgl::ParseDriverVersion(aDLLVersion, dllNumericVersion);
-wgl::ParseDriverVersion(aDLLVersion2, dllNumericVersion2);
-wgl::ParseDriverVersion(maDriverVersion, driverNumericVersion);
-wgl::ParseDriverVersion("9.17.10.0", knownSafeMismatchVersion);
-
-// If there's a driver version mismatch, consider this harmful only 
when
-// the driver version is less than knownSafeMismatchVersion.  See the
-// above comment about crashes with old mismatches. If the 
GetDllVersion
-// call fails, then they return 0, so that will be considered a 
mismatch.
-if (dllNumericVersion != driverNumericVersion &&
-dllNumericVersion2 != driverNumericVersion &&
-(driverNumericVersion < knownSafeMismatchVersion ||
- std::max(dllNumericVersion, dllNumericVersion2) < 
knownSafeMismatchVersion))
-{
-mbHasDriverVersionMismatch = true;
-}
-}
 }
 
 // Macro for assigning a device vendor id to a string.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - vcl/inc vcl/opengl vcl/workben

2016-01-11 Thread Michael Meeks
 vcl/inc/openglgdiimpl.hxx |7 ++-
 vcl/opengl/gdiimpl.cxx|   45 +++--
 vcl/workben/vcldemo.cxx   |4 +++-
 3 files changed, 40 insertions(+), 16 deletions(-)

New commits:
commit 1b2a60dbde98034125aa30551c12bcf0d1c420b8
Author: Michael Meeks 
Date:   Fri Jan 8 22:33:11 2016 +

tdf#96919 - vcl opengl: implement missing XOR mode.

Also revert "tdf#96257: Silly work-around to produce same result ..."
from commit ec8bc265050d86a749140c353360a78cce4e3fce.

XOR rendering (it turns out) behaves oddly, and not for all operations.

Change-Id: Ie07d988bbf7fed10fb5625ac547a01a306b05319
Reviewed-on: https://gerrit.libreoffice.org/21282
Tested-by: Jenkins 
Reviewed-by: Michael Meeks 
Reviewed-on: https://gerrit.libreoffice.org/21288
Reviewed-by: Tor Lillqvist 
Tested-by: Tor Lillqvist 

diff --git a/vcl/inc/openglgdiimpl.hxx b/vcl/inc/openglgdiimpl.hxx
index 14beab5..a178d18 100644
--- a/vcl/inc/openglgdiimpl.hxx
+++ b/vcl/inc/openglgdiimpl.hxx
@@ -80,6 +80,8 @@ protected:
 bool mbUseScissor;
 bool mbUseStencil;
 
+bool mbXORMode;
+
 /**
  * All rendering happens to this off-screen texture. For
  * non-virtual devices, ie. windows - we will blit it and
@@ -152,8 +154,11 @@ public:
  */
 bool IsOffscreen() const { return mpProvider == nullptr || 
mpProvider->IsOffScreen(); }
 
+/// Oddly not all operations obey the XOR option.
+enum XOROption { IGNORE_XOR, IMPLEMENT_XOR };
+
 // operations to do before painting
-void PreDraw();
+void PreDraw(XOROption eOpt = IGNORE_XOR);
 
 // operations to do after painting
 void PostDraw();
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index 8c31f5e..7304a1a 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -68,6 +68,7 @@ OpenGLSalGraphicsImpl::OpenGLSalGraphicsImpl(SalGraphics& 
rParent, SalGeometryPr
 , mpFlush(new OpenGLFlushIdle(this))
 , mbUseScissor(false)
 , mbUseStencil(false)
+, mbXORMode(false)
 , mnLineColor(SALCOLOR_NONE)
 , mnFillColor(SALCOLOR_NONE)
 #ifdef DBG_UTIL
@@ -176,7 +177,7 @@ void OpenGLSalGraphicsImpl::DeInit()
 mpContext.clear();
 }
 
-void OpenGLSalGraphicsImpl::PreDraw()
+void OpenGLSalGraphicsImpl::PreDraw(XOROption eOpt)
 {
 OpenGLZone::enter();
 
@@ -196,13 +197,27 @@ void OpenGLSalGraphicsImpl::PreDraw()
 
 glViewport( 0, 0, GetWidth(), GetHeight() );
 CHECK_GL_ERROR();
-ImplInitClipRegion();
 
+ImplInitClipRegion();
 CHECK_GL_ERROR();
+
+if (eOpt == IMPLEMENT_XOR && mbXORMode)
+{
+glEnable(GL_COLOR_LOGIC_OP);
+CHECK_GL_ERROR();
+
+glLogicOp(GL_XOR);
+}
 }
 
 void OpenGLSalGraphicsImpl::PostDraw()
 {
+if (mbXORMode)
+{
+glDisable(GL_COLOR_LOGIC_OP);
+CHECK_GL_ERROR();
+}
+
 if( mbUseScissor )
 {
 glDisable( GL_SCISSOR_TEST );
@@ -404,8 +419,9 @@ void OpenGLSalGraphicsImpl::SetFillColor( SalColor 
nSalColor )
 }
 
 // enable/disable XOR drawing
-void OpenGLSalGraphicsImpl::SetXORMode( bool /*bSet*/, bool /*bInvertOnly*/ )
+void OpenGLSalGraphicsImpl::SetXORMode( bool bSet, bool )
 {
+mbXORMode = bSet;
 }
 
 // set line color for raster operations
@@ -503,6 +519,7 @@ bool OpenGLSalGraphicsImpl::UseSolid( SalColor nColor, 
sal_uInt8 nTransparency )
 #endif
 mProgramSolidColor = nColor;
 mProgramSolidTransparency = nTransparency / 100.0;
+
 return true;
 }
 
@@ -1331,7 +1348,7 @@ void OpenGLSalGraphicsImpl::drawPixel( long nX, long nY )
 VCL_GL_INFO( "::drawPixel" );
 if( mnLineColor != SALCOLOR_NONE )
 {
-PreDraw();
+PreDraw( XOROption::IMPLEMENT_XOR );
 if( UseSolid( mnLineColor ) )
 DrawPoint( nX, nY );
 PostDraw();
@@ -1343,7 +1360,7 @@ void OpenGLSalGraphicsImpl::drawPixel( long nX, long nY, 
SalColor nSalColor )
 VCL_GL_INFO( "::drawPixel" );
 if( nSalColor != SALCOLOR_NONE )
 {
-PreDraw();
+PreDraw( XOROption::IMPLEMENT_XOR );
 if( UseSolid( nSalColor ) )
 DrawPoint( nX, nY );
 PostDraw();
@@ -1355,7 +1372,7 @@ void OpenGLSalGraphicsImpl::drawLine( long nX1, long nY1, 
long nX2, long nY2 )
 VCL_GL_INFO( "::drawLine" );
 if( mnLineColor != SALCOLOR_NONE )
 {
-PreDraw();
+PreDraw( XOROption::IMPLEMENT_XOR );
 if( UseSolidAA( mnLineColor ) )
 DrawLineAA( nX1, nY1, nX2, nY2 );
 PostDraw();
@@ -1365,7 +1382,7 @@ void OpenGLSalGraphicsImpl::drawLine( long nX1, long nY1, 
long nX2, long nY2 )
 void OpenGLSalGraphicsImpl::drawRect( long nX, long nY, long nWidth, long 
nHeight )
 {
 VCL_GL_INFO( "::drawRect" );
-PreDraw();
+PreDraw( XOROption::IMPLEMENT_XOR );
 
 if( UseSolid( mnFillColor ) )
 

[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - vcl/inc vcl/opengl

2016-01-07 Thread Michael Meeks
 vcl/inc/opengl/FixedTextureAtlas.hxx |3 ++-
 vcl/inc/opengl/texture.hxx   |   10 +++---
 vcl/opengl/FixedTextureAtlas.cxx |   22 --
 vcl/opengl/salbmp.cxx|   15 ++-
 vcl/opengl/texture.cxx   |   19 ++-
 vcl/opengl/x11/gdiimpl.cxx   |   12 +++-
 6 files changed, 52 insertions(+), 29 deletions(-)

New commits:
commit ab1eed777a2e5fa94fdde1cc8260cf8ad264c145
Author: Michael Meeks 
Date:   Mon Jan 4 21:51:28 2016 +

tdf#96894 - get ordering right for TextureAtlas cleanup on shutdown.

Do it much earlier - while we have a valid OpenGLContext.
FixedTextureAtlasManager should also use ref-counted textures properly.
Also - dispose embedded textures early in VCL shutdown while we have
a valid OpenGLContext.
Also - dispose the native widget control cache earlier too.

Change-Id: Ie258283147d02984b6f507c0075d114ae7288051
Reviewed-on: https://gerrit.libreoffice.org/21089
Reviewed-by: Michael Meeks 
Tested-by: Michael Meeks 
Reviewed-on: https://gerrit.libreoffice.org/21119
Tested-by: Jenkins 
Reviewed-by: Tor Lillqvist 

diff --git a/vcl/inc/opengl/FixedTextureAtlas.hxx 
b/vcl/inc/opengl/FixedTextureAtlas.hxx
index 3627140..5b22b619 100644
--- a/vcl/inc/opengl/FixedTextureAtlas.hxx
+++ b/vcl/inc/opengl/FixedTextureAtlas.hxx
@@ -16,7 +16,7 @@
 
 class VCL_PLUGIN_PUBLIC FixedTextureAtlasManager
 {
-std::vector mpTextures;
+std::vector mpTextures;
 
 int mWidthFactor;
 int mHeightFactor;
@@ -26,6 +26,7 @@ class VCL_PLUGIN_PUBLIC FixedTextureAtlasManager
 
 public:
 FixedTextureAtlasManager(int nWidthFactor, int nHeightFactor, int 
nTextureSize);
+~FixedTextureAtlasManager();
 OpenGLTexture InsertBuffer(int nWidth, int nHeight, int nFormat, int 
nType, sal_uInt8* pData);
 
 int GetSubtextureSize()
diff --git a/vcl/inc/opengl/texture.hxx b/vcl/inc/opengl/texture.hxx
index e57aa9e..9388918 100644
--- a/vcl/inc/opengl/texture.hxx
+++ b/vcl/inc/opengl/texture.hxx
@@ -31,8 +31,8 @@
 
 class ImplOpenGLTexture
 {
-public:
 intmnRefCount;
+public:
 GLuint mnTexture;
 intmnWidth;
 intmnHeight;
@@ -47,6 +47,7 @@ public:
 ImplOpenGLTexture( int nWidth, int nHeight, int nFormat, int nType, void 
const * pData );
 ImplOpenGLTexture( int nX, int nY, int nWidth, int nHeight );
 ~ImplOpenGLTexture();
+void Dispose();
 
 bool InsertBuffer(int nX, int nY, int nWidth, int nHeight, int nFormat, 
int nType, sal_uInt8* pData);
 
@@ -70,11 +71,14 @@ public:
 if (mpSlotReferences->at(nSlotNumber) == 0)
 mnFreeSlots++;
 }
+
+if (mnRefCount <= 0)
+delete this;
 }
 
-bool ExistRefs()
+bool IsUnique()
 {
-return mnRefCount > 0;
+return mnRefCount == 1;
 }
 
 bool InitializeSlots(int nSlotSize);
diff --git a/vcl/opengl/FixedTextureAtlas.cxx b/vcl/opengl/FixedTextureAtlas.cxx
index 8a3e927..80c1cfe 100644
--- a/vcl/opengl/FixedTextureAtlas.cxx
+++ b/vcl/opengl/FixedTextureAtlas.cxx
@@ -24,11 +24,21 @@ FixedTextureAtlasManager::FixedTextureAtlasManager(int 
nWidthFactor, int nHeight
 {
 }
 
+FixedTextureAtlasManager::~FixedTextureAtlasManager()
+{
+for (auto i = mpTextures.begin(); i != mpTextures.end(); ++i)
+{
+// Free texture early in VCL shutdown while we have a context.
+(*i)->Dispose();
+(*i)->DecreaseRefCount(0);
+}
+}
+
 void FixedTextureAtlasManager::CreateNewTexture()
 {
 int nTextureWidth = mWidthFactor  * mSubTextureSize;
 int nTextureHeight = mHeightFactor * mSubTextureSize;
-mpTextures.push_back(std::unique_ptr(new 
ImplOpenGLTexture(nTextureWidth, nTextureHeight, true)));
+mpTextures.push_back(new ImplOpenGLTexture(nTextureWidth, nTextureHeight, 
true));
 mpTextures.back()->InitializeSlots(mWidthFactor * mHeightFactor);
 }
 
@@ -36,21 +46,21 @@ OpenGLTexture FixedTextureAtlasManager::InsertBuffer(int 
nWidth, int nHeight, in
 {
 ImplOpenGLTexture* pTexture = nullptr;
 
-auto funFreeSlot = [] (std::unique_ptr& mpTexture)
+auto funFreeSlot = [] (ImplOpenGLTexture *mpTexture)
 {
 return mpTexture->mnFreeSlots > 0;
 };
 
-auto aIterator = std::find_if(mpTextures.begin(), mpTextures.end(), 
funFreeSlot);
+auto it = std::find_if(mpTextures.begin(), mpTextures.end(), funFreeSlot);
 
-if (aIterator != mpTextures.end())
+if (it != mpTextures.end())
 {
-pTexture = (*aIterator).get();
+pTexture = *it;
 }
 else
 {
 CreateNewTexture();
-pTexture = mpTextures.back().get();
+pTexture = mpTextures.back();
 }
 
 int nSlot = pTexture->FindFreeSlot();
diff --git a/vcl/opengl/salbmp.cxx 

[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - vcl/inc vcl/opengl vcl/Package_opengl.mk vcl/workben

2015-12-31 Thread Michael Meeks
 vcl/Package_opengl.mk  |1 
 vcl/inc/openglgdiimpl.hxx  |3 +
 vcl/opengl/gdiimpl.cxx |   60 ++---
 vcl/opengl/invert50FragmentShader.glsl |   23 
 vcl/workben/vcldemo.cxx|   11 +-
 5 files changed, 62 insertions(+), 36 deletions(-)

New commits:
commit b3da866919c9a6904f8b007bbe018846dcf7f35c
Author: Michael Meeks 
Date:   Thu Dec 31 21:19:48 2015 +

tdf#95507 - implement opengl / 50% invert method.

Change-Id: I8488cb8e8074831a6f81e6c8c122462c9819d25d
Reviewed-on: https://gerrit.libreoffice.org/21026
Tested-by: Jenkins 
Reviewed-by: Michael Meeks 

diff --git a/vcl/Package_opengl.mk b/vcl/Package_opengl.mk
index df3520c..9d42502 100644
--- a/vcl/Package_opengl.mk
+++ b/vcl/Package_opengl.mk
@@ -17,6 +17,7 @@ $(eval $(call 
gb_Package_add_files,vcl_opengl_shader,$(LIBO_ETC_FOLDER)/opengl,\
blendedTextureVertexShader.glsl \
dumbVertexShader.glsl \
diffTextureFragmentShader.glsl \
+invert50FragmentShader.glsl \
convolutionFragmentShader.glsl \
linearGradientFragmentShader.glsl \
maskFragmentShader.glsl \
diff --git a/vcl/inc/openglgdiimpl.hxx b/vcl/inc/openglgdiimpl.hxx
index c4fa5c2..647c83f 100644
--- a/vcl/inc/openglgdiimpl.hxx
+++ b/vcl/inc/openglgdiimpl.hxx
@@ -111,7 +111,8 @@ public:
 bool UseSolid( SalColor nColor );
 bool UseSolidAA( SalColor nColor, double fTransparency );
 bool UseSolidAA( SalColor nColor );
-bool UseInvert();
+bool UseInvert50();
+bool UseInvert(SalInvert nFlags);
 
 void DrawPoint( long nX, long nY );
 void DrawLine( double nX1, double nY1, double nX2, double nY2 );
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index a5cec8a..e92b6b6 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -551,6 +551,13 @@ bool OpenGLSalGraphicsImpl::UseSolid( SalColor nColor, 
double fTransparency )
 return true;
 }
 
+bool OpenGLSalGraphicsImpl::UseInvert50()
+{
+if( !UseProgram( "dumbVertexShader", "invert50FragmentShader" ) )
+return false;
+return true;
+}
+
 bool OpenGLSalGraphicsImpl::UseSolid( SalColor nColor )
 {
 return UseSolid( nColor, 0.0f );
@@ -575,13 +582,24 @@ bool OpenGLSalGraphicsImpl::UseSolidAA( SalColor nColor )
 return UseSolidAA( nColor, 0.0 );
 }
 
-bool OpenGLSalGraphicsImpl::UseInvert()
+bool OpenGLSalGraphicsImpl::UseInvert( SalInvert nFlags )
 {
 OpenGLZone aZone;
 
-if( !UseSolid( MAKE_SALCOLOR( 255, 255, 255 ) ) )
-return false;
-mpProgram->SetBlendMode( GL_ONE_MINUS_DST_COLOR, GL_ZERO );
+if( ( nFlags & SAL_INVERT_50 ) ||
+( nFlags & SAL_INVERT_TRACKFRAME ) )
+{
+if( !UseInvert50() )
+return false;
+mpProgram->SetBlendMode( GL_ONE_MINUS_DST_COLOR,
+ GL_ONE_MINUS_SRC_COLOR );
+}
+else
+{
+if( !UseSolid( MAKE_SALCOLOR( 255, 255, 255 ) ) )
+return false;
+mpProgram->SetBlendMode( GL_ONE_MINUS_DST_COLOR, GL_ZERO );
+}
 return true;
 }
 
@@ -1737,25 +1755,10 @@ void OpenGLSalGraphicsImpl::invert(
 long nWidth, long nHeight,
 SalInvert nFlags)
 {
-// TODO Figure out what are those:
-//   * SAL_INVERT_50 (50/50 pattern?)
-//   * SAL_INVERT_TRACKFRAME (dash-line rectangle?)
-
 PreDraw();
 
-if( nFlags & SAL_INVERT_TRACKFRAME )
-{
-
-}
-else if( nFlags & SAL_INVERT_50 )
-{
-
-}
-else // just invert
-{
-if( UseInvert() )
-DrawRect( nX, nY, nWidth, nHeight );
-}
+if( UseInvert( nFlags ) )
+DrawRect( nX, nY, nWidth, nHeight );
 
 PostDraw();
 }
@@ -1764,19 +1767,8 @@ void OpenGLSalGraphicsImpl::invert( sal_uInt32 nPoints, 
const SalPoint* pPtAry,
 {
 PreDraw();
 
-if( nFlags & SAL_INVERT_TRACKFRAME )
-{
-
-}
-else if( nFlags & SAL_INVERT_50 )
-{
-
-}
-else // just invert
-{
-if( UseInvert() )
-DrawPolygon( nPoints, pPtAry );
-}
+if( UseInvert( nFlags ) )
+DrawPolygon( nPoints, pPtAry );
 
 PostDraw();
 }
diff --git a/vcl/opengl/invert50FragmentShader.glsl 
b/vcl/opengl/invert50FragmentShader.glsl
new file mode 100644
index 000..76f3e1f
--- /dev/null
+++ b/vcl/opengl/invert50FragmentShader.glsl
@@ -0,0 +1,23 @@
+/* -*- 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/.
+ */
+
+/*precision mediump float;*/
+
+void main() {
+vec2 tex_mod = mod(gl_FragCoord, 2);
+bool bLeft = tex_mod.x > 0 && tex_mod.x < 1;
+   

[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - vcl/inc vcl/opengl vcl/source

2015-12-23 Thread Michael Meeks
 vcl/inc/openglgdiimpl.hxx |2 +-
 vcl/inc/svdata.hxx|1 +
 vcl/opengl/gdiimpl.cxx|   44 +++-
 vcl/source/app/svdata.cxx |   19 ++-
 4 files changed, 39 insertions(+), 27 deletions(-)

New commits:
commit 2a27d83ad8b2cab3af86624f58c183f78c2a67b8
Author: Michael Meeks 
Date:   Thu Dec 10 18:31:04 2015 +

vcl: opengl - lean on the default window's context much more.

Avoid creating our own OpenGLContext to render until we need to
refresh the screen. Also always re-use context from default window.
This simplifies our OpenGL Context use significantly, and avoids
problems with the initial default context getting destroyed in
some cases.

Change-Id: Ic2239236d3e1f14fd27979c9aab85efd84e6b760
Reviewed-on: https://gerrit.libreoffice.org/20853
Tested-by: Jenkins 
Reviewed-by: Caolán McNamara 
Tested-by: Caolán McNamara 

diff --git a/vcl/inc/openglgdiimpl.hxx b/vcl/inc/openglgdiimpl.hxx
index 3e5ec94..c4fa5c2 100644
--- a/vcl/inc/openglgdiimpl.hxx
+++ b/vcl/inc/openglgdiimpl.hxx
@@ -158,7 +158,7 @@ public:
 void PostDraw();
 
 protected:
-bool AcquireContext();
+bool AcquireContext(bool bForceCreate = false);
 bool ReleaseContext();
 
 /// retrieve the default context for offscreen rendering
diff --git a/vcl/inc/svdata.hxx b/vcl/inc/svdata.hxx
index 46527f0..b559cf3 100644
--- a/vcl/inc/svdata.hxx
+++ b/vcl/inc/svdata.hxx
@@ -357,6 +357,7 @@ struct ImplSVData
 
 voidImplDeInitSVData();
 VCL_PLUGIN_PUBLIC vcl::Window* ImplGetDefaultWindow();
+VCL_PLUGIN_PUBLIC vcl::Window* ImplGetDefaultContextWindow();
 VCL_PLUGIN_PUBLIC ResMgr* ImplGetResMgr();
 VCL_PLUGIN_PUBLIC ResId VclResId( sal_Int32 nId ); // throws std::bad_alloc if 
no res mgr
 DockingManager* ImplGetDockingManager();
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index ba480f2..a5cec8a 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -92,7 +92,7 @@ OpenGLSalGraphicsImpl::~OpenGLSalGraphicsImpl()
 
 rtl::Reference OpenGLSalGraphicsImpl::GetOpenGLContext()
 {
-if( !AcquireContext() )
+if( !AcquireContext(true) )
 return nullptr;
 return mpContext;
 }
@@ -102,7 +102,7 @@ rtl::Reference 
OpenGLSalGraphicsImpl::GetDefaultContext()
 return ImplGetDefaultWindow()->GetGraphics()->GetOpenGLContext();
 }
 
-bool OpenGLSalGraphicsImpl::AcquireContext( )
+bool OpenGLSalGraphicsImpl::AcquireContext( bool bForceCreate )
 {
 ImplSVData* pSVData = ImplGetSVData();
 
@@ -121,6 +121,8 @@ bool OpenGLSalGraphicsImpl::AcquireContext( )
 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;
 while( pContext )
 {
@@ -134,7 +136,12 @@ bool OpenGLSalGraphicsImpl::AcquireContext( )
 mpContext = pContext;
 else if( mpWindowContext.is() )
 mpContext = mpWindowContext;
-else
+else if( bForceCreate && !IsOffscreen() )
+{
+mpWindowContext = CreateWinContext();
+mpContext = mpWindowContext;
+}
+if( !mpContext.is() )
 mpContext = GetDefaultContext();
 
 return mpContext.is();
@@ -175,11 +182,10 @@ void OpenGLSalGraphicsImpl::Init()
 VCL_GL_INFO("::Init - re-size offscreen texture");
 }
 
-if( !IsOffscreen() )
+if( mpWindowContext.is() )
 {
-if( mpWindowContext.is() )
-mpWindowContext->reset();
-mpWindowContext = CreateWinContext();
+mpWindowContext->reset();
+mpWindowContext.clear();
 }
 }
 
@@ -192,8 +198,11 @@ void OpenGLSalGraphicsImpl::DeInit()
 // let it know. Other eg. VirtualDevice contexts which have
 // references on and rely on this context continuing to work will
 // get a shiny new context in AcquireContext:: next PreDraw.
-if( mpContext.is() && !IsOffscreen() )
-mpContext->reset();
+if( mpWindowContext.is() )
+{
+mpWindowContext->reset();
+mpWindowContext.clear();
+}
 mpContext.clear();
 }
 
@@ -245,11 +254,6 @@ void OpenGLSalGraphicsImpl::PostDraw()
 
 assert (maOffscreenTex);
 
-if( IsOffscreen() )
-assert( !mpWindowContext.is() );
-else
-assert( mpWindowContext.is() );
-
 // Always queue the flush.
 if( !IsOffscreen() )
 flush();
@@ -2005,15 +2009,13 @@ void OpenGLSalGraphicsImpl::doFlush()
 if( IsOffscreen() )
 return;
 
-assert( mpWindowContext.is() );
-
 if( !maOffscreenTex )
 {
 VCL_GL_INFO( "flushAndSwap - odd no texture !" );
 return;
 }
 
-if (mnDrawCountAtFlush == mnDrawCount)
+if( mnDrawCountAtFlush == mnDrawCount )
 {
 VCL_GL_INFO( "eliding redundant flushAndSwap, no