If you don't declare the destructor virtual in the base class, you will leak memory and the destructor of an inherited class might not be called at all. Removed unnecessary comments. Enhanced readability, because I felt like it...

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12375 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2005-04-13 19:31:24 +00:00
parent 99cd375fb3
commit 4c90b41029
+91 -69
View File
@@ -1,5 +1,5 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Copyright (c) 2001-2002, Haiku, Inc. // Copyright (c) 2001-2005, Haiku, Inc.
// //
// Permission is hereby granted, free of charge, to any person obtaining a // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
@@ -41,13 +41,16 @@ class BitmapManager;
managed by the BitmapManager class. It is also the base class for managed by the BitmapManager class. It is also the base class for
all cursors. Every BBitmap has a shadow ServerBitmap object. all cursors. Every BBitmap has a shadow ServerBitmap object.
*/ */
class ServerBitmap class ServerBitmap {
{ public:
public: ServerBitmap(BRect rect,
ServerBitmap(BRect rect,color_space space, int32 flags, color_space space,
int32 bytesperline=-1, screen_id screen=B_MAIN_SCREEN_ID); int32 flags,
ServerBitmap(const ServerBitmap *bmp); int32 bytesperline = -1,
~ServerBitmap(void); screen_id screen = B_MAIN_SCREEN_ID);
ServerBitmap(const ServerBitmap* bmp);
virtual ~ServerBitmap();
/*! /*!
\brief Returns the area in which the buffer resides \brief Returns the area in which the buffer resides
@@ -55,92 +58,111 @@ public:
- \c B_ERROR if the buffer is not allocated in an area - \c B_ERROR if the buffer is not allocated in an area
- area_id for the buffer - area_id for the buffer
*/ */
area_id Area(void) const { return fArea; } inline area_id Area() const
{ return fArea; }
// Returns the offset of the bitmap in its area // Returns the offset of the bitmap in its area
int32 AreaOffset(void) { return fOffset; } inline int32 AreaOffset() const
{ return fOffset; }
//! Returns the bitmap's buffer //! Returns the bitmap's buffer
uint8 *Bits(void) const { return fBuffer; } inline uint8* Bits() const
uint32 BitsLength(void) const; { return fBuffer; }
//! Returns the size of the bitmap inline uint32 BitsLength() const;
BRect Bounds() const { return BRect(0,0,fWidth-1,fHeight-1); };
inline BRect Bounds() const
{ return BRect(0, 0, fWidth - 1, fHeight - 1); }
//! Returns the number of bytes in each row, including padding //! Returns the number of bytes in each row, including padding
int32 BytesPerRow(void) const { return fBytesPerRow; }; inline int32 BytesPerRow() const
{ return fBytesPerRow; }
//! Returns the pixel color depth inline uint8 BitsPerPixel() const
uint8 BitsPerPixel(void) const { return fBitsPerPixel; } { return fBitsPerPixel }
//! Returns the color space of the bitmap inline color_space ColorSpace() const
color_space ColorSpace(void) const { return fSpace; } { return fSpace; }
//! Returns the width of the bitmap inline int32 Width() const
int32 Width(void) const { return fWidth; } { return fWidth; }
//! Returns the height of the bitmap inline int32 Height() const
int32 Height(void) const { return fHeight; } { return fHeight; }
//! Returns whether the bitmap is valid inline bool InitCheck() const
bool InitCheck(void) const { return fInitialized; } { return fInitialized; }
//! Returns the identifier token for the bitmap //! Returns the identifier token for the bitmap
int32 Token(void) const { return fToken; } inline int32 Token() const
{ return fToken; }
//! Does a shallow copy of the bitmap passed to it //! Does a shallow copy of the bitmap passed to it
void ShallowCopy(const ServerBitmap *from) inline void ShallowCopy(const ServerBitmap *from);
{
if(!from)
return;
fInitialized=from->fInitialized;
fArea=from->fArea;
fBuffer=from->fBuffer;
fWidth=from->fWidth;
fHeight=from->fHeight;
fBytesPerRow=from->fBytesPerRow;
fSpace=from->fSpace;
fFlags=from->fFlags;
fBitsPerPixel=from->fBitsPerPixel;
fToken=from->fToken;
fOffset=from->fOffset;
}
protected: protected:
friend class BitmapManager; friend class BitmapManager;
friend class PicturePlayer; friend class PicturePlayer;
//! Internal function used by the BitmapManager. //! used by the BitmapManager
void _SetArea(area_id ID) { fArea=ID; } inline void _SetArea(area_id ID)
{ fArea=ID; }
//! Internal function used by the BitmapManager. //! used by the BitmapManager
void _SetBuffer(void *ptr) { fBuffer=(uint8*)ptr; } inline void _SetBuffer(void *ptr)
void _AllocateBuffer(void); { fBuffer=(uint8*)ptr; }
void _FreeBuffer(void);
void _AllocateBuffer();
void _FreeBuffer();
void _HandleSpace(color_space space, int32 bytesperline=-1); void _HandleSpace(color_space space,
int32 bytesperline = -1);
bool fInitialized; bool fInitialized;
area_id fArea; area_id fArea;
uint8 *fBuffer; uint8* fBuffer;
int32 fWidth,fHeight; int32 fWidth;
int32 fBytesPerRow; int32 fHeight;
color_space fSpace; int32 fBytesPerRow;
int32 fFlags; color_space fSpace;
int fBitsPerPixel; int32 fFlags;
int32 fToken; int fBitsPerPixel;
int32 fOffset; int32 fToken;
int32 fOffset;
}; };
class UtilityBitmap : public ServerBitmap class UtilityBitmap : public ServerBitmap {
public:
UtilityBitmap(BRect rect,
color_space space,
int32 flags,
int32 bytesperline = -1,
screen_id screen = B_MAIN_SCREEN_ID);
UtilityBitmap(const ServerBitmap* bmp);
virtual ~UtilityBitmap();
};
// ShallowCopy
void
ServerBitmap::ShallowCopy(const ServerBitmap* from)
{ {
public: if (!from)
UtilityBitmap(BRect rect,color_space space, int32 flags, return;
int32 bytesperline=-1, screen_id screen=B_MAIN_SCREEN_ID);
UtilityBitmap(const ServerBitmap *bmp); fInitialized = from->fInitialized;
~UtilityBitmap(void); fArea = from->fArea;
}; fBuffer = from->fBuffer;
fWidth = from->fWidth;
fHeight = from->fHeight;
fBytesPerRow = from->fBytesPerRow;
fSpace = from->fSpace;
fFlags = from->fFlags;
fBitsPerPixel = from->fBitsPerPixel;
fToken = from->fToken;
fOffset = from->fOffset;
}
#endif
#endif // _SERVER_BITMAP_H_