Line data Source code
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 :
21 : #include "bitmapbackbuffer.hxx"
22 :
23 : #include <osl/mutex.hxx>
24 :
25 : #include <vcl/svapp.hxx>
26 : #include <vcl/bitmapex.hxx>
27 : #include <vcl/bmpacc.hxx>
28 :
29 :
30 : namespace vclcanvas
31 : {
32 0 : BitmapBackBuffer::BitmapBackBuffer( const BitmapEx& rBitmap,
33 : const OutputDevice& rRefDevice ) :
34 : maBitmap( rBitmap ),
35 : mpVDev( NULL ),
36 : mrRefDevice( rRefDevice ),
37 : mbBitmapContentIsCurrent( false ),
38 0 : mbVDevContentIsCurrent( false )
39 : {
40 0 : }
41 :
42 0 : BitmapBackBuffer::~BitmapBackBuffer()
43 : {
44 : // make sure solar mutex is held on deletion (other methods
45 : // are supposed to be called with already locked solar mutex)
46 0 : SolarMutexGuard aGuard;
47 :
48 0 : mpVDev.disposeAndClear();
49 0 : }
50 :
51 0 : OutputDevice& BitmapBackBuffer::getOutDev()
52 : {
53 0 : createVDev();
54 0 : updateVDev();
55 0 : return *mpVDev;
56 : }
57 :
58 0 : const OutputDevice& BitmapBackBuffer::getOutDev() const
59 : {
60 0 : createVDev();
61 0 : updateVDev();
62 0 : return *mpVDev;
63 : }
64 :
65 0 : void BitmapBackBuffer::clear()
66 : {
67 : // force current content to bitmap, make all transparent white
68 0 : getBitmapReference().Erase(COL_TRANSPARENT);
69 0 : }
70 :
71 0 : BitmapEx& BitmapBackBuffer::getBitmapReference()
72 : {
73 : OSL_ENSURE( !mbBitmapContentIsCurrent || !mbVDevContentIsCurrent,
74 : "BitmapBackBuffer::getBitmapReference(): Both bitmap and VDev are valid?!" );
75 :
76 0 : if( mbVDevContentIsCurrent && mpVDev )
77 : {
78 : // VDev content is more current than bitmap - copy contents before!
79 0 : mpVDev->EnableMapMode( false );
80 0 : mpVDev->SetAntialiasing( AntialiasingFlags::EnableB2dDraw );
81 0 : const Point aEmptyPoint;
82 0 : *maBitmap = mpVDev->GetBitmapEx( aEmptyPoint,
83 0 : mpVDev->GetOutputSizePixel() );
84 : }
85 :
86 : // client queries bitmap, and will possibly alter content -
87 : // next time, VDev needs to be updated
88 0 : mbBitmapContentIsCurrent = true;
89 0 : mbVDevContentIsCurrent = false;
90 :
91 0 : return *maBitmap;
92 : }
93 :
94 0 : Size BitmapBackBuffer::getBitmapSizePixel() const
95 : {
96 0 : Size aSize = maBitmap->GetSizePixel();
97 :
98 0 : if( mbVDevContentIsCurrent && mpVDev )
99 : {
100 0 : mpVDev->EnableMapMode( false );
101 0 : mpVDev->SetAntialiasing( AntialiasingFlags::EnableB2dDraw );
102 0 : aSize = mpVDev->GetOutputSizePixel();
103 : }
104 :
105 0 : return aSize;
106 : }
107 :
108 0 : void BitmapBackBuffer::createVDev() const
109 : {
110 0 : if( !mpVDev )
111 : {
112 : // VDev not yet created, do it now. Create an alpha-VDev,
113 : // if bitmap has transparency.
114 0 : mpVDev = maBitmap->IsTransparent() ?
115 : VclPtr<VirtualDevice>::Create( mrRefDevice, 0, 0 ) :
116 0 : VclPtr<VirtualDevice>::Create( mrRefDevice );
117 :
118 : OSL_ENSURE( mpVDev,
119 : "BitmapBackBuffer::createVDev(): Unable to create VirtualDevice" );
120 :
121 0 : mpVDev->SetOutputSizePixel( maBitmap->GetSizePixel() );
122 :
123 : // #i95645#
124 : #if defined( MACOSX )
125 : // use AA on VCLCanvas for Mac
126 : mpVDev->SetAntialiasing( AntialiasingFlags::EnableB2dDraw | mpVDev->GetAntialiasing() );
127 : #else
128 : // switch off AA for WIN32 and UNIX, the VCLCanvas does not look good with it and
129 : // is not required to do AA. It would need to be adapted to use it correctly
130 : // (especially gradient painting). This will need extra work.
131 0 : mpVDev->SetAntialiasing(mpVDev->GetAntialiasing() & ~AntialiasingFlags::EnableB2dDraw);
132 : #endif
133 : }
134 0 : }
135 :
136 0 : void BitmapBackBuffer::updateVDev() const
137 : {
138 : OSL_ENSURE( !mbBitmapContentIsCurrent || !mbVDevContentIsCurrent,
139 : "BitmapBackBuffer::updateVDev(): Both bitmap and VDev are valid?!" );
140 :
141 0 : if( mpVDev && mbBitmapContentIsCurrent )
142 : {
143 : // fill with bitmap content
144 0 : mpVDev->EnableMapMode( false );
145 0 : mpVDev->SetAntialiasing( AntialiasingFlags::EnableB2dDraw );
146 0 : const Point aEmptyPoint;
147 0 : mpVDev->DrawBitmapEx( aEmptyPoint, *maBitmap );
148 : }
149 :
150 : // canvas queried the VDev, and will possibly paint into
151 : // it. Next time, bitmap must be updated
152 0 : mbBitmapContentIsCurrent = false;
153 0 : mbVDevContentIsCurrent = true;
154 0 : }
155 : }
156 :
157 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|