Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

338 lines
9.1 KiB

  1. #include <windows.h>
  2. #include <drawdib.h>
  3. #include <mmsystem.h>
  4. #include "ddt.h"
  5. static char szAppName[]="Display Test";
  6. static HANDLE hInstApp;
  7. static int fhLog;
  8. static UINT (FAR *displayFPS)[3][2];
  9. void LogMsg (LPSTR sz,...);
  10. void ErrMsg (LPSTR sz,...);
  11. DWORD VideoForWindowsVersion()
  12. {
  13. HINSTANCE h;
  14. DWORD (FAR PASCAL *Version)(void);
  15. DWORD ver=0;
  16. SetErrorMode(SEM_NOOPENFILEERRORBOX);
  17. h = LoadLibrary("MSVIDEO");
  18. SetErrorMode(0);
  19. if (h <= HINSTANCE_ERROR)
  20. return ver;
  21. (FARPROC)Version = GetProcAddress(h, "VideoForWindowsVersion");
  22. if (Version != NULL)
  23. ver = Version();
  24. FreeLibrary(h);
  25. return ver;
  26. }
  27. #define BI_CRAM mmioFOURCC('C','R','A','M')
  28. #ifndef QUERYDIBSUPPORT
  29. #define QUERYDIBSUPPORT 3073
  30. #define QDI_SETDIBITS 0x0001
  31. #define QDI_GETDIBITS 0x0002
  32. #define QDI_DIBTOSCREEN 0x0004
  33. #define QDI_STRETCHDIB 0x0008
  34. #endif
  35. DWORD QueryDibSupport(LPBITMAPINFOHEADER lpbi)
  36. {
  37. HDC hdc;
  38. DWORD dw = 0;
  39. hdc = GetDC(NULL);
  40. //
  41. // send the Escape to see if they support this DIB
  42. //
  43. if (!Escape(hdc, QUERYDIBSUPPORT, (int)lpbi->biSize, (LPVOID)lpbi, (LPVOID)&dw) > 0)
  44. dw = -1;
  45. ReleaseDC(NULL, hdc);
  46. return dw;
  47. }
  48. static void TestDisplay(void)
  49. {
  50. (LPVOID)displayFPS = (LPVOID)DrawDibProfileDisplay(NULL);
  51. #define SUCK(bpp,n) \
  52. displayFPS[bpp/8][n][0]/10, displayFPS[bpp/8][n][0]%10, \
  53. displayFPS[bpp/8][n][1]/10, displayFPS[bpp/8][n][1]%10, \
  54. (LPSTR)(displayFPS[bpp/8][n][0] < displayFPS[bpp/8][n][1] ? "** POOR **" : "")
  55. #define SUCKS(bpp) \
  56. SUCK(bpp,0), \
  57. SUCK(bpp,1), \
  58. SUCK(bpp,2) \
  59. ErrMsg(
  60. " 8 Bit DIBs \tStretchDI \tSetDI+BitBlt\n"
  61. " Stretch x1 \t%03d.%01d fps\t%03d.%01d fps %s\n"
  62. " Stretch x2 \t%03d.%01d fps\t%03d.%01d fps %s\n"
  63. " Stretch xN \t%03d.%01d fps\t%03d.%01d fps %s\n\n"
  64. " 16 Bit DIBs\n"
  65. " Stetch x1 \t%03d.%01d fps\t%03d.%01d fps %s\n"
  66. " Stretch x2 \t%03d.%01d fps\t%03d.%01d fps %s\n"
  67. " Stretch xN \t%03d.%01d fps\t%03d.%01d fps %s\n\n"
  68. " 24 Bit DIBs\n"
  69. " Stetch x1 \t%03d.%01d fps\t%03d.%01d fps %s\n"
  70. " Stretch x2 \t%03d.%01d fps\t%03d.%01d fps %s\n"
  71. " Stretch xN \t%03d.%01d fps\t%03d.%01d fps %s",
  72. SUCKS(8),
  73. SUCKS(16),
  74. SUCKS(24)
  75. );
  76. }
  77. void Sleep(UINT uSleep)
  78. {
  79. MSG msg;
  80. int id;
  81. id = SetTimer(NULL, 42, uSleep, NULL);
  82. while (GetMessage(&msg, NULL, 0, 0))
  83. {
  84. if (msg.message == WM_TIMER && msg.wParam == (WORD)id)
  85. break;
  86. TranslateMessage(&msg);
  87. DispatchMessage(&msg);
  88. }
  89. KillTimer(NULL, id);
  90. }
  91. #pragma optimize("", off)
  92. void GetNetName(char *pBuffer)
  93. {
  94. _asm
  95. {
  96. mov bx, pBuffer ; ds:bx -> pBuffer
  97. xor ax,ax ; zero the buffer
  98. mov [bx],ax
  99. mov [bx+2],ax
  100. mov [bx+4],ax
  101. mov [bx+8],ax
  102. mov [bx+10],ax
  103. mov [bx+12],ax
  104. mov [bx+14],ax
  105. mov dx, bx ; ds:dx -> pBuffer
  106. mov ax, 5E00h ; get machine name
  107. int 21h
  108. cmc
  109. sbb ax,ax
  110. }
  111. }
  112. #pragma optimize("", on)
  113. void NetName(char *achNetName)
  114. {
  115. int i;
  116. GetNetName(achNetName);
  117. for (i=15; i>=0 && (achNetName[i] == ' ' || achNetName[i] == 0); i--)
  118. achNetName[i] = 0;
  119. if (achNetName[0] == 0)
  120. lstrcpy(achNetName, "(Unknown)");
  121. }
  122. void DisplayName(char *szDisplay)
  123. {
  124. char achDriver[128];
  125. char achDriverName[128];
  126. HDC hdc;
  127. GetPrivateProfileString("boot", "display.drv","",achDriver, sizeof(achDriver),"system.ini");
  128. GetPrivateProfileString("boot.description","display.drv","",achDriverName, sizeof(achDriverName),"system.ini");
  129. hdc = GetDC(NULL);
  130. wsprintf(szDisplay, "%dx%dx%d, %s, %s",
  131. GetSystemMetrics(SM_CXSCREEN),
  132. GetSystemMetrics(SM_CYSCREEN),
  133. GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL),
  134. (LPSTR)achDriver, (LPSTR)achDriverName);
  135. ReleaseDC(NULL, hdc);
  136. }
  137. BOOL WriteLog()
  138. {
  139. char ach[128];
  140. OFSTRUCT of;
  141. int i;
  142. BITMAPINFOHEADER bi;
  143. DWORD f;
  144. DWORD VfW;
  145. WORD Win;
  146. // Open log file, keep trying for a while.
  147. GetModuleFileName(hInstApp, ach, sizeof(ach));
  148. lstrcpy(ach+lstrlen(ach)-4,".log");
  149. SetErrorMode(SEM_FAILCRITICALERRORS);
  150. for (i=0; i<100; i++)
  151. {
  152. fhLog = OpenFile(ach, &of, OF_READWRITE|OF_SHARE_DENY_WRITE);
  153. if (fhLog == -1) //!!! should we do this?
  154. fhLog = OpenFile(ach, &of, OF_READWRITE|OF_CREATE|OF_SHARE_DENY_WRITE);
  155. if (fhLog != -1)
  156. break;
  157. Sleep(2000); // sleep for a while
  158. }
  159. SetErrorMode(0);
  160. if (fhLog == -1)
  161. return FALSE;
  162. _llseek(fhLog, 0, SEEK_END);
  163. LogMsg("Display Test Results 1.0 *******************************************\r\n");
  164. NetName(ach);
  165. LogMsg("User: \t%s\r\n",(LPSTR)ach);
  166. VfW = VideoForWindowsVersion();
  167. Win = (WORD)GetVersion();
  168. LogMsg("Windows:\t%d.%02d %s\r\n",LOBYTE(Win), HIBYTE(Win), (LPSTR)(GetSystemMetrics(SM_DEBUG) ? "(Debug)" : ""));
  169. LogMsg("VfW: \t%d.%02d.%02d.%02d\r\n",HIBYTE(HIWORD(VfW)),LOBYTE(HIWORD(VfW)),HIBYTE(VfW),LOBYTE(VfW));
  170. DisplayName(ach);
  171. LogMsg("Display:\t%s\r\n",(LPSTR)ach);
  172. #define SDIB(f) \
  173. (LPSTR)((f != -1) ? ((f & QDI_SETDIBITS ) ? "Yes" : "No") : "Not Supported" )
  174. bi.biSize = sizeof(BITMAPINFOHEADER);
  175. bi.biWidth = 100;
  176. bi.biHeight = 100;
  177. bi.biPlanes = 1;
  178. bi.biBitCount = 0;
  179. bi.biCompression = 0;
  180. bi.biSizeImage = 0;
  181. bi.biXPelsPerMeter = 0;
  182. bi.biYPelsPerMeter = 0;
  183. bi.biClrUsed = 0;
  184. bi.biClrImportant = 0;
  185. bi.biBitCount = 16;
  186. bi.biCompression = 0;
  187. f = QueryDibSupport(&bi);
  188. LogMsg("RGB555: \t%s\r\n",SDIB(f));
  189. bi.biBitCount = 32;
  190. bi.biCompression = 0;
  191. f = QueryDibSupport(&bi);
  192. LogMsg("RGB32: \t%s\r\n",SDIB(f));
  193. bi.biBitCount = 16;
  194. bi.biCompression = BI_CRAM;
  195. f = QueryDibSupport(&bi);
  196. LogMsg("Cram16: \t%s\r\n",SDIB(f));
  197. bi.biBitCount = 8;
  198. bi.biCompression = BI_CRAM;
  199. f = QueryDibSupport(&bi);
  200. LogMsg("Cram8: \t%s\r\n",SDIB(f));
  201. LogMsg("\r\n");
  202. LogMsg(
  203. "\t8 Bit DIBs \tStretchDI\tSetDI+BitBlt\r\n"
  204. "\tStretch x1 \t%03d.%01d \t%03d.%01d\t%s\r\n"
  205. "\tStretch x2 \t%03d.%01d \t%03d.%01d\t%s\r\n"
  206. "\tStretch xN \t%03d.%01d \t%03d.%01d\t%s\r\n\r\n"
  207. "\t16 Bit DIBs\r\n"
  208. "\tStetch x1 \t%03d.%01d \t%03d.%01d\t%s\r\n"
  209. "\tStretch x2 \t%03d.%01d \t%03d.%01d\t%s\r\n"
  210. "\tStretch xN \t%03d.%01d \t%03d.%01d\t%s\r\n\r\n"
  211. "\t24 Bit DIBs\r\n"
  212. "\tStetch x1 \t%03d.%01d \t%03d.%01d\t%s\r\n"
  213. "\tStretch x2 \t%03d.%01d \t%03d.%01d\t%s\r\n"
  214. "\tStretch xN \t%03d.%01d \t%03d.%01d\t%s\r\n\r\n",
  215. SUCKS(8),
  216. SUCKS(16),
  217. SUCKS(24)
  218. );
  219. LogMsg("\r\n");
  220. _lclose(fhLog);
  221. return TRUE;
  222. }
  223. /*----------------------------------------------------------------------------*\
  224. | WinMain( hInst, hPrev, lpszCmdLine, cmdShow ) |
  225. | |
  226. | Description: |
  227. | The main procedure for the App. After initializing, it just goes |
  228. | into a message-processing loop until it gets a WM_QUIT message |
  229. | (meaning the app was closed). |
  230. | |
  231. | Arguments: |
  232. | hInst instance handle of this instance of the app |
  233. | hPrev instance handle of previous instance, NULL if first |
  234. | szCmdLine ->null-terminated command line |
  235. | cmdShow specifies how the window is initially displayed |
  236. | |
  237. | Returns: |
  238. | The exit code as specified in the WM_QUIT message. |
  239. | |
  240. \*----------------------------------------------------------------------------*/
  241. int PASCAL WinMain(HANDLE hInst, HANDLE hPrev, LPSTR szCmdLine, WORD sw)
  242. {
  243. hInstApp = hInst;
  244. TestDisplay();
  245. if (hPrev == NULL)
  246. WriteLog();
  247. return 0;
  248. }
  249. void ErrMsg (LPSTR sz,...)
  250. {
  251. static char ach[2000];
  252. wvsprintf (ach,sz,(LPSTR)(&sz+1)); /* Format the string */
  253. MessageBox(NULL,ach,szAppName,
  254. #ifdef BIDI
  255. MB_RTL_READING |
  256. #endif
  257. MB_OK|MB_ICONEXCLAMATION|MB_TASKMODAL);
  258. }
  259. void LogMsg (LPSTR sz,...)
  260. {
  261. static char ach[2000];
  262. int len;
  263. len = wvsprintf (ach,sz,(LPSTR)(&sz+1)); /* Format the string */
  264. if (fhLog != -1)
  265. _lwrite(fhLog, ach, len);
  266. }