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

Tomaz Vajngerl tomaz.vajngerl at collabora.com
Mon Mar 14 22:04:32 UTC 2016


 vcl/inc/opengl/AccumulatedTextures.hxx |   39 ++++++++++++++++++++++++++-
 vcl/inc/opengl/texture.hxx             |    4 ++
 vcl/opengl/gdiimpl.cxx                 |   42 ++++++++----------------------
 vcl/opengl/texture.cxx                 |   46 +++++++++++++++++++++++++++++++++
 4 files changed, 99 insertions(+), 32 deletions(-)

New commits:
commit f2f274b55d0b6a8faf3dde83c14d6aded1e8ba09
Author: Tomaz Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Mon Mar 14 23:01:10 2016 +0100

    opengl: optimize text texture drawing
    
    Change-Id: I795779fa90fd147df8bfb9310ac2b9ce99c85b35

diff --git a/vcl/inc/opengl/AccumulatedTextures.hxx b/vcl/inc/opengl/AccumulatedTextures.hxx
index 3fe327c..9ce170c 100644
--- a/vcl/inc/opengl/AccumulatedTextures.hxx
+++ b/vcl/inc/opengl/AccumulatedTextures.hxx
@@ -15,10 +15,20 @@
 #include "opengl/texture.hxx"
 #include <memory>
 
+struct TextureDrawParameters
+{
+    std::vector<GLfloat> maVertices;
+    std::vector<GLfloat> maTextureCoords;
+    GLint getNumberOfVertices()
+    {
+        return maVertices.size() / 2;
+    }
+};
+
 struct AccumulatedTexturesEntry
 {
     OpenGLTexture maTexture;
-    std::unordered_map<SalColor, std::vector<SalTwoRect>> maColorTwoRectMap;
+    std::unordered_map<SalColor, TextureDrawParameters> maColorTextureDrawParametersMap;
 
     AccumulatedTexturesEntry(const OpenGLTexture& rTexture)
         : maTexture(rTexture)
@@ -26,7 +36,32 @@ struct AccumulatedTexturesEntry
 
     void insert(const SalColor& aColor, const SalTwoRect& r2Rect)
     {
-        maColorTwoRectMap[aColor].push_back(r2Rect);
+        TextureDrawParameters& aDrawParameters = maColorTextureDrawParametersMap[aColor];
+        maTexture.FillCoords<GL_TRIANGLES>(aDrawParameters.maTextureCoords, r2Rect, false);
+
+        GLfloat nX1 = r2Rect.mnDestX;
+        GLfloat nY1 = r2Rect.mnDestY;
+        GLfloat nX2 = r2Rect.mnDestX + r2Rect.mnDestWidth;
+        GLfloat nY2 = r2Rect.mnDestY + r2Rect.mnDestHeight;
+
+        auto& rVertices = aDrawParameters.maVertices;
+        rVertices.push_back(nX1);
+        rVertices.push_back(nY1);
+
+        rVertices.push_back(nX2);
+        rVertices.push_back(nY1);
+
+        rVertices.push_back(nX1);
+        rVertices.push_back(nY2);
+
+        rVertices.push_back(nX1);
+        rVertices.push_back(nY2);
+
+        rVertices.push_back(nX2);
+        rVertices.push_back(nY1);
+
+        rVertices.push_back(nX2);
+        rVertices.push_back(nY2);
     }
 };
 
diff --git a/vcl/inc/opengl/texture.hxx b/vcl/inc/opengl/texture.hxx
index 9388918..c51948d 100644
--- a/vcl/inc/opengl/texture.hxx
+++ b/vcl/inc/opengl/texture.hxx
@@ -111,6 +111,7 @@ public:
     GLuint          Id() const;
     int             GetWidth() const;
     int             GetHeight() const;
+
     void            GetCoord( GLfloat* pCoord, const SalTwoRect& rPosAry, bool bInverted=false ) const;
     void            GetWholeCoord( GLfloat* pCoord ) const;
 
@@ -130,6 +131,9 @@ public:
     OpenGLTexture&  operator=( const OpenGLTexture& rTexture );
     bool            operator==( const OpenGLTexture& rTexture ) const;
     bool            operator!=( const OpenGLTexture& rTexture ) const;
+
+    template<GLenum type>
+    void FillCoords(std::vector<GLfloat>& aCoordVector, const SalTwoRect& rPosAry, bool bInverted) const;
 };
 
 #endif // INCLUDED_VCL_INC_OPENGL_TEXTURE_H
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index 567ecf2..f7c165b 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -1607,16 +1607,15 @@ void OpenGLSalGraphicsImpl::FlushDeferredDrawing(bool bIsInDraw)
         }
         aUseColor = aColorForTextureMap[rTexture.Id()];
 
-
-
         if (!UseSolid(MAKE_SALCOLOR(aUseColor.GetRed(), aUseColor.GetGreen(), aUseColor.GetBlue())))
             return;
