/src/libreoffice/canvas/source/vcl/devicehelper.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <sal/config.h> |
21 | | |
22 | | #include <basegfx/utils/canvastools.hxx> |
23 | | #include <basegfx/utils/unopolypolygon.hxx> |
24 | | #include <canvas/canvastools.hxx> |
25 | | #include <tools/mapunit.hxx> |
26 | | #include <tools/stream.hxx> |
27 | | #include <vcl/canvastools.hxx> |
28 | | #include <vcl/dibtools.hxx> |
29 | | |
30 | | #include "canvasbitmap.hxx" |
31 | | #include "devicehelper.hxx" |
32 | | |
33 | | using namespace ::com::sun::star; |
34 | | |
35 | | namespace vclcanvas |
36 | | { |
37 | | DeviceHelper::DeviceHelper() |
38 | 0 | {} |
39 | | |
40 | | void DeviceHelper::init( const OutDevProviderSharedPtr& rOutDev ) |
41 | 0 | { |
42 | 0 | mpOutDev = rOutDev; |
43 | 0 | } |
44 | | |
45 | | geometry::RealSize2D DeviceHelper::getPhysicalResolution() |
46 | 0 | { |
47 | 0 | if( !mpOutDev ) |
48 | 0 | return ::canvastools::createInfiniteSize2D(); // we're disposed |
49 | | |
50 | | // Map a one-by-one millimeter box to pixel |
51 | 0 | OutputDevice& rOutDev = mpOutDev->getOutDev(); |
52 | 0 | const MapMode aOldMapMode( rOutDev.GetMapMode() ); |
53 | 0 | rOutDev.SetMapMode( MapMode(MapUnit::MapMM) ); |
54 | 0 | const Size aPixelSize( rOutDev.LogicToPixel(Size(1,1)) ); |
55 | 0 | rOutDev.SetMapMode( aOldMapMode ); |
56 | |
|
57 | 0 | return vcl::unotools::size2DFromSize( aPixelSize ); |
58 | 0 | } |
59 | | |
60 | | geometry::RealSize2D DeviceHelper::getPhysicalSize() |
61 | 0 | { |
62 | 0 | if( !mpOutDev ) |
63 | 0 | return ::canvastools::createInfiniteSize2D(); // we're disposed |
64 | | |
65 | | // Map the pixel dimensions of the output window to millimeter |
66 | 0 | OutputDevice& rOutDev = mpOutDev->getOutDev(); |
67 | 0 | const MapMode aOldMapMode( rOutDev.GetMapMode() ); |
68 | 0 | rOutDev.SetMapMode( MapMode(MapUnit::MapMM) ); |
69 | 0 | const Size aLogSize( rOutDev.PixelToLogic(rOutDev.GetOutputSizePixel()) ); |
70 | 0 | rOutDev.SetMapMode( aOldMapMode ); |
71 | |
|
72 | 0 | return vcl::unotools::size2DFromSize( aLogSize ); |
73 | 0 | } |
74 | | |
75 | | uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon( |
76 | | const uno::Reference< rendering::XGraphicDevice >& , |
77 | | const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points ) |
78 | 0 | { |
79 | 0 | uno::Reference< rendering::XLinePolyPolygon2D > xPoly; |
80 | 0 | if( !mpOutDev ) |
81 | 0 | return xPoly; // we're disposed |
82 | | |
83 | 0 | xPoly.set( new ::basegfx::unotools::UnoPolyPolygon( |
84 | 0 | ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) ); |
85 | | // vcl only handles even_odd polygons |
86 | 0 | xPoly->setFillRule(rendering::FillRule_EVEN_ODD); |
87 | |
|
88 | 0 | return xPoly; |
89 | 0 | } |
90 | | |
91 | | uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon( |
92 | | const uno::Reference< rendering::XGraphicDevice >& , |
93 | | const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points ) |
94 | 0 | { |
95 | 0 | uno::Reference< rendering::XBezierPolyPolygon2D > xPoly; |
96 | 0 | if( !mpOutDev ) |
97 | 0 | return xPoly; // we're disposed |
98 | | |
99 | 0 | xPoly.set( new ::basegfx::unotools::UnoPolyPolygon( |
100 | 0 | ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) ); |
101 | | // vcl only handles even_odd polygons |
102 | 0 | xPoly->setFillRule(rendering::FillRule_EVEN_ODD); |
103 | |
|
104 | 0 | return xPoly; |
105 | 0 | } |
106 | | |
107 | | uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap( |
108 | | const uno::Reference< rendering::XGraphicDevice >& rDevice, |
109 | | const geometry::IntegerSize2D& size ) |
110 | 0 | { |
111 | 0 | if( !mpOutDev ) |
112 | 0 | return uno::Reference< rendering::XBitmap >(); // we're disposed |
113 | | |
114 | 0 | return uno::Reference< rendering::XBitmap >( |
115 | 0 | new CanvasBitmap( vcl::unotools::sizeFromIntegerSize2D(size), |
116 | 0 | false, |
117 | 0 | *rDevice, |
118 | 0 | mpOutDev ) ); |
119 | 0 | } |
120 | | |
121 | | uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap( |
122 | | const uno::Reference< rendering::XGraphicDevice >& , |
123 | | const geometry::IntegerSize2D& ) |
124 | 0 | { |
125 | 0 | return uno::Reference< rendering::XVolatileBitmap >(); |
126 | 0 | } |
127 | | |
128 | | uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap( |
129 | | const uno::Reference< rendering::XGraphicDevice >& rDevice, |
130 | | const geometry::IntegerSize2D& size ) |
131 | 0 | { |
132 | 0 | if( !mpOutDev ) |
133 | 0 | return uno::Reference< rendering::XBitmap >(); // we're disposed |
134 | | |
135 | 0 | return uno::Reference< rendering::XBitmap >( |
136 | 0 | new CanvasBitmap( vcl::unotools::sizeFromIntegerSize2D(size), |
137 | 0 | true, |
138 | 0 | *rDevice, |
139 | 0 | mpOutDev ) ); |
140 | 0 | } |
141 | | |
142 | | uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap( |
143 | | const uno::Reference< rendering::XGraphicDevice >& , |
144 | | const geometry::IntegerSize2D& ) |
145 | 0 | { |
146 | 0 | return uno::Reference< rendering::XVolatileBitmap >(); |
147 | 0 | } |
148 | | |
149 | | void DeviceHelper::disposing() |
150 | 0 | { |
151 | | // release all references |
152 | 0 | mpOutDev.reset(); |
153 | 0 | } |
154 | | |
155 | | uno::Any DeviceHelper::isAccelerated() const |
156 | 0 | { |
157 | 0 | return css::uno::Any(false); |
158 | 0 | } |
159 | | |
160 | | uno::Any DeviceHelper::getDeviceHandle() const |
161 | 0 | { |
162 | 0 | if( !mpOutDev ) |
163 | 0 | return uno::Any(); |
164 | | |
165 | 0 | return uno::Any( |
166 | 0 | reinterpret_cast< sal_Int64 >(&mpOutDev->getOutDev()) ); |
167 | 0 | } |
168 | | |
169 | | uno::Any DeviceHelper::getSurfaceHandle() const |
170 | 0 | { |
171 | 0 | return getDeviceHandle(); |
172 | 0 | } |
173 | | |
174 | | namespace |
175 | | { |
176 | | uno::Reference<rendering::XColorSpace>& GetDeviceColorSpace() |
177 | 0 | { |
178 | 0 | static uno::Reference<rendering::XColorSpace> xColorSpace = |
179 | 0 | []() |
180 | 0 | { |
181 | 0 | auto xTmp = canvastools::getStdColorSpace(); |
182 | 0 | assert( xTmp.is() ); |
183 | 0 | return xTmp; |
184 | 0 | }(); |
185 | 0 | return xColorSpace; |
186 | 0 | }; |
187 | | } |
188 | | |
189 | | uno::Reference<rendering::XColorSpace> const & DeviceHelper::getColorSpace() const |
190 | 0 | { |
191 | | // always the same |
192 | 0 | return GetDeviceColorSpace(); |
193 | 0 | } |
194 | | |
195 | | void DeviceHelper::dumpScreenContent() const |
196 | 0 | { |
197 | 0 | static sal_Int32 nFilePostfixCount(0); |
198 | |
|
199 | 0 | if( !mpOutDev ) |
200 | 0 | return; |
201 | | |
202 | 0 | OUString aFilename = "dbg_frontbuffer" + OUString::number(nFilePostfixCount) + ".bmp"; |
203 | |
|
204 | 0 | SvFileStream aStream( aFilename, StreamMode::STD_READWRITE ); |
205 | |
|
206 | 0 | const ::Point aEmptyPoint; |
207 | 0 | OutputDevice& rOutDev = mpOutDev->getOutDev(); |
208 | 0 | bool bOldMap( rOutDev.IsMapModeEnabled() ); |
209 | 0 | rOutDev.EnableMapMode( false ); |
210 | 0 | WriteDIB(rOutDev.GetBitmap(aEmptyPoint, rOutDev.GetOutputSizePixel()), aStream, false); |
211 | 0 | rOutDev.EnableMapMode( bOldMap ); |
212 | |
|
213 | 0 | ++nFilePostfixCount; |
214 | 0 | } |
215 | | |
216 | | } |
217 | | |
218 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |