Branch libreoffice-5-0-4
[LibreOffice.git] / canvas / source / opengl / ogl_spritecanvas.cxx
blob75d96b12940015a00e944a1e709f33b725fb826e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include "ogl_spritecanvas.hxx"
12 #include <canvas/debug.hxx>
13 #include <canvas/verbosetrace.hxx>
14 #include <tools/diagnose_ex.h>
16 #include <osl/mutex.hxx>
18 #include <com/sun/star/uno/XComponentContext.hpp>
19 #include <com/sun/star/registry/XRegistryKey.hpp>
20 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
21 #include <com/sun/star/lang/NoSupportException.hpp>
23 #include <toolkit/helper/vclunohelper.hxx>
24 #include <cppuhelper/factory.hxx>
25 #include <cppuhelper/implementationentry.hxx>
26 #include <comphelper/servicedecl.hxx>
28 #include "ogl_canvascustomsprite.hxx"
30 #define SPRITECANVAS_SERVICE_NAME "com.sun.star.rendering.SpriteCanvas.OGL"
31 #define SPRITECANVAS_IMPLEMENTATION_NAME "com.sun.star.comp.rendering.SpriteCanvas.OGL"
34 using namespace ::com::sun::star;
36 namespace oglcanvas
38 SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
39 const uno::Reference< uno::XComponentContext >& rxContext ) :
40 maArguments(aArguments),
41 mxComponentContext( rxContext )
45 void SpriteCanvas::initialize()
47 // Only call initialize when not in probe mode
48 if( maArguments.getLength() == 0 )
49 return;
51 VERBOSE_TRACE( "SpriteCanvas::initialize called" );
53 /* aArguments:
54 0: ptr to creating instance (Window or VirtualDevice)
55 1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
56 2: current bounds of creating instance
57 3: bool, denoting always on top state for Window (always false for VirtualDevice)
58 4: XWindow for creating Window (or empty for VirtualDevice)
59 5: SystemGraphicsData as a streamed Any
61 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 5 &&
62 maArguments[4].getValueTypeClass() == uno::TypeClass_INTERFACE,
63 "OpenGL SpriteCanvas::initialize: wrong number of arguments, or wrong types" );
65 uno::Reference< awt::XWindow > xParentWindow;
66 maArguments[4] >>= xParentWindow;
67 vcl::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
68 if( !pParentWindow )
69 throw lang::NoSupportException(
70 "Parent window not VCL window, or canvas out-of-process!", NULL);
72 awt::Rectangle aRect;
73 maArguments[2] >>= aRect;
75 // setup helper
76 maDeviceHelper.init( *pParentWindow,
77 *this,
78 aRect );
79 maCanvasHelper.init( *this, maDeviceHelper );
80 maArguments.realloc(0);
83 void SpriteCanvas::disposeThis()
85 ::osl::MutexGuard aGuard( m_aMutex );
87 mxComponentContext.clear();
89 // forward to parent
90 SpriteCanvasBaseT::disposeThis();
93 sal_Bool SAL_CALL SpriteCanvas::showBuffer( sal_Bool bUpdateAll ) throw (uno::RuntimeException, std::exception)
95 ::osl::MutexGuard aGuard( m_aMutex );
97 // avoid repaints on hidden window (hidden: not mapped to
98 // screen). Return failure, since the screen really has _not_
99 // been updated (caller should try again later)
100 return mbIsVisible && SpriteCanvasBaseT::showBuffer( bUpdateAll );
103 sal_Bool SAL_CALL SpriteCanvas::switchBuffer( sal_Bool bUpdateAll ) throw (uno::RuntimeException, std::exception)
105 ::osl::MutexGuard aGuard( m_aMutex );
107 // avoid repaints on hidden window (hidden: not mapped to
108 // screen). Return failure, since the screen really has _not_
109 // been updated (caller should try again later)
110 return mbIsVisible && SpriteCanvasBaseT::switchBuffer( bUpdateAll );
113 uno::Reference< rendering::XAnimatedSprite > SAL_CALL SpriteCanvas::createSpriteFromAnimation(
114 const uno::Reference< rendering::XAnimation >& /*animation*/ ) throw (lang::IllegalArgumentException,
115 uno::RuntimeException, std::exception)
117 return uno::Reference< rendering::XAnimatedSprite >();
120 uno::Reference< rendering::XAnimatedSprite > SAL_CALL SpriteCanvas::createSpriteFromBitmaps(
121 const uno::Sequence< uno::Reference< rendering::XBitmap > >& /*animationBitmaps*/,
122 ::sal_Int8 /*interpolationMode*/ ) throw (lang::IllegalArgumentException,
123 rendering::VolatileContentDestroyedException,
124 uno::RuntimeException, std::exception)
126 return uno::Reference< rendering::XAnimatedSprite >();
129 uno::Reference< rendering::XCustomSprite > SAL_CALL SpriteCanvas::createCustomSprite(
130 const geometry::RealSize2D& spriteSize ) throw (lang::IllegalArgumentException,
131 uno::RuntimeException, std::exception)
133 return uno::Reference< rendering::XCustomSprite >(
134 new CanvasCustomSprite(spriteSize, this, maDeviceHelper) );
137 uno::Reference< rendering::XSprite > SAL_CALL SpriteCanvas::createClonedSprite(
138 const uno::Reference< rendering::XSprite >& /*original*/ ) throw (lang::IllegalArgumentException,
139 uno::RuntimeException, std::exception)
141 return uno::Reference< rendering::XSprite >();
144 sal_Bool SAL_CALL SpriteCanvas::updateScreen(sal_Bool bUpdateAll)
145 throw (uno::RuntimeException, std::exception)
147 ::osl::MutexGuard aGuard( m_aMutex );
148 return maDeviceHelper.showBuffer(mbIsVisible, bUpdateAll);
151 ::rtl::OUString SAL_CALL SpriteCanvas::getServiceName( ) throw (uno::RuntimeException, std::exception)
153 return ::rtl::OUString( SPRITECANVAS_SERVICE_NAME );
156 void SpriteCanvas::show( const ::rtl::Reference< CanvasCustomSprite >& xSprite )
158 ::osl::MutexGuard aGuard( m_aMutex );
159 maDeviceHelper.show(xSprite);
162 void SpriteCanvas::hide( const ::rtl::Reference< CanvasCustomSprite >& xSprite )
164 ::osl::MutexGuard aGuard( m_aMutex );
165 maDeviceHelper.hide(xSprite);
168 bool SpriteCanvas::renderRecordedActions() const
170 return maCanvasHelper.renderRecordedActions();
173 static uno::Reference<uno::XInterface> initCanvas( SpriteCanvas* pCanvas )
175 uno::Reference<uno::XInterface> xRet(static_cast<cppu::OWeakObject*>(pCanvas));
176 pCanvas->initialize();
177 return xRet;
180 namespace sdecl = comphelper::service_decl;
181 sdecl::class_<SpriteCanvas, sdecl::with_args<true> > serviceImpl(&initCanvas);
182 const sdecl::ServiceDecl oglSpriteCanvasDecl(
183 serviceImpl,
184 SPRITECANVAS_IMPLEMENTATION_NAME,
185 SPRITECANVAS_SERVICE_NAME );
188 // The C shared lib entry points
189 COMPHELPER_SERVICEDECL_EXPORTS1(oglcanvas, oglcanvas::oglSpriteCanvasDecl);
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */