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>
14 #include <osl/mutex.hxx>
16 #include <tools/diagnose_ex.h>
18 
20 #include "ogl_spritecanvas.hxx"
21 
22 using namespace ::com::sun::star;
23 
24 namespace oglcanvas
25 {
26  SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
27  const uno::Reference< uno::XComponentContext >& /*rxContext*/ ) :
28  maArguments(aArguments)
29  {
30  }
31 
32  void SpriteCanvas::initialize()
33  {
34  // Only call initialize when not in probe mode
35  if( !maArguments.hasElements() )
36  return;
37 
38  SAL_INFO("canvas.ogl", "SpriteCanvas::initialize called" );
39 
40  /* aArguments:
41  0: ptr to creating instance (Window or VirtualDevice)
42  1: current bounds of creating instance
43  2: bool, denoting always on top state for Window (always false for VirtualDevice)
44  3: XWindow for creating Window (or empty for VirtualDevice)
45  4: SystemGraphicsData as a streamed Any
46  */
47  ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 &&
48  maArguments[3].getValueTypeClass() == uno::TypeClass_INTERFACE,
49  "OpenGL SpriteCanvas::initialize: wrong number of arguments, or wrong types" );
50 
51  uno::Reference< awt::XWindow > xParentWindow;
52  maArguments[3] >>= xParentWindow;
53  VclPtr<vcl::Window> pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
54  if( !pParentWindow )
55  throw lang::NoSupportException(
56  "Parent window not VCL window, or canvas out-of-process!", nullptr);
57 
58  awt::Rectangle aRect;
59  maArguments[1] >>= aRect;
60 
61  // setup helper
62  maDeviceHelper.init( *pParentWindow,
63  *this,
64  aRect );
65  maCanvasHelper.init( *this, maDeviceHelper );
66  maArguments.realloc(0);
67  }
68 
69  void SpriteCanvas::disposeThis()
70  {
71  ::osl::MutexGuard aGuard( m_aMutex );
72 
73  // forward to parent
74  SpriteCanvasBaseT::disposeThis();
75  }
76 
77  sal_Bool SAL_CALL SpriteCanvas::showBuffer( sal_Bool bUpdateAll )
78  {
79  ::osl::MutexGuard aGuard( m_aMutex );
80 
81  // avoid repaints on hidden window (hidden: not mapped to
82  // screen). Return failure, since the screen really has _not_
83  // been updated (caller should try again later)
84  return mbIsVisible && SpriteCanvasBaseT::showBuffer( bUpdateAll );
85  }
86 
87  sal_Bool SAL_CALL SpriteCanvas::switchBuffer( sal_Bool bUpdateAll )
88  {
89  ::osl::MutexGuard aGuard( m_aMutex );
90 
91  // avoid repaints on hidden window (hidden: not mapped to
92  // screen). Return failure, since the screen really has _not_
93  // been updated (caller should try again later)
94  return mbIsVisible && SpriteCanvasBaseT::switchBuffer( bUpdateAll );
95  }
96 
97  uno::Reference< rendering::XAnimatedSprite > SAL_CALL SpriteCanvas::createSpriteFromAnimation(
98  const uno::Reference< rendering::XAnimation >& /*animation*/ )
99  {
100  return uno::Reference< rendering::XAnimatedSprite >();
101  }
102 
103  uno::Reference< rendering::XAnimatedSprite > SAL_CALL SpriteCanvas::createSpriteFromBitmaps(
104  const uno::Sequence< uno::Reference< rendering::XBitmap > >& /*animationBitmaps*/,
105  ::sal_Int8 /*interpolationMode*/ )
106  {
107  return uno::Reference< rendering::XAnimatedSprite >();
108  }
109 
110  uno::Reference< rendering::XCustomSprite > SAL_CALL SpriteCanvas::createCustomSprite(
111  const geometry::RealSize2D& spriteSize )
112  {
113  return uno::Reference< rendering::XCustomSprite >(
114  new CanvasCustomSprite(spriteSize, this, maDeviceHelper) );
115  }
116 
117  uno::Reference< rendering::XSprite > SAL_CALL SpriteCanvas::createClonedSprite(
118  const uno::Reference< rendering::XSprite >& /*original*/ )
119  {
120  return uno::Reference< rendering::XSprite >();
121  }
122 
123  sal_Bool SAL_CALL SpriteCanvas::updateScreen(sal_Bool bUpdateAll)
124  {
125  ::osl::MutexGuard aGuard( m_aMutex );
126  return maDeviceHelper.showBuffer(mbIsVisible, bUpdateAll);
127  }
128 
129  OUString SAL_CALL SpriteCanvas::getServiceName( )
130  {
131  return "com.sun.star.rendering.SpriteCanvas.OGL";
132  }
133 
134  void SpriteCanvas::show( const ::rtl::Reference< CanvasCustomSprite >& xSprite )
135  {
136  ::osl::MutexGuard aGuard( m_aMutex );
137  maDeviceHelper.show(xSprite);
138  }
139 
140  void SpriteCanvas::hide( const ::rtl::Reference< CanvasCustomSprite >& xSprite )
141  {
142  ::osl::MutexGuard aGuard( m_aMutex );
143  maDeviceHelper.hide(xSprite);
144  }
145 
146  void SpriteCanvas::renderRecordedActions() const
147  {
148  maCanvasHelper.renderRecordedActions();
149  }
150 
151 }
152 
153 
154 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
156  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
157 {
159  return nullptr;
160  auto p = new oglcanvas::SpriteCanvas(args, context);
161  cppu::acquire(p);
162  p->initialize();
163  return static_cast<cppu::OWeakObject*>(p);
164 }
165 
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
osl::Mutex m_aMutex
signed char sal_Int8
static VclPtr< vcl::Window > GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
SpriteCanvas(const css::uno::Sequence< css::uno::Any > &aArguments, const css::uno::Reference< css::uno::XComponentContext > &rxContext)
unsigned char sal_Bool
#define ENSURE_ARG_OR_THROW(c, m)
Product of this component's factory.
#define SAL_INFO(area, stream)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_rendering_SpriteCanvas_OGL_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
void * p
static bool supportsOpenGL()