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