Update git submodules
[LibreOffice.git] / canvas / source / opengl / ogl_spritecanvas.cxx
blob9bec462f96e2fcc0bc25fe3c1bac5fd86cb8e2a2
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 <sal/config.h>
11 #include <sal/log.hxx>
13 #include <com/sun/star/lang/NoSupportException.hpp>
14 #include <osl/mutex.hxx>
15 #include <toolkit/helper/vclunohelper.hxx>
16 #include <comphelper/diagnose_ex.hxx>
17 #include <vcl/opengl/OpenGLHelper.hxx>
18 #include <vcl/window.hxx>
20 #include "ogl_canvascustomsprite.hxx"
21 #include "ogl_spritecanvas.hxx"
23 using namespace ::com::sun::star;
25 namespace oglcanvas
27 SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
28 const uno::Reference< uno::XComponentContext >& /*rxContext*/ ) :
29 maArguments(aArguments)
33 void SpriteCanvas::initialize()
35 // Only call initialize when not in probe mode
36 if( !maArguments.hasElements() )
37 return;
39 SAL_INFO("canvas.ogl", "SpriteCanvas::initialize called" );
41 /* aArguments:
42 0: ptr to creating instance (Window or VirtualDevice)
43 1: current bounds of creating instance
44 2: bool, denoting always on top state for Window (always false for VirtualDevice)
45 3: XWindow for creating Window (or empty for VirtualDevice)
46 4: SystemGraphicsData as a streamed Any
48 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 &&
49 maArguments[3].getValueTypeClass() == uno::TypeClass_INTERFACE,
50 "OpenGL SpriteCanvas::initialize: wrong number of arguments, or wrong types" );
52 uno::Reference< awt::XWindow > xParentWindow;
53 maArguments[3] >>= xParentWindow;
54 VclPtr<vcl::Window> pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
55 if( !pParentWindow )
56 throw lang::NoSupportException(
57 u"Parent window not VCL window, or canvas out-of-process!"_ustr, nullptr);
59 awt::Rectangle aRect;
60 maArguments[1] >>= aRect;
62 // setup helper
63 maDeviceHelper.init( *pParentWindow,
64 *this,
65 aRect );
66 maCanvasHelper.init( *this, maDeviceHelper );
67 maArguments.realloc(0);
70 void SpriteCanvas::disposeThis()
72 ::osl::MutexGuard aGuard( m_aMutex );
74 // forward to parent
75 SpriteCanvasBaseT::disposeThis();
78 sal_Bool SAL_CALL SpriteCanvas::showBuffer( sal_Bool bUpdateAll )
80 ::osl::MutexGuard aGuard( m_aMutex );
82 // avoid repaints on hidden window (hidden: not mapped to
83 // screen). Return failure, since the screen really has _not_
84 // been updated (caller should try again later)
85 return mbIsVisible && SpriteCanvasBaseT::showBuffer( bUpdateAll );
88 sal_Bool SAL_CALL SpriteCanvas::switchBuffer( sal_Bool bUpdateAll )
90 ::osl::MutexGuard aGuard( m_aMutex );
92 // avoid repaints on hidden window (hidden: not mapped to
93 // screen). Return failure, since the screen really has _not_
94 // been updated (caller should try again later)
95 return mbIsVisible && SpriteCanvasBaseT::switchBuffer( bUpdateAll );
98 uno::Reference< rendering::XAnimatedSprite > SAL_CALL SpriteCanvas::createSpriteFromAnimation(
99 const uno::Reference< rendering::XAnimation >& /*animation*/ )
101 return uno::Reference< rendering::XAnimatedSprite >();
104 uno::Reference< rendering::XAnimatedSprite > SAL_CALL SpriteCanvas::createSpriteFromBitmaps(
105 const uno::Sequence< uno::Reference< rendering::XBitmap > >& /*animationBitmaps*/,
106 ::sal_Int8 /*interpolationMode*/ )
108 return uno::Reference< rendering::XAnimatedSprite >();
111 uno::Reference< rendering::XCustomSprite > SAL_CALL SpriteCanvas::createCustomSprite(
112 const geometry::RealSize2D& spriteSize )
114 return uno::Reference< rendering::XCustomSprite >(
115 new CanvasCustomSprite(spriteSize, this, maDeviceHelper) );
118 uno::Reference< rendering::XSprite > SAL_CALL SpriteCanvas::createClonedSprite(
119 const uno::Reference< rendering::XSprite >& /*original*/ )
121 return uno::Reference< rendering::XSprite >();
124 sal_Bool SAL_CALL SpriteCanvas::updateScreen(sal_Bool bUpdateAll)
126 ::osl::MutexGuard aGuard( m_aMutex );
127 return maDeviceHelper.showBuffer(mbIsVisible, bUpdateAll);
130 OUString SAL_CALL SpriteCanvas::getServiceName( )
132 return u"com.sun.star.rendering.SpriteCanvas.OGL"_ustr;
135 void SpriteCanvas::show( const ::rtl::Reference< CanvasCustomSprite >& xSprite )
137 ::osl::MutexGuard aGuard( m_aMutex );
138 maDeviceHelper.show(xSprite);
141 void SpriteCanvas::hide( const ::rtl::Reference< CanvasCustomSprite >& xSprite )
143 ::osl::MutexGuard aGuard( m_aMutex );
144 maDeviceHelper.hide(xSprite);
147 void SpriteCanvas::renderRecordedActions() const
149 maCanvasHelper.renderRecordedActions();
155 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
156 com_sun_star_comp_rendering_SpriteCanvas_OGL_get_implementation(
157 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
159 if( !OpenGLHelper::supportsOpenGL())
160 return nullptr;
161 rtl::Reference<oglcanvas::SpriteCanvas> p = new oglcanvas::SpriteCanvas(args, context);
162 p->initialize();
163 return cppu::acquire(p.get());
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */