bump product version to 7.6.3.2-android
[LibreOffice.git] / canvas / source / cairo / cairo_canvas.cxx
blob1a16a9f813cb1060c34433af538bb9261194cbd3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
21 #include <sal/log.hxx>
23 #include <com/sun/star/awt/Rectangle.hpp>
24 #include <com/sun/star/lang/NoSupportException.hpp>
25 #include <osl/mutex.hxx>
26 #include <comphelper/diagnose_ex.hxx>
27 #include <vcl/sysdata.hxx>
28 #include <vcl/skia/SkiaHelper.hxx>
29 #include <cppuhelper/supportsservice.hxx>
31 #include "cairo_canvas.hxx"
33 using namespace ::cairo;
34 using namespace ::com::sun::star;
36 namespace cairocanvas
38 Canvas::Canvas( const uno::Sequence< uno::Any >& aArguments,
39 const uno::Reference< uno::XComponentContext >& /*rxContext*/ ) :
40 maArguments(aArguments)
44 void Canvas::initialize()
46 // #i64742# Only perform initialization when not in probe mode
47 if( !maArguments.hasElements() )
48 return;
50 assert( !SkiaHelper::isVCLSkiaEnabled() );
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
59 SAL_INFO("canvas.cairo","Canvas created " << this);
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" );
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" );
74 awt::Rectangle aBounds;
75 maArguments[1] >>= aBounds;
77 uno::Sequence<sal_Int8> aSeq;
78 maArguments[4] >>= aSeq;
80 const SystemGraphicsData* pSysData=reinterpret_cast<const SystemGraphicsData*>(aSeq.getConstArray());
81 if( !pSysData || !pSysData->nSize )
82 throw lang::NoSupportException( "Passed SystemGraphicsData invalid!" );
84 bool bHasCairo = pOutDev->SupportsCairo();
85 ENSURE_ARG_OR_THROW(bHasCairo, "SpriteCanvas::SpriteCanvas: No Cairo capability");
87 // setup helper
88 maDeviceHelper.init( *this, *pOutDev );
90 maCanvasHelper.init( basegfx::B2ISize(aBounds.Width, aBounds.Height), *this, this );
92 // forward surface to render on to canvashelper
93 maCanvasHelper.setSurface( maDeviceHelper.getSurface(), false );
95 maArguments.realloc(0);
98 Canvas::~Canvas()
100 SAL_INFO("canvas.cairo", "CairoCanvas destroyed" );
103 void Canvas::disposeThis()
105 ::osl::MutexGuard aGuard( m_aMutex );
107 // forward to parent
108 CanvasBaseT::disposeThis();
111 OUString SAL_CALL Canvas::getServiceName( )
113 return "com.sun.star.rendering.Canvas.Cairo";
116 // XServiceInfo
117 sal_Bool Canvas::supportsService(const OUString& sServiceName)
119 return cppu::supportsService(this, sServiceName);
122 OUString Canvas::getImplementationName()
124 return "com.sun.star.comp.rendering.Canvas.Cairo";
126 css::uno::Sequence< OUString > Canvas::getSupportedServiceNames()
128 return { getServiceName() };
131 bool Canvas::repaint( const SurfaceSharedPtr& pSurface,
132 const rendering::ViewState& viewState,
133 const rendering::RenderState& renderState )
135 return maCanvasHelper.repaint( pSurface, viewState, renderState );
138 SurfaceSharedPtr Canvas::getSurface()
140 return maDeviceHelper.getSurface();
143 SurfaceSharedPtr Canvas::createSurface( const ::basegfx::B2ISize& rSize, int aContent )
145 return maDeviceHelper.createSurface( rSize, aContent );
148 SurfaceSharedPtr Canvas::createSurface( ::Bitmap& rBitmap )
150 SurfaceSharedPtr pSurface;
152 BitmapSystemData aData;
153 if( rBitmap.GetSystemData( aData ) ) {
154 const Size& rSize = rBitmap.GetSizePixel();
156 pSurface = maDeviceHelper.createSurface( aData, rSize );
159 return pSurface;
162 SurfaceSharedPtr Canvas::changeSurface()
164 // non-modifiable surface here
165 return SurfaceSharedPtr();
168 OutputDevice* Canvas::getOutputDevice()
170 return maDeviceHelper.getOutputDevice();
174 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
175 com_sun_star_comp_rendering_Canvas_Cairo_get_implementation(
176 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
178 rtl::Reference<cairocanvas::Canvas> p = new cairocanvas::Canvas(args, context);
179 try {
180 p->initialize();
181 } catch (css::uno::Exception&) {
182 p->dispose();
183 throw;
185 return cppu::acquire(p.get());
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */