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

Generated by: LCOV version 1.10