LCOV - code coverage report
Current view: top level - libreoffice/canvas/source/vcl - bitmapbackbuffer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 50 0.0 %
Date: 2012-12-27 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( sal_False );
      81           0 :             const Point aEmptyPoint;
      82           0 :             *maBitmap = mpVDev->GetBitmapEx( aEmptyPoint,
      83           0 :                                              mpVDev->GetOutputSizePixel() );
      84             :         }
      85             : 
      86             :         // client queries bitmap, and will possibly alter content -
      87             :         // next time, VDev needs to be updated
      88           0 :         mbBitmapContentIsCurrent = true;
      89           0 :         mbVDevContentIsCurrent   = false;
      90             : 
      91           0 :         return *maBitmap;
      92             :     }
      93             : 
      94           0 :     Size BitmapBackBuffer::getBitmapSizePixel() const
      95             :     {
      96           0 :         Size aSize = maBitmap->GetSizePixel();
      97             : 
      98           0 :         if( mbVDevContentIsCurrent && mpVDev )
      99             :         {
     100           0 :             mpVDev->EnableMapMode( sal_False );
     101           0 :             aSize = mpVDev->GetOutputSizePixel();
     102             :         }
     103             : 
     104           0 :         return aSize;
     105             :     }
     106             : 
     107           0 :     void BitmapBackBuffer::createVDev() const
     108             :     {
     109           0 :         if( !mpVDev )
     110             :         {
     111             :             // VDev not yet created, do it now. Create an alpha-VDev,
     112             :             // if bitmap has transparency.
     113           0 :             mpVDev = maBitmap->IsTransparent() ?
     114           0 :                 new VirtualDevice( mrRefDevice, 0, 0 ) :
     115           0 :                 new VirtualDevice( mrRefDevice );
     116             : 
     117             :             OSL_ENSURE( mpVDev,
     118             :                         "BitmapBackBuffer::createVDev(): Unable to create VirtualDevice" );
     119             : 
     120           0 :             mpVDev->SetOutputSizePixel( maBitmap->GetSizePixel() );
     121             : 
     122             :             // #i95645#
     123             : #if defined( QUARTZ )
     124             :             // use AA on VCLCanvas for Mac
     125             :             mpVDev->SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW | mpVDev->GetAntialiasing() );
     126             : #else
     127             :             // switch off AA for WIN32 and UNIX, the VCLCanvas does not look good with it and
     128             :             // is not required to do AA. It would need to be adapted to use it correctly
     129             :             // (especially gradient painting). This will need extra work.
     130           0 :             mpVDev->SetAntialiasing(mpVDev->GetAntialiasing() & ~ANTIALIASING_ENABLE_B2DDRAW);
     131             : #endif
     132             :         }
     133           0 :     }
     134             : 
     135           0 :     void BitmapBackBuffer::updateVDev() const
     136             :     {
     137             :         OSL_ENSURE( !mbBitmapContentIsCurrent || !mbVDevContentIsCurrent,
     138             :                     "BitmapBackBuffer::updateVDev(): Both bitmap and VDev are valid?!" );
     139             : 
     140           0 :         if( mpVDev && mbBitmapContentIsCurrent )
     141             :         {
     142             :             // fill with bitmap content
     143           0 :             mpVDev->EnableMapMode( sal_False );
     144           0 :             const Point aEmptyPoint;
     145           0 :             mpVDev->DrawBitmapEx( aEmptyPoint, *maBitmap );
     146             :         }
     147             : 
     148             :         // canvas queried the VDev, and will possibly paint into
     149             :         // it. Next time, bitmap must be updated
     150           0 :         mbBitmapContentIsCurrent = false;
     151           0 :         mbVDevContentIsCurrent   = true;
     152           0 :     }
     153             : }
     154             : 
     155             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10