LibreOffice Module canvas (master)  1
cairo_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  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <sal/config.h>
21 #include <sal/log.hxx>
22 
25 #include <com/sun/star/awt/XTopWindow.hpp>
26 #include <com/sun/star/awt/Rectangle.hpp>
27 #include <com/sun/star/lang/NoSupportException.hpp>
28 #include <osl/mutex.hxx>
30 #include <tools/diagnose_ex.h>
32 
33 #include "cairo_spritecanvas.hxx"
34 
35 using namespace ::cairo;
36 using namespace ::com::sun::star;
37 
38 namespace cairocanvas
39 {
40  SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
41  const uno::Reference< uno::XComponentContext >& /*rxContext*/ ) :
42  maArguments(aArguments)
43  {
44  }
45 
47  {
48  SAL_INFO("canvas.cairo", "CairoSpriteCanvas created " << this);
49 
50  // #i64742# Only call initialize when not in probe mode
51  if( !maArguments.hasElements() )
52  return;
53 
54  /* maArguments:
55  0: ptr to creating instance (Window or VirtualDevice)
56  1: current bounds of creating instance
57  2: bool, denoting always on top state for Window (always false for VirtualDevice)
58  3: XWindow for creating Window (or empty for VirtualDevice)
59  4: SystemGraphicsData as a streamed Any
60  */
61  ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 &&
62  maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER &&
63  maArguments[3].getValueTypeClass() == uno::TypeClass_INTERFACE,
64  "CairoSpriteCanvas::initialize: wrong number of arguments, or wrong types" );
65 
66  awt::Rectangle aRect;
67  maArguments[1] >>= aRect;
68 
69  bool bIsFullscreen( false );
70  maArguments[2] >>= bIsFullscreen;
71 
72  uno::Reference< awt::XWindow > xParentWindow;
73  maArguments[3] >>= xParentWindow;
74 
75  VclPtr<vcl::Window> pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
76  if( !pParentWindow )
77  throw lang::NoSupportException(
78  "Parent window not VCL window, or canvas out-of-process!", nullptr);
79 
80  bool bHasCairo = pParentWindow->SupportsCairo();
81  ENSURE_ARG_OR_THROW(bHasCairo,
82  "CairoSpriteCanvas::SpriteCanvas: No Cairo capability");
83 
84  Size aPixelSize( pParentWindow->GetOutputSizePixel() );
85  const ::basegfx::B2ISize aSize( aPixelSize.Width(),
86  aPixelSize.Height() );
87 
88  // setup helper
89  maDeviceHelper.init( *pParentWindow,
90  *this,
91  aSize,
92  bIsFullscreen );
93 
94  setWindow(uno::Reference<awt::XWindow2>(xParentWindow, uno::UNO_QUERY_THROW));
95 
97  *this,
98  aSize );
99 
100  maArguments.realloc(0);
101  }
102 
104  {
105  ::osl::MutexGuard aGuard( m_aMutex );
106 
107  // forward to parent
109  }
110 
112  {
113  return updateScreen( bUpdateAll );
114  }
115 
117  {
118  return updateScreen( bUpdateAll );
119  }
120 
122  {
123  ::osl::MutexGuard aGuard( m_aMutex );
124 
125  // avoid repaints on hidden window (hidden: not mapped to
126  // screen). Return failure, since the screen really has _not_
127  // been updated (caller should try again later)
128  return mbIsVisible && maCanvasHelper.updateScreen(
130  bUpdateAll,
132  }
133 
134  OUString SAL_CALL SpriteCanvas::getServiceName( )
135  {
136  return "com.sun.star.rendering.SpriteCanvas.Cairo";
137  }
138 
139  // XServiceInfo
140  sal_Bool SpriteCanvas::supportsService(const OUString& sServiceName)
141  {
142  return cppu::supportsService(this, sServiceName);
143 
144  }
146  {
147  return "com.sun.star.comp.rendering.Canvas.Cairo";
148  }
149  css::uno::Sequence< OUString > SpriteCanvas::getSupportedServiceNames()
150  {
151  return { getServiceName() };
152  }
153 
155  {
156  return maDeviceHelper.getBufferSurface();
157  }
158 
159  SurfaceSharedPtr SpriteCanvas::createSurface( const ::basegfx::B2ISize& rSize, int aContent )
160  {
161  return maDeviceHelper.createSurface( rSize, aContent );
162  }
163 
165  {
167  if( rBitmap.GetSystemData( aData ) ) {
168  const Size& rSize = rBitmap.GetSizePixel();
169 
170  return maDeviceHelper.createSurface( aData, rSize );
171  }
172 
173  return SurfaceSharedPtr();
174  }
175 
177  {
178  // non-modifiable surface here
179  return SurfaceSharedPtr();
180  }
181 
183  {
184  return maDeviceHelper.getOutputDevice();
185  }
186 
188  {
189  return maDeviceHelper.getBufferSurface();
190  }
191 
193  {
194  return maDeviceHelper.getWindowSurface();
195  }
196 
197  const ::basegfx::B2ISize& SpriteCanvas::getSizePixel() const
198  {
199  return maDeviceHelper.getSizePixel();
200  }
201 
202  void SpriteCanvas::setSizePixel( const ::basegfx::B2ISize& rSize )
203  {
204  maCanvasHelper.setSize( rSize );
205  // re-set background surface, in case it needed recreation
206  maCanvasHelper.setSurface( maDeviceHelper.getBufferSurface(),
207  false );
208  }
209 
211  {
212  maDeviceHelper.flush();
213  }
214 
215  bool SpriteCanvas::repaint( const SurfaceSharedPtr& pSurface,
216  const rendering::ViewState& viewState,
217  const rendering::RenderState& renderState )
218  {
219  return maCanvasHelper.repaint( pSurface, viewState, renderState );
220  }
221 }
222 
223 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
225  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
226 {
227  auto p = new cairocanvas::SpriteCanvas(args, context);
228  p->acquire();
229  p->initialize();
230  return static_cast<cppu::OWeakObject*>(p);
231 }
232 
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void disposeThis() override
Dispose all internal references.
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_rendering_SpriteCanvas_Cairo_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
const char aData[]
bool SupportsCairo() const
static VclPtr< vcl::Window > GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
const ::basegfx::B2ISize & getSizePixel() const
SpriteCanvas(const css::uno::Sequence< css::uno::Any > &aArguments, const css::uno::Reference< css::uno::XComponentContext > &rxContext)
Size GetSizePixel() const
virtual OUString SAL_CALL getImplementationName() override
virtual ::cairo::SurfaceSharedPtr createSurface(const ::basegfx::B2ISize &rSize, int aContent) override
virtual ::cairo::SurfaceSharedPtr getSurface() override
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
virtual ::cairo::SurfaceSharedPtr changeSurface() override
SpriteRedrawManager maRedrawManager
css::uno::Sequence< css::uno::Any > maArguments
::basegfx::B2IRange b2IRectangleFromAwtRectangle(const awt::Rectangle &rRect)
virtual sal_Bool SAL_CALL showBuffer(sal_Bool bUpdateAll) override
std::shared_ptr< Surface > SurfaceSharedPtr
virtual OUString SAL_CALL getServiceName() override
virtual bool repaint(const ::cairo::SurfaceSharedPtr &pSurface, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState) override
virtual sal_Bool SAL_CALL switchBuffer(sal_Bool bUpdateAll) override
unsigned char sal_Bool
bool GetSystemData(BitmapSystemData &rData) const
Size GetOutputSizePixel() const
virtual void disposeThis() override
CanvasHelper maCanvasHelper
Definition: canvasbase.hxx:441
#define ENSURE_ARG_OR_THROW(c, m)
::cairo::SurfaceSharedPtr const & getWindowSurface() const
Product of this component's factory.
#define SAL_INFO(area, stream)
void setSizePixel(const ::basegfx::B2ISize &rSize)
void * p
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual OutputDevice * getOutputDevice() override
osl::Mutex m_aMutex
::basegfx::B2DRectangle maBounds
::cairo::SurfaceSharedPtr const & getBufferSurface() const
virtual sal_Bool SAL_CALL updateScreen(sal_Bool bUpdateAll) override