3 <TITLE>BitmapManager.htm
</TITLE>
4 <style type=
"text/css">
6 .Default {background-color: rgb
(255,255,255); color: rgb
(0,0,0); font-family: 'Dutch801 Rm BT'; font-size: 12pt}
7 .OBOS-Function-Def {background-color: rgb
(255,255,255); color: rgb
(0,0,0); font-family: 'Dutch801 Rm BT'; font-size: 16pt}
8 .OBOS-Title {background-color: rgb
(255,255,255); color: rgb
(0,128,0); font-family: 'Dutch801 Rm BT'; font-size: 24pt}
9 .Text-Background {background-color: rgb
(255,255,255)}
14 .WP-Default {text-align: left
; text-indent: 0px; margin-left: 0px; margin-right: 0px}
18 <BODY BGCOLOR=
"#ffffff">
19 <DIV class=
"sheet" id=
"Sheet 1">
20 <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>
21 <P class=
"Body" style=
"margin: 0px"><BR>
23 <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>
24 <P class=
"Body" style=
"margin: 0px"><BR>
28 <P class=
"Body" style=
"margin: 0px"><BR>
30 <P class=
"Body" style=
"margin: 0px"><BR>
32 <TABLE WIDTH=
621 HEIGHT=
105 BORDER=
1 CELLPADDING=
1 CELLSPACING=
2>
34 <TD WIDTH=
238 HEIGHT=
17>
35 <P class=
"Body" style=
"margin: 0px">BitmapManager(void)
</P>
37 <TD WIDTH=
228 HEIGHT=
17>
38 <P class=
"Body" style=
"margin: 0px">~BitmapManager(void)
</P>
42 <TD WIDTH=
238 HEIGHT=
62>
43 <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>
45 <TD WIDTH=
228 HEIGHT=
62>
46 <P class=
"Body" style=
"margin: 0px">void DeleteBitmap(ServerBitmap *bitmap)
</P>
50 <P class=
"Body" style=
"margin: 0px"><BR>
53 <P class=
"Body" style=
"margin: 0px"><BR>
54 extern
"C" void set_area_buffer_management(void);
</P>
55 <P class=
"Body" style=
"margin: 0px">void * expand_area_storage(long size)
</P>
56 <P class=
"Body" style=
"margin: 0px">void contract_area_storage(void *buffer)
</P>
57 <P class=
"Body" style=
"margin: 0px"><BR>
60 <P class=
"Body" style=
"margin: 0px"><span class=
"OBOS-Function-Def">BitmapManager(void)
</span></P>
61 <P class=
"Body" style=
"margin: 0px"><BR>
62 1) Create the bitmap list
</P>
63 <P class=
"Body" style=
"margin: 0px">2) Create the bitmap area
</P>
64 <P class=
"Body" style=
"margin: 0px">3) Allocate the access semaphore
</P>
65 <P class=
"Body" style=
"margin: 0px">4) Call set_buffer_area_management
</P>
66 <P class=
"Body" style=
"margin: 0px">5) Set up the buffer pool via bpool
</P>
67 <P class=
"Body" style=
"margin: 0px"><BR>
68 <span class=
"OBOS-Function-Def">~BitmapManager(void)
</span></P>
69 <P class=
"Body" style=
"margin: 0px"><BR>
70 1) Iterate over each item in the bitmap list, removing each item, calling brel() on its buffer, and deleting it.
</P>
71 <P class=
"Body" style=
"margin: 0px">2) Delete the bitmap list
</P>
72 <P class=
"Body" style=
"margin: 0px">3) Delete the bitmap area
</P>
73 <P class=
"Body" style=
"margin: 0px">4) Free the access semaphore
</P>
74 <P class=
"Body" style=
"margin: 0px"><BR>
75 <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>
76 <P class=
"Body" style=
"margin: 0px"><BR>
77 CreateBitmap is called by outside objects to allocate a ServerBitmap object. If a problem occurs, it returns NULL.
</P>
78 <P class=
"Body" style=
"margin: 0px"><BR>
79 1) Acquire the access semaphore
</P>
80 <P class=
"Body" style=
"margin: 0px">2) Verify parameters and if any are invalid, spew an error to stderr and return NULL
</P>
81 <P class=
"Body" style=
"margin: 0px">3) Allocate a new ServerBitmap
</P>
82 <P class=
"Body" style=
"margin: 0px">4) Allocate a buffer for the bitmap via bget() with the bitmap's theoretical buffer length
</P>
83 <P class=
"Body" style=
"margin: 0px">5) If NULL, delete the bitmap and return NULL
</P>
84 <P class=
"Body" style=
"margin: 0px">6) Set the bitmap's area and buffer to the appropriate values (area_for buffer and buffer)
</P>
85 <P class=
"Body" style=
"margin: 0px">7) Add the bitmap to the bitmap list
</P>
86 <P class=
"Body" style=
"margin: 0px">8) Release the access semaphore
</P>
87 <P class=
"Body" style=
"margin: 0px">9) Return the bitmap
</P>
88 <P class=
"Body" style=
"margin: 0px"><BR>
89 <span class=
"OBOS-Function-Def">void DeleteBitmap(ServerBitmap *bitmap)
</span></P>
90 <P class=
"Body" style=
"margin: 0px"><span class=
"Default"><BR>
91 Frees a ServerBitmap allocated by CreateBitmap()
</span></P>
92 <P class=
"Body" style=
"margin: 0px"><span class=
"Default"><BR>
93 1) Acquire the access semaphore
</span></P>
94 <P class=
"Body" style=
"margin: 0px"><span class=
"Default">2) Find the bitmap in the list
</span></P>
95 <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>
96 <P class=
"Body" style=
"margin: 0px"><span class=
"Default">4) call brel() on the bitmap's buffer if it is non-NULL
</span></P>
97 <P class=
"Body" style=
"margin: 0px"><span class=
"Default">5) delete the bitmap
</span></P>
98 <P class=
"Body" style=
"margin: 0px"><span class=
"Default">6) Release the access semaphore
</span></P>
99 <P class=
"Body" style=
"margin: 0px"><span class=
"Default"><BR>
100 </span><span class=
"OBOS-Function-Def">extern
"C" void set_area_buffer_management(void)
</span></P>
101 <P class=
"Body" style=
"margin: 0px"><span class=
"Default"><BR>
102 C function defined externally to point the BGET manager to our homegrown area allocation and deallocation functions.
</span></P>
103 <P class=
"Body" style=
"margin: 0px"><span class=
"Default"><BR>
104 </span><span class=
"OBOS-Function-Def">void * expand_area_storage(long size)
</span></P>
105 <P class=
"Body" style=
"margin: 0px"><BR>
106 "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>
107 <P class=
"Body" style=
"margin: 0px"><BR>
108 1) If size is less than B_PAGE_SIZE, set the area size to B_PAGE_SIZE
</P>
109 <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>
110 <P class=
"Body" style=
"margin: 0px">3) Call create_area with the area size.
</P>
111 <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>
112 <P class=
"Body" style=
"margin: 0px"><BR>
113 <span class=
"OBOS-Function-Def">void contract_area_storage(void *buffer)
</span></P>
114 <P class=
"Body" style=
"margin: 0px"><span class=
"Default"><BR>
115 </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>
116 <P class=
"Body" style=
"margin: 0px"><span class=
"Default"><BR>
117 1) Call area_for on the buffer
</span></P>
118 <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>
119 <DIV class=
"layer" id=
"Layer 1">