1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _VCLCANVAS_BITMAPBACKBUFFER_HXX_
25 #define _VCLCANVAS_BITMAPBACKBUFFER_HXX_
26 
27 #include <vcl/virdev.hxx>
28 #include <vcl/bitmapex.hxx>
29 
30 #include <canvas/vclwrapper.hxx>
31 #include "outdevprovider.hxx"
32 
33 #include <boost/shared_ptr.hpp>
34 
35 
36 namespace vclcanvas
37 {
38     /** Backbuffer implementation for canvas bitmap.
39 
40     	This class abstracts away the renderable bitmap for the bitmap
41     	canvas. The actual VirtualDevice is only created when
42     	necessary, which makes read-only bitmaps a lot smaller.
43     */
44 	class BitmapBackBuffer : public OutDevProvider
45     {
46     public:
47         /** Create a backbuffer for given reference device
48          */
49         BitmapBackBuffer( const BitmapEx& 		rBitmap,
50                           const OutputDevice& 	rRefDevice );
51 
52         ~BitmapBackBuffer();
53 
54         virtual OutputDevice& 		getOutDev();
55         virtual const OutputDevice& getOutDev() const;
56 
57         /// Clear the underlying bitmap to white, all transparent
58         void clear();
59 
60         /** Exposing our internal bitmap. Only to be used from
61             CanvasBitmapHelper
62 
63         	@internal
64         */
65         BitmapEx&					getBitmapReference();
66         Size						getBitmapSizePixel() const;
67 
68     private:
69         void createVDev() const;
70         void updateVDev() const;
71 
72         ::canvas::vcltools::VCLObject<BitmapEx>	maBitmap;
73         mutable VirtualDevice*					mpVDev; // created only on demand
74 
75         const OutputDevice& 					mrRefDevice;
76 
77         /** When true, the bitmap contains the last valid
78             content. When false, and mbVDevContentIsCurrent is true,
79             the VDev contains the last valid content (which must be
80             copied back to the bitmap, when getBitmapReference() is
81             called). When both are false, this object is just
82             initialized.
83          */
84         mutable bool							mbBitmapContentIsCurrent;
85 
86         /** When true, and mpVDev is non-NULL, the VDev contains the
87             last valid content. When false, and
88             mbBitmapContentIsCurrent is true, the bitmap contains the
89             last valid content. When both are false, this object is
90             just initialized.
91          */
92         mutable bool							mbVDevContentIsCurrent;
93     };
94 
95     typedef ::boost::shared_ptr< BitmapBackBuffer > BitmapBackBufferSharedPtr;
96 
97 }
98 
99 #endif /* #ifndef _VCLCANVAS_BITMAPBACKBUFFER_HXX_ */
100 
101