1 /* 2 * Copyright 2001-2009, 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 /*! \class ServerBitmap ServerBitmap.h 25 \brief Bitmap class used inside the server. 26 27 This class is not directly allocated or freed. Instead, it is 28 managed by the BitmapManager class. It is also the base class for 29 all cursors. Every BBitmap has a shadow ServerBitmap object. 30 */ 31 class ServerBitmap { 32 public: 33 inline bool IsValid() const 34 { return fBuffer != NULL; } 35 36 void Acquire(); 37 38 inline uint8* Bits() const 39 { return fBuffer; } 40 inline uint32 BitsLength() const 41 { return (uint32)(fBytesPerRow * fHeight); } 42 43 inline BRect Bounds() const 44 { return BRect(0, 0, fWidth - 1, fHeight - 1); } 45 inline int32 Width() const 46 { return fWidth; } 47 inline int32 Height() const 48 { return fHeight; } 49 50 inline int32 BytesPerRow() const 51 { return fBytesPerRow; } 52 53 inline color_space ColorSpace() const 54 { return fSpace; } 55 inline uint32 Flags() const 56 { return fFlags; } 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 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 bool _Release(); 96 97 void _AllocateBuffer(); 98 99 ClientMemoryAllocator* fAllocator; 100 void* fAllocationCookie; 101 ::Overlay* fOverlay; 102 uint8* fBuffer; 103 int32 fReferenceCount; 104 105 int32 fWidth; 106 int32 fHeight; 107 int32 fBytesPerRow; 108 color_space fSpace; 109 uint32 fFlags; 110 111 ServerApp* fOwner; 112 int32 fToken; 113 }; 114 115 class UtilityBitmap : public ServerBitmap { 116 public: 117 UtilityBitmap(BRect rect, color_space space, 118 uint32 flags, int32 bytesperline = -1, 119 screen_id screen = B_MAIN_SCREEN_ID); 120 UtilityBitmap(const ServerBitmap* bmp); 121 122 UtilityBitmap(const uint8* alreadyPaddedData, 123 uint32 width, uint32 height, 124 color_space format); 125 126 virtual ~UtilityBitmap(); 127 }; 128 129 130 //! (only for server bitmaps) 131 void 132 ServerBitmap::ShallowCopy(const ServerBitmap* from) 133 { 134 if (!from) 135 return; 136 137 fBuffer = from->fBuffer; 138 fWidth = from->fWidth; 139 fHeight = from->fHeight; 140 fBytesPerRow = from->fBytesPerRow; 141 fSpace = from->fSpace; 142 fFlags = from->fFlags; 143 fToken = from->fToken; 144 } 145 146 #endif // SERVER_BITMAP_H 147