Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

DDRAWDisplay.h File Reference

#include "basetype.h"
#include "DisplayModeInfo.h"

Go to the source code of this file.

Typedefs

typedef DDRAWDisplay DDRAWDisplay

Functions

void DDRAWDisplay_GetDisplayFormat (const DDRAWDisplay *D, int32 *Width, int32 *Height, int32 *BitsPerPixel, uint32 *Flags)
geBoolean DDRAWDisplay_GetDisplayInfo (char *DescriptionString, unsigned int DescriptionStringMaxLength, DisplayModeInfo *Info)
geBoolean DDRAWDisplay_GetPixelFormat (DDRAWDisplay *D, int32 *bytes_per_pixel, int32 *R_shift, uint32 *R_mask, int32 *R_width, int32 *G_shift, uint32 *G_mask, int32 *G_width, int32 *B_shift, uint32 *B_mask, int32 *B_width)
geBoolean DDRAWDisplay_Lock (DDRAWDisplay *D, uint8 **Buffer, int32 *Pitch)
geBoolean DDRAWDisplay_Unlock (DDRAWDisplay *D)
geBoolean DDRAWDisplay_Blit (DDRAWDisplay *D)
geBoolean DDRAWDisplay_Wipe (DDRAWDisplay *D, uint32 color)
geBoolean DDRAWDisplay_SetActive (DDRAWDisplay *D, geBoolean Active)
void DDRAWDisplay_Destroy (DDRAWDisplay **D)


Typedef Documentation

typedef struct DDRAWDisplay DDRAWDisplay
 

Definition at line 34 of file DDRAWDisplay.h.


Function Documentation

geBoolean DDRAWDisplay_Blit DDRAWDisplay D  ) 
 

Definition at line 347 of file DDRAWDisplay.c.

References DDRAWDisplay::bActive, tagRECT::bottom, DDRAWDisplay_IsValid(), DDRAWDisplay_RestoreAll(), FASTBLT, FLIP, GE_FALSE, GE_TRUE, geBoolean, geErrorLog_AddString, tagRECT::left, DDRAWDisplay::lpDDSBack, DDRAWDisplay::lpDDSPrimary, DDRAWDisplay::ModeFlags, NULL, tagRECT::right, tagRECT::top, and VIDEO.

Referenced by Display_Blit().

00348 {
00349         HRESULT                 ddrval;
00350         DDSURFACEDESC2  ddsd;
00351         RECT                    rDest, rSrc;
00352         int                             Forever=1;
00353         assert( DDRAWDisplay_IsValid(D)!=GE_FALSE );
00354 
00355         if(!D->bActive)
00356         {
00357                 return  GE_TRUE;
00358         }
00359 
00360         memset(&ddsd, 0, sizeof(DDSCAPS2));
00361         ddsd.dwSize     =sizeof(ddsd);
00362         ddsd.dwFlags=DDSD_HEIGHT | DDSD_WIDTH; 
00363 
00364         D->lpDDSBack->lpVtbl->GetSurfaceDesc(D->lpDDSBack, &ddsd);
00365         rDest.left      =rDest.top      =0;
00366         rDest.right     =ddsd.dwWidth-1;
00367         rDest.bottom=ddsd.dwHeight-1;
00368 
00369         memset(&ddsd, 0, sizeof(DDSCAPS2));
00370         ddsd.dwSize     =sizeof(ddsd);
00371         ddsd.dwFlags=DDSD_HEIGHT | DDSD_WIDTH;
00372 
00373         D->lpDDSPrimary->lpVtbl->GetSurfaceDesc(D->lpDDSPrimary, &ddsd);
00374         rSrc.left       =rSrc.top       =0;
00375         rSrc.right      =ddsd.dwWidth-1;
00376         rSrc.bottom     =ddsd.dwHeight-1;
00377 
00378         ddrval  =DD_OK;
00379         if((D->ModeFlags & VIDEO) && (D->ModeFlags & FASTBLT))
00380         {
00381                 while(Forever)
00382                 {
00383                         ddrval  =D->lpDDSPrimary->lpVtbl->BltFast(D->lpDDSPrimary, 0, 0, D->lpDDSBack, NULL, 0);
00384                         if(ddrval==DD_OK)
00385                         {
00386                                 break;
00387                         }
00388 
00389                         if(ddrval==DDERR_SURFACELOST)
00390                         {
00391                                 if (DDRAWDisplay_RestoreAll(D) == GE_FALSE)
00392                                 {
00393                                         geErrorLog_AddString(-1,"DDRAWDisplay_Blit: lost surface",NULL);
00394                                         return  GE_FALSE;
00395                                 }
00396                         }
00397                         else if(ddrval!=DDERR_WASSTILLDRAWING)
00398                         {
00399                                 geErrorLog_AddString(-1,"DDRAWDisplay_Blit: was still drawing",NULL);
00400                                 return  GE_FALSE;
00401                         }
00402                 }
00403         }
00404         else if(D->ModeFlags & FLIP)
00405         {
00406                 while(Forever)
00407                 {
00408                         ddrval  =D->lpDDSPrimary->lpVtbl->Flip(D->lpDDSPrimary, D->lpDDSBack, DDFLIP_NOVSYNC);
00409                         if(ddrval==DD_OK)
00410                         {
00411                                 break;
00412                         }
00413 
00414                         if(ddrval==DDERR_SURFACELOST)
00415                         {
00416                                 if (DDRAWDisplay_RestoreAll(D)==GE_FALSE)
00417                                 {
00418                                         geErrorLog_AddString(-1,"DDRAWDisplay_Blit: lost surface",NULL);
00419                                         return  GE_FALSE;
00420                                 }
00421                         }
00422                         else if(ddrval!=DDERR_WASSTILLDRAWING)
00423                         {
00424                                 geErrorLog_AddString(-1,"DDRAWDisplay_Blit: was still drawing",NULL);
00425                                 return  GE_FALSE;
00426                         }
00427                 }
00428         }
00429         else    //safe blt
00430         {
00431                 while(Forever)
00432                 {
00433                         ddrval  =D->lpDDSPrimary->lpVtbl->Blt(D->lpDDSPrimary, NULL, D->lpDDSBack, NULL, DDBLT_WAIT, NULL);
00434                         if(ddrval==DD_OK)
00435                                 break;
00436 
00437                         if(ddrval==DDERR_SURFACELOST)
00438                         {
00439                                 if (DDRAWDisplay_RestoreAll(D)==GE_FALSE)
00440                                 {
00441                                         geErrorLog_AddString(-1,"DDRAWDisplay_Blit: lost surface",NULL);
00442                                         return  GE_FALSE;
00443                                 }
00444                         }
00445                         else if(ddrval!=DDERR_WASSTILLDRAWING)
00446                         {
00447                                 geErrorLog_AddString(-1,"DDRAWDisplay_Blit: was still drawing",NULL);
00448                                 return  GE_FALSE;
00449                         }
00450                 }
00451         }
00452         return GE_TRUE;
00453 }

void DDRAWDisplay_Destroy DDRAWDisplay **  D  ) 
 

Definition at line 179 of file DDRAWDisplay.c.

References DDRAWDisplay_IsValid(), DDRAWDisplay_UnloadDLL(), DDRAWDisplay_Unlock(), DDRAWDisplay::DLL, FLIP, GE_FALSE, GE_TRUE, DDRAWDisplay::Locked, DDRAWDisplay::lpDDSBack, DDRAWDisplay::lpDDSPrimary, DDRAWDisplay::ModeFlags, and NULL.

Referenced by Display_Destroy().

00180 {
00181         DDRAWDisplay *D;
00182 
00183         assert( pD );
00184         assert( DDRAWDisplay_IsValid(*pD)!=GE_FALSE );
00185         D = *pD;
00186 
00187         if (D->Locked == GE_TRUE)
00188                 DDRAWDisplay_Unlock(D);
00189 
00190         if (D->ModeFlags & FLIP)
00191         {
00192                 D->lpDDSBack    =NULL;
00193         }
00194         else
00195         {
00196                 if(D->lpDDSBack)
00197                 {
00198                         D->lpDDSBack->lpVtbl->Release(D->lpDDSBack);
00199                         D->lpDDSBack    =NULL;
00200                 }
00201         }
00202         if(D->lpDDSPrimary)
00203         {
00204                 D->lpDDSPrimary->lpVtbl->Release(D->lpDDSPrimary);
00205                 D->lpDDSPrimary =NULL;
00206         }
00207 
00208         DDRAWDisplay_UnloadDLL(&(D->DLL));
00209         
00210         free(D);
00211         *pD = NULL;
00212 }

void DDRAWDisplay_GetDisplayFormat const DDRAWDisplay D,
int32 Width,
int32 Height,
int32 BitsPerPixel,
uint32 Flags
 

Definition at line 161 of file DDRAWDisplay.c.

References DDRAWDisplay::BitsPerPixel, DDRAWDisplay::Height, DDRAWDisplay::ModeFlags, NULL, and DDRAWDisplay::Width.

Referenced by Display_GetDisplayFormat().

00166 {
00167         assert( D            != NULL );
00168         assert( Width        != NULL );
00169         assert( Height       != NULL );
00170         assert( BitsPerPixel != NULL );
00171         assert( Flags        != NULL );
00172 
00173         *Width        = D->Width;
00174         *Height       = D->Height;
00175         *BitsPerPixel = D->BitsPerPixel;
00176         *Flags        = D->ModeFlags;
00177 }       

geBoolean DDRAWDisplay_GetDisplayInfo char *  DescriptionString,
unsigned int  DescriptionStringMaxLength,
DisplayModeInfo Info
 

Definition at line 814 of file DDRAWDisplay.c.

References DDRAWDISPLAY_DESCRIPTION_STRING, DDRAWDisplay_LoadDLL(), DDRAWDisplay_ModeCallback(), DDRAWDisplay_UnloadDLL(), GE_FALSE, GE_TRUE, geBoolean, geErrorLog_Add, geErrorLog_AddString, DDRAWDisplay_DLLHooks::lpDD4, NULL, and TRUE.

Referenced by Display_GetDisplayInfo().

00817 {
00818         DDDEVICEIDENTIFIER      DDDeviceIdentifier;
00819         DDRAWDisplay_DLLHooks DLL={NULL,0};
00820         HRESULT                         ddrval = 0;
00821         
00822         assert( Info != NULL );
00823 
00824         if (DDRAWDisplay_LoadDLL( &DLL )==GE_FALSE)
00825                 {
00826                         geErrorLog_AddString(-1,"failed to load DDRAW dll",NULL);
00827                         return GE_FALSE;
00828                 }
00829         
00830         #if 0
00831                 {
00832                         //test for general dma support
00833                         DDCAPS                          ddcaps;
00834                         memset(&ddcaps, 0, sizeof(DDCAPS));
00835                         ddcaps.dwSize   =sizeof(ddcaps);
00836                         DLL.lpDD4->lpVtbl->GetCaps(DLL.lpDD4, &ddcaps, NULL);
00837 
00838                         if(ddcaps.dwCaps & DDCAPS_CANBLTSYSMEM)
00839                         {
00840                                 //System to video blits supported
00841                                 if(ddcaps.dwSVBCaps & DDCAPS_BLTQUEUE)
00842                                 {
00843                                         D->bDMA =TRUE;  //      DMA Asynch System to Video blits supported
00844                                 }
00845                         }
00846                 }
00847         #endif
00848 
00849 
00850         #if 0           // need this?
00851                 ddrval  =DLL.lpDD4->lpVtbl->SetCooperativeLevel(DLL.lpDD4, ActiveWnd,
00852                         DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
00853                 if(ddrval != DD_OK)
00854                         {
00855                                 geErrorLog_Add(-1,"Failed to set Cooperative Level",NULL);
00856                                 goto GetDisplayInfo_ERROR;
00857                         }
00858         #endif
00859         
00860         memset(&DDDeviceIdentifier, 0, sizeof(DDDeviceIdentifier));
00861 
00862         ddrval  =DLL.lpDD4->lpVtbl->GetDeviceIdentifier(DLL.lpDD4, &DDDeviceIdentifier,0);
00863         
00864         if(ddrval != DD_OK)
00865         {
00866                 geErrorLog_AddString(-1,"ddraw GetDeviceIdentifier() failed", NULL);
00867                 goto GetDisplayInfo_ERROR;
00868         }
00869 
00870         if (strlen(DDDeviceIdentifier.szDescription) + strlen(DDRAWDISPLAY_DESCRIPTION_STRING) >= DescriptionStringMaxLength)
00871                 {
00872                         geErrorLog_AddString(-1,"description string too short",NULL);
00873                         goto GetDisplayInfo_ERROR;
00874                 }
00875 
00876         strcpy(DescriptionString,DDRAWDISPLAY_DESCRIPTION_STRING);
00877 //      strcat(DescriptionString,DDDeviceIdentifier.szDescription);
00878 
00879 
00880         DLL.lpDD4->lpVtbl->EnumDisplayModes(DLL.lpDD4, 0, NULL, (LPVOID)Info, DDRAWDisplay_ModeCallback);
00881 
00882         DDRAWDisplay_UnloadDLL(&DLL);
00883         return          GE_TRUE;        
00884 
00885         GetDisplayInfo_ERROR:
00886                 DDRAWDisplay_UnloadDLL(&DLL);
00887                 return GE_FALSE;
00888 
00889 }

geBoolean DDRAWDisplay_GetPixelFormat DDRAWDisplay D,
int32 bytes_per_pixel,
int32 R_shift,
uint32 R_mask,
int32 R_width,
int32 G_shift,
uint32 G_mask,
int32 G_width,
int32 B_shift,
uint32 B_mask,
int32 B_width
 

Definition at line 640 of file DDRAWDisplay.c.

References DDRAWDisplay_IsValid(), GE_FALSE, GE_TRUE, geBoolean, DDRAWDisplay::lpDDSPrimary, NULL, and uint32.

Referenced by Display_GetPixelFormat().

00652 {
00653         DDPIXELFORMAT   ddpf;
00654         uint32                  i, j;
00655 
00656         assert( DDRAWDisplay_IsValid(D)!=GE_FALSE );
00657         //assert( pixel_pitch     != NULL );
00658         assert( bytes_per_pixel != NULL );
00659         assert( R_shift         != NULL );
00660         assert( R_mask          != NULL );
00661         assert( R_width         != NULL );
00662         assert( G_shift         != NULL );
00663         assert( G_mask          != NULL );
00664         assert( G_width         != NULL );
00665         assert( B_shift         != NULL );
00666         assert( B_mask          != NULL );
00667         assert( B_width         != NULL );
00668 
00669         ddpf.dwSize     =sizeof(ddpf);
00670         D->lpDDSPrimary->lpVtbl->GetPixelFormat(D->lpDDSPrimary, &ddpf);
00671 
00672         if(!(ddpf.dwFlags & DDPF_RGB))
00673         {
00674                 return GE_FALSE;
00675         }
00676         *bytes_per_pixel        =ddpf.dwRGBBitCount / 8;
00677         *R_mask         =ddpf.dwRBitMask;
00678         *G_mask         =ddpf.dwGBitMask;
00679         *B_mask         =ddpf.dwBBitMask;
00680 
00681         for(j=0,i=ddpf.dwRBitMask;!(i & 1);i>>=1,j++);
00682         *R_shift        =j;
00683 
00684         for(j=0,i=ddpf.dwGBitMask;!(i & 1);i>>=1,j++);
00685         *G_shift        =j;
00686 
00687         for(j=0,i=ddpf.dwBBitMask;!(i & 1);i>>=1,j++);
00688         *B_shift        =j;
00689 
00690         for(i=(ddpf.dwRBitMask>>*R_shift),*R_width=0;i;i >>= 1, (*R_width)++);
00691         for(i=(ddpf.dwGBitMask>>*G_shift),*G_width=0;i;i >>= 1, (*G_width)++);
00692         for(i=(ddpf.dwBBitMask>>*B_shift),*B_width=0;i;i >>= 1, (*B_width)++);
00693         return GE_TRUE;
00694 }

geBoolean DDRAWDisplay_Lock DDRAWDisplay D,
uint8 **  Buffer,
int32 Pitch
 

Definition at line 242 of file DDRAWDisplay.c.

References DDRAWDisplay::bActive, tagRECT::bottom, DDRAWDisplay::Buffer, DDRAWDisplay_IsValid(), DDRAWDisplay_RestoreAll(), GE_FALSE, GE_TRUE, geBoolean, geErrorLog_AddString, tagRECT::left, DDRAWDisplay::Locked, DDRAWDisplay::lpDDSBack, NULL, DDRAWDisplay::Pitch, tagRECT::right, tagRECT::top, and uint8.

Referenced by Display_Lock().

00243 {
00244         HRESULT                 ddrval;
00245         DDSURFACEDESC2  ddsd;
00246         RECT                    wrect;
00247         int Forever = 1;
00248         assert( DDRAWDisplay_IsValid(D)!=GE_FALSE );
00249 
00250         if(!D->bActive)
00251                 return GE_TRUE;
00252                 // <> should probably be GE_FALSE, but this stays compatible with the existing convention
00253 
00254         assert( Buffer != NULL );
00255         assert( Pitch  != NULL );
00256 
00257         if (D->Locked != GE_FALSE)
00258                 {
00259                         geErrorLog_AddString(-1,"DDRAWDisplay_Lock: already locked",NULL );
00260                         return GE_FALSE;
00261                 }
00262         
00263         memset(&ddsd, 0, sizeof(DDSCAPS2));
00264         ddsd.dwSize     =sizeof(ddsd);
00265         ddsd.dwFlags=DDSD_HEIGHT | DDSD_WIDTH;
00266 
00267         D->lpDDSBack->lpVtbl->GetSurfaceDesc(D->lpDDSBack, &ddsd);
00268         wrect.left   = 0;
00269         wrect.top    = 0;
00270         wrect.right  = ddsd.dwWidth-1;
00271         wrect.bottom = ddsd.dwHeight-1;
00272 
00273         while(Forever)
00274         {
00275                 ddrval  =D->lpDDSBack->lpVtbl->Lock(D->lpDDSBack, &wrect, &ddsd, DDLOCK_SURFACEMEMORYPTR, NULL);
00276                 if(ddrval==DD_OK)
00277                 {
00278                         break;
00279                 }
00280 
00281                 if(ddrval==DDERR_SURFACELOST)
00282                 {
00283                         if (DDRAWDisplay_RestoreAll(D) == GE_FALSE) 
00284                         {
00285                                 geErrorLog_AddString(-1,"DDRAWDisplay_Lock: lost ddraw surface", NULL);
00286                                 return  GE_FALSE;
00287                         }
00288                 }
00289                 else if(ddrval!=DDERR_WASSTILLDRAWING)
00290                 {
00291                         geErrorLog_AddString(-1,"DDRAWDisplay_Lock: was still drawing",geErrorLog_IntToString(ddrval));
00292                         return  GE_FALSE;
00293                 }
00294         }
00295         *Buffer = (uint8 *)ddsd.lpSurface;
00296         *Pitch  = ddsd.lPitch;
00297         D->Locked = GE_TRUE;
00298         D->Buffer = *Buffer;
00299         D->Pitch  = *Pitch;
00300         return GE_TRUE;
00301 }

geBoolean DDRAWDisplay_SetActive DDRAWDisplay D,
geBoolean  Active
 

Definition at line 727 of file DDRAWDisplay.c.

References DDRAWDisplay::bActive, DDRAWDisplay_RestoreAll(), GE_FALSE, GE_TRUE, geBoolean, geErrorLog_AddString, DDRAWDisplay::hWnd, DDRAWDisplay::lpDDSPrimary, and NULL.

Referenced by Display_SetActive().

00728 {
00729         assert( D != NULL );
00730 
00731         D->bActive      =wParam;
00732 
00733         if(D->bActive)
00734         {       
00735                 if(D->lpDDSPrimary->lpVtbl->IsLost(D->lpDDSPrimary)==DDERR_SURFACELOST)
00736                 {
00737                         if(DDRAWDisplay_RestoreAll(D)!=GE_FALSE)
00738                         {
00739                                 ShowWindow(D->hWnd, SW_SHOWNORMAL);     //dx doesn't restore it
00740                         }
00741                         else
00742                         {
00743                                 geErrorLog_AddString(-1,"DDRAWDisplay_SetActive: Couldn't restore surfaces",NULL);
00744                                 return GE_FALSE;
00745                         }
00746                 }
00747         }
00748         return  GE_TRUE;
00749 }

geBoolean DDRAWDisplay_Unlock DDRAWDisplay D  ) 
 

