00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <stdlib.h>
00024 #include <assert.h>
00025 #include "DisplayModeInfo.h"
00026
00027 #ifdef GENESIS_VERSION_2
00028 #include "errorlog.h"
00029 #else
00030 #define geErrorLog_AddString(Error,xx,yy)
00031 #endif
00032
00033
00034 #define DISPLAYMODES_MAX 16
00035
00036 typedef struct DisplayModeInfo_Data
00037 {
00038 int Width;
00039 int Height;
00040 int BitsPerPixel;
00041 uint32 Flags;
00042 } DisplayModeInfo_Data;
00043
00044
00045 typedef struct DisplayModeInfo
00046 {
00047 DisplayModeInfo_Data Mode[DISPLAYMODES_MAX];
00048 int ModeCount;
00049 } DisplayModeInfo;
00050
00051
00052 DisplayModeInfo *DisplayModeInfo_Create(void)
00053 {
00054 DisplayModeInfo *Info;
00055
00056 Info = malloc(sizeof(*Info));
00057 if (Info == NULL)
00058 {
00059 geErrorLog_AddString(GE_ERR_MEMORY_RESOURCE,"DisplayModeInfo: unable to get memory for object",NULL);
00060 return NULL;
00061 }
00062 Info-> ModeCount = 0;
00063 return Info;
00064 }
00065
00066 void DisplayModeInfo_Destroy(DisplayModeInfo **Info)
00067 {
00068 assert ( Info != NULL );
00069 assert (*Info != NULL );
00070 free ( *Info );
00071 *Info = NULL;
00072 }
00073
00074 int DisplayModeInfo_GetModeCount(DisplayModeInfo *Info)
00075 {
00076 assert( Info != NULL );
00077
00078 return Info->ModeCount;
00079 }
00080
00081 geBoolean DisplayModeInfo_AddEntry(DisplayModeInfo *Info,
00082 int Width,
00083 int Height,
00084 int BitsPerPixel,
00085 uint32 Flags)
00086 {
00087 assert( Info != NULL );
00088
00089 if (Info->ModeCount<DISPLAYMODES_MAX)
00090 {
00091 Info->Mode[Info->ModeCount].Width = Width;
00092 Info->Mode[Info->ModeCount].Height = Height;
00093 Info->Mode[Info->ModeCount].BitsPerPixel = BitsPerPixel;
00094 Info->Mode[Info->ModeCount].Flags = Flags;
00095 Info->ModeCount++;
00096 return GE_TRUE;
00097 }
00098 else
00099 {
00100 geErrorLog_AddString(GE_ERR_INTERNAL_RESOURCE,"GE_DisplayModeInfo_AddEntry:Too many modes",NULL);
00101 return GE_FALSE;
00102 }
00103 }
00104
00105 geBoolean DisplayModeInfo_GetNth(DisplayModeInfo *Info, int Nth,
00106 int *Width,
00107 int *Height,
00108 int *BitsPerPixel,
00109 uint32 *Flags)
00110 {
00111 assert( Info != NULL );
00112 assert( Width != NULL );
00113 assert( Height != NULL );
00114 assert( BitsPerPixel != NULL );
00115 assert( Flags != NULL );
00116 if ((Nth < 0) || (Nth > Info->ModeCount))
00117 {
00118 geErrorLog_AddString(GE_ERR_BAD_PARAMETER,"DisplayModeInfo_GetNth: bad mode index",geErrorLog_IntToString(Nth));
00119 return GE_FALSE;
00120 }
00121
00122 *Width = Info->Mode[Nth].Width;
00123 *Height = Info->Mode[Nth].Height;
00124 *BitsPerPixel = Info->Mode[Nth].BitsPerPixel;
00125 *Flags = Info->Mode[Nth].Flags;
00126 return GE_TRUE;
00127 }
00128