diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-07-31 16:31:29 +0900 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-08-03 09:23:31 +0900 |
commit | 6d9ddfb9c7a946e9b9cc58ae2cebcf3a21a5bf22 (patch) | |
tree | 7991a528f7dc5366b48fe620eb2dcbc0d2f74d69 /vcl | |
parent | 21f128623292b3d90f3b736f3c5c268a677e18ff (diff) |
opengl: when scaling, create a new texture with equal settings
Change-Id: Id0258fe0db89aa06b91233ae2052f018d606cc74
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/opengl/salbmp.hxx | 2 | ||||
-rw-r--r-- | vcl/opengl/scale.cxx | 52 |
2 files changed, 49 insertions, 5 deletions
diff --git a/vcl/inc/opengl/salbmp.hxx b/vcl/inc/opengl/salbmp.hxx index daefbe26b8a2..8baee941f1a4 100644 --- a/vcl/inc/opengl/salbmp.hxx +++ b/vcl/inc/opengl/salbmp.hxx @@ -102,6 +102,8 @@ private: bool ImplScaleConvolution(const double& rScaleX, const double& rScaleY, const vcl::Kernel& rKernel); bool ImplScaleArea( double rScaleX, double rScaleY ); + bool getFormatAndType(GLenum& nFormat, GLenum& nType); + public: bool ImplScale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag ); diff --git a/vcl/opengl/scale.cxx b/vcl/opengl/scale.cxx index 22db644c0454..0b2d5cf3b2a8 100644 --- a/vcl/opengl/scale.cxx +++ b/vcl/opengl/scale.cxx @@ -51,6 +51,31 @@ public: void GetSize( Size& rSize ) const SAL_OVERRIDE; }; +bool OpenGLSalBitmap::getFormatAndType(GLenum& nFormat, GLenum& nType) +{ + switch(mnBits) + { + case 8: + nFormat = GL_LUMINANCE; + nType = GL_UNSIGNED_BYTE; + break; + case 16: + nFormat = GL_RGB; + nType = GL_UNSIGNED_SHORT_5_6_5; + break; + case 24: + nFormat = GL_RGB; + nType = GL_UNSIGNED_BYTE; + break; + case 32: + default: + nFormat = GL_RGBA; + nType = GL_UNSIGNED_BYTE; + break; + } + return true; +} + bool OpenGLSalBitmap::ImplScaleFilter( const double& rScaleX, const double& rScaleY, @@ -67,7 +92,11 @@ bool OpenGLSalBitmap::ImplScaleFilter( if( !pProgram ) return false; - OpenGLTexture aNewTex = OpenGLTexture( nNewWidth, nNewHeight ); + GLenum nFormat; + GLenum nType; + getFormatAndType(nFormat, nType); + + OpenGLTexture aNewTex = OpenGLTexture(nNewWidth, nNewHeight, nFormat, nType, nullptr); pFramebuffer = mpContext->AcquireFramebuffer( aNewTex ); pProgram->SetTexture( "sampler", maTexture ); @@ -146,10 +175,15 @@ bool OpenGLSalBitmap::ImplScaleConvolution( if( pProgram == 0 ) return false; + GLenum nFormat; + GLenum nType; + getFormatAndType(nFormat, nType); + // horizontal scaling in scratch texture if( mnWidth != nNewWidth ) { - OpenGLTexture aScratchTex = OpenGLTexture( nNewWidth, mnHeight ); + OpenGLTexture aScratchTex = OpenGLTexture(nNewWidth, mnHeight, nFormat, nType, nullptr); + pFramebuffer = mpContext->AcquireFramebuffer( aScratchTex ); for( sal_uInt32 i = 0; i < 16; i++ ) @@ -171,7 +205,8 @@ bool OpenGLSalBitmap::ImplScaleConvolution( // vertical scaling in final texture if( mnHeight != nNewHeight ) { - OpenGLTexture aScratchTex = OpenGLTexture( nNewWidth, nNewHeight ); + OpenGLTexture aScratchTex = OpenGLTexture(nNewWidth, nNewHeight, nFormat, nType, nullptr); + pFramebuffer = mpContext->AcquireFramebuffer( aScratchTex ); for( sal_uInt32 i = 0; i < 16; i++ ) @@ -231,7 +266,12 @@ bool OpenGLSalBitmap::ImplScaleArea( double rScaleX, double rScaleY ) if( pProgram == 0 ) return false; - OpenGLTexture aScratchTex = OpenGLTexture( nNewWidth, nNewHeight ); + GLenum nFormat; + GLenum nType; + getFormatAndType(nFormat, nType); + + OpenGLTexture aScratchTex = OpenGLTexture(nNewWidth, nNewHeight, nFormat, nType, nullptr); + OpenGLFramebuffer* pFramebuffer = mpContext->AcquireFramebuffer( aScratchTex ); // NOTE: This setup is also done in OpenGLSalGraphicsImpl::DrawTransformedTexture(). @@ -333,7 +373,9 @@ void ScaleOp::GetSize( Size& rSize ) const bool OpenGLSalBitmap::Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag ) { - SAL_INFO( "vcl.opengl", "::Scale " << static_cast<int>(nScaleFlag) ); + SAL_INFO("vcl.opengl", "::Scale " << int(nScaleFlag) + << " from " << mnWidth << "x" << mnHeight + << " to " << (mnWidth * rScaleX) << "x" << (mnHeight * rScaleY) ); if( nScaleFlag == BmpScaleFlag::Fast || nScaleFlag == BmpScaleFlag::BiLinear || |