Update ooo320-m1
[ooovba.git] / canvas / source / vcl / bitmapbackbuffer.cxx
blob649f46b480d6245cf69c38f522aeb7b5af38ac35
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bitmapbackbuffer.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_canvas.hxx"
34 #include "bitmapbackbuffer.hxx"
36 #include <osl/mutex.hxx>
37 #include <vos/mutex.hxx>
39 #include <vcl/svapp.hxx>
40 #include <vcl/bitmapex.hxx>
41 #include <vcl/bmpacc.hxx>
44 namespace vclcanvas
46 BitmapBackBuffer::BitmapBackBuffer( const BitmapEx& rBitmap,
47 const OutputDevice& rRefDevice ) :
48 maBitmap( rBitmap ),
49 mpVDev( NULL ),
50 mrRefDevice( rRefDevice ),
51 mbBitmapContentIsCurrent( false ),
52 mbVDevContentIsCurrent( false )
56 BitmapBackBuffer::~BitmapBackBuffer()
58 // make sure solar mutex is held on deletion (other methods
59 // are supposed to be called with already locked solar mutex)
60 ::vos::OGuard aGuard( Application::GetSolarMutex() );
62 if( mpVDev )
63 delete mpVDev;
66 OutputDevice& BitmapBackBuffer::getOutDev()
68 createVDev();
69 updateVDev();
70 return *mpVDev;
73 const OutputDevice& BitmapBackBuffer::getOutDev() const
75 createVDev();
76 updateVDev();
77 return *mpVDev;
80 void BitmapBackBuffer::clear()
82 // force current content to bitmap, make all transparent white
83 getBitmapReference().Erase(COL_TRANSPARENT);
86 BitmapEx& BitmapBackBuffer::getBitmapReference()
88 OSL_ENSURE( !mbBitmapContentIsCurrent || !mbVDevContentIsCurrent,
89 "BitmapBackBuffer::getBitmapReference(): Both bitmap and VDev are valid?!" );
91 if( mbVDevContentIsCurrent && mpVDev )
93 // VDev content is more current than bitmap - copy contents before!
94 mpVDev->EnableMapMode( FALSE );
95 const Point aEmptyPoint;
96 *maBitmap = mpVDev->GetBitmapEx( aEmptyPoint,
97 mpVDev->GetOutputSizePixel() );
100 // client queries bitmap, and will possibly alter content -
101 // next time, VDev needs to be updated
102 mbBitmapContentIsCurrent = true;
103 mbVDevContentIsCurrent = false;
105 return *maBitmap;
108 Size BitmapBackBuffer::getBitmapSizePixel() const
110 Size aSize = maBitmap->GetSizePixel();
112 if( mbVDevContentIsCurrent && mpVDev )
114 mpVDev->EnableMapMode( FALSE );
115 aSize = mpVDev->GetOutputSizePixel();
118 return aSize;
121 void BitmapBackBuffer::createVDev() const
123 if( !mpVDev )
125 // VDev not yet created, do it now. Create an alpha-VDev,
126 // if bitmap has transparency.
127 mpVDev = maBitmap->IsTransparent() ?
128 new VirtualDevice( mrRefDevice, 0, 0 ) :
129 new VirtualDevice( mrRefDevice );
131 OSL_ENSURE( mpVDev,
132 "BitmapBackBuffer::createVDev(): Unable to create VirtualDevice" );
134 mpVDev->SetOutputSizePixel( maBitmap->GetSizePixel() );
136 // #i95645#
137 #if defined( QUARTZ )
138 // use AA on VCLCanvas for Mac
139 mpVDev->SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW | mpVDev->GetAntialiasing() );
140 #else
141 // switch off AA for WIN32 and UNIX, the VCLCanvas does not look good with it and
142 // is not required to do AA. It would need to be adapted to use it correctly
143 // (especially gradient painting). This will need extra work.
144 mpVDev->SetAntialiasing(mpVDev->GetAntialiasing() & !ANTIALIASING_ENABLE_B2DDRAW);
145 #endif
149 void BitmapBackBuffer::updateVDev() const
151 OSL_ENSURE( !mbBitmapContentIsCurrent || !mbVDevContentIsCurrent,
152 "BitmapBackBuffer::updateVDev(): Both bitmap and VDev are valid?!" );
154 if( mpVDev && mbBitmapContentIsCurrent )
156 // fill with bitmap content
157 mpVDev->EnableMapMode( FALSE );
158 const Point aEmptyPoint;
159 mpVDev->DrawBitmapEx( aEmptyPoint, *maBitmap );
162 // canvas queried the VDev, and will possibly paint into
163 // it. Next time, bitmap must be updated
164 mbBitmapContentIsCurrent = false;
165 mbVDevContentIsCurrent = true;