Leaked source code of windows server 2003
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.

655 lines
21 KiB

  1. /****************************************************************************
  2. *
  3. * File: testdd.cpp
  4. * Project: DxDiag (DirectX Diagnostic Tool)
  5. * Author: Mike Anderson (manders@microsoft.com)
  6. * Purpose: Test DirectDraw functionality on this machine
  7. *
  8. * (C) Copyright 1998 Microsoft Corp. All rights reserved.
  9. *
  10. ****************************************************************************/
  11. #include <Windows.h>
  12. #define DIRECTDRAW_VERSION 5 // run on DX5 and later versions
  13. #include <ddraw.h>
  14. #include "reginfo.h"
  15. #include "sysinfo.h"
  16. #include "dispinfo.h"
  17. #include "testdd.h"
  18. #include "resource.h"
  19. #ifndef ReleasePpo
  20. #define ReleasePpo(ppo) \
  21. if (*(ppo) != NULL) \
  22. { \
  23. (*(ppo))->Release(); \
  24. *(ppo) = NULL; \
  25. } \
  26. else (VOID)0
  27. #endif
  28. enum TESTID
  29. {
  30. TESTID_LOAD_DDRAW_DLL= 1,
  31. TESTID_GET_DIRECTDRAWCREATE,
  32. TESTID_DIRECTDRAWCREATE,
  33. TESTID_GETCAPS,
  34. TESTID_USER_VERIFY_RECTANGLES,
  35. TESTID_USER_VERIFY_WINDOW_BOUNCE,
  36. TESTID_USER_VERIFY_FULLSCREEN_BOUNCE,
  37. TESTID_SETCOOPERATIVELEVEL_NORMAL,
  38. TESTID_CREATEPRIMARYSURFACE,
  39. TESTID_GETPRIMARYSURFACEDESC,
  40. TESTID_COLORFILL_BLT_TO_PRIMARY,
  41. TESTID_CREATE_OFFSCREENPLAIN_SURFACE,
  42. TESTID_COLORFILL_BLT_TO_OFFSCREENPLAIN,
  43. TESTID_BLT_OFFSCREENPLAIN_TO_FRONT,
  44. TESTID_CREATE_TEST_WINDOW,
  45. TESTID_SETCOOPERATIVELEVEL_FULLSCREEN,
  46. TESTID_SETDISPLAYMODE,
  47. TESTID_CREATEPRIMARYSURFACE_FLIP_ONEBACK,
  48. TESTID_GETATTACHEDSURFACE,
  49. TESTID_COLORFILL_TO_BACKBUFFER,
  50. TESTID_FLIP,
  51. };
  52. typedef HRESULT (WINAPI* LPDIRECTDRAWCREATE)(GUID FAR *lpGUID,
  53. LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter);
  54. BOOL BTranslateError(HRESULT hr, TCHAR* psz, BOOL bEnglish = FALSE); // from main.cpp (yuck)
  55. static HRESULT TestPrimary(HWND hwndMain, LPDIRECTDRAW pdd, LONG* piStepThatFailed);
  56. static HRESULT TestPrimaryBlt(HWND hwndMain, LPDIRECTDRAW pdd, LONG* piStepThatFailed);
  57. static HRESULT TestFullscreen(HWND hwndMain, LPDIRECTDRAW pdd, LONG* piStepThatFailed);
  58. static HRESULT CreateTestWindow(HWND hwndMain, HWND* phwnd);
  59. /****************************************************************************
  60. *
  61. * TestDD
  62. *
  63. ****************************************************************************/
  64. VOID TestDD(HWND hwndMain, DisplayInfo* pDisplayInfo)
  65. {
  66. HRESULT hr = S_OK;
  67. TCHAR szPath[MAX_PATH];
  68. HINSTANCE hInstDDraw = NULL;
  69. LPDIRECTDRAWCREATE pDDCreate;
  70. LPDIRECTDRAW pdd = NULL;
  71. TCHAR sz[300];
  72. TCHAR szTitle[100];
  73. LoadString(NULL, IDS_STARTDDTEST, sz, 300);
  74. LoadString(NULL, IDS_APPFULLNAME, szTitle, 100);
  75. if (IDNO == MessageBox(hwndMain, sz, szTitle, MB_YESNO))
  76. return;
  77. // Remove info from any previous test:
  78. ZeroMemory(&pDisplayInfo->m_testResultDD, sizeof(TestResult));
  79. pDisplayInfo->m_testResultDD.m_bStarted = TRUE;
  80. // Load ddraw.dll
  81. GetSystemDirectory(szPath, MAX_PATH);
  82. lstrcat(szPath, TEXT("\\ddraw.dll"));
  83. hInstDDraw = LoadLibrary(szPath);
  84. if (hInstDDraw == NULL)
  85. {
  86. pDisplayInfo->m_testResultDD.m_iStepThatFailed = TESTID_LOAD_DDRAW_DLL;
  87. pDisplayInfo->m_testResultDD.m_hr = DDERR_NOTFOUND;
  88. goto LEnd;
  89. }
  90. // Get DirectDrawCreate entry point
  91. pDDCreate = (LPDIRECTDRAWCREATE)GetProcAddress(hInstDDraw, "DirectDrawCreate");
  92. if (pDDCreate == NULL)
  93. {
  94. pDisplayInfo->m_testResultDD.m_iStepThatFailed = TESTID_GET_DIRECTDRAWCREATE;
  95. pDisplayInfo->m_testResultDD.m_hr = DDERR_NOTFOUND;
  96. goto LEnd;
  97. }
  98. // Call DirectDrawCreate
  99. if (FAILED(hr = pDDCreate(&pDisplayInfo->m_guid, &pdd, NULL)))
  100. {
  101. pDisplayInfo->m_testResultDD.m_iStepThatFailed = TESTID_DIRECTDRAWCREATE;
  102. pDisplayInfo->m_testResultDD.m_hr = hr;
  103. goto LEnd;
  104. }
  105. // Get DirectDraw caps
  106. DDCAPS ddcaps;
  107. DDCAPS ddcaps2;
  108. ddcaps.dwSize = sizeof(ddcaps);
  109. ddcaps2.dwSize = sizeof(ddcaps2);
  110. if (FAILED(hr = pdd->GetCaps(&ddcaps, &ddcaps2)))
  111. {
  112. pDisplayInfo->m_testResultDD.m_iStepThatFailed = TESTID_GETCAPS;
  113. pDisplayInfo->m_testResultDD.m_hr = hr;
  114. goto LEnd;
  115. }
  116. ReleasePpo(&pdd);
  117. if (!pDisplayInfo->m_bCanRenderWindow)
  118. {
  119. LoadString(NULL, IDS_SKIPWINDOWED, sz, 300);
  120. MessageBox(hwndMain, sz, szTitle, MB_OK);
  121. }
  122. else
  123. {
  124. // First test
  125. LoadString(NULL, IDS_DDTEST1, sz, 300);
  126. if (IDCANCEL == MessageBox(hwndMain, sz, szTitle, MB_OKCANCEL))
  127. {
  128. pDisplayInfo->m_testResultDD.m_bCancelled = TRUE;
  129. goto LEnd;
  130. }
  131. if (FAILED(hr = pDDCreate(&pDisplayInfo->m_guid, &pdd, NULL)))
  132. {
  133. pDisplayInfo->m_testResultDD.m_iStepThatFailed = TESTID_DIRECTDRAWCREATE;
  134. pDisplayInfo->m_testResultDD.m_hr = hr;
  135. goto LEnd;
  136. }
  137. if (FAILED(hr = TestPrimary(hwndMain, pdd, &pDisplayInfo->m_testResultDD.m_iStepThatFailed)))
  138. {
  139. pDisplayInfo->m_testResultDD.m_hr = hr;
  140. goto LEnd;
  141. }
  142. ReleasePpo(&pdd);
  143. LoadString(NULL, IDS_CONFIRMDDTEST1, sz, 300);
  144. if (IDNO == MessageBox(hwndMain, sz, szTitle, MB_YESNO))
  145. {
  146. pDisplayInfo->m_testResultDD.m_iStepThatFailed = TESTID_USER_VERIFY_RECTANGLES;
  147. pDisplayInfo->m_testResultDD.m_hr = S_OK;
  148. goto LEnd;
  149. }
  150. // Second test
  151. LoadString(NULL, IDS_DDTEST2, sz, 300);
  152. if (IDCANCEL == MessageBox(hwndMain, sz, szTitle, MB_OKCANCEL))
  153. {
  154. pDisplayInfo->m_testResultDD.m_bCancelled = TRUE;
  155. goto LEnd;
  156. }
  157. if (FAILED(hr = pDDCreate(&pDisplayInfo->m_guid, &pdd, NULL)))
  158. {
  159. pDisplayInfo->m_testResultDD.m_iStepThatFailed = TESTID_DIRECTDRAWCREATE;
  160. pDisplayInfo->m_testResultDD.m_hr = hr;
  161. goto LEnd;
  162. }
  163. if (FAILED(hr = TestPrimaryBlt(hwndMain, pdd, &pDisplayInfo->m_testResultDD.m_iStepThatFailed)))
  164. {
  165. pDisplayInfo->m_testResultDD.m_hr = hr;
  166. goto LEnd;
  167. }
  168. ReleasePpo(&pdd);
  169. LoadString(NULL, IDS_CONFIRMDDTEST2, sz, 300);
  170. if (IDNO == MessageBox(hwndMain, sz, szTitle, MB_YESNO))
  171. {
  172. pDisplayInfo->m_testResultDD.m_iStepThatFailed = TESTID_USER_VERIFY_WINDOW_BOUNCE;
  173. pDisplayInfo->m_testResultDD.m_hr = S_OK;
  174. }
  175. }
  176. // Third test
  177. LoadString(NULL, IDS_DDTEST3, sz, 300);
  178. if (IDCANCEL == MessageBox(hwndMain, sz, szTitle, MB_OKCANCEL))
  179. {
  180. pDisplayInfo->m_testResultDD.m_bCancelled = TRUE;
  181. goto LEnd;
  182. }
  183. if (FAILED(hr = pDDCreate(&pDisplayInfo->m_guid, &pdd, NULL)))
  184. {
  185. pDisplayInfo->m_testResultDD.m_iStepThatFailed = TESTID_DIRECTDRAWCREATE;
  186. pDisplayInfo->m_testResultDD.m_hr = hr;
  187. goto LEnd;
  188. }
  189. POINT ptMouse;
  190. GetCursorPos(&ptMouse);
  191. if (FAILED(hr = TestFullscreen(hwndMain, pdd, &pDisplayInfo->m_testResultDD.m_iStepThatFailed)))
  192. {
  193. pDisplayInfo->m_testResultDD.m_hr = hr;
  194. goto LEnd;
  195. }
  196. SetCursorPos( ptMouse.x, ptMouse.y );
  197. ReleasePpo(&pdd);
  198. LoadString(NULL, IDS_CONFIRMDDTEST3, sz, 300);
  199. if (IDNO == MessageBox(hwndMain, sz, szTitle, MB_YESNO))
  200. {
  201. pDisplayInfo->m_testResultDD.m_iStepThatFailed = TESTID_USER_VERIFY_FULLSCREEN_BOUNCE;
  202. pDisplayInfo->m_testResultDD.m_hr = S_OK;
  203. goto LEnd;
  204. }
  205. LoadString(NULL, IDS_ENDDDTESTS, sz, 300);
  206. MessageBox(hwndMain, sz, szTitle, MB_OK);
  207. LEnd:
  208. ReleasePpo(&pdd);
  209. if (hInstDDraw != NULL)
  210. FreeLibrary(hInstDDraw);
  211. if (pDisplayInfo->m_testResultDD.m_bCancelled)
  212. {
  213. LoadString(NULL, IDS_TESTSCANCELLED, sz, 300);
  214. lstrcpy(pDisplayInfo->m_testResultDD.m_szDescription, sz);
  215. LoadString(NULL, IDS_TESTSCANCELLED_ENGLISH, sz, 300);
  216. lstrcpy(pDisplayInfo->m_testResultDD.m_szDescription, sz);
  217. }
  218. else
  219. {
  220. if (pDisplayInfo->m_testResultDD.m_iStepThatFailed == 0)
  221. {
  222. LoadString(NULL, IDS_TESTSSUCCESSFUL, sz, 300);
  223. lstrcpy(pDisplayInfo->m_testResultDD.m_szDescription, sz);
  224. LoadString(NULL, IDS_TESTSSUCCESSFUL_ENGLISH, sz, 300);
  225. lstrcpy(pDisplayInfo->m_testResultDD.m_szDescriptionEnglish, sz);
  226. }
  227. else
  228. {
  229. TCHAR szDesc[300];
  230. TCHAR szError[300];
  231. if (0 == LoadString(NULL, IDS_FIRSTDDTESTERROR + pDisplayInfo->m_testResultDD.m_iStepThatFailed - 1,
  232. szDesc, 300))
  233. {
  234. LoadString(NULL, IDS_UNKNOWNERROR, sz, 300);
  235. lstrcpy(szDesc, sz);
  236. }
  237. LoadString(NULL, IDS_FAILUREFMT, sz, 300);
  238. BTranslateError(pDisplayInfo->m_testResultDD.m_hr, szError);
  239. wsprintf(pDisplayInfo->m_testResultDD.m_szDescription, sz,
  240. pDisplayInfo->m_testResultDD.m_iStepThatFailed,
  241. szDesc, pDisplayInfo->m_testResultDD.m_hr, szError);
  242. // Nonlocalized version:
  243. if (0 == LoadString(NULL, IDS_FIRSTDDTESTERROR_ENGLISH + pDisplayInfo->m_testResultDD.m_iStepThatFailed - 1,
  244. szDesc, 300))
  245. {
  246. LoadString(NULL, IDS_UNKNOWNERROR_ENGLISH, sz, 300);
  247. lstrcpy(szDesc, sz);
  248. }
  249. LoadString(NULL, IDS_FAILUREFMT_ENGLISH, sz, 300);
  250. BTranslateError(pDisplayInfo->m_testResultDD.m_hr, szError, TRUE);
  251. wsprintf(pDisplayInfo->m_testResultDD.m_szDescriptionEnglish, sz,
  252. pDisplayInfo->m_testResultDD.m_iStepThatFailed,
  253. szDesc, pDisplayInfo->m_testResultDD.m_hr, szError);
  254. }
  255. }
  256. }
  257. /****************************************************************************
  258. *
  259. * TestPrimary
  260. *
  261. ****************************************************************************/
  262. HRESULT TestPrimary(HWND hwndMain, LPDIRECTDRAW pdd, LONG* piStepThatFailed)
  263. {
  264. HRESULT hr = S_OK;
  265. DDSURFACEDESC ddsd;
  266. LPDIRECTDRAWSURFACE pdds = NULL;
  267. RECT rc;
  268. if (FAILED(hr = pdd->SetCooperativeLevel(NULL, DDSCL_NORMAL)))
  269. {
  270. *piStepThatFailed = TESTID_SETCOOPERATIVELEVEL_NORMAL;
  271. goto LEnd;
  272. }
  273. ZeroMemory(&ddsd, sizeof(ddsd));
  274. ddsd.dwSize = sizeof(ddsd);
  275. ddsd.dwFlags = DDSD_CAPS;
  276. ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
  277. if (FAILED(hr = pdd->CreateSurface(&ddsd, &pdds, NULL)))
  278. {
  279. *piStepThatFailed = TESTID_CREATEPRIMARYSURFACE;
  280. goto LEnd;
  281. }
  282. ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
  283. if (FAILED(hr = pdds->GetSurfaceDesc(&ddsd)))
  284. {
  285. *piStepThatFailed = TESTID_GETPRIMARYSURFACEDESC;
  286. goto LEnd;
  287. }
  288. SetRect(&rc, 0, 0, ddsd.dwWidth, ddsd.dwHeight);
  289. InflateRect(&rc, -64, -64);
  290. DDBLTFX ddbltfx;
  291. ZeroMemory(&ddbltfx, sizeof(ddbltfx));
  292. ddbltfx.dwSize = sizeof(ddbltfx);
  293. while (rc.right > rc.left + 2 && rc.bottom > rc.top + 2)
  294. {
  295. ddbltfx.dwFillColor = ~ddbltfx.dwFillColor;
  296. if (FAILED(hr = pdds->Blt(&rc, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx)))
  297. {
  298. *piStepThatFailed = TESTID_COLORFILL_BLT_TO_PRIMARY;
  299. goto LEnd;
  300. }
  301. InflateRect(&rc, -4, -4);
  302. }
  303. // Give the user a moment to verify the test pattern
  304. Sleep(2000);
  305. // Clean up affected screen area in case this display isn't part of the desktop:
  306. ddbltfx.dwFillColor = 0;
  307. if (FAILED(hr = pdds->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx)))
  308. {
  309. *piStepThatFailed = TESTID_COLORFILL_BLT_TO_PRIMARY;
  310. goto LEnd;
  311. }
  312. LEnd:
  313. ReleasePpo(&pdds);
  314. InvalidateRect(NULL, NULL, FALSE); // repaint desktop
  315. return hr;
  316. }
  317. /****************************************************************************
  318. *
  319. * TestPrimaryBlt
  320. *
  321. ****************************************************************************/
  322. HRESULT TestPrimaryBlt(HWND hwndMain, LPDIRECTDRAW pdd, LONG* piStepThatFailed)
  323. {
  324. HRESULT hr = S_OK;
  325. DDSURFACEDESC ddsd;
  326. LPDIRECTDRAWSURFACE pddsFront = NULL;
  327. LPDIRECTDRAWSURFACE pddsBack = NULL;
  328. RECT rc;
  329. RECT rcDest;
  330. RECT rcScreen;
  331. DDBLTFX ddbltfx;
  332. INT i;
  333. LONG xv = 1;
  334. LONG yv = 2;
  335. if (FAILED(hr = pdd->SetCooperativeLevel(NULL, DDSCL_NORMAL)))
  336. {
  337. *piStepThatFailed = TESTID_SETCOOPERATIVELEVEL_NORMAL;
  338. goto LEnd;
  339. }
  340. ZeroMemory(&ddsd, sizeof(ddsd));
  341. ddsd.dwSize = sizeof(ddsd);
  342. ddsd.dwFlags = DDSD_CAPS;
  343. ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
  344. if (FAILED(hr = pdd->CreateSurface(&ddsd, &pddsFront, NULL)))
  345. {
  346. *piStepThatFailed = TESTID_CREATEPRIMARYSURFACE;
  347. goto LEnd;
  348. }
  349. ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
  350. if (FAILED(hr = pddsFront->GetSurfaceDesc(&ddsd)))
  351. {
  352. *piStepThatFailed = TESTID_GETPRIMARYSURFACEDESC;
  353. goto LEnd;
  354. }
  355. SetRect(&rcScreen, 0, 0, ddsd.dwWidth, ddsd.dwHeight);
  356. ZeroMemory(&ddsd, sizeof(ddsd));
  357. ddsd.dwSize = sizeof(ddsd);
  358. ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
  359. ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
  360. ddsd.dwWidth = 200;
  361. ddsd.dwHeight = 200;
  362. if (FAILED(hr = pdd->CreateSurface(&ddsd, &pddsBack, NULL)))
  363. {
  364. *piStepThatFailed = TESTID_CREATE_OFFSCREENPLAIN_SURFACE;
  365. goto LEnd;
  366. }
  367. SetRect(&rc, 0, 0, 32, 32);
  368. OffsetRect(&rc, 10, 35);
  369. ZeroMemory(&ddbltfx, sizeof(ddbltfx));
  370. ddbltfx.dwSize = sizeof(ddbltfx);
  371. for (i = 0; i < 200; i++)
  372. {
  373. ddbltfx.dwFillColor = 0;
  374. if (FAILED(hr = pddsBack->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx)))
  375. {
  376. *piStepThatFailed = TESTID_COLORFILL_BLT_TO_OFFSCREENPLAIN;
  377. goto LEnd;
  378. }
  379. OffsetRect(&rc, xv, yv);
  380. if (rc.left < 2 && xv < 0 || rc.right > 198 && xv > 0)
  381. xv = -xv;
  382. if (rc.top < 2 && yv < 0 || rc.bottom > 198 && yv > 0)
  383. yv = -yv;
  384. ddbltfx.dwFillColor = 0xffffffff;
  385. if (FAILED(hr = pddsBack->Blt(&rc, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx)))
  386. {
  387. *piStepThatFailed = TESTID_COLORFILL_BLT_TO_OFFSCREENPLAIN;
  388. goto LEnd;
  389. }
  390. SetRect(&rcDest, 0, 0, 200, 200);
  391. OffsetRect(&rcDest, (rcScreen.right - 200) / 2, (rcScreen.bottom - 200) / 2);
  392. if (FAILED(hr = pddsFront->Blt(&rcDest, pddsBack, NULL, DDBLT_WAIT, NULL)))
  393. {
  394. *piStepThatFailed = TESTID_BLT_OFFSCREENPLAIN_TO_FRONT;
  395. goto LEnd;
  396. }
  397. Sleep(2);
  398. }
  399. // Clean up affected screen area in case this display isn't part of the desktop:
  400. ddbltfx.dwFillColor = 0;
  401. if (FAILED(hr = pddsFront->Blt(&rc, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx)))
  402. {
  403. *piStepThatFailed = TESTID_COLORFILL_BLT_TO_PRIMARY;
  404. goto LEnd;
  405. }
  406. LEnd:
  407. InvalidateRect(NULL, NULL, FALSE); // repaint desktop
  408. ReleasePpo(&pddsBack);
  409. ReleasePpo(&pddsFront);
  410. return hr;
  411. }
  412. /****************************************************************************
  413. *
  414. * TestFullscreen
  415. *
  416. ****************************************************************************/
  417. HRESULT TestFullscreen(HWND hwndMain, LPDIRECTDRAW pdd, LONG* piStepThatFailed)
  418. {
  419. HRESULT hr;
  420. HWND hwnd = NULL;
  421. DDSURFACEDESC ddsd;
  422. LPDIRECTDRAWSURFACE pddsFront = NULL;
  423. LPDIRECTDRAWSURFACE pddsBack = NULL;
  424. RECT rc;
  425. RECT rcScreen;
  426. DDBLTFX ddbltfx;
  427. BOOL bDisplayModeSet = FALSE;
  428. INT i;
  429. LONG xv = 1;
  430. LONG yv = 2;
  431. ShowCursor(FALSE);
  432. if (FAILED(hr = CreateTestWindow(hwndMain, &hwnd)))
  433. {
  434. *piStepThatFailed = TESTID_CREATE_TEST_WINDOW;
  435. goto LEnd;
  436. }
  437. if (FAILED(hr = pdd->SetCooperativeLevel(hwnd,
  438. DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN)))
  439. {
  440. *piStepThatFailed = TESTID_SETCOOPERATIVELEVEL_FULLSCREEN;
  441. goto LEnd;
  442. }
  443. if (FAILED(hr = pdd->SetDisplayMode(640, 480, 16)))
  444. {
  445. TCHAR szMessage[300];
  446. TCHAR szTitle[100];
  447. pdd->SetCooperativeLevel(hwnd, DDSCL_NORMAL);
  448. SendMessage(hwnd, WM_CLOSE, 0, 0);
  449. LoadString(NULL, IDS_SETDISPLAYMODEFAILED, szMessage, 300);
  450. LoadString(NULL, IDS_APPFULLNAME, szTitle, 100);
  451. MessageBox(hwndMain, szMessage, szTitle, MB_OK);
  452. *piStepThatFailed = TESTID_SETDISPLAYMODE;
  453. goto LEnd;
  454. }
  455. bDisplayModeSet = TRUE;
  456. ZeroMemory(&ddsd, sizeof(ddsd));
  457. ddsd.dwSize = sizeof(ddsd);
  458. ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
  459. ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
  460. ddsd.dwBackBufferCount = 1;
  461. if (FAILED(hr = pdd->CreateSurface(&ddsd, &pddsFront, NULL)))
  462. {
  463. *piStepThatFailed = TESTID_CREATEPRIMARYSURFACE_FLIP_ONEBACK;
  464. goto LEnd;
  465. }
  466. ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
  467. if (FAILED(hr = pddsFront->GetSurfaceDesc(&ddsd)))
  468. {
  469. *piStepThatFailed = TESTID_GETPRIMARYSURFACEDESC;
  470. goto LEnd;
  471. }
  472. SetRect(&rcScreen, 0, 0, ddsd.dwWidth, ddsd.dwHeight);
  473. ZeroMemory(&ddbltfx, sizeof(ddbltfx));
  474. ddbltfx.dwSize = sizeof(ddbltfx);
  475. DDSCAPS ddscaps;
  476. ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
  477. if (FAILED(hr = pddsFront->GetAttachedSurface(&ddscaps, &pddsBack)))
  478. {
  479. *piStepThatFailed = TESTID_GETATTACHEDSURFACE;
  480. goto LEnd;
  481. }
  482. SetRect(&rc, 0, 0, 32, 32);
  483. OffsetRect(&rc, 10, 35);
  484. ZeroMemory(&ddbltfx, sizeof(ddbltfx));
  485. ddbltfx.dwSize = sizeof(ddbltfx);
  486. for (i = 0; i < 200; i++)
  487. {
  488. ddbltfx.dwFillColor = 0;
  489. if (FAILED(hr = pddsBack->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx)))
  490. {
  491. *piStepThatFailed = TESTID_COLORFILL_TO_BACKBUFFER;
  492. goto LEnd;
  493. }
  494. OffsetRect(&rc, xv, yv);
  495. if (rc.left < 2 && xv < 0 || rc.right > 198 && xv > 0)
  496. xv = -xv;
  497. if (rc.top < 2 && yv < 0 || rc.bottom > 198 && yv > 0)
  498. yv = -yv;
  499. OffsetRect(&rc, (rcScreen.right - 200) / 2, (rcScreen.bottom - 200) / 2);
  500. ddbltfx.dwFillColor = 0xffffffff;
  501. if (FAILED(hr = pddsBack->Blt(&rc, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx)))
  502. {
  503. *piStepThatFailed = TESTID_COLORFILL_TO_BACKBUFFER;
  504. goto LEnd;
  505. }
  506. OffsetRect(&rc, -(rcScreen.right - 200) / 2, -(rcScreen.bottom - 200) / 2);
  507. if (FAILED(hr = pddsFront->Flip(NULL, DDFLIP_WAIT)))
  508. {
  509. *piStepThatFailed = TESTID_FLIP;
  510. goto LEnd;
  511. }
  512. Sleep(2);
  513. }
  514. ddbltfx.dwFillColor = 0;
  515. if (FAILED(hr = pddsFront->Blt(&rc, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx)))
  516. {
  517. *piStepThatFailed = TESTID_COLORFILL_BLT_TO_PRIMARY;
  518. goto LEnd;
  519. }
  520. LEnd:
  521. ShowCursor(TRUE);
  522. ReleasePpo(&pddsBack);
  523. ReleasePpo(&pddsFront);
  524. if (FAILED(hr))
  525. {
  526. // Something has already failed, so report that failure
  527. // rather than any failure of SetCooperativeLevel
  528. pdd->SetCooperativeLevel(hwnd, DDSCL_NORMAL);
  529. }
  530. else
  531. {
  532. if (FAILED(hr = pdd->SetCooperativeLevel(hwnd, DDSCL_NORMAL)))
  533. {
  534. *piStepThatFailed = TESTID_SETCOOPERATIVELEVEL_NORMAL;
  535. }
  536. }
  537. if (hwnd != NULL)
  538. SendMessage(hwnd, WM_CLOSE, 0, 0);
  539. if (bDisplayModeSet)
  540. {
  541. if (FAILED(hr))
  542. {
  543. // Something has already failed, so report that failure
  544. // rather than any failure of RestoreDisplayMode
  545. pdd->RestoreDisplayMode();
  546. }
  547. else
  548. {
  549. // Nothing has failed yet, so report any failure of RestoreDisplayMode
  550. if (FAILED(hr = pdd->RestoreDisplayMode()))
  551. return hr;
  552. }
  553. }
  554. return hr;
  555. }
  556. /****************************************************************************
  557. *
  558. * CreateTestWindow
  559. *
  560. ****************************************************************************/
  561. HRESULT CreateTestWindow(HWND hwndMain, HWND* phwnd)
  562. {
  563. static BOOL bClassRegistered = FALSE;
  564. WNDCLASS wndClass;
  565. TCHAR* pszClass = TEXT("DxDiag Test Window"); // Don't need to localize
  566. HINSTANCE hInst = (HINSTANCE)GetWindowLongPtr(hwndMain, GWLP_HINSTANCE);
  567. TCHAR szTitle[200];
  568. if (!bClassRegistered)
  569. {
  570. ZeroMemory(&wndClass, sizeof(wndClass));
  571. wndClass.style = CS_HREDRAW | CS_VREDRAW;
  572. wndClass.lpfnWndProc = DefWindowProc;
  573. wndClass.cbClsExtra = 0;
  574. wndClass.cbWndExtra = 0;
  575. wndClass.hInstance = hInst;
  576. wndClass.hIcon = NULL;
  577. wndClass.hCursor = NULL;
  578. wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  579. wndClass.lpszMenuName = NULL;
  580. wndClass.lpszClassName = pszClass;
  581. if (NULL == RegisterClass(&wndClass))
  582. return E_FAIL;
  583. bClassRegistered = TRUE;
  584. }
  585. LoadString(NULL, IDS_APPFULLNAME, szTitle, 200);
  586. *phwnd = CreateWindow(pszClass, szTitle, WS_OVERLAPPED,
  587. 0, 0, 0, 0, hwndMain, NULL, hInst, NULL);
  588. if (*phwnd == NULL)
  589. return E_FAIL;
  590. ShowWindow(*phwnd, SW_SHOW);
  591. return S_OK;
  592. }