summaryrefslogtreecommitdiff
path: root/vcl/opengl
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.com>2016-10-02 18:09:30 +0200
committerTomaž Vajngerl <quikee@gmail.com>2016-11-07 12:59:38 +0000
commit19dc288ce4a5ad7a386ff2b4208b7284d8731067 (patch)
treeefff7545278a77719dfd821439ec97ad3bb2b7eb /vcl/opengl
parent055be3f4be764e445064effabf06de9d1ed819f7 (diff)
opengl: use shared_ptr for ImplOpenGLTexture
Change-Id: I755e312e3e0a69b99a8f02f7d05561b7289845ce Reviewed-on: https://gerrit.libreoffice.org/30597 Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/opengl')
-rw-r--r--vcl/opengl/FixedTextureAtlas.cxx3
-rw-r--r--vcl/opengl/PackedTextureAtlas.cxx6
-rw-r--r--vcl/opengl/texture.cxx28
3 files changed, 14 insertions, 23 deletions
diff --git a/vcl/opengl/FixedTextureAtlas.cxx b/vcl/opengl/FixedTextureAtlas.cxx
index 963818c17847..33a5a1360374 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 46fdf3b5a36b..bad17587762d 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 0681161b2b29..2c05b35cb95c 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)
{