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 <tools/diagnose_ex.h>
22 #include <canvas/canvastools.hxx>
23 #include <rtl/instance.hxx>
24 #include <toolkit/helper/vclunohelper.hxx>
25 #include <vcl/canvastools.hxx>
26 #include <basegfx/tools/canvastools.hxx>
27 #include <basegfx/tools/unopolypolygon.hxx>
28 #include <vcl/dibtools.hxx>
30 #include "devicehelper.hxx"
31 #include "spritecanvas.hxx"
32 #include "spritecanvashelper.hxx"
33 #include "canvasbitmap.hxx"
35 using namespace ::com::sun::star
;
39 DeviceHelper::DeviceHelper() :
43 void DeviceHelper::init( const OutDevProviderSharedPtr
& rOutDev
)
48 geometry::RealSize2D
DeviceHelper::getPhysicalResolution()
51 return ::canvas::tools::createInfiniteSize2D(); // we're disposed
53 // Map a one-by-one millimeter box to pixel
54 OutputDevice
& rOutDev
= mpOutDev
->getOutDev();
55 const MapMode
aOldMapMode( rOutDev
.GetMapMode() );
56 rOutDev
.SetMapMode( MapMode(MAP_MM
) );
57 const Size
aPixelSize( rOutDev
.LogicToPixel(Size(1,1)) );
58 rOutDev
.SetMapMode( aOldMapMode
);
60 return vcl::unotools::size2DFromSize( aPixelSize
);
63 geometry::RealSize2D
DeviceHelper::getPhysicalSize()
66 return ::canvas::tools::createInfiniteSize2D(); // we're disposed
68 // Map the pixel dimensions of the output window to millimeter
69 OutputDevice
& rOutDev
= mpOutDev
->getOutDev();
70 const MapMode
aOldMapMode( rOutDev
.GetMapMode() );
71 rOutDev
.SetMapMode( MapMode(MAP_MM
) );
72 const Size
aLogSize( rOutDev
.PixelToLogic(rOutDev
.GetOutputSizePixel()) );
73 rOutDev
.SetMapMode( aOldMapMode
);
75 return vcl::unotools::size2DFromSize( aLogSize
);
78 uno::Reference
< rendering::XLinePolyPolygon2D
> DeviceHelper::createCompatibleLinePolyPolygon(
79 const uno::Reference
< rendering::XGraphicDevice
>& ,
80 const uno::Sequence
< uno::Sequence
< geometry::RealPoint2D
> >& points
)
82 uno::Reference
< rendering::XLinePolyPolygon2D
> xPoly
;
84 return xPoly
; // we're disposed
86 xPoly
.set( new ::basegfx::unotools::UnoPolyPolygon(
87 ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points
) ) );
88 // vcl only handles even_odd polygons
89 xPoly
->setFillRule(rendering::FillRule_EVEN_ODD
);
94 uno::Reference
< rendering::XBezierPolyPolygon2D
> DeviceHelper::createCompatibleBezierPolyPolygon(
95 const uno::Reference
< rendering::XGraphicDevice
>& ,
96 const uno::Sequence
< uno::Sequence
< geometry::RealBezierSegment2D
> >& points
)
98 uno::Reference
< rendering::XBezierPolyPolygon2D
> xPoly
;
100 return xPoly
; // we're disposed
102 xPoly
.set( new ::basegfx::unotools::UnoPolyPolygon(
103 ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points
) ) );
104 // vcl only handles even_odd polygons
105 xPoly
->setFillRule(rendering::FillRule_EVEN_ODD
);
110 uno::Reference
< rendering::XBitmap
> DeviceHelper::createCompatibleBitmap(
111 const uno::Reference
< rendering::XGraphicDevice
>& rDevice
,
112 const geometry::IntegerSize2D
& size
)
115 return uno::Reference
< rendering::XBitmap
>(); // we're disposed
117 return uno::Reference
< rendering::XBitmap
>(
118 new CanvasBitmap( vcl::unotools::sizeFromIntegerSize2D(size
),
124 uno::Reference
< rendering::XVolatileBitmap
> DeviceHelper::createVolatileBitmap(
125 const uno::Reference
< rendering::XGraphicDevice
>& ,
126 const geometry::IntegerSize2D
& )
128 return uno::Reference
< rendering::XVolatileBitmap
>();
131 uno::Reference
< rendering::XBitmap
> DeviceHelper::createCompatibleAlphaBitmap(
132 const uno::Reference
< rendering::XGraphicDevice
>& rDevice
,
133 const geometry::IntegerSize2D
& size
)
136 return uno::Reference
< rendering::XBitmap
>(); // we're disposed
138 return uno::Reference
< rendering::XBitmap
>(
139 new CanvasBitmap( vcl::unotools::sizeFromIntegerSize2D(size
),
145 uno::Reference
< rendering::XVolatileBitmap
> DeviceHelper::createVolatileAlphaBitmap(
146 const uno::Reference
< rendering::XGraphicDevice
>& ,
147 const geometry::IntegerSize2D
& )
149 return uno::Reference
< rendering::XVolatileBitmap
>();
152 bool DeviceHelper::enterFullScreenMode( bool bEnter
)
158 void DeviceHelper::disposing()
160 // release all references
164 uno::Any
DeviceHelper::isAccelerated() const
166 return ::com::sun::star::uno::makeAny(false);
169 uno::Any
DeviceHelper::getDeviceHandle() const
175 reinterpret_cast< sal_Int64
>(&mpOutDev
->getOutDev()) );
178 uno::Any
DeviceHelper::getSurfaceHandle() const
180 return getDeviceHandle();
185 struct DeviceColorSpace
: public rtl::StaticWithInit
<uno::Reference
<rendering::XColorSpace
>,
188 uno::Reference
<rendering::XColorSpace
> operator()()
190 uno::Reference
< rendering::XColorSpace
> xColorSpace( canvas::tools::getStdColorSpace(), uno::UNO_QUERY
);
191 assert( xColorSpace
.is() );
197 uno::Reference
<rendering::XColorSpace
> DeviceHelper::getColorSpace() const
200 return DeviceColorSpace::get();
203 void DeviceHelper::dumpScreenContent() const
205 static sal_Int32
nFilePostfixCount(0);
209 OUString aFilename
= "dbg_frontbuffer" + OUString::number(nFilePostfixCount
) + ".bmp";
211 SvFileStream
aStream( aFilename
, STREAM_STD_READWRITE
);
213 const ::Point aEmptyPoint
;
214 OutputDevice
& rOutDev
= mpOutDev
->getOutDev();
215 bool bOldMap( rOutDev
.IsMapModeEnabled() );
216 rOutDev
.EnableMapMode( false );
217 WriteDIB(rOutDev
.GetBitmap(aEmptyPoint
, rOutDev
.GetOutputSizePixel()), aStream
, false, true);
218 rOutDev
.EnableMapMode( bOldMap
);
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */