xref: /haiku/src/servers/app/ServerBitmap.h (revision cbe0a0c436162d78cc3f92a305b64918c839d079)
1 /*
2  * Copyright 2001-2010, 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 <AutoDeleter.h>
14 #include <GraphicsDefs.h>
15 #include <Rect.h>
16 #include <OS.h>
17 
18 #include <Referenceable.h>
19 
20 #include "ClientMemoryAllocator.h"
21 
22 
23 class BitmapManager;
24 class HWInterface;
25 class Overlay;
26 class ServerApp;
27 
28 
29 /*!	\class ServerBitmap ServerBitmap.h
30 	\brief Bitmap class used inside the server.
31 
32 	This class is not directly allocated or freed. Instead, it is
33 	managed by the BitmapManager class. It is also the base class for
34 	all cursors. Every BBitmap has a shadow ServerBitmap object.
35 */
36 class ServerBitmap : public BReferenceable {
37 public:
38 	inline	bool			IsValid() const
39 								{ return fBuffer != NULL; }
40 
41 	inline	uint8*			Bits() const
42 								{ return fBuffer; }
43 	inline	uint32			BitsLength() const;
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 			area_id			Area() const;
64 			uint32			AreaOffset() const;
65 
66 			void			SetOverlay(::Overlay* overlay);
67 			::Overlay*		Overlay() const;
68 
69 			void			SetOwner(ServerApp* owner);
70 			ServerApp*		Owner() const;
71 
72 	//! Does a shallow copy of the bitmap passed to it
73 	inline	void			ShallowCopy(const ServerBitmap *from);
74 
75 			status_t		ImportBits(const void *bits, int32 bitsLength,
76 								int32 bytesPerRow, color_space colorSpace);
77 			status_t		ImportBits(const void *bits, int32 bitsLength,
78 								int32 bytesPerRow, color_space colorSpace,
79 								BPoint from, BPoint to, int32 width,
80 								int32 height);
81 
82 			void			PrintToStream();
83 
84 protected:
85 	friend class BitmapManager;
86 
87 							ServerBitmap(BRect rect, color_space space,
88 								uint32 flags, int32 bytesPerRow = -1,
89 								screen_id screen = B_MAIN_SCREEN_ID);
90 							ServerBitmap(const ServerBitmap* bmp);
91 	virtual					~ServerBitmap();
92 
93 			void			AllocateBuffer();
94 
95 protected:
96 			ClientMemory	fClientMemory;
97 			AreaMemory*		fMemory;
98 			ObjectDeleter< ::Overlay>
99 							fOverlay;
100 			uint8*			fBuffer;
101 
102 			int32			fWidth;
103 			int32			fHeight;
104 			int32			fBytesPerRow;
105 			color_space		fSpace;
106 			uint32			fFlags;
107 
108 			ServerApp*		fOwner;
109 			int32			fToken;
110 };
111 
112 class UtilityBitmap : public ServerBitmap {
113 public:
114 							UtilityBitmap(BRect rect, color_space space,
115 								uint32 flags, int32 bytesperline = -1,
116 								screen_id screen = B_MAIN_SCREEN_ID);
117 							UtilityBitmap(const ServerBitmap* bmp);
118 
119 							UtilityBitmap(const uint8* alreadyPaddedData,
120 								uint32 width, uint32 height,
121 								color_space format);
122 
123 	virtual					~UtilityBitmap();
124 };
125 
126 
127 uint32
128 ServerBitmap::BitsLength() const
129 {
130 	int64 length = fBytesPerRow * fHeight;
131 	return (length > 0 && length <= UINT32_MAX) ? (uint32)length : 0;
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