1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <canvas/debug.hxx>
22 #include <canvas/verbosetrace.hxx>
23 #include <canvas/canvastools.hxx>
25 #include <osl/mutex.hxx>
26 #include <cppuhelper/compbase1.hxx>
28 #include <com/sun/star/lang/NoSupportException.hpp>
30 #include <toolkit/helper/vclunohelper.hxx>
31 #include <basegfx/tools/canvastools.hxx>
32 #include <basegfx/tools/unopolypolygon.hxx>
34 #include <vcl/canvastools.hxx>
36 #include <tools/stream.hxx>
38 #include "cairo_spritecanvas.hxx"
39 #include "cairo_canvasbitmap.hxx"
40 #include "cairo_devicehelper.hxx"
42 using namespace ::cairo
;
43 using namespace ::com::sun::star
;
47 DeviceHelper::DeviceHelper() :
48 mpSurfaceProvider( NULL
),
54 void DeviceHelper::implInit( SurfaceProvider
& rSurfaceProvider
,
55 OutputDevice
& rRefDevice
)
57 mpSurfaceProvider
= &rSurfaceProvider
;
58 mpRefDevice
= &rRefDevice
;
60 // no own surface, this is handled by derived classes
63 void DeviceHelper::init( SurfaceProvider
& rSurfaceProvider
,
64 OutputDevice
& rRefDevice
)
66 implInit(rSurfaceProvider
, rRefDevice
);
68 OutputDevice
* pOutDev
=getOutputDevice();
69 mpSurface
= cairo::createSurface( *pOutDev
,
70 pOutDev
->GetOutOffXPixel(),
71 pOutDev
->GetOutOffYPixel(),
72 pOutDev
->GetOutputWidthPixel(),
73 pOutDev
->GetOutputHeightPixel() );
76 void DeviceHelper::disposing()
78 // release all references
81 mpSurfaceProvider
= NULL
;
84 void DeviceHelper::setSize( const ::basegfx::B2ISize
& rSize
)
86 OSL_TRACE("DeviceHelper::setSize(): device size %d x %d", rSize
.getX(), rSize
.getY() );
91 OutputDevice
* pOutDev
=getOutputDevice();
93 #if defined (UNX) && !defined (MACOSX)
96 mpSurface
->Resize( rSize
.getX() + pOutDev
->GetOutOffXPixel(),
97 rSize
.getY() + pOutDev
->GetOutOffYPixel() );
100 mpSurface
= cairo::createSurface(
102 pOutDev
->GetOutOffXPixel(),
103 pOutDev
->GetOutOffYPixel(),
104 rSize
.getX(), rSize
.getY() );
107 geometry::RealSize2D
DeviceHelper::getPhysicalResolution()
109 // Map a one-by-one millimeter box to pixel
110 const MapMode
aOldMapMode( mpRefDevice
->GetMapMode() );
111 mpRefDevice
->SetMapMode( MapMode(MAP_MM
) );
112 const Size
aPixelSize( mpRefDevice
->LogicToPixel(Size(1,1)) );
113 mpRefDevice
->SetMapMode( aOldMapMode
);
115 return ::vcl::unotools::size2DFromSize( aPixelSize
);
118 geometry::RealSize2D
DeviceHelper::getPhysicalSize()
121 return ::canvas::tools::createInfiniteSize2D(); // we're disposed
123 // Map the pixel dimensions of the output window to millimeter
124 const MapMode
aOldMapMode( mpRefDevice
->GetMapMode() );
125 mpRefDevice
->SetMapMode( MapMode(MAP_MM
) );
126 const Size
aLogSize( mpRefDevice
->PixelToLogic(mpRefDevice
->GetOutputSizePixel()) );
127 mpRefDevice
->SetMapMode( aOldMapMode
);
129 return ::vcl::unotools::size2DFromSize( aLogSize
);
132 uno::Reference
< rendering::XLinePolyPolygon2D
> DeviceHelper::createCompatibleLinePolyPolygon(
133 const uno::Reference
< rendering::XGraphicDevice
>& ,
134 const uno::Sequence
< uno::Sequence
< geometry::RealPoint2D
> >& points
)
137 if( !mpSurfaceProvider
)
138 return uno::Reference
< rendering::XLinePolyPolygon2D
>(); // we're disposed
140 return uno::Reference
< rendering::XLinePolyPolygon2D
>(
141 new ::basegfx::unotools::UnoPolyPolygon(
142 ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points
) ) );
145 uno::Reference
< rendering::XBezierPolyPolygon2D
> DeviceHelper::createCompatibleBezierPolyPolygon(
146 const uno::Reference
< rendering::XGraphicDevice
>& ,
147 const uno::Sequence
< uno::Sequence
< geometry::RealBezierSegment2D
> >& points
)
150 if( !mpSurfaceProvider
)
151 return uno::Reference
< rendering::XBezierPolyPolygon2D
>(); // we're disposed
153 return uno::Reference
< rendering::XBezierPolyPolygon2D
>(
154 new ::basegfx::unotools::UnoPolyPolygon(
155 ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points
) ) );
158 uno::Reference
< rendering::XBitmap
> DeviceHelper::createCompatibleBitmap(
159 const uno::Reference
< rendering::XGraphicDevice
>& rDevice
,
160 const geometry::IntegerSize2D
& size
)
163 if( !mpSurfaceProvider
)
164 return uno::Reference
< rendering::XBitmap
>(); // we're disposed
166 return uno::Reference
< rendering::XBitmap
>(
168 ::basegfx::unotools::b2ISizeFromIntegerSize2D( size
),
169 SurfaceProviderRef(mpSurfaceProvider
),
174 uno::Reference
< rendering::XVolatileBitmap
> DeviceHelper::createVolatileBitmap(
175 const uno::Reference
< rendering::XGraphicDevice
>& ,
176 const geometry::IntegerSize2D
& /*size*/ )
178 return uno::Reference
< rendering::XVolatileBitmap
>();
181 uno::Reference
< rendering::XBitmap
> DeviceHelper::createCompatibleAlphaBitmap(
182 const uno::Reference
< rendering::XGraphicDevice
>& rDevice
,
183 const geometry::IntegerSize2D
& size
)
186 if( !mpSurfaceProvider
)
187 return uno::Reference
< rendering::XBitmap
>(); // we're disposed
189 return uno::Reference
< rendering::XBitmap
>(
191 ::basegfx::unotools::b2ISizeFromIntegerSize2D( size
),
192 SurfaceProviderRef(mpSurfaceProvider
),
197 uno::Reference
< rendering::XVolatileBitmap
> DeviceHelper::createVolatileAlphaBitmap(
198 const uno::Reference
< rendering::XGraphicDevice
>& ,
199 const geometry::IntegerSize2D
& /*size*/ )
201 return uno::Reference
< rendering::XVolatileBitmap
>();
204 sal_Bool
DeviceHelper::hasFullScreenMode()
206 // TODO(F3): offer fullscreen mode the XCanvas way
210 sal_Bool
DeviceHelper::enterFullScreenMode( sal_Bool
/*bEnter*/ )
212 // TODO(F3): offer fullscreen mode the XCanvas way
216 uno::Any
DeviceHelper::isAccelerated() const
218 return ::com::sun::star::uno::makeAny(false);
221 uno::Any
DeviceHelper::getDeviceHandle() const
223 return uno::makeAny( reinterpret_cast< sal_Int64
>(mpRefDevice
) );
226 uno::Any
DeviceHelper::getSurfaceHandle() const
233 struct DeviceColorSpace
: public rtl::StaticWithInit
<uno::Reference
<rendering::XColorSpace
>,
236 uno::Reference
<rendering::XColorSpace
> operator()()
238 return vcl::unotools::createStandardColorSpace();
243 uno::Reference
<rendering::XColorSpace
> DeviceHelper::getColorSpace() const
246 return DeviceColorSpace::get();
249 void DeviceHelper::dumpScreenContent() const
251 static sal_Int32
nFilePostfixCount(0);
255 OUString
aFilename("dbg_frontbuffer");
256 aFilename
+= OUString::valueOf(nFilePostfixCount
);
259 SvFileStream
aStream( aFilename
, STREAM_STD_READWRITE
);
261 const ::Point aEmptyPoint
;
262 bool bOldMap( mpRefDevice
->IsMapModeEnabled() );
263 mpRefDevice
->EnableMapMode( sal_False
);
264 aStream
<< mpRefDevice
->GetBitmap(aEmptyPoint
,
265 mpRefDevice
->GetOutputSizePixel());
266 mpRefDevice
->EnableMapMode( bOldMap
);
272 SurfaceSharedPtr
DeviceHelper::getSurface()
277 SurfaceSharedPtr
DeviceHelper::createSurface( const ::basegfx::B2ISize
& rSize
, Content aContent
)
280 return mpSurface
->getSimilar( aContent
, rSize
.getX(), rSize
.getY() );
282 return SurfaceSharedPtr();
285 SurfaceSharedPtr
DeviceHelper::createSurface( BitmapSystemData
& rData
, const Size
& rSize
)
288 return createBitmapSurface( *mpRefDevice
, rData
, rSize
);
290 return SurfaceSharedPtr();
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */