xref: /haiku/src/servers/app/ServerBitmap.h (revision d3d8b26997fac34a84981e6d2b649521de2cc45a)
1 /*
2  * Copyright 2001-2006, 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 "RGBColor.h"
14 
15 #include <GraphicsDefs.h>
16 #include <Rect.h>
17 #include <OS.h>
18 
19 class BitmapManager;
20 class ClientMemoryAllocator;
21 class HWInterface;
22 class Overlay;
23 
24 
25 /*!
26 	\class ServerBitmap ServerBitmap.h
27 	\brief Bitmap class used inside the server.
28 
29 	This class is not directly allocated or freed. Instead, it is
30 	managed by the BitmapManager class. It is also the base class for
31 	all cursors. Every BBitmap has a shadow ServerBitmap object.
32 */
33 class ServerBitmap {
34  public:
35 	inline	bool			IsValid() const
36 								{ return fBuffer != NULL; }
37 
38 			void			Acquire();
39 
40 	inline	uint8*			Bits() const
41 								{ return fBuffer; }
42 	inline	uint32			BitsLength() const
43 								{ return (uint32)(fBytesPerRow * fHeight); }
44 
45 	inline	BRect			Bounds() const
46 								{ return BRect(0, 0, fWidth - 1, fHeight - 1); }
47 	inline	int32			Width() const
48 								{ return fWidth; }
49 	inline	int32			Height() const
50 								{ return fHeight; }
51 
52 	inline	int32			BytesPerRow() const
53 								{ return fBytesPerRow; }
54 	inline	uint8			BitsPerPixel() const
55 								{ return fBitsPerPixel; }
56 	inline	color_space		ColorSpace() const
57 								{ return fSpace; }
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* cookie);
70 			::Overlay*		Overlay() 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 	friend class PicturePlayer;
87 
88 							ServerBitmap(BRect rect,
89 										 color_space space,
90 										 int32 flags,
91 										 int32 bytesPerRow = -1,
92 										 screen_id screen = B_MAIN_SCREEN_ID);
93 							ServerBitmap(const ServerBitmap* bmp);
94 	virtual					~ServerBitmap();
95 
96 	//! used by the BitmapManager
97 //	inline	void			_SetBuffer(void *ptr)
98 //								{ fBuffer = (uint8*)ptr; }
99 
100 			bool			_Release();
101 
102 			void			_AllocateBuffer();
103 
104 			void			_HandleSpace(color_space space,
105 										 int32 bytesperline = -1);
106 
107 			ClientMemoryAllocator* fAllocator;
108 			void*			fAllocationCookie;
109 			::Overlay*		fOverlay;
110 			uint8*			fBuffer;
111 			int32			fReferenceCount;
112 
113 			int32			fWidth;
114 			int32			fHeight;
115 			int32			fBytesPerRow;
116 			color_space		fSpace;
117 			int32			fFlags;
118 			int				fBitsPerPixel;
119 			int32			fToken;
120 };
121 
122 class UtilityBitmap : public ServerBitmap {
123  public:
124 							UtilityBitmap(BRect rect,
125 										  color_space space,
126 										  int32 flags,
127 										  int32 bytesperline = -1,
128 										  screen_id screen = B_MAIN_SCREEN_ID);
129 							UtilityBitmap(const ServerBitmap* bmp);
130 
131 							UtilityBitmap(const uint8* alreadyPaddedData,
132 										  uint32 width,
133 										  uint32 height,
134 										  color_space format);
135 
136 
137 	virtual					~UtilityBitmap();
138 };
139 
140 // ShallowCopy (only for server bitmaps)
141 void
142 ServerBitmap::ShallowCopy(const ServerBitmap* from)
143 {
144 	if (!from)
145 		return;
146 
147 	fBuffer			= from->fBuffer;
148 	fWidth			= from->fWidth;
149 	fHeight			= from->fHeight;
150 	fBytesPerRow	= from->fBytesPerRow;
151 	fSpace			= from->fSpace;
152 	fFlags			= from->fFlags;
153 	fBitsPerPixel	= from->fBitsPerPixel;
154 	fToken			= from->fToken;
155 }
156 
157 #endif	// SERVER_BITMAP_H
158