[Libreoffice-commits] core.git: Branch 'libreoffice-5-2' - vcl/inc vcl/opengl

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Wed Jun 8 13:54:21 UTC 2016


 vcl/inc/opengl/texture.hxx |   10 ++++++++++
 vcl/opengl/texture.cxx     |   16 ++++++++--------
 2 files changed, 18 insertions(+), 8 deletions(-)

New commits:
commit 6efb6fa31270adc84b5884cd4a84e1a3296d535d
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Wed Jun 8 19:07:46 2016 +0900

    tdf#100184 fix the lifecycle of a texture in an atlas
    
    Previously, when a texture atlas was destroyed we teared down
    the  ImplOpenGLTexture even if there were OpenGLTexture instances
    around. This caused that we could try to access an already
    deallocated ImplOpenGLTexture which causes a seg. fault.
    
    Now we change this so that a FixedTexture is no different than a
    OpenGLTexture - we just release the reference, so any existing
    OpenGLTextures for our texture would still be valid.
    
    An additional problem is that FixedTexture registers a callback
    for slot deallocation so we know when a OpenGLTextures that holds
    a specific "slot" on the texture is deallocated. However if
    FixedTexture is not existent anymore, the callback still gets
    triggered and is trying to access invalid memory. To solve this
    we need to unregister callbacks before FixedTexture is destroyed.
    
    Additionally improve validity of a OpenGLTexture is valid. If
    ImplOpenGLTexture is not allocated (nullptr) is one case, but in
    addition to that if ImplOpenGLTexture has an id == 0 it also means
    that it is not valid (anymore).
    
    (cherry picked from commit 8dcf60ecbe9c159831ece3b6201882f1d0033472)
    
    Change-Id: I87346198e8928e112619da62687d5856cb8aafb8
    Reviewed-on: https://gerrit.libreoffice.org/26058
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/vcl/inc/opengl/texture.hxx b/vcl/inc/opengl/texture.hxx
index 5b4ccff..055ba21 100644
--- a/vcl/inc/opengl/texture.hxx
+++ b/vcl/inc/opengl/texture.hxx
@@ -66,6 +66,11 @@ public:
         mFunctSlotDeallocateCallback = aCallback;
     }
 
+    void ResetSlotDeallocateCallback()
+    {
+        mFunctSlotDeallocateCallback = std::function<void(int)>();
+    }
+
     GLuint AddStencil();
 };
 
@@ -78,6 +83,11 @@ private:
     ImplOpenGLTexture* mpImpl;
     int mnSlotNumber;
 
+    inline bool IsValid() const
+    {
+        return (mpImpl && mpImpl->mnTexture != 0);
+    }
+
 public:
                     OpenGLTexture();
                     OpenGLTexture(ImplOpenGLTexture* pImpl, Rectangle aRectangle, int nSlotNumber);
diff --git a/vcl/opengl/texture.cxx b/vcl/opengl/texture.cxx
index 0999484..bfe001b 100644
--- a/vcl/opengl/texture.cxx
+++ b/vcl/opengl/texture.cxx
@@ -364,7 +364,7 @@ void OpenGLTexture::GetCoord( GLfloat* pCoord, const SalTwoRect& rPosAry, bool b
 {
     VCL_GL_INFO( "Getting coord " << Id() << " [" << maRect.Left() << "," << maRect.Top() << "] " << GetWidth() << "x" << GetHeight() );
 
-    if( mpImpl == nullptr )
+    if (!IsValid())
     {
         pCoord[0] = pCoord[1] = pCoord[2] = pCoord[3] = 0.0f;
         pCoord[4] = pCoord[5] = pCoord[6] = pCoord[7] = 0.0f;
@@ -398,7 +398,7 @@ void OpenGLTexture::FillCoords<GL_TRIANGLES>(std::vector<GLfloat>& aCoord, const
     GLfloat y1 = 0.0f;
     GLfloat y2 = 0.0f;
 
-    if (mpImpl)
+    if (IsValid())
     {
         double fTextureWidth(mpImpl->mnWidth);
         double fTextureHeight(mpImpl->mnHeight);
@@ -457,7 +457,7 @@ void OpenGLTexture::GetWholeCoord( GLfloat* pCoord ) const
 
 OpenGLTexture OpenGLTexture::GetWholeTexture()
 {
-    if (mpImpl)
+    if (IsValid())
         return OpenGLTexture(mpImpl, Rectangle(Point(0, 0), Size(mpImpl->mnWidth, mpImpl->mnHeight)), -1);
     return OpenGLTexture();
 }
@@ -471,7 +471,7 @@ GLenum OpenGLTexture::GetFilter() const
 
 bool OpenGLTexture::CopyData(int nWidth, int nHeight, int nFormat, int nType, sal_uInt8* pData)
 {
-    if (!pData || mpImpl == nullptr)
+    if (!pData || !IsValid())
         return false;
 
     int nX = maRect.Left();
@@ -494,7 +494,7 @@ void OpenGLTexture::SetFilter( GLenum nFilter )
 
 void OpenGLTexture::Bind()
 {
-    if (mpImpl)
+    if (IsValid())
     {
         std::unique_ptr<RenderState>& rState = OpenGLContext::getVCLContext()->state();
         rState->texture().bind(mpImpl->mnTexture);
@@ -507,7 +507,7 @@ void OpenGLTexture::Bind()
 
 void OpenGLTexture::Unbind()
 {
-    if (mpImpl)
+    if (IsValid())
     {
         std::unique_ptr<RenderState>& rState = OpenGLContext::getVCLContext()->state();
         rState->texture().unbind(mpImpl->mnTexture);
@@ -534,7 +534,7 @@ void OpenGLTexture::SaveToFile(const OUString& rFileName)
 
 void OpenGLTexture::Read( GLenum nFormat, GLenum nType, sal_uInt8* pData )
 {
-    if( mpImpl == nullptr )
+    if (!IsValid())
     {
         SAL_WARN( "vcl.opengl", "Can't read invalid texture" );
         return;
@@ -575,7 +575,7 @@ void OpenGLTexture::Read( GLenum nFormat, GLenum nType, sal_uInt8* pData )
 
 OpenGLTexture::operator bool() const
 {
-    return ( mpImpl != nullptr );
+    return IsValid();
 }
 
 OpenGLTexture&  OpenGLTexture::operator=( const OpenGLTexture& rTexture )


More information about the Libreoffice-commits mailing list