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 .
20 #include <canvas/debug.hxx>
21 #include <canvas/verbosetrace.hxx>
22 #include <canvas/canvastools.hxx>
24 #include <osl/mutex.hxx>
25 #include <cppuhelper/compbase1.hxx>
27 #include <com/sun/star/lang/NoSupportException.hpp>
29 #include <toolkit/helper/vclunohelper.hxx>
30 #include <basegfx/tools/canvastools.hxx>
31 #include <basegfx/tools/unopolypolygon.hxx>
33 #include <vcl/canvastools.hxx>
34 #include <vcl/dibtools.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
= pOutDev
->CreateSurface(pOutDev
->GetOutOffXPixel(),
70 pOutDev
->GetOutOffYPixel(),
71 pOutDev
->GetOutputWidthPixel(),
72 pOutDev
->GetOutputHeightPixel());
75 void DeviceHelper::disposing()
77 // release all references
80 mpSurfaceProvider
= NULL
;
83 void DeviceHelper::setSize( const ::basegfx::B2ISize
& rSize
)
87 "device size " << rSize
.getX() << " x " << rSize
.getY());
92 OutputDevice
* pOutDev
= getOutputDevice();
95 bool bReuseSurface
= mpSurface
&&
96 mpSurface
->Resize(rSize
.getX() + pOutDev
->GetOutOffXPixel(),
97 rSize
.getY() + pOutDev
->GetOutOffYPixel());
101 mpSurface
= pOutDev
->CreateSurface(
102 pOutDev
->GetOutOffXPixel(),
103 pOutDev
->GetOutOffYPixel(),
104 rSize
.getX(), rSize
.getY() );
108 geometry::RealSize2D
DeviceHelper::getPhysicalResolution()
110 // Map a one-by-one millimeter box to pixel
111 const MapMode
aOldMapMode( mpRefDevice
->GetMapMode() );
112 mpRefDevice
->SetMapMode( MapMode(MAP_MM
) );
113 const Size
aPixelSize( mpRefDevice
->LogicToPixel(Size(1,1)) );
114 mpRefDevice
->SetMapMode( aOldMapMode
);
116 return vcl::unotools::size2DFromSize( aPixelSize
);
119 geometry::RealSize2D
DeviceHelper::getPhysicalSize()
122 return ::canvas::tools::createInfiniteSize2D(); // we're disposed
124 // Map the pixel dimensions of the output window to millimeter
125 const MapMode
aOldMapMode( mpRefDevice
->GetMapMode() );
126 mpRefDevice
->SetMapMode( MapMode(MAP_MM
) );
127 const Size
aLogSize( mpRefDevice
->PixelToLogic(mpRefDevice
->GetOutputSizePixel()) );
128 mpRefDevice
->SetMapMode( aOldMapMode
);
130 return vcl::unotools::size2DFromSize( aLogSize
);
133 uno::Reference
< rendering::XLinePolyPolygon2D
> DeviceHelper::createCompatibleLinePolyPolygon(
134 const uno::Reference
< rendering::XGraphicDevice
>& ,
135 const uno::Sequence
< uno::Sequence
< geometry::RealPoint2D
> >& points
)
138 if( !mpSurfaceProvider
)
139 return uno::Reference
< rendering::XLinePolyPolygon2D
>(); // we're disposed
141 return uno::Reference
< rendering::XLinePolyPolygon2D
>(
142 new ::basegfx::unotools::UnoPolyPolygon(
143 ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points
) ) );
146 uno::Reference
< rendering::XBezierPolyPolygon2D
> DeviceHelper::createCompatibleBezierPolyPolygon(
147 const uno::Reference
< rendering::XGraphicDevice
>& ,
148 const uno::Sequence
< uno::Sequence
< geometry::RealBezierSegment2D
> >& points
)
151 if( !mpSurfaceProvider
)
152 return uno::Reference
< rendering::XBezierPolyPolygon2D
>(); // we're disposed
154 return uno::Reference
< rendering::XBezierPolyPolygon2D
>(
155 new ::basegfx::unotools::UnoPolyPolygon(
156 ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points
) ) );
159 uno::Reference
< rendering::XBitmap
> DeviceHelper::createCompatibleBitmap(
160 const uno::Reference
< rendering::XGraphicDevice
>& rDevice
,
161 const geometry::IntegerSize2D
& size
)
164 if( !mpSurfaceProvider
)
165 return uno::Reference
< rendering::XBitmap
>(); // we're disposed
167 return uno::Reference
< rendering::XBitmap
>(
169 ::basegfx::unotools::b2ISizeFromIntegerSize2D( size
),
170 SurfaceProviderRef(mpSurfaceProvider
),
175 uno::Reference
< rendering::XVolatileBitmap
> DeviceHelper::createVolatileBitmap(
176 const uno::Reference
< rendering::XGraphicDevice
>& ,
177 const geometry::IntegerSize2D
& /*size*/ )
179 return uno::Reference
< rendering::XVolatileBitmap
>();
182 uno::Reference
< rendering::XBitmap
> DeviceHelper::createCompatibleAlphaBitmap(
183 const uno::Reference
< rendering::XGraphicDevice
>& rDevice
,
184 const geometry::IntegerSize2D
& size
)
187 if( !mpSurfaceProvider
)
188 return uno::Reference
< rendering::XBitmap
>(); // we're disposed
190 return uno::Reference
< rendering::XBitmap
>(
192 ::basegfx::unotools::b2ISizeFromIntegerSize2D( size
),
193 SurfaceProviderRef(mpSurfaceProvider
),
198 uno::Reference
< rendering::XVolatileBitmap
> DeviceHelper::createVolatileAlphaBitmap(
199 const uno::Reference
< rendering::XGraphicDevice
>& ,
200 const geometry::IntegerSize2D
& /*size*/ )
202 return uno::Reference
< rendering::XVolatileBitmap
>();
205 uno::Any
DeviceHelper::isAccelerated() const
207 return ::com::sun::star::uno::makeAny(false);
210 uno::Any
DeviceHelper::getDeviceHandle() const
212 return uno::makeAny( reinterpret_cast< sal_Int64
>(mpRefDevice
.get()) );
215 uno::Any
DeviceHelper::getSurfaceHandle() const
222 struct DeviceColorSpace
: public rtl::StaticWithInit
<uno::Reference
<rendering::XColorSpace
>,
225 uno::Reference
<rendering::XColorSpace
> operator()()
227 return vcl::unotools::createStandardColorSpace();
232 uno::Reference
<rendering::XColorSpace
> DeviceHelper::getColorSpace() const
235 return DeviceColorSpace::get();
238 void DeviceHelper::dumpScreenContent() const
240 static sal_Int32
nFilePostfixCount(0);
244 OUString
aFilename("dbg_frontbuffer");
245 aFilename
+= OUString::number(nFilePostfixCount
);
248 SvFileStream
aStream( aFilename
, STREAM_STD_READWRITE
);
250 const ::Point aEmptyPoint
;
251 bool bOldMap( mpRefDevice
->IsMapModeEnabled() );
252 mpRefDevice
->EnableMapMode( false );
253 const ::Bitmap
aTempBitmap(mpRefDevice
->GetBitmap(aEmptyPoint
, mpRefDevice
->GetOutputSizePixel()));
254 WriteDIB(aTempBitmap
, aStream
, false, true);
255 mpRefDevice
->EnableMapMode( bOldMap
);
261 SurfaceSharedPtr
DeviceHelper::createSurface( const ::basegfx::B2ISize
& rSize
, int aContent
)
264 return mpSurface
->getSimilar( aContent
, rSize
.getX(), rSize
.getY() );
266 return SurfaceSharedPtr();
269 SurfaceSharedPtr
DeviceHelper::createSurface( BitmapSystemData
& rData
, const Size
& rSize
)
272 return mpRefDevice
->CreateBitmapSurface(rData
, rSize
);
274 return SurfaceSharedPtr();
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */