1*25ea7f45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*25ea7f45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*25ea7f45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*25ea7f45SAndrew Rist  * distributed with this work for additional information
6*25ea7f45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*25ea7f45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*25ea7f45SAndrew Rist  * "License"); you may not use this file except in compliance
9*25ea7f45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*25ea7f45SAndrew Rist  *
11*25ea7f45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*25ea7f45SAndrew Rist  *
13*25ea7f45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*25ea7f45SAndrew Rist  * software distributed under the License is distributed on an
15*25ea7f45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*25ea7f45SAndrew Rist  * KIND, either express or implied.  See the License for the
17*25ea7f45SAndrew Rist  * specific language governing permissions and limitations
18*25ea7f45SAndrew Rist  * under the License.
19*25ea7f45SAndrew Rist  *
20*25ea7f45SAndrew Rist  *************************************************************/
21*25ea7f45SAndrew Rist 
22*25ea7f45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_canvas.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <canvas/debug.hxx>
28cdf0e10cSrcweir #include <canvas/verbosetrace.hxx>
29cdf0e10cSrcweir #include <canvas/canvastools.hxx>
30cdf0e10cSrcweir #include <tools/diagnose_ex.h>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <osl/mutex.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp>
35cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
36cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
37cdf0e10cSrcweir #include <com/sun/star/lang/NoSupportException.hpp>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
42cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
43cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx>
44cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #ifdef WNT
47cdf0e10cSrcweir # include <tools/prewin.h>
48cdf0e10cSrcweir # include <windows.h>
49cdf0e10cSrcweir # include <tools/postwin.h>
50cdf0e10cSrcweir #endif
51cdf0e10cSrcweir 
52cdf0e10cSrcweir #include <vcl/sysdata.hxx>
53cdf0e10cSrcweir 
54cdf0e10cSrcweir #include "cairo_canvas.hxx"
55cdf0e10cSrcweir 
56cdf0e10cSrcweir using namespace ::cairo;
57cdf0e10cSrcweir using namespace ::com::sun::star;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir namespace cairocanvas
60cdf0e10cSrcweir {
Canvas(const uno::Sequence<uno::Any> & aArguments,const uno::Reference<uno::XComponentContext> & rxContext)61cdf0e10cSrcweir     Canvas::Canvas( const uno::Sequence< uno::Any >&                aArguments,
62cdf0e10cSrcweir                     const uno::Reference< uno::XComponentContext >& rxContext ) :
63cdf0e10cSrcweir         maArguments(aArguments),
64cdf0e10cSrcweir         mxComponentContext( rxContext )
65cdf0e10cSrcweir     {
66cdf0e10cSrcweir     }
67cdf0e10cSrcweir 
initialize()68cdf0e10cSrcweir     void Canvas::initialize()
69cdf0e10cSrcweir     {
70cdf0e10cSrcweir         // #i64742# Only perform initialization when not in probe mode
71cdf0e10cSrcweir         if( maArguments.getLength() == 0 )
72cdf0e10cSrcweir             return;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir         /* maArguments:
75cdf0e10cSrcweir            0: ptr to creating instance (Window or VirtualDevice)
76cdf0e10cSrcweir            1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
77cdf0e10cSrcweir            2: current bounds of creating instance
78cdf0e10cSrcweir            3: bool, denoting always on top state for Window (always false for VirtualDevice)
79cdf0e10cSrcweir            4: XWindow for creating Window (or empty for VirtualDevice)
80cdf0e10cSrcweir            5: SystemGraphicsData as a streamed Any
81cdf0e10cSrcweir          */
82cdf0e10cSrcweir 		VERBOSE_TRACE("Canvas created %p\n", this);
83cdf0e10cSrcweir 
84cdf0e10cSrcweir         ENSURE_ARG_OR_THROW( maArguments.getLength() >= 6 &&
85cdf0e10cSrcweir                              maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER &&
86cdf0e10cSrcweir                              maArguments[5].getValueTypeClass() == uno::TypeClass_SEQUENCE,
87cdf0e10cSrcweir                              "Canvas::initialize: wrong number of arguments, or wrong types" );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         // We expect a single Any here, containing a pointer to a valid
90cdf0e10cSrcweir         // VCL output device, on which to output (mostly needed for text)
91cdf0e10cSrcweir         sal_Int64 nPtr = 0;
92cdf0e10cSrcweir         maArguments[0] >>= nPtr;
93cdf0e10cSrcweir         OutputDevice* pOutDev = reinterpret_cast<OutputDevice*>(nPtr);
94cdf0e10cSrcweir 
95cdf0e10cSrcweir         ENSURE_ARG_OR_THROW( pOutDev != NULL,
96cdf0e10cSrcweir                              "Canvas::initialize: invalid OutDev pointer" );
97cdf0e10cSrcweir 
98cdf0e10cSrcweir         awt::Rectangle aBounds;
99cdf0e10cSrcweir         maArguments[2] >>= aBounds;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir         uno::Sequence<sal_Int8> aSeq;
102cdf0e10cSrcweir         maArguments[5] >>= aSeq;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir         const SystemGraphicsData* pSysData=reinterpret_cast<const SystemGraphicsData*>(aSeq.getConstArray());
105cdf0e10cSrcweir         if( !pSysData || !pSysData->nSize )
106cdf0e10cSrcweir             throw lang::NoSupportException(
107cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
108cdf0e10cSrcweir                                      "Passed SystemGraphicsData invalid!")),
109cdf0e10cSrcweir                 NULL);
110cdf0e10cSrcweir 
111cdf0e10cSrcweir         bool bHasXRender = IsCairoWorking(pOutDev);
112cdf0e10cSrcweir         ENSURE_ARG_OR_THROW( bHasXRender == true,
113cdf0e10cSrcweir                              "SpriteCanvas::SpriteCanvas: No RENDER extension" );
114cdf0e10cSrcweir 
115cdf0e10cSrcweir         // setup helper
116cdf0e10cSrcweir         maDeviceHelper.init( *this,
117cdf0e10cSrcweir                              *pOutDev );
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         maCanvasHelper.init( basegfx::B2ISize(aBounds.Width, aBounds.Height),
120cdf0e10cSrcweir                              *this, this );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         // forward surface to render on to canvashelper
123cdf0e10cSrcweir         maCanvasHelper.setSurface(
124cdf0e10cSrcweir             maDeviceHelper.getSurface(),
125cdf0e10cSrcweir             false );
126cdf0e10cSrcweir 
127cdf0e10cSrcweir         maArguments.realloc(0);
128cdf0e10cSrcweir     }
129cdf0e10cSrcweir 
~Canvas()130cdf0e10cSrcweir     Canvas::~Canvas()
131cdf0e10cSrcweir     {
132cdf0e10cSrcweir         OSL_TRACE( "CairoCanvas destroyed" );
133cdf0e10cSrcweir     }
134cdf0e10cSrcweir 
disposing()135cdf0e10cSrcweir     void SAL_CALL Canvas::disposing()
136cdf0e10cSrcweir     {
137cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         mxComponentContext.clear();
140cdf0e10cSrcweir 
141cdf0e10cSrcweir         // forward to parent
142cdf0e10cSrcweir         CanvasBaseT::disposing();
143cdf0e10cSrcweir     }
144cdf0e10cSrcweir 
getServiceName()145cdf0e10cSrcweir     ::rtl::OUString SAL_CALL Canvas::getServiceName(  ) throw (uno::RuntimeException)
146cdf0e10cSrcweir     {
147cdf0e10cSrcweir         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CANVAS_SERVICE_NAME ) );
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir 
repaint(const SurfaceSharedPtr & pSurface,const rendering::ViewState & viewState,const rendering::RenderState & renderState)150cdf0e10cSrcweir     bool Canvas::repaint( const SurfaceSharedPtr&       pSurface,
151cdf0e10cSrcweir                           const rendering::ViewState&   viewState,
152cdf0e10cSrcweir                           const rendering::RenderState&	renderState )
153cdf0e10cSrcweir     {
154cdf0e10cSrcweir         return maCanvasHelper.repaint( pSurface, viewState, renderState );
155cdf0e10cSrcweir     }
156cdf0e10cSrcweir 
getSurface()157cdf0e10cSrcweir     SurfaceSharedPtr Canvas::getSurface()
158cdf0e10cSrcweir     {
159cdf0e10cSrcweir         return maDeviceHelper.getSurface();
160cdf0e10cSrcweir     }
161cdf0e10cSrcweir 
createSurface(const::basegfx::B2ISize & rSize,Content aContent)162cdf0e10cSrcweir     SurfaceSharedPtr Canvas::createSurface( const ::basegfx::B2ISize& rSize, Content aContent )
163cdf0e10cSrcweir     {
164cdf0e10cSrcweir         return maDeviceHelper.createSurface( rSize, aContent );
165cdf0e10cSrcweir     }
166cdf0e10cSrcweir 
createSurface(::Bitmap & rBitmap)167cdf0e10cSrcweir     SurfaceSharedPtr Canvas::createSurface( ::Bitmap& rBitmap )
168cdf0e10cSrcweir     {
169cdf0e10cSrcweir         SurfaceSharedPtr pSurface;
170cdf0e10cSrcweir 
171cdf0e10cSrcweir         BitmapSystemData aData;
172cdf0e10cSrcweir         if( rBitmap.GetSystemData( aData ) ) {
173cdf0e10cSrcweir             const Size& rSize = rBitmap.GetSizePixel();
174cdf0e10cSrcweir 
175cdf0e10cSrcweir             pSurface = maDeviceHelper.createSurface( aData, rSize );
176cdf0e10cSrcweir         }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         return pSurface;
179cdf0e10cSrcweir     }
180cdf0e10cSrcweir 
changeSurface(bool,bool)181cdf0e10cSrcweir     SurfaceSharedPtr Canvas::changeSurface( bool, bool )
182cdf0e10cSrcweir     {
183cdf0e10cSrcweir         // non-modifiable surface here
184cdf0e10cSrcweir         return SurfaceSharedPtr();
185cdf0e10cSrcweir     }
186cdf0e10cSrcweir 
getOutputDevice()187cdf0e10cSrcweir     OutputDevice* Canvas::getOutputDevice()
188cdf0e10cSrcweir     {
189cdf0e10cSrcweir         return maDeviceHelper.getOutputDevice();
190cdf0e10cSrcweir     }
191cdf0e10cSrcweir }
192