1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2001-2002, OpenBeOS 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 // DEALINGS IN THE SOFTWARE. 21 // 22 // File Name: Bitmap.h 23 // Author: Ingo Weinhold (bonefish@users.sf.net) 24 // Description: BBitmap objects represent off-screen windows that 25 // contain bitmap data. 26 //------------------------------------------------------------------------------ 27 28 #ifndef _BITMAP_H 29 #define _BITMAP_H 30 31 #include <Archivable.h> 32 #include <InterfaceDefs.h> 33 #include <Rect.h> 34 35 class BWindow; 36 37 enum { 38 B_BITMAP_CLEAR_TO_WHITE = 0x00000001, 39 B_BITMAP_ACCEPTS_VIEWS = 0x00000002, 40 B_BITMAP_IS_AREA = 0x00000004, 41 B_BITMAP_IS_LOCKED = 0x00000008 | B_BITMAP_IS_AREA, 42 B_BITMAP_IS_CONTIGUOUS = 0x00000010 | B_BITMAP_IS_LOCKED, 43 B_BITMAP_IS_OFFSCREEN = 0x00000020, 44 B_BITMAP_WILL_OVERLAY = 0x00000040 | B_BITMAP_IS_OFFSCREEN, 45 B_BITMAP_RESERVE_OVERLAY_CHANNEL = 0x00000080 46 }; 47 48 #define B_ANY_BYTES_PER_ROW -1 49 50 //----------------------------------------------------------------// 51 //----- BBitmap class --------------------------------------------// 52 53 class BBitmap : public BArchivable { 54 public: 55 BBitmap(BRect bounds, uint32 flags, color_space colorSpace, 56 int32 bytesPerRow = B_ANY_BYTES_PER_ROW, 57 screen_id screenID = B_MAIN_SCREEN_ID); 58 BBitmap(BRect bounds, color_space colorSpace, bool acceptsViews = false, 59 bool needsContiguous = false); 60 BBitmap(const BBitmap *source, bool acceptsViews = false, 61 bool needsContiguous = false); 62 virtual ~BBitmap(); 63 64 // Archiving 65 BBitmap(BMessage *data); 66 static BArchivable *Instantiate(BMessage *data); 67 virtual status_t Archive(BMessage *data, bool deep = true) const; 68 69 status_t InitCheck() const; 70 bool IsValid() const; 71 72 status_t LockBits(uint32 *state = NULL); 73 void UnlockBits(); 74 75 area_id Area() const; 76 void *Bits() const; 77 int32 BitsLength() const; 78 int32 BytesPerRow() const; 79 color_space ColorSpace() const; 80 BRect Bounds() const; 81 82 void SetBits(const void *data, int32 length, int32 offset, 83 color_space colorSpace); 84 85 status_t GetOverlayRestrictions(overlay_restrictions *restrictions) const; 86 87 // to mimic a BWindow 88 virtual void AddChild(BView *view); 89 virtual bool RemoveChild(BView *view); 90 int32 CountChildren() const; 91 BView *ChildAt(int32 index) const; 92 BView *FindView(const char *viewName) const; 93 BView *FindView(BPoint point) const; 94 bool Lock(); 95 void Unlock(); 96 bool IsLocked() const; 97 98 //----- Private or reserved -----------------------------------------// 99 100 virtual status_t Perform(perform_code d, void *arg); 101 102 private: 103 friend class BView; 104 friend class BApplication; 105 friend void _get_screen_bitmap_(BBitmap *, BRect, bool); 106 107 virtual void _ReservedBitmap1(); 108 virtual void _ReservedBitmap2(); 109 virtual void _ReservedBitmap3(); 110 111 BBitmap(const BBitmap &); 112 BBitmap &operator=(const BBitmap &); 113 114 char *get_shared_pointer() const; 115 void set_bits(long offset, char *data, long length); 116 void set_bits_24(long offset, char *data, long length); 117 void set_bits_24_local_gray(long offset, char *data, long length); 118 void set_bits_24_local_256(long offset, uchar *data, long length); 119 void set_bits_24_24(long offset, char *data, long length, 120 bool bigEndianDest); 121 void set_bits_8_24(long offset, char *data, long length, 122 bool bigEndianDest); 123 void set_bits_gray_24(long offset, char *data, long length, 124 bool bigEndianDest); 125 int32 get_server_token() const; 126 void InitObject(BRect bounds, color_space colorSpace, uint32 flags, 127 int32 bytesPerRow, screen_id screenID); 128 void AssertPtr(); 129 130 void *fBasePtr; 131 int32 fSize; 132 color_space fColorSpace; 133 BRect fBounds; 134 int32 fBytesPerRow; 135 BWindow *fWindow; 136 int32 fServerToken; 137 int32 fToken; 138 uint8 unused; 139 area_id fArea; 140 area_id fOrigArea; 141 uint32 fFlags; 142 status_t fInitError; 143 }; 144 145 /*-------------------------------------------------------------*/ 146 /*-------------------------------------------------------------*/ 147 148 #endif // _BITMAP_H 149