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

Tomaž Vajngerl tomaz.vajngerl at collabora.com
Mon Nov 7 13:00:02 UTC 2016


 vcl/inc/opengl/texture.hxx        |   10 ++--------
 vcl/opengl/FixedTextureAtlas.cxx  |    3 +--
 vcl/opengl/PackedTextureAtlas.cxx |    6 +++---
 vcl/opengl/texture.cxx            |   28 ++++++++++------------------
 4 files changed, 16 insertions(+), 31 deletions(-)

New commits:
commit 19dc288ce4a5ad7a386ff2b4208b7284d8731067
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Sun Oct 2 18:09:30 2016 +0200

    opengl: use shared_ptr for ImplOpenGLTexture
    
    Change-Id: I755e312e3e0a69b99a8f02f7d05561b7289845ce
    Reviewed-on: https://gerrit.libreoffice.org/30597
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    Tested-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/vcl/inc/opengl/texture.hxx b/vcl/inc/opengl/texture.hxx
index c8f658e..a0c8029 100644
--- a/vcl/inc/opengl/texture.hxx
+++ b/vcl/inc/opengl/texture.hxx
@@ -32,7 +32,6 @@
 
 class ImplOpenGLTexture
 {
-    int    mnRefCount;
 public:
     GLuint mnTexture;
     int    mnWidth;
@@ -53,11 +52,6 @@ public:
     void IncreaseRefCount(int nSlotNumber);
     void DecreaseRefCount(int nSlotNumber);
 
-    bool IsUnique()
-    {
-        return mnRefCount == 1;
-    }
-
     bool InitializeSlotMechanism(int nInitialSlotSize);
 
     void SetSlotDeallocateCallback(std::function<void(int)> aCallback)
@@ -79,7 +73,7 @@ private:
     // if the rect size doesn't match the mpImpl one, this instance
     // is a sub-area from the real OpenGL texture
     Rectangle maRect;
-    ImplOpenGLTexture* mpImpl;
+    std::shared_ptr<ImplOpenGLTexture> mpImpl;
     int mnSlotNumber;
 
     inline bool GetTextureRect(const SalTwoRect& rPosAry, bool bInverted, GLfloat& x1, GLfloat& x2, GLfloat& y1, GLfloat& y2) const;
@@ -91,7 +85,7 @@ private:
 
 public:
                     OpenGLTexture();
-                    OpenGLTexture(ImplOpenGLTexture* pImpl, Rectangle aRectangle, int nSlotNumber);
+                    OpenGLTexture(const std::shared_ptr<ImplOpenGLTexture>& pImpl, Rectangle aRectangle, int nSlotNumber);
 
                     OpenGLTexture( int nWidth, int nHeight, bool bAllocate = true );
                     OpenGLTexture( int nWidth, int nHeight, int nFormat, int nType, void const * pData );
diff --git a/vcl/opengl/FixedTextureAtlas.cxx b/vcl/opengl/FixedTextureAtlas.cxx
index 963818c..33a5a13 100644
--- a/vcl/opengl/FixedTextureAtlas.cxx
+++ b/vcl/opengl/FixedTextureAtlas.cxx
@@ -21,7 +21,7 @@
 
 struct FixedTexture
 {
-    ImplOpenGLTexture* mpTexture;
+    std::shared_ptr<ImplOpenGLTexture> mpTexture;
     int mnFreeSlots;
     std::vector<bool> maAllocatedSlots;
 
@@ -42,7 +42,6 @@ struct FixedTexture
     ~FixedTexture()
     {
         mpTexture->ResetSlotDeallocateCallback();
-        mpTexture->DecreaseRefCount(-1);
     }
 
     void allocateSlot(int nSlot)
diff --git a/vcl/opengl/PackedTextureAtlas.cxx b/vcl/opengl/PackedTextureAtlas.cxx
index 46fdf3b..bad1758 100644
--- a/vcl/opengl/PackedTextureAtlas.cxx
+++ b/vcl/opengl/PackedTextureAtlas.cxx
@@ -109,7 +109,7 @@ Node* Node::insert(int nWidth, int nHeight, int nPadding)
 
 struct PackedTexture
 {
-    std::unique_ptr<ImplOpenGLTexture> mpTexture;
+    std::shared_ptr<ImplOpenGLTexture> mpTexture;
     std::unique_ptr<Node> mpRootNode;
 
     PackedTexture(int nWidth, int nHeight)
@@ -149,7 +149,7 @@ OpenGLTexture PackedTextureAtlasManager::Reserve(int nWidth, int nHeight)
         Node* pNode = pPackedTexture->mpRootNode->insert(nWidth, nHeight, 1);
         if (pNode != nullptr)
         {
-            return OpenGLTexture(pPackedTexture->mpTexture.get(), pNode->mRectangle, -1);
+            return OpenGLTexture(pPackedTexture->mpTexture, pNode->mRectangle, -1);
         }
     }
     CreateNewTexture();
@@ -157,7 +157,7 @@ OpenGLTexture PackedTextureAtlasManager::Reserve(int nWidth, int nHeight)
     Node* pNode = pPackedTexture->mpRootNode->insert(nWidth, nHeight, 1);
     if (pNode != nullptr)
     {
-        return OpenGLTexture(pPackedTexture->mpTexture.get(), pNode->mRectangle, -1);
+        return OpenGLTexture(pPackedTexture->mpTexture, pNode->mRectangle, -1);
     }
     return OpenGLTexture();
 }
diff --git a/vcl/opengl/texture.cxx b/vcl/opengl/texture.cxx
index 0681161..2c05b35 100644
--- a/vcl/opengl/texture.cxx
+++ b/vcl/opengl/texture.cxx
@@ -40,7 +40,6 @@ SAL_CONSTEXPR GLenum constInternalFormat = GL_RGBA8;
 
 // texture with allocated size
 ImplOpenGLTexture::ImplOpenGLTexture( int nWidth, int nHeight, bool bAllocate ) :
-    mnRefCount( 1 ),
     mnTexture( 0 ),
     mnWidth( nWidth ),
     mnHeight( nHeight ),
@@ -73,7 +72,6 @@ ImplOpenGLTexture::ImplOpenGLTexture( int nWidth, int nHeight, bool bAllocate )
 
 // texture with content retrieved from FBO
 ImplOpenGLTexture::ImplOpenGLTexture( int nX, int nY, int nWidth, int nHeight ) :
-    mnRefCount( 1 ),
     mnTexture( 0 ),
     mnWidth( nWidth ),
     mnHeight( nHeight ),
@@ -106,7 +104,6 @@ ImplOpenGLTexture::ImplOpenGLTexture( int nX, int nY, int nWidth, int nHeight )
 
 // texture from buffer data
 ImplOpenGLTexture::ImplOpenGLTexture( int nWidth, int nHeight, int nFormat, int nType, void const * pData ) :
-    mnRefCount( 1 ),
     mnTexture( 0 ),
     mnWidth( nWidth ),
     mnHeight( nHeight ),
@@ -224,7 +221,6 @@ bool ImplOpenGLTexture::InitializeSlotMechanism(int nInitialSlotSize)
 
 void ImplOpenGLTexture::IncreaseRefCount(int nSlotNumber)
 {
-    mnRefCount++;
     if (mpSlotReferences && nSlotNumber >= 0)
     {
         if (nSlotNumber >= int(mpSlotReferences->size()))
@@ -248,23 +244,18 @@ void ImplOpenGLTexture::DecreaseRefCount(int nSlotNumber)
             mFunctSlotDeallocateCallback(nSlotNumber);
         }
     }
-
-    mnRefCount--;
-    if (mnRefCount <= 0)
-        delete this;
 }
 
-
 OpenGLTexture::OpenGLTexture() :
     maRect( 0, 0, 0, 0 ),
-    mpImpl(nullptr),
+    mpImpl(),
     mnSlotNumber(-1)
 {
 }
 
-OpenGLTexture::OpenGLTexture(ImplOpenGLTexture* pImpl, Rectangle aRectangle, int nSlotNumber)
+OpenGLTexture::OpenGLTexture(const std::shared_ptr<ImplOpenGLTexture>& rpImpl, Rectangle aRectangle, int nSlotNumber)
     : maRect(aRectangle)
-    , mpImpl(pImpl)
+    , mpImpl(rpImpl)
     , mnSlotNumber(nSlotNumber)
 {
     if (mpImpl)
@@ -273,23 +264,24 @@ OpenGLTexture::OpenGLTexture(ImplOpenGLTexture* pImpl, Rectangle aRectangle, int
 
 OpenGLTexture::OpenGLTexture( int nWidth, int nHeight, bool bAllocate )
     : maRect( Point( 0, 0 ), Size( nWidth, nHeight ) )
+    , mpImpl(new ImplOpenGLTexture(nWidth, nHeight, bAllocate))
     , mnSlotNumber(-1)
 {
-    mpImpl = new ImplOpenGLTexture( nWidth, nHeight, bAllocate );
 }
 
 OpenGLTexture::OpenGLTexture( int nX, int nY, int nWidth, int nHeight )
     : maRect( Point( 0, 0 ), Size( nWidth, nHeight ) )
+    , mpImpl(new ImplOpenGLTexture(nX, nY, nWidth, nHeight))
     , mnSlotNumber(-1)
 {
-    mpImpl = new ImplOpenGLTexture( nX, nY, nWidth, nHeight );
 }
 
 OpenGLTexture::OpenGLTexture( int nWidth, int nHeight, int nFormat, int nType, void const * pData )
     : maRect( Point( 0, 0 ), Size( nWidth, nHeight ) )
+    , mpImpl(new ImplOpenGLTexture(nWidth, nHeight, nFormat, nType, pData))
     , mnSlotNumber(-1)
 {
-    mpImpl = new ImplOpenGLTexture( nWidth, nHeight, nFormat, nType, pData );
+
 }
 
 OpenGLTexture::OpenGLTexture( const OpenGLTexture& rTexture )
@@ -322,12 +314,12 @@ OpenGLTexture::~OpenGLTexture()
 
 bool OpenGLTexture::IsUnique() const
 {
-    return mpImpl == nullptr || mpImpl->IsUnique();
+    return mpImpl || mpImpl.unique();
 }
 
 GLuint OpenGLTexture::Id() const
 {
-    if( mpImpl )
+    if (mpImpl)
         return mpImpl->mnTexture;
     return 0;
 }
@@ -572,7 +564,7 @@ OpenGLTexture::operator bool() const
     return IsValid();
 }
 
-OpenGLTexture&  OpenGLTexture::operator=( const OpenGLTexture& rTexture )
+OpenGLTexture& OpenGLTexture::operator=( const OpenGLTexture& rTexture )
 {
     if (rTexture.mpImpl)
     {


More information about the Libreoffice-commits mailing list