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 20 class BitmapManager; 21 class ClientMemoryAllocator; 22 class HWInterface; 23 class Overlay; 24 class ServerApp; 25 26 27 /*! \class ServerBitmap ServerBitmap.h 28 \brief Bitmap class used inside the server. 29 30 This class is not directly allocated or freed. Instead, it is 31 managed by the BitmapManager class. It is also the base class for 32 all cursors. Every BBitmap has a shadow ServerBitmap object. 33 */ 34 class ServerBitmap : public BReferenceable { 35 public: 36 inline bool IsValid() const 37 { return fBuffer != NULL; } 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 54 inline color_space ColorSpace() const 55 { return fSpace; } 56 inline uint32 Flags() const 57 { return fFlags; } 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* overlay); 70 ::Overlay* Overlay() const; 71 72 void SetOwner(ServerApp* owner); 73 ServerApp* Owner() const; 74 75 //! Does a shallow copy of the bitmap passed to it 76 inline void ShallowCopy(const ServerBitmap *from); 77 78 status_t ImportBits(const void *bits, int32 bitsLength, 79 int32 bytesPerRow, color_space colorSpace); 80 status_t ImportBits(const void *bits, int32 bitsLength, 81 int32 bytesPerRow, color_space colorSpace, 82 BPoint from, BPoint to, int32 width, 83 int32 height); 84 85 void PrintToStream(); 86 87 protected: 88 friend class BitmapManager; 89 90 ServerBitmap(BRect rect, color_space space, 91 uint32 flags, int32 bytesPerRow = -1, 92 screen_id screen = B_MAIN_SCREEN_ID); 93 ServerBitmap(const ServerBitmap* bmp); 94 virtual ~ServerBitmap(); 95 96 void AllocateBuffer(); 97 98 protected: 99 ClientMemoryAllocator* fAllocator; 100 void* fAllocationCookie; 101 ::Overlay* 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 114 class UtilityBitmap : public ServerBitmap { 115 public: 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) 130 void 131 ServerBitmap::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 146