fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / canvas / source / vcl / bitmapbackbuffer.cxx
blobae3e7cfb57991b1aa6a494ed8933c9438ce09870
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "bitmapbackbuffer.hxx"
23 #include <osl/mutex.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/bitmapex.hxx>
27 #include <vcl/bmpacc.hxx>
30 namespace vclcanvas
32 BitmapBackBuffer::BitmapBackBuffer( const BitmapEx& rBitmap,
33 const OutputDevice& rRefDevice ) :
34 maBitmap( rBitmap ),
35 mpVDev( NULL ),
36 mrRefDevice( rRefDevice ),
37 mbBitmapContentIsCurrent( false ),
38 mbVDevContentIsCurrent( false )
42 BitmapBackBuffer::~BitmapBackBuffer()
44 // make sure solar mutex is held on deletion (other methods
45 // are supposed to be called with already locked solar mutex)
46 SolarMutexGuard aGuard;
48 if( mpVDev )
49 delete mpVDev;
52 OutputDevice& BitmapBackBuffer::getOutDev()
54 createVDev();
55 updateVDev();
56 return *mpVDev;
59 const OutputDevice& BitmapBackBuffer::getOutDev() const
61 createVDev();
62 updateVDev();
63 return *mpVDev;
66 void BitmapBackBuffer::clear()
68 // force current content to bitmap, make all transparent white
69 getBitmapReference().Erase(COL_TRANSPARENT);
72 BitmapEx& BitmapBackBuffer::getBitmapReference()
74 OSL_ENSURE( !mbBitmapContentIsCurrent || !mbVDevContentIsCurrent,
75 "BitmapBackBuffer::getBitmapReference(): Both bitmap and VDev are valid?!" );
77 if( mbVDevContentIsCurrent && mpVDev )
79 // VDev content is more current than bitmap - copy contents before!
80 mpVDev->EnableMapMode( sal_False );
81 const Point aEmptyPoint;
82 *maBitmap = mpVDev->GetBitmapEx( aEmptyPoint,
83 mpVDev->GetOutputSizePixel() );
86 // client queries bitmap, and will possibly alter content -
87 // next time, VDev needs to be updated
88 mbBitmapContentIsCurrent = true;
89 mbVDevContentIsCurrent = false;
91 return *maBitmap;
94 Size BitmapBackBuffer::getBitmapSizePixel() const
96 Size aSize = maBitmap->GetSizePixel();
98 if( mbVDevContentIsCurrent && mpVDev )
100 mpVDev->EnableMapMode( sal_False );
101 aSize = mpVDev->GetOutputSizePixel();
104 return aSize;
107 void BitmapBackBuffer::createVDev() const
109 if( !mpVDev )
111 // VDev not yet created, do it now. Create an alpha-VDev,
112 // if bitmap has transparency.
113 mpVDev = maBitmap->IsTransparent() ?
114 new VirtualDevice( mrRefDevice, 0, 0 ) :
115 new VirtualDevice( mrRefDevice );
117 OSL_ENSURE( mpVDev,
118 "BitmapBackBuffer::createVDev(): Unable to create VirtualDevice" );
120 mpVDev->SetOutputSizePixel( maBitmap->GetSizePixel() );
122 // #i95645#
123 #if defined( MACOSX )
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 mpVDev->SetAntialiasing(mpVDev->GetAntialiasing() & ~ANTIALIASING_ENABLE_B2DDRAW);
131 #endif
135 void BitmapBackBuffer::updateVDev() const
137 OSL_ENSURE( !mbBitmapContentIsCurrent || !mbVDevContentIsCurrent,
138 "BitmapBackBuffer::updateVDev(): Both bitmap and VDev are valid?!" );
140 if( mpVDev && mbBitmapContentIsCurrent )
142 // fill with bitmap content
143 mpVDev->EnableMapMode( sal_False );
144 const Point aEmptyPoint;
145 mpVDev->DrawBitmapEx( aEmptyPoint, *maBitmap );
148 // canvas queried the VDev, and will possibly paint into
149 // it. Next time, bitmap must be updated
150 mbBitmapContentIsCurrent = false;
151 mbVDevContentIsCurrent = true;
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */