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