LCOV - code coverage report
Current view: top level - canvas/source/vcl - bitmapbackbuffer.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 53 0.0 %
Date: 2014-04-14 Functions: 0 10 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 "bitmapbackbuffer.hxx"
      22             : 
      23             : #include <osl/mutex.hxx>
      24             : 
      25             : #include <vcl/svapp.hxx>
      26             : #include <vcl/bitmapex.hxx>
      27             : #include <vcl/bmpacc.hxx>
      28             : 
      29             : 
      30             : namespace vclcanvas
      31             : {
      32           0 :     BitmapBackBuffer::BitmapBackBuffer( const BitmapEx&         rBitmap,
      33             :                                         const OutputDevice&     rRefDevice ) :
      34             :         maBitmap( rBitmap ),
      35             :         mpVDev( NULL ),
      36             :         mrRefDevice( rRefDevice ),
      37             :         mbBitmapContentIsCurrent( false ),
      38           0 :         mbVDevContentIsCurrent( false )
      39             :     {
      40           0 :     }
      41             : 
      42           0 :     BitmapBackBuffer::~BitmapBackBuffer()
      43             :     {
      44             :         // make sure solar mutex is held on deletion (other methods
      45             :         // are supposed to be called with already locked solar mutex)
      46           0 :         SolarMutexGuard aGuard;
      47             : 
      48           0 :         if( mpVDev )
      49           0 :             delete mpVDev;
      50           0 :     }
      51             : 
      52           0 :     OutputDevice& BitmapBackBuffer::getOutDev()
      53             :     {
      54           0 :         createVDev();
      55           0 :         updateVDev();
      56           0 :         return *mpVDev;
      57             :     }
      58             : 
      59           0 :     const OutputDevice& BitmapBackBuffer::getOutDev() const
      60             :     {
      61           0 :         createVDev();
      62           0 :         updateVDev();
      63           0 :         return *mpVDev;
      64             :     }
      65             : 
      66           0 :     void BitmapBackBuffer::clear()
      67             :     {
      68             :         // force current content to bitmap, make all transparent white
      69           0 :         getBitmapReference().Erase(COL_TRANSPARENT);
      70           0 :     }
      71             : 
      72           0 :     BitmapEx& BitmapBackBuffer::getBitmapReference()
      73             :     {
      74             :         OSL_ENSURE( !mbBitmapContentIsCurrent || !mbVDevContentIsCurrent,
      75             :                     "BitmapBackBuffer::getBitmapReference(): Both bitmap and VDev are valid?!" );
      76             : 
      77           0 :         if( mbVDevContentIsCurrent && mpVDev )
      78             :         {
      79             :             // VDev content is more current than bitmap - copy contents before!
      80           0 :             mpVDev->EnableMapMode( false );
      81           0 :             mpVDev->SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW );
      82           0 :             const Point aEmptyPoint;
      83           0 :             *maBitmap = mpVDev->GetBitmapEx( aEmptyPoint,
      84           0 :                                              mpVDev->GetOutputSizePixel() );
      85             :         }
      86             : 
      87             :         // client queries bitmap, and will possibly alter content -
      88             :         // next time, VDev needs to be updated
      89           0 :         mbBitmapContentIsCurrent = true;
      90           0 :         mbVDevContentIsCurrent   = false;
      91             : 
      92           0 :         return *maBitmap;
      93             :     }
      94             : 
      95           0 :     Size BitmapBackBuffer::getBitmapSizePixel() const
      96             :     {
      97           0 :         Size aSize = maBitmap->GetSizePixel();
      98             : 
      99           0 :         if( mbVDevContentIsCurrent && mpVDev )
     100             :         {
     101           0 :             mpVDev->EnableMapMode( false );
     102           0 :             mpVDev->SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW );
     103           0 :             aSize = mpVDev->GetOutputSizePixel();
     104             :         }
     105             : 
     106           0 :         return aSize;
     107             :     }
     108             : 
     109           0 :     void BitmapBackBuffer::createVDev() const
     110             :     {
     111           0 :         if( !mpVDev )
     112             :         {
     113             :             // VDev not yet created, do it now. Create an alpha-VDev,
     114             :             // if bitmap has transparency.
     115           0 :             mpVDev = maBitmap->IsTransparent() ?
     116           0 :                 new VirtualDevice( mrRefDevice, 0, 0 ) :
     117           0 :                 new VirtualDevice( mrRefDevice );
     118             : 
     119             :             OSL_ENSURE( mpVDev,
     120             :                         "BitmapBackBuffer::createVDev(): Unable to create VirtualDevice" );
     121             : 
     122           0 :             mpVDev->SetOutputSizePixel( maBitmap->GetSizePixel() );
     123             : 
     124             :             // #i95645#
     125             : #if defined( MACOSX )
     126             :             // use AA on VCLCanvas for Mac
     127             :             mpVDev->SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW | mpVDev->GetAntialiasing() );
     128             : #else
     129             :             // switch off AA for WIN32 and UNIX, the VCLCanvas does not look good with it and
     130             :             // is not required to do AA. It would need to be adapted to use it correctly
     131             :             // (especially gradient painting). This will need extra work.
     132           0 :             mpVDev->SetAntialiasing(mpVDev->GetAntialiasing() & ~ANTIALIASING_ENABLE_B2DDRAW);
     133             : #endif
     134             :         }
     135           0 :     }
     136             : 
     137           0 :     void BitmapBackBuffer::updateVDev() const
     138             :     {
     139             :         OSL_ENSURE( !mbBitmapContentIsCurrent || !mbVDevContentIsCurrent,
     140             :                     "BitmapBackBuffer::updateVDev(): Both bitmap and VDev are valid?!" );
     141             : 
     142           0 :         if( mpVDev && mbBitmapContentIsCurrent )
     143             :         {
     144             :             // fill with bitmap content
     145           0 :             mpVDev->EnableMapMode( false );
     146           0 :             mpVDev->SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW );
     147           0 :             const Point aEmptyPoint;
     148           0 :             mpVDev->DrawBitmapEx( aEmptyPoint, *maBitmap );
     149             :         }
     150             : 
     151             :         // canvas queried the VDev, and will possibly paint into
     152             :         // it. Next time, bitmap must be updated
     153           0 :         mbBitmapContentIsCurrent = false;
     154           0 :         mbVDevContentIsCurrent   = true;
     155           0 :     }
     156             : }
     157             : 
     158             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10