Line data Source code
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 :
21 : #include <canvas/debug.hxx>
22 : #include <tools/diagnose_ex.h>
23 : #include <canvas/canvastools.hxx>
24 :
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>
30 :
31 : #include "devicehelper.hxx"
32 : #include "spritecanvas.hxx"
33 : #include "spritecanvashelper.hxx"
34 : #include "canvasbitmap.hxx"
35 :
36 :
37 : using namespace ::com::sun::star;
38 :
39 : namespace vclcanvas
40 : {
41 0 : DeviceHelper::DeviceHelper() :
42 0 : mpOutDev()
43 0 : {}
44 :
45 0 : void DeviceHelper::init( const OutDevProviderSharedPtr& rOutDev )
46 : {
47 0 : mpOutDev = rOutDev;
48 0 : }
49 :
50 0 : geometry::RealSize2D DeviceHelper::getPhysicalResolution()
51 : {
52 0 : if( !mpOutDev )
53 0 : return ::canvas::tools::createInfiniteSize2D(); // we're disposed
54 :
55 : // Map a one-by-one millimeter box to pixel
56 0 : OutputDevice& rOutDev = mpOutDev->getOutDev();
57 0 : const MapMode aOldMapMode( rOutDev.GetMapMode() );
58 0 : rOutDev.SetMapMode( MapMode(MAP_MM) );
59 0 : const Size aPixelSize( rOutDev.LogicToPixel(Size(1,1)) );
60 0 : rOutDev.SetMapMode( aOldMapMode );
61 :
62 0 : return ::vcl::unotools::size2DFromSize( aPixelSize );
63 : }
64 :
65 0 : geometry::RealSize2D DeviceHelper::getPhysicalSize()
66 : {
67 0 : if( !mpOutDev )
68 0 : return ::canvas::tools::createInfiniteSize2D(); // we're disposed
69 :
70 : // Map the pixel dimensions of the output window to millimeter
71 0 : OutputDevice& rOutDev = mpOutDev->getOutDev();
72 0 : const MapMode aOldMapMode( rOutDev.GetMapMode() );
73 0 : rOutDev.SetMapMode( MapMode(MAP_MM) );
74 0 : const Size aLogSize( rOutDev.PixelToLogic(rOutDev.GetOutputSizePixel()) );
75 0 : rOutDev.SetMapMode( aOldMapMode );
76 :
77 0 : return ::vcl::unotools::size2DFromSize( aLogSize );
78 : }
79 :
80 0 : uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
81 : const uno::Reference< rendering::XGraphicDevice >& ,
82 : const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points )
83 : {
84 0 : uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
85 0 : if( !mpOutDev )
86 0 : return xPoly; // we're disposed
87 :
88 : xPoly.set( new ::basegfx::unotools::UnoPolyPolygon(
89 0 : ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) );
90 : // vcl only handles even_odd polygons
91 0 : xPoly->setFillRule(rendering::FillRule_EVEN_ODD);
92 :
93 0 : return xPoly;
94 : }
95 :
96 0 : uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
97 : const uno::Reference< rendering::XGraphicDevice >& ,
98 : const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points )
99 : {
100 0 : uno::Reference< rendering::XBezierPolyPolygon2D > xPoly;
101 0 : if( !mpOutDev )
102 0 : return xPoly; // we're disposed
103 :
104 : xPoly.set( new ::basegfx::unotools::UnoPolyPolygon(
105 0 : ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) );
106 : // vcl only handles even_odd polygons
107 0 : xPoly->setFillRule(rendering::FillRule_EVEN_ODD);
108 :
109 0 : return xPoly;
110 : }
111 :
112 0 : uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
113 : const uno::Reference< rendering::XGraphicDevice >& rDevice,
114 : const geometry::IntegerSize2D& size )
115 : {
116 0 : if( !mpOutDev )
117 0 : return uno::Reference< rendering::XBitmap >(); // we're disposed
118 :
119 : return uno::Reference< rendering::XBitmap >(
120 : new CanvasBitmap( ::vcl::unotools::sizeFromIntegerSize2D(size),
121 : false,
122 : *rDevice.get(),
123 0 : mpOutDev ) );
124 : }
125 :
126 0 : uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap(
127 : const uno::Reference< rendering::XGraphicDevice >& ,
128 : const geometry::IntegerSize2D& )
129 : {
130 0 : return uno::Reference< rendering::XVolatileBitmap >();
131 : }
132 :
133 0 : uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap(
134 : const uno::Reference< rendering::XGraphicDevice >& rDevice,
135 : const geometry::IntegerSize2D& size )
136 : {
137 0 : if( !mpOutDev )
138 0 : return uno::Reference< rendering::XBitmap >(); // we're disposed
139 :
140 : return uno::Reference< rendering::XBitmap >(
141 : new CanvasBitmap( ::vcl::unotools::sizeFromIntegerSize2D(size),
142 : true,
143 : *rDevice.get(),
144 0 : mpOutDev ) );
145 : }
146 :
147 0 : uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap(
148 : const uno::Reference< rendering::XGraphicDevice >& ,
149 : const geometry::IntegerSize2D& )
150 : {
151 0 : return uno::Reference< rendering::XVolatileBitmap >();
152 : }
153 :
154 0 : sal_Bool DeviceHelper::hasFullScreenMode()
155 : {
156 0 : return false;
157 : }
158 :
159 0 : sal_Bool DeviceHelper::enterFullScreenMode( sal_Bool bEnter )
160 : {
161 : (void)bEnter;
162 0 : return false;
163 : }
164 :
165 0 : void DeviceHelper::disposing()
166 : {
167 : // release all references
168 0 : mpOutDev.reset();
169 0 : }
170 :
171 0 : uno::Any DeviceHelper::isAccelerated() const
172 : {
173 0 : return ::com::sun::star::uno::makeAny(false);
174 : }
175 :
176 0 : uno::Any DeviceHelper::getDeviceHandle() const
177 : {
178 0 : if( !mpOutDev )
179 0 : return uno::Any();
180 :
181 : return uno::makeAny(
182 0 : reinterpret_cast< sal_Int64 >(&mpOutDev->getOutDev()) );
183 : }
184 :
185 0 : uno::Any DeviceHelper::getSurfaceHandle() const
186 : {
187 0 : return getDeviceHandle();
188 : }
189 :
190 : namespace
191 : {
192 : struct DeviceColorSpace: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>,
193 : DeviceColorSpace>
194 : {
195 0 : uno::Reference<rendering::XColorSpace> operator()()
196 : {
197 0 : uno::Reference< rendering::XColorSpace > xColorSpace( canvas::tools::getStdColorSpace(), uno::UNO_QUERY );
198 : assert( xColorSpace.is() );
199 0 : return xColorSpace;
200 : }
201 : };
202 : }
203 :
204 0 : uno::Reference<rendering::XColorSpace> DeviceHelper::getColorSpace() const
205 : {
206 : // always the same
207 0 : return DeviceColorSpace::get();
208 : }
209 :
210 0 : void DeviceHelper::dumpScreenContent() const
211 : {
212 : static sal_Int32 nFilePostfixCount(0);
213 :
214 0 : if( mpOutDev )
215 : {
216 0 : rtl::OUString aFilename("dbg_frontbuffer");
217 0 : aFilename += rtl::OUString::valueOf(nFilePostfixCount);
218 0 : aFilename += rtl::OUString(".bmp");
219 :
220 0 : SvFileStream aStream( aFilename, STREAM_STD_READWRITE );
221 :
222 0 : const ::Point aEmptyPoint;
223 0 : OutputDevice& rOutDev = mpOutDev->getOutDev();
224 0 : bool bOldMap( rOutDev.IsMapModeEnabled() );
225 0 : rOutDev.EnableMapMode( sal_False );
226 : aStream << rOutDev.GetBitmap(aEmptyPoint,
227 0 : rOutDev.GetOutputSizePixel());
228 0 : rOutDev.EnableMapMode( bOldMap );
229 :
230 0 : ++nFilePostfixCount;
231 : }
232 0 : }
233 :
234 0 : }
235 :
236 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|