xref: /haiku/headers/os/interface/Bitmap.h (revision 4bd0c1066b227cec4b79883bdef697c7a27f2e90)
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 			void				SetBits(const void* data, int32 length,
83 									int32 offset, color_space colorSpace);
84 
85 	// not part of the R5 API
86 			status_t			ImportBits(const void* data, int32 length,
87 									int32 bpr, int32 offset,
88 									color_space colorSpace);
89 			status_t			ImportBits(const void* data, int32 length,
90 									int32 bpr, color_space colorSpace,
91 									BPoint from, BPoint to, int32 width,
92 									int32 height);
93 			status_t			ImportBits(const BBitmap* bitmap);
94 			status_t			ImportBits(const BBitmap* bitmap, BPoint from,
95 									BPoint to, int32 width, int32 height);
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 private:
115 	friend class BView;
116 	friend class BApplication;
117 	friend class ::BPrivate::BPrivateScreen;
118 	friend class Private;
119 
120 	virtual	status_t			Perform(perform_code d, void* arg);
121 	virtual	void				_ReservedBitmap1();
122 	virtual	void				_ReservedBitmap2();
123 	virtual	void				_ReservedBitmap3();
124 
125 			int32				_ServerToken() const;
126 			void				_InitObject(BRect bounds,
127 									color_space colorSpace, uint32 flags,
128 									int32 bytesPerRow, screen_id screenID);
129 			void				_CleanUp();
130 			void				_AssertPointer();
131 
132 			void				_ReconnectToAppServer();
133 
134 private:
135 			uint8*				fBasePointer;
136 			int32				fSize;
137 			color_space			fColorSpace;
138 			BRect				fBounds;
139 			int32				fBytesPerRow;
140 			BWindow*			fWindow;
141 			int32				fServerToken;
142 			int32				fAreaOffset;
143 			uint8				unused;
144 			area_id				fArea;
145 			area_id				fServerArea;
146 			uint32				fFlags;
147 			status_t			fInitError;
148 };
149 
150 #endif	// _BITMAP_H
151