LCOV - code coverage report
Current view: top level - include/canvas/base - graphicdevicebase.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 25 94 26.6 %
Date: 2015-06-13 12:38:46 Functions: 7 150 4.7 %
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< css::rendering::XGraphicDevice,
      61             :                                                   css::rendering::XColorSpace,
      62             :                                                   css::rendering::XPropertySet,
      63             :                                                   css::lang::XServiceInfo,
      64             :                                                   css::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. Every time 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=css::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           3 :         GraphicDeviceBase() :
     117             :             maDeviceHelper(),
     118             :             maPropHelper(),
     119           3 :             mbDumpScreenContent(false)
     120             :         {
     121           3 :             maPropHelper.initProperties( PropertySetHelper::MakeMap
     122             :                                          ("HardwareAcceleration",
     123             :                                           boost::bind(&DeviceHelper::isAccelerated,
     124             :                                                       boost::ref(maDeviceHelper)))
     125             :                                          ("DeviceHandle",
     126             :                                           boost::bind(&DeviceHelper::getDeviceHandle,
     127           6 :                                                       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           3 :         }
     138             : 
     139           3 :         virtual void disposeThis() SAL_OVERRIDE
     140             :         {
     141           3 :             MutexType aGuard( BaseType::m_aMutex );
     142             : 
     143           3 :             maDeviceHelper.disposing();
     144             : 
     145             :             // pass on to base class
     146           3 :             BaseType::disposeThis();
     147           3 :         }
     148             : 
     149             :         // XGraphicDevice
     150           0 :         virtual css::uno::Reference< css::rendering::XBufferController > SAL_CALL getBufferController(  ) throw (css::uno::RuntimeException) SAL_OVERRIDE
     151             :         {
     152           0 :             return css::uno::Reference< css::rendering::XBufferController >();
     153             :         }
     154             : 
     155          10 :         virtual css::uno::Reference< css::rendering::XColorSpace > SAL_CALL getDeviceColorSpace(  ) throw (css::uno::RuntimeException) SAL_OVERRIDE
     156             :         {
     157          10 :             MutexType aGuard( BaseType::m_aMutex );
     158             : 
     159          10 :             return maDeviceHelper.getColorSpace();
     160             :         }
     161             : 
     162           0 :         virtual css::geometry::RealSize2D SAL_CALL getPhysicalResolution() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     163             :         {
     164           0 :             MutexType aGuard( BaseType::m_aMutex );
     165             : 
     166           0 :             return maDeviceHelper.getPhysicalResolution();
     167             :         }
     168             : 
     169           0 :         virtual css::geometry::RealSize2D SAL_CALL getPhysicalSize() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     170             :         {
     171           0 :             MutexType aGuard( BaseType::m_aMutex );
     172             : 
     173           0 :             return maDeviceHelper.getPhysicalSize();
     174             :         }
     175             : 
     176          12 :         virtual css::uno::Reference< css::rendering::XLinePolyPolygon2D > SAL_CALL createCompatibleLinePolyPolygon( const css::uno::Sequence< css::uno::Sequence< css::geometry::RealPoint2D > >& points ) throw (css::uno::RuntimeException) SAL_OVERRIDE
     177             :         {
     178          12 :             MutexType aGuard( BaseType::m_aMutex );
     179             : 
     180          12 :             return maDeviceHelper.createCompatibleLinePolyPolygon( this, points );
     181             :         }
     182             : 
     183           4 :         virtual css::uno::Reference< css::rendering::XBezierPolyPolygon2D > SAL_CALL createCompatibleBezierPolyPolygon( const css::uno::Sequence< css::uno::Sequence< css::geometry::RealBezierSegment2D > >& points ) throw (css::uno::RuntimeException) SAL_OVERRIDE
     184             :         {
     185           4 :             MutexType aGuard( BaseType::m_aMutex );
     186             : 
     187           4 :             return maDeviceHelper.createCompatibleBezierPolyPolygon( this, points );
     188             :         }
     189             : 
     190           0 :         virtual css::uno::Reference< css::rendering::XBitmap > SAL_CALL createCompatibleBitmap( const css::geometry::IntegerSize2D& size )
     191             :             throw (css::lang::IllegalArgumentException,
     192             :                    css::uno::RuntimeException,
     193             :                    std::exception) SAL_OVERRIDE
     194             :         {
     195           0 :             tools::verifyBitmapSize(size,
     196             :                                     BOOST_CURRENT_FUNCTION,
     197           0 :                                     static_cast< UnambiguousBaseType* >(this));
     198             : 
     199           0 :             MutexType aGuard( BaseType::m_aMutex );
     200             : 
     201           0 :             return maDeviceHelper.createCompatibleBitmap( this, size );
     202             :         }
     203             : 
     204           0 :         virtual css::uno::Reference< css::rendering::XVolatileBitmap > SAL_CALL createVolatileBitmap( const css::geometry::IntegerSize2D& size ) throw (css::lang::IllegalArgumentException,
     205             :                                                                                                                                                                                                css::uno::RuntimeException) SAL_OVERRIDE
     206             :         {
     207           0 :             tools::verifyBitmapSize(size,
     208             :                                     BOOST_CURRENT_FUNCTION,
     209           0 :                                     static_cast< UnambiguousBaseType* >(this));
     210             : 
     211           0 :             MutexType aGuard( BaseType::m_aMutex );
     212             : 
     213           0 :             return maDeviceHelper.createVolatileBitmap( this, size );
     214             :         }
     215             : 
     216           2 :         virtual css::uno::Reference< css::rendering::XBitmap > SAL_CALL createCompatibleAlphaBitmap( const css::geometry::IntegerSize2D& size )
     217             :             throw (css::lang::IllegalArgumentException,
     218             :                    css::uno::RuntimeException,
     219             :                    std::exception) SAL_OVERRIDE
     220             :         {
     221           2 :             tools::verifyBitmapSize(size,
     222             :                                     BOOST_CURRENT_FUNCTION,
     223           4 :                                     static_cast< UnambiguousBaseType* >(this));
     224             : 
     225           2 :             MutexType aGuard( BaseType::m_aMutex );
     226             : 
     227           2 :             return maDeviceHelper.createCompatibleAlphaBitmap( this, size );
     228             :         }
     229             : 
     230           0 :         virtual css::uno::Reference< css::rendering::XVolatileBitmap > SAL_CALL createVolatileAlphaBitmap( const css::geometry::IntegerSize2D& size ) throw (css::lang::IllegalArgumentException,
     231             :                                                                                                                                                                                                     css::uno::RuntimeException) SAL_OVERRIDE
     232             :         {
     233           0 :             tools::verifyBitmapSize(size,
     234             :                                     BOOST_CURRENT_FUNCTION,
     235           0 :                                     static_cast< UnambiguousBaseType* >(this));
     236             : 
     237           0 :             MutexType aGuard( BaseType::m_aMutex );
     238             : 
     239           0 :             return maDeviceHelper.createVolatileAlphaBitmap( this, size );
     240             :         }
     241             : 
     242           0 :         virtual css::uno::Reference< css::lang::XMultiServiceFactory > SAL_CALL getParametricPolyPolygonFactory(  ) throw (css::uno::RuntimeException) SAL_OVERRIDE
     243             :         {
     244           0 :             return this;
     245             :         }
     246             : 
     247           0 :         virtual sal_Bool SAL_CALL hasFullScreenMode(  ) throw (css::uno::RuntimeException) SAL_OVERRIDE
     248             :         {
     249           0 :             return sal_False;
     250             :         }
     251             : 
     252           0 :         virtual sal_Bool SAL_CALL enterFullScreenMode( sal_Bool ) throw (css::uno::RuntimeException) SAL_OVERRIDE
     253             :         {
     254           0 :             return false;
     255             :         }
     256             : 
     257             :         // XMultiServiceFactory
     258           0 :         virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( const OUString& aServiceSpecifier ) throw (css::uno::Exception, css::uno::RuntimeException) SAL_OVERRIDE
     259             :         {
     260             :             return css::uno::Reference< css::rendering::XParametricPolyPolygon2D >(
     261             :                 ParametricPolyPolygon::create(this,
     262             :                                               aServiceSpecifier,
     263           0 :                                               css::uno::Sequence< css::uno::Any >()));
     264             :         }
     265             : 
     266           0 :         virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments( const OUString& aServiceSpecifier, const css::uno::Sequence< css::uno::Any >& Arguments ) throw (css::uno::Exception, css::uno::RuntimeException) SAL_OVERRIDE
     267             :         {
     268             :             return css::uno::Reference< css::rendering::XParametricPolyPolygon2D >(
     269             :                 ParametricPolyPolygon::create(this,
     270             :                                               aServiceSpecifier,
     271           0 :                                               Arguments));
     272             :         }
     273             : 
     274           0 :         virtual css::uno::Sequence< OUString > SAL_CALL getAvailableServiceNames(  ) throw (css::uno::RuntimeException) SAL_OVERRIDE
     275             :         {
     276           0 :             return ParametricPolyPolygon::getAvailableServiceNames();
     277             :         }
     278             : 
     279             : 
     280             :         // XUpdatable
     281           0 :         virtual void SAL_CALL update() throw (css::uno::RuntimeException, std::exception) 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 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw (css::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 css::uno::Any& aValue ) throw (css::beans::UnknownPropertyException,
     299             :                                                                                      css::beans::PropertyVetoException,
     300             :                                                                                      css::lang::IllegalArgumentException,
     301             :                                                                                      css::lang::WrappedTargetException,
     302             :                                                                                      css::uno::RuntimeException,
     303             :                                                                                      std::exception) SAL_OVERRIDE
     304             :         {
     305           0 :             MutexType aGuard( BaseType::m_aMutex );
     306           0 :             maPropHelper.setPropertyValue( aPropertyName, aValue );
     307           0 :         }
     308             : 
     309           0 :         virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& aPropertyName ) throw (css::beans::UnknownPropertyException,
     310             :                                                                                                 css::lang::WrappedTargetException,
     311             :                                                                                                 css::uno::RuntimeException,
     312             :                                                                                                 std::exception) SAL_OVERRIDE
     313             :         {
     314           0 :             MutexType aGuard( BaseType::m_aMutex );
     315           0 :             return maPropHelper.getPropertyValue( aPropertyName );
     316             :         }
     317             : 
     318           0 :         virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName,
     319             :                                                          const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) throw (css::beans::UnknownPropertyException,
     320             :                                                                                                                                                                         css::lang::WrappedTargetException,
     321             :                                                                                                                                                                         css::uno::RuntimeException) SAL_OVERRIDE
     322             :         {
     323           0 :             MutexType aGuard( BaseType::m_aMutex );
     324           0 :             maPropHelper.addPropertyChangeListener( aPropertyName,
     325           0 :                                                     xListener );
     326           0 :         }
     327             : 
     328           0 :         virtual void SAL_CALL removePropertyChangeListener( const OUString& ,
     329             :                                                             const css::uno::Reference< css::beans::XPropertyChangeListener >& ) throw (css::beans::UnknownPropertyException,
     330             :                                                                                                                                                                            css::lang::WrappedTargetException,
     331             :                                                                                                                                                                            css::uno::RuntimeException) SAL_OVERRIDE
     332             :         {
     333           0 :         }
     334             : 
     335           0 :         virtual void SAL_CALL addVetoableChangeListener( const OUString& aPropertyName,
     336             :                                                          const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener ) throw (css::beans::UnknownPropertyException,
     337             :                                                                                                                                                                         css::lang::WrappedTargetException,
     338             :                                                                                                                                                                         css::uno::RuntimeException) SAL_OVERRIDE
     339             :         {
     340           0 :             MutexType aGuard( BaseType::m_aMutex );
     341           0 :             maPropHelper.addVetoableChangeListener( aPropertyName,
     342           0 :                                                     xListener );
     343           0 :         }
     344             : 
     345           0 :         virtual void SAL_CALL removeVetoableChangeListener( const OUString& ,
     346             :                                                             const css::uno::Reference< css::beans::XVetoableChangeListener >& ) throw (css::beans::UnknownPropertyException,
     347             :                                                                                                                                                                            css::lang::WrappedTargetException,
     348             :                                                                                                                                                                            css::uno::RuntimeException) SAL_OVERRIDE
     349             :         {
     350           0 :         }
     351             : 
     352             :     protected:
     353           3 :         ~GraphicDeviceBase() {} // we're a ref-counted UNO class. _We_ destroy ourselves.
     354             : 
     355           0 :         css::uno::Any getDumpScreenContent() const
     356             :         {
     357           0 :             return css::uno::makeAny( mbDumpScreenContent );
     358             :         }
     359             : 
     360           0 :         void setDumpScreenContent( const css::uno::Any& rAny )
     361             :         {
     362             :             // TODO(Q1): this was mbDumpScreenContent =
     363             :             // rAny.get<bool>(), only that gcc3.3 wouldn't eat it
     364           0 :             rAny >>= mbDumpScreenContent;
     365           0 :         }
     366             : 
     367             :         DeviceHelperType  maDeviceHelper;
     368             :         PropertySetHelper maPropHelper;
     369             :         bool              mbDumpScreenContent;
     370             : 
     371             :     private:
     372             :         GraphicDeviceBase( const GraphicDeviceBase& ) SAL_DELETED_FUNCTION;
     373             :         GraphicDeviceBase& operator=( const GraphicDeviceBase& ) SAL_DELETED_FUNCTION;
     374             :     };
     375             : }
     376             : 
     377             : #endif // INCLUDED_CANVAS_BASE_GRAPHICDEVICEBASE_HXX
     378             : 
     379             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11