haiku/docs/develop/servers/app_server/BitmapManager.htm

124 lines
7.1 KiB
HTML

<HTML>
<HEAD>
<TITLE>BitmapManager.htm</TITLE>
<style type="text/css">
<!--
.Default {background-color: rgb(255,255,255); color: rgb(0,0,0); font-family: 'Dutch801 Rm BT'; font-size: 12pt}
.OBOS-Function-Def {background-color: rgb(255,255,255); color: rgb(0,0,0); font-family: 'Dutch801 Rm BT'; font-size: 16pt}
.OBOS-Title {background-color: rgb(255,255,255); color: rgb(0,128,0); font-family: 'Dutch801 Rm BT'; font-size: 24pt}
.Text-Background {background-color: rgb(255,255,255)}
.GR-Default {}
.Body {margin: 0px}
.Footer {margin: 0px}
.Header {margin: 0px}
.WP-Default {text-align: left; text-indent: 0px; margin-left: 0px; margin-right: 0px}
-->
</style>
</HEAD>
<BODY BGCOLOR="#ffffff">
<DIV class="sheet" id="Sheet 1">
<P class="Body" style="margin: 0px"><span class="OBOS-Title">BitmapManager class</span><span style="color: rgb(0,0,0); font-size: 24pt"></span></P>
<P class="Body" style="margin: 0px"><BR>
</P>
<P class="Body" style="margin: 0px">The BitmapManager object handles all ServerBitmap allocation and deallocation. The rest of the server uses CreateBitmap and DeleteBitmap instead of new and delete. It utilizes the outside pool manager BGET.</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<HR>
</P>
<P class="Body" style="margin: 0px"><BR>
Member Functions</P>
<P class="Body" style="margin: 0px"><BR>
</P>
<TABLE WIDTH=621 HEIGHT=105 BORDER=1 CELLPADDING=1 CELLSPACING=2>
<TR>
<TD WIDTH=238 HEIGHT=17>
<P class="Body" style="margin: 0px">BitmapManager(void)</P>
</TD>
<TD WIDTH=228 HEIGHT=17>
<P class="Body" style="margin: 0px">~BitmapManager(void)</P>
</TD>
</TR>
<TR>
<TD WIDTH=238 HEIGHT=62>
<P class="Body" style="margin: 0px">ServerBitmap *CreateBitmap(BRect bounds, color_space space, int32 flags, int32 bytes_per_row=-1, screen_id screen=B_MAIN_SCREEN_ID)</P>
</TD>
<TD WIDTH=228 HEIGHT=62>
<P class="Body" style="margin: 0px">void DeleteBitmap(ServerBitmap *bitmap)</P>
</TD>
</TR>
</TABLE>
<P class="Body" style="margin: 0px"><BR>
<BR>
Global Functions</P>
<P class="Body" style="margin: 0px"><BR>
extern "C" void set_area_buffer_management(void);</P>
<P class="Body" style="margin: 0px">void * expand_area_storage(long size)</P>
<P class="Body" style="margin: 0px">void contract_area_storage(void *buffer)</P>
<P class="Body" style="margin: 0px"><BR>
<HR>
</P>
<P class="Body" style="margin: 0px"><span class="OBOS-Function-Def">BitmapManager(void)</span></P>
<P class="Body" style="margin: 0px"><BR>
1) Create the bitmap list</P>
<P class="Body" style="margin: 0px">2) Create the bitmap area</P>
<P class="Body" style="margin: 0px">3) Allocate the access semaphore</P>
<P class="Body" style="margin: 0px">4) Call set_buffer_area_management</P>
<P class="Body" style="margin: 0px">5) Set up the buffer pool via bpool</P>
<P class="Body" style="margin: 0px"><BR>
<span class="OBOS-Function-Def">~BitmapManager(void)</span></P>
<P class="Body" style="margin: 0px"><BR>
1) Iterate over each item in the bitmap list, removing each item, calling brel() on its buffer, and deleting it.</P>
<P class="Body" style="margin: 0px">2) Delete the bitmap list</P>
<P class="Body" style="margin: 0px">3) Delete the bitmap area</P>
<P class="Body" style="margin: 0px">4) Free the access semaphore</P>
<P class="Body" style="margin: 0px"><BR>
<span class="OBOS-Function-Def">ServerBitmap *CreateBitmap(BRect bounds, color_space space, int32 flags, int32 bytes_per_row=-1, screen_id screen=B_MAIN_SCREEN_ID)</span></P>
<P class="Body" style="margin: 0px"><BR>
CreateBitmap is called by outside objects to allocate a ServerBitmap object. If a problem occurs, it returns NULL.</P>
<P class="Body" style="margin: 0px"><BR>
1) Acquire the access semaphore</P>
<P class="Body" style="margin: 0px">2) Verify parameters and if any are invalid, spew an error to stderr and return NULL</P>
<P class="Body" style="margin: 0px">3) Allocate a new ServerBitmap</P>
<P class="Body" style="margin: 0px">4) Allocate a buffer for the bitmap via bget() with the bitmap's theoretical buffer length</P>
<P class="Body" style="margin: 0px">5) If NULL, delete the bitmap and return NULL</P>
<P class="Body" style="margin: 0px">6) Set the bitmap's area and buffer to the appropriate values (area_for buffer and buffer)</P>
<P class="Body" style="margin: 0px">7) Add the bitmap to the bitmap list</P>
<P class="Body" style="margin: 0px">8) Release the access semaphore</P>
<P class="Body" style="margin: 0px">9) Return the bitmap</P>
<P class="Body" style="margin: 0px"><BR>
<span class="OBOS-Function-Def">void DeleteBitmap(ServerBitmap *bitmap)</span></P>
<P class="Body" style="margin: 0px"><span class="Default"><BR>
Frees a ServerBitmap allocated by CreateBitmap()</span></P>
<P class="Body" style="margin: 0px"><span class="Default"><BR>
1) Acquire the access semaphore</span></P>
<P class="Body" style="margin: 0px"><span class="Default">2) Find the bitmap in the list</span></P>
<P class="Body" style="margin: 0px"><span class="Default">3) Remove the bitmap from the list or release the semaphore and return if not found</span></P>
<P class="Body" style="margin: 0px"><span class="Default">4) call brel() on the bitmap's buffer if it is non-NULL</span></P>
<P class="Body" style="margin: 0px"><span class="Default">5) delete the bitmap</span></P>
<P class="Body" style="margin: 0px"><span class="Default">6) Release the access semaphore</span></P>
<P class="Body" style="margin: 0px"><span class="Default"><BR>
</span><span class="OBOS-Function-Def">extern "C" void set_area_buffer_management(void)</span></P>
<P class="Body" style="margin: 0px"><span class="Default"><BR>
C function defined externally to point the BGET manager to our homegrown area allocation and deallocation functions.</span></P>
<P class="Body" style="margin: 0px"><span class="Default"><BR>
</span><span class="OBOS-Function-Def">void * expand_area_storage(long size)</span></P>
<P class="Body" style="margin: 0px"><BR>
"Internal" global function accessed only by set_area_buffer_management and BGET to handle the task of adding more area space to make room for more bitmaps.</P>
<P class="Body" style="margin: 0px"><BR>
1) If size is less than B_PAGE_SIZE, set the area size to B_PAGE_SIZE</P>
<P class="Body" style="margin: 0px">2) If size % B_PAGE_SIZE, set area size to (size/B_PAGE_SIZE)+1)*B_PAGE_SIZE, otherwise setting it to the given size</P>
<P class="Body" style="margin: 0px">3) Call create_area with the area size.</P>
<P class="Body" style="margin: 0px">4) If it couldn't allocate an area, write a panic message to stderr and return NULL, otherwise, return the pointer to the area.</P>
<P class="Body" style="margin: 0px"><BR>
<span class="OBOS-Function-Def">void contract_area_storage(void *buffer)</span></P>
<P class="Body" style="margin: 0px"><span class="Default"><BR>
</span>"Internal" global function accessed only by set_area_buffer_management and BGET to <span class="Default">remove the area which was previously used for the bitmap pool</span></P>
<P class="Body" style="margin: 0px"><span class="Default"><BR>
1) Call area_for on the buffer</span></P>
<P class="Body" style="margin: 0px"><span class="Default">2) If the area_id is not B_ERROR, call delete_area on its area_id.</span></P>
<DIV class="layer" id="Layer 1">
</DIV>
</DIV>
</BODY>
</HTML>