LibreOffice Module canvas (master)  1
ogl_spritecanvas.cxx
Go to the documentation of this file.
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 <sal/config.h>
11 #include <sal/log.hxx>
12 
13 #include <com/sun/star/lang/NoSupportException.hpp>
15 #include <osl/mutex.hxx>
17 #include <tools/diagnose_ex.h>
18 
20 #include "ogl_spritecanvas.hxx"
21 
22 #define SPRITECANVAS_SERVICE_NAME "com.sun.star.rendering.SpriteCanvas.OGL"
23 #define SPRITECANVAS_IMPLEMENTATION_NAME "com.sun.star.comp.rendering.SpriteCanvas.OGL"
24 
25 
26 using namespace ::com::sun::star;
27 
29 
30 namespace oglcanvas
31 {
32  SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
33  const uno::Reference< uno::XComponentContext >& /*rxContext*/ ) :
34  maArguments(aArguments)
35  {
36  }
37 
39  {
40  // Only call initialize when not in probe mode
41  if( !maArguments.hasElements() )
42  return;
43 
44  SAL_INFO("canvas.ogl", "SpriteCanvas::initialize called" );
45 
46  /* aArguments:
47  0: ptr to creating instance (Window or VirtualDevice)
48  1: current bounds of creating instance
49  2: bool, denoting always on top state for Window (always false for VirtualDevice)
50  3: XWindow for creating Window (or empty for VirtualDevice)
51  4: SystemGraphicsData as a streamed Any
52  */
53  ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 &&
54  maArguments[3].getValueTypeClass() == uno::TypeClass_INTERFACE,
55  "OpenGL SpriteCanvas::initialize: wrong number of arguments, or wrong types" );
56 
57  uno::Reference< awt::XWindow > xParentWindow;
58  maArguments[3] >>= xParentWindow;
59  VclPtr<vcl::Window> pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
60  if( !pParentWindow )
61  throw lang::NoSupportException(
62  "Parent window not VCL window, or canvas out-of-process!", nullptr);
63 
64  awt::Rectangle aRect;
65  maArguments[1] >>= aRect;
66 
67  // setup helper
68  maDeviceHelper.init( *pParentWindow,
69  *this,
70  aRect );
71  maCanvasHelper.init( *this, maDeviceHelper );
72  maArguments.realloc(0);
73  }
74 
76  {
77  ::osl::MutexGuard aGuard( m_aMutex );
78 
79  // forward to parent
81  }
82 
84  {
85  ::osl::MutexGuard aGuard( m_aMutex );
86 
87  // avoid repaints on hidden window (hidden: not mapped to
88  // screen). Return failure, since the screen really has _not_
89  // been updated (caller should try again later)
90  return mbIsVisible && SpriteCanvasBaseT::showBuffer( bUpdateAll );
91  }
92 
94  {
95  ::osl::MutexGuard aGuard( m_aMutex );
96 
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::switchBuffer( bUpdateAll );
101  }
102 
103  uno::Reference< rendering::XAnimatedSprite > SAL_CALL SpriteCanvas::createSpriteFromAnimation(
104  const uno::Reference< rendering::XAnimation >& /*animation*/ )
105  {
106  return uno::Reference< rendering::XAnimatedSprite >();
107  }
108 
109  uno::Reference< rendering::XAnimatedSprite > SAL_CALL SpriteCanvas::createSpriteFromBitmaps(
110  const uno::Sequence< uno::Reference< rendering::XBitmap > >& /*animationBitmaps*/,
111  ::sal_Int8 /*interpolationMode*/ )
112  {
113  return uno::Reference< rendering::XAnimatedSprite >();
114  }
115 
116  uno::Reference< rendering::XCustomSprite > SAL_CALL SpriteCanvas::createCustomSprite(
117  const geometry::RealSize2D& spriteSize )
118  {
119  return uno::Reference< rendering::XCustomSprite >(
120  new CanvasCustomSprite(spriteSize, this, maDeviceHelper) );
121  }
122 
123  uno::Reference< rendering::XSprite > SAL_CALL SpriteCanvas::createClonedSprite(
124  const uno::Reference< rendering::XSprite >& /*original*/ )
125  {
126  return uno::Reference< rendering::XSprite >();
127  }
128 
130  {
131  ::osl::MutexGuard aGuard( m_aMutex );
132  return maDeviceHelper.showBuffer(mbIsVisible, bUpdateAll);
133  }
134 
135  OUString SAL_CALL SpriteCanvas::getServiceName( )
136  {
138  }
139 
140  void SpriteCanvas::show( const ::rtl::Reference< CanvasCustomSprite >& xSprite )
141  {
142  ::osl::MutexGuard aGuard( m_aMutex );
143  maDeviceHelper.show(xSprite);
144  }
145 
146  void SpriteCanvas::hide( const ::rtl::Reference< CanvasCustomSprite >& xSprite )
147  {
148  ::osl::MutexGuard aGuard( m_aMutex );
149  maDeviceHelper.hide(xSprite);
150  }
151 
153  {
154  maCanvasHelper.renderRecordedActions();
155  }
156 
157  static uno::Reference<uno::XInterface> initCanvas( SpriteCanvas* pCanvas )
158  {
159  uno::Reference<uno::XInterface> xRet(static_cast<cppu::OWeakObject*>(pCanvas));
160  pCanvas->initialize();
161  return xRet;
162  }
163 
166  serviceImpl,
169 }
170 
171 // The C shared lib entry points
172 extern "C"
173 SAL_DLLPUBLIC_EXPORT void* oglcanvas_component_getFactory( char const* pImplName,
174  void*, void* )
175 {
176  return sdecl::component_getFactoryHelper( pImplName, {&oglcanvas::oglSpriteCanvasDecl} );
177 }
178 
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_Bool SAL_CALL updateScreen(sal_Bool bUpdateAll) override
osl::Mutex m_aMutex
SAL_DLLPUBLIC_EXPORT void * oglcanvas_component_getFactory(char const *pImplName, void *, void *)
signed char sal_Int8
static VclPtr< vcl::Window > GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
css::uno::Sequence< css::uno::Any > maArguments
virtual css::uno::Reference< css::rendering::XAnimatedSprite > SAL_CALL createSpriteFromAnimation(const css::uno::Reference< css::rendering::XAnimation > &animation) override
Sequence< PropertyValue > aArguments
const sdecl::ServiceDecl oglSpriteCanvasDecl(serviceImpl, SPRITECANVAS_IMPLEMENTATION_NAME, SPRITECANVAS_SERVICE_NAME)
SpriteCanvas(const css::uno::Sequence< css::uno::Any > &aArguments, const css::uno::Reference< css::uno::XComponentContext > &rxContext)
sdecl::vba_service_class_< SwVbaDocument, sdecl::with_args< true > > const serviceImpl
#define SPRITECANVAS_SERVICE_NAME
void renderRecordedActions() const
Write out recorded actions.
unsigned char sal_Bool
virtual sal_Bool SAL_CALL switchBuffer(sal_Bool bUpdateAll) override
CanvasHelper maCanvasHelper
Definition: canvasbase.hxx:442
#define ENSURE_ARG_OR_THROW(c, m)
virtual sal_Bool SAL_CALL showBuffer(sal_Bool bUpdateAll) override
sdecl::class_< SpriteCanvas, sdecl::with_args< true > > const serviceImpl & initCanvas
void show(const ::rtl::Reference< CanvasCustomSprite > &)
Product of this component's factory.
#define SPRITECANVAS_IMPLEMENTATION_NAME
virtual css::uno::Reference< css::rendering::XCustomSprite > SAL_CALL createCustomSprite(const css::geometry::RealSize2D &spriteSize) override
virtual void disposeThis() override
Dispose all internal references.
#define SAL_INFO(area, stream)
virtual css::uno::Reference< css::rendering::XAnimatedSprite > SAL_CALL createSpriteFromBitmaps(const css::uno::Sequence< css::uno::Reference< css::rendering::XBitmap > > &animationBitmaps,::sal_Int8 interpolationMode) override
virtual void disposeThis() override
Definition: canvasbase.hxx:124
void hide(const ::rtl::Reference< CanvasCustomSprite > &)
virtual OUString SAL_CALL getServiceName() override
virtual css::uno::Reference< css::rendering::XSprite > SAL_CALL createClonedSprite(const css::uno::Reference< css::rendering::XSprite > &original) override