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 #ifndef INCLUDED_CANVAS_GRAPHICDEVICEBASE_HXX 25 #define INCLUDED_CANVAS_GRAPHICDEVICEBASE_HXX 26 27 #include <rtl/ref.hxx> 28 #include <com/sun/star/lang/XServiceInfo.hpp> 29 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 30 #include <com/sun/star/beans/XPropertySet.hpp> 31 #include <com/sun/star/util/XUpdatable.hpp> 32 #include <com/sun/star/rendering/XGraphicDevice.hpp> 33 #include <com/sun/star/rendering/XColorSpace.hpp> 34 35 #include <canvas/parametricpolypolygon.hxx> 36 #include <canvas/propertysethelper.hxx> 37 38 39 /* Definition of GraphicDeviceBase class */ 40 41 namespace canvas 42 { 43 /** Helper template base class for XGraphicDevice implementations. 44 45 This base class provides partial implementations of the 46 XGraphicDevice-related interface, such as XColorSpace. 47 48 This template basically interposes itself between the full 49 interface you implement (i.e. not restricted to XGraphicDevice 50 etc.). The problem with UNO partial interface implementation 51 actually is, that you cannot do it the plain way, since 52 deriving from a common base subclass always introduces the 53 whole set of pure virtuals, that your baseclass helper just 54 overrided) and your implementation class. You then only have 55 to implement the functionality <em>besides</em> 56 XGraphicDevice. If you want to support the optional debug 57 XUpdatable interface, also add that to the base classes 58 (client code will call the corresponding update() method, 59 whenever a burst of animations is over). 60 61 <pre> 62 Example: 63 typedef ::cppu::WeakComponentImplHelper5< ::com::sun::star::rendering::XGraphicDevice, 64 ::com::sun::star::rendering::XColorSpace, 65 ::com::sun::star::rendering::XPropertySet, 66 ::com::sun::star::lang::XServiceInfo, 67 ::com::sun::star::lang::XServiceName > GraphicDeviceBase_Base; 68 typedef ::canvas::internal::GraphicDeviceBase< GraphicDeviceBase, DeviceHelper > ExampleDevice_Base; 69 70 class ExampleDevice : public ExampleDevice_Base 71 { 72 }; 73 </pre> 74 75 @tpl Base 76 Base class to use, most probably one of the 77 WeakComponentImplHelperN templates with the appropriate 78 interfaces. At least XGraphicDevice should be among them (why else 79 would you use this template, then?). Base class must have an 80 Base( const Mutex& ) constructor (like the 81 WeakComponentImplHelperN templates have). As the very least, 82 the base class must be derived from uno::XInterface, as some 83 error reporting mechanisms rely on that. 84 85 @tpl DeviceHelper 86 Device helper implementation for the backend in question. This 87 object will be held as a member of this template class, and 88 basically gets forwarded all XGraphicDevice API calls that 89 could not be handled generically. 90 91 @tpl Mutex 92 Lock strategy to use. Defaults to using the 93 BaseMutexHelper-provided lock. Every time one of the methods is 94 entered, an object of type Mutex is created with m_aMutex as 95 the sole parameter, and destroyed again when the method scope 96 is left. 97 98 @tpl UnambiguousBase 99 Optional unambiguous base class for XInterface of Base. It's 100 sometimes necessary to specify this parameter, e.g. if Base 101 derives from multiple UNO interface (were each provides its 102 own version of XInterface, making the conversion ambiguous) 103 */ 104 template< class Base, 105 class DeviceHelper, 106 class Mutex=::osl::MutexGuard, 107 class UnambiguousBase=::com::sun::star::uno::XInterface > class GraphicDeviceBase : 108 public Base 109 { 110 public: 111 typedef Base BaseType; 112 typedef DeviceHelper DeviceHelperType; 113 typedef Mutex MutexType; 114 typedef UnambiguousBase UnambiguousBaseType; 115 typedef GraphicDeviceBase ThisType; 116 117 typedef ::rtl::Reference< GraphicDeviceBase > Reference; 118 GraphicDeviceBase()119 GraphicDeviceBase() : 120 maDeviceHelper(), 121 maPropHelper(), 122 mbDumpScreenContent(false) 123 { 124 maPropHelper.initProperties( PropertySetHelper::MakeMap 125 ("HardwareAcceleration", 126 boost::bind(&DeviceHelper::isAccelerated, 127 boost::ref(maDeviceHelper))) 128 ("DeviceHandle", 129 boost::bind(&DeviceHelper::getDeviceHandle, 130 boost::ref(maDeviceHelper))) 131 ("SurfaceHandle", 132 boost::bind(&DeviceHelper::getSurfaceHandle, 133 boost::ref(maDeviceHelper))) 134 ("DumpScreenContent", 135 boost::bind(&ThisType::getDumpScreenContent, 136 this), 137 boost::bind(&ThisType::setDumpScreenContent, 138 this, 139 _1))); 140 } 141 142 #if defined __SUNPRO_CC 143 using Base::disposing; 144 #endif disposing()145 virtual void SAL_CALL disposing() 146 { 147 MutexType aGuard( BaseType::m_aMutex ); 148 149 maDeviceHelper.disposing(); 150 151 // pass on to base class 152 cppu::WeakComponentImplHelperBase::disposing(); 153 } 154 155 // XGraphicDevice getBufferController()156 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBufferController > SAL_CALL getBufferController( ) 157 { 158 return ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBufferController >(); 159 } 160 getDeviceColorSpace()161 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XColorSpace > SAL_CALL getDeviceColorSpace( ) 162 { 163 MutexType aGuard( BaseType::m_aMutex ); 164 165 return maDeviceHelper.getColorSpace(); 166 } 167 getPhysicalResolution()168 virtual ::com::sun::star::geometry::RealSize2D SAL_CALL getPhysicalResolution( ) 169 { 170 MutexType aGuard( BaseType::m_aMutex ); 171 172 return maDeviceHelper.getPhysicalResolution(); 173 } 174 getPhysicalSize()175 virtual ::com::sun::star::geometry::RealSize2D SAL_CALL getPhysicalSize( ) 176 { 177 MutexType aGuard( BaseType::m_aMutex ); 178 179 return maDeviceHelper.getPhysicalSize(); 180 } 181 createCompatibleLinePolyPolygon(const::com::sun::star::uno::Sequence<::com::sun::star::uno::Sequence<::com::sun::star::geometry::RealPoint2D>> & points)182 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XLinePolyPolygon2D > SAL_CALL createCompatibleLinePolyPolygon( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealPoint2D > >& points ) 183 { 184 MutexType aGuard( BaseType::m_aMutex ); 185 186 return maDeviceHelper.createCompatibleLinePolyPolygon( this, points ); 187 } 188 createCompatibleBezierPolyPolygon(const::com::sun::star::uno::Sequence<::com::sun::star::uno::Sequence<::com::sun::star::geometry::RealBezierSegment2D>> & points)189 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBezierPolyPolygon2D > SAL_CALL createCompatibleBezierPolyPolygon( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealBezierSegment2D > >& points ) 190 { 191 MutexType aGuard( BaseType::m_aMutex ); 192 193 return maDeviceHelper.createCompatibleBezierPolyPolygon( this, points ); 194 } 195 createCompatibleBitmap(const::com::sun::star::geometry::IntegerSize2D & size)196 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap > SAL_CALL createCompatibleBitmap( const ::com::sun::star::geometry::IntegerSize2D& size ) 197 { 198 tools::verifyBitmapSize(size, 199 BOOST_CURRENT_FUNCTION, 200 static_cast< UnambiguousBaseType* >(this)); 201 202 MutexType aGuard( BaseType::m_aMutex ); 203 204 return maDeviceHelper.createCompatibleBitmap( this, size ); 205 } 206 createVolatileBitmap(const::com::sun::star::geometry::IntegerSize2D & size)207 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XVolatileBitmap > SAL_CALL createVolatileBitmap( const ::com::sun::star::geometry::IntegerSize2D& size ) 208 { 209 tools::verifyBitmapSize(size, 210 BOOST_CURRENT_FUNCTION, 211 static_cast< UnambiguousBaseType* >(this)); 212 213 MutexType aGuard( BaseType::m_aMutex ); 214 215 return maDeviceHelper.createVolatileBitmap( this, size ); 216 } 217 createCompatibleAlphaBitmap(const::com::sun::star::geometry::IntegerSize2D & size)218 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap > SAL_CALL createCompatibleAlphaBitmap( const ::com::sun::star::geometry::IntegerSize2D& size ) 219 { 220 tools::verifyBitmapSize(size, 221 BOOST_CURRENT_FUNCTION, 222 static_cast< UnambiguousBaseType* >(this)); 223 224 MutexType aGuard( BaseType::m_aMutex ); 225 226 return maDeviceHelper.createCompatibleAlphaBitmap( this, size ); 227 } 228 createVolatileAlphaBitmap(const::com::sun::star::geometry::IntegerSize2D & size)229 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XVolatileBitmap > SAL_CALL createVolatileAlphaBitmap( const ::com::sun::star::geometry::IntegerSize2D& size ) 230 { 231 tools::verifyBitmapSize(size, 232 BOOST_CURRENT_FUNCTION, 233 static_cast< UnambiguousBaseType* >(this)); 234 235 MutexType aGuard( BaseType::m_aMutex ); 236 237 return maDeviceHelper.createVolatileAlphaBitmap( this, size ); 238 } 239 getParametricPolyPolygonFactory()240 virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > SAL_CALL getParametricPolyPolygonFactory( ) 241 { 242 return this; 243 } 244 hasFullScreenMode()245 virtual ::sal_Bool SAL_CALL hasFullScreenMode( ) 246 { 247 MutexType aGuard( BaseType::m_aMutex ); 248 249 return maDeviceHelper.hasFullScreenMode(); 250 } 251 enterFullScreenMode(::sal_Bool bEnter)252 virtual ::sal_Bool SAL_CALL enterFullScreenMode( ::sal_Bool bEnter ) 253 { 254 MutexType aGuard( BaseType::m_aMutex ); 255 256 return maDeviceHelper.enterFullScreenMode( bEnter ); 257 } 258 259 // XMultiServiceFactory createInstance(const::rtl::OUString & aServiceSpecifier)260 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance( const ::rtl::OUString& aServiceSpecifier ) 261 { 262 return ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XParametricPolyPolygon2D >( 263 ParametricPolyPolygon::create(this, 264 aServiceSpecifier, 265 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >())); 266 } 267 createInstanceWithArguments(const::rtl::OUString & aServiceSpecifier,const::com::sun::star::uno::Sequence<::com::sun::star::uno::Any> & Arguments)268 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::rtl::OUString& aServiceSpecifier, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Arguments ) 269 { 270 return ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XParametricPolyPolygon2D >( 271 ParametricPolyPolygon::create(this, 272 aServiceSpecifier, 273 Arguments)); 274 } 275 getAvailableServiceNames()276 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames( ) 277 { 278 return ParametricPolyPolygon::getAvailableServiceNames(); 279 } 280 281 282 // XUpdatable update()283 virtual void SAL_CALL update() 284 { 285 MutexType aGuard( BaseType::m_aMutex ); 286 287 if( mbDumpScreenContent ) 288 maDeviceHelper.dumpScreenContent(); 289 } 290 291 292 // XPropertySet getPropertySetInfo()293 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() 294 { 295 MutexType aGuard( BaseType::m_aMutex ); 296 return maPropHelper.getPropertySetInfo(); 297 } 298 setPropertyValue(const::rtl::OUString & aPropertyName,const::com::sun::star::uno::Any & aValue)299 virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, 300 const ::com::sun::star::uno::Any& aValue ) 301 { 302 MutexType aGuard( BaseType::m_aMutex ); 303 maPropHelper.setPropertyValue( aPropertyName, aValue ); 304 } 305 getPropertyValue(const::rtl::OUString & aPropertyName)306 virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& aPropertyName ) 307 { 308 MutexType aGuard( BaseType::m_aMutex ); 309 return maPropHelper.getPropertyValue( aPropertyName ); 310 } 311 addPropertyChangeListener(const::rtl::OUString & aPropertyName,const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertyChangeListener> & xListener)312 virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, 313 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) 314 { 315 MutexType aGuard( BaseType::m_aMutex ); 316 maPropHelper.addPropertyChangeListener( aPropertyName, 317 xListener ); 318 } 319 removePropertyChangeListener(const::rtl::OUString & aPropertyName,const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertyChangeListener> & xListener)320 virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, 321 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) 322 { 323 MutexType aGuard( BaseType::m_aMutex ); 324 maPropHelper.removePropertyChangeListener( aPropertyName, 325 xListener ); 326 } 327 addVetoableChangeListener(const::rtl::OUString & aPropertyName,const::com::sun::star::uno::Reference<::com::sun::star::beans::XVetoableChangeListener> & xListener)328 virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& aPropertyName, 329 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& xListener ) 330 { 331 MutexType aGuard( BaseType::m_aMutex ); 332 maPropHelper.addVetoableChangeListener( aPropertyName, 333 xListener ); 334 } 335 removeVetoableChangeListener(const::rtl::OUString & aPropertyName,const::com::sun::star::uno::Reference<::com::sun::star::beans::XVetoableChangeListener> & xListener)336 virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& aPropertyName, 337 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& xListener ) 338 { 339 MutexType aGuard( BaseType::m_aMutex ); 340 maPropHelper.removeVetoableChangeListener( aPropertyName, 341 xListener ); 342 } 343 344 protected: ~GraphicDeviceBase()345 ~GraphicDeviceBase() {} // we're a ref-counted UNO class. _We_ destroy ourselves. 346 getDumpScreenContent() const347 ::com::sun::star::uno::Any getDumpScreenContent() const 348 { 349 return ::com::sun::star::uno::makeAny( mbDumpScreenContent ); 350 } 351 setDumpScreenContent(const::com::sun::star::uno::Any & rAny)352 void setDumpScreenContent( const ::com::sun::star::uno::Any& rAny ) 353 { 354 // TODO(Q1): this was mbDumpScreenContent = 355 // rAny.get<bool>(), only that gcc3.3 wouldn't eat it 356 rAny >>= mbDumpScreenContent; 357 } 358 359 DeviceHelperType maDeviceHelper; 360 PropertySetHelper maPropHelper; 361 bool mbDumpScreenContent; 362 363 private: 364 GraphicDeviceBase( const GraphicDeviceBase& ); 365 GraphicDeviceBase& operator=( const GraphicDeviceBase& ); 366 }; 367 } 368 369 #endif /* INCLUDED_CANVAS_GRAPHICDEVICEBASE_HXX */ 370