[Libreoffice-commits] core.git: vcl/inc vcl/opengl vcl/Package_opengl.mk vcl/workben

Michael Meeks michael.meeks at collabora.com
Thu Dec 31 14:39:23 PST 2015


 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 e81c4d3ea00949cb4d8c3f44e09e70b19eebb826
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Thu Dec 31 21:19:48 2015 +0000

    tdf#95507 - implement opengl / 50% invert method.
    
    Change-Id: I8488cb8e8074831a6f81e6c8c122462c9819d25d
    Reviewed-on: https://gerrit.libreoffice.org/21025
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

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 a81b1e8..63bebdc 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 549f8ae..21ff211 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;
 }
 
@@ -1742,25 +1760,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();
 }
@@ -1769,19 +1772,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 0000000..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;
+    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 31b0b58..a29de5f 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);
+            }
         }
     };
 


More information about the Libreoffice-commits mailing list