1 /* 2 * Copyright 2001-2007, 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 class BitmapManager; 18 class ClientMemoryAllocator; 19 class HWInterface; 20 class Overlay; 21 class ServerApp; 22 23 24 /*! 25 \class ServerBitmap ServerBitmap.h 26 \brief Bitmap class used inside the server. 27 28 This class is not directly allocated or freed. Instead, it is 29 managed by the BitmapManager class. It is also the base class for 30 all cursors. Every BBitmap has a shadow ServerBitmap object. 31 */ 32 class ServerBitmap { 33 public: 34 inline bool IsValid() const 35 { return fBuffer != NULL; } 36 37 void Acquire(); 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 inline uint8 BitsPerPixel() const 54 { return fBitsPerPixel; } 55 inline color_space ColorSpace() const 56 { return fSpace; } 57 58 //! Returns the identifier token for the bitmap 59 inline int32 Token() const 60 { return fToken; } 61 62 inline void* AllocationCookie() const 63 { return fAllocationCookie; } 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 86 protected: 87 friend class BitmapManager; 88 friend class PicturePlayer; 89 90 ServerBitmap(BRect rect, 91 color_space space, 92 int32 flags, 93 int32 bytesPerRow = -1, 94 screen_id screen = B_MAIN_SCREEN_ID); 95 ServerBitmap(const ServerBitmap* bmp); 96 virtual ~ServerBitmap(); 97 98 //! used by the BitmapManager 99 // inline void _SetBuffer(void *ptr) 100 // { fBuffer = (uint8*)ptr; } 101 102 bool _Release(); 103 104 void _AllocateBuffer(); 105 106 void _HandleSpace(color_space space, 107 int32 bytesperline = -1); 108 109 ClientMemoryAllocator* fAllocator; 110 void* fAllocationCookie; 111 ::Overlay* fOverlay; 112 uint8* fBuffer; 113 int32 fReferenceCount; 114 115 int32 fWidth; 116 int32 fHeight; 117 int32 fBytesPerRow; 118 color_space fSpace; 119 int32 fFlags; 120 int fBitsPerPixel; 121 122 ServerApp* fOwner; 123 int32 fToken; 124 }; 125 126 class UtilityBitmap : public ServerBitmap { 127 public: 128 UtilityBitmap(BRect rect, 129 color_space space, 130 int32 flags, 131 int32 bytesperline = -1, 132 screen_id screen = B_MAIN_SCREEN_ID); 133 UtilityBitmap(const ServerBitmap* bmp); 134 135 UtilityBitmap(const uint8* alreadyPaddedData, 136 uint32 width, 137 uint32 height, 138 color_space format); 139 140 141 virtual ~UtilityBitmap(); 142 }; 143 144 // ShallowCopy (only for server bitmaps) 145 void 146 ServerBitmap::ShallowCopy(const ServerBitmap* from) 147 { 148 if (!from) 149 return; 150 151 fBuffer = from->fBuffer; 152 fWidth = from->fWidth; 153 fHeight = from->fHeight; 154 fBytesPerRow = from->fBytesPerRow; 155 fSpace = from->fSpace; 156 fFlags = from->fFlags; 157 fBitsPerPixel = from->fBitsPerPixel; 158 fToken = from->fToken; 159 } 160 161 #endif // SERVER_BITMAP_H 162