LCOV - code coverage report
Current view: top level - include/canvas/base - graphicdevicebase.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 102 0.0 %
Date: 2014-04-14 Functions: 0 150 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10