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