[Libreoffice-commits] core.git: 5 commits - vcl/inc vcl/opengl

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Wed Sep 16 05:17:17 PDT 2015


 vcl/inc/opengl/salbmp.hxx        |    2 -
 vcl/opengl/FixedTextureAtlas.cxx |   17 ++++++-----
 vcl/opengl/framebuffer.cxx       |    7 +++-
 vcl/opengl/salbmp.cxx            |   58 ++++++++++++++++++++++++++++++---------
 vcl/opengl/scale.cxx             |   45 ++----------------------------
 vcl/opengl/texture.cxx           |   22 ++++++++------
 6 files changed, 77 insertions(+), 74 deletions(-)

New commits:
commit 7993663cc559e2a2c72804f7b4fa553f8c7441c3
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Wed Sep 16 14:10:35 2015 +0200

    opengl: check framebuffer completeness
    
    Change-Id: Idd80b7390694038ab0913edab0e496593beb0e15

diff --git a/vcl/opengl/framebuffer.cxx b/vcl/opengl/framebuffer.cxx
index b1135fc..403c379 100644
--- a/vcl/opengl/framebuffer.cxx
+++ b/vcl/opengl/framebuffer.cxx
@@ -68,8 +68,11 @@ void OpenGLFramebuffer::AttachTexture( const OpenGLTexture& rTexture )
     mnAttachedTexture = rTexture.Id();
     mnWidth = rTexture.GetWidth();
     mnHeight = rTexture.GetHeight();
-    glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
-                            mnAttachedTexture, 0 );
+    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mnAttachedTexture, 0);
+    if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
+    {
+        SAL_WARN("vcl.opengl", "Framebuffer incomplete");
+    }
     CHECK_GL_ERROR();
 }
 
commit b85d24e430051054e54602aa14bf00b164c3865b
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Wed Sep 16 14:02:23 2015 +0200

    opengl: support reading back 1-bit masks from texture
    
    Change-Id: Ibe8d9140f7a54016f2cd684198856ac27d880aa3

diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx
index 05c1000..286c463 100644
--- a/vcl/opengl/salbmp.cxx
+++ b/vcl/opengl/salbmp.cxx
@@ -469,8 +469,6 @@ GLuint OpenGLSalBitmap::CreateTexture()
 bool OpenGLSalBitmap::ReadTexture()
 {
     sal_uInt8* pData = maUserBuffer.get();
-    GLenum nFormat = GL_RGBA;
-    GLenum nType = GL_UNSIGNED_BYTE;
 
     SAL_INFO( "vcl.opengl", "::ReadTexture " << mnWidth << "x" << mnHeight );
 
@@ -479,8 +477,8 @@ bool OpenGLSalBitmap::ReadTexture()
 
     if (mnBits == 8 || mnBits == 16 || mnBits == 24 || mnBits == 32)
     {
-        // no conversion needed for truecolor
-        pData = maUserBuffer.get();
+        GLenum nFormat = GL_RGBA;
+        GLenum nType = GL_UNSIGNED_BYTE;
 
         switch( mnBits )
         {
@@ -497,18 +495,54 @@ bool OpenGLSalBitmap::ReadTexture()
                     nType = GL_UNSIGNED_BYTE;
                     break;
         }
+
+        makeCurrent();
+        maTexture.Read(nFormat, nType, pData);
+        mnBufWidth = mnWidth;
+        mnBufHeight = mnHeight;
+        return true;
     }
-    else
-    {
-        return false;
+    else if (mnBits == 1)
+    {   // convert buffers from 24-bit RGB to 1-bit Mask
+        std::vector<sal_uInt8> aBuffer(mnWidth * mnHeight * 3);
+        makeCurrent();
+        sal_uInt8* pBuffer = aBuffer.data();
+        maTexture.Read(GL_RGB, GL_UNSIGNED_BYTE, pBuffer);
+
+        int nShift = 7;
+        size_t nIndex = 0;
+
+        sal_uInt8* pCurrent = pBuffer;
+
+        for (size_t i = 0; i < aBuffer.size(); i += 3)
+        {
+            sal_uInt8 nR = *pCurrent++;
+            sal_uInt8 nG = *pCurrent++;
+            sal_uInt8 nB = *pCurrent++;
+
+            if (nR > 0 && nG > 0 && nB > 0)
+            {
+                pData[nIndex] |= (1 << nShift);
+            }
+            nShift--;
+            if (nShift < 0)
+            {
+                nShift = 7;
+                nIndex++;
+                pData[nIndex] = 0;
+            }
+        }
+
+        mnBufWidth = mnWidth;
+        mnBufHeight = mnHeight;
+        return true;
     }
 
-    makeCurrent();
-    maTexture.Read( nFormat, nType, pData );
-    mnBufWidth = mnWidth;
-    mnBufHeight = mnHeight;
+    SAL_WARN("vcl.opengl", "::ReadTexture - tx:" << maTexture.Id() << " @ "
+             << mnWidth << "x" << mnHeight << "- unimplemented bit depth: "
+             << mnBits);
+    return false;
 
-    return true;
 }
 
 sal_uInt16 OpenGLSalBitmap::GetBitCount() const
commit 0165da09288b5f6573bda114af664a26557fad8a
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Wed Sep 16 13:47:47 2015 +0200

    tdf#93666: use x,y coords when reading texture part + don't bind
    
    Fixes shrinking shapes with gradients when the VirtualDev is
    reused to create a alpha mask (and the texture is reused and
    reading back from just one part of the texture which uses
    glReadPixels code-path).
    
    Binding texture is not necessary when we use and bind it to the
    framebuffer.
    
    Change-Id: Ie3994f749e1a2c17d4d3df44710b7453d7a4f45f

diff --git a/vcl/opengl/texture.cxx b/vcl/opengl/texture.cxx
index 9b3c605..c0373cc 100644
--- a/vcl/opengl/texture.cxx
+++ b/vcl/opengl/texture.cxx
@@ -361,30 +361,32 @@ void OpenGLTexture::Read( GLenum nFormat, GLenum nType, sal_uInt8* pData )
         return;
     }
 
