/src/libreoffice/canvas/source/vcl/bitmapbackbuffer.cxx
Line | Count | Source |
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/bitmap.hxx> |
24 | | #include <vcl/svapp.hxx> |
25 | | |
26 | | #include "bitmapbackbuffer.hxx" |
27 | | #include "impltools.hxx" |
28 | | |
29 | | namespace vclcanvas |
30 | | { |
31 | | BitmapBackBuffer::BitmapBackBuffer( const ::Bitmap& rBitmap, |
32 | | const OutputDevice& rRefDevice ) : |
33 | 0 | maBitmap( rBitmap ), |
34 | 0 | mpVDev( nullptr ), |
35 | 0 | mrRefDevice( rRefDevice ), |
36 | 0 | mbBitmapContentIsCurrent( false ), |
37 | 0 | mbVDevContentIsCurrent( false ) |
38 | 0 | { |
39 | 0 | } |
40 | | |
41 | | BitmapBackBuffer::~BitmapBackBuffer() |
42 | 0 | { |
43 | | // make sure solar mutex is held on deletion (other methods |
44 | | // are supposed to be called with already locked solar mutex) |
45 | 0 | SolarMutexGuard aGuard; |
46 | |
|
47 | 0 | mpVDev.disposeAndClear(); |
48 | 0 | } |
49 | | |
50 | | OutputDevice& BitmapBackBuffer::getOutDev() |
51 | 0 | { |
52 | 0 | createVDev(); |
53 | 0 | updateVDev(); |
54 | 0 | return *mpVDev; |
55 | 0 | } |
56 | | |
57 | | const OutputDevice& BitmapBackBuffer::getOutDev() const |
58 | 0 | { |
59 | 0 | createVDev(); |
60 | 0 | updateVDev(); |
61 | 0 | return *mpVDev; |
62 | 0 | } |
63 | | |
64 | | void BitmapBackBuffer::clear() |
65 | 0 | { |
66 | | // force current content to bitmap, make all transparent white |
67 | 0 | getBitmapReference().Erase(COL_TRANSPARENT); |
68 | 0 | } |
69 | | |
70 | | ::Bitmap& BitmapBackBuffer::getBitmapReference() |
71 | 0 | { |
72 | 0 | OSL_ENSURE( !mbBitmapContentIsCurrent || !mbVDevContentIsCurrent, |
73 | 0 | "BitmapBackBuffer::getBitmapReference(): Both bitmap and VDev are valid?!" ); |
74 | |
|
75 | 0 | if( mbVDevContentIsCurrent && mpVDev ) |
76 | 0 | { |
77 | | // VDev content is more current than bitmap - copy contents before! |
78 | 0 | mpVDev->EnableMapMode( false ); |
79 | 0 | mpVDev->SetAntialiasing( AntialiasingFlags::Enable ); |
80 | 0 | const Point aEmptyPoint; |
81 | 0 | *maBitmap = mpVDev->GetBitmap( aEmptyPoint, |
82 | 0 | mpVDev->GetOutputSizePixel() ); |
83 | 0 | } |
84 | | |
85 | | // client queries bitmap, and will possibly alter content - |
86 | | // next time, VDev needs to be updated |
87 | 0 | mbBitmapContentIsCurrent = true; |
88 | 0 | mbVDevContentIsCurrent = false; |
89 | |
|
90 | 0 | return *maBitmap; |
91 | 0 | } |
92 | | |
93 | | Size BitmapBackBuffer::getBitmapSizePixel() const |
94 | 0 | { |
95 | 0 | Size aSize = maBitmap->GetSizePixel(); |
96 | |
|
97 | 0 | if( mbVDevContentIsCurrent && mpVDev ) |
98 | 0 | { |
99 | 0 | mpVDev->EnableMapMode( false ); |
100 | 0 | mpVDev->SetAntialiasing( AntialiasingFlags::Enable ); |
101 | 0 | aSize = mpVDev->GetOutputSizePixel(); |
102 | 0 | } |
103 | |
|
104 | 0 | return aSize; |
105 | 0 | } |
106 | | |
107 | | void BitmapBackBuffer::createVDev() const |
108 | 0 | { |
109 | 0 | if( mpVDev ) |
110 | 0 | return; |
111 | | |
112 | | // VDev not yet created, do it now. Create an alpha-VDev, |
113 | | // if bitmap has transparency. |
114 | 0 | mpVDev = maBitmap->HasAlpha() ? |
115 | 0 | VclPtr<VirtualDevice>::Create( mrRefDevice, DeviceFormat::WITH_ALPHA ) : |
116 | 0 | VclPtr<VirtualDevice>::Create( mrRefDevice ); |
117 | |
|
118 | 0 | OSL_ENSURE( mpVDev, |
119 | 0 | "BitmapBackBuffer::createVDev(): Unable to create VirtualDevice" ); |
120 | |
|
121 | 0 | mpVDev->SetOutputSizePixel( maBitmap->GetSizePixel() ); |
122 | |
|
123 | 0 | vclcanvastools::SetDefaultDeviceAntiAliasing( mpVDev ); |
124 | 0 | } |
125 | | |
126 | | void BitmapBackBuffer::updateVDev() const |
127 | 0 | { |
128 | 0 | OSL_ENSURE( !mbBitmapContentIsCurrent || !mbVDevContentIsCurrent, |
129 | 0 | "BitmapBackBuffer::updateVDev(): Both bitmap and VDev are valid?!" ); |
130 | |
|
131 | 0 | if( mpVDev && mbBitmapContentIsCurrent ) |
132 | 0 | { |
133 | | // fill with bitmap content |
134 | 0 | mpVDev->EnableMapMode( false ); |
135 | 0 | mpVDev->SetAntialiasing( AntialiasingFlags::Enable ); |
136 | 0 | const Point aEmptyPoint; |
137 | 0 | mpVDev->DrawBitmap( aEmptyPoint, *maBitmap ); |
138 | 0 | } |
139 | | |
140 | | // canvas queried the VDev, and will possibly paint into |
141 | | // it. Next time, bitmap must be updated |
142 | 0 | mbBitmapContentIsCurrent = false; |
143 | 0 | mbVDevContentIsCurrent = true; |
144 | 0 | } |
145 | | } |
146 | | |
147 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |