Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : */
9 :
10 : #include "ogl_spritecanvas.hxx"
11 :
12 : #include <canvas/debug.hxx>
13 : #include <canvas/verbosetrace.hxx>
14 : #include <tools/diagnose_ex.h>
15 :
16 : #include <osl/mutex.hxx>
17 :
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>
22 :
23 : #include <toolkit/helper/vclunohelper.hxx>
24 : #include <cppuhelper/factory.hxx>
25 : #include <cppuhelper/implementationentry.hxx>
26 : #include <comphelper/servicedecl.hxx>
27 :
28 : #include "ogl_canvascustomsprite.hxx"
29 :
30 : #include <GL/gl.h>
31 : #include <GL/glext.h>
32 :
33 : #define SPRITECANVAS_SERVICE_NAME "com.sun.star.rendering.SpriteCanvas.OGL"
34 : #define SPRITECANVAS_IMPLEMENTATION_NAME "com.sun.star.comp.rendering.SpriteCanvas.OGL"
35 :
36 :
37 : using namespace ::com::sun::star;
38 :
39 : namespace oglcanvas
40 : {
41 0 : SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
42 : const uno::Reference< uno::XComponentContext >& rxContext ) :
43 : maArguments(aArguments),
44 0 : mxComponentContext( rxContext )
45 : {
46 0 : }
47 :
48 0 : void SpriteCanvas::initialize()
49 : {
50 : // Only call initialize when not in probe mode
51 0 : if( maArguments.getLength() == 0 )
52 0 : return;
53 :
54 : VERBOSE_TRACE( "SpriteCanvas::initialize called" );
55 :
56 : /* aArguments:
57 : 0: ptr to creating instance (Window or VirtualDevice)
58 : 1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
59 : 2: current bounds of creating instance
60 : 3: bool, denoting always on top state for Window (always false for VirtualDevice)
61 : 4: XWindow for creating Window (or empty for VirtualDevice)
62 : 5: SystemGraphicsData as a streamed Any
63 : */
64 0 : ENSURE_ARG_OR_THROW( maArguments.getLength() >= 5 &&
65 : maArguments[4].getValueTypeClass() == uno::TypeClass_INTERFACE,
66 : "OpenGL SpriteCanvas::initialize: wrong number of arguments, or wrong types" );
67 :
68 0 : uno::Reference< awt::XWindow > xParentWindow;
69 0 : maArguments[4] >>= xParentWindow;
70 0 : Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
71 0 : if( !pParentWindow )
72 : throw lang::NoSupportException(
73 0 : "Parent window not VCL window, or canvas out-of-process!", NULL);
74 :
75 0 : awt::Rectangle aRect;
76 0 : maArguments[2] >>= aRect;
77 :
78 : // setup helper
79 : maDeviceHelper.init( *pParentWindow,
80 : *this,
81 0 : aRect );
82 0 : maCanvasHelper.init( *this, maDeviceHelper );
83 0 : maArguments.realloc(0);
84 : }
85 :
86 0 : void SAL_CALL SpriteCanvas::disposeThis()
87 : {
88 0 : ::osl::MutexGuard aGuard( m_aMutex );
89 :
90 0 : mxComponentContext.clear();
91 :
92 : // forward to parent
93 0 : SpriteCanvasBaseT::disposeThis();
94 0 : }
95 :
96 0 : sal_Bool SAL_CALL SpriteCanvas::showBuffer( sal_Bool bUpdateAll ) throw (uno::RuntimeException, std::exception)
97 : {
98 0 : ::osl::MutexGuard aGuard( m_aMutex );
99 :
100 : // avoid repaints on hidden window (hidden: not mapped to
101 : // screen). Return failure, since the screen really has _not_
102 : // been updated (caller should try again later)
103 0 : return !mbIsVisible ? false : SpriteCanvasBaseT::showBuffer( bUpdateAll );
104 : }
105 :
106 0 : sal_Bool SAL_CALL SpriteCanvas::switchBuffer( sal_Bool bUpdateAll ) throw (uno::RuntimeException)
107 : {
108 0 : ::osl::MutexGuard aGuard( m_aMutex );
109 :
110 : // avoid repaints on hidden window (hidden: not mapped to
111 : // screen). Return failure, since the screen really has _not_
112 : // been updated (caller should try again later)
113 0 : return !mbIsVisible ? false : SpriteCanvasBaseT::switchBuffer( bUpdateAll );
114 : }
115 :
116 0 : uno::Reference< rendering::XAnimatedSprite > SAL_CALL SpriteCanvas::createSpriteFromAnimation(
117 : const uno::Reference< rendering::XAnimation >& /*animation*/ ) throw (lang::IllegalArgumentException,
118 : uno::RuntimeException, std::exception)
119 : {
120 0 : return uno::Reference< rendering::XAnimatedSprite >();
121 : }
122 :
123 0 : uno::Reference< rendering::XAnimatedSprite > SAL_CALL SpriteCanvas::createSpriteFromBitmaps(
124 : const uno::Sequence< uno::Reference< rendering::XBitmap > >& /*animationBitmaps*/,
125 : ::sal_Int8 /*interpolationMode*/ ) throw (lang::IllegalArgumentException,
126 : rendering::VolatileContentDestroyedException,
127 : uno::RuntimeException, std::exception)
128 : {
129 0 : return uno::Reference< rendering::XAnimatedSprite >();
130 : }
131 :
132 0 : uno::Reference< rendering::XCustomSprite > SAL_CALL SpriteCanvas::createCustomSprite(
133 : const geometry::RealSize2D& spriteSize ) throw (lang::IllegalArgumentException,
134 : uno::RuntimeException, std::exception)
135 : {
136 : return uno::Reference< rendering::XCustomSprite >(
137 0 : new CanvasCustomSprite(spriteSize, this, maDeviceHelper) );
138 : }
139 :
140 0 : uno::Reference< rendering::XSprite > SAL_CALL SpriteCanvas::createClonedSprite(
141 : const uno::Reference< rendering::XSprite >& /*original*/ ) throw (lang::IllegalArgumentException,
142 : uno::RuntimeException, std::exception)
143 : {
144 0 : return uno::Reference< rendering::XSprite >();
145 : }
146 :
147 0 : sal_Bool SAL_CALL SpriteCanvas::updateScreen(sal_Bool bUpdateAll)
148 : throw (uno::RuntimeException, std::exception)
149 : {
150 0 : ::osl::MutexGuard aGuard( m_aMutex );
151 0 : return maDeviceHelper.showBuffer(mbIsVisible, bUpdateAll);
152 : }
153 :
154 0 : ::rtl::OUString SAL_CALL SpriteCanvas::getServiceName( ) throw (uno::RuntimeException, std::exception)
155 : {
156 0 : return ::rtl::OUString( SPRITECANVAS_SERVICE_NAME );
157 : }
158 :
159 0 : void SpriteCanvas::show( const ::rtl::Reference< CanvasCustomSprite >& xSprite )
160 : {
161 0 : ::osl::MutexGuard aGuard( m_aMutex );
162 0 : maDeviceHelper.show(xSprite);
163 0 : }
164 :
165 0 : void SpriteCanvas::hide( const ::rtl::Reference< CanvasCustomSprite >& xSprite )
166 : {
167 0 : ::osl::MutexGuard aGuard( m_aMutex );
168 0 : maDeviceHelper.hide(xSprite);
169 0 : }
170 :
171 0 : bool SpriteCanvas::renderRecordedActions() const
172 : {
173 0 : return maCanvasHelper.renderRecordedActions();
174 : }
175 :
176 0 : static uno::Reference<uno::XInterface> initCanvas( SpriteCanvas* pCanvas )
177 : {
178 0 : uno::Reference<uno::XInterface> xRet(static_cast<cppu::OWeakObject*>(pCanvas));
179 0 : pCanvas->initialize();
180 0 : return xRet;
181 : }
182 :
183 : namespace sdecl = comphelper::service_decl;
184 0 : sdecl::class_<SpriteCanvas, sdecl::with_args<true> > serviceImpl(&initCanvas);
185 0 : const sdecl::ServiceDecl oglSpriteCanvasDecl(
186 : serviceImpl,
187 : SPRITECANVAS_IMPLEMENTATION_NAME,
188 : SPRITECANVAS_SERVICE_NAME );
189 : }
190 :
191 : // The C shared lib entry points
192 0 : COMPHELPER_SERVICEDECL_EXPORTS1(oglcanvas, oglcanvas::oglSpriteCanvasDecl);
193 :
194 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|