Move setting of LD_LIBRARY_PATH closer to invocation of cppunittester
[LibreOffice.git] / canvas / source / vcl / bitmapbackbuffer.cxx
blob3766276f3b53cd2fdba86cf891c66224485651fe
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 .
20 #include <sal/config.h>
22 #include <osl/diagnose.h>
23 #include <vcl/bitmapex.hxx>
24 #include <vcl/svapp.hxx>
26 #include "bitmapbackbuffer.hxx"
27 #include "impltools.hxx"
29 namespace vclcanvas
31 BitmapBackBuffer::BitmapBackBuffer( const BitmapEx& rBitmap,
32 const OutputDevice& rRefDevice ) :
33 maBitmap( rBitmap ),
34 mpVDev( nullptr ),
35 mrRefDevice( rRefDevice ),
36 mbBitmapContentIsCurrent( false ),
37 mbVDevContentIsCurrent( false )
41 BitmapBackBuffer::~BitmapBackBuffer()
43 // make sure solar mutex is held on deletion (other methods
44 // are supposed to be called with already locked solar mutex)
45 SolarMutexGuard aGuard;
47 mpVDev.disposeAndClear();
50 OutputDevice& BitmapBackBuffer::getOutDev()
52 createVDev();
53 updateVDev();
54 return *mpVDev;
57 const OutputDevice& BitmapBackBuffer::getOutDev() const
59 createVDev();
60 updateVDev();
61 return *mpVDev;
64 void BitmapBackBuffer::clear()
66 // force current content to bitmap, make all transparent white
67 getBitmapReference().Erase(COL_TRANSPARENT);
70 BitmapEx& BitmapBackBuffer::getBitmapReference()
72 OSL_ENSURE( !mbBitmapContentIsCurrent || !mbVDevContentIsCurrent,
73 "BitmapBackBuffer::getBitmapReference(): Both bitmap and VDev are valid?!" );
75 if( mbVDevContentIsCurrent && mpVDev )
77 // VDev content is more current than bitmap - copy contents before!
78 mpVDev->EnableMapMode( false );
79 mpVDev->SetAntialiasing( AntialiasingFlags::Enable );
80 const Point aEmptyPoint;
81 *maBitmap = mpVDev->GetBitmapEx( aEmptyPoint,
82 mpVDev->GetOutputSizePixel() );
85 // client queries bitmap, and will possibly alter content -
86 // next time, VDev needs to be updated
87 mbBitmapContentIsCurrent = true;
88 mbVDevContentIsCurrent = false;
90 return *maBitmap;
93 Size BitmapBackBuffer::getBitmapSizePixel() const
95 Size aSize = maBitmap->GetSizePixel();
97 if( mbVDevContentIsCurrent && mpVDev )
99 mpVDev->EnableMapMode( false );
100 mpVDev->SetAntialiasing( AntialiasingFlags::Enable );
101 aSize = mpVDev->GetOutputSizePixel();
104 return aSize;
107 void BitmapBackBuffer::createVDev() const
109 if( mpVDev )
110 return;
112 // VDev not yet created, do it now. Create an alpha-VDev,
113 // if bitmap has transparency.
114 mpVDev = maBitmap->IsAlpha() ?
115 VclPtr<VirtualDevice>::Create( mrRefDevice, DeviceFormat::WITH_ALPHA ) :
116 VclPtr<VirtualDevice>::Create( mrRefDevice );
118 OSL_ENSURE( mpVDev,
119 "BitmapBackBuffer::createVDev(): Unable to create VirtualDevice" );
121 mpVDev->SetOutputSizePixel( maBitmap->GetSizePixel() );
123 tools::SetDefaultDeviceAntiAliasing( mpVDev );
126 void BitmapBackBuffer::updateVDev() const
128 OSL_ENSURE( !mbBitmapContentIsCurrent || !mbVDevContentIsCurrent,
129 "BitmapBackBuffer::updateVDev(): Both bitmap and VDev are valid?!" );
131 if( mpVDev && mbBitmapContentIsCurrent )
133 // fill with bitmap content
134 mpVDev->EnableMapMode( false );
135 mpVDev->SetAntialiasing( AntialiasingFlags::Enable );
136 const Point aEmptyPoint;
137 mpVDev->DrawBitmapEx( aEmptyPoint, *maBitmap );
140 // canvas queried the VDev, and will possibly paint into
141 // it. Next time, bitmap must be updated
142 mbBitmapContentIsCurrent = false;
143 mbVDevContentIsCurrent = true;
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */