LCOV - code coverage report
Current view: top level - libreoffice/canvas/source/cairo - cairo_devicehelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 102 0.0 %
Date: 2012-12-27 Functions: 0 26 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             : 
      21             : #include <canvas/debug.hxx>
      22             : #include <canvas/verbosetrace.hxx>
      23             : #include <canvas/canvastools.hxx>
      24             : 
      25             : #include <osl/mutex.hxx>
      26             : #include <cppuhelper/compbase1.hxx>
      27             : 
      28             : #include <com/sun/star/lang/NoSupportException.hpp>
      29             : 
      30             : #include <toolkit/helper/vclunohelper.hxx>
      31             : #include <basegfx/tools/canvastools.hxx>
      32             : #include <basegfx/tools/unopolypolygon.hxx>
      33             : 
      34             : #include <vcl/canvastools.hxx>
      35             : 
      36             : #include <tools/stream.hxx>
      37             : 
      38             : #include "cairo_spritecanvas.hxx"
      39             : #include "cairo_canvasbitmap.hxx"
      40             : #include "cairo_devicehelper.hxx"
      41             : 
      42             : using namespace ::cairo;
      43             : using namespace ::com::sun::star;
      44             : 
      45             : namespace cairocanvas
      46             : {
      47           0 :     DeviceHelper::DeviceHelper() :
      48             :         mpSurfaceProvider( NULL ),
      49             :         mpRefDevice( NULL ),
      50           0 :         mpSurface()
      51             :     {
      52           0 :     }
      53             : 
      54           0 :     void DeviceHelper::implInit( SurfaceProvider& rSurfaceProvider,
      55             :                                  OutputDevice&    rRefDevice )
      56             :     {
      57           0 :         mpSurfaceProvider = &rSurfaceProvider;
      58           0 :         mpRefDevice = &rRefDevice;
      59             : 
      60             :         // no own surface, this is handled by derived classes
      61           0 :     }
      62             : 
      63           0 :     void DeviceHelper::init( SurfaceProvider& rSurfaceProvider,
      64             :                              OutputDevice&    rRefDevice )
      65             :     {
      66           0 :         implInit(rSurfaceProvider, rRefDevice);
      67             : 
      68           0 :         OutputDevice* pOutDev=getOutputDevice();
      69             :         mpSurface = cairo::createSurface( *pOutDev,
      70           0 :                                           pOutDev->GetOutOffXPixel(),
      71           0 :                                           pOutDev->GetOutOffYPixel(),
      72           0 :                                           pOutDev->GetOutputWidthPixel(),
      73           0 :                                           pOutDev->GetOutputHeightPixel() );
      74           0 :     }
      75             : 
      76           0 :     void DeviceHelper::disposing()
      77             :     {
      78             :         // release all references
      79           0 :         mpSurface.reset();
      80           0 :         mpRefDevice = NULL;
      81           0 :         mpSurfaceProvider = NULL;
      82           0 :     }
      83             : 
      84           0 :     void DeviceHelper::setSize( const ::basegfx::B2ISize& rSize )
      85             :     {
      86             :         OSL_TRACE("DeviceHelper::setSize(): device size %d x %d", rSize.getX(), rSize.getY() );
      87             : 
      88           0 :         if( !mpRefDevice )
      89           0 :             return; // disposed
      90             : 
      91           0 :         OutputDevice* pOutDev=getOutputDevice();
      92             : 
      93             : #if defined (UNX) && !defined (QUARTZ)
      94             :         // X11 only
      95           0 :         if( mpSurface )
      96           0 :             mpSurface->Resize( rSize.getX() + pOutDev->GetOutOffXPixel(),
      97           0 :                                rSize.getY() + pOutDev->GetOutOffYPixel() );
      98             :         else
      99             : #endif
     100             :             mpSurface = cairo::createSurface(
     101             :                 *pOutDev,
     102           0 :                 pOutDev->GetOutOffXPixel(),
     103           0 :                 pOutDev->GetOutOffYPixel(),
     104           0 :                 rSize.getX(), rSize.getY() );
     105             :     }
     106             : 
     107           0 :     geometry::RealSize2D DeviceHelper::getPhysicalResolution()
     108             :     {
     109             :         // Map a one-by-one millimeter box to pixel
     110           0 :         const MapMode aOldMapMode( mpRefDevice->GetMapMode() );
     111           0 :         mpRefDevice->SetMapMode( MapMode(MAP_MM) );
     112           0 :         const Size aPixelSize( mpRefDevice->LogicToPixel(Size(1,1)) );
     113           0 :         mpRefDevice->SetMapMode( aOldMapMode );
     114             : 
     115           0 :         return ::vcl::unotools::size2DFromSize( aPixelSize );
     116             :     }
     117             : 
     118           0 :     geometry::RealSize2D DeviceHelper::getPhysicalSize()
     119             :     {
     120           0 :         if( !mpRefDevice )
     121           0 :             return ::canvas::tools::createInfiniteSize2D(); // we're disposed
     122             : 
     123             :         // Map the pixel dimensions of the output window to millimeter
     124           0 :         const MapMode aOldMapMode( mpRefDevice->GetMapMode() );
     125           0 :         mpRefDevice->SetMapMode( MapMode(MAP_MM) );
     126           0 :         const Size aLogSize( mpRefDevice->PixelToLogic(mpRefDevice->GetOutputSizePixel()) );
     127           0 :         mpRefDevice->SetMapMode( aOldMapMode );
     128             : 
     129           0 :         return ::vcl::unotools::size2DFromSize( aLogSize );
     130             :     }
     131             : 
     132           0 :     uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
     133             :         const uno::Reference< rendering::XGraphicDevice >&              ,
     134             :         const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >&  points )
     135             :     {
     136             :         // disposed?
     137           0 :         if( !mpSurfaceProvider )
     138           0 :             return uno::Reference< rendering::XLinePolyPolygon2D >(); // we're disposed
     139             : 
     140             :         return uno::Reference< rendering::XLinePolyPolygon2D >(
     141             :             new ::basegfx::unotools::UnoPolyPolygon(
     142           0 :                 ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) );
     143             :     }
     144             : 
     145           0 :     uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
     146             :         const uno::Reference< rendering::XGraphicDevice >&                      ,
     147             :         const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >&  points )
     148             :     {
     149             :         // disposed?
     150           0 :         if( !mpSurfaceProvider )
     151           0 :             return uno::Reference< rendering::XBezierPolyPolygon2D >(); // we're disposed
     152             : 
     153             :         return uno::Reference< rendering::XBezierPolyPolygon2D >(
     154             :             new ::basegfx::unotools::UnoPolyPolygon(
     155           0 :                 ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) );
     156             :     }
     157             : 
     158           0 :     uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
     159             :         const uno::Reference< rendering::XGraphicDevice >&  rDevice,
     160             :         const geometry::IntegerSize2D&                      size )
     161             :     {
     162             :         // disposed?
     163           0 :         if( !mpSurfaceProvider )
     164           0 :             return uno::Reference< rendering::XBitmap >(); // we're disposed
     165             : 
     166             :         return uno::Reference< rendering::XBitmap >(
     167             :             new CanvasBitmap(
     168             :                 ::basegfx::unotools::b2ISizeFromIntegerSize2D( size ),
     169             :                 SurfaceProviderRef(mpSurfaceProvider),
     170             :                 rDevice.get(),
     171           0 :                 false ));
     172             :     }
     173             : 
     174           0 :     uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap(
     175             :         const uno::Reference< rendering::XGraphicDevice >&  ,
     176             :         const geometry::IntegerSize2D&                      /*size*/ )
     177             :     {
     178           0 :         return uno::Reference< rendering::XVolatileBitmap >();
     179             :     }
     180             : 
     181           0 :     uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap(
     182             :         const uno::Reference< rendering::XGraphicDevice >&  rDevice,
     183             :         const geometry::IntegerSize2D&                      size )
     184             :     {
     185             :         // disposed?
     186           0 :         if( !mpSurfaceProvider )
     187           0 :             return uno::Reference< rendering::XBitmap >(); // we're disposed
     188             : 
     189             :         return uno::Reference< rendering::XBitmap >(
     190             :             new CanvasBitmap(
     191             :                 ::basegfx::unotools::b2ISizeFromIntegerSize2D( size ),
     192             :                 SurfaceProviderRef(mpSurfaceProvider),
     193             :                 rDevice.get(),
     194           0 :                 true ));
     195             :     }
     196             : 
     197           0 :     uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap(
     198             :         const uno::Reference< rendering::XGraphicDevice >&  ,
     199             :         const geometry::IntegerSize2D&                      /*size*/ )
     200             :     {
     201           0 :         return uno::Reference< rendering::XVolatileBitmap >();
     202             :     }
     203             : 
     204           0 :     sal_Bool DeviceHelper::hasFullScreenMode()
     205             :     {
     206             :         // TODO(F3): offer fullscreen mode the XCanvas way
     207           0 :         return false;
     208             :     }
     209             : 
     210           0 :     sal_Bool DeviceHelper::enterFullScreenMode( sal_Bool /*bEnter*/ )
     211             :     {
     212             :         // TODO(F3): offer fullscreen mode the XCanvas way
     213           0 :         return false;
     214             :     }
     215             : 
     216           0 :     uno::Any DeviceHelper::isAccelerated() const
     217             :     {
     218           0 :         return ::com::sun::star::uno::makeAny(false);
     219             :     }
     220             : 
     221           0 :     uno::Any DeviceHelper::getDeviceHandle() const
     222             :     {
     223           0 :         return uno::makeAny( reinterpret_cast< sal_Int64 >(mpRefDevice) );
     224             :     }
     225             : 
     226           0 :     uno::Any DeviceHelper::getSurfaceHandle() const
     227             :     {
     228           0 :         return uno::Any();
     229             :     }
     230             : 
     231             :     namespace
     232             :     {
     233             :         struct DeviceColorSpace: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>,
     234             :                                                             DeviceColorSpace>
     235             :         {
     236           0 :             uno::Reference<rendering::XColorSpace> operator()()
     237             :             {
     238           0 :                 return vcl::unotools::createStandardColorSpace();
     239             :             }
     240             :         };
     241             :     }
     242             : 
     243           0 :     uno::Reference<rendering::XColorSpace> DeviceHelper::getColorSpace() const
     244             :     {
     245             :         // always the same
     246           0 :         return DeviceColorSpace::get();
     247             :     }
     248             : 
     249           0 :     void DeviceHelper::dumpScreenContent() const
     250             :     {
     251             :         static sal_Int32 nFilePostfixCount(0);
     252             : 
     253           0 :         if( mpRefDevice )
     254             :         {
     255           0 :             OUString aFilename("dbg_frontbuffer");
     256           0 :             aFilename += OUString::valueOf(nFilePostfixCount);
     257           0 :             aFilename += OUString(".bmp");
     258             : 
     259           0 :             SvFileStream aStream( aFilename, STREAM_STD_READWRITE );
     260             : 
     261           0 :             const ::Point aEmptyPoint;
     262           0 :             bool bOldMap( mpRefDevice->IsMapModeEnabled() );
     263           0 :             mpRefDevice->EnableMapMode( sal_False );
     264             :             aStream << mpRefDevice->GetBitmap(aEmptyPoint,
     265           0 :                                               mpRefDevice->GetOutputSizePixel());
     266           0 :             mpRefDevice->EnableMapMode( bOldMap );
     267             : 
     268           0 :             ++nFilePostfixCount;
     269             :         }
     270           0 :     }
     271             : 
     272           0 :     SurfaceSharedPtr DeviceHelper::getSurface()
     273             :     {
     274           0 :         return mpSurface;
     275             :     }
     276             : 
     277           0 :     SurfaceSharedPtr DeviceHelper::createSurface( const ::basegfx::B2ISize& rSize, Content aContent )
     278             :     {
     279           0 :         if( mpSurface )
     280           0 :             return mpSurface->getSimilar( aContent, rSize.getX(), rSize.getY() );
     281             : 
     282           0 :         return SurfaceSharedPtr();
     283             :     }
     284             : 
     285           0 :     SurfaceSharedPtr DeviceHelper::createSurface( BitmapSystemData& rData, const Size& rSize )
     286             :     {
     287           0 :         if( mpRefDevice )
     288           0 :             return createBitmapSurface( *mpRefDevice, rData, rSize );
     289             : 
     290           0 :         return SurfaceSharedPtr();
     291             :     }
     292           0 : }
     293             : 
     294             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10