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 "RGBColor.h" 14 15 #include <GraphicsDefs.h> 16 #include <Rect.h> 17 #include <OS.h> 18 19 class BitmapManager; 20 class ClientMemoryAllocator; 21 class HWInterface; 22 class Overlay; 23 class ServerApp; 24 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 { 35 public: 36 inline bool IsValid() const 37 { return fBuffer != NULL; } 38 39 void Acquire(); 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 inline uint8 BitsPerPixel() const 56 { return fBitsPerPixel; } 57 inline color_space ColorSpace() const 58 { return fSpace; } 59 60 //! Returns the identifier token for the bitmap 61 inline int32 Token() const 62 { return fToken; } 63 64 inline void* AllocationCookie() const 65 { return fAllocationCookie; } 66 67 area_id Area() const; 68 uint32 AreaOffset() const; 69 70 void SetOverlay(::Overlay* overlay); 71 ::Overlay* Overlay() const; 72 73 void SetOwner(ServerApp* owner); 74 ServerApp* Owner() const; 75 76 //! Does a shallow copy of the bitmap passed to it 77 inline void ShallowCopy(const ServerBitmap *from); 78 79 status_t ImportBits(const void *bits, int32 bitsLength, 80 int32 bytesPerRow, color_space colorSpace); 81 status_t ImportBits(const void *bits, int32 bitsLength, 82 int32 bytesPerRow, color_space colorSpace, 83 BPoint from, BPoint to, int32 width, 84 int32 height); 85 86 void PrintToStream(); 87 88 protected: 89 friend class BitmapManager; 90 friend class PicturePlayer; 91 92 ServerBitmap(BRect rect, 93 color_space space, 94 int32 flags, 95 int32 bytesPerRow = -1, 96 screen_id screen = B_MAIN_SCREEN_ID); 97 ServerBitmap(const ServerBitmap* bmp); 98 virtual ~ServerBitmap(); 99 100 //! used by the BitmapManager 101 // inline void _SetBuffer(void *ptr) 102 // { fBuffer = (uint8*)ptr; } 103 104 bool _Release(); 105 106 void _AllocateBuffer(); 107 108 void _HandleSpace(color_space space, 109 int32 bytesperline = -1); 110 111 ClientMemoryAllocator* fAllocator; 112 void* fAllocationCookie; 113 ::Overlay* fOverlay; 114 uint8* fBuffer; 115 int32 fReferenceCount; 116 117 int32 fWidth; 118 int32 fHeight; 119 int32 fBytesPerRow; 120 color_space fSpace; 121 int32 fFlags; 122 int fBitsPerPixel; 123 124 ServerApp* fOwner; 125 int32 fToken; 126 }; 127 128 class UtilityBitmap : public ServerBitmap { 129 public: 130 UtilityBitmap(BRect rect, 131 color_space space, 132 int32 flags, 133 int32 bytesperline = -1, 134 screen_id screen = B_MAIN_SCREEN_ID); 135 UtilityBitmap(const ServerBitmap* bmp); 136 137 UtilityBitmap(const uint8* alreadyPaddedData, 138 uint32 width, 139 uint32 height, 140 color_space format); 141 142 143 virtual ~UtilityBitmap(); 144 }; 145 146 // ShallowCopy (only for server bitmaps) 147 void 148 ServerBitmap::ShallowCopy(const ServerBitmap* from) 149 { 150 if (!from) 151 return; 152 153 fBuffer = from->fBuffer; 154 fWidth = from->fWidth; 155 fHeight = from->fHeight; 156 fBytesPerRow = from->fBytesPerRow; 157 fSpace = from->fSpace; 158 fFlags = from->fFlags; 159 fBitsPerPixel = from->fBitsPerPixel; 160 fToken = from->fToken; 161 } 162 163 #endif // SERVER_BITMAP_H 164