Kaydet (Commit) 19dc288c authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

opengl: use shared_ptr for ImplOpenGLTexture

Change-Id: I755e312e3e0a69b99a8f02f7d05561b7289845ce
Reviewed-on: https://gerrit.libreoffice.org/30597Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
Tested-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst 055be3f4
......@@ -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 );
......
......@@ -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)
......
......@@ -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();
}
......
......@@ -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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment