CWS-TOOLING: integrate CWS os146
[LibreOffice.git] / canvas / source / cairo / cairo_canvas.cxx
blob54d04158c993ebc2bed8ffd83aa4c8aa2d49305a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_canvas.hxx"
31 #include <canvas/debug.hxx>
32 #include <canvas/verbosetrace.hxx>
33 #include <canvas/canvastools.hxx>
34 #include <tools/diagnose_ex.h>
36 #include <osl/mutex.hxx>
38 #include <com/sun/star/registry/XRegistryKey.hpp>
39 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
40 #include <com/sun/star/uno/XComponentContext.hpp>
41 #include <com/sun/star/lang/NoSupportException.hpp>
43 #include <toolkit/helper/vclunohelper.hxx>
45 #include <basegfx/matrix/b2dhommatrix.hxx>
46 #include <basegfx/point/b2dpoint.hxx>
47 #include <basegfx/tools/canvastools.hxx>
48 #include <basegfx/numeric/ftools.hxx>
50 #ifdef WNT
51 # include <tools/prewin.h>
52 # include <windows.h>
53 # include <tools/postwin.h>
54 #endif
56 #include <vcl/sysdata.hxx>
58 #include "cairo_canvas.hxx"
60 using namespace ::cairo;
61 using namespace ::com::sun::star;
63 namespace cairocanvas
65 Canvas::Canvas( const uno::Sequence< uno::Any >& aArguments,
66 const uno::Reference< uno::XComponentContext >& rxContext ) :
67 maArguments(aArguments),
68 mxComponentContext( rxContext )
72 void Canvas::initialize()
74 // #i64742# Only perform initialization when not in probe mode
75 if( maArguments.getLength() == 0 )
76 return;
78 /* maArguments:
79 0: ptr to creating instance (Window or VirtualDevice)
80 1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
81 2: current bounds of creating instance
82 3: bool, denoting always on top state for Window (always false for VirtualDevice)
83 4: XWindow for creating Window (or empty for VirtualDevice)
84 5: SystemGraphicsData as a streamed Any
86 VERBOSE_TRACE("Canvas created %p\n", this);
88 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 6 &&
89 maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER &&
90 maArguments[5].getValueTypeClass() == uno::TypeClass_SEQUENCE,
91 "Canvas::initialize: wrong number of arguments, or wrong types" );
93 // We expect a single Any here, containing a pointer to a valid
94 // VCL output device, on which to output (mostly needed for text)
95 sal_Int64 nPtr = 0;
96 maArguments[0] >>= nPtr;
97 OutputDevice* pOutDev = reinterpret_cast<OutputDevice*>(nPtr);
99 ENSURE_ARG_OR_THROW( pOutDev != NULL,
100 "Canvas::initialize: invalid OutDev pointer" );
102 awt::Rectangle aBounds;
103 maArguments[2] >>= aBounds;
105 uno::Sequence<sal_Int8> aSeq;
106 maArguments[5] >>= aSeq;
108 const SystemGraphicsData* pSysData=reinterpret_cast<const SystemGraphicsData*>(aSeq.getConstArray());
109 if( !pSysData || !pSysData->nSize )
110 throw lang::NoSupportException(
111 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
112 "Passed SystemGraphicsData invalid!")),
113 NULL);
115 bool bHasXRender = IsCairoWorking(pOutDev);
116 ENSURE_ARG_OR_THROW( bHasXRender == true,
117 "SpriteCanvas::SpriteCanvas: No RENDER extension" );
119 // setup helper
120 maDeviceHelper.init( *this,
121 *pOutDev );
123 maCanvasHelper.init( basegfx::B2ISize(aBounds.Width, aBounds.Height),
124 *this, this );
126 // forward surface to render on to canvashelper
127 maCanvasHelper.setSurface(
128 maDeviceHelper.getSurface(),
129 false );
131 maArguments.realloc(0);
134 Canvas::~Canvas()
136 OSL_TRACE( "CairoCanvas destroyed" );
139 void SAL_CALL Canvas::disposing()
141 ::osl::MutexGuard aGuard( m_aMutex );
143 mxComponentContext.clear();
145 // forward to parent
146 CanvasBaseT::disposing();
149 ::rtl::OUString SAL_CALL Canvas::getServiceName( ) throw (uno::RuntimeException)
151 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CANVAS_SERVICE_NAME ) );
154 bool Canvas::repaint( const SurfaceSharedPtr& pSurface,
155 const rendering::ViewState& viewState,
156 const rendering::RenderState& renderState )
158 return maCanvasHelper.repaint( pSurface, viewState, renderState );
161 SurfaceSharedPtr Canvas::getSurface()
163 return maDeviceHelper.getSurface();
166 SurfaceSharedPtr Canvas::createSurface( const ::basegfx::B2ISize& rSize, Content aContent )
168 return maDeviceHelper.createSurface( rSize, aContent );
171 SurfaceSharedPtr Canvas::createSurface( ::Bitmap& rBitmap )
173 SurfaceSharedPtr pSurface;
175 BitmapSystemData aData;
176 if( rBitmap.GetSystemData( aData ) ) {
177 const Size& rSize = rBitmap.GetSizePixel();
179 pSurface = maDeviceHelper.createSurface( aData, rSize );
182 return pSurface;
185 SurfaceSharedPtr Canvas::changeSurface( bool, bool )
187 // non-modifiable surface here
188 return SurfaceSharedPtr();
191 OutputDevice* Canvas::getOutputDevice()
193 return maDeviceHelper.getOutputDevice();