xref: /haiku/src/servers/app/ServerBitmap.h (revision 23f179da55b1bd1ba84fbf3d3c56947e2c8d0aca)
1 /*
2  * Copyright 2001-2009, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		DarkWyrm <bpmagic@columbus.rr.com>
7  *		Axel Dörfler, axeld@pinc-software.de
8  */
9 #ifndef SERVER_BITMAP_H
10 #define SERVER_BITMAP_H
11 
12 
13 #include <GraphicsDefs.h>
14 #include <Rect.h>
15 #include <OS.h>
16 
17 #include <Referenceable.h>
18 
19 
20 class BitmapManager;
21 class ClientMemoryAllocator;
22 class HWInterface;
23 class Overlay;
24 class ServerApp;
25 
26 
27 /*!	\class ServerBitmap ServerBitmap.h
28 	\brief Bitmap class used inside the server.
29 
30 	This class is not directly allocated or freed. Instead, it is
31 	managed by the BitmapManager class. It is also the base class for
32 	all cursors. Every BBitmap has a shadow ServerBitmap object.
33 */
34 class ServerBitmap : public BReferenceable {
35 public:
36 	inline	bool			IsValid() const
37 								{ return fBuffer != NULL; }
38 
39 	inline	uint8*			Bits() const
40 								{ return fBuffer; }
41 	inline	uint32			BitsLength() const
42 								{ return (uint32)(fBytesPerRow * fHeight); }
43 
44 	inline	BRect			Bounds() const
45 								{ return BRect(0, 0, fWidth - 1, fHeight - 1); }
46 	inline	int32			Width() const
47 								{ return fWidth; }
48 	inline	int32			Height() const
49 								{ return fHeight; }
50 
51 	inline	int32			BytesPerRow() const
52 								{ return fBytesPerRow; }
53 
54 	inline	color_space		ColorSpace() const
55 								{ return fSpace; }
56 	inline	uint32			Flags() const
57 								{ return fFlags; }
58 
59 	//! Returns the identifier token for the bitmap
60 	inline	int32			Token() const
61 								{ return fToken; }
62 
63 	inline	void*			AllocationCookie() const
64 								{ return fAllocationCookie; }
65 
66 			area_id			Area() const;
67 			uint32			AreaOffset() const;
68 
69 			void			SetOverlay(::Overlay* overlay);
70 			::Overlay*		Overlay() const;
71 
72 			bool			SetOwner(ServerApp* owner);
73 			ServerApp*		Owner() const;
74 
75 			bool			ReleaseClientReference();
76 
77 	//! Does a shallow copy of the bitmap passed to it
78 	inline	void			ShallowCopy(const ServerBitmap *from);
79 
80 			status_t		ImportBits(const void *bits, int32 bitsLength,
81 								int32 bytesPerRow, color_space colorSpace);
82 			status_t		ImportBits(const void *bits, int32 bitsLength,
83 								int32 bytesPerRow, color_space colorSpace,
84 								BPoint from, BPoint to, int32 width,
85 								int32 height);
86 
87 			void			PrintToStream();
88 
89 protected:
90 	friend class BitmapManager;
91 
92 							ServerBitmap(BRect rect, color_space space,
93 								uint32 flags, int32 bytesPerRow = -1,
94 								screen_id screen = B_MAIN_SCREEN_ID);
95 							ServerBitmap(const ServerBitmap* bmp);
96 	virtual					~ServerBitmap();
97 
98 	virtual	void			LastReferenceReleased();
99 
100 			void			AllocateBuffer();
101 
102 protected:
103 			ClientMemoryAllocator* fAllocator;
104 			void*			fAllocationCookie;
105 			::Overlay*		fOverlay;
106 			uint8*			fBuffer;
107 			int32			fReferenceCount;
108 
109 			int32			fWidth;
110 			int32			fHeight;
111 			int32			fBytesPerRow;
112 			color_space		fSpace;
113 			uint32			fFlags;
114 
115 			ServerApp*		fOwner;
116 			int32			fToken;
117 			bool			fHasClientReference;
118 };
119 
120 class UtilityBitmap : public ServerBitmap {
121 public:
122 							UtilityBitmap(BRect rect, color_space space,
123 								uint32 flags, int32 bytesperline = -1,
124 								screen_id screen = B_MAIN_SCREEN_ID);
125 							UtilityBitmap(const ServerBitmap* bmp);
126 
127 							UtilityBitmap(const uint8* alreadyPaddedData,
128 								uint32 width, uint32 height,
129 								color_space format);
130 
131 	virtual					~UtilityBitmap();
132 };
133 
134 
135 //! (only for server bitmaps)
136 void
137 ServerBitmap::ShallowCopy(const ServerBitmap* from)
138 {
139 	if (!from)
140 		return;
141 
142 	fBuffer = from->fBuffer;
143 	fWidth = from->fWidth;
144 	fHeight = from->fHeight;
145 	fBytesPerRow = from->fBytesPerRow;
146 	fSpace = from->fSpace;
147 	fFlags = from->fFlags;
148 	fToken = from->fToken;
149 }
150 
151 #endif	// SERVER_BITMAP_H
152