-        for (auto rColorTwoRectPair: rPair.second->maColorTwoRectMap)
+        for (auto rColorTwoRectPair: rPair.second->maColorTextureDrawParametersMap)
         {
-            for (SalTwoRect& rPosAry : rColorTwoRectPair.second)
-            {
-                DrawRect(rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth, rPosAry.mnDestHeight);
-            }
+            TextureDrawParameters& rParameters = rColorTwoRectPair.second;
+            ApplyProgramMatrices();
+            mpProgram->SetTextureCoord(rParameters.maTextureCoords.data());
+            mpProgram->SetVertices(rParameters.maVertices.data());
+            glDrawArrays(GL_TRIANGLES, 0, rParameters.getNumberOfVertices());
         }
     }
 #endif
@@ -1628,31 +1627,14 @@ void OpenGLSalGraphicsImpl::FlushDeferredDrawing(bool bIsInDraw)
     {
         OpenGLTexture& rTexture = rPair.second->maTexture;
         mpProgram->SetTexture("sampler", rTexture);
-        for (auto& rColorTwoRectPair: rPair.second->maColorTwoRectMap)
+        for (auto& rColorTwoRectPair: rPair.second->maColorTextureDrawParametersMap)
         {
             mpProgram->SetColor("color", rColorTwoRectPair.first, 0);
-            for (SalTwoRect& rPosAry : rColorTwoRectPair.second)
-            {
-                GLfloat pTexCoord[8];
-                rTexture.GetCoord(pTexCoord, rPosAry, false);
-                mpProgram->SetTextureCoord(pTexCoord);
-
-                GLfloat nX1 = rPosAry.mnDestX;
-                GLfloat nY1 = rPosAry.mnDestY;
-                GLfloat nX2 = rPosAry.mnDestX + rPosAry.mnDestWidth;
-                GLfloat nY2 = rPosAry.mnDestY + rPosAry.mnDestHeight;
-
-                GLfloat pVertices[] =
-                {
-                    nX1, nY2,
-                    nX1, nY1,
-                    nX2, nY1,
-                    nX2, nY2
-                };
-                ApplyProgramMatrices();
-                mpProgram->SetVertices(pVertices);
-                glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
-            }
+            TextureDrawParameters& rParameters = rColorTwoRectPair.second;
+            ApplyProgramMatrices();
+            mpProgram->SetTextureCoord(rParameters.maTextureCoords.data());
+            mpProgram->SetVertices(rParameters.maVertices.data());
+            glDrawArrays(GL_TRIANGLES, 0, rParameters.getNumberOfVertices());
         }
     }
     mpProgram->Clean();
diff --git a/vcl/opengl/texture.cxx b/vcl/opengl/texture.cxx
index 7f047e5..809d085 100644
--- a/vcl/opengl/texture.cxx
+++ b/vcl/opengl/texture.cxx
@@ -360,6 +360,52 @@ void OpenGLTexture::GetCoord( GLfloat* pCoord, const SalTwoRect& rPosAry, bool b
     }
 }
 
+template <>
+void OpenGLTexture::FillCoords<GL_TRIANGLES>(std::vector<GLfloat>& aCoord, const SalTwoRect& rPosAry, bool bInverted) const
+{
+    VCL_GL_INFO("Add coord " << Id() << " [" << maRect.Left() << "," << maRect.Top() << "] " << GetWidth() << "x" << GetHeight() );
+
+    GLfloat x1 = 0.0f;
+    GLfloat x2 = 0.0f;
+    GLfloat y1 = 0.0f;
+    GLfloat y2 = 0.0f;
+
+    if (mpImpl)
+    {
+        x1 = (maRect.Left() + rPosAry.mnSrcX) / (double) mpImpl->mnWidth;
+        x2 = (maRect.Left() + rPosAry.mnSrcX + rPosAry.mnSrcWidth) / (double) mpImpl->mnWidth;
+
+        if (bInverted)
+        {
+            y2 = 1.0f - (maRect.Top() + rPosAry.mnSrcY) / (double) mpImpl->mnHeight;
+            y1 = 1.0f - (maRect.Top() + rPosAry.mnSrcY + rPosAry.mnSrcHeight) / (double) mpImpl->mnHeight;
+        }
+        else
+        {
+            y1 = 1.0f - (maRect.Top() + rPosAry.mnSrcY) / (double) mpImpl->mnHeight;
+            y2 = 1.0f - (maRect.Top() + rPosAry.mnSrcY + rPosAry.mnSrcHeight) / (double) mpImpl->mnHeight;
+        }
+    }
+
+    aCoord.push_back(x1);
+    aCoord.push_back(y1);
+
+    aCoord.push_back(x2);
+    aCoord.push_back(y1);
+
+    aCoord.push_back(x1);
+    aCoord.push_back(y2);
+
+    aCoord.push_back(x1);
+    aCoord.push_back(y2);
+
+    aCoord.push_back(x2);
+    aCoord.push_back(y1);
+
+    aCoord.push_back(x2);
+    aCoord.push_back(y2);
+}
+
 void OpenGLTexture::GetWholeCoord( GLfloat* pCoord ) const
 {
     if( GetWidth() != mpImpl->mnWidth || GetHeight() != mpImpl->mnHeight )


More information about the Libreoffice-commits mailing list