summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2015-12-31 21:19:48 +0000
committerMichael Meeks <michael.meeks@collabora.com>2015-12-31 22:37:23 +0000
commitb3da866919c9a6904f8b007bbe018846dcf7f35c (patch)
tree22bf496e3ce8851dd0812438a9caae7d99e67b4e
parent42b36a01de6b3f43ccd56e7c2062dfad2002fba1 (diff)
tdf#95507 - implement opengl / 50% invert method.
Change-Id: I8488cb8e8074831a6f81e6c8c122462c9819d25d Reviewed-on: https://gerrit.libreoffice.org/21026 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
-rw-r--r--vcl/Package_opengl.mk1
-rw-r--r--vcl/inc/openglgdiimpl.hxx3
-rw-r--r--vcl/opengl/gdiimpl.cxx60
-rw-r--r--vcl/opengl/invert50FragmentShader.glsl23
-rw-r--r--vcl/workben/vcldemo.cxx11
5 files changed, 62 insertions, 36 deletions
diff --git a/vcl/Package_opengl.mk b/vcl/Package_opengl.mk
index df3520c8483f..9d4250279bd9 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 c4fa5c2e42ca..647c83f9996c 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 a5cec8a77ba9..e92b6b66bd7a 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 000000000000..76f3e1f3ac63
--- /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;
+ bool bTop = tex_mod.y > 0 && tex_mod.y < 1;
+ // horrors - where is the XOR operator ?
+ if ((bTop && bLeft) || (!bTop && !bLeft))
+ gl_FragColor = vec4(255,255,255,0);
+ else
+ gl_FragColor = vec4(0,0,0,0);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/workben/vcldemo.cxx b/vcl/workben/vcldemo.cxx
index 423ff2a23231..bfd29e58eaf2 100644
--- a/vcl/workben/vcldemo.cxx
+++ b/vcl/workben/vcldemo.cxx
@@ -564,11 +564,20 @@ public:
{
RENDER_DETAILS(ellipse,KEY_E,5000)
virtual void RenderRegion(OutputDevice &rDev, Rectangle r,
- const RenderContext &) override
+ const RenderContext &rCtx) override
{
rDev.SetLineColor(Color(COL_RED));
rDev.SetFillColor(Color(COL_GREEN));
rDev.DrawEllipse(r);
+
+ if (rCtx.meStyle == RENDER_EXPANDED)
+ {
+ auto aRegions = partition(rCtx, 2, 2);
+ rDev.Invert(aRegions[0]);
+ rDev.Invert(aRegions[1], InvertFlags::N50);
+ rDev.Invert(aRegions[2], InvertFlags::Highlight);
+ rDev.Invert(aRegions[3], (InvertFlags)0xffff);
+ }
}
};