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 <ctype.h> // don't ask. msdev breaks otherwise... 28 #include <vcl/window.hxx> 29 #include <vcl/canvastools.hxx> 30 #include <canvas/debug.hxx> 31 #include <canvas/verbosetrace.hxx> 32 #include <canvas/canvastools.hxx> 33 #include <tools/diagnose_ex.h> 34 35 #include <osl/mutex.hxx> 36 #include <cppuhelper/compbase1.hxx> 37 38 #include <com/sun/star/lang/NoSupportException.hpp> 39 #include <toolkit/helper/vclunohelper.hxx> 40 #include <basegfx/tools/canvastools.hxx> 41 #include "dx_linepolypolygon.hxx" 42 #include "dx_spritecanvas.hxx" 43 #include "dx_canvasbitmap.hxx" 44 #include "dx_devicehelper.hxx" 45 46 47 #undef WB_LEFT 48 #undef WB_RIGHT 49 #include "dx_winstuff.hxx" 50 51 52 #include <vcl/sysdata.hxx> 53 54 using namespace ::com::sun::star; 55 56 namespace dxcanvas 57 { DeviceHelper()58 DeviceHelper::DeviceHelper() : 59 mpDevice( NULL ), 60 mnHDC(0) 61 { 62 } 63 init(HDC hdc,rendering::XGraphicDevice & rDevice)64 void DeviceHelper::init( HDC hdc, 65 rendering::XGraphicDevice& rDevice ) 66 { 67 mnHDC = hdc; 68 mpDevice = &rDevice; 69 } 70 disposing()71 void DeviceHelper::disposing() 72 { 73 // release all references 74 mnHDC = 0; 75 mpDevice = NULL; 76 } 77 getPhysicalResolution()78 geometry::RealSize2D DeviceHelper::getPhysicalResolution() 79 { 80 if( !mpDevice ) 81 return ::canvas::tools::createInfiniteSize2D(); // we're disposed 82 83 HDC hDC = getHDC(); 84 ENSURE_OR_THROW( hDC, 85 "DeviceHelper::getPhysicalResolution(): cannot retrieve HDC from window" ); 86 87 const int nHorzRes( GetDeviceCaps( hDC, 88 LOGPIXELSX ) ); 89 const int nVertRes( GetDeviceCaps( hDC, 90 LOGPIXELSY ) ); 91 92 return geometry::RealSize2D( nHorzRes*25.4, 93 nVertRes*25.4 ); 94 } 95 getPhysicalSize()96 geometry::RealSize2D DeviceHelper::getPhysicalSize() 97 { 98 if( !mpDevice ) 99 return ::canvas::tools::createInfiniteSize2D(); // we're disposed 100 101 HDC hDC=getHDC(); 102 ENSURE_OR_THROW( hDC, 103 "DeviceHelper::getPhysicalSize(): cannot retrieve HDC from window" ); 104 105 const int nHorzSize( GetDeviceCaps( hDC, 106 HORZSIZE ) ); 107 const int nVertSize( GetDeviceCaps( hDC, 108 VERTSIZE ) ); 109 110 return geometry::RealSize2D( nHorzSize, 111 nVertSize ); 112 } 113 createCompatibleLinePolyPolygon(const uno::Reference<rendering::XGraphicDevice> &,const uno::Sequence<uno::Sequence<geometry::RealPoint2D>> & points)114 uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon( 115 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/, 116 const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points ) 117 { 118 if( !mpDevice ) 119 return uno::Reference< rendering::XLinePolyPolygon2D >(); // we're disposed 120 121 return uno::Reference< rendering::XLinePolyPolygon2D >( 122 new LinePolyPolygon( 123 ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) ); 124 } 125 createCompatibleBezierPolyPolygon(const uno::Reference<rendering::XGraphicDevice> &,const uno::Sequence<uno::Sequence<geometry::RealBezierSegment2D>> & points)126 uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon( 127 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/, 128 const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points ) 129 { 130 if( !mpDevice ) 131 return uno::Reference< rendering::XBezierPolyPolygon2D >(); // we're disposed 132 133 return uno::Reference< rendering::XBezierPolyPolygon2D >( 134 new LinePolyPolygon( 135 ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) ); 136 } 137 createCompatibleBitmap(const uno::Reference<rendering::XGraphicDevice> &,const geometry::IntegerSize2D & size)138 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap( 139 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/, 140 const geometry::IntegerSize2D& size ) 141 { 142 if( !mpDevice ) 143 return uno::Reference< rendering::XBitmap >(); // we're disposed 144 145 DXBitmapSharedPtr pBitmap( 146 new DXBitmap( 147 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size), 148 false)); 149 150 // create a 24bit RGB system memory surface 151 return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,mpDevice)); 152 } 153 createVolatileBitmap(const uno::Reference<rendering::XGraphicDevice> &,const geometry::IntegerSize2D &)154 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap( 155 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/, 156 const geometry::IntegerSize2D& /*size*/ ) 157 { 158 return uno::Reference< rendering::XVolatileBitmap >(); 159 } 160 createCompatibleAlphaBitmap(const uno::Reference<rendering::XGraphicDevice> &,const geometry::IntegerSize2D & size)161 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap( 162 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/, 163 const geometry::IntegerSize2D& size ) 164 { 165 if( !mpDevice ) 166 return uno::Reference< rendering::XBitmap >(); // we're disposed 167 168 DXBitmapSharedPtr pBitmap( 169 new DXBitmap( 170 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size), 171 true)); 172 173 // create a 32bit ARGB system memory surface 174 return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,mpDevice)); 175 } 176 createVolatileAlphaBitmap(const uno::Reference<rendering::XGraphicDevice> &,const geometry::IntegerSize2D &)177 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap( 178 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/, 179 const geometry::IntegerSize2D& /*size*/ ) 180 { 181 return uno::Reference< rendering::XVolatileBitmap >(); 182 } 183 hasFullScreenMode()184 sal_Bool DeviceHelper::hasFullScreenMode() 185 { 186 return false; 187 } 188 enterFullScreenMode(sal_Bool)189 sal_Bool DeviceHelper::enterFullScreenMode( sal_Bool /*bEnter*/ ) 190 { 191 return false; 192 } 193 isAccelerated() const194 uno::Any DeviceHelper::isAccelerated() const 195 { 196 return ::com::sun::star::uno::makeAny(false); 197 } 198 getDeviceHandle() const199 uno::Any DeviceHelper::getDeviceHandle() const 200 { 201 HDC hdc( getHDC() ); 202 if( hdc ) 203 return uno::makeAny( reinterpret_cast< sal_Int64 >(hdc) ); 204 else 205 return uno::Any(); 206 } 207 getSurfaceHandle() const208 uno::Any DeviceHelper::getSurfaceHandle() const 209 { 210 // TODO(F1): expose DirectDraw object 211 //return mpBackBuffer->getBitmap().get(); 212 return uno::Any(); 213 } 214 215 namespace 216 { 217 struct DeviceColorSpace: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>, 218 DeviceColorSpace> 219 { operator ()dxcanvas::__anond0c8ad670111::DeviceColorSpace220 uno::Reference<rendering::XColorSpace> operator()() 221 { 222 return vcl::unotools::createStandardColorSpace(); 223 } 224 }; 225 } 226 getColorSpace() const227 uno::Reference<rendering::XColorSpace> DeviceHelper::getColorSpace() const 228 { 229 // always the same 230 return DeviceColorSpace::get(); 231 } 232 } 233