diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2016-06-08 19:07:46 +0900 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2016-06-08 19:35:45 +0900 |
commit | 8dcf60ecbe9c159831ece3b6201882f1d0033472 (patch) | |
tree | cfcfc0db0a7896e247eb8752624cc62ae2a7f578 /vcl/opengl/texture.cxx | |
parent | 6cd3882bec5aa63b61d7cc9db66ff3bae5d43f1c (diff) |
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).
Change-Id: I87346198e8928e112619da62687d5856cb8aafb8
Diffstat (limited to 'vcl/opengl/texture.cxx')
-rw-r--r-- | vcl/opengl/texture.cxx | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/vcl/opengl/texture.cxx b/vcl/opengl/texture.cxx index 3de7ac8d705e..03055c451bf6 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; @@ -388,7 +388,7 @@ void OpenGLTexture::GetCoord( GLfloat* pCoord, const SalTwoRect& rPosAry, bool b bool OpenGLTexture::GetTextureRect(const SalTwoRect& rPosAry, bool bInverted, GLfloat& x1, GLfloat& x2, GLfloat& y1, GLfloat& y2) const { - if (mpImpl) + if (IsValid()) { double fTextureWidth(mpImpl->mnWidth); double fTextureHeight(mpImpl->mnHeight); @@ -463,7 +463,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(); } @@ -477,7 +477,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(); @@ -500,7 +500,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); @@ -513,7 +513,7 @@ void OpenGLTexture::Bind() void OpenGLTexture::Unbind() { - if (mpImpl) + if (IsValid()) { std::unique_ptr<RenderState>& rState = OpenGLContext::getVCLContext()->state(); rState->texture().unbind(mpImpl->mnTexture); @@ -540,7 +540,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; @@ -581,7 +581,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 ) |