-    Bind();
-    glPixelStorei( GL_PACK_ALIGNMENT, 1 );
-
     VCL_GL_INFO( "vcl.opengl", "Reading texture " << Id() << " " << GetWidth() << "x" << GetHeight() );
 
     if( GetWidth() == mpImpl->mnWidth && GetHeight() == mpImpl->mnHeight )
     {
+        Bind();
+        glPixelStorei( GL_PACK_ALIGNMENT, 1 );
         // XXX: Call not available with GLES 2.0
         glGetTexImage( GL_TEXTURE_2D, 0, nFormat, nType, pData );
+        Unbind();
     }
     else
     {
+        long nWidth = maRect.GetWidth();
+        long nHeight = maRect.GetHeight();
+        long nX = maRect.Left();
+        long nY = mpImpl->mnHeight - maRect.Top() - nHeight;
+
         // Retrieve current context
         ImplSVData* pSVData = ImplGetSVData();
         rtl::Reference<OpenGLContext> pContext = pSVData->maGDIData.mpLastContext;
-        OpenGLFramebuffer* pFramebuffer;
-
-        pFramebuffer = pContext->AcquireFramebuffer( *this );
-        glReadPixels( maRect.Left(), mpImpl->mnHeight - maRect.Top(), GetWidth(), GetHeight(), nFormat, nType, pData );
-        OpenGLContext::ReleaseFramebuffer( pFramebuffer );
-        CHECK_GL_ERROR();
+        OpenGLFramebuffer* pFramebuffer = pContext->AcquireFramebuffer(*this);
+        glPixelStorei(GL_PACK_ALIGNMENT, 1);
+        glReadPixels(nX, nY, nWidth, nHeight, nFormat, nType, pData);
+        OpenGLContext::ReleaseFramebuffer(pFramebuffer);
     }
 
-    Unbind();
     CHECK_GL_ERROR();
 }
 
commit 4823b6d4e989943c31e20027564ab4eca43f6f8d
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Fri Sep 11 12:27:45 2015 +0200

    opengl: optimize search for a free slot in texture atlas
    
    Change-Id: Ic853457871b914f9c1beb2f648bf7d9d18dce957

diff --git a/vcl/opengl/FixedTextureAtlas.cxx b/vcl/opengl/FixedTextureAtlas.cxx
index f6e4005..8a3e927 100644
--- a/vcl/opengl/FixedTextureAtlas.cxx
+++ b/vcl/opengl/FixedTextureAtlas.cxx
@@ -36,15 +36,18 @@ OpenGLTexture FixedTextureAtlasManager::InsertBuffer(int nWidth, int nHeight, in
 {
     ImplOpenGLTexture* pTexture = nullptr;
 
-    for (size_t i = 0; i < mpTextures.size(); i++)
+    auto funFreeSlot = [] (std::unique_ptr<ImplOpenGLTexture>& mpTexture)
     {
-        if (mpTextures[i]->mnFreeSlots > 0)
-        {
-            pTexture = mpTextures[i].get();
-        }
-    }
+        return mpTexture->mnFreeSlots > 0;
+    };
+
+    auto aIterator = std::find_if(mpTextures.begin(), mpTextures.end(), funFreeSlot);
 
-    if (!pTexture)
+    if (aIterator != mpTextures.end())
+    {
+        pTexture = (*aIterator).get();
+    }
+    else
     {
         CreateNewTexture();
         pTexture = mpTextures.back().get();
commit 0eb9f13d401eb473338c7da2e4cfd0e366996aee
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Fri Sep 11 12:25:35 2015 +0200

    opengl: this doesn't really do anything as data is null anyway
    
    Change-Id: Iacd75beecc14023173a9aa52a30298bbfe787d61

diff --git a/vcl/inc/opengl/salbmp.hxx b/vcl/inc/opengl/salbmp.hxx
index 1c425da..592c848 100644
--- a/vcl/inc/opengl/salbmp.hxx
+++ b/vcl/inc/opengl/salbmp.hxx
@@ -105,8 +105,6 @@ private:
     bool ImplScaleConvolution(const double& rScaleX, const double& rScaleY, const vcl::Kernel& rKernel);
     bool ImplScaleArea( double rScaleX, double rScaleY );
 
-    bool getFormatAndType(GLenum& nFormat, GLenum& nType);
-
 public:
 
     bool ImplScale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag );
diff --git a/vcl/opengl/scale.cxx b/vcl/opengl/scale.cxx
index 1ddb6d4..5f5c37c 100644
--- a/vcl/opengl/scale.cxx
+++ b/vcl/opengl/scale.cxx
@@ -52,31 +52,6 @@ public:
     void GetSize( Size& rSize ) const SAL_OVERRIDE;
 };
 
-bool OpenGLSalBitmap::getFormatAndType(GLenum& nFormat, GLenum& nType)
-{
-    switch(mnBits)
-    {
-    case  8:
-        nFormat = GL_LUMINANCE;
-        nType = GL_UNSIGNED_BYTE;
-        break;
-    case 16:
-        nFormat = GL_RGB;
-        nType = GL_UNSIGNED_SHORT_5_6_5;
-        break;
-    case 24:
-        nFormat = GL_RGB;
-        nType = GL_UNSIGNED_BYTE;
-        break;
-    case 32:
-    default:
-        nFormat = GL_RGBA;
-        nType = GL_UNSIGNED_BYTE;
-        break;
-    }
-    return true;
-}
-
 bool OpenGLSalBitmap::ImplScaleFilter(
     const double& rScaleX,
     const double& rScaleY,
@@ -93,11 +68,7 @@ bool OpenGLSalBitmap::ImplScaleFilter(
     if( !pProgram )
         return false;
 
-    GLenum nFormat;
-    GLenum nType;
-    getFormatAndType(nFormat, nType);
-
-    OpenGLTexture aNewTex = OpenGLTexture(nNewWidth, nNewHeight, nFormat, nType, nullptr);
+    OpenGLTexture aNewTex(nNewWidth, nNewHeight);
     pFramebuffer = mpContext->AcquireFramebuffer( aNewTex );
 
     pProgram->SetTexture( "sampler", maTexture );
@@ -176,14 +147,10 @@ bool OpenGLSalBitmap::ImplScaleConvolution(
     if( pProgram == 0 )
         return false;
 
-    GLenum nFormat;
-    GLenum nType;
-    getFormatAndType(nFormat, nType);
-
     // horizontal scaling in scratch texture
     if( mnWidth != nNewWidth )
     {
-        OpenGLTexture aScratchTex = OpenGLTexture(nNewWidth, mnHeight, nFormat, nType, nullptr);
+        OpenGLTexture aScratchTex(nNewWidth, nNewHeight);
 
         pFramebuffer = mpContext->AcquireFramebuffer( aScratchTex );
 
@@ -206,7 +173,7 @@ bool OpenGLSalBitmap::ImplScaleConvolution(
     // vertical scaling in final texture
     if( mnHeight != nNewHeight )
     {
-        OpenGLTexture aScratchTex = OpenGLTexture(nNewWidth, nNewHeight, nFormat, nType, nullptr);
+        OpenGLTexture aScratchTex(nNewWidth, nNewHeight);
 
         pFramebuffer = mpContext->AcquireFramebuffer( aScratchTex );
 
@@ -267,11 +234,7 @@ bool OpenGLSalBitmap::ImplScaleArea( double rScaleX, double rScaleY )
     if( pProgram == 0 )
         return false;
 
-    GLenum nFormat;
-    GLenum nType;
-    getFormatAndType(nFormat, nType);
-
-    OpenGLTexture aScratchTex = OpenGLTexture(nNewWidth, nNewHeight, nFormat, nType, nullptr);
+    OpenGLTexture aScratchTex(nNewWidth, nNewHeight);
 
     OpenGLFramebuffer* pFramebuffer = mpContext->AcquireFramebuffer( aScratchTex );
 


More information about the Libreoffice-commits mailing list