Implemented reference counting of ServerBitmaps, made constructor and destructor private,

as only the BitmapManager class is allowed to call them.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15718 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-12-29 15:36:18 +00:00
parent 93052717b0
commit 4acb99b60f
3 changed files with 85 additions and 81 deletions
+36 -49
View File
@@ -1,36 +1,19 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2005, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: ServerBitmap.h
// Author: DarkWyrm <[email protected]>
// Description: Bitmap class used inside the server
//
//------------------------------------------------------------------------------
/*
* Copyright 2001-2005, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* DarkWyrm <[email protected]>
*/
#ifndef _SERVER_BITMAP_H_
#define _SERVER_BITMAP_H_
#include <GraphicsDefs.h>
#include <Rect.h>
#include <OS.h>
class BitmapManager;
/*!
@@ -43,14 +26,7 @@ class BitmapManager;
*/
class ServerBitmap {
public:
ServerBitmap(BRect rect,
color_space space,
int32 flags,
int32 bytesperline = -1,
screen_id screen = B_MAIN_SCREEN_ID);
ServerBitmap(const ServerBitmap* bmp);
virtual ~ServerBitmap();
void Acquire();
/*!
\brief Returns the area in which the buffer resides
@@ -60,11 +36,11 @@ class ServerBitmap {
*/
inline area_id Area() const
{ return fArea; }
// Returns the offset of the bitmap in its area
inline int32 AreaOffset() const
{ return fOffset; }
//! Returns the bitmap's buffer
inline uint8* Bits() const
{ return fBuffer; }
@@ -74,21 +50,21 @@ class ServerBitmap {
inline BRect Bounds() const
{ return BRect(0, 0, fWidth - 1, fHeight - 1); }
//! Returns the number of bytes in each row, including padding
inline int32 BytesPerRow() const
{ return fBytesPerRow; }
inline uint8 BitsPerPixel() const
{ return fBitsPerPixel; }
inline color_space ColorSpace() const
{ return fSpace; }
//! Returns the bitmap's width in pixels per row
inline int32 Width() const
{ return fWidth; }
//! Returns the bitmap's row count
inline int32 Height() const
{ return fHeight; }
@@ -99,32 +75,43 @@ class ServerBitmap {
//! 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);
protected:
friend class BitmapManager;
friend class PicturePlayer;
ServerBitmap(BRect rect,
color_space space,
int32 flags,
int32 bytesperline = -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; }
{ fArea = ID; }
//! used by the BitmapManager
inline void _SetBuffer(void *ptr)
{ fBuffer=(uint8*)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;
@@ -159,7 +146,7 @@ ServerBitmap::ShallowCopy(const ServerBitmap* from)
{
if (!from)
return;
fInitialized = from->fInitialized;
fArea = from->fArea;
fBuffer = from->fBuffer;