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 <tools/diagnose_ex.h>
23 #include <canvas/canvastools.hxx>
25 #include <rtl/instance.hxx>
26 #include <toolkit/helper/vclunohelper.hxx>
27 #include <vcl/canvastools.hxx>
28 #include <basegfx/tools/canvastools.hxx>
29 #include <basegfx/tools/unopolypolygon.hxx>
31 #include "devicehelper.hxx"
32 #include "spritecanvas.hxx"
33 #include "spritecanvashelper.hxx"
34 #include "canvasbitmap.hxx"
37 using namespace ::com::sun::star
;
41 DeviceHelper::DeviceHelper() :
45 void DeviceHelper::init( const OutDevProviderSharedPtr
& rOutDev
)
50 geometry::RealSize2D
DeviceHelper::getPhysicalResolution()
53 return ::canvas::tools::createInfiniteSize2D(); // we're disposed
55 // Map a one-by-one millimeter box to pixel
56 OutputDevice
& rOutDev
= mpOutDev
->getOutDev();
57 const MapMode
aOldMapMode( rOutDev
.GetMapMode() );
58 rOutDev
.SetMapMode( MapMode(MAP_MM
) );
59 const Size
aPixelSize( rOutDev
.LogicToPixel(Size(1,1)) );
60 rOutDev
.SetMapMode( aOldMapMode
);
62 return ::vcl::unotools::size2DFromSize( aPixelSize
);
65 geometry::RealSize2D
DeviceHelper::getPhysicalSize()
68 return ::canvas::tools::createInfiniteSize2D(); // we're disposed
70 // Map the pixel dimensions of the output window to millimeter
71 OutputDevice
& rOutDev
= mpOutDev
->getOutDev();
72 const MapMode
aOldMapMode( rOutDev
.GetMapMode() );
73 rOutDev
.SetMapMode( MapMode(MAP_MM
) );
74 const Size
aLogSize( rOutDev
.PixelToLogic(rOutDev
.GetOutputSizePixel()) );
75 rOutDev
.SetMapMode( aOldMapMode
);
77 return ::vcl::unotools::size2DFromSize( aLogSize
);
80 uno::Reference
< rendering::XLinePolyPolygon2D
> DeviceHelper::createCompatibleLinePolyPolygon(
81 const uno::Reference
< rendering::XGraphicDevice
>& ,
82 const uno::Sequence
< uno::Sequence
< geometry::RealPoint2D
> >& points
)
84 uno::Reference
< rendering::XLinePolyPolygon2D
> xPoly
;
86 return xPoly
; // we're disposed
88 xPoly
.set( new ::basegfx::unotools::UnoPolyPolygon(
89 ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points
) ) );
90 // vcl only handles even_odd polygons
91 xPoly
->setFillRule(rendering::FillRule_EVEN_ODD
);
96 uno::Reference
< rendering::XBezierPolyPolygon2D
> DeviceHelper::createCompatibleBezierPolyPolygon(
97 const uno::Reference
< rendering::XGraphicDevice
>& ,
98 const uno::Sequence
< uno::Sequence
< geometry::RealBezierSegment2D
> >& points
)
100 uno::Reference
< rendering::XBezierPolyPolygon2D
> xPoly
;
102 return xPoly
; // we're disposed
104 xPoly
.set( new ::basegfx::unotools::UnoPolyPolygon(
105 ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points
) ) );
106 // vcl only handles even_odd polygons
107 xPoly
->setFillRule(rendering::FillRule_EVEN_ODD
);
112 uno::Reference
< rendering::XBitmap
> DeviceHelper::createCompatibleBitmap(
113 const uno::Reference
< rendering::XGraphicDevice
>& rDevice
,
114 const geometry::IntegerSize2D
& size
)
117 return uno::Reference
< rendering::XBitmap
>(); // we're disposed
119 return uno::Reference
< rendering::XBitmap
>(
120 new CanvasBitmap( ::vcl::unotools::sizeFromIntegerSize2D(size
),
126 uno::Reference
< rendering::XVolatileBitmap
> DeviceHelper::createVolatileBitmap(
127 const uno::Reference
< rendering::XGraphicDevice
>& ,
128 const geometry::IntegerSize2D
& )
130 return uno::Reference
< rendering::XVolatileBitmap
>();
133 uno::Reference
< rendering::XBitmap
> DeviceHelper::createCompatibleAlphaBitmap(
134 const uno::Reference
< rendering::XGraphicDevice
>& rDevice
,
135 const geometry::IntegerSize2D
& size
)
138 return uno::Reference
< rendering::XBitmap
>(); // we're disposed
140 return uno::Reference
< rendering::XBitmap
>(
141 new CanvasBitmap( ::vcl::unotools::sizeFromIntegerSize2D(size
),
147 uno::Reference
< rendering::XVolatileBitmap
> DeviceHelper::createVolatileAlphaBitmap(
148 const uno::Reference
< rendering::XGraphicDevice
>& ,
149 const geometry::IntegerSize2D
& )
151 return uno::Reference
< rendering::XVolatileBitmap
>();
154 sal_Bool
DeviceHelper::hasFullScreenMode()
159 sal_Bool
DeviceHelper::enterFullScreenMode( sal_Bool bEnter
)
165 void DeviceHelper::disposing()
167 // release all references
171 uno::Any
DeviceHelper::isAccelerated() const
173 return ::com::sun::star::uno::makeAny(false);
176 uno::Any
DeviceHelper::getDeviceHandle() const
182 reinterpret_cast< sal_Int64
>(&mpOutDev
->getOutDev()) );
185 uno::Any
DeviceHelper::getSurfaceHandle() const
187 return getDeviceHandle();
192 struct DeviceColorSpace
: public rtl::StaticWithInit
<uno::Reference
<rendering::XColorSpace
>,
195 uno::Reference
<rendering::XColorSpace
> operator()()
197 uno::Reference
< rendering::XColorSpace
> xColorSpace( canvas::tools::getStdColorSpace(), uno::UNO_QUERY
);
198 assert( xColorSpace
.is() );
204 uno::Reference
<rendering::XColorSpace
> DeviceHelper::getColorSpace() const
207 return DeviceColorSpace::get();
210 void DeviceHelper::dumpScreenContent() const
212 static sal_Int32
nFilePostfixCount(0);
216 OUString
aFilename("dbg_frontbuffer");
217 aFilename
+= OUString::valueOf(nFilePostfixCount
);
218 aFilename
+= OUString(".bmp");
220 SvFileStream
aStream( aFilename
, STREAM_STD_READWRITE
);
222 const ::Point aEmptyPoint
;
223 OutputDevice
& rOutDev
= mpOutDev
->getOutDev();
224 bool bOldMap( rOutDev
.IsMapModeEnabled() );
225 rOutDev
.EnableMapMode( sal_False
);
226 aStream
<< rOutDev
.GetBitmap(aEmptyPoint
,
227 rOutDev
.GetOutputSizePixel());
228 rOutDev
.EnableMapMode( bOldMap
);
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */