1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include "oglframegrabber.hxx"
12 #include <cppuhelper/supportsservice.hxx>
13 #include <vcl/bitmapex.hxx>
14 #include <vcl/graph.hxx>
15 #include <vcl/salbtype.hxx>
16 #include <vcl/bmpacc.hxx>
18 #include <vcl/opengl/OpenGLHelper.hxx>
20 #include <boost/scoped_array.hpp>
22 using namespace com::sun::star
;
23 using namespace libgltf
;
25 namespace avmedia
{ namespace ogl
{
27 OGLFrameGrabber::OGLFrameGrabber( glTFHandle
& rHandle
)
29 , m_rHandle( rHandle
)
33 OGLFrameGrabber::~OGLFrameGrabber()
37 uno::Reference
< css::graphic::XGraphic
> SAL_CALL
OGLFrameGrabber::grabFrame( double /*fMediaTime*/ )
38 throw ( uno::RuntimeException
, std::exception
)
40 boost::scoped_array
<sal_uInt8
> pBuffer(new sal_uInt8
[m_rHandle
.viewport
.width
* m_rHandle
.viewport
.height
* 4]);
41 glTFHandle
* pHandle
= &m_rHandle
;
42 int nRet
= gltf_renderer_get_bitmap(&pHandle
, 1, reinterpret_cast<char*>(pBuffer
.get()), GL_BGRA
);
45 SAL_WARN("avmedia.opengl", "Error occurred while rendering to bitmap! Error code: " << nRet
);
46 return uno::Reference
< css::graphic::XGraphic
>();
48 BitmapEx aBitmap
= OpenGLHelper::ConvertBGRABufferToBitmapEx(pBuffer
.get(), m_rHandle
.viewport
.width
, m_rHandle
.viewport
.height
);
49 return Graphic( aBitmap
).GetXGraphic();
52 OUString SAL_CALL
OGLFrameGrabber::getImplementationName() throw ( uno::RuntimeException
, std::exception
)
54 return OUString("com.sun.star.comp.avmedia.FrameGrabber_OpenGL");
57 sal_Bool SAL_CALL
OGLFrameGrabber::supportsService( const OUString
& rServiceName
)
58 throw ( uno::RuntimeException
, std::exception
)
60 return cppu::supportsService(this, rServiceName
);
63 uno::Sequence
< OUString
> SAL_CALL
OGLFrameGrabber::getSupportedServiceNames()
64 throw ( uno::RuntimeException
, std::exception
)
66 uno::Sequence
< OUString
> aRet(1);
67 aRet
[0] = "com.sun.star.media.FrameGrabber_OpenGL";
72 } // namespace avmedia
74 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */