1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_canvas.hxx" 26 27 #include <canvas/debug.hxx> 28 #include <tools/diagnose_ex.h> 29 #include <canvas/canvastools.hxx> 30 31 #include <rtl/instance.hxx> 32 #include <toolkit/helper/vclunohelper.hxx> 33 #include <vcl/canvastools.hxx> 34 #include <basegfx/tools/canvastools.hxx> 35 #include <basegfx/tools/unopolypolygon.hxx> 36 37 #include "devicehelper.hxx" 38 #include "spritecanvas.hxx" 39 #include "spritecanvashelper.hxx" 40 #include "canvasbitmap.hxx" 41 42 43 using namespace ::com::sun::star; 44 45 namespace vclcanvas 46 { 47 DeviceHelper::DeviceHelper() : 48 mpOutDev() 49 {} 50 51 void DeviceHelper::init( const OutDevProviderSharedPtr& rOutDev ) 52 { 53 mpOutDev = rOutDev; 54 } 55 56 geometry::RealSize2D DeviceHelper::getPhysicalResolution() 57 { 58 if( !mpOutDev ) 59 return ::canvas::tools::createInfiniteSize2D(); // we're disposed 60 61 // Map a one-by-one millimeter box to pixel 62 OutputDevice& rOutDev = mpOutDev->getOutDev(); 63 const MapMode aOldMapMode( rOutDev.GetMapMode() ); 64 rOutDev.SetMapMode( MapMode(MAP_MM) ); 65 const Size aPixelSize( rOutDev.LogicToPixel(Size(1,1)) ); 66 rOutDev.SetMapMode( aOldMapMode ); 67 68 return ::vcl::unotools::size2DFromSize( aPixelSize ); 69 } 70 71 geometry::RealSize2D DeviceHelper::getPhysicalSize() 72 { 73 if( !mpOutDev ) 74 return ::canvas::tools::createInfiniteSize2D(); // we're disposed 75 76 // Map the pixel dimensions of the output window to millimeter 77 OutputDevice& rOutDev = mpOutDev->getOutDev(); 78 const MapMode aOldMapMode( rOutDev.GetMapMode() ); 79 rOutDev.SetMapMode( MapMode(MAP_MM) ); 80 const Size aLogSize( rOutDev.PixelToLogic(rOutDev.GetOutputSizePixel()) ); 81 rOutDev.SetMapMode( aOldMapMode ); 82 83 return ::vcl::unotools::size2DFromSize( aLogSize ); 84 } 85 86 uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon( 87 const uno::Reference< rendering::XGraphicDevice >& , 88 const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points ) 89 { 90 uno::Reference< rendering::XLinePolyPolygon2D > xPoly; 91 if( !mpOutDev ) 92 return xPoly; // we're disposed 93 94 xPoly.set( new ::basegfx::unotools::UnoPolyPolygon( 95 ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) ); 96 // vcl only handles even_odd polygons 97 xPoly->setFillRule(rendering::FillRule_EVEN_ODD); 98 99 return xPoly; 100 } 101 102 uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon( 103 const uno::Reference< rendering::XGraphicDevice >& , 104 const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points ) 105 { 106 uno::Reference< rendering::XBezierPolyPolygon2D > xPoly; 107 if( !mpOutDev ) 108 return xPoly; // we're disposed 109 110 xPoly.set( new ::basegfx::unotools::UnoPolyPolygon( 111 ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) ); 112 // vcl only handles even_odd polygons 113 xPoly->setFillRule(rendering::FillRule_EVEN_ODD); 114 115 return xPoly; 116 } 117 118 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap( 119 const uno::Reference< rendering::XGraphicDevice >& rDevice, 120 const geometry::IntegerSize2D& size ) 121 { 122 if( !mpOutDev ) 123 return uno::Reference< rendering::XBitmap >(); // we're disposed 124 125 return uno::Reference< rendering::XBitmap >( 126 new CanvasBitmap( ::vcl::unotools::sizeFromIntegerSize2D(size), 127 false, 128 *rDevice.get(), 129 mpOutDev ) ); 130 } 131 132 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap( 133 const uno::Reference< rendering::XGraphicDevice >& , 134 const geometry::IntegerSize2D& ) 135 { 136 return uno::Reference< rendering::XVolatileBitmap >(); 137 } 138 139 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap( 140 const uno::Reference< rendering::XGraphicDevice >& rDevice, 141 const geometry::IntegerSize2D& size ) 142 { 143 if( !mpOutDev ) 144 return uno::Reference< rendering::XBitmap >(); // we're disposed 145 146 return uno::Reference< rendering::XBitmap >( 147 new CanvasBitmap( ::vcl::unotools::sizeFromIntegerSize2D(size), 148 true, 149 *rDevice.get(), 150 mpOutDev ) ); 151 } 152 153 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap( 154 const uno::Reference< rendering::XGraphicDevice >& , 155 const geometry::IntegerSize2D& ) 156 { 157 return uno::Reference< rendering::XVolatileBitmap >(); 158 } 159 160 sal_Bool DeviceHelper::hasFullScreenMode() 161 { 162 return false; 163 } 164 165 sal_Bool DeviceHelper::enterFullScreenMode( sal_Bool bEnter ) 166 { 167 (void)bEnter; 168 return false; 169 } 170 171 void DeviceHelper::disposing() 172 { 173 // release all references 174 mpOutDev.reset(); 175 } 176 177 uno::Any DeviceHelper::isAccelerated() const 178 { 179 return ::com::sun::star::uno::makeAny(false); 180 } 181 182 uno::Any DeviceHelper::getDeviceHandle() const 183 { 184 if( !mpOutDev ) 185 return uno::Any(); 186 187 return uno::makeAny( 188 reinterpret_cast< sal_Int64 >(&mpOutDev->getOutDev()) ); 189 } 190 191 uno::Any DeviceHelper::getSurfaceHandle() const 192 { 193 return getDeviceHandle(); 194 } 195 196 namespace 197 { 198 struct DeviceColorSpace: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>, 199 DeviceColorSpace> 200 { 201 uno::Reference<rendering::XColorSpace> operator()() 202 { 203 return vcl::unotools::createStandardColorSpace(); 204 } 205 }; 206 } 207 208 uno::Reference<rendering::XColorSpace> DeviceHelper::getColorSpace() const 209 { 210 // always the same 211 return DeviceColorSpace::get(); 212 } 213 214 void DeviceHelper::dumpScreenContent() const 215 { 216 static sal_uInt32 nFilePostfixCount(0); 217 218 if( mpOutDev ) 219 { 220 String aFilename( String::CreateFromAscii("dbg_frontbuffer") ); 221 aFilename += String::CreateFromInt32(nFilePostfixCount); 222 aFilename += String::CreateFromAscii(".bmp"); 223 224 SvFileStream aStream( aFilename, STREAM_STD_READWRITE ); 225 226 const ::Point aEmptyPoint; 227 OutputDevice& rOutDev = mpOutDev->getOutDev(); 228 bool bOldMap( rOutDev.IsMapModeEnabled() ); 229 rOutDev.EnableMapMode( sal_False ); 230 aStream << rOutDev.GetBitmap(aEmptyPoint, 231 rOutDev.GetOutputSizePixel()); 232 rOutDev.EnableMapMode( bOldMap ); 233 234 ++nFilePostfixCount; 235 } 236 } 237 238 } 239