[Libreoffice-commits] core.git: Branch 'feature/opengl-vcl' - 2 commits - include/vcl vcl/inc vcl/opengl vcl/source

Louis-Francis Ratté-Boulianne lfrb at collabora.com
Wed Nov 12 12:39:51 PST 2014


 include/vcl/region.hxx    |    2 +
 vcl/inc/openglgdiimpl.hxx |    4 ++
 vcl/opengl/gdiimpl.cxx    |   76 ++++++++++++++++++++++++++++++----------------
 vcl/source/gdi/region.cxx |   17 ++++++++++
 4 files changed, 74 insertions(+), 25 deletions(-)

New commits:
commit 8d59f8bef9cdbe0bc665469ed0ad528f7368a4d5
Author: Louis-Francis Ratté-Boulianne <lfrb at collabora.com>
Date:   Wed Nov 12 15:37:36 2014 -0500

    vcl: Fix gradient programs attribute binding
    
    Change-Id: I4210f09759824bf9415350262fd07534c9b3a317

diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index cfa924f..15ebce0 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -341,8 +341,8 @@ bool OpenGLSalGraphicsImpl::CreateLinearGradientProgram( void )
     if( mnLinearGradientProgram == 0 )
         return false;
 
-    glBindAttribLocation( mnTextureProgram, GL_ATTRIB_POS, "position" );
-    glBindAttribLocation( mnTextureProgram, GL_ATTRIB_TEX, "tex_coord_in" );
+    glBindAttribLocation( mnLinearGradientProgram, GL_ATTRIB_POS, "position" );
+    glBindAttribLocation( mnLinearGradientProgram, GL_ATTRIB_TEX, "tex_coord_in" );
     mnLinearGradientStartColorUniform = glGetUniformLocation( mnLinearGradientProgram, "start_color" );
     mnLinearGradientEndColorUniform = glGetUniformLocation( mnLinearGradientProgram, "end_color" );
 
@@ -356,8 +356,8 @@ bool OpenGLSalGraphicsImpl::CreateRadialGradientProgram( void )
     if( mnRadialGradientProgram == 0 )
         return false;
 
-    glBindAttribLocation( mnTextureProgram, GL_ATTRIB_POS, "position" );
-    glBindAttribLocation( mnTextureProgram, GL_ATTRIB_TEX, "tex_coord_in" );
+    glBindAttribLocation( mnRadialGradientProgram, GL_ATTRIB_POS, "position" );
+    glBindAttribLocation( mnRadialGradientProgram, GL_ATTRIB_TEX, "tex_coord_in" );
     mnRadialGradientStartColorUniform = glGetUniformLocation( mnRadialGradientProgram, "start_color" );
     mnRadialGradientEndColorUniform = glGetUniformLocation( mnRadialGradientProgram, "end_color" );
     mnRadialGradientCenterUniform = glGetUniformLocation( mnRadialGradientProgram, "center" );
commit cd8b67df8ddb07aa6723dc64ad5dea7c70c343cf
Author: Louis-Francis Ratté-Boulianne <lfrb at collabora.com>
Date:   Wed Nov 12 15:37:11 2014 -0500

    vcl: Use scissor or stencil for clipping in OpenGL backend
    
    Change-Id: Ib6620572391999d5f8124a1a8695909d6c48643d

diff --git a/include/vcl/region.hxx b/include/vcl/region.hxx
index 362fa45..081e605 100644
--- a/include/vcl/region.hxx
+++ b/include/vcl/region.hxx
@@ -102,6 +102,8 @@ public:
     void SetEmpty();
     void SetNull();
 
+    bool IsRectangle() const;
+
     Rectangle GetBoundRect() const;
     bool HasPolyPolygonOrB2DPolyPolygon() const { return (getB2DPolyPolygon() || getPolyPolygon()); }
     void GetRegionRectangles(RectangleVector& rTarget) const;
diff --git a/vcl/inc/openglgdiimpl.hxx b/vcl/inc/openglgdiimpl.hxx
index 3d1c585..82bb919 100644
--- a/vcl/inc/openglgdiimpl.hxx
+++ b/vcl/inc/openglgdiimpl.hxx
@@ -40,6 +40,10 @@ protected:
     SalVirtualDevice* mpVDev;
     int mnPainting;
 
+    // clipping
+    bool mbUseScissor;
+    bool mbUseStencil;
+
     bool mbOffscreen;
     GLuint mnFramebufferId;
     OpenGLTextureSharedPtr mpOffscreenTex;
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index 393930f..cfa924f 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -61,6 +61,8 @@
 OpenGLSalGraphicsImpl::OpenGLSalGraphicsImpl()
     : mpFrame(NULL)
     , mnPainting(0)
+    , mbUseScissor(false)
+    , mbUseStencil(false)
     , mbOffscreen(false)
     , mnFramebufferId(0)
     , mpOffscreenTex(NULL)
