LibreOffice Module canvas (master) 1
cairo_canvas.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
23#include <com/sun/star/awt/Rectangle.hpp>
24#include <com/sun/star/lang/NoSupportException.hpp>
25#include <osl/mutex.hxx>
27#include <vcl/sysdata.hxx>
30
31#include "cairo_canvas.hxx"
32
33using namespace ::cairo;
34using namespace ::com::sun::star;
35
36namespace cairocanvas
37{
38 Canvas::Canvas( const uno::Sequence< uno::Any >& aArguments,
39 const uno::Reference< uno::XComponentContext >& /*rxContext*/ ) :
40 maArguments(aArguments)
41 {
42 }
43
44 void Canvas::initialize()
45 {
46 // #i64742# Only perform initialization when not in probe mode
47 if( !maArguments.hasElements() )
48 return;
49
51
52 /* maArguments:
53 0: ptr to creating instance (Window or VirtualDevice)
54 1: current bounds of creating instance
55 2: bool, denoting always on top state for Window (always false for VirtualDevice)
56 3: XWindow for creating Window (or empty for VirtualDevice)
57 4: SystemGraphicsData as a streamed Any
58 */
59 SAL_INFO("canvas.cairo","Canvas created " << this);
60
61 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 5 &&
62 maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER &&
63 maArguments[4].getValueTypeClass() == uno::TypeClass_SEQUENCE,
64 "Canvas::initialize: wrong number of arguments, or wrong types" );
65
66 // We expect a single Any here, containing a pointer to a valid
67 // VCL output device, on which to output (mostly needed for text)
68 sal_Int64 nPtr = 0;
69 maArguments[0] >>= nPtr;
70 OutputDevice* pOutDev = reinterpret_cast<OutputDevice*>(nPtr);
71 ENSURE_ARG_OR_THROW( pOutDev != nullptr,
72 "Canvas::initialize: invalid OutDev pointer" );
73
74 awt::Rectangle aBounds;
75 maArguments[1] >>= aBounds;
76
77 uno::Sequence<sal_Int8> aSeq;
78 maArguments[4] >>= aSeq;
79
80 const SystemGraphicsData* pSysData=reinterpret_cast<const SystemGraphicsData*>(aSeq.getConstArray());
81 if( !pSysData || !pSysData->nSize )
82 throw lang::NoSupportException( "Passed SystemGraphicsData invalid!" );
83
84 bool bHasCairo = pOutDev->SupportsCairo();
85 ENSURE_ARG_OR_THROW(bHasCairo, "SpriteCanvas::SpriteCanvas: No Cairo capability");
86
87 // setup helper
88 maDeviceHelper.init( *this, *pOutDev );
89
90 maCanvasHelper.init( basegfx::B2ISize(aBounds.Width, aBounds.Height), *this, this );
91
92 // forward surface to render on to canvashelper
93 maCanvasHelper.setSurface( maDeviceHelper.getSurface(), false );
94
95 maArguments.realloc(0);
96 }
97
98 Canvas::~Canvas()
99 {
100 SAL_INFO("canvas.cairo", "CairoCanvas destroyed" );
101 }
102
103 void Canvas::disposeThis()
104 {
105 ::osl::MutexGuard aGuard( m_aMutex );
106
107 // forward to parent
108 CanvasBaseT::disposeThis();
109 }
110
111 OUString SAL_CALL Canvas::getServiceName( )
112 {
113 return "com.sun.star.rendering.Canvas.Cairo";
114 }
115
116 // XServiceInfo
117 sal_Bool Canvas::supportsService(const OUString& sServiceName)
118 {
120
121 }
122 OUString Canvas::getImplementationName()
123 {
124 return "com.sun.star.comp.rendering.Canvas.Cairo";
125 }
126 css::uno::Sequence< OUString > Canvas::getSupportedServiceNames()
127 {
128 return { getServiceName() };
129 }
130
131 bool Canvas::repaint( const SurfaceSharedPtr& pSurface,
132 const rendering::ViewState& viewState,
133 const rendering::RenderState& renderState )
134 {
135 return maCanvasHelper.repaint( pSurface, viewState, renderState );
136 }
137
138 SurfaceSharedPtr Canvas::getSurface()
139 {
140 return maDeviceHelper.getSurface();
141 }
142
143 SurfaceSharedPtr Canvas::createSurface( const ::basegfx::B2ISize& rSize, int aContent )
144 {
145 return maDeviceHelper.createSurface( rSize, aContent );
146 }
147
148 SurfaceSharedPtr Canvas::createSurface( ::Bitmap& rBitmap )
149 {
150 SurfaceSharedPtr pSurface;
151
153 if( rBitmap.GetSystemData( aData ) ) {
154 const Size& rSize = rBitmap.GetSizePixel();
155
156 pSurface = maDeviceHelper.createSurface( aData, rSize );
157 }
158
159 return pSurface;
160 }
161
162 SurfaceSharedPtr Canvas::changeSurface()
163 {
164 // non-modifiable surface here
165 return SurfaceSharedPtr();
166 }
167
168 OutputDevice* Canvas::getOutputDevice()
169 {
170 return maDeviceHelper.getOutputDevice();
171 }
172}
173
174extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
176 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
177{
179 try {
180 p->initialize();
181 } catch (css::uno::Exception&) {
182 p->dispose();
183 throw;
184 }
185 return cppu::acquire(p.get());
186}
187
188
189/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral sServiceName
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_rendering_Canvas_Cairo_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
Size GetSizePixel() const
bool GetSystemData(BitmapSystemData &rData) const
bool SupportsCairo() const
Product of this component's factory.
Canvas(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
Sequence< sal_Int8 > aSeq
#define SAL_INFO(area, stream)
constexpr OUStringLiteral aData
VCL_DLLPUBLIC bool isVCLSkiaEnabled()
std::shared_ptr< Surface > SurfaceSharedPtr
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
args
unsigned char sal_Bool