diff options
author | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-05-09 00:31:05 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2014-05-09 00:39:42 +0200 |
commit | 7ffd1af7228e05d05229ec66923208b6c4fdb845 (patch) | |
tree | dec51320175b5be0c8d929250c584c2da93d1ee3 | |
parent | 6470b42ce82ddd862c21adf853d27ce0184abc06 (diff) |
move the renderToFile function to the helper to avoid the context
Change-Id: I5493126047179d67b2f2ed0d3d5d936ebbaf4810
-rw-r--r-- | include/vcl/opengl/OpenGLHelper.hxx | 1 | ||||
-rw-r--r-- | vcl/source/opengl/OpenGLContext.cxx | 13 | ||||
-rw-r--r-- | vcl/source/opengl/OpenGLHelper.cxx | 18 |
3 files changed, 20 insertions, 12 deletions
diff --git a/include/vcl/opengl/OpenGLHelper.hxx b/include/vcl/opengl/OpenGLHelper.hxx index 3530b2b7ec80..4afeae49228a 100644 --- a/include/vcl/opengl/OpenGLHelper.hxx +++ b/include/vcl/opengl/OpenGLHelper.hxx @@ -23,6 +23,7 @@ public: static sal_uInt8* ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx); static BitmapEx ConvertBGRABufferToBitmapEx(const sal_uInt8* const pBuffer, long nWidth, long nHeight); + static void renderToFile(long nWidth, long nHeight, const OUString& rFileName); static const char* GLErrorString(GLenum errorCode); }; diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx index f79a16052b41..8ad2d7a365aa 100644 --- a/vcl/source/opengl/OpenGLContext.cxx +++ b/vcl/source/opengl/OpenGLContext.cxx @@ -558,20 +558,9 @@ void OpenGLContext::renderToFile() { int iWidth = m_aGLWin.Width; int iHeight = m_aGLWin.Height; - boost::scoped_array<sal_uInt8> buf(new sal_uInt8[iWidth * iHeight * 4]); - glReadPixels(0, 0, iWidth, iHeight, GL_BGRA, GL_UNSIGNED_BYTE, buf.get()); - - BitmapEx aBmp = OpenGLHelper::ConvertBGRABufferToBitmapEx(buf.get(), iWidth, iHeight); static int nIdx = 0; OUString aName = OUString( "file:///home/moggi/Documents/work/output" ) + OUString::number( nIdx++ ) + ".png"; - try { - vcl::PNGWriter aWriter( aBmp ); - SvFileStream sOutput( aName, STREAM_WRITE ); - aWriter.Write( sOutput ); - sOutput.Close(); - } catch (...) { - SAL_WARN("vcl.opengl", "Error writing png to " << aName); - } + OpenGLHelper::renderToFile(iWidth, iHeight, aName); } #if defined( WNT ) diff --git a/vcl/source/opengl/OpenGLHelper.cxx b/vcl/source/opengl/OpenGLHelper.cxx index 0ed24d0844d7..4ef2ce0e62d7 100644 --- a/vcl/source/opengl/OpenGLHelper.cxx +++ b/vcl/source/opengl/OpenGLHelper.cxx @@ -14,6 +14,9 @@ #include <config_folders.h> #include <vcl/salbtype.hxx> #include <vcl/bmpacc.hxx> +#include <boost/scoped_array.hpp> +#include <vcl/pngwrite.hxx> +#include <vcl/graph.hxx> #include <vector> @@ -168,6 +171,21 @@ sal_uInt8* OpenGLHelper::ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx) return pBitmapBuf; } +void OpenGLHelper::renderToFile(long nWidth, long nHeight, const OUString& rFileName) +{ + boost::scoped_array<sal_uInt8> pBuffer(new sal_uInt8[nWidth*nHeight*4]); + glReadPixels(0, 0, nWidth, nHeight, GL_BGRA, GL_UNSIGNED_BYTE, pBuffer.get()); + BitmapEx aBitmap = ConvertBGRABufferToBitmapEx(pBuffer.get(), nWidth, nHeight); + try { + vcl::PNGWriter aWriter( aBitmap ); + SvFileStream sOutput( rFileName, STREAM_WRITE ); + aWriter.Write( sOutput ); + sOutput.Close(); + } catch (...) { + SAL_WARN("vcl.opengl", "Error writing png to " << rFileName); + } +} + BitmapEx OpenGLHelper::ConvertBGRABufferToBitmapEx(const sal_uInt8* const pBuffer, long nWidth, long nHeight) { assert(pBuffer); |