@@ -97,6 +99,10 @@ void OpenGLSalGraphicsImpl::PreDraw()
     if( mbOffscreen )
         glBindFramebuffer( GL_FRAMEBUFFER, mnFramebufferId );
     glViewport( 0, 0, GetWidth(), GetHeight() );
+    if( mbUseScissor )
+        glEnable( GL_SCISSOR_TEST );
+    if( mbUseStencil )
+        glEnable( GL_STENCIL_TEST );
 
     CHECK_GL_ERROR();
 }
@@ -105,8 +111,12 @@ void OpenGLSalGraphicsImpl::PostDraw()
 {
     if( mbOffscreen )
         glBindFramebuffer( GL_FRAMEBUFFER, 0 );
-    if( mnPainting == 0 )
+    else if( mnPainting == 0 )
         glFlush();
+    if( mbUseScissor )
+        glDisable( GL_SCISSOR_TEST );
+    if( mbUseStencil )
+        glDisable( GL_STENCIL_TEST );
     CHECK_GL_ERROR();
 }
 
@@ -117,28 +127,46 @@ void OpenGLSalGraphicsImpl::freeResources()
 
 bool OpenGLSalGraphicsImpl::setClipRegion( const vcl::Region& rClip )
 {
-    const basegfx::B2DPolyPolygon aClip( rClip.GetAsB2DPolyPolygon() );
+    SAL_INFO( "vcl.opengl", "::setClipRegion " << rClip );
 
-    SAL_INFO( "vcl.opengl", "::setClipRegion" );
+    if( rClip.IsEmpty() )
+    {
+        ResetClipRegion();
+        return true;
+    }
 
-    /*maContext.makeCurrent();
-    glViewport( 0, 0, GetWidth(), GetHeight() );
+    if( false ) //rClip.IsRectangle() )
+    {
+        Rectangle aRect( rClip.GetBoundRect() );
 
-    glEnable( GL_STENCIL_TEST );
+        mbUseStencil = false;
+        mbUseScissor = true;
+        maContext.makeCurrent();
+        glScissor( aRect.Left(), GetHeight() - aRect.Top(), aRect.GetWidth(), aRect.GetHeight() );
+    }
+    else
+    {
+        mbUseStencil = true;
+        mbUseScissor = false;
+        maContext.makeCurrent();
+        glViewport( 0, 0, GetWidth(), GetHeight() );
 
-    glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
-    glStencilMask( 0xFF );
-    glStencilFunc( GL_NEVER, 1, 0xFF );
-    glStencilOp( GL_REPLACE, GL_KEEP, GL_KEEP );
+        glEnable( GL_STENCIL_TEST );
+        glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
+        glStencilMask( 0xFF );
+        glStencilFunc( GL_NEVER, 1, 0xFF );
+        glStencilOp( GL_REPLACE, GL_KEEP, GL_KEEP );
 
-    glClear( GL_STENCIL_BUFFER_BIT );
-    BeginSolid( SALCOLOR_NONE );
-    DrawPolyPolygon( aClip );
-    EndSolid();
+        glClear( GL_STENCIL_BUFFER_BIT );
+        BeginSolid( SALCOLOR_NONE );
+        DrawPolyPolygon( rClip.GetAsB2DPolyPolygon() );
+        EndSolid();
 
-    glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
-    glStencilMask( 0x00 );
-    glStencilFunc( GL_EQUAL, 1, 0xFF );*/
+        glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
+        glStencilMask( 0x00 );
+        glStencilFunc( GL_EQUAL, 1, 0xFF );
+        glDisable( GL_STENCIL_TEST );
+    }
 
     return true;
 }
@@ -147,10 +175,8 @@ bool OpenGLSalGraphicsImpl::setClipRegion( const vcl::Region& rClip )
 void OpenGLSalGraphicsImpl::ResetClipRegion()
 {
     SAL_INFO( "vcl.opengl", "::ResetClipRegion" );
-    maContext.makeCurrent();
-    glDisable(GL_STENCIL_TEST);
-
-    CHECK_GL_ERROR();
+    mbUseScissor = false;
+    mbUseStencil = false;
 }
 
 // get the depth of the device
diff --git a/vcl/source/gdi/region.cxx b/vcl/source/gdi/region.cxx
index 3f56d0e..6fb78b0 100644
--- a/vcl/source/gdi/region.cxx
+++ b/vcl/source/gdi/region.cxx
@@ -1434,6 +1434,23 @@ bool vcl::Region::IsOver( const Rectangle& rRect ) const
     return !aRegion.IsEmpty();
 }
 
+bool vcl::Region::IsRectangle() const
+{
+    if( IsEmpty() || IsNull() )
+        return false;
+
+    if( getB2DPolyPolygon() )
+        return basegfx::tools::isRectangle( *getB2DPolyPolygon() );
+
+    if( getPolyPolygon() )
+        return getPolyPolygon()->IsRect();
+
+    if( getRegionBand() )
+        return (getRegionBand()->getRectangleCount() == 1);
+
+    return false;
+}
+
 void vcl::Region::SetNull()
 {
     // reset all content


More information about the Libreoffice-commits mailing list