xref: /haiku/headers/os/interface/Bitmap.h (revision 9e25244c5e9051f6cd333820d6332397361abd6c)
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 
13 class BView;
14 class BWindow;
15 namespace BPrivate {
16 	class BPrivateScreen;
17 }
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 		// 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 
45 class BBitmap : public BArchivable {
46 public:
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 	virtual						~BBitmap();
60 
61 	// Archiving
62 								BBitmap(BMessage* data);
63 	static	BArchivable*		Instantiate(BMessage* data);
64 	virtual	status_t			Archive(BMessage* data, bool deep = true) const;
65 
66 			status_t			InitCheck() const;
67 			bool				IsValid() const;
68 
69 			status_t			LockBits(uint32* state = NULL);
70 			void				UnlockBits();
71 
72 			area_id				Area() const;
73 			void*				Bits() const;
74 			int32				BitsLength() const;
75 			int32				BytesPerRow() const;
76 			color_space			ColorSpace() const;
77 			BRect				Bounds() const;
78 
79 			status_t			SetDrawingFlags(uint32 flags);
80 			uint32				Flags() const;
81 
82 			status_t			ImportBits(const void* data, int32 length,
83 									int32 bpr, int32 offset,
84 									color_space colorSpace);
85 			status_t			ImportBits(const void* data, int32 length,
86 									int32 bpr, color_space colorSpace,
87 									BPoint from, BPoint to, BSize size);
88 			status_t			ImportBits(const BBitmap* bitmap);
89 			status_t			ImportBits(const BBitmap* bitmap, BPoint from,
90 									BPoint to, BSize size);
91 
92 			status_t			GetOverlayRestrictions(
93 									overlay_restrictions* restrictions) const;
94 
95 	// to mimic a BWindow
96 	virtual	void				AddChild(BView* view);
97 	virtual	bool				RemoveChild(BView* view);
98 			int32				CountChildren() const;
99 			BView*				ChildAt(int32 index) const;
100 			BView*				FindView(const char* viewName) const;
101 			BView*				FindView(BPoint point) const;
102 			bool				Lock();
103 			void				Unlock();
104 			bool				IsLocked() const;
105 
106 			BBitmap&			operator=(const BBitmap& source);
107 
108 	class Private;
109 
110 public:
111 	// deprecated
112 			void				SetBits(const void* data, int32 length,
113 									int32 offset, color_space colorSpace);
114 
115 private:
116 			status_t			ImportBits(const void* data, int32 length,
117 									int32 bpr, color_space colorSpace,
118 									BPoint from, BPoint to, int32 width, int32 height);
119 			status_t			ImportBits(const BBitmap* bitmap, BPoint from,
120 									BPoint to, int32 width, int32 height);
121 
122 private:
123 	friend class BView;
124 	friend class BApplication;
125 	friend class ::BPrivate::BPrivateScreen;
126 	friend class Private;
127 
128 	virtual	status_t			Perform(perform_code d, void* arg);
129 	virtual	void				_ReservedBitmap1();
130 	virtual	void				_ReservedBitmap2();
131 	virtual	void				_ReservedBitmap3();
132 
133 			int32				_ServerToken() const;
134 			void				_InitObject(BRect bounds,
135 									color_space colorSpace, uint32 flags,
136 									int32 bytesPerRow, screen_id screenID);
137 			void				_CleanUp();
138 			void				_AssertPointer();
139 
140 			void				_ReconnectToAppServer();
141 
142 private:
143 			uint8*				fBasePointer;
144 			int32				fSize;
145 			color_space			fColorSpace;
146 			BRect				fBounds;
147 			int32				fBytesPerRow;
148 			BWindow*			fWindow;
149 			int32				fServerToken;
150 			int32				fAreaOffset;
151 			uint8				unused;
152 			area_id				fArea;
153 			area_id				fServerArea;
154 			uint32				fFlags;
155 			status_t			fInitError;
156 };
157 
158 #endif	// _BITMAP_H
159