Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

BitmapScreen.cpp

Go to the documentation of this file.
00001 // BitmapScreen.cpp: implementation of the BitmapScreen class.
00004 
00005 
00006 #include "stdafx.h"
00007 #include "BitmapScreen.h"
00008 
00010 // Construction
00012 
00016 BitmapScreen::BitmapScreen(const int tlX, const int tlY, const int w, const int h)
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 }
00025 
00027 // Member Functions
00029 
00035 void BitmapScreen::paint(HDC hDC)
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 }
00055 
00060 const DIBitmap* BitmapScreen::getReadBuffer()
00061 {
00062     currentBufferLock.WaitToRead();
00063     return &buffer[currentBuffer];
00064 }
00065 
00070 void BitmapScreen::DoneReading()
00071 {
00072     currentBufferLock.Done();
00073 }
00074 
00080 DIBitmap* BitmapScreen::getWriteBuffer()
00081 {
00082     WaitForSingleObject(writeMutex, INFINITE);
00083     return &buffer[0 == currentBuffer ? 1 : 0];
00084 }
00085 
00094 bool BitmapScreen::DoneWriting()
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 }
00113 
00114 

Generated on Mon Mar 25 06:29:58 2002 for Window Dressing by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001