bump product version to 7.2.5.1
[LibreOffice.git] / canvas / source / cairo / cairo_canvas.cxx
blob5b727905673ae4a286f3357e4da2c30ccb71ce96
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 <tools/diagnose_ex.h>
27 #include <vcl/sysdata.hxx>
28 #include <vcl/skia/SkiaHelper.hxx>
29 #include <vcl/window.hxx>
30 #include <cppuhelper/supportsservice.hxx>
32 #include "cairo_canvas.hxx"
34 using namespace ::cairo;
35 using namespace ::com::sun::star;
37 namespace cairocanvas
39 Canvas::Canvas( const uno::Sequence< uno::Any >& aArguments,
40 const uno::Reference< uno::XComponentContext >& /*rxContext*/ ) :
41 maArguments(aArguments)
45 void Canvas::initialize()
47 // #i64742# Only perform initialization when not in probe mode
48 if( !maArguments.hasElements() )
49 return;
51 assert( !SkiaHelper::isVCLSkiaEnabled() );
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
60 SAL_INFO("canvas.cairo","Canvas created " << this);
62 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 5 &&
63 maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER &&
64 maArguments[4].getValueTypeClass() == uno::TypeClass_SEQUENCE,
65 "Canvas::initialize: wrong number of arguments, or wrong types" );
67 // We expect a single Any here, containing a pointer to a valid
68 // VCL output device, on which to output (mostly needed for text)
69 sal_Int64 nPtr = 0;
70 maArguments[0] >>= nPtr;
71 OutputDevice* pOutDev = reinterpret_cast<OutputDevice*>(nPtr);
72 ENSURE_ARG_OR_THROW( pOutDev != nullptr,
73 "Canvas::initialize: invalid OutDev pointer" );
75 awt::Rectangle aBounds;
76 maArguments[1] >>= aBounds;
78 uno::Sequence<sal_Int8> aSeq;
79 maArguments[4] >>= aSeq;
81 const SystemGraphicsData* pSysData=reinterpret_cast<const SystemGraphicsData*>(aSeq.getConstArray());
82 if( !pSysData || !pSysData->nSize )
83 throw lang::NoSupportException( "Passed SystemGraphicsData invalid!" );
85 bool bHasCairo = pOutDev->SupportsCairo();
86 ENSURE_ARG_OR_THROW(bHasCairo, "SpriteCanvas::SpriteCanvas: No Cairo capability");
88 // setup helper
89 maDeviceHelper.init( *this, *pOutDev );
91 maCanvasHelper.init( basegfx::B2ISize(aBounds.Width, aBounds.Height), *this, this );
93 // forward surface to render on to canvashelper
94 maCanvasHelper.setSurface( maDeviceHelper.getSurface(), false );
96 maArguments.realloc(0);
99 Canvas::~Canvas()
101 SAL_INFO("canvas.cairo", "CairoCanvas destroyed" );
104 void Canvas::disposeThis()
106 ::osl::MutexGuard aGuard( m_aMutex );
108 // forward to parent
109 CanvasBaseT::disposeThis();
112 OUString SAL_CALL Canvas::getServiceName( )
114 return "com.sun.star.rendering.Canvas.Cairo";
117 // XServiceInfo
118 sal_Bool Canvas::supportsService(const OUString& sServiceName)
120 return cppu::supportsService(this, sServiceName);
123 OUString Canvas::getImplementationName()
125 return "com.sun.star.comp.rendering.Canvas.Cairo";
127 css::uno::Sequence< OUString > Canvas::getSupportedServiceNames()
129 return { getServiceName() };
132 bool Canvas::repaint( const SurfaceSharedPtr& pSurface,
133 const rendering::ViewState& viewState,
134 const rendering::RenderState& renderState )
136 return maCanvasHelper.repaint( pSurface, viewState, renderState );
139 SurfaceSharedPtr Canvas::getSurface()
141 return maDeviceHelper.getSurface();
144 SurfaceSharedPtr Canvas::createSurface( const ::basegfx::B2ISize& rSize, int aContent )
146 return maDeviceHelper.createSurface( rSize, aContent );
149 SurfaceSharedPtr Canvas::createSurface( ::Bitmap& rBitmap )
151 SurfaceSharedPtr pSurface;
153 BitmapSystemData aData;
154 if( rBitmap.GetSystemData( aData ) ) {
155 const Size& rSize = rBitmap.GetSizePixel();
157 pSurface = maDeviceHelper.createSurface( aData, rSize );
160 return pSurface;
163 SurfaceSharedPtr Canvas::changeSurface()
165 // non-modifiable surface here
166 return SurfaceSharedPtr();
169 OutputDevice* Canvas::getOutputDevice()
171 return maDeviceHelper.getOutputDevice();
175 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
176 com_sun_star_comp_rendering_Canvas_Cairo_get_implementation(
177 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
179 rtl::Reference<cairocanvas::Canvas> p = new cairocanvas::Canvas(args, context);
180 p->acquire();
181 try {
182 p->initialize();
183 } catch (css::uno::Exception&) {
184 p->dispose();
185 p->release();
186 throw;
188 return static_cast<cppu::OWeakObject*>(p.get());
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */