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>
32
34
35using namespace ::cairo;
36using namespace ::com::sun::star;
37
38namespace cairocanvas
39{
40 SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
41 const uno::Reference< uno::XComponentContext >& /*rxContext*/ ) :
42 maArguments(aArguments)
43 {
44 }
45
46 void SpriteCanvas::initialize()
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->GetOutDev()->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
96 maCanvasHelper.init( maRedrawManager,
97 *this,
98 aSize );
99
100 maArguments.realloc(0);
101 }
102
103 void SpriteCanvas::disposeThis()
104 {
105 ::osl::MutexGuard aGuard( m_aMutex );
106
107 // forward to parent
108 SpriteCanvasBaseT::disposeThis();
109 }
110
111 sal_Bool SAL_CALL SpriteCanvas::showBuffer( sal_Bool bUpdateAll )
112 {
113 return updateScreen( bUpdateAll );
114 }
115
116 sal_Bool SAL_CALL SpriteCanvas::switchBuffer( sal_Bool bUpdateAll )
117 {
118 return updateScreen( bUpdateAll );
119 }
120
121 sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll )
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(
129 ::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds),
130 bUpdateAll,
131 mbSurfaceDirty);
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 {
143
144 }
145 OUString SpriteCanvas::getImplementationName()
146 {
147 return "com.sun.star.comp.rendering.SpriteCanvas.Cairo";
148 }
149 css::uno::Sequence< OUString > SpriteCanvas::getSupportedServiceNames()
150 {
151 return { getServiceName() };
152 }
153
154 SurfaceSharedPtr SpriteCanvas::getSurface()
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
164 SurfaceSharedPtr SpriteCanvas::createSurface( ::Bitmap& rBitmap )
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
176 SurfaceSharedPtr SpriteCanvas::changeSurface()
177 {
178 // non-modifiable surface here
179 return SurfaceSharedPtr();
180 }
181
182 OutputDevice* SpriteCanvas::getOutputDevice()
183 {
184 return maDeviceHelper.getOutputDevice();
185 }
186
187 SurfaceSharedPtr const & SpriteCanvas::getBufferSurface() const
188 {
189 return maDeviceHelper.getBufferSurface();
190 }
191
192 SurfaceSharedPtr const & SpriteCanvas::getWindowSurface() const
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
210 void SpriteCanvas::flush()
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
223extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
225 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
226{
228 p->initialize();
229 return cppu::acquire(p.get());
230}
231
232/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral sServiceName
::basegfx::B2DRectangle maBounds
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)
Size GetSizePixel() const
bool GetSystemData(BitmapSystemData &rData) const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
Product of this component's factory.
SpriteCanvas(const css::uno::Sequence< css::uno::Any > &aArguments, const css::uno::Reference< css::uno::XComponentContext > &rxContext)
#define ENSURE_ARG_OR_THROW(c, m)
std::mutex m_aMutex
Sequence< PropertyValue > aArguments
void * p
#define SAL_INFO(area, stream)
constexpr OUStringLiteral aData
std::shared_ptr< Surface > SurfaceSharedPtr
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
args
unsigned char sal_Bool