1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cairo_devicehelper.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_canvas.hxx"
34 #include <canvas/debug.hxx>
35 #include <canvas/verbosetrace.hxx>
36 #include <canvas/canvastools.hxx>
38 #include <osl/mutex.hxx>
39 #include <cppuhelper/compbase1.hxx>
41 #include <com/sun/star/lang/NoSupportException.hpp>
43 #include <toolkit/helper/vclunohelper.hxx>
44 #include <basegfx/tools/canvastools.hxx>
45 #include <basegfx/tools/unopolypolygon.hxx>
47 #include <vcl/canvastools.hxx>
49 #include <tools/stream.hxx>
51 #include "cairo_spritecanvas.hxx"
52 #include "cairo_canvasbitmap.hxx"
53 #include "cairo_devicehelper.hxx"
55 using namespace ::cairo
;
56 using namespace ::com::sun::star
;
60 DeviceHelper::DeviceHelper() :
61 mpSurfaceProvider( NULL
),
67 void DeviceHelper::implInit( SurfaceProvider
& rSurfaceProvider
,
68 OutputDevice
& rRefDevice
)
70 mpSurfaceProvider
= &rSurfaceProvider
;
71 mpRefDevice
= &rRefDevice
;
73 // no own surface, this is handled by derived classes
76 void DeviceHelper::init( SurfaceProvider
& rSurfaceProvider
,
77 OutputDevice
& rRefDevice
)
79 implInit(rSurfaceProvider
, rRefDevice
);
81 OutputDevice
* pOutDev
=getOutputDevice();
82 mpSurface
= cairo::createSurface( *pOutDev
,
83 pOutDev
->GetOutOffXPixel(),
84 pOutDev
->GetOutOffYPixel(),
85 pOutDev
->GetOutputWidthPixel(),
86 pOutDev
->GetOutputHeightPixel() );
89 void DeviceHelper::disposing()
91 // release all references
94 mpSurfaceProvider
= NULL
;
97 void DeviceHelper::setSize( const ::basegfx::B2ISize
& rSize
)
99 OSL_TRACE("DeviceHelper::setSize(): device size %d x %d", rSize
.getX(), rSize
.getY() );
104 OutputDevice
* pOutDev
=getOutputDevice();
106 #if defined (UNX) && !defined (QUARTZ)
109 mpSurface
->Resize( rSize
.getX() + pOutDev
->GetOutOffXPixel(),
110 rSize
.getY() + pOutDev
->GetOutOffYPixel() );
113 mpSurface
= cairo::createSurface(
115 pOutDev
->GetOutOffXPixel(),
116 pOutDev
->GetOutOffYPixel(),
117 rSize
.getX(), rSize
.getY() );
120 geometry::RealSize2D
DeviceHelper::getPhysicalResolution()
122 // Map a one-by-one millimeter box to pixel
123 const MapMode
aOldMapMode( mpRefDevice
->GetMapMode() );
124 mpRefDevice
->SetMapMode( MapMode(MAP_MM
) );
125 const Size
aPixelSize( mpRefDevice
->LogicToPixel(Size(1,1)) );
126 mpRefDevice
->SetMapMode( aOldMapMode
);
128 return ::vcl::unotools::size2DFromSize( aPixelSize
);
131 geometry::RealSize2D
DeviceHelper::getPhysicalSize()
134 return ::canvas::tools::createInfiniteSize2D(); // we're disposed
136 // Map the pixel dimensions of the output window to millimeter
137 const MapMode
aOldMapMode( mpRefDevice
->GetMapMode() );
138 mpRefDevice
->SetMapMode( MapMode(MAP_MM
) );
139 const Size
aLogSize( mpRefDevice
->PixelToLogic(mpRefDevice
->GetOutputSizePixel()) );
140 mpRefDevice
->SetMapMode( aOldMapMode
);
142 return ::vcl::unotools::size2DFromSize( aLogSize
);
145 uno::Reference
< rendering::XLinePolyPolygon2D
> DeviceHelper::createCompatibleLinePolyPolygon(
146 const uno::Reference
< rendering::XGraphicDevice
>& ,
147 const uno::Sequence
< uno::Sequence
< geometry::RealPoint2D
> >& points
)
150 if( !mpSurfaceProvider
)
151 return uno::Reference
< rendering::XLinePolyPolygon2D
>(); // we're disposed
153 return uno::Reference
< rendering::XLinePolyPolygon2D
>(
154 new ::basegfx::unotools::UnoPolyPolygon(
155 ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points
) ) );
158 uno::Reference
< rendering::XBezierPolyPolygon2D
> DeviceHelper::createCompatibleBezierPolyPolygon(
159 const uno::Reference
< rendering::XGraphicDevice
>& ,
160 const uno::Sequence
< uno::Sequence
< geometry::RealBezierSegment2D
> >& points
)
163 if( !mpSurfaceProvider
)
164 return uno::Reference
< rendering::XBezierPolyPolygon2D
>(); // we're disposed
166 return uno::Reference
< rendering::XBezierPolyPolygon2D
>(
167 new ::basegfx::unotools::UnoPolyPolygon(
168 ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points
) ) );
171 uno::Reference
< rendering::XBitmap
> DeviceHelper::createCompatibleBitmap(
172 const uno::Reference
< rendering::XGraphicDevice
>& rDevice
,
173 const geometry::IntegerSize2D
& size
)
176 if( !mpSurfaceProvider
)
177 return uno::Reference
< rendering::XBitmap
>(); // we're disposed
179 return uno::Reference
< rendering::XBitmap
>(
181 ::basegfx::unotools::b2ISizeFromIntegerSize2D( size
),
182 SurfaceProviderRef(mpSurfaceProvider
),
187 uno::Reference
< rendering::XVolatileBitmap
> DeviceHelper::createVolatileBitmap(
188 const uno::Reference
< rendering::XGraphicDevice
>& ,
189 const geometry::IntegerSize2D
& /*size*/ )
191 return uno::Reference
< rendering::XVolatileBitmap
>();
194 uno::Reference
< rendering::XBitmap
> DeviceHelper::createCompatibleAlphaBitmap(
195 const uno::Reference
< rendering::XGraphicDevice
>& rDevice
,
196 const geometry::IntegerSize2D
& size
)
199 if( !mpSurfaceProvider
)
200 return uno::Reference
< rendering::XBitmap
>(); // we're disposed
202 return uno::Reference
< rendering::XBitmap
>(
204 ::basegfx::unotools::b2ISizeFromIntegerSize2D( size
),
205 SurfaceProviderRef(mpSurfaceProvider
),
210 uno::Reference
< rendering::XVolatileBitmap
> DeviceHelper::createVolatileAlphaBitmap(
211 const uno::Reference
< rendering::XGraphicDevice
>& ,
212 const geometry::IntegerSize2D
& /*size*/ )
214 return uno::Reference
< rendering::XVolatileBitmap
>();
217 sal_Bool
DeviceHelper::hasFullScreenMode()
219 // TODO(F3): offer fullscreen mode the XCanvas way
223 sal_Bool
DeviceHelper::enterFullScreenMode( sal_Bool
/*bEnter*/ )
225 // TODO(F3): offer fullscreen mode the XCanvas way
229 uno::Any
DeviceHelper::isAccelerated() const
231 return ::com::sun::star::uno::makeAny(false);
234 uno::Any
DeviceHelper::getDeviceHandle() const
236 return uno::makeAny( reinterpret_cast< sal_Int64
>(mpRefDevice
) );
239 uno::Any
DeviceHelper::getSurfaceHandle() const
246 struct DeviceColorSpace
: public rtl::StaticWithInit
<uno::Reference
<rendering::XColorSpace
>,
249 uno::Reference
<rendering::XColorSpace
> operator()()
251 return vcl::unotools::createStandardColorSpace();
256 uno::Reference
<rendering::XColorSpace
> DeviceHelper::getColorSpace() const
259 return DeviceColorSpace::get();
262 void DeviceHelper::dumpScreenContent() const
264 static sal_uInt32
nFilePostfixCount(0);
268 String
aFilename( String::CreateFromAscii("dbg_frontbuffer") );
269 aFilename
+= String::CreateFromInt32(nFilePostfixCount
);
270 aFilename
+= String::CreateFromAscii(".bmp");
272 SvFileStream
aStream( aFilename
, STREAM_STD_READWRITE
);
274 const ::Point aEmptyPoint
;
275 bool bOldMap( mpRefDevice
->IsMapModeEnabled() );
276 mpRefDevice
->EnableMapMode( FALSE
);
277 aStream
<< mpRefDevice
->GetBitmap(aEmptyPoint
,
278 mpRefDevice
->GetOutputSizePixel());
279 mpRefDevice
->EnableMapMode( bOldMap
);
285 SurfaceSharedPtr
DeviceHelper::getSurface()
290 SurfaceSharedPtr
DeviceHelper::createSurface( const ::basegfx::B2ISize
& rSize
, Content aContent
)
293 return mpSurface
->getSimilar( aContent
, rSize
.getX(), rSize
.getY() );
295 return SurfaceSharedPtr();
298 SurfaceSharedPtr
DeviceHelper::createSurface( BitmapSystemData
& rData
, const Size
& rSize
)
301 return createBitmapSurface( *mpRefDevice
, rData
, rSize
);
303 return SurfaceSharedPtr();