LibreOffice Module canvas (master) 1
bitmapbackbuffer.cxx
Go to the documentation of this file.
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#include <sal/config.h>
21
22#include <osl/diagnose.h>
23#include <vcl/bitmapex.hxx>
24#include <vcl/svapp.hxx>
25
26#include "bitmapbackbuffer.hxx"
27#include "impltools.hxx"
28
29namespace vclcanvas
30{
32 const OutputDevice& rRefDevice ) :
33 maBitmap( rBitmap ),
34 mpVDev( nullptr ),
35 mrRefDevice( rRefDevice ),
36 mbBitmapContentIsCurrent( false ),
37 mbVDevContentIsCurrent( false )
38 {
39 }
40
42 {
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;
46
48 }
49
51 {
52 createVDev();
53 updateVDev();
54 return *mpVDev;
55 }
56
58 {
59 createVDev();
60 updateVDev();
61 return *mpVDev;
62 }
63
65 {
66 // force current content to bitmap, make all transparent white
68 }
69
71 {
73 "BitmapBackBuffer::getBitmapReference(): Both bitmap and VDev are valid?!" );
74
76 {
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() );
83 }
84
85 // client queries bitmap, and will possibly alter content -
86 // next time, VDev needs to be updated
89
90 return *maBitmap;
91 }
92
94 {
95 Size aSize = maBitmap->GetSizePixel();
96
98 {
99 mpVDev->EnableMapMode( false );
100 mpVDev->SetAntialiasing( AntialiasingFlags::Enable );
101 aSize = mpVDev->GetOutputSizePixel();
102 }
103
104 return aSize;
105 }
106
108 {
109 if( mpVDev )
110 return;
111
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 ) :
117
118 OSL_ENSURE( mpVDev,
119 "BitmapBackBuffer::createVDev(): Unable to create VirtualDevice" );
120
121 mpVDev->SetOutputSizePixel( maBitmap->GetSizePixel() );
122
124 }
125
127 {
129 "BitmapBackBuffer::updateVDev(): Both bitmap and VDev are valid?!" );
130
132 {
133 // fill with bitmap content
134 mpVDev->EnableMapMode( false );
135 mpVDev->SetAntialiasing( AntialiasingFlags::Enable );
136 const Point aEmptyPoint;
137 mpVDev->DrawBitmapEx( aEmptyPoint, *maBitmap );
138 }
139
140 // canvas queried the VDev, and will possibly paint into
141 // it. Next time, bitmap must be updated
144 }
145}
146
147/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool Erase(const Color &rFillColor)
bool IsAlpha() const
const Size & GetSizePixel() const
void disposeAndClear()
static VclPtr< reference_type > Create(Arg &&... arg)
bool mbVDevContentIsCurrent
When true, and mpVDev is non-NULL, the VDev contains the last valid content.
BitmapEx & getBitmapReference()
Exposing our internal bitmap.
BitmapBackBuffer(const BitmapEx &rBitmap, const OutputDevice &rRefDevice)
Create a backbuffer for given reference device.
const OutputDevice & mrRefDevice
virtual ~BitmapBackBuffer() override
VclPtr< VirtualDevice > mpVDev
virtual OutputDevice & getOutDev() override
::canvas::vcltools::VCLObject< BitmapEx > maBitmap
bool mbBitmapContentIsCurrent
When true, the bitmap contains the last valid content.
void clear()
Clear the underlying bitmap to white, all transparent.
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
void SetDefaultDeviceAntiAliasing(OutputDevice *pDevice)
Definition: impltools.cxx:248