#include <BitmapScreen.h>
Inherits VScreen.
Public Methods | |
DIBitmap * | getWriteBuffer () |
bool | DoneWriting () |
const DIBitmap * | getReadBuffer () |
void | DoneReading () |
void | paint (HDC) |
BitmapScreen (const int, const int, const int, const int) | |
Private Attributes | |
DIBitmap | buffer [2] |
Two DIBitmaps forming a double buffer. | |
HANDLE | writeMutex |
A Handle to a Mutex used for serialising calls to getWriteBuffer(). | |
CSWMRG | currentBufferLock |
A single writer multiple reader guard protecting the switch between buffers. | |
volatile int | currentBuffer |
An index into the array of DIBitmaps. |
Definition at line 25 of file BitmapScreen.h.
|
Constructor - Takes the same parameters as VScreen Definition at line 16 of file BitmapScreen.cpp. References buffer, DIBitmap::createCompatible(), currentBuffer, and writeMutex.
00017 : VScreen(tlX, tlY, w, h) 00018 { 00019 currentBuffer = 0; 00020 buffer[0].createCompatible(w, h, 8); 00021 buffer[1].createCompatible(w, h, 8); 00022 00023 writeMutex = CreateMutex(NULL, false, NULL); 00024 } |
|
Releases the read lock. This most be called for each read lock obtained or a write lock will never suceed and block any other lock attempts. Definition at line 70 of file BitmapScreen.cpp. References currentBufferLock, and CSWMRG::Done(). Referenced by Cls_OnCommand(), Cls_OnCreate(), and UpdateHandler::update().
00071 { 00072 currentBufferLock.Done(); 00073 } |
|
After checking the validity of the updated buffer a write lock is obtained the buffers are switched and the lock released. The Mutex serialising writes is also released.
Definition at line 94 of file BitmapScreen.cpp. References buffer, currentBuffer, currentBufferLock, CSWMRG::Done(), VScreen::getHeight(), DIBitmap::getPBITMAPINFOHEADER(), VScreen::getWidth(), CSWMRG::WaitToWrite(), and writeMutex. Referenced by Cls_OnCreate(), and UpdateHandler::update().
00095 { 00096 int otherBuffer = 0 == currentBuffer ? 1 : 0; 00097 00098 if( abs(buffer[otherBuffer].getPBITMAPINFOHEADER()->biHeight) != abs(VScreen::getHeight()) 00099 || buffer[otherBuffer].getPBITMAPINFOHEADER()->biWidth != VScreen::getWidth() ){ 00100 assert( ReleaseMutex(writeMutex) ); 00101 return false; 00102 } 00103 00104 currentBufferLock.WaitToWrite(); 00105 00106 currentBuffer = otherBuffer; 00107 00108 currentBufferLock.Done(); 00109 00110 assert( ReleaseMutex(writeMutex) ); 00111 return true; 00112 } |
|
Obtains a read lock and returns a pointer to a const DIBitmap. The pointer should be considered invalid after calling DoneReading. Definition at line 60 of file BitmapScreen.cpp. References buffer, currentBuffer, currentBufferLock, and CSWMRG::WaitToRead(). Referenced by Cls_OnCommand(), Cls_OnCreate(), and UpdateHandler::update().
00061 { 00062 currentBufferLock.WaitToRead(); 00063 return &buffer[currentBuffer]; 00064 } |
|
Returns a pointer to a writable DIBitmap. This function is serialised using the writeMutex. The pointer should be considered invalid after calling DoneWriting. Definition at line 80 of file BitmapScreen.cpp. References buffer, currentBuffer, and writeMutex. Referenced by Cls_OnCreate(), and UpdateHandler::update().
00081 { 00082 WaitForSingleObject(writeMutex, INFINITE); 00083 return &buffer[0 == currentBuffer ? 1 : 0]; 00084 } |
|
Requests a read lock and then sets the dibs bits to the specified DC. Releases the read lock before returning.
Reimplemented from VScreen. Definition at line 35 of file BitmapScreen.cpp. References buffer, currentBuffer, currentBufferLock, CSWMRG::Done(), VScreen::getRgnRect(), and CSWMRG::WaitToRead(). Referenced by Cls_OnPaint().
00036 { 00037 currentBufferLock.WaitToRead(); 00038 00039 RECT regionR = VScreen::getRgnRect(); 00040 00041 SetDIBitsToDevice( 00042 hDC, 00043 regionR.left, regionR.top, 00044 buffer[currentBuffer].getPBITMAPINFOHEADER()->biWidth, 00045 abs(buffer[currentBuffer].getPBITMAPINFOHEADER()->biHeight), 00046 0, 0, 00047 0, 00048 abs(buffer[currentBuffer].getPBITMAPINFOHEADER()->biHeight), 00049 buffer[currentBuffer].getPBytes(), 00050 buffer[currentBuffer].getPBITMAPINFO(), 00051 DIB_RGB_COLORS); 00052 00053 currentBufferLock.Done(); 00054 } |