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 : :
30 : : #include <canvas/debug.hxx>
31 : : #include <canvas/verbosetrace.hxx>
32 : : #include <canvas/canvastools.hxx>
33 : :
34 : : #include <osl/mutex.hxx>
35 : : #include <cppuhelper/compbase1.hxx>
36 : :
37 : : #include <com/sun/star/lang/NoSupportException.hpp>
38 : :
39 : : #include <toolkit/helper/vclunohelper.hxx>
40 : : #include <basegfx/tools/canvastools.hxx>
41 : : #include <basegfx/tools/unopolypolygon.hxx>
42 : :
43 : : #include <vcl/canvastools.hxx>
44 : :
45 : : #include <tools/stream.hxx>
46 : :
47 : : #include "cairo_spritecanvas.hxx"
48 : : #include "cairo_canvasbitmap.hxx"
49 : : #include "cairo_devicehelper.hxx"
50 : :
51 : : using namespace ::cairo;
52 : : using namespace ::com::sun::star;
53 : :
54 : : namespace cairocanvas
55 : : {
56 : 0 : DeviceHelper::DeviceHelper() :
57 : : mpSurfaceProvider( NULL ),
58 : : mpRefDevice( NULL ),
59 : 0 : mpSurface()
60 : : {
61 : 0 : }
62 : :
63 : 0 : void DeviceHelper::implInit( SurfaceProvider& rSurfaceProvider,
64 : : OutputDevice& rRefDevice )
65 : : {
66 : 0 : mpSurfaceProvider = &rSurfaceProvider;
67 : 0 : mpRefDevice = &rRefDevice;
68 : :
69 : : // no own surface, this is handled by derived classes
70 : 0 : }
71 : :
72 : 0 : void DeviceHelper::init( SurfaceProvider& rSurfaceProvider,
73 : : OutputDevice& rRefDevice )
74 : : {
75 : 0 : implInit(rSurfaceProvider, rRefDevice);
76 : :
77 : 0 : OutputDevice* pOutDev=getOutputDevice();
78 : : mpSurface = cairo::createSurface( *pOutDev,
79 : 0 : pOutDev->GetOutOffXPixel(),
80 : 0 : pOutDev->GetOutOffYPixel(),
81 : 0 : pOutDev->GetOutputWidthPixel(),
82 : 0 : pOutDev->GetOutputHeightPixel() );
83 : 0 : }
84 : :
85 : 0 : void DeviceHelper::disposing()
86 : : {
87 : : // release all references
88 : 0 : mpSurface.reset();
89 : 0 : mpRefDevice = NULL;
90 : 0 : mpSurfaceProvider = NULL;
91 : 0 : }
92 : :
93 : 0 : void DeviceHelper::setSize( const ::basegfx::B2ISize& rSize )
94 : : {
95 : : OSL_TRACE("DeviceHelper::setSize(): device size %d x %d", rSize.getX(), rSize.getY() );
96 : :
97 : 0 : if( !mpRefDevice )
98 : 0 : return; // disposed
99 : :
100 : 0 : OutputDevice* pOutDev=getOutputDevice();
101 : :
102 : : #if defined (UNX) && !defined (QUARTZ)
103 : : // X11 only
104 : 0 : if( mpSurface )
105 : 0 : mpSurface->Resize( rSize.getX() + pOutDev->GetOutOffXPixel(),
106 : 0 : rSize.getY() + pOutDev->GetOutOffYPixel() );
107 : : else
108 : : #endif
109 : : mpSurface = cairo::createSurface(
110 : : *pOutDev,
111 : 0 : pOutDev->GetOutOffXPixel(),
112 : 0 : pOutDev->GetOutOffYPixel(),
113 : 0 : rSize.getX(), rSize.getY() );
114 : : }
115 : :
116 : 0 : geometry::RealSize2D DeviceHelper::getPhysicalResolution()
117 : : {
118 : : // Map a one-by-one millimeter box to pixel
119 : 0 : const MapMode aOldMapMode( mpRefDevice->GetMapMode() );
120 : 0 : mpRefDevice->SetMapMode( MapMode(MAP_MM) );
121 : 0 : const Size aPixelSize( mpRefDevice->LogicToPixel(Size(1,1)) );
122 : 0 : mpRefDevice->SetMapMode( aOldMapMode );
123 : :
124 : 0 : return ::vcl::unotools::size2DFromSize( aPixelSize );
125 : : }
126 : :
127 : 0 : geometry::RealSize2D DeviceHelper::getPhysicalSize()
128 : : {
129 : 0 : if( !mpRefDevice )
130 : 0 : return ::canvas::tools::createInfiniteSize2D(); // we're disposed
131 : :
132 : : // Map the pixel dimensions of the output window to millimeter
133 : 0 : const MapMode aOldMapMode( mpRefDevice->GetMapMode() );
134 : 0 : mpRefDevice->SetMapMode( MapMode(MAP_MM) );
135 : 0 : const Size aLogSize( mpRefDevice->PixelToLogic(mpRefDevice->GetOutputSizePixel()) );
136 : 0 : mpRefDevice->SetMapMode( aOldMapMode );
137 : :
138 : 0 : return ::vcl::unotools::size2DFromSize( aLogSize );
139 : : }
140 : :
141 : 0 : uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
142 : : const uno::Reference< rendering::XGraphicDevice >& ,
143 : : const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points )
144 : : {
145 : : // disposed?
146 : 0 : if( !mpSurfaceProvider )
147 : 0 : return uno::Reference< rendering::XLinePolyPolygon2D >(); // we're disposed
148 : :
149 : : return uno::Reference< rendering::XLinePolyPolygon2D >(
150 : : new ::basegfx::unotools::UnoPolyPolygon(
151 : 0 : ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) );
152 : : }
153 : :
154 : 0 : uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
155 : : const uno::Reference< rendering::XGraphicDevice >& ,
156 : : const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points )
157 : : {
158 : : // disposed?
159 : 0 : if( !mpSurfaceProvider )
160 : 0 : return uno::Reference< rendering::XBezierPolyPolygon2D >(); // we're disposed
161 : :
162 : : return uno::Reference< rendering::XBezierPolyPolygon2D >(
163 : : new ::basegfx::unotools::UnoPolyPolygon(
164 : 0 : ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) );
165 : : }
166 : :
167 : 0 : uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
168 : : const uno::Reference< rendering::XGraphicDevice >& rDevice,
169 : : const geometry::IntegerSize2D& size )
170 : : {
171 : : // disposed?
172 : 0 : if( !mpSurfaceProvider )
173 : 0 : return uno::Reference< rendering::XBitmap >(); // we're disposed
174 : :
175 : : return uno::Reference< rendering::XBitmap >(
176 : : new CanvasBitmap(
177 : : ::basegfx::unotools::b2ISizeFromIntegerSize2D( size ),
178 : : SurfaceProviderRef(mpSurfaceProvider),
179 : : rDevice.get(),
180 : 0 : false ));
181 : : }
182 : :
183 : 0 : uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap(
184 : : const uno::Reference< rendering::XGraphicDevice >& ,
185 : : const geometry::IntegerSize2D& /*size*/ )
186 : : {
187 : 0 : return uno::Reference< rendering::XVolatileBitmap >();
188 : : }
189 : :
190 : 0 : uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap(
191 : : const uno::Reference< rendering::XGraphicDevice >& rDevice,
192 : : const geometry::IntegerSize2D& size )
193 : : {
194 : : // disposed?
195 : 0 : if( !mpSurfaceProvider )
196 : 0 : return uno::Reference< rendering::XBitmap >(); // we're disposed
197 : :
198 : : return uno::Reference< rendering::XBitmap >(
199 : : new CanvasBitmap(
200 : : ::basegfx::unotools::b2ISizeFromIntegerSize2D( size ),
201 : : SurfaceProviderRef(mpSurfaceProvider),
202 : : rDevice.get(),
203 : 0 : true ));
204 : : }
205 : :
206 : 0 : uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap(
207 : : const uno::Reference< rendering::XGraphicDevice >& ,
208 : : const geometry::IntegerSize2D& /*size*/ )
209 : : {
210 : 0 : return uno::Reference< rendering::XVolatileBitmap >();
211 : : }
212 : :
213 : 0 : sal_Bool DeviceHelper::hasFullScreenMode()
214 : : {
215 : : // TODO(F3): offer fullscreen mode the XCanvas way
216 : 0 : return false;
217 : : }
218 : :
219 : 0 : sal_Bool DeviceHelper::enterFullScreenMode( sal_Bool /*bEnter*/ )
220 : : {
221 : : // TODO(F3): offer fullscreen mode the XCanvas way
222 : 0 : return false;
223 : : }
224 : :
225 : 0 : uno::Any DeviceHelper::isAccelerated() const
226 : : {
227 : 0 : return ::com::sun::star::uno::makeAny(false);
228 : : }
229 : :
230 : 0 : uno::Any DeviceHelper::getDeviceHandle() const
231 : : {
232 : 0 : return uno::makeAny( reinterpret_cast< sal_Int64 >(mpRefDevice) );
233 : : }
234 : :
235 : 0 : uno::Any DeviceHelper::getSurfaceHandle() const
236 : : {
237 : 0 : return uno::Any();
238 : : }
239 : :
240 : : namespace
241 : : {
242 : : struct DeviceColorSpace: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>,
243 : : DeviceColorSpace>
244 : : {
245 : 0 : uno::Reference<rendering::XColorSpace> operator()()
246 : : {
247 : 0 : return vcl::unotools::createStandardColorSpace();
248 : : }
249 : : };
250 : : }
251 : :
252 : 0 : uno::Reference<rendering::XColorSpace> DeviceHelper::getColorSpace() const
253 : : {
254 : : // always the same
255 : 0 : return DeviceColorSpace::get();
256 : : }
257 : :
258 : 0 : void DeviceHelper::dumpScreenContent() const
259 : : {
260 : : static sal_Int32 nFilePostfixCount(0);
261 : :
262 : 0 : if( mpRefDevice )
263 : : {
264 : 0 : rtl::OUString aFilename("dbg_frontbuffer");
265 : 0 : aFilename += rtl::OUString::valueOf(nFilePostfixCount);
266 : 0 : aFilename += rtl::OUString(".bmp");
267 : :
268 : 0 : SvFileStream aStream( aFilename, STREAM_STD_READWRITE );
269 : :
270 : 0 : const ::Point aEmptyPoint;
271 : 0 : bool bOldMap( mpRefDevice->IsMapModeEnabled() );
272 : 0 : mpRefDevice->EnableMapMode( sal_False );
273 : : aStream << mpRefDevice->GetBitmap(aEmptyPoint,
274 : 0 : mpRefDevice->GetOutputSizePixel());
275 : 0 : mpRefDevice->EnableMapMode( bOldMap );
276 : :
277 : 0 : ++nFilePostfixCount;
278 : : }
279 : 0 : }
280 : :
281 : 0 : SurfaceSharedPtr DeviceHelper::getSurface()
282 : : {
283 : 0 : return mpSurface;
284 : : }
285 : :
286 : 0 : SurfaceSharedPtr DeviceHelper::createSurface( const ::basegfx::B2ISize& rSize, Content aContent )
287 : : {
288 : 0 : if( mpSurface )
289 : 0 : return mpSurface->getSimilar( aContent, rSize.getX(), rSize.getY() );
290 : :
291 : 0 : return SurfaceSharedPtr();
292 : : }
293 : :
294 : 0 : SurfaceSharedPtr DeviceHelper::createSurface( BitmapSystemData& rData, const Size& rSize )
295 : : {
296 : 0 : if( mpRefDevice )
297 : 0 : return createBitmapSurface( *mpRefDevice, rData, rSize );
298 : :
299 : 0 : return SurfaceSharedPtr();
300 : : }
301 : 0 : }
302 : :
303 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|