[Libreoffice-commits] core.git: 4 commits - vcl/opengl vcl/source

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Thu Jul 2 22:53:26 PDT 2015


 vcl/opengl/gdiimpl.cxx             |  107 ++++++++++++++++++++-----------------
 vcl/source/opengl/OpenGLHelper.cxx |    6 +-
 2 files changed, 64 insertions(+), 49 deletions(-)

New commits:
commit f7f0486376adbabf3ea66bfd8a7b692c335ec3c8
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Fri Jul 3 14:38:24 2015 +0900

    tdf#88831 fix inverted textures when OpenGL is enabled
    
    GLX returns a wrong value if the y coords are inverted. Most other
    programs don't even ask for this (gnome-shell for example) and just
    assumes "true" (and this works because most relevant X servers work
    like this). We make this more robust and assume true only if the
    returned value is GLX_DONT_CARE (-1).
    
    Change-Id: I4800b3364fd00f5f4a8f5a459472bfa8d97827ba

diff --git a/vcl/source/opengl/OpenGLHelper.cxx b/vcl/source/opengl/OpenGLHelper.cxx
index 5663ccb..3ed6bdd 100644
--- a/vcl/source/opengl/OpenGLHelper.cxx
+++ b/vcl/source/opengl/OpenGLHelper.cxx
@@ -539,7 +539,11 @@ GLXFBConfig OpenGLHelper::GetPixmapFBConfig( Display* pDisplay, bool& bInverted
         }
 
         glXGetFBConfigAttrib( pDisplay, aFbConfigs[i], GLX_Y_INVERTED_EXT, &nValue );
-        bInverted = nValue == True;
+
+        // Looks like that X sends GLX_DONT_CARE but this usually means "true" for most
+        // of the X implementations. Investigation on internet pointed that this could be
+        // safely "true" all the time (for example gnome-shell always assumes "true").
+        bInverted = nValue == True || nValue == int(GLX_DONT_CARE);
 
         break;
     }
commit 149e62670ed01f33612e841c8d17b6bd416e2d88
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Tue Jun 30 18:07:41 2015 +0900

    opengl: draw rectangle lines with only one glDrawArrays call
    
    Change-Id: I33e065fe6c084d0bed04ee99c447004fe573278a

diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index 2526cde..f56dd4a 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -1195,13 +1195,24 @@ void OpenGLSalGraphicsImpl::drawRect( long nX, long nY, long nWidth, long nHeigh
 
     if( UseSolid( mnLineColor ) )
     {
-        const long nX1( nX );
-        const long nY1( nY );
-        const long nX2( nX + nWidth );
-        const long nY2( nY + nHeight );
-        const SalPoint aPoints[] = { { nX1, nY1 }, { nX2, nY1 },
-                                     { nX2, nY2 }, { nX1, nY2 } };
-        DrawLines( 4, aPoints, true ); // No need for AA.
+        GLfloat fX1 = OPENGL_COORD_X(nX);
+        GLfloat fY1 = OPENGL_COORD_Y(nY);
+        GLfloat fX2 = OPENGL_COORD_X(nX + nWidth);
+        GLfloat fY2 = OPENGL_COORD_Y(nY + nHeight);
+
+        GLfloat pPoints[16];
+
+        pPoints[0] = fX1;
+        pPoints[1] = fY1;
+        pPoints[2] = fX2;
+        pPoints[3] = fY1;
+        pPoints[4] = fX2;
+        pPoints[5] = fY2;
+        pPoints[6] = fX1;
+        pPoints[7] = fY2;
+
+        mpProgram->SetVertices(pPoints);
+        glDrawArrays(GL_LINE_LOOP, 0, 4);
     }
 
     PostDraw();
commit 33d32a78943d19b0d06821ad1a06054f633f60fc
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Tue Jun 30 18:03:34 2015 +0900

    opengl: use common macro for conversion of coordinates
    
    add macro OPENGL_COORD_X and OPENGL_COORD_Y to convert (normalize)
    to opengl coordinates that need to be in between -1.0f, 1.0f.
    
    Change-Id: Ide5c53e80fd9140d32883d44e6112b83a01fd111

diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index e2512b6..2526cde 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -36,6 +36,9 @@
 
 #include <vector>
 
+#define OPENGL_COORD_X(x) GLfloat((2.0 * double(x)) / GetWidth() - 1.0)
+#define OPENGL_COORD_Y(y) GLfloat(1.0 - (2.0 * double(y)) / GetHeight())
+
 OpenGLSalGraphicsImpl::OpenGLSalGraphicsImpl(SalGraphics& rParent, SalGeometryProvider *pProvider)
     : mpContext(0)
     , mrParent(rParent)
@@ -450,8 +453,8 @@ void OpenGLSalGraphicsImpl::DrawPoint( long nX, long nY )
 {
     GLfloat pPoint[2];
 
-    pPoint[0] = 2 * nX / GetWidth() - 1.0f;
-    pPoint[1] = 1.0f - 2 * nY / GetHeight();
+    pPoint[0] = OPENGL_COORD_X(nX);
+    pPoint[1] = OPENGL_COORD_Y(nY);
 
     mpProgram->SetVertices( pPoint );
     glDrawArrays( GL_POINTS, 0, 1 );
@@ -463,10 +466,10 @@ void OpenGLSalGraphicsImpl::DrawLine( double nX1, double nY1, double nX2, double
 {
     GLfloat pPoints[4];
 
-    pPoints[0] = (2 * nX1) / GetWidth() - 1.0;
-    pPoints[1] = 1.0f - 2 * nY1 / GetHeight();
-    pPoints[2] = (2 * nX2) / GetWidth() - 1.0;;
-    pPoints[3] = 1.0f - 2 * nY2 / GetHeight();
+    pPoints[0] = OPENGL_COORD_X(nX1);
+    pPoints[1] = OPENGL_COORD_Y(nY1);
+    pPoints[2] = OPENGL_COORD_X(nX2);
+    pPoints[3] = OPENGL_COORD_Y(nY2);
 
     mpProgram->SetVertices( pPoints );
     glDrawArrays( GL_LINES, 0, 2 );
@@ -483,10 +486,10 @@ void OpenGLSalGraphicsImpl::DrawLineAA( double nX1, double nY1, double nX2, doub
     {   // Horizontal/vertical, no need for AA, both points have normal color.
         GLfloat pPoints[4];
 
-        pPoints[0] = (2 * nX1) / GetWidth() - 1.0;
-        pPoints[1] = 1.0f - 2 * nY1 / GetHeight();
-        pPoints[2] = (2 * nX2) / GetWidth() - 1.0;;
-        pPoints[3] = 1.0f - 2 * nY2 / GetHeight();
+        pPoints[0] = OPENGL_COORD_X(nX1);
+        pPoints[1] = OPENGL_COORD_Y(nY1);
+        pPoints[2] = OPENGL_COORD_X(nX2);
+        pPoints[3] = OPENGL_COORD_Y(nY2);
 
         mpProgram->SetVertices( pPoints );
         // Still set up for the trivial "gradients", because presumably UseSolidAA() has been called.
@@ -620,18 +623,14 @@ void OpenGLSalGraphicsImpl::ImplDrawLineAA( double nX1, double nY1, double nX2,
 
     GLfloat vertices[]=
     {
-#define convertX( x ) GLfloat( (2 * (x)) / GetWidth()  - 1.0f)
-#define convertY( y ) GLfloat( 1.0f - (2 * (y)) / GetHeight())
-        convertX(x1-tx-Rx), convertY(y1-ty-Ry), //fading edge1
-        convertX(x2-tx-Rx), convertY(y2-ty-Ry),
-        convertX(x1-tx),convertY(y1-ty),        //core
-        convertX(x2-tx),convertY(y2-ty),
-        convertX(x1+tx),convertY(y1+ty),
-        convertX(x2+tx),convertY(y2+ty),
-        convertX(x1+tx+Rx), convertY(y1+ty+Ry), //fading edge2
-        convertX(x2+tx+Rx), convertY(y2+ty+Ry)
-#undef convertX
-#undef convertY
+        OPENGL_COORD_X(x1-tx-Rx), OPENGL_COORD_Y(y1-ty-Ry), //fading edge1
+        OPENGL_COORD_X(x2-tx-Rx), OPENGL_COORD_Y(y2-ty-Ry),
+        OPENGL_COORD_X(x1-tx),    OPENGL_COORD_Y(y1-ty),    //core
+        OPENGL_COORD_X(x2-tx),    OPENGL_COORD_Y(y2-ty),
+        OPENGL_COORD_X(x1+tx),    OPENGL_COORD_Y(y1+ty),
+        OPENGL_COORD_X(x2+tx),    OPENGL_COORD_Y(y2+ty),
+        OPENGL_COORD_X(x1+tx+Rx), OPENGL_COORD_Y(y1+ty+Ry), //fading edge2
+        OPENGL_COORD_X(x2+tx+Rx), OPENGL_COORD_Y(y2+ty+Ry)
     };
 
     GLfloat aTexCoord[16] = { 0, 0, 1, 0, 2, 1, 3, 1, 4, 1, 5, 1, 6, 0, 7, 0 };
@@ -673,8 +672,8 @@ void OpenGLSalGraphicsImpl::DrawConvexPolygon( sal_uInt32 nPoints, const SalPoin
 
     for( i = 0, j = 0; i < nPoints; i++, j += 2 )
     {
-        aVertices[j] = (2 * pPtAry[i].mnX) / GetWidth() - 1.0;
-        aVertices[j+1] = 1.0 - (2 * pPtAry[i].mnY / GetHeight());
+        aVertices[j]   = OPENGL_COORD_X(pPtAry[i].mnX);
+        aVertices[j+1] = OPENGL_COORD_Y(pPtAry[i].mnY);
     }
 
     mpProgram->SetVertices( &aVertices[0] );
@@ -715,8 +714,8 @@ void OpenGLSalGraphicsImpl::DrawConvexPolygon( const Polygon& rPolygon, bool blo
     for( i = 0, j = 0; i < nPoints; i++, j += 2 )
     {
         const Point& rPt = rPolygon.GetPoint( i );
-        aVertices[j] = (2 * rPt.X()) / GetWidth() - 1.0;
-        aVertices[j+1] = 1.0 - (2 * rPt.Y() / GetHeight());
+        aVertices[j]   = OPENGL_COORD_X(rPt.X());
+        aVertices[j+1] = OPENGL_COORD_Y(rPt.Y());
     }
 
     mpProgram->SetVertices( &aVertices[0] );
@@ -758,8 +757,8 @@ void OpenGLSalGraphicsImpl::DrawTrapezoid( const basegfx::B2DTrapezoid& trapezoi
     for( i = 0, j = 0; i < nPoints; i++, j += 2 )
     {
         const basegfx::B2DPoint& rPt = rPolygon.getB2DPoint( i );
-        aVertices[j] = (2 * rPt.getX()) / GetWidth() - 1.0;
-        aVertices[j+1] = 1.0 - (2 * rPt.getY() / GetHeight());
+        aVertices[j]   = OPENGL_COORD_X(rPt.getX());
+        aVertices[j+1] = OPENGL_COORD_Y(rPt.getY());
     }
 
     mpProgram->SetVertices( &aVertices[0] );
@@ -858,8 +857,8 @@ void OpenGLSalGraphicsImpl::DrawRegionBand( const RegionBand& rRegion )
         return;
 
 #define ADD_VERTICE(pt) \
-    aVertices.push_back( 2 * pt.X() / GetWidth() - 1.0 ); \
-    aVertices.push_back( 1.0 - (2 * pt.Y() / GetHeight()) );
+    aVertices.push_back(OPENGL_COORD_X(pt.X())); \
+    aVertices.push_back(OPENGL_COORD_Y(pt.Y()));
 
     for( size_t i = 0; i < aRects.size(); ++i )
     {
@@ -872,7 +871,6 @@ void OpenGLSalGraphicsImpl::DrawRegionBand( const RegionBand& rRegion )
         ADD_VERTICE( aRects[i].TopRight() );
         ADD_VERTICE( aRects[i].BottomRight() );
     }
-
 #undef ADD_VERTICE
 
     mpProgram->SetVertices( &aVertices[0] );
@@ -1821,4 +1819,7 @@ void OpenGLSalGraphicsImpl::endPaint()
     CHECK_GL_ERROR();
 }
 
+#undef OPENGL_COORD_X
+#undef OPENGL_COORD_Y
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 240e5daab408c4189a2687ab44cffd73572ee8a8
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Tue Jun 30 17:57:14 2015 +0900

    opengl: fix fat hairlines - draw hairlines using DrawLineAA
    
    Change-Id: I935bef48fd057e6223dcfc437cbaf2888842fd61

diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index 351fc1d..e2512b6 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -1348,20 +1348,19 @@ bool OpenGLSalGraphicsImpl::drawPolyLine(
     //bool bDrawnOk = true;
     if( bIsHairline )
     {
-        // hairlines can be drawn in a simpler way (the linejoin and linecap styles can be ignored)
-        basegfx::B2DTrapezoidVector aB2DTrapVector;
-        basegfx::tools::createLineTrapezoidFromB2DPolygon( aB2DTrapVector, aPolygon, rLineWidth.getX() );
-        // draw tesselation result
-        if( aB2DTrapVector.size())
+        PreDraw();
+        if( UseSolidAA( mnLineColor ) )
         {
-            PreDraw();
-            if( UseSolid( mnLineColor, fTransparency ))
+            sal_uInt32 nPoints = rPolygon.count();
+            for (sal_uInt32 i = 0; i < nPoints - 1; ++i)
             {
-                for( size_t i = 0; i < aB2DTrapVector.size(); ++i )
-                    DrawTrapezoid( aB2DTrapVector[ i ] );
+                const basegfx::B2DPoint& rPt1 = rPolygon.getB2DPoint(i);
+                const basegfx::B2DPoint& rPt2 = rPolygon.getB2DPoint(i+1);
+                DrawLineAA(rPt1.getX(), rPt1.getY(),
+                           rPt2.getX(), rPt2.getY());
             }
-            PostDraw();
         }
+        PostDraw();
         return true;
     }
 


More information about the Libreoffice-commits mailing list