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 <GraphicsDefs.h>
14#include <Rect.h>
15#include <OS.h>
16
17#include <Referenceable.h>
18
19#include "ClientMemoryAllocator.h"
20
21
22class BitmapManager;
23class HWInterface;
24class Overlay;
25class ServerApp;
26
27
28/*!	\class ServerBitmap ServerBitmap.h
29	\brief Bitmap class used inside the server.
30
31	This class is not directly allocated or freed. Instead, it is
32	managed by the BitmapManager class. It is also the base class for
33	all cursors. Every BBitmap has a shadow ServerBitmap object.
34*/
35class ServerBitmap : public BReferenceable {
36public:
37	inline	bool			IsValid() const
38								{ return fBuffer != NULL; }
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
55	inline	color_space		ColorSpace() const
56								{ return fSpace; }
57	inline	uint32			Flags() const
58								{ return fFlags; }
59
60	//! Returns the identifier token for the bitmap
61	inline	int32			Token() const
62								{ return fToken; }
63
64			area_id			Area() const;
65			uint32			AreaOffset() const;
66
67			void			SetOverlay(::Overlay* overlay);
68			::Overlay*		Overlay() const;
69
70			void			SetOwner(ServerApp* owner);
71			ServerApp*		Owner() const;
72
73	//! Does a shallow copy of the bitmap passed to it
74	inline	void			ShallowCopy(const ServerBitmap *from);
75
76			status_t		ImportBits(const void *bits, int32 bitsLength,
77								int32 bytesPerRow, color_space colorSpace);
78			status_t		ImportBits(const void *bits, int32 bitsLength,
79								int32 bytesPerRow, color_space colorSpace,
80								BPoint from, BPoint to, int32 width,
81								int32 height);
82
83			void			PrintToStream();
84
85protected:
86	friend class BitmapManager;
87
88							ServerBitmap(BRect rect, color_space space,
89								uint32 flags, int32 bytesPerRow = -1,
90								screen_id screen = B_MAIN_SCREEN_ID);
91							ServerBitmap(const ServerBitmap* bmp);
92	virtual					~ServerBitmap();
93
94			void			AllocateBuffer();
95
96protected:
97			ClientMemory	fClientMemory;
98			AreaMemory*		fMemory;
99			::Overlay*		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
112class UtilityBitmap : public ServerBitmap {
113public:
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//! (only for server bitmaps)
128void
129ServerBitmap::ShallowCopy(const ServerBitmap* from)
130{
131	if (!from)
132		return;
133
134	fBuffer = from->fBuffer;
135	fWidth = from->fWidth;
136	fHeight = from->fHeight;
137	fBytesPerRow = from->fBytesPerRow;
138	fSpace = from->fSpace;
139	fFlags = from->fFlags;
140	fToken = from->fToken;
141}
142
143#endif	// SERVER_BITMAP_H
144