LCOV - code coverage report
Current view: top level - include/canvas/base - graphicdevicebase.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 11 102 10.8 %
Date: 2014-11-03 Functions: 3 150 2.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< 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.  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=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           2 :         GraphicDeviceBase() :
     117             :             maDeviceHelper(),
     118             :             maPropHelper(),
     119           2 :             mbDumpScreenContent(false)
     120             :         {
     121           2 :             maPropHelper.initProperties( PropertySetHelper::MakeMap
     122             :                                          ("HardwareAcceleration",
     123             :                                           boost::bind(&DeviceHelper::isAccelerated,
     124             :                                                       boost::ref(maDeviceHelper)))
     125             :                                          ("DeviceHandle",
     126             :                                           boost::bind(&DeviceHelper::getDeviceHandle,
     127           4 :                                                       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           2 :         }
     138             : 
     139           2 :         virtual void disposeThis() SAL_OVERRIDE
     140             :         {
     141           2 :             MutexType aGuard( BaseType::m_aMutex );
     142             : 
     143           2 :             maDeviceHelper.disposing();
     144             : 
     145             :             // pass on to base class
     146           2 :             BaseType::disposeThis();
     147           2 :         }
     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           0 :         virtual css::uno::Reference< css::rendering::XColorSpace > SAL_CALL getDeviceColorSpace(  ) throw (css::uno::RuntimeException) SAL_OVERRIDE
     156             :         {
     157           0 :             MutexType aGuard( BaseType::m_aMutex );
     158             : 
     159           0 :             return maDeviceHelper.getColorSpace();
     160             :         }
     161             : 
     162           0 :         virtual css::geometry::RealSize2D SAL_CALL getPhysicalResolution(  ) throw (css::uno::RuntimeException) 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) SAL_OVERRIDE
     170             :         {
     171           0 :             MutexType aGuard( BaseType::m_aMutex );
     172             : 
     173           0 :             return maDeviceHelper.getPhysicalSize();
     174             :         }
     175             : 
     176           0 :         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           0 :             MutexType aGuard( BaseType::m_aMutex );
     179             : 
     180           0 :             return maDeviceHelper.createCompatibleLinePolyPolygon( this, points );
     181             :         }
     182             : 
     183           0 :         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           0 :             MutexType aGuard( BaseType::m_aMutex );
     186             : 
     187           0 :             return maDeviceHelper.createCompatibleBezierPolyPolygon( this, points );
     188             :         }
     189             : 
     190           0 :         virtual css::uno::Reference< css::rendering::XBitmap > SAL_CALL createCompatibleBitmap( const css::geometry::IntegerSize2D& size ) throw (css::lang::IllegalArgumentException,
     191             :                                                                                                                                                                                          css::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 css::uno::Reference< css::rendering::XVolatileBitmap > SAL_CALL createVolatileBitmap( const css::geometry::IntegerSize2D& size ) throw (css::lang::IllegalArgumentException,
     203             :                                                                                                                                                                                                css::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 css::uno::Reference< css::rendering::XBitmap > SAL_CALL createCompatibleAlphaBitmap( const css::geometry::IntegerSize2D& size ) throw (css::lang::IllegalArgumentException,
     215             :                                                                                                                                                                                               css::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 css::uno::Reference< css::rendering::XVolatileBitmap > SAL_CALL createVolatileAlphaBitmap( const css::geometry::IntegerSize2D& size ) throw (css::lang::IllegalArgumentException,
     227             :                                                                                                                                                                                                     css::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 css::uno::Reference< css::lang::XMultiServiceFactory > SAL_CALL getParametricPolyPolygonFactory(  ) throw (css::uno::RuntimeException) SAL_OVERRIDE
     239             :         {
     240           0 :             return this;
     241             :         }
     242             : 
     243           0 :         virtual sal_Bool SAL_CALL hasFullScreenMode(  ) throw (css::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 (css::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 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 (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 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) SAL_OVERRIDE
     303             :         {
     304           0 :             MutexType aGuard( BaseType::m_aMutex );
     305           0 :             maPropHelper.setPropertyValue( aPropertyName, aValue );
     306           0 :         }
     307             : 
     308           0 :         virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& aPropertyName ) throw (css::beans::UnknownPropertyException,
     309             :                                                                                                                     css::lang::WrappedTargetException,
     310             :                                                                                                                     css::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 css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) throw (css::beans::UnknownPropertyException,
     318             :                                                                                                                                                                         css::lang::WrappedTargetException,
     319             :                                                                                                                                                                         css::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 css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) throw (css::beans::UnknownPropertyException,
     328             :                                                                                                                                                                            css::lang::WrappedTargetException,
     329             :                                                                                                                                                                            css::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 css::uno::Reference< css::beans::XVetoableChangeListener >& xListener ) throw (css::beans::UnknownPropertyException,
     338             :                                                                                                                                                                         css::lang::WrappedTargetException,
     339             :                                                                                                                                                                         css::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 css::uno::Reference< css::beans::XVetoableChangeListener >& xListener ) throw (css::beans::UnknownPropertyException,
     348             :                                                                                                                                                                            css::lang::WrappedTargetException,
     349             :                                                                                                                                                                            css::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           2 :         ~GraphicDeviceBase() {} // we're a ref-counted UNO class. _We_ destroy ourselves.
     358             : 
     359           0 :         css::uno::Any getDumpScreenContent() const
     360             :         {
     361           0 :             return css::uno::makeAny( mbDumpScreenContent );
     362             :         }
     363             : 
     364           0 :         void setDumpScreenContent( const css::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