Definition at line 303 of file DDRAWDisplay.c.

References DDRAWDisplay::bActive, DDRAWDisplay_IsValid(), DDRAWDisplay_RestoreAll(), GE_FALSE, GE_TRUE, geBoolean, geErrorLog_AddString, DDRAWDisplay::Locked, DDRAWDisplay::lpDDSBack, and NULL.

Referenced by DDRAWDisplay_Destroy(), and Display_Unlock().

00304 {
00305         int Forever=1;
00306         HRESULT                 ddrval  =DD_OK;
00307         assert( DDRAWDisplay_IsValid(D)!=GE_FALSE );
00308 
00309         if(!D->bActive)
00310                 return GE_TRUE;
00311                 // <> should probably be GE_FALSE, but this stays compatible with the existing convention
00312 
00313         if (D->Locked != GE_TRUE)
00314                 {
00315                         geErrorLog_AddString(-1,"DDRAWDisplay_Unlock: surface not locked",NULL);
00316                         return GE_FALSE;
00317                 }
00318         
00319         D->Locked = GE_FALSE;
00320         
00321         while(Forever)
00322         {
00323                 ddrval  =D->lpDDSBack->lpVtbl->Unlock(D->lpDDSBack, NULL);
00324                 if(ddrval==DD_OK)
00325                         break;
00326 
00327                 #pragma message (" can you loose a locked surface?")
00328                 if(ddrval==DDERR_SURFACELOST)           
00329                 {
00330                         if (DDRAWDisplay_RestoreAll(D) == GE_FALSE)
00331                         {
00332                                 geErrorLog_AddString(-1,"DDRAWDisplay_Unlock: surface lost\n",NULL);
00333                                 return  GE_FALSE;
00334                         }
00335                 }
00336                 else if(ddrval!=DDERR_WASSTILLDRAWING)
00337                 {
00338                         geErrorLog_AddString(-1,"DDRAWDisplay_Unlock: was still drawing.",geErrorLog_IntToString(ddrval));
00339                         return  GE_FALSE;
00340                 }
00341         }
00342 
00343         D->Locked = GE_FALSE;
00344         return GE_TRUE;
00345 }

geBoolean DDRAWDisplay_Wipe DDRAWDisplay D,
uint32  color
 

Definition at line 697 of file DDRAWDisplay.c.

References DDRAWDisplay::bActive, DDRAWDisplay::Buffer, DDRAWDisplay_IsValid(), GE_FALSE, GE_TRUE, geBoolean, geErrorLog_AddString, DDRAWDisplay::Locked, DDRAWDisplay::lpDDSBack, NULL, and DDRAWDisplay::Pitch.

Referenced by Display_Wipe().

00698 {
00699         DDSURFACEDESC2  ddsd;
00700         int                             Width, Height;
00701 
00702         assert( DDRAWDisplay_IsValid(D)!=GE_FALSE );
00703 
00704         if(!D->bActive)
00705         {
00706                 return GE_FALSE;
00707         }
00708 
00709         if (!D->Locked)
00710                 {
00711                         geErrorLog_AddString(-1,"DDRAWDisplay_Wipe: surface not locked",NULL );
00712                         return GE_FALSE;
00713                 }
00714         memset(&ddsd, 0, sizeof(DDSCAPS2));
00715         ddsd.dwSize     =sizeof(ddsd);
00716         ddsd.dwFlags=DDSD_HEIGHT | DDSD_WIDTH;
00717         #pragma message ("this may not be necessary")
00718         D->lpDDSBack->lpVtbl->GetSurfaceDesc(D->lpDDSBack, &ddsd);
00719 
00720         Width   =ddsd.dwWidth;
00721         Height  =ddsd.dwHeight;
00722 
00723         memset(D->Buffer, color, (Height*D->Pitch));
00724         return GE_TRUE;
00725 }


Generated on Tue Sep 30 12:37:24 2003 for GTestAndEngine by doxygen 1.3.2