xref: /AOO41X/main/canvas/source/vcl/bitmapbackbuffer.cxx (revision 47148b3bc50811ceb41802e4cc50a5db21535900)
125ea7f45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
325ea7f45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
425ea7f45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
525ea7f45SAndrew Rist  * distributed with this work for additional information
625ea7f45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
725ea7f45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
825ea7f45SAndrew Rist  * "License"); you may not use this file except in compliance
925ea7f45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
1125ea7f45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
1325ea7f45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1425ea7f45SAndrew Rist  * software distributed under the License is distributed on an
1525ea7f45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1625ea7f45SAndrew Rist  * KIND, either express or implied.  See the License for the
1725ea7f45SAndrew Rist  * specific language governing permissions and limitations
1825ea7f45SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
2025ea7f45SAndrew Rist  *************************************************************/
2125ea7f45SAndrew Rist 
2225ea7f45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_canvas.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "bitmapbackbuffer.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <osl/mutex.hxx>
30cdf0e10cSrcweir #include <vos/mutex.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <vcl/svapp.hxx>
33cdf0e10cSrcweir #include <vcl/bitmapex.hxx>
34cdf0e10cSrcweir #include <vcl/bmpacc.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace vclcanvas
38cdf0e10cSrcweir {
BitmapBackBuffer(const BitmapEx & rBitmap,const OutputDevice & rRefDevice)39cdf0e10cSrcweir     BitmapBackBuffer::BitmapBackBuffer( const BitmapEx& 		rBitmap,
40cdf0e10cSrcweir                                         const OutputDevice& 	rRefDevice ) :
41cdf0e10cSrcweir         maBitmap( rBitmap ),
42cdf0e10cSrcweir         mpVDev( NULL ),
43cdf0e10cSrcweir         mrRefDevice( rRefDevice ),
44cdf0e10cSrcweir         mbBitmapContentIsCurrent( false ),
45cdf0e10cSrcweir         mbVDevContentIsCurrent( false )
46cdf0e10cSrcweir     {
47cdf0e10cSrcweir     }
48cdf0e10cSrcweir 
~BitmapBackBuffer()49cdf0e10cSrcweir     BitmapBackBuffer::~BitmapBackBuffer()
50cdf0e10cSrcweir     {
51cdf0e10cSrcweir         // make sure solar mutex is held on deletion (other methods
52cdf0e10cSrcweir         // are supposed to be called with already locked solar mutex)
53cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
54cdf0e10cSrcweir 
55cdf0e10cSrcweir         if( mpVDev )
56cdf0e10cSrcweir             delete mpVDev;
57cdf0e10cSrcweir     }
58cdf0e10cSrcweir 
getOutDev()59cdf0e10cSrcweir     OutputDevice& BitmapBackBuffer::getOutDev()
60cdf0e10cSrcweir     {
61cdf0e10cSrcweir         createVDev();
62cdf0e10cSrcweir         updateVDev();
63cdf0e10cSrcweir         return *mpVDev;
64cdf0e10cSrcweir     }
65cdf0e10cSrcweir 
getOutDev() const66cdf0e10cSrcweir     const OutputDevice& BitmapBackBuffer::getOutDev() const
67cdf0e10cSrcweir     {
68cdf0e10cSrcweir         createVDev();
69cdf0e10cSrcweir         updateVDev();
70cdf0e10cSrcweir         return *mpVDev;
71cdf0e10cSrcweir     }
72cdf0e10cSrcweir 
clear()73cdf0e10cSrcweir     void BitmapBackBuffer::clear()
74cdf0e10cSrcweir     {
75cdf0e10cSrcweir         // force current content to bitmap, make all transparent white
76cdf0e10cSrcweir         getBitmapReference().Erase(COL_TRANSPARENT);
77cdf0e10cSrcweir     }
78cdf0e10cSrcweir 
getBitmapReference()79cdf0e10cSrcweir     BitmapEx& BitmapBackBuffer::getBitmapReference()
80cdf0e10cSrcweir     {
81cdf0e10cSrcweir         OSL_ENSURE( !mbBitmapContentIsCurrent || !mbVDevContentIsCurrent,
82cdf0e10cSrcweir                     "BitmapBackBuffer::getBitmapReference(): Both bitmap and VDev are valid?!" );
83cdf0e10cSrcweir 
84cdf0e10cSrcweir         if( mbVDevContentIsCurrent && mpVDev )
85cdf0e10cSrcweir         {
86cdf0e10cSrcweir             // VDev content is more current than bitmap - copy contents before!
87cdf0e10cSrcweir             mpVDev->EnableMapMode( sal_False );
88*5f27b83cSArmin Le Grand             mpVDev->SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW );
89cdf0e10cSrcweir             const Point aEmptyPoint;
90cdf0e10cSrcweir             *maBitmap = mpVDev->GetBitmapEx( aEmptyPoint,
91cdf0e10cSrcweir                                              mpVDev->GetOutputSizePixel() );
92cdf0e10cSrcweir         }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir         // client queries bitmap, and will possibly alter content -
95cdf0e10cSrcweir         // next time, VDev needs to be updated
96cdf0e10cSrcweir         mbBitmapContentIsCurrent = true;
97cdf0e10cSrcweir         mbVDevContentIsCurrent 	 = false;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         return *maBitmap;
100cdf0e10cSrcweir     }
101cdf0e10cSrcweir 
getBitmapSizePixel() const102cdf0e10cSrcweir     Size BitmapBackBuffer::getBitmapSizePixel() const
103cdf0e10cSrcweir     {
104cdf0e10cSrcweir         Size aSize = maBitmap->GetSizePixel();
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         if( mbVDevContentIsCurrent && mpVDev )
107cdf0e10cSrcweir         {
108cdf0e10cSrcweir             mpVDev->EnableMapMode( sal_False );
109*5f27b83cSArmin Le Grand             mpVDev->SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW );
110cdf0e10cSrcweir             aSize = mpVDev->GetOutputSizePixel();
111cdf0e10cSrcweir         }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir         return aSize;
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir 
createVDev() const116cdf0e10cSrcweir     void BitmapBackBuffer::createVDev() const
117cdf0e10cSrcweir     {
118cdf0e10cSrcweir         if( !mpVDev )
119cdf0e10cSrcweir         {
120cdf0e10cSrcweir             // VDev not yet created, do it now. Create an alpha-VDev,
121cdf0e10cSrcweir             // if bitmap has transparency.
122cdf0e10cSrcweir             mpVDev = maBitmap->IsTransparent() ?
123cdf0e10cSrcweir                 new VirtualDevice( mrRefDevice, 0, 0 ) :
124cdf0e10cSrcweir                 new VirtualDevice( mrRefDevice );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir             OSL_ENSURE( mpVDev,
127cdf0e10cSrcweir                         "BitmapBackBuffer::createVDev(): Unable to create VirtualDevice" );
128cdf0e10cSrcweir 
129cdf0e10cSrcweir             mpVDev->SetOutputSizePixel( maBitmap->GetSizePixel() );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir             // #i95645#
132cdf0e10cSrcweir #if defined( QUARTZ )
133cdf0e10cSrcweir             // use AA on VCLCanvas for Mac
134cdf0e10cSrcweir 			mpVDev->SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW | mpVDev->GetAntialiasing() );
135cdf0e10cSrcweir #else
136cdf0e10cSrcweir             // switch off AA for WIN32 and UNIX, the VCLCanvas does not look good with it and
137cdf0e10cSrcweir             // is not required to do AA. It would need to be adapted to use it correctly
138cdf0e10cSrcweir             // (especially gradient painting). This will need extra work.
139cdf0e10cSrcweir 			mpVDev->SetAntialiasing(mpVDev->GetAntialiasing() & ~ANTIALIASING_ENABLE_B2DDRAW);
140cdf0e10cSrcweir #endif
141cdf0e10cSrcweir         }
142cdf0e10cSrcweir     }
143cdf0e10cSrcweir 
updateVDev() const144cdf0e10cSrcweir     void BitmapBackBuffer::updateVDev() const
145cdf0e10cSrcweir     {
146cdf0e10cSrcweir         OSL_ENSURE( !mbBitmapContentIsCurrent || !mbVDevContentIsCurrent,
147cdf0e10cSrcweir                     "BitmapBackBuffer::updateVDev(): Both bitmap and VDev are valid?!" );
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         if( mpVDev && mbBitmapContentIsCurrent )
150cdf0e10cSrcweir         {
151cdf0e10cSrcweir             // fill with bitmap content
152cdf0e10cSrcweir             mpVDev->EnableMapMode( sal_False );
153*5f27b83cSArmin Le Grand             mpVDev->SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW );
154cdf0e10cSrcweir             const Point aEmptyPoint;
155cdf0e10cSrcweir             mpVDev->DrawBitmapEx( aEmptyPoint, *maBitmap );
156cdf0e10cSrcweir         }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir         // canvas queried the VDev, and will possibly paint into
159cdf0e10cSrcweir         // it. Next time, bitmap must be updated
160cdf0e10cSrcweir         mbBitmapContentIsCurrent = false;
161cdf0e10cSrcweir         mbVDevContentIsCurrent 	 = true;
162cdf0e10cSrcweir     }
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165