1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _VCLCANVAS_BITMAPBACKBUFFER_HXX_
29 #define _VCLCANVAS_BITMAPBACKBUFFER_HXX_
30 
31 #include <vcl/virdev.hxx>
32 #include <vcl/bitmapex.hxx>
33 
34 #include <canvas/vclwrapper.hxx>
35 #include "outdevprovider.hxx"
36 
37 #include <boost/shared_ptr.hpp>
38 
39 
40 namespace vclcanvas
41 {
42     /** Backbuffer implementation for canvas bitmap.
43 
44     	This class abstracts away the renderable bitmap for the bitmap
45     	canvas. The actual VirtualDevice is only created when
46     	necessary, which makes read-only bitmaps a lot smaller.
47     */
48 	class BitmapBackBuffer : public OutDevProvider
49     {
50     public:
51         /** Create a backbuffer for given reference device
52          */
53         BitmapBackBuffer( const BitmapEx& 		rBitmap,
54                           const OutputDevice& 	rRefDevice );
55 
56         ~BitmapBackBuffer();
57 
58         virtual OutputDevice& 		getOutDev();
59         virtual const OutputDevice& getOutDev() const;
60 
61         /// Clear the underlying bitmap to white, all transparent
62         void clear();
63 
64         /** Exposing our internal bitmap. Only to be used from
65             CanvasBitmapHelper
66 
67         	@internal
68         */
69         BitmapEx&					getBitmapReference();
70         Size						getBitmapSizePixel() const;
71 
72     private:
73         void createVDev() const;
74         void updateVDev() const;
75 
76         ::canvas::vcltools::VCLObject<BitmapEx>	maBitmap;
77         mutable VirtualDevice*					mpVDev; // created only on demand
78 
79         const OutputDevice& 					mrRefDevice;
80 
81         /** When true, the bitmap contains the last valid
82             content. When false, and mbVDevContentIsCurrent is true,
83             the VDev contains the last valid content (which must be
84             copied back to the bitmap, when getBitmapReference() is
85             called). When both are false, this object is just
86             initialized.
87          */
88         mutable bool							mbBitmapContentIsCurrent;
89 
90         /** When true, and mpVDev is non-NULL, the VDev contains the
91             last valid content. When false, and
92             mbBitmapContentIsCurrent is true, the bitmap contains the
93             last valid content. When both are false, this object is
94             just initialized.
95          */
96         mutable bool							mbVDevContentIsCurrent;
97     };
98 
99     typedef ::boost::shared_ptr< BitmapBackBuffer > BitmapBackBufferSharedPtr;
100 
101 }
102 
103 #endif /* #ifndef _VCLCANVAS_BITMAPBACKBUFFER_HXX_ */
104 
105