xref: /haiku/headers/os/interface/Bitmap.h (revision d3d8b26997fac34a84981e6d2b649521de2cc45a)
1 /*
2  * Copyright 2001-2006, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Ingo Weinhold (bonefish@users.sf.net)
7  */
8 #ifndef	_BITMAP_H
9 #define	_BITMAP_H
10 
11 
12 #include <Archivable.h>
13 #include <InterfaceDefs.h>
14 #include <Rect.h>
15 
16 class BPrivateScreen;
17 class BWindow;
18 
19 enum {
20 	B_BITMAP_CLEAR_TO_WHITE				= 0x00000001,
21 	B_BITMAP_ACCEPTS_VIEWS				= 0x00000002,
22 	B_BITMAP_IS_AREA					= 0x00000004,
23 	B_BITMAP_IS_LOCKED					= 0x00000008 | B_BITMAP_IS_AREA,
24 	B_BITMAP_IS_CONTIGUOUS				= 0x00000010 | B_BITMAP_IS_LOCKED,
25 	B_BITMAP_IS_OFFSCREEN				= 0x00000020,
26 	B_BITMAP_WILL_OVERLAY				= 0x00000040 | B_BITMAP_IS_OFFSCREEN,
27 	B_BITMAP_RESERVE_OVERLAY_CHANNEL	= 0x00000080,
28 	B_BITMAP_NO_SERVER_LINK				= 0x00000100
29 };
30 
31 #define B_ANY_BYTES_PER_ROW	-1
32 
33 
34 class BBitmap : public BArchivable {
35 	public:
36 		BBitmap(BRect bounds, uint32 flags, color_space colorSpace,
37 				int32 bytesPerRow = B_ANY_BYTES_PER_ROW,
38 				screen_id screenID = B_MAIN_SCREEN_ID);
39 		BBitmap(BRect bounds, color_space colorSpace, bool acceptsViews = false,
40 				bool needsContiguous = false);
41 		BBitmap(const BBitmap *source, bool acceptsViews = false,
42 				bool needsContiguous = false);
43 		virtual ~BBitmap();
44 
45 		// Archiving
46 		BBitmap(BMessage *data);
47 		static BArchivable *Instantiate(BMessage *data);
48 		virtual status_t Archive(BMessage *data, bool deep = true) const;
49 
50 		status_t InitCheck() const;
51 		bool IsValid() const;
52 
53 		status_t LockBits(uint32 *state = NULL);
54 		void UnlockBits();
55 
56 		area_id Area() const;
57 		void *Bits() const;
58 		int32 BitsLength() const;
59 		int32 BytesPerRow() const;
60 		color_space ColorSpace() const;
61 		BRect Bounds() const;
62 		uint32 Flags() const;
63 
64 		void SetBits(const void *data, int32 length, int32 offset,
65 					 color_space colorSpace);
66 
67 		// not part of the R5 API
68 		status_t ImportBits(const void *data, int32 length, int32 bpr,
69 							int32 offset, color_space colorSpace);
70 		status_t ImportBits(const void *data, int32 length, int32 bpr,
71 							color_space colorSpace, BPoint from, BPoint to,
72 							int32 width, int32 height);
73 		status_t ImportBits(const BBitmap *bitmap);
74 		status_t ImportBits(const BBitmap *bitmap, BPoint from, BPoint to,
75 							int32 width, int32 height);
76 
77 		status_t GetOverlayRestrictions(overlay_restrictions *restrictions) const;
78 
79 		// to mimic a BWindow
80 		virtual void AddChild(BView *view);
81 		virtual bool RemoveChild(BView *view);
82 		int32 CountChildren() const;
83 		BView *ChildAt(int32 index) const;
84 		BView *FindView(const char *viewName) const;
85 		BView *FindView(BPoint point) const;
86 		bool Lock();
87 		void Unlock();
88 		bool IsLocked() const;
89 
90 		//----- Private or reserved -----------------------------------------//
91 
92 		virtual status_t Perform(perform_code d, void *arg);
93 
94 	private:
95 		friend class BView;
96 		friend class BApplication;
97 		friend class BPrivateScreen;
98 
99 		virtual void _ReservedBitmap1();
100 		virtual void _ReservedBitmap2();
101 		virtual void _ReservedBitmap3();
102 
103 		BBitmap(const BBitmap &);
104 		BBitmap &operator=(const BBitmap &);
105 
106 		int32 _ServerToken() const;
107 		void _InitObject(BRect bounds, color_space colorSpace, uint32 flags,
108 						int32 bytesPerRow, screen_id screenID);
109 		void _CleanUp();
110 		void _AssertPointer();
111 
112 		uint8		*fBasePointer;
113 		int32		fSize;
114 		color_space	fColorSpace;
115 		BRect		fBounds;
116 		int32		fBytesPerRow;
117 		BWindow		*fWindow;
118 		int32		fServerToken;
119 		int32		fAreaOffset;
120 		uint8		unused;
121 		area_id		fArea;
122 		area_id		fServerArea;
123 		uint32		fFlags;
124 		status_t	fInitError;
125 };
126 
127 #endif	// _BITMAP_H
128