Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <canvas/debug.hxx>
31 : : #include <tools/diagnose_ex.h>
32 : : #include <canvas/canvastools.hxx>
33 : :
34 : : #include <rtl/instance.hxx>
35 : : #include <toolkit/helper/vclunohelper.hxx>
36 : : #include <vcl/canvastools.hxx>
37 : : #include <basegfx/tools/canvastools.hxx>
38 : : #include <basegfx/tools/unopolypolygon.hxx>
39 : :
40 : : #include "devicehelper.hxx"
41 : : #include "spritecanvas.hxx"
42 : : #include "spritecanvashelper.hxx"
43 : : #include "canvasbitmap.hxx"
44 : :
45 : :
46 : : using namespace ::com::sun::star;
47 : :
48 : : namespace vclcanvas
49 : : {
50 : 0 : DeviceHelper::DeviceHelper() :
51 : 0 : mpOutDev()
52 : 0 : {}
53 : :
54 : 0 : void DeviceHelper::init( const OutDevProviderSharedPtr& rOutDev )
55 : : {
56 : 0 : mpOutDev = rOutDev;
57 : 0 : }
58 : :
59 : 0 : geometry::RealSize2D DeviceHelper::getPhysicalResolution()
60 : : {
61 : 0 : if( !mpOutDev )
62 : 0 : return ::canvas::tools::createInfiniteSize2D(); // we're disposed
63 : :
64 : : // Map a one-by-one millimeter box to pixel
65 : 0 : OutputDevice& rOutDev = mpOutDev->getOutDev();
66 : 0 : const MapMode aOldMapMode( rOutDev.GetMapMode() );
67 : 0 : rOutDev.SetMapMode( MapMode(MAP_MM) );
68 : 0 : const Size aPixelSize( rOutDev.LogicToPixel(Size(1,1)) );
69 : 0 : rOutDev.SetMapMode( aOldMapMode );
70 : :
71 : 0 : return ::vcl::unotools::size2DFromSize( aPixelSize );
72 : : }
73 : :
74 : 0 : geometry::RealSize2D DeviceHelper::getPhysicalSize()
75 : : {
76 : 0 : if( !mpOutDev )
77 : 0 : return ::canvas::tools::createInfiniteSize2D(); // we're disposed
78 : :
79 : : // Map the pixel dimensions of the output window to millimeter
80 : 0 : OutputDevice& rOutDev = mpOutDev->getOutDev();
81 : 0 : const MapMode aOldMapMode( rOutDev.GetMapMode() );
82 : 0 : rOutDev.SetMapMode( MapMode(MAP_MM) );
83 : 0 : const Size aLogSize( rOutDev.PixelToLogic(rOutDev.GetOutputSizePixel()) );
84 : 0 : rOutDev.SetMapMode( aOldMapMode );
85 : :
86 : 0 : return ::vcl::unotools::size2DFromSize( aLogSize );
87 : : }
88 : :
89 : 0 : uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
90 : : const uno::Reference< rendering::XGraphicDevice >& ,
91 : : const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points )
92 : : {
93 : 0 : uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
94 : 0 : if( !mpOutDev )
95 : 0 : return xPoly; // we're disposed
96 : :
97 : : xPoly.set( new ::basegfx::unotools::UnoPolyPolygon(
98 : 0 : ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) );
99 : : // vcl only handles even_odd polygons
100 : 0 : xPoly->setFillRule(rendering::FillRule_EVEN_ODD);
101 : :
102 : 0 : return xPoly;
103 : : }
104 : :
105 : 0 : uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
106 : : const uno::Reference< rendering::XGraphicDevice >& ,
107 : : const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points )
108 : : {
109 : 0 : uno::Reference< rendering::XBezierPolyPolygon2D > xPoly;
110 : 0 : if( !mpOutDev )
111 : 0 : return xPoly; // we're disposed
112 : :
113 : : xPoly.set( new ::basegfx::unotools::UnoPolyPolygon(
114 : 0 : ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) );
115 : : // vcl only handles even_odd polygons
116 : 0 : xPoly->setFillRule(rendering::FillRule_EVEN_ODD);
117 : :
118 : 0 : return xPoly;
119 : : }
120 : :
121 : 0 : uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
122 : : const uno::Reference< rendering::XGraphicDevice >& rDevice,
123 : : const geometry::IntegerSize2D& size )
124 : : {
125 : 0 : if( !mpOutDev )
126 : 0 : return uno::Reference< rendering::XBitmap >(); // we're disposed
127 : :
128 : : return uno::Reference< rendering::XBitmap >(
129 : : new CanvasBitmap( ::vcl::unotools::sizeFromIntegerSize2D(size),
130 : : false,
131 : : *rDevice.get(),
132 : 0 : mpOutDev ) );
133 : : }
134 : :
135 : 0 : uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap(
136 : : const uno::Reference< rendering::XGraphicDevice >& ,
137 : : const geometry::IntegerSize2D& )
138 : : {
139 : 0 : return uno::Reference< rendering::XVolatileBitmap >();
140 : : }
141 : :
142 : 0 : uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap(
143 : : const uno::Reference< rendering::XGraphicDevice >& rDevice,
144 : : const geometry::IntegerSize2D& size )
145 : : {
146 : 0 : if( !mpOutDev )
147 : 0 : return uno::Reference< rendering::XBitmap >(); // we're disposed
148 : :
149 : : return uno::Reference< rendering::XBitmap >(
150 : : new CanvasBitmap( ::vcl::unotools::sizeFromIntegerSize2D(size),
151 : : true,
152 : : *rDevice.get(),
153 : 0 : mpOutDev ) );
154 : : }
155 : :
156 : 0 : uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap(
157 : : const uno::Reference< rendering::XGraphicDevice >& ,
158 : : const geometry::IntegerSize2D& )
159 : : {
160 : 0 : return uno::Reference< rendering::XVolatileBitmap >();
161 : : }
162 : :
163 : 0 : sal_Bool DeviceHelper::hasFullScreenMode()
164 : : {
165 : 0 : return false;
166 : : }
167 : :
168 : 0 : sal_Bool DeviceHelper::enterFullScreenMode( sal_Bool bEnter )
169 : : {
170 : : (void)bEnter;
171 : 0 : return false;
172 : : }
173 : :
174 : 0 : void DeviceHelper::disposing()
175 : : {
176 : : // release all references
177 : 0 : mpOutDev.reset();
178 : 0 : }
179 : :
180 : 0 : uno::Any DeviceHelper::isAccelerated() const
181 : : {
182 : 0 : return ::com::sun::star::uno::makeAny(false);
183 : : }
184 : :
185 : 0 : uno::Any DeviceHelper::getDeviceHandle() const
186 : : {
187 : 0 : if( !mpOutDev )
188 : 0 : return uno::Any();
189 : :
190 : : return uno::makeAny(
191 : 0 : reinterpret_cast< sal_Int64 >(&mpOutDev->getOutDev()) );
192 : : }
193 : :
194 : 0 : uno::Any DeviceHelper::getSurfaceHandle() const
195 : : {
196 : 0 : return getDeviceHandle();
197 : : }
198 : :
199 : : namespace
200 : : {
201 : : struct DeviceColorSpace: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>,
202 : : DeviceColorSpace>
203 : : {
204 : 0 : uno::Reference<rendering::XColorSpace> operator()()
205 : : {
206 : 0 : return vcl::unotools::createStandardColorSpace();
207 : : }
208 : : };
209 : : }
210 : :
211 : 0 : uno::Reference<rendering::XColorSpace> DeviceHelper::getColorSpace() const
212 : : {
213 : : // always the same
214 : 0 : return DeviceColorSpace::get();
215 : : }
216 : :
217 : 0 : void DeviceHelper::dumpScreenContent() const
218 : : {
219 : : static sal_Int32 nFilePostfixCount(0);
220 : :
221 : 0 : if( mpOutDev )
222 : : {
223 : 0 : rtl::OUString aFilename("dbg_frontbuffer");
224 : 0 : aFilename += rtl::OUString::valueOf(nFilePostfixCount);
225 : 0 : aFilename += rtl::OUString(".bmp");
226 : :
227 : 0 : SvFileStream aStream( aFilename, STREAM_STD_READWRITE );
228 : :
229 : 0 : const ::Point aEmptyPoint;
230 : 0 : OutputDevice& rOutDev = mpOutDev->getOutDev();
231 : 0 : bool bOldMap( rOutDev.IsMapModeEnabled() );
232 : 0 : rOutDev.EnableMapMode( sal_False );
233 : : aStream << rOutDev.GetBitmap(aEmptyPoint,
234 : 0 : rOutDev.GetOutputSizePixel());
235 : 0 : rOutDev.EnableMapMode( bOldMap );
236 : :
237 : 0 : ++nFilePostfixCount;
238 : : }
239 : 0 : }
240 : :
241 : 0 : }
242 : :
243 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|