1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <canvas/debug.hxx>
21 #include <canvas/verbosetrace.hxx>
22 #include <canvas/canvastools.hxx>
23 #include <tools/diagnose_ex.h>
25 #include <osl/mutex.hxx>
27 #include <com/sun/star/registry/XRegistryKey.hpp>
28 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include <com/sun/star/lang/NoSupportException.hpp>
32 #include <toolkit/helper/vclunohelper.hxx>
33 #include <vcl/opengl/OpenGLWrapper.hxx>
35 #include <basegfx/matrix/b2dhommatrix.hxx>
36 #include <basegfx/point/b2dpoint.hxx>
37 #include <basegfx/tools/canvastools.hxx>
38 #include <basegfx/numeric/ftools.hxx>
40 #include <vcl/sysdata.hxx>
42 #include "cairo_canvas.hxx"
44 using namespace ::cairo
;
45 using namespace ::com::sun::star
;
49 Canvas::Canvas( const uno::Sequence
< uno::Any
>& aArguments
,
50 const uno::Reference
< uno::XComponentContext
>& rxContext
) :
51 maArguments(aArguments
),
52 mxComponentContext( rxContext
)
56 void Canvas::initialize()
58 // #i64742# Only perform initialization when not in probe mode
59 if( maArguments
.getLength() == 0 )
62 // tdf#93870 - force VCL canvas in OpenGL mode for now.
63 assert( !OpenGLWrapper::isVCLOpenGLEnabled() );
66 0: ptr to creating instance (Window or VirtualDevice)
67 1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
68 2: current bounds of creating instance
69 3: bool, denoting always on top state for Window (always false for VirtualDevice)
70 4: XWindow for creating Window (or empty for VirtualDevice)
71 5: SystemGraphicsData as a streamed Any
73 VERBOSE_TRACE("Canvas created %p\n", this);
75 ENSURE_ARG_OR_THROW( maArguments
.getLength() >= 6 &&
76 maArguments
[0].getValueTypeClass() == uno::TypeClass_HYPER
&&
77 maArguments
[5].getValueTypeClass() == uno::TypeClass_SEQUENCE
,
78 "Canvas::initialize: wrong number of arguments, or wrong types" );
80 // We expect a single Any here, containing a pointer to a valid
81 // VCL output device, on which to output (mostly needed for text)
83 maArguments
[0] >>= nPtr
;
84 OutputDevice
* pOutDev
= reinterpret_cast<OutputDevice
*>(nPtr
);
86 ENSURE_ARG_OR_THROW( pOutDev
!= NULL
,
87 "Canvas::initialize: invalid OutDev pointer" );
89 awt::Rectangle aBounds
;
90 maArguments
[2] >>= aBounds
;
92 uno::Sequence
<sal_Int8
> aSeq
;
93 maArguments
[5] >>= aSeq
;
95 const SystemGraphicsData
* pSysData
=reinterpret_cast<const SystemGraphicsData
*>(aSeq
.getConstArray());
96 if( !pSysData
|| !pSysData
->nSize
)
97 throw lang::NoSupportException( "Passed SystemGraphicsData invalid!" );
99 bool bHasCairo
= pOutDev
->SupportsCairo();
100 ENSURE_ARG_OR_THROW(bHasCairo
, "SpriteCanvas::SpriteCanvas: No Cairo capability");
103 maDeviceHelper
.init( *this, *pOutDev
);
105 maCanvasHelper
.init( basegfx::B2ISize(aBounds
.Width
, aBounds
.Height
), *this, this );
107 // forward surface to render on to canvashelper
108 maCanvasHelper
.setSurface( maDeviceHelper
.getSurface(), false );
110 maArguments
.realloc(0);
115 OSL_TRACE( "CairoCanvas destroyed" );
118 void Canvas::disposeThis()
120 ::osl::MutexGuard
aGuard( m_aMutex
);
122 mxComponentContext
.clear();
125 CanvasBaseT::disposeThis();
128 OUString SAL_CALL
Canvas::getServiceName( ) throw (uno::RuntimeException
, std::exception
)
130 return OUString( CANVAS_SERVICE_NAME
);
133 bool Canvas::repaint( const SurfaceSharedPtr
& pSurface
,
134 const rendering::ViewState
& viewState
,
135 const rendering::RenderState
& renderState
)
137 return maCanvasHelper
.repaint( pSurface
, viewState
, renderState
);
140 SurfaceSharedPtr
Canvas::getSurface()
142 return maDeviceHelper
.getSurface();
145 SurfaceSharedPtr
Canvas::createSurface( const ::basegfx::B2ISize
& rSize
, int aContent
)
147 return maDeviceHelper
.createSurface( rSize
, aContent
);
150 SurfaceSharedPtr
Canvas::createSurface( ::Bitmap
& rBitmap
)
152 SurfaceSharedPtr pSurface
;
154 BitmapSystemData aData
;
155 if( rBitmap
.GetSystemData( aData
) ) {
156 const Size
& rSize
= rBitmap
.GetSizePixel();
158 pSurface
= maDeviceHelper
.createSurface( aData
, rSize
);
164 SurfaceSharedPtr
Canvas::changeSurface( bool, bool )
166 // non-modifiable surface here
167 return SurfaceSharedPtr();
170 OutputDevice
* Canvas::getOutputDevice()
172 return maDeviceHelper
.getOutputDevice();
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */