diff options
author | Louis-Francis Ratté-Boulianne <lfrb@collabora.com> | 2014-11-12 13:16:29 -0500 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-11-13 07:54:17 +0100 |
commit | 1aef60fb3fbd5d9ce6521fd861207e6af7bcc5fb (patch) | |
tree | 91353eda7fdca2d802f07e2fcbcf60c3e56906bf /vcl/opengl | |
parent | 9ac5aa94665da9c6b9188716345e79ade00dd0cc (diff) |
vcl: Add support for GPU scaling when no rendering is involved
Change-Id: Id5aa4c1e843d286026a7bcd1297670db467dcbbc
Diffstat (limited to 'vcl/opengl')
-rw-r--r-- | vcl/opengl/salbmp.cxx | 62 |
1 files changed, 47 insertions, 15 deletions
diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx index ad794b1eab46..686a7850b9bd 100644 --- a/vcl/opengl/salbmp.cxx +++ b/vcl/opengl/salbmp.cxx @@ -22,9 +22,12 @@ #include <vcl/opengl/OpenGLHelper.hxx> #include "vcl/bitmap.hxx" +#include "vcl/outdev.hxx" #include "vcl/salbtype.hxx" +#include "svdata.hxx" #include "salgdi.hxx" +#include "opengl/contextprovider.hxx" #include "opengl/salbmp.hxx" static bool isValidBitCount( sal_uInt16 nBitCount ) @@ -420,31 +423,44 @@ GLuint OpenGLSalBitmap::CreateTexture() bool OpenGLSalBitmap::ReadTexture() { - SalTwoRect aPosAry; - GLuint nFramebufferId, nRenderbufferDepthId, nRenderbufferColorId; + GLuint nFramebufferId; sal_uInt8* pData = maUserBuffer.get(); + GLenum nFormat = GL_RGBA; + GLenum nType = GL_UNSIGNED_BYTE; - SAL_INFO( "vcl.opengl", "::ReadTexture" ); + SAL_INFO( "vcl.opengl", "::ReadTexture " << mnWidth << "x" << mnHeight ); - // TODO Check mnTexWidth and mnTexHeight + if( pData == NULL ) + return false; + + if( mnBits == 16 || mnBits == 24 || mnBits == 32 ) + { + // no conversion needed for truecolor + pData = maUserBuffer.get(); + + switch( mnBits ) + { + 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: nFormat = GL_RGBA; + nType = GL_UNSIGNED_BYTE; + break; + } + } mpContext->makeCurrent(); - OpenGLHelper::createFramebuffer( mnWidth, mnHeight, nFramebufferId, - nRenderbufferDepthId, nRenderbufferColorId, true ); + glGenFramebuffers( 1, &nFramebufferId ); glBindFramebuffer( GL_FRAMEBUFFER, nFramebufferId ); - aPosAry.mnSrcX = aPosAry.mnDestX = 0; - aPosAry.mnSrcY = aPosAry.mnDestY = 0; - aPosAry.mnSrcWidth = aPosAry.mnDestWidth = mnWidth; - aPosAry.mnSrcHeight = aPosAry.mnDestHeight = mnHeight; - - //DrawTexture( mnTexture, aPosAry ); - glReadPixels( 0, 0, mnWidth, mnHeight, GL_RGBA, GL_UNSIGNED_BYTE, pData ); + glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mpTexture->Id(), 0 ); + glReadPixels( 0, 0, mnWidth, mnHeight, nFormat, nType, pData ); glBindFramebuffer( GL_FRAMEBUFFER, 0 ); glDeleteFramebuffers( 1, &nFramebufferId ); - glDeleteRenderbuffers( 1, &nRenderbufferDepthId ); - glDeleteRenderbuffers( 1, &nRenderbufferColorId ); CHECK_GL_ERROR(); return true; @@ -465,6 +481,22 @@ BitmapBuffer* OpenGLSalBitmap::AcquireBuffer( bool /*bReadOnly*/ ) return NULL; } + if( !maPendingOps.empty() ) + { + OpenGLContextProvider *pProvider; + pProvider = dynamic_cast< OpenGLContextProvider* >( ImplGetDefaultWindow()->GetGraphics() ); + if( pProvider == NULL ) + { + SAL_WARN( "vcl.opengl", "Couldn't get default OpenGL context provider" ); + return NULL; + } + mpContext = pProvider->GetOpenGLContext(); + mpContext->makeCurrent(); + SAL_INFO( "vcl.opengl", "** Creating texture and reading it back immediatly" ); + if( !CreateTexture() || !AllocateUserData() || !ReadTexture() ) + return NULL; + } + BitmapBuffer* pBuffer = new BitmapBuffer; pBuffer->mnWidth = mnWidth; pBuffer->mnHeight = mnHeight; |