1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cairo_canvas.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_canvas.hxx"
34 #include <canvas/debug.hxx>
35 #include <canvas/verbosetrace.hxx>
36 #include <canvas/canvastools.hxx>
37 #include <tools/diagnose_ex.h>
39 #include <osl/mutex.hxx>
41 #include <com/sun/star/registry/XRegistryKey.hpp>
42 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
43 #include <com/sun/star/uno/XComponentContext.hpp>
44 #include <com/sun/star/lang/NoSupportException.hpp>
46 #include <toolkit/helper/vclunohelper.hxx>
48 #include <basegfx/matrix/b2dhommatrix.hxx>
49 #include <basegfx/point/b2dpoint.hxx>
50 #include <basegfx/tools/canvastools.hxx>
51 #include <basegfx/numeric/ftools.hxx>
54 # include <tools/prewin.h>
56 # include <tools/postwin.h>
59 #include <vcl/sysdata.hxx>
61 #include "cairo_canvas.hxx"
63 using namespace ::cairo
;
64 using namespace ::com::sun::star
;
68 Canvas::Canvas( const uno::Sequence
< uno::Any
>& aArguments
,
69 const uno::Reference
< uno::XComponentContext
>& rxContext
) :
70 maArguments(aArguments
),
71 mxComponentContext( rxContext
)
75 void Canvas::initialize()
77 // #i64742# Only perform initialization when not in probe mode
78 if( maArguments
.getLength() == 0 )
82 0: ptr to creating instance (Window or VirtualDevice)
83 1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
84 2: current bounds of creating instance
85 3: bool, denoting always on top state for Window (always false for VirtualDevice)
86 4: XWindow for creating Window (or empty for VirtualDevice)
87 5: SystemGraphicsData as a streamed Any
89 VERBOSE_TRACE("Canvas created %p\n", this);
91 ENSURE_ARG_OR_THROW( maArguments
.getLength() >= 6 &&
92 maArguments
[0].getValueTypeClass() == uno::TypeClass_HYPER
&&
93 maArguments
[5].getValueTypeClass() == uno::TypeClass_SEQUENCE
,
94 "Canvas::initialize: wrong number of arguments, or wrong types" );
96 // We expect a single Any here, containing a pointer to a valid
97 // VCL output device, on which to output (mostly needed for text)
99 maArguments
[0] >>= nPtr
;
100 OutputDevice
* pOutDev
= reinterpret_cast<OutputDevice
*>(nPtr
);
102 ENSURE_ARG_OR_THROW( pOutDev
!= NULL
,
103 "Canvas::initialize: invalid OutDev pointer" );
105 awt::Rectangle aBounds
;
106 maArguments
[2] >>= aBounds
;
108 uno::Sequence
<sal_Int8
> aSeq
;
109 maArguments
[5] >>= aSeq
;
111 const SystemGraphicsData
* pSysData
=reinterpret_cast<const SystemGraphicsData
*>(aSeq
.getConstArray());
112 if( !pSysData
|| !pSysData
->nSize
)
113 throw lang::NoSupportException(
114 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
115 "Passed SystemGraphicsData invalid!")),
118 bool bHasXRender
= IsCairoWorking(pOutDev
);
119 ENSURE_ARG_OR_THROW( bHasXRender
== true,
120 "SpriteCanvas::SpriteCanvas: No RENDER extension" );
123 maDeviceHelper
.init( *this,
126 maCanvasHelper
.init( basegfx::B2ISize(aBounds
.Width
, aBounds
.Height
),
129 // forward surface to render on to canvashelper
130 maCanvasHelper
.setSurface(
131 maDeviceHelper
.getSurface(),
134 maArguments
.realloc(0);
139 OSL_TRACE( "CairoCanvas destroyed" );
142 void SAL_CALL
Canvas::disposing()
144 ::osl::MutexGuard
aGuard( m_aMutex
);
146 mxComponentContext
.clear();
149 CanvasBaseT::disposing();
152 ::rtl::OUString SAL_CALL
Canvas::getServiceName( ) throw (uno::RuntimeException
)
154 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CANVAS_SERVICE_NAME
) );
157 bool Canvas::repaint( const SurfaceSharedPtr
& pSurface
,
158 const rendering::ViewState
& viewState
,
159 const rendering::RenderState
& renderState
)
161 return maCanvasHelper
.repaint( pSurface
, viewState
, renderState
);
164 SurfaceSharedPtr
Canvas::getSurface()
166 return maDeviceHelper
.getSurface();
169 SurfaceSharedPtr
Canvas::createSurface( const ::basegfx::B2ISize
& rSize
, Content aContent
)
171 return maDeviceHelper
.createSurface( rSize
, aContent
);
174 SurfaceSharedPtr
Canvas::createSurface( ::Bitmap
& rBitmap
)
176 SurfaceSharedPtr pSurface
;
178 BitmapSystemData aData
;
179 if( rBitmap
.GetSystemData( aData
) ) {
180 const Size
& rSize
= rBitmap
.GetSizePixel();
182 pSurface
= maDeviceHelper
.createSurface( aData
, rSize
);
188 SurfaceSharedPtr
Canvas::changeSurface( bool, bool )
190 // non-modifiable surface here
191 return SurfaceSharedPtr();
194 OutputDevice
* Canvas::getOutputDevice()
196 return maDeviceHelper
.getOutputDevice();