haiku/headers/private/servers/app/ServerBitmap.h
Axel Dörfler aa1f543799 Some work on cursors:
* Fixed a myriad of bugs all over the place, ranging from locking errors to
  deleting objects that don't belong to the one deleting them (hello HWInterface!)
* Almost all ServerWindow cursor stuff was broken; I've replaced all commands
  to set a cursor with a single one AS_SET_CURSOR.
* Renamed some cursor commands.
* Changed the (broken) way ServerApp::fAppCursor was maintained - the application
  cursor is now NULL as long as possible.
* Removed superfluous ServerCursor app signature stuff.
* The BApplication will no longer duplicate the default/I-beam cursors, it will
  just reuse the default ones which now have fixed tokens.
* As a result, changing the cursor is now working as expected, closing bug #102.
* Rewrote Cursor.h, renamed private members to match our style guide.
* Minor cleanup.

What's still left to be done is reference counting the cursor objects to make them
work right and reliable.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16237 a95241bf-73f2-0310-859d-f6bbb57e9c96
2006-02-05 18:14:14 +00:00

150 lines
3.4 KiB
C++

/*
* Copyright 2001-2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* DarkWyrm <bpmagic@columbus.rr.com>
*/
#ifndef _SERVER_BITMAP_H_
#define _SERVER_BITMAP_H_
#include <GraphicsDefs.h>
#include <Rect.h>
#include <OS.h>
class BitmapManager;
/*!
\class ServerBitmap ServerBitmap.h
\brief Bitmap class used inside the server.
This class is not directly allocated or freed. Instead, it is
managed by the BitmapManager class. It is also the base class for
all cursors. Every BBitmap has a shadow ServerBitmap object.
*/
class ServerBitmap {
public:
inline bool IsValid() const
{ return fInitialized; }
void Acquire();
inline area_id Area() const
{ return fArea; }
inline int32 AreaOffset() const
{ return fOffset; }
inline uint8* Bits() const
{ return fBuffer; }
inline uint32 BitsLength() const
{ return (uint32)(fBytesPerRow * fHeight); }
inline BRect Bounds() const
{ return BRect(0, 0, fWidth - 1, fHeight - 1); }
inline int32 Width() const
{ return fWidth; }
inline int32 Height() const
{ return fHeight; }
inline int32 BytesPerRow() const
{ return fBytesPerRow; }
inline uint8 BitsPerPixel() const
{ return fBitsPerPixel; }
inline color_space ColorSpace() const
{ return fSpace; }
//! Returns the identifier token for the bitmap
inline int32 Token() const
{ return fToken; }
//! Does a shallow copy of the bitmap passed to it
inline void ShallowCopy(const ServerBitmap *from);
void PrintToStream();
protected:
friend class BitmapManager;
friend class PicturePlayer;
ServerBitmap(BRect rect,
color_space space,
int32 flags,
int32 bytesPerRow = -1,
screen_id screen = B_MAIN_SCREEN_ID);
ServerBitmap(const ServerBitmap* bmp);
virtual ~ServerBitmap();
//! used by the BitmapManager
inline void _SetArea(area_id ID)
{ fArea = ID; }
//! used by the BitmapManager
inline void _SetBuffer(void *ptr)
{ fBuffer = (uint8*)ptr; }
bool _Release();
void _AllocateBuffer();
void _FreeBuffer();
void _HandleSpace(color_space space,
int32 bytesperline = -1);
bool fInitialized;
area_id fArea;
uint8* fBuffer;
int32 fReferenceCount;
int32 fWidth;
int32 fHeight;
int32 fBytesPerRow;
color_space fSpace;
int32 fFlags;
int fBitsPerPixel;
int32 fToken;
int32 fOffset;
};
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);
UtilityBitmap(const uint8* alreadyPaddedData,
uint32 width,
uint32 height,
color_space format);
virtual ~UtilityBitmap();
};
// ShallowCopy
void
ServerBitmap::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;
}
#endif // _SERVER_BITMAP_H_