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