1/*
2 * Copyright 2001-2007, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef	_BITMAP_H
6#define	_BITMAP_H
7
8
9#include <Archivable.h>
10#include <InterfaceDefs.h>
11#include <Rect.h>
12
13class BView;
14class BWindow;
15namespace BPrivate {
16	class BPrivateScreen;
17}
18
19enum {
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		// Offscreen but non-overlay bitmaps are not supported on Haiku,
27		// but appearantly never were on BeOS either! The accelerant API
28		// would need to be extended to so that the app_server can ask
29		// the graphics driver to reserve memory for a bitmap and for this
30		// to make any sense, an accelerated blit from this memory into
31		// the framebuffer needs to be added to the API as well.
32	B_BITMAP_WILL_OVERLAY				= 0x00000040 | B_BITMAP_IS_OFFSCREEN,
33	B_BITMAP_RESERVE_OVERLAY_CHANNEL	= 0x00000080,
34
35	// Haiku extensions:
36	B_BITMAP_NO_SERVER_LINK				= 0x00000100,
37		// Cheap to create, object will manage memory itself,
38		// no BApplication needs to run, but one can't draw such
39		// a BBitmap.
40};
41
42#define B_ANY_BYTES_PER_ROW	-1
43
44
45class BBitmap : public BArchivable {
46public:
47								BBitmap(BRect bounds, uint32 flags,
48									color_space colorSpace,
49									int32 bytesPerRow = B_ANY_BYTES_PER_ROW,
50									screen_id screenID = B_MAIN_SCREEN_ID);
51								BBitmap(BRect bounds, color_space colorSpace,
52									bool acceptsViews = false,
53									bool needsContiguous = false);
54								BBitmap(const BBitmap& source, uint32 flags);
55								BBitmap(const BBitmap& source);
56								BBitmap(const BBitmap* source,
57									bool acceptsViews = false,
58									bool needsContiguous = false);
59								BBitmap(area_id area, ptrdiff_t areaOffset,
60									BRect bounds, uint32 flags,
61									color_space colorSpace,
62									int32 bytesPerRow = B_ANY_BYTES_PER_ROW,
63									screen_id screenID = B_MAIN_SCREEN_ID);
64	virtual						~BBitmap();
65
66	// Archiving
67								BBitmap(BMessage* data);
68	static	BArchivable*		Instantiate(BMessage* data);
69	virtual	status_t			Archive(BMessage* data, bool deep = true) const;
70
71			status_t			InitCheck() const;
72			bool				IsValid() const;
73
74			status_t			LockBits(uint32* state = NULL);
75			void				UnlockBits();
76
77			area_id				Area() const;
78			void*				Bits() const;
79			int32				BitsLength() const;
80			int32				BytesPerRow() const;
81			color_space			ColorSpace() const;
82			BRect				Bounds() const;
83
84			status_t			SetDrawingFlags(uint32 flags);
85			uint32				Flags() const;
86
87			status_t			ImportBits(const void* data, int32 length,
88									int32 bpr, int32 offset,
89									color_space colorSpace);
90			status_t			ImportBits(const void* data, int32 length,
91									int32 bpr, color_space colorSpace,
92									BPoint from, BPoint to, BSize size);
93			status_t			ImportBits(const BBitmap* bitmap);
94			status_t			ImportBits(const BBitmap* bitmap, BPoint from,
95									BPoint to, BSize size);
96
97			status_t			GetOverlayRestrictions(
98									overlay_restrictions* restrictions) const;
99
100	// to mimic a BWindow
101	virtual	void				AddChild(BView* view);
102	virtual	bool				RemoveChild(BView* view);
103			int32				CountChildren() const;
104			BView*				ChildAt(int32 index) const;
105			BView*				FindView(const char* viewName) const;
106			BView*				FindView(BPoint point) const;
107			bool				Lock();
108			void				Unlock();
109			bool				IsLocked() const;
110
111			BBitmap&			operator=(const BBitmap& source);
112
113	class Private;
114
115public:
116	// deprecated
117			void				SetBits(const void* data, int32 length,
118									int32 offset, color_space colorSpace);
119
120private:
121			status_t			ImportBits(const void* data, int32 length,
122									int32 bpr, color_space colorSpace,
123									BPoint from, BPoint to, int32 width, int32 height);
124			status_t			ImportBits(const BBitmap* bitmap, BPoint from,
125									BPoint to, int32 width, int32 height);
126
127private:
128	friend class BView;
129	friend class BApplication;
130	friend class ::BPrivate::BPrivateScreen;
131	friend class Private;
132
133	virtual	status_t			Perform(perform_code d, void* arg);
134	virtual	void				_ReservedBitmap1();
135	virtual	void				_ReservedBitmap2();
136	virtual	void				_ReservedBitmap3();
137
138			int32				_ServerToken() const;
139			void				_InitObject(BRect bounds,
140									color_space colorSpace, uint32 flags,
141									int32 bytesPerRow, screen_id screenID,
142									area_id area = -1,
143									ptrdiff_t areaOffset = 0);
144			void				_CleanUp();
145			void				_AssertPointer();
146
147			void				_ReconnectToAppServer();
148
149private:
150			uint8*				fBasePointer;
151			int32				fSize;
152			color_space			fColorSpace;
153			BRect				fBounds;
154			int32				fBytesPerRow;
155			BWindow*			fWindow;
156			int32				fServerToken;
157			int32				fAreaOffset;
158			uint8				unused;
159			area_id				fArea;
160			area_id				fServerArea;
161			uint32				fFlags;
162			status_t			fInitError;
163};
164
165#endif	// _BITMAP_H
166