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