1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2001-2005, Haiku, Inc. 3 // 4 // Distributed under the terms of the MIT license. 5 // 6 // File Name: Bitmap.h 7 // Author: Ingo Weinhold (bonefish@users.sf.net) 8 // Description: BBitmap objects represent off-screen windows that 9 // contain bitmap data. 10 //------------------------------------------------------------------------------ 11 12 #ifndef _BITMAP_H 13 #define _BITMAP_H 14 15 #include <Archivable.h> 16 #include <InterfaceDefs.h> 17 #include <Rect.h> 18 19 class BPrivateScreen; 20 class BWindow; 21 22 enum { 23 B_BITMAP_CLEAR_TO_WHITE = 0x00000001, 24 B_BITMAP_ACCEPTS_VIEWS = 0x00000002, 25 B_BITMAP_IS_AREA = 0x00000004, 26 B_BITMAP_IS_LOCKED = 0x00000008 | B_BITMAP_IS_AREA, 27 B_BITMAP_IS_CONTIGUOUS = 0x00000010 | B_BITMAP_IS_LOCKED, 28 B_BITMAP_IS_OFFSCREEN = 0x00000020, 29 B_BITMAP_WILL_OVERLAY = 0x00000040 | B_BITMAP_IS_OFFSCREEN, 30 B_BITMAP_RESERVE_OVERLAY_CHANNEL = 0x00000080, 31 B_BITMAP_NO_SERVER_LINK = 0x00000100 32 }; 33 34 #define B_ANY_BYTES_PER_ROW -1 35 36 //----------------------------------------------------------------// 37 //----- BBitmap class --------------------------------------------// 38 39 class BBitmap : public BArchivable { 40 public: 41 BBitmap(BRect bounds, uint32 flags, color_space colorSpace, 42 int32 bytesPerRow = B_ANY_BYTES_PER_ROW, 43 screen_id screenID = B_MAIN_SCREEN_ID); 44 BBitmap(BRect bounds, color_space colorSpace, bool acceptsViews = false, 45 bool needsContiguous = false); 46 BBitmap(const BBitmap *source, bool acceptsViews = false, 47 bool needsContiguous = false); 48 virtual ~BBitmap(); 49 50 // Archiving 51 BBitmap(BMessage *data); 52 static BArchivable *Instantiate(BMessage *data); 53 virtual status_t Archive(BMessage *data, bool deep = true) const; 54 55 status_t InitCheck() const; 56 bool IsValid() const; 57 58 status_t LockBits(uint32 *state = NULL); 59 void UnlockBits(); 60 61 area_id Area() const; 62 void *Bits() const; 63 int32 BitsLength() const; 64 int32 BytesPerRow() const; 65 color_space ColorSpace() const; 66 BRect Bounds() const; 67 68 void SetBits(const void *data, int32 length, int32 offset, 69 color_space colorSpace); 70 71 // not part of the R5 API 72 status_t ImportBits(const void *data, int32 length, int32 bpr, 73 int32 offset, color_space colorSpace); 74 status_t ImportBits(const BBitmap *bitmap); 75 76 status_t GetOverlayRestrictions(overlay_restrictions *restrictions) const; 77 78 // to mimic a BWindow 79 virtual void AddChild(BView *view); 80 virtual bool RemoveChild(BView *view); 81 int32 CountChildren() const; 82 BView *ChildAt(int32 index) const; 83 BView *FindView(const char *viewName) const; 84 BView *FindView(BPoint point) const; 85 bool Lock(); 86 void Unlock(); 87 bool IsLocked() const; 88 89 //----- Private or reserved -----------------------------------------// 90 91 virtual status_t Perform(perform_code d, void *arg); 92 93 private: 94 friend class BView; 95 friend class BApplication; 96 friend class BPrivateScreen; 97 //friend void _get_screen_bitmap_(BBitmap *, BRect, bool); 98 99 virtual void _ReservedBitmap1(); 100 virtual void _ReservedBitmap2(); 101 virtual void _ReservedBitmap3(); 102 103 BBitmap(const BBitmap &); 104 BBitmap &operator=(const BBitmap &); 105 106 char *get_shared_pointer() const; 107 int32 get_server_token() const; 108 void InitObject(BRect bounds, color_space colorSpace, uint32 flags, 109 int32 bytesPerRow, screen_id screenID); 110 void CleanUp(); 111 112 void AssertPtr(); 113 114 void *fBasePtr; 115 int32 fSize; 116 color_space fColorSpace; 117 BRect fBounds; 118 int32 fBytesPerRow; 119 BWindow *fWindow; 120 int32 fServerToken; 121 int32 fToken; 122 uint8 unused; 123 area_id fArea; 124 area_id fOrigArea; 125 uint32 fFlags; 126 status_t fInitError; 127 }; 128 129 /*-------------------------------------------------------------*/ 130 /*-------------------------------------------------------------*/ 131 132 #endif // _BITMAP_H 133