xref: /trunk/main/canvas/source/cairo/cairo_canvas.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
125ea7f45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
325ea7f45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
425ea7f45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
525ea7f45SAndrew Rist  * distributed with this work for additional information
625ea7f45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
725ea7f45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
825ea7f45SAndrew Rist  * "License"); you may not use this file except in compliance
925ea7f45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
1125ea7f45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
1325ea7f45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1425ea7f45SAndrew Rist  * software distributed under the License is distributed on an
1525ea7f45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1625ea7f45SAndrew Rist  * KIND, either express or implied.  See the License for the
1725ea7f45SAndrew Rist  * specific language governing permissions and limitations
1825ea7f45SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
2025ea7f45SAndrew Rist  *************************************************************/
2125ea7f45SAndrew Rist 
2225ea7f45SAndrew 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 
52*906a4e93SYuri Dario #ifdef OS2
53*906a4e93SYuri Dario # include <svpm.h>
54*906a4e93SYuri Dario #endif
55*906a4e93SYuri Dario 
56cdf0e10cSrcweir #include <vcl/sysdata.hxx>
57cdf0e10cSrcweir 
58cdf0e10cSrcweir #include "cairo_canvas.hxx"
59cdf0e10cSrcweir 
60cdf0e10cSrcweir using namespace ::cairo;
61cdf0e10cSrcweir using namespace ::com::sun::star;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir namespace cairocanvas
64cdf0e10cSrcweir {
Canvas(const uno::Sequence<uno::Any> & aArguments,const uno::Reference<uno::XComponentContext> & rxContext)65cdf0e10cSrcweir     Canvas::Canvas( const uno::Sequence< uno::Any >&                aArguments,
66cdf0e10cSrcweir                     const uno::Reference< uno::XComponentContext >& rxContext ) :
67cdf0e10cSrcweir         maArguments(aArguments),
68cdf0e10cSrcweir         mxComponentContext( rxContext )
69cdf0e10cSrcweir     {
70cdf0e10cSrcweir     }
71cdf0e10cSrcweir 
initialize()72cdf0e10cSrcweir     void Canvas::initialize()
73cdf0e10cSrcweir     {
74cdf0e10cSrcweir         // #i64742# Only perform initialization when not in probe mode
75cdf0e10cSrcweir         if( maArguments.getLength() == 0 )
76cdf0e10cSrcweir             return;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         /* maArguments:
79cdf0e10cSrcweir            0: ptr to creating instance (Window or VirtualDevice)
80cdf0e10cSrcweir            1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
81cdf0e10cSrcweir            2: current bounds of creating instance
82cdf0e10cSrcweir            3: bool, denoting always on top state for Window (always false for VirtualDevice)
83cdf0e10cSrcweir            4: XWindow for creating Window (or empty for VirtualDevice)
84cdf0e10cSrcweir            5: SystemGraphicsData as a streamed Any
85cdf0e10cSrcweir          */
86cdf0e10cSrcweir         VERBOSE_TRACE("Canvas created %p\n", this);
87cdf0e10cSrcweir 
88cdf0e10cSrcweir         ENSURE_ARG_OR_THROW( maArguments.getLength() >= 6 &&
89cdf0e10cSrcweir                              maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER &&
90cdf0e10cSrcweir                              maArguments[5].getValueTypeClass() == uno::TypeClass_SEQUENCE,
91cdf0e10cSrcweir                              "Canvas::initialize: wrong number of arguments, or wrong types" );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         // We expect a single Any here, containing a pointer to a valid
94cdf0e10cSrcweir         // VCL output device, on which to output (mostly needed for text)
95cdf0e10cSrcweir         sal_Int64 nPtr = 0;
96cdf0e10cSrcweir         maArguments[0] >>= nPtr;
97cdf0e10cSrcweir         OutputDevice* pOutDev = reinterpret_cast<OutputDevice*>(nPtr);
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         ENSURE_ARG_OR_THROW( pOutDev != NULL,
100cdf0e10cSrcweir                              "Canvas::initialize: invalid OutDev pointer" );
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         awt::Rectangle aBounds;
103cdf0e10cSrcweir         maArguments[2] >>= aBounds;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         uno::Sequence<sal_Int8> aSeq;
106cdf0e10cSrcweir         maArguments[5] >>= aSeq;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir         const SystemGraphicsData* pSysData=reinterpret_cast<const SystemGraphicsData*>(aSeq.getConstArray());
109cdf0e10cSrcweir         if( !pSysData || !pSysData->nSize )
110cdf0e10cSrcweir             throw lang::NoSupportException(
111cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
112cdf0e10cSrcweir                                      "Passed SystemGraphicsData invalid!")),
113cdf0e10cSrcweir                 NULL);
114cdf0e10cSrcweir 
115cdf0e10cSrcweir         bool bHasXRender = IsCairoWorking(pOutDev);
116cdf0e10cSrcweir         ENSURE_ARG_OR_THROW( bHasXRender == true,
117cdf0e10cSrcweir                              "SpriteCanvas::SpriteCanvas: No RENDER extension" );
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         // setup helper
120cdf0e10cSrcweir         maDeviceHelper.init( *this,
121cdf0e10cSrcweir                              *pOutDev );
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         maCanvasHelper.init( basegfx::B2ISize(aBounds.Width, aBounds.Height),
124cdf0e10cSrcweir                              *this, this );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         // forward surface to render on to canvashelper
127cdf0e10cSrcweir         maCanvasHelper.setSurface(
128cdf0e10cSrcweir             maDeviceHelper.getSurface(),
129cdf0e10cSrcweir             false );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         maArguments.realloc(0);
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir 
~Canvas()134cdf0e10cSrcweir     Canvas::~Canvas()
135cdf0e10cSrcweir     {
136cdf0e10cSrcweir         OSL_TRACE( "CairoCanvas destroyed" );
137cdf0e10cSrcweir     }
138cdf0e10cSrcweir 
disposing()139cdf0e10cSrcweir     void SAL_CALL Canvas::disposing()
140cdf0e10cSrcweir     {
141cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
142cdf0e10cSrcweir 
143cdf0e10cSrcweir         mxComponentContext.clear();
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         // forward to parent
146cdf0e10cSrcweir         CanvasBaseT::disposing();
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir 
getServiceName()149cdf0e10cSrcweir     ::rtl::OUString SAL_CALL Canvas::getServiceName(  ) throw (uno::RuntimeException)
150cdf0e10cSrcweir     {
151cdf0e10cSrcweir         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CANVAS_SERVICE_NAME ) );
152cdf0e10cSrcweir     }
153cdf0e10cSrcweir 
repaint(const SurfaceSharedPtr & pSurface,const rendering::ViewState & viewState,const rendering::RenderState & renderState)154cdf0e10cSrcweir     bool Canvas::repaint( const SurfaceSharedPtr&       pSurface,
155cdf0e10cSrcweir                           const rendering::ViewState&   viewState,
156cdf0e10cSrcweir                           const rendering::RenderState& renderState )
157cdf0e10cSrcweir     {
158cdf0e10cSrcweir         return maCanvasHelper.repaint( pSurface, viewState, renderState );
159cdf0e10cSrcweir     }
160cdf0e10cSrcweir 
getSurface()161cdf0e10cSrcweir     SurfaceSharedPtr Canvas::getSurface()
162cdf0e10cSrcweir     {
163cdf0e10cSrcweir         return maDeviceHelper.getSurface();
164cdf0e10cSrcweir     }
165cdf0e10cSrcweir 
createSurface(const::basegfx::B2ISize & rSize,Content aContent)166cdf0e10cSrcweir     SurfaceSharedPtr Canvas::createSurface( const ::basegfx::B2ISize& rSize, Content aContent )
167cdf0e10cSrcweir     {
168cdf0e10cSrcweir         return maDeviceHelper.createSurface( rSize, aContent );
169cdf0e10cSrcweir     }
170cdf0e10cSrcweir 
createSurface(::Bitmap & rBitmap)171cdf0e10cSrcweir     SurfaceSharedPtr Canvas::createSurface( ::Bitmap& rBitmap )
172cdf0e10cSrcweir     {
173cdf0e10cSrcweir         SurfaceSharedPtr pSurface;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         BitmapSystemData aData;
176cdf0e10cSrcweir         if( rBitmap.GetSystemData( aData ) ) {
177cdf0e10cSrcweir             const Size& rSize = rBitmap.GetSizePixel();
178cdf0e10cSrcweir 
179cdf0e10cSrcweir             pSurface = maDeviceHelper.createSurface( aData, rSize );
180cdf0e10cSrcweir         }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         return pSurface;
183cdf0e10cSrcweir     }
184cdf0e10cSrcweir 
changeSurface(bool,bool)185cdf0e10cSrcweir     SurfaceSharedPtr Canvas::changeSurface( bool, bool )
186cdf0e10cSrcweir     {
187cdf0e10cSrcweir         // non-modifiable surface here
188cdf0e10cSrcweir         return SurfaceSharedPtr();
189cdf0e10cSrcweir     }
190cdf0e10cSrcweir 
getOutputDevice()191cdf0e10cSrcweir     OutputDevice* Canvas::getOutputDevice()
192cdf0e10cSrcweir     {
193cdf0e10cSrcweir         return maDeviceHelper.getOutputDevice();
194cdf0e10cSrcweir     }
195cdf0e10cSrcweir }
196