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( ) throw (::com::sun::star::uno::RuntimeException) 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( ) throw (::com::sun::star::uno::RuntimeException) 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( ) throw (::com::sun::star::uno::RuntimeException) 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( ) throw (::com::sun::star::uno::RuntimeException) 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 ) throw (::com::sun::star::uno::RuntimeException) 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 ) throw (::com::sun::star::uno::RuntimeException) 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 ) throw (::com::sun::star::lang::IllegalArgumentException, 197 ::com::sun::star::uno::RuntimeException) 198 { 199 tools::verifyBitmapSize(size, 200 BOOST_CURRENT_FUNCTION, 201 static_cast< UnambiguousBaseType* >(this)); 202 203 MutexType aGuard( BaseType::m_aMutex ); 204 205 return maDeviceHelper.createCompatibleBitmap( this, size ); 206 } 207 createVolatileBitmap(const::com::sun::star::geometry::IntegerSize2D & size)208 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XVolatileBitmap > SAL_CALL createVolatileBitmap( const ::com::sun::star::geometry::IntegerSize2D& size ) throw (::com::sun::star::lang::IllegalArgumentException, 209 ::com::sun::star::uno::RuntimeException) 210 { 211 tools::verifyBitmapSize(size, 212 BOOST_CURRENT_FUNCTION, 213 static_cast< UnambiguousBaseType* >(this)); 214 215 MutexType aGuard( BaseType::m_aMutex ); 216 217 return maDeviceHelper.createVolatileBitmap( this, size ); 218 } 219 createCompatibleAlphaBitmap(const::com::sun::star::geometry::IntegerSize2D & size)220 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap > SAL_CALL createCompatibleAlphaBitmap( const ::com::sun::star::geometry::IntegerSize2D& size ) throw (::com::sun::star::lang::IllegalArgumentException, 221 ::com::sun::star::uno::RuntimeException) 222 { 223 tools::verifyBitmapSize(size, 224 BOOST_CURRENT_FUNCTION, 225 static_cast< UnambiguousBaseType* >(this)); 226 227 MutexType aGuard( BaseType::m_aMutex ); 228 229 return maDeviceHelper.createCompatibleAlphaBitmap( this, size ); 230 } 231 createVolatileAlphaBitmap(const::com::sun::star::geometry::IntegerSize2D & size)232 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XVolatileBitmap > SAL_CALL createVolatileAlphaBitmap( const ::com::sun::star::geometry::IntegerSize2D& size ) throw (::com::sun::star::lang::IllegalArgumentException, 233 ::com::sun::star::uno::RuntimeException) 234 { 235 tools::verifyBitmapSize(size, 236 BOOST_CURRENT_FUNCTION, 237 static_cast< UnambiguousBaseType* >(this)); 238 239 MutexType aGuard( BaseType::m_aMutex ); 240 241 return maDeviceHelper.createVolatileAlphaBitmap( this, size ); 242 } 243 getParametricPolyPolygonFactory()244 virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > SAL_CALL getParametricPolyPolygonFactory( ) throw (::com::sun::star::uno::RuntimeException) 245 { 246 return this; 247 } 248 hasFullScreenMode()249 virtual ::sal_Bool SAL_CALL hasFullScreenMode( ) throw (::com::sun::star::uno::RuntimeException) 250 { 251 MutexType aGuard( BaseType::m_aMutex ); 252 253 return maDeviceHelper.hasFullScreenMode(); 254 } 255 enterFullScreenMode(::sal_Bool bEnter)256 virtual ::sal_Bool SAL_CALL enterFullScreenMode( ::sal_Bool bEnter ) throw (::com::sun::star::uno::RuntimeException) 257 { 258 MutexType aGuard( BaseType::m_aMutex ); 259 260 return maDeviceHelper.enterFullScreenMode( bEnter ); 261 } 262 263 // XMultiServiceFactory createInstance(const::rtl::OUString & aServiceSpecifier)264 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance( const ::rtl::OUString& aServiceSpecifier ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) 265 { 266 return ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XParametricPolyPolygon2D >( 267 ParametricPolyPolygon::create(this, 268 aServiceSpecifier, 269 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >())); 270 } 271 createInstanceWithArguments(const::rtl::OUString & aServiceSpecifier,const::com::sun::star::uno::Sequence<::com::sun::star::uno::Any> & Arguments)272 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 ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) 273 { 274 return ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XParametricPolyPolygon2D >( 275 ParametricPolyPolygon::create(this, 276 aServiceSpecifier, 277 Arguments)); 278 } 279 getAvailableServiceNames()280 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames( ) throw (::com::sun::star::uno::RuntimeException) 281 { 282 return ParametricPolyPolygon::getAvailableServiceNames(); 283 } 284 285 286 // XUpdatable update()287 virtual void SAL_CALL update() throw (com::sun::star::uno::RuntimeException) 288 { 289 MutexType aGuard( BaseType::m_aMutex ); 290 291 if( mbDumpScreenContent ) 292 maDeviceHelper.dumpScreenContent(); 293 } 294 295 296 // XPropertySet getPropertySetInfo()297 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw (::com::sun::star::uno::RuntimeException) 298 { 299 MutexType aGuard( BaseType::m_aMutex ); 300 return maPropHelper.getPropertySetInfo(); 301 } 302 setPropertyValue(const::rtl::OUString & aPropertyName,const::com::sun::star::uno::Any & aValue)303 virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, 304 const ::com::sun::star::uno::Any& aValue ) throw (::com::sun::star::beans::UnknownPropertyException, 305 ::com::sun::star::beans::PropertyVetoException, 306 ::com::sun::star::lang::IllegalArgumentException, 307 ::com::sun::star::lang::WrappedTargetException, 308 ::com::sun::star::uno::RuntimeException) 309 { 310 MutexType aGuard( BaseType::m_aMutex ); 311 maPropHelper.setPropertyValue( aPropertyName, aValue ); 312 } 313 getPropertyValue(const::rtl::OUString & aPropertyName)314 virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& aPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, 315 ::com::sun::star::lang::WrappedTargetException, 316 ::com::sun::star::uno::RuntimeException) 317 { 318 MutexType aGuard( BaseType::m_aMutex ); 319 return maPropHelper.getPropertyValue( aPropertyName ); 320 } 321 addPropertyChangeListener(const::rtl::OUString & aPropertyName,const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertyChangeListener> & xListener)322 virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, 323 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw (::com::sun::star::beans::UnknownPropertyException, 324 ::com::sun::star::lang::WrappedTargetException, 325 ::com::sun::star::uno::RuntimeException) 326 { 327 MutexType aGuard( BaseType::m_aMutex ); 328 maPropHelper.addPropertyChangeListener( aPropertyName, 329 xListener ); 330 } 331 removePropertyChangeListener(const::rtl::OUString & aPropertyName,const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertyChangeListener> & xListener)332 virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, 333 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw (::com::sun::star::beans::UnknownPropertyException, 334 ::com::sun::star::lang::WrappedTargetException, 335 ::com::sun::star::uno::RuntimeException) 336 { 337 MutexType aGuard( BaseType::m_aMutex ); 338 maPropHelper.removePropertyChangeListener( aPropertyName, 339 xListener ); 340 } 341 addVetoableChangeListener(const::rtl::OUString & aPropertyName,const::com::sun::star::uno::Reference<::com::sun::star::beans::XVetoableChangeListener> & xListener)342 virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& aPropertyName, 343 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& xListener ) throw (::com::sun::star::beans::UnknownPropertyException, 344 ::com::sun::star::lang::WrappedTargetException, 345 ::com::sun::star::uno::RuntimeException) 346 { 347 MutexType aGuard( BaseType::m_aMutex ); 348 maPropHelper.addVetoableChangeListener( aPropertyName, 349 xListener ); 350 } 351 removeVetoableChangeListener(const::rtl::OUString & aPropertyName,const::com::sun::star::uno::Reference<::com::sun::star::beans::XVetoableChangeListener> & xListener)352 virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& aPropertyName, 353 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& xListener ) throw (::com::sun::star::beans::UnknownPropertyException, 354 ::com::sun::star::lang::WrappedTargetException, 355 ::com::sun::star::uno::RuntimeException) 356 { 357 MutexType aGuard( BaseType::m_aMutex ); 358 maPropHelper.removeVetoableChangeListener( aPropertyName, 359 xListener ); 360 } 361 362 protected: ~GraphicDeviceBase()363 ~GraphicDeviceBase() {} // we're a ref-counted UNO class. _We_ destroy ourselves. 364 getDumpScreenContent() const365 ::com::sun::star::uno::Any getDumpScreenContent() const 366 { 367 return ::com::sun::star::uno::makeAny( mbDumpScreenContent ); 368 } 369 setDumpScreenContent(const::com::sun::star::uno::Any & rAny)370 void setDumpScreenContent( const ::com::sun::star::uno::Any& rAny ) 371 { 372 // TODO(Q1): this was mbDumpScreenContent = 373 // rAny.get<bool>(), only that gcc3.3 wouldn't eat it 374 rAny >>= mbDumpScreenContent; 375 } 376 377 DeviceHelperType maDeviceHelper; 378 PropertySetHelper maPropHelper; 379 bool mbDumpScreenContent; 380 381 private: 382 GraphicDeviceBase( const GraphicDeviceBase& ); 383 GraphicDeviceBase& operator=( const GraphicDeviceBase& ); 384 }; 385 } 386 387 #endif /* INCLUDED_CANVAS_GRAPHICDEVICEBASE_HXX */ 388