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 | |
parent | 9ac5aa94665da9c6b9188716345e79ade00dd0cc (diff) |
vcl: Add support for GPU scaling when no rendering is involved
Change-Id: Id5aa4c1e843d286026a7bcd1297670db467dcbbc
-rw-r--r-- | vcl/inc/opengl/contextprovider.hxx | 28 | ||||
-rw-r--r-- | vcl/inc/unx/salgdi.h | 7 | ||||
-rw-r--r-- | vcl/opengl/salbmp.cxx | 62 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/salgdi.cxx | 9 |
4 files changed, 90 insertions, 16 deletions
diff --git a/vcl/inc/opengl/contextprovider.hxx b/vcl/inc/opengl/contextprovider.hxx new file mode 100644 index 000000000000..47eb98cd92e7 --- /dev/null +++ b/vcl/inc/opengl/contextprovider.hxx @@ -0,0 +1,28 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_VCL_INC_OPENGL_CONTEXTPROVIDER_HXX +#define INCLUDED_VCL_INC_OPENGL_CONTEXTPROVIDER_HXX + +#include "vclpluginapi.h" + +#include <vcl/opengl/OpenGLContext.hxx> + +class VCLPLUG_GEN_PUBLIC OpenGLContextProvider +{ +public: + virtual ~OpenGLContextProvider() {}; + + /* Get the OpenGL context provided by this instance */ + virtual OpenGLContext* GetOpenGLContext() const = 0; +}; + +#endif // INCLUDED_VCL_INC_OPENGL_CONTEXTPROVIDER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/unx/salgdi.h b/vcl/inc/unx/salgdi.h index e3d8a0c085f0..f693ed137db1 100644 --- a/vcl/inc/unx/salgdi.h +++ b/vcl/inc/unx/salgdi.h @@ -32,6 +32,8 @@ #include "sallayout.hxx" #include "vclpluginapi.h" +#include "opengl/contextprovider.hxx" + #include <boost/scoped_ptr.hpp> #include <deque> @@ -60,7 +62,7 @@ namespace basegfx { class B2DTrapezoid; } -class VCLPLUG_GEN_PUBLIC X11SalGraphics : public SalGraphics +class VCLPLUG_GEN_PUBLIC X11SalGraphics : public SalGraphics, public OpenGLContextProvider { friend class ServerFontLayout; friend class X11SalGraphicsImpl; @@ -297,6 +299,9 @@ public: unsigned int w, unsigned int h, int dest_x, int dest_y ); static void releaseGlyphPeer(); + +public: + virtual OpenGLContext* GetOpenGLContext() const SAL_OVERRIDE; }; inline const SalDisplay *X11SalGraphics::GetDisplay() const 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; diff --git a/vcl/unx/generic/gdi/salgdi.cxx b/vcl/unx/generic/gdi/salgdi.cxx index 62e8989d4839..2723db40d139 100644 --- a/vcl/unx/generic/gdi/salgdi.cxx +++ b/vcl/unx/generic/gdi/salgdi.cxx @@ -167,6 +167,15 @@ void X11SalGraphics::DeInit() SetDrawable( None, m_nXScreen ); } +OpenGLContext* X11SalGraphics::GetOpenGLContext() const +{ + OpenGLSalGraphicsImpl *pImpl; + pImpl = dynamic_cast<OpenGLSalGraphicsImpl*>(mpImpl.get()); + if( pImpl ) + return &pImpl->GetOpenGLContext(); + return NULL; +} + void X11SalGraphics::SetClipRegion( GC pGC, Region pXReg ) const { Display *pDisplay = GetXDisplay(); |