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
23class BitmapManager;
24class HWInterface;
25class Overlay;
26class 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*/
36class ServerBitmap : public BReferenceable {
37public:
38 inline bool IsValid() const
39 { return fBuffer != NULL; }
40
41 inline uint8* Bits() const
42 { return fBuffer; }
43 inline uint32 BitsLength() const
44 { return (uint32)(fBytesPerRow * fHeight); }
45
46 inline BRect Bounds() const
47 { return BRect(0, 0, fWidth - 1, fHeight - 1); }
48 inline int32 Width() const
49 { return fWidth; }
50 inline int32 Height() const
51 { return fHeight; }
52
53 inline int32 BytesPerRow() const
54 { return fBytesPerRow; }
55
56 inline color_space ColorSpace() const
57 { return fSpace; }
58 inline uint32 Flags() const
59 { return fFlags; }
60
61 //! Returns the identifier token for the bitmap
62 inline int32 Token() const
63 { return fToken; }
64
65 area_id Area() const;
66 uint32 AreaOffset() const;
67
68 void SetOverlay(::Overlay* overlay);
69 ::Overlay* Overlay() const;
70
71 void SetOwner(ServerApp* owner);
72 ServerApp* Owner() const;
73
74 //! Does a shallow copy of the bitmap passed to it
75 inline void ShallowCopy(const ServerBitmap *from);
76
77 status_t ImportBits(const void *bits, int32 bitsLength,
78 int32 bytesPerRow, color_space colorSpace);
79 status_t ImportBits(const void *bits, int32 bitsLength,
80 int32 bytesPerRow, color_space colorSpace,
81 BPoint from, BPoint to, int32 width,
82 int32 height);
83
84 void PrintToStream();
85
86protected:
87 friend class BitmapManager;
88
89 ServerBitmap(BRect rect, color_space space,
90 uint32 flags, int32 bytesPerRow = -1,
91 screen_id screen = B_MAIN_SCREEN_ID);
92 ServerBitmap(const ServerBitmap* bmp);
93 virtual ~ServerBitmap();
94
95 void AllocateBuffer();
96
97protected:
98 ClientMemory fClientMemory;
99 AreaMemory* fMemory;
100 ObjectDeleter< ::Overlay>
101 fOverlay;
102 uint8* fBuffer;
103
104 int32 fWidth;
105 int32 fHeight;
106 int32 fBytesPerRow;
107 color_space fSpace;
108 uint32 fFlags;
109
110 ServerApp* fOwner;
111 int32 fToken;
112};
113
114class UtilityBitmap : public ServerBitmap {
115public:
116 UtilityBitmap(BRect rect, color_space space,
117 uint32 flags, int32 bytesperline = -1,
118 screen_id screen = B_MAIN_SCREEN_ID);
119 UtilityBitmap(const ServerBitmap* bmp);
120
121 UtilityBitmap(const uint8* alreadyPaddedData,
122 uint32 width, uint32 height,
123 color_space format);
124
125 virtual ~UtilityBitmap();
126};
127
128
129//! (only for server bitmaps)
130void
131ServerBitmap::ShallowCopy(const ServerBitmap* from)
132{
133 if (!from)
134 return;
135
136 fBuffer = from->fBuffer;
137 fWidth = from->fWidth;
138 fHeight = from->fHeight;
139 fBytesPerRow = from->fBytesPerRow;
140 fSpace = from->fSpace;
141 fFlags = from->fFlags;
142 fToken = from->fToken;
143}
144
145#endif // SERVER_BITMAP_H