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.

711 lines
17 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1999-2000 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * perfdraw.cpp
  8. *
  9. * Abstract:
  10. *
  11. * Contains all the tests for any routines that 'Draw'.
  12. *
  13. \**************************************************************************/
  14. #include "perftest.h"
  15. // Global array for holding line vertices:
  16. Point SweepLines[2000];
  17. int Initialize_256_Pixel_Sweep_Lines()
  18. {
  19. int c = 0;
  20. int i;
  21. for (i = 0; i < 510; i += 4)
  22. {
  23. SweepLines[c].X = 255;
  24. SweepLines[c].Y = 255;
  25. c++;
  26. SweepLines[c].X = i;
  27. SweepLines[c].Y = 0;
  28. c++;
  29. }
  30. for (i = 0; i < 510; i += 4)
  31. {
  32. SweepLines[c].X = 255;
  33. SweepLines[c].Y = 255;
  34. c++;
  35. SweepLines[c].X = 510;
  36. SweepLines[c].Y = i;
  37. c++;
  38. }
  39. for (i = 0; i < 510; i += 4)
  40. {
  41. SweepLines[c].X = 255;
  42. SweepLines[c].Y = 255;
  43. c++;
  44. SweepLines[c].X = 510 - i;
  45. SweepLines[c].Y = 510;
  46. c++;
  47. }
  48. for (i = 0; i < 510; i += 4)
  49. {
  50. SweepLines[c].X = 255;
  51. SweepLines[c].Y = 255;
  52. c++;
  53. SweepLines[c].X = 0;
  54. SweepLines[c].Y = 510 - i;
  55. c++;
  56. }
  57. return(c / 2);
  58. }
  59. float Draw_Lines_PerPixel_Nominal_Solid_Opaque_Aliased(Graphics *g, HDC hdc)
  60. {
  61. UINT iterations;
  62. float seconds;
  63. int i;
  64. int lines = Initialize_256_Pixel_Sweep_Lines();
  65. if (g)
  66. {
  67. Pen pen(Color::Red, 1);
  68. StartTimer();
  69. do {
  70. for (i = 0; i < lines; i++)
  71. {
  72. g->DrawLine(&pen, SweepLines[i*2].X, SweepLines[i*2].Y,
  73. SweepLines[i*2+1].X, SweepLines[i*2+1].Y);
  74. }
  75. } while (!EndTimer());
  76. g->Flush(FlushIntentionSync);
  77. GetTimer(&seconds, &iterations);
  78. }
  79. else
  80. {
  81. POINT points[2000];
  82. for (i = 0; i < lines * 2 + 1; i++)
  83. {
  84. points[i].x = SweepLines[i].X;
  85. points[i].y = SweepLines[i].Y;
  86. }
  87. HPEN hpen = CreatePen(PS_SOLID, 1, RGB(0xff, 0, 0));
  88. HGDIOBJ oldPen = SelectObject(hdc, hpen);
  89. StartTimer();
  90. do {
  91. for (i = 0; i < lines; i++)
  92. {
  93. Polyline(hdc, &points[i*2], 2);
  94. }
  95. } while (!EndTimer());
  96. GdiFlush();
  97. GetTimer(&seconds, &iterations);
  98. SelectObject(hdc, oldPen);
  99. }
  100. UINT pixels = 256 * lines * iterations;
  101. return(pixels / seconds / KILO); // Kilo-pixels per second
  102. }
  103. float Draw_Lines_PerPixel_Nominal_Solid_Opaque_Antialiased(Graphics *g, HDC hdc)
  104. {
  105. UINT iterations;
  106. float seconds;
  107. int i;
  108. if (!g) return(0); // There is no GDI equivalent
  109. int lines = Initialize_256_Pixel_Sweep_Lines();
  110. g->SetSmoothingMode(SmoothingModeAntiAlias);
  111. Pen pen(Color::Red, 1);
  112. StartTimer();
  113. do {
  114. for (i = 0; i < lines; i++)
  115. {
  116. g->DrawLine(&pen, SweepLines[i*2].X, SweepLines[i*2].Y,
  117. SweepLines[i*2+1].X, SweepLines[i*2+1].Y);
  118. }
  119. } while (!EndTimer());
  120. g->Flush(FlushIntentionSync);
  121. GetTimer(&seconds, &iterations);
  122. UINT pixels = 256 * lines * iterations;
  123. return(pixels / seconds / KILO); // Kilo-pixels per second
  124. }
  125. float Draw_Lines_PerPixel_Nominal_Solid_Opaque_Antialiased_Quality(Graphics *g, HDC hdc)
  126. {
  127. UINT iterations;
  128. float seconds;
  129. int i;
  130. if (!g) return(0); // There is no GDI equivalent
  131. int lines = Initialize_256_Pixel_Sweep_Lines();
  132. g->SetSmoothingMode(SmoothingModeAntiAlias);
  133. g->SetCompositingQuality(CompositingQualityHighQuality);
  134. Pen pen(Color::Red, 1);
  135. StartTimer();
  136. do {
  137. for (i = 0; i < lines; i++)
  138. {
  139. g->DrawLine(&pen, SweepLines[i*2].X, SweepLines[i*2].Y,
  140. SweepLines[i*2+1].X, SweepLines[i*2+1].Y);
  141. }
  142. } while (!EndTimer());
  143. g->Flush(FlushIntentionSync);
  144. GetTimer(&seconds, &iterations);
  145. UINT pixels = 256 * lines * iterations;
  146. return(pixels / seconds / KILO); // Kilo-pixels per second
  147. }
  148. float Draw_Lines_PerPixel_Wide_Solid_Opaque_Aliased(Graphics *g, HDC hdc)
  149. {
  150. UINT iterations;
  151. float seconds;
  152. int i;
  153. int lines = Initialize_256_Pixel_Sweep_Lines();
  154. if (g)
  155. {
  156. Pen pen(Color::Red, 2);
  157. StartTimer();
  158. do {
  159. for (i = 0; i < lines; i++)
  160. {
  161. g->DrawLine(&pen, SweepLines[i*2].X, SweepLines[i*2].Y,
  162. SweepLines[i*2+1].X, SweepLines[i*2+1].Y);
  163. }
  164. } while (!EndTimer());
  165. g->Flush(FlushIntentionSync);
  166. GetTimer(&seconds, &iterations);
  167. }
  168. else
  169. {
  170. POINT points[2000];
  171. for (i = 0; i < lines * 2 + 1; i++)
  172. {
  173. points[i].x = SweepLines[i].X;
  174. points[i].y = SweepLines[i].Y;
  175. }
  176. HPEN hpen = CreatePen(PS_SOLID, 2, RGB(0xff, 0, 0));
  177. HGDIOBJ oldPen = SelectObject(hdc, hpen);
  178. StartTimer();
  179. do {
  180. for (i = 0; i < lines; i++)
  181. {
  182. Polyline(hdc, &points[i*2], 2);
  183. }
  184. } while (!EndTimer());
  185. GdiFlush();
  186. GetTimer(&seconds, &iterations);
  187. SelectObject(hdc, oldPen);
  188. }
  189. UINT pixels = 256 * lines * iterations;
  190. return(pixels / seconds / KILO); // Kilo-pixels per second
  191. }
  192. float Draw_Lines_PerPixel_Wide_Solid_Opaque_Antialiased(Graphics *g, HDC hdc)
  193. {
  194. UINT iterations;
  195. float seconds;
  196. int i;
  197. if (!g) return(0); // There is no GDI equivalent
  198. g->SetSmoothingMode(SmoothingModeAntiAlias);
  199. int lines = Initialize_256_Pixel_Sweep_Lines();
  200. Pen pen(Color::Red, 2);
  201. StartTimer();
  202. do {
  203. for (i = 0; i < lines; i++)
  204. {
  205. g->DrawLine(&pen, SweepLines[i*2].X, SweepLines[i*2].Y,
  206. SweepLines[i*2+1].X, SweepLines[i*2+1].Y);
  207. }
  208. } while (!EndTimer());
  209. g->Flush(FlushIntentionSync);
  210. GetTimer(&seconds, &iterations);
  211. UINT pixels = 256 * lines * iterations;
  212. return(pixels / seconds / KILO); // Kilo-pixels per second
  213. }
  214. float Draw_Lines_PerPixel_Wide_Solid_Opaque_Antialiased_Quality(Graphics *g, HDC hdc)
  215. {
  216. UINT iterations;
  217. float seconds;
  218. int i;
  219. if (!g) return(0); // There is no GDI equivalent
  220. g->SetSmoothingMode(SmoothingModeAntiAlias);
  221. g->SetCompositingQuality(CompositingQualityHighQuality);
  222. int lines = Initialize_256_Pixel_Sweep_Lines();
  223. Pen pen(Color::Red, 2);
  224. StartTimer();
  225. do {
  226. for (i = 0; i < lines; i++)
  227. {
  228. g->DrawLine(&pen, SweepLines[i*2].X, SweepLines[i*2].Y,
  229. SweepLines[i*2+1].X, SweepLines[i*2+1].Y);
  230. }
  231. } while (!EndTimer());
  232. g->Flush(FlushIntentionSync);
  233. GetTimer(&seconds, &iterations);
  234. UINT pixels = 256 * lines * iterations;
  235. return(pixels / seconds / KILO); // Kilo-pixels per second
  236. }
  237. float Draw_Lines_PerLine_Nominal_Solid_Opaque_Aliased(Graphics *g, HDC hdc)
  238. {
  239. UINT iterations;
  240. float seconds;
  241. if (g)
  242. {
  243. StartTimer();
  244. do {
  245. Pen pen(Color::Red, 1);
  246. g->DrawLine(&pen, 255, 255, 256, 256); // 2 pixels long
  247. } while (!EndTimer());
  248. g->Flush(FlushIntentionSync);
  249. GetTimer(&seconds, &iterations);
  250. }
  251. else
  252. {
  253. StartTimer();
  254. do {
  255. POINT points[] = { 255, 255, 256, 256 };
  256. HPEN hpen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
  257. HGDIOBJ oldPen = SelectObject(hdc, hpen);
  258. Polyline(hdc, points, 2);
  259. SelectObject(hdc, oldPen);
  260. DeleteObject(hpen);
  261. } while (!EndTimer());
  262. GdiFlush();
  263. GetTimer(&seconds, &iterations);
  264. }
  265. return(iterations / seconds / KILO); // Kilo-lines per second
  266. }
  267. float Draw_Lines_PerLine_Nominal_Solid_Opaque_Antialiased(Graphics *g, HDC hdc)
  268. {
  269. UINT iterations;
  270. float seconds;
  271. if (!g) return(0); // There is no GDI equivalent
  272. g->SetSmoothingMode(SmoothingModeAntiAlias);
  273. StartTimer();
  274. do {
  275. Pen pen(Color::Red, 1);
  276. g->DrawLine(&pen, 255, 255, 256, 256); // 2 pixels long
  277. } while (!EndTimer());
  278. g->Flush(FlushIntentionSync);
  279. GetTimer(&seconds, &iterations);
  280. return(iterations / seconds / KILO); // Kilo-lines per second
  281. }
  282. float Draw_Lines_PerLine_Wide_Solid_Opaque_Aliased(Graphics *g, HDC hdc)
  283. {
  284. UINT iterations;
  285. float seconds;
  286. if (g)
  287. {
  288. StartTimer();
  289. do {
  290. Pen pen(Color::Red, 2);
  291. g->DrawLine(&pen, 255, 255, 256, 256); // 2 pixels long
  292. } while (!EndTimer());
  293. g->Flush(FlushIntentionSync);
  294. GetTimer(&seconds, &iterations);
  295. }
  296. else
  297. {
  298. StartTimer();
  299. do {
  300. POINT points[] = { 255, 255, 256, 256 };
  301. HPEN hpen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
  302. HGDIOBJ oldPen = SelectObject(hdc, hpen);
  303. Polyline(hdc, points, 2);
  304. SelectObject(hdc, oldPen);
  305. DeleteObject(hpen);
  306. } while (!EndTimer());
  307. GdiFlush();
  308. GetTimer(&seconds, &iterations);
  309. }
  310. return(iterations / seconds / KILO); // Kilo-lines per second
  311. }
  312. float Draw_Lines_PerLine_Wide_Solid_Opaque_Antialiased(Graphics *g, HDC hdc)
  313. {
  314. UINT iterations;
  315. float seconds;
  316. if (!g) return(0); // There is no GDI equivalent
  317. g->SetSmoothingMode(SmoothingModeAntiAlias);
  318. StartTimer();
  319. do {
  320. Pen pen(Color::Red, 2);
  321. g->DrawLine(&pen, 255, 255, 256, 256); // 2 pixels long
  322. } while (!EndTimer());
  323. g->Flush(FlushIntentionSync);
  324. GetTimer(&seconds, &iterations);
  325. return(iterations / seconds / KILO); // Kilo-lines per second
  326. }
  327. float Draw_Ellipse_PerCall_Big_Nominal_Aliased(Graphics *g, HDC hdc)
  328. {
  329. UINT iterations;
  330. float seconds;
  331. if (g)
  332. {
  333. StartTimer();
  334. do {
  335. Pen pen(Color::Red, 0.1f);
  336. g->DrawEllipse(&pen, 0, 0, 512, 512);
  337. } while (!EndTimer());
  338. g->Flush(FlushIntentionSync);
  339. GetTimer(&seconds, &iterations);
  340. }
  341. else
  342. {
  343. HGDIOBJ hbrush = GetStockObject(NULL_BRUSH);
  344. HGDIOBJ oldBrush = SelectObject(hdc, hbrush);
  345. StartTimer();
  346. do {
  347. HPEN hpen = CreatePen(PS_SOLID, 0, RGB(255, 0, 0));
  348. HGDIOBJ oldPen = SelectObject(hdc, hpen);
  349. Ellipse(hdc, 0, 0, 512, 512);
  350. SelectObject(hdc, oldPen);
  351. DeleteObject(hpen);
  352. } while (!EndTimer());
  353. GdiFlush();
  354. GetTimer(&seconds, &iterations);
  355. SelectObject(hdc, oldBrush);
  356. DeleteObject(hbrush);
  357. }
  358. return(iterations / seconds / KILO); // Kilo-calls per second
  359. }
  360. float Draw_Ellipse_PerCall_Big_WideLine_Aliased(Graphics *g, HDC hdc)
  361. {
  362. UINT iterations;
  363. float seconds;
  364. if (g)
  365. {
  366. StartTimer();
  367. do {
  368. Pen pen(Color::Red, 5);
  369. g->DrawEllipse(&pen, 0, 0, 512, 512);
  370. } while (!EndTimer());
  371. g->Flush(FlushIntentionSync);
  372. GetTimer(&seconds, &iterations);
  373. }
  374. else
  375. {
  376. HGDIOBJ hbrush = GetStockObject(NULL_BRUSH);
  377. HGDIOBJ oldBrush = SelectObject(hdc, hbrush);
  378. StartTimer();
  379. do {
  380. HPEN hpen = CreatePen(PS_SOLID, 5, RGB(255, 0, 0));
  381. HGDIOBJ oldPen = SelectObject(hdc, hpen);
  382. Ellipse(hdc, 0, 0, 512, 512);
  383. SelectObject(hdc, oldPen);
  384. DeleteObject(hpen);
  385. } while (!EndTimer());
  386. GdiFlush();
  387. GetTimer(&seconds, &iterations);
  388. SelectObject(hdc, oldBrush);
  389. DeleteObject(hbrush);
  390. }
  391. return(iterations / seconds / KILO); // Kilo-calls per second
  392. }
  393. float Draw_Ellipse_PerCall_Small_Nominal_Aliased(Graphics *g, HDC hdc)
  394. {
  395. UINT iterations;
  396. float seconds;
  397. if (g)
  398. {
  399. HGDIOBJ hbrush = GetStockObject(NULL_BRUSH);
  400. HGDIOBJ oldBrush = SelectObject(hdc, hbrush);
  401. StartTimer();
  402. do {
  403. Pen pen(Color::Red, 0.1f);
  404. g->DrawEllipse(&pen, 64, 64, 64, 64);
  405. } while (!EndTimer());
  406. g->Flush(FlushIntentionSync);
  407. GetTimer(&seconds, &iterations);
  408. }
  409. else
  410. {
  411. HGDIOBJ hbrush = GetStockObject(NULL_BRUSH);
  412. HGDIOBJ oldBrush = SelectObject(hdc, hbrush);
  413. StartTimer();
  414. do {
  415. HPEN hpen = CreatePen(PS_SOLID, 0, RGB(255, 0, 0));
  416. HGDIOBJ oldPen = SelectObject(hdc, hpen);
  417. Ellipse(hdc, 64, 64, 128, 128);
  418. SelectObject(hdc, oldPen);
  419. DeleteObject(hpen);
  420. } while (!EndTimer());
  421. GdiFlush();
  422. GetTimer(&seconds, &iterations);
  423. SelectObject(hdc, oldBrush);
  424. DeleteObject(hbrush);
  425. }
  426. return(iterations / seconds / KILO); // Kilo-calls per second
  427. }
  428. float Draw_Ellipse_PerCall_Small_WideLine_Aliased(Graphics *g, HDC hdc)
  429. {
  430. UINT iterations;
  431. float seconds;
  432. if (g)
  433. {
  434. StartTimer();
  435. do {
  436. Pen pen(Color::Red, 5);
  437. g->DrawEllipse(&pen, 64, 64, 64, 64);
  438. } while (!EndTimer());
  439. g->Flush(FlushIntentionSync);
  440. GetTimer(&seconds, &iterations);
  441. }
  442. else
  443. {
  444. HGDIOBJ hbrush = GetStockObject(NULL_BRUSH);
  445. HGDIOBJ oldBrush = SelectObject(hdc, hbrush);
  446. StartTimer();
  447. do {
  448. HPEN hpen = CreatePen(PS_SOLID, 5, RGB(255, 0, 0));
  449. HGDIOBJ oldPen = SelectObject(hdc, hpen);
  450. Ellipse(hdc, 64, 64, 128, 128);
  451. SelectObject(hdc, oldPen);
  452. DeleteObject(hpen);
  453. } while (!EndTimer());
  454. GdiFlush();
  455. GetTimer(&seconds, &iterations);
  456. SelectObject(hdc, oldBrush);
  457. DeleteObject(hbrush);
  458. }
  459. return(iterations / seconds / KILO); // Kilo-calls per second
  460. }
  461. float Draw_Pie_PerCall_Nominal(Graphics *g, HDC hdc)
  462. {
  463. UINT iterations;
  464. float seconds;
  465. if (!g) return(0); // There is no GDI equivalent
  466. StartTimer();
  467. do {
  468. Pen pen(Color::Red, 0.1f);
  469. g->DrawPie(&pen, 0, 0, 512, 512, 90, 120);
  470. } while (!EndTimer());
  471. g->Flush(FlushIntentionSync);
  472. GetTimer(&seconds, &iterations);
  473. return(iterations / seconds / KILO); // Kilo-calls per second
  474. }
  475. ////////////////////////////////////////////////////////////////////////////////
  476. // Add tests for this file here. Always use the 'T' macro for adding entries.
  477. // The parameter meanings are as follows:
  478. //
  479. // Parameter
  480. // ---------
  481. // 1 UniqueIdentifier - Must be a unique number assigned to no other test
  482. // 2 Priority - On a scale of 1 to 5, how important is the test?
  483. // 3 Function - Function name
  484. // 4 Comment - Anything to describe the test
  485. Test DrawTests[] =
  486. {
  487. T(1000, 1, Draw_Lines_PerPixel_Nominal_Solid_Opaque_Aliased , "Kpixels/s"),
  488. T(1001, 1, Draw_Lines_PerPixel_Nominal_Solid_Opaque_Antialiased , "Kpixels/s"),
  489. T(1002, 1, Draw_Lines_PerPixel_Wide_Solid_Opaque_Aliased , "Kpixels/s"),
  490. T(1003, 1, Draw_Lines_PerPixel_Wide_Solid_Opaque_Antialiased , "Kpixels/s"),
  491. T(1004, 1, Draw_Lines_PerLine_Nominal_Solid_Opaque_Aliased , "Klines/s"),
  492. T(1005, 1, Draw_Lines_PerLine_Nominal_Solid_Opaque_Antialiased , "Klines/s"),
  493. T(1006, 1, Draw_Lines_PerLine_Wide_Solid_Opaque_Aliased , "Klines/s"),
  494. T(1007, 1, Draw_Lines_PerLine_Wide_Solid_Opaque_Antialiased , "Klines/s"),
  495. T(1008, 1, Draw_Ellipse_PerCall_Big_Nominal_Aliased , "Kcalls/s"),
  496. T(1009, 1, Draw_Ellipse_PerCall_Big_WideLine_Aliased , "Kcalls/s"),
  497. T(1010, 1, Draw_Pie_PerCall_Nominal , "Kcalls/s"),
  498. T(1011, 1, Draw_Ellipse_PerCall_Small_Nominal_Aliased , "Kcalls/s"),
  499. T(1012, 1, Draw_Ellipse_PerCall_Small_WideLine_Aliased , "Kcalls/s"),
  500. T(1013, 1, Draw_Lines_PerPixel_Nominal_Solid_Opaque_Antialiased_Quality , "Kpixels/s"),
  501. T(1014, 1, Draw_Lines_PerPixel_Wide_Solid_Opaque_Antialiased_Quality , "Kpixels/s"),
  502. };
  503. INT DrawTests_Count = sizeof(DrawTests) / sizeof(DrawTests[0]);