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.

275 lines
7.5 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1999-2000 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * perftest.h
  8. *
  9. * Abstract:
  10. *
  11. * This is the common include module for the GDI+ performance tests.
  12. *
  13. \**************************************************************************/
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <stdarg.h>
  17. #include <windows.h>
  18. #include <math.h> // sin & cos
  19. #include <tchar.h>
  20. #include <commctrl.h>
  21. #include <objbase.h>
  22. #if 0
  23. // So that we can continue testing the old drawing functionality for
  24. // a while, don't use the new API headers yet:
  25. #define RenderingHintAntiAlias RenderingModeAntiAlias
  26. #define TextRenderingHintAntiAlias TextAntiAlias
  27. #define TextRenderingHintClearType TextClearType
  28. #define PixelFormatMax PIXFMT_MAX
  29. #define PixelFormat32bppARGB PIXFMT_32BPP_ARGB
  30. #define PixelFormat32bppPARGB PIXFMT_32BPP_PARGB
  31. #define PixelFormat32bppRGB PIXFMT_32BPP_RGB
  32. #define PixelFormat16bppRGB555 PIXFMT_16BPP_RGB555
  33. #define PixelFormat16bppRGB565 PIXFMT_16BPP_RGB565
  34. #define PixelFormat24bppRGB PIXFMT_24BPP_RGB
  35. #define LinearGradientBrush LineGradientBrush
  36. #define InterpolationModeBicubic InterpolateBicubic
  37. #define InterpolationModeBilinear InterpolateBilinear
  38. #define UNITPIXEL PageUnitPixel
  39. #else
  40. #define USE_NEW_APIS 1
  41. #define USE_NEW_APIS2 1
  42. #define UNITPIXEL UnitPixel
  43. #endif
  44. #include <gdiplus.h>
  45. using namespace Gdiplus;
  46. #include "resource.h"
  47. #include "debug.h"
  48. // Handy window handle:
  49. extern HWND ghwndMain;
  50. // Dimensions of any bitmap destinations:
  51. #define TestWidth 800
  52. #define TestHeight 600
  53. //--------------------------------------------------------------------------
  54. // Types
  55. //
  56. // Enums for test permutations
  57. //--------------------------------------------------------------------------
  58. enum DestinationType
  59. {
  60. Destination_Screen_Current,
  61. Destination_Screen_800_600_8bpp_DefaultPalette,
  62. Destination_Screen_800_600_8bpp_HalftonePalette,
  63. Destination_Screen_800_600_16bpp,
  64. Destination_Screen_800_600_24bpp,
  65. Destination_Screen_800_600_32bpp,
  66. Destination_CompatibleBitmap_8bpp,
  67. Destination_DIB_15bpp,
  68. Destination_DIB_16bpp,
  69. Destination_DIB_24bpp,
  70. Destination_DIB_32bpp,
  71. Destination_Bitmap_32bpp_ARGB,
  72. Destination_Bitmap_32bpp_PARGB,
  73. Destination_Count // Must be last entry, used for count
  74. };
  75. enum ApiType
  76. {
  77. Api_GdiPlus,
  78. Api_Gdi,
  79. Api_Count // Must be last entry, used for count
  80. };
  81. enum StateType
  82. {
  83. State_Default,
  84. State_Antialias,
  85. State_Count // Must be last entry, used for count
  86. };
  87. typedef float (*TESTFUNCTION)(Graphics *, HDC);
  88. struct Test
  89. {
  90. INT UniqueIdentifier;
  91. INT Priority;
  92. TESTFUNCTION Function;
  93. LPCTSTR Description;
  94. LPCTSTR Comment;
  95. };
  96. struct Config
  97. {
  98. LPCTSTR Description;
  99. BOOL Enabled;
  100. };
  101. struct TestConfig
  102. {
  103. BOOL Enabled;
  104. Test* TestEntry; // Points to static entry describing test
  105. };
  106. extern TestConfig *TestList; // Sorted test list
  107. extern Config ApiList[];
  108. extern Config DestinationList[];
  109. extern Config StateList[];
  110. //--------------------------------------------------------------------------
  111. // Test groupings
  112. //
  113. //--------------------------------------------------------------------------
  114. #define T(uniqueIdentifier, priority, function, comment) \
  115. { uniqueIdentifier, priority, function, _T(#function), _T(comment) }
  116. struct TestGroup
  117. {
  118. Test* Tests;
  119. INT Count;
  120. };
  121. extern Test DrawTests[];
  122. extern Test FillTests[];
  123. extern Test ImageTests[];
  124. extern Test TextTests[];
  125. extern Test OtherTests[];
  126. extern INT DrawTests_Count;
  127. extern INT FillTests_Count;
  128. extern INT ImageTests_Count;
  129. extern INT TextTests_Count;
  130. extern INT OtherTests_Count;
  131. extern INT Test_Count; // Total number of tests
  132. //--------------------------------------------------------------------------
  133. // TestResult -
  134. //
  135. // Structure for maintaining test result information. The data is kept
  136. // as a multi-dimensional array, and the following routines are used
  137. // for access.
  138. //--------------------------------------------------------------------------
  139. struct TestResult
  140. {
  141. float Score;
  142. };
  143. inline INT ResultIndex(INT destinationIndex, INT apiIndex, INT stateIndex, INT testIndex)
  144. {
  145. return(((testIndex * State_Count + stateIndex) * Api_Count + apiIndex) *
  146. Destination_Count + destinationIndex);
  147. }
  148. inline INT ResultCount()
  149. {
  150. return(Destination_Count * Api_Count * State_Count * Test_Count);
  151. }
  152. extern TestResult *ResultsList; // Allocation to track test results
  153. //--------------------------------------------------------------------------
  154. // TestSuite -
  155. //
  156. // Class that abstracts all the state setup for running all the tests.
  157. //--------------------------------------------------------------------------
  158. class TestSuite
  159. {
  160. private:
  161. // Save Destination state:
  162. BOOL ModeSet; // Was a mode set?
  163. HPALETTE HalftonePalette, OldPalette;
  164. // Saved State state:
  165. GraphicsState SavedState;
  166. public:
  167. BOOL InitializeDestination(DestinationType, Bitmap**, HBITMAP*);
  168. VOID UninitializeDestination(DestinationType, Bitmap *, HBITMAP);
  169. BOOL InitializeApi(ApiType, Bitmap *, HBITMAP, HWND, Graphics **, HDC *);
  170. VOID UninitializeApi(ApiType, Bitmap *, HBITMAP, HWND, Graphics *, HDC);
  171. BOOL InitializeState(ApiType, StateType, Graphics*, HDC);
  172. VOID UninitializeState(ApiType, StateType, Graphics*, HDC);
  173. TestSuite();
  174. ~TestSuite();
  175. VOID Run(HWND hwnd);
  176. };
  177. ///////////////////////////////////////////////////////////////////////////
  178. // Test settings:
  179. extern BOOL AutoRun;
  180. extern BOOL ExcelOut;
  181. extern BOOL Icecap;
  182. extern BOOL FoundIcecap;
  183. extern BOOL TestRender;
  184. extern INT CurrentTestIndex;
  185. extern CHAR CurrentTestDescription[];
  186. extern LPTSTR processor;
  187. extern TCHAR osVer[MAX_PATH];
  188. extern TCHAR deviceName[MAX_PATH];
  189. extern TCHAR machineName[MAX_PATH];
  190. ///////////////////////////////////////////////////////////////////////////
  191. // IceCAP API functions
  192. #define PROFILE_GLOBALLEVEL 1
  193. #define PROFILE_CURRENTID ((unsigned long)0xFFFFFFFF)
  194. typedef int (_stdcall *ICCOMMENTMARKPROFILEFUNC)(long lMarker, const char *szComment);
  195. typedef int (_stdcall *ICCONTROLPROFILEFUNC)(int nLevel, unsigned long dwId);
  196. extern ICCONTROLPROFILEFUNC ICStartProfile, ICStopProfile;
  197. extern ICCOMMENTMARKPROFILEFUNC ICCommentMarkProfile;
  198. ///////////////////////////////////////////////////////////////////////////
  199. // Worker routines
  200. VOID MessageF(LPTSTR fmt, ...);
  201. HBITMAP CreateCompatibleDIB2(HDC hdc, int width, int height);
  202. VOID CreatePerformanceReport(TestResult *results, BOOL useExcel);
  203. VOID GetOutputFileName(TCHAR*);
  204. ///////////////////////////////////////////////////////////////////////////
  205. // Timer utility functions
  206. #define MIN_ITERATIONS 16 // Must be power of two
  207. #define MIN_DURATION 200 // Minimum time duration, in milliseconds
  208. #define MEGA 1000000 // Handy constant for computing megapixels
  209. #define KILO 1000 // Handy constant for computing kilopixels
  210. void StartTimer();
  211. BOOL EndTimer();
  212. void GetTimer(float* seconds, UINT* iterations);