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