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>
31 
32 #include "cairo_spritecanvas.hxx"
33 
34 using namespace ::cairo;
35 using namespace ::com::sun::star;
36 
37 namespace cairocanvas
38 {
39  SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
40  const uno::Reference< uno::XComponentContext >& /*rxContext*/ ) :
41  maArguments(aArguments)
42  {
43  }
44 
46  {
47  SAL_INFO("canvas.cairo", "CairoSpriteCanvas created " << this);
48 
49  // #i64742# Only call initialize when not in probe mode
50  if( !maArguments.hasElements() )
51  return;
52 
53  /* maArguments:
54  0: ptr to creating instance (Window or VirtualDevice)
55  1: current bounds of creating instance
56  2: bool, denoting always on top state for Window (always false for VirtualDevice)
57  3: XWindow for creating Window (or empty for VirtualDevice)
58  4: SystemGraphicsData as a streamed Any
59  */
60  ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 &&
61  maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER &&
62  maArguments[3].getValueTypeClass() == uno::TypeClass_INTERFACE,
63  "CairoSpriteCanvas::initialize: wrong number of arguments, or wrong types" );
64 
65  awt::Rectangle aRect;
66  maArguments[1] >>= aRect;
67 
68  bool bIsFullscreen( false );
69  maArguments[2] >>= bIsFullscreen;
70 
71  uno::Reference< awt::XWindow > xParentWindow;
72  maArguments[3] >>= xParentWindow;
73 
74  VclPtr<vcl::Window> pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
75  if( !pParentWindow )
76  throw lang::NoSupportException(
77  "Parent window not VCL window, or canvas out-of-process!", nullptr);
78 
79  bool bHasCairo = pParentWindow->SupportsCairo();
80  ENSURE_ARG_OR_THROW(bHasCairo,
81  "CairoSpriteCanvas::SpriteCanvas: No Cairo capability");
82 
83  Size aPixelSize( pParentWindow->GetOutputSizePixel() );
84  const ::basegfx::B2ISize aSize( aPixelSize.Width(),
85  aPixelSize.Height() );
86 
87  // setup helper
88  maDeviceHelper.init( *pParentWindow,
89  *this,
90  aSize,
91  bIsFullscreen );
92 
93  setWindow(uno::Reference<awt::XWindow2>(xParentWindow, uno::UNO_QUERY_THROW));
94 
96  *this,
97  aSize );
98 
99  maArguments.realloc(0);
100  }
101 
103  {
104  ::osl::MutexGuard aGuard( m_aMutex );
105 
106  // forward to parent
108  }
109 
111  {
112  return updateScreen( bUpdateAll );
113  }
114 
116  {
117  return updateScreen( bUpdateAll );
118  }
119 
121  {
122  ::osl::MutexGuard aGuard( m_aMutex );
123 
124  // avoid repaints on hidden window (hidden: not mapped to
125  // screen). Return failure, since the screen really has _not_
126  // been updated (caller should try again later)
127  return mbIsVisible && maCanvasHelper.updateScreen(
129  bUpdateAll,
131  }
132 
133  OUString SAL_CALL SpriteCanvas::getServiceName( )
134  {
136  }
137 
139  {
140  return maDeviceHelper.getBufferSurface();
141  }
142 
143  SurfaceSharedPtr SpriteCanvas::createSurface( const ::basegfx::B2ISize& rSize, int aContent )
144  {
145  return maDeviceHelper.createSurface( rSize, aContent );
146  }
147 
149  {
151  if( rBitmap.GetSystemData( aData ) ) {
152  const Size& rSize = rBitmap.GetSizePixel();
153 
154  return maDeviceHelper.createSurface( aData, rSize );
155  }
156 
157  return SurfaceSharedPtr();
158  }
159 
161  {
162  // non-modifiable surface here
163  return SurfaceSharedPtr();
164  }
165 
167  {
168  return maDeviceHelper.getOutputDevice();
169  }
170 
172  {
173  return maDeviceHelper.getBufferSurface();
174  }
175 
177  {
178  return maDeviceHelper.getWindowSurface();
179  }
180 
181  const ::basegfx::B2ISize& SpriteCanvas::getSizePixel() const
182  {
183  return maDeviceHelper.getSizePixel();
184  }
185 
186  void SpriteCanvas::setSizePixel( const ::basegfx::B2ISize& rSize )
187  {
188  maCanvasHelper.setSize( rSize );
189  // re-set background surface, in case it needed recreation
190  maCanvasHelper.setSurface( maDeviceHelper.getBufferSurface(),
191  false );
192  }
193 
195  {
196  maDeviceHelper.flush();
197  }
198 
199  bool SpriteCanvas::repaint( const SurfaceSharedPtr& pSurface,
200  const rendering::ViewState& viewState,
201  const rendering::RenderState& renderState )
202  {
203  return maCanvasHelper.repaint( pSurface, viewState, renderState );
204  }
205 }
206 
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void disposeThis() override
Dispose all internal references.
osl::Mutex m_aMutex
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 ::cairo::SurfaceSharedPtr createSurface(const ::basegfx::B2ISize &rSize, int aContent) override
virtual ::cairo::SurfaceSharedPtr getSurface() 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
#define SPRITECANVAS_SERVICE_NAME
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:442
#define ENSURE_ARG_OR_THROW(c, m)
::cairo::SurfaceSharedPtr const & getWindowSurface() const
#define SAL_INFO(area, stream)
void setSizePixel(const ::basegfx::B2ISize &rSize)
virtual OutputDevice * getOutputDevice() override
::basegfx::B2DRectangle maBounds
::cairo::SurfaceSharedPtr const & getBufferSurface() const
virtual sal_Bool SAL_CALL updateScreen(sal_Bool bUpdateAll) override