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>
34 #include <basegfx/matrix/b2dhommatrix.hxx>
35 #include <basegfx/point/b2dpoint.hxx>
36 #include <basegfx/tools/canvastools.hxx>
37 #include <basegfx/numeric/ftools.hxx>
39 #include <vcl/sysdata.hxx>
41 #include "cairo_canvas.hxx"
43 using namespace ::cairo
;
44 using namespace ::com::sun::star
;
48 Canvas::Canvas( const uno::Sequence
< uno::Any
>& aArguments
,
49 const uno::Reference
< uno::XComponentContext
>& rxContext
) :
50 maArguments(aArguments
),
51 mxComponentContext( rxContext
)
55 void Canvas::initialize()
57 // #i64742# Only perform initialization when not in probe mode
58 if( maArguments
.getLength() == 0 )
62 0: ptr to creating instance (Window or VirtualDevice)
63 1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
64 2: current bounds of creating instance
65 3: bool, denoting always on top state for Window (always false for VirtualDevice)
66 4: XWindow for creating Window (or empty for VirtualDevice)
67 5: SystemGraphicsData as a streamed Any
69 VERBOSE_TRACE("Canvas created %p\n", this);
71 ENSURE_ARG_OR_THROW( maArguments
.getLength() >= 6 &&
72 maArguments
[0].getValueTypeClass() == uno::TypeClass_HYPER
&&
73 maArguments
[5].getValueTypeClass() == uno::TypeClass_SEQUENCE
,
74 "Canvas::initialize: wrong number of arguments, or wrong types" );
76 // We expect a single Any here, containing a pointer to a valid
77 // VCL output device, on which to output (mostly needed for text)
79 maArguments
[0] >>= nPtr
;
80 OutputDevice
* pOutDev
= reinterpret_cast<OutputDevice
*>(nPtr
);
82 ENSURE_ARG_OR_THROW( pOutDev
!= NULL
,
83 "Canvas::initialize: invalid OutDev pointer" );
85 awt::Rectangle aBounds
;
86 maArguments
[2] >>= aBounds
;
88 uno::Sequence
<sal_Int8
> aSeq
;
89 maArguments
[5] >>= aSeq
;
91 const SystemGraphicsData
* pSysData
=reinterpret_cast<const SystemGraphicsData
*>(aSeq
.getConstArray());
92 if( !pSysData
|| !pSysData
->nSize
)
93 throw lang::NoSupportException( "Passed SystemGraphicsData invalid!", NULL
);
95 bool bHasXRender
= IsCairoWorking(pOutDev
);
96 ENSURE_ARG_OR_THROW( bHasXRender
== true, "SpriteCanvas::SpriteCanvas: No RENDER extension" );
99 maDeviceHelper
.init( *this, *pOutDev
);
101 maCanvasHelper
.init( basegfx::B2ISize(aBounds
.Width
, aBounds
.Height
), *this, this );
103 // forward surface to render on to canvashelper
104 maCanvasHelper
.setSurface( maDeviceHelper
.getSurface(), false );
106 maArguments
.realloc(0);
111 OSL_TRACE( "CairoCanvas destroyed" );
114 void Canvas::disposeThis()
116 ::osl::MutexGuard
aGuard( m_aMutex
);
118 mxComponentContext
.clear();
121 CanvasBaseT::disposeThis();
124 OUString SAL_CALL
Canvas::getServiceName( ) throw (uno::RuntimeException
)
126 return OUString( CANVAS_SERVICE_NAME
);
129 bool Canvas::repaint( const SurfaceSharedPtr
& pSurface
,
130 const rendering::ViewState
& viewState
,
131 const rendering::RenderState
& renderState
)
133 return maCanvasHelper
.repaint( pSurface
, viewState
, renderState
);
136 SurfaceSharedPtr
Canvas::getSurface()
138 return maDeviceHelper
.getSurface();
141 SurfaceSharedPtr
Canvas::createSurface( const ::basegfx::B2ISize
& rSize
, Content aContent
)
143 return maDeviceHelper
.createSurface( rSize
, aContent
);
146 SurfaceSharedPtr
Canvas::createSurface( ::Bitmap
& rBitmap
)
148 SurfaceSharedPtr pSurface
;
150 BitmapSystemData aData
;
151 if( rBitmap
.GetSystemData( aData
) ) {
152 const Size
& rSize
= rBitmap
.GetSizePixel();
154 pSurface
= maDeviceHelper
.createSurface( aData
, rSize
);
160 SurfaceSharedPtr
Canvas::changeSurface( bool, bool )
162 // non-modifiable surface here
163 return SurfaceSharedPtr();
166 OutputDevice
* Canvas::getOutputDevice()
168 return maDeviceHelper
.getOutputDevice();
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */