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