Imported BitmapManager code. Not documented yet.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2700 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm 2003-02-13 00:03:31 +00:00
parent e16ebaf892
commit fde0b388cc
7 changed files with 1429 additions and 1 deletions

View File

@ -0,0 +1,116 @@
/*
BitmapManager:
Handler for allocating and freeing area memory for BBitmaps on the server side.
Utilizes the public domain pool allocator BGET.
*/
#include "BitmapManager.h"
#include "ServerBitmap.h"
#include <stdio.h>
// Define BGET function calls here because of C++ name mangling causes link problems
typedef long bufsize;
extern "C" void bpool(void *buffer, bufsize len);
extern "C" void *bget(bufsize size);
extern "C" void *bgetz(bufsize size);
extern "C" void *bgetr(void *buffer, bufsize newsize);
extern "C" void brel(void *buf);
extern "C" void bectl(int (*compact)(bufsize sizereq, int sequence),
void *(*acquire)(bufsize size),
void (*release)(void *buf), bufsize pool_incr);
extern "C" void bstats(bufsize *curalloc, bufsize *totfree, bufsize *maxfree,
long *nget, long *nrel);
extern "C" void bstatse(bufsize *pool_incr, long *npool, long *npget,
long *nprel, long *ndget, long *ndrel);
extern "C" void bufdump(void *buf);
extern "C" void bpoold(void *pool, int dumpalloc, int dumpfree);
extern "C" int bpoolv(void *pool);
// This is a call which makes BGET use a couple of home-grown functions which
// manage the buffer via area functions
extern "C" void set_area_buffer_management(void);
#define BITMAP_AREA_SIZE B_PAGE_SIZE * 2
BitmapManager::BitmapManager(void)
{
bmplist=new BList(0);
// When create_area is passed the B_ANY_ADDRESS flag, the address of the area
// is stored in the pointer to a pointer.
bmparea=create_area("bitmap_area",(void**)&buffer,B_ANY_ADDRESS,BITMAP_AREA_SIZE,
B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
if(bmparea==B_BAD_VALUE ||
bmparea==B_NO_MEMORY ||
bmparea==B_ERROR)
printf("PANIC: BitmapManager couldn't allocate area!!\n");
lock=create_sem(1,"bmpmanager_lock");
if(lock<0)
printf("PANIC: BitmapManager couldn't allocate locking semaphore!!\n");
set_area_buffer_management();
bpool(buffer,BITMAP_AREA_SIZE);
}
BitmapManager::~BitmapManager(void)
{
if(bmplist->CountItems()>0)
{
ServerBitmap *tbmp=NULL;
int32 itemcount=bmplist->CountItems();
for(int32 i=0; i<itemcount; i++)
{
tbmp=(ServerBitmap*)bmplist->RemoveItem(0L);
if(tbmp)
{
brel(tbmp->_buffer);
delete tbmp;
tbmp=NULL;
}
}
}
delete bmplist;
delete_area(bmparea);
delete_sem(lock);
}
ServerBitmap * BitmapManager::CreateBitmap(BRect bounds, color_space space, int32 flags,
int32 bytes_per_row=-1, screen_id screen=B_MAIN_SCREEN_ID)
{
acquire_sem(lock);
ServerBitmap *bmp=new ServerBitmap(bounds, space, flags, bytes_per_row);
// Server version of this code will also need to handle such things as
// bitmaps which accept child views by checking the flags.
uint8 *bmpbuffer=(uint8 *)bget(bmp->BitsLength());
if(!bmpbuffer)
{
delete bmp;
return NULL;
}
bmp->_area=area_for(bmpbuffer);
bmp->_buffer=bmpbuffer;
bmplist->AddItem(bmp);
release_sem(lock);
return bmp;
}
void BitmapManager::DeleteBitmap(ServerBitmap *bitmap)
{
acquire_sem(lock);
ServerBitmap *tbmp=(ServerBitmap*)bmplist->RemoveItem(bmplist->IndexOf(bitmap));
if(!tbmp)
{
release_sem(lock);
return;
}
// Server code will require a check to ensure bitmap doesn't have its own area
brel(tbmp->_buffer);
delete tbmp;
release_sem(lock);
}

View File

@ -0,0 +1,27 @@
#ifndef BITMAP_MANAGER_H_
#define BITMAP_MANAGER_H_
#include <GraphicsDefs.h>
#include <List.h>
#include <Rect.h>
#include <OS.h>
#include "TokenHandler.h"
class ServerBitmap;
class BitmapManager
{
public:
BitmapManager(void);
~BitmapManager(void);
ServerBitmap *CreateBitmap(BRect bounds, color_space space, int32 flags,
int32 bytes_per_row=-1, screen_id screen=B_MAIN_SCREEN_ID);
void DeleteBitmap(ServerBitmap *bitmap);
protected:
BList *bmplist;
area_id bmparea;
int8 *buffer;
TokenHandler tokenizer;
sem_id lock;
};
#endif

View File

@ -7,7 +7,9 @@ UseFreeTypeHeaders ;
Server app_server :
# Misc. Sources
areafunc.c
Angle.cpp
bget.c
TokenHandler.cpp
PatternHandler.cpp
@ -18,6 +20,7 @@ Server app_server :
# Manager Classes
AppServer.cpp
BitmapManager.cpp
CursorManager.cpp
Desktop.cpp
ServerApp.cpp

View File

@ -31,6 +31,8 @@
#include <Rect.h>
#include <OS.h>
class BitmapManager;
/*!
\class ServerBitmap ServerBitmap.h
\brief Bitmap class used inside the server.
@ -81,7 +83,8 @@ public:
bool InitCheck(void) { return _initialized; }
protected:
friend BitmapManager;
//! Internal function used by the BitmapManager.
void _SetArea(area_id ID) { _area=ID; }

View File

@ -0,0 +1,48 @@
#include <OS.h>
#include "bget.h"
#include <stdio.h>
void * expand_area_storage(long size);
void contract_area_storage(void *buffer);
void set_area_buffer_management(void)
{
bectl(NULL, expand_area_storage, contract_area_storage, B_PAGE_SIZE);
}
void * expand_area_storage(long size)
{
long areasize=0;
area_id a;
int *parea;
if(size<B_PAGE_SIZE)
areasize=B_PAGE_SIZE;
else
{
if((size % B_PAGE_SIZE)!=0)
areasize=((long)(size/B_PAGE_SIZE)+1)*B_PAGE_SIZE;
else
areasize=size;
}
a=create_area("bitmap_area",(void**)&parea,B_ANY_ADDRESS,areasize,
B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
if(a==B_BAD_VALUE ||
a==B_NO_MEMORY ||
a==B_ERROR)
{
printf("PANIC: BitmapManager couldn't allocate area!!\n");
return NULL;
}
return parea;
}
void contract_area_storage(void *buffer)
{
area_id trash=area_for(buffer);
if(trash==B_ERROR)
return;
delete_area(trash);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,31 @@
/*
Interface definitions for bget.c, the memory management package.
*/
#define PROTOTYPES
#ifndef _
#ifdef PROTOTYPES
#define _(x) x /* If compiler knows prototypes */
#else
#define _(x) () /* It it doesn't */
#endif /* PROTOTYPES */
#endif
typedef long bufsize;
void bpool _((void *buffer, bufsize len));
void *bget _((bufsize size));
void *bgetz _((bufsize size));
void *bgetr _((void *buffer, bufsize newsize));
void brel _((void *buf));
void bectl _((int (*compact)(bufsize sizereq, int sequence),
void *(*acquire)(bufsize size),
void (*release)(void *buf), bufsize pool_incr));
void bstats _((bufsize *curalloc, bufsize *totfree, bufsize *maxfree,
long *nget, long *nrel));
void bstatse _((bufsize *pool_incr, long *npool, long *npget,
long *nprel, long *ndget, long *ndrel));
void bufdump _((void *buf));
void bpoold _((void *pool, int dumpalloc, int dumpfree));
int bpoolv _((void *pool));