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.

611 lines
30 KiB

  1. /**************************************************************************\
  2. *
  3. * DEBUGGING macros
  4. *
  5. \**************************************************************************/
  6. #ifndef _GDIDEBUG_H_
  7. #define _GDIDEBUG_H_
  8. #define DBG_BASIC (DBG || 0)
  9. #define DBG_TRACE (DBG || 0)
  10. #define DBG_CORE (DBG_BASIC || DBG_TRACE || DBG)
  11. // GDIFunctionName
  12. // Used to identify the current function.
  13. // Use GDIFunctionID inside each function with the name of the function
  14. // or some unique identifier.
  15. // Scope wil be used to resolve the right GDIFunctionName to use.
  16. typedef const char *GDIFunctionNameType;
  17. typedef const char GDIFunctionIDType[];
  18. static const GDIFunctionNameType GDIFunctionName = NULL; // This is the default value.
  19. extern GDIFunctionIDType UnknownGDIFunc;
  20. #define GDIFunctionID(id) static const GDIFunctionIDType GDIFunctionName = #id
  21. #if DBG_CORE
  22. extern HSEMAPHORE ghsemDEBUG; // for serializing debug output
  23. #endif
  24. #if DBG_BASIC
  25. //
  26. // Variable defined in USER\server\server.c
  27. // set to 1 on DBG build trace through display driver loading
  28. //
  29. extern ULONG GreTraceDisplayDriverLoad;
  30. extern ULONG GreTraceFontLoad;
  31. VOID WINAPI DoRip(PSZ);
  32. VOID WINAPI DoWarning(PSZ,LONG);
  33. VOID WINAPI DoIDRip(PCSTR,PSZ);
  34. VOID WINAPI DoIDWarning(PCSTR,PSZ,LONG);
  35. #define RIP(x) do { if (GDIFunctionName) DoIDRip(GDIFunctionName, (PSZ) x); else DoRip((PSZ) x); } while (0)
  36. #define ASSERTGDI(x,y) if(!(x)) RIP(y)
  37. #define FREASSERTGDI(x, y) ASSERTGDI((x),(y))
  38. #define WARNING(x) do { if (GDIFunctionName) DoIDWarning(GDIFunctionName,x,0); else DoWarning(x,0); } while (0)
  39. #define WARNING1(x) do { if (GDIFunctionName) DoIDWarning(GDIFunctionName,x,1); else DoWarning(x,1); } while (0)
  40. #define TRACE_INIT(str) { if (GreTraceDisplayDriverLoad) { KdPrint(str); } }
  41. #define TRACE_CACHE(str) { if (gflFontDebug & DEBUG_CACHE){ KdPrint(str); } }
  42. #define TRACE_INSERT(str) { if (gflFontDebug & DEBUG_INSERT){ KdPrint(str); } }
  43. #define TRACE_FONT(str) { \
  44. if (GreTraceFontLoad) { \
  45. TEB *pteb = NtCurrentTeb(); \
  46. CLIENT_ID *pId = &pteb->ClientId; \
  47. GreAcquireSemaphore(ghsemDEBUG); \
  48. KdPrint(("TRACE_FONT: p=%u t=%u\n", \
  49. pId->UniqueProcess, \
  50. pId->UniqueThread)); \
  51. KdPrint((" ")); \
  52. KdPrint(str); \
  53. KdPrint(("\n")); \
  54. GreReleaseSemaphore(ghsemDEBUG); \
  55. } \
  56. }
  57. VOID vPrintENUMLOGFONTEXDVW(ENUMLOGFONTEXDVW *pelfw);
  58. VOID vPrintIFIMETRICS(IFIMETRICS *pifi);
  59. #define DBGEXCEPT 1
  60. extern int bStopExcept;
  61. extern int bWarnExcept;
  62. #define WARNINGX(n) \
  63. if (bWarnExcept) \
  64. { \
  65. DbgPrint("GDI exception hit WARNINGX(%d)\n",n); \
  66. if (bStopExcept) \
  67. DbgBreakPoint(); \
  68. }
  69. #else
  70. #define RIP(x)
  71. #define ASSERTGDI(x,y)
  72. #define WARNING(x)
  73. #define WARNING1(x)
  74. #define TRACE_INIT(str)
  75. #define TRACE_CACHE(str)
  76. #define TRACE_INSERT(str)
  77. #define TRACE_FONT(str)
  78. #define WARNINGX(n)
  79. #ifdef PRERELEASE
  80. #define FREASSERTGDI(x, y) if(!(x) && KD_DEBUGGER_ENABLED) { DbgPrint((y)); DbgBreakPoint(); }
  81. #else
  82. #define FREASSERTGDI(x, y)
  83. #endif
  84. #endif
  85. #if DBG_TRACE
  86. #define GDITRACE_KEYS_PER_CLASS 32
  87. // GDI Trace Classes
  88. typedef enum {
  89. GDITC_TEMP,
  90. GDITC_ATTRIBUTE,
  91. GDITC_BLT,
  92. GDITC_BRUSH,
  93. GDITC_CLIP,
  94. GDITC_COLOR,
  95. GDITC_CURVE,
  96. GDITC_DC,
  97. GDITC_DRV,
  98. GDITC_ENG,
  99. GDITC_FILL,
  100. GDITC_FONT,
  101. GDITC_LINE,
  102. GDITC_META,
  103. GDITC_PALETTE,
  104. GDITC_PATH,
  105. GDITC_PEN,
  106. GDITC_REGION,
  107. GDITC_SHAPE,
  108. GDITC_SPRITE,
  109. GDITC_SYSTEM,
  110. GDITC_TEXT,
  111. GDITC_VIEW,
  112. GDITC_TOTAL
  113. } GDITraceClass;
  114. // Special classes
  115. #define GDITC_0 0
  116. #define GDITC_NOCLASS 0
  117. // GDI Trace Entry Flags
  118. #define GDITRACE_FLAG_ALWAYS 0x01
  119. #define GDITRACE_FLAG_ANYTRACE 0x02
  120. #define GDITRACE_FLAG_IGNORE_CLASS 0x04
  121. #define GDITRACE_FLAG_INTERNAL_MASK 0x08
  122. #define GDITRACE_FLAG_INTERNAL (GDITRACE_FLAG_INTERNAL_MASK | GDITRACE_FLAG_IGNORE_CLASS)
  123. #define GDITF_0 0
  124. #define GDITF_NOFLAG 0
  125. #define GDITF_ALWAYS (GDITRACE_FLAG_ALWAYS << GDITRACE_FLAG_SHIFT)
  126. #define GDITF_ANYTRACE (GDITRACE_FLAG_ANYTRACE << GDITRACE_FLAG_SHIFT)
  127. #define GDITF_IGNORE_CLASS (GDITRACE_FLAG_IGNORE_CLASS << GDITRACE_FLAG_SHIFT)
  128. #define GDITF_INTERNAL_MASK (GDITRACE_FLAG_INTERNAL_MASK << GDITRACE_FLAG_SHIFT)
  129. #define GDITF_INTERNAL (GDITRACE_FLAG_INTERNAL << GDITRACE_FLAG_SHIFT)
  130. typedef DWORD GDITraceEntry;
  131. typedef WORD GDITraceKeyMask;
  132. typedef DWORD GDITraceClassMask;
  133. #define GDITRACE_KEY_MASK_BITS_TEST 16 // 8*sizeof(GDITraceKeyMask)
  134. #define GDITRACE_CLASS_MASK_BITS_TEST 32 // 8*sizeof(GDITraceClassMask)
  135. #define GDITRACE_ENTRY_BITS (8*sizeof(GDITraceEntry))
  136. #define GDITRACE_KEY_MASK_BITS (8*sizeof(GDITraceKeyMask))
  137. #define GDITRACE_FLAGS 4
  138. #define GDITRACE_KEY_INDEX_BITS (GDITRACE_ENTRY_BITS-GDITRACE_KEY_MASK_BITS-GDITRACE_FLAGS)
  139. // 1 bit to cover 2 masks per class (2 subclasses)
  140. #define GDITRACE_SUBCLASS_BITS 1
  141. #define GDITRACE_CLASS_BITS (GDITRACE_KEY_INDEX_BITS-GDITRACE_SUBCLASS_BITS)
  142. // 5 bits cover 32 bit positions in a GDITraceClassMask
  143. #define GDITRACE_CLASS_MASK_BITPOS_BITS 5
  144. #define GDITRACE_CLASS_INDEX_BITS (GDITRACE_CLASS_BITS-GDITRACE_CLASS_MASK_BITPOS_BITS)
  145. #if (1 << GDITRACE_SUBCLASS_BITS) != ((GDITRACE_KEYS_PER_CLASS+GDITRACE_KEY_MASK_BITS_TEST-1)/GDITRACE_KEY_MASK_BITS_TEST)
  146. #error Adjust GDITRACE_SUBCLASS_BITS to cover Key Masks per Class (SubClasses).
  147. #endif
  148. #define GDITRACE_CLASS_MASK_BITS (1 << GDITRACE_CLASS_MASK_BITPOS_BITS)
  149. #if GDITRACE_CLASS_MASK_BITS != GDITRACE_CLASS_MASK_BITS_TEST
  150. #error Adjust GDITRACE_CLASS_MASK_BITPOS_BITS to cover bit positions in GDITraceClassMask
  151. #endif
  152. typedef struct {
  153. GDITraceEntry KeyMask:GDITRACE_KEY_MASK_BITS;
  154. GDITraceEntry SubClass:GDITRACE_SUBCLASS_BITS;
  155. GDITraceEntry ClassBitPos:GDITRACE_CLASS_MASK_BITPOS_BITS;
  156. GDITraceEntry ClassIndex:GDITRACE_CLASS_INDEX_BITS;
  157. GDITraceEntry Always:1;
  158. GDITraceEntry Anytrace:1;
  159. GDITraceEntry IgnoreClass:1;
  160. GDITraceEntry Internal:1;
  161. } GDITraceEntryType;
  162. #define GDITRACE_KEY_SHIFT 0
  163. #define GDITRACE_KEY_MASK ((1 << GDITRACE_KEY_MASK_BITS) - 1)
  164. #define GDITRACE_KEY_INDEX_SHIFT (GDITRACE_KEY_SHIFT+GDITRACE_KEY_MASK_BITS)
  165. #define GDITRACE_KEY_INDEX_MASK ((1 << GDITRACE_KEY_INDEX_BITS) - 1)
  166. #define GDITRACE_SUBCLASS_SHIFT GDITRACE_KEY_INDEX_SHIFT
  167. #define GDITRACE_SUBCLASS_MASK ((1 << GDITRACE_SUBCLASS_BITS) - 1)
  168. #define GDITRACE_CLASS_SHIFT (GDITRACE_SUBCLASS_SHIFT+GDITRACE_SUBCLASS_BITS)
  169. #define GDITRACE_CLASS_MASK ((1 << GDITRACE_CLASS_BITS) - 1)
  170. #define GDITRACE_CLASS_MASK_BITPOS_SHIFT GDITRACE_CLASS_SHIFT
  171. #define GDITRACE_CLASS_MASK_BITPOS_MASK ((1 << GDITRACE_CLASS_MASK_BITPOS_BITS) - 1)
  172. #define GDITRACE_CLASS_INDEX_SHIFT (GDITRACE_CLASS_MASK_BITPOS_SHIFT+GDITRACE_CLASS_MASK_BITPOS_BITS)
  173. #define GDITRACE_CLASS_INDEX_MASK ((1 << GDITRACE_CLASS_INDEX_BITS) - 1)
  174. #define GDITRACE_FLAG_SHIFT (GDITRACE_KEY_INDEX_SHIFT+GDITRACE_KEY_INDEX_BITS)
  175. #define GDITRACE_FLAG_MASK ((1 << GDITRACE_FLAGS) - 1)
  176. #define GDITRACE_KEY_MASKS_PER_CLASS ((GDITRACE_KEYS_PER_CLASS+GDITRACE_KEY_MASK_BITS-1)/GDITRACE_KEY_MASK_BITS)
  177. #define GDITRACE_TOTAL_KEY_MASKS (GDITC_TOTAL*GDITRACE_KEY_MASKS_PER_CLASS)
  178. #define GDITRACE_TOTAL_CLASS_MASKS ((GDITC_TOTAL+GDITRACE_CLASS_MASK_BITS-1)/GDITRACE_CLASS_MASK_BITS)
  179. extern GDITraceClassMask gGDITraceClassMask[GDITRACE_TOTAL_CLASS_MASKS];
  180. extern GDITraceKeyMask gGDITraceKeyMask[GDITRACE_TOTAL_KEY_MASKS];
  181. extern GDITraceKeyMask gGDITraceInternalMask[GDITRACE_TOTAL_KEY_MASKS];
  182. extern HANDLE gGDITraceHandle1;
  183. extern HANDLE gGDITraceHandle2;
  184. extern BOOL gGDITraceHandleBreak;
  185. #define GDITRACE_COMPOSE_WORD_MASK ((1 << (8*sizeof(WORD))) - 1)
  186. #define GDITRACE_COMPOSE_SHIFT_PER_WORD_INDEX \
  187. (8*sizeof(WORD)*sizeof(WORD)/sizeof(GDITraceKeyMask))
  188. #define GDITRACE_COMPOSE_WORD_INDICIES_PER_MASK \
  189. ((unsigned)(sizeof(GDITraceKeyMask)/sizeof(WORD)))
  190. // ComposeGDITE(WORD Mask, int MaskWordIndex, TOKEN Class, TOKEN Flag)
  191. #define ComposeGDITE(Mask, MaskWordIndex, Class, Flags) \
  192. ( \
  193. (((((Mask) & GDITRACE_COMPOSE_WORD_MASK) << \
  194. (GDITRACE_COMPOSE_SHIFT_PER_WORD_INDEX* \
  195. (MaskWordIndex % GDITRACE_COMPOSE_WORD_INDICIES_PER_MASK))) & \
  196. GDITRACE_KEY_MASK) << GDITRACE_KEY_SHIFT) | \
  197. (((MaskWordIndex / GDITRACE_COMPOSE_WORD_INDICIES_PER_MASK) & \
  198. GDITRACE_SUBCLASS_MASK) << GDITRACE_SUBCLASS_SHIFT) | \
  199. (((GDITC_##Class) & GDITRACE_CLASS_MASK) << GDITRACE_CLASS_SHIFT)| \
  200. ((GDITF_##Flags) & (GDITRACE_FLAG_MASK << GDITRACE_FLAG_SHIFT)) \
  201. )
  202. #define GDITE(Key) GDITE_##Key
  203. // DEFTK( TOKEN Key, WORD Mask, int MaskWordIndex, TOKEN Class, TOKEN Flag)
  204. #define DEFTK(Key, Mask, MaskWordIndex, Class, Flags) \
  205. typedef enum { \
  206. GDITE(Key) = ComposeGDITE(Mask, MaskWordIndex, Class, Flags), \
  207. } enum_GDITE_##Key;
  208. #define GDITM(Key) (((GDITE(Key)) >> GDITRACE_KEY_SHIFT) & GDITRACE_KEY_MASK)
  209. #define GDITMIndex(Key) (((GDITE(Key)) >> GDITRACE_KEY_INDEX_SHIFT) & GDITRACE_KEY_INDEX_MASK)
  210. #define GDITCBit(Key) (((GDITE(Key)) >> GDITRACE_CLASS_MASK_BITPOS_SHIFT) & GDITRACE_CLASS_MASK_BITPOS_MASK)
  211. #define GDITCIndex(Key) (((GDITE(Key)) >> GDITRACE_CLASS_INDEX_SHIFT) & GDITRACE_CLASS_INDEX_MASK)
  212. #define GDITFAlways(Key) ((GDITE(Key)) & GDITF_ALWAYS)
  213. #define GDITFAnytrace(Key) ((GDITE(Key)) & GDITF_ANYTRACE)
  214. #define GDITFIgnoreC(Key) ((GDITE(Key)) & GDITF_IGNORE_CLASS)
  215. #define GDITFInternal(Key) ((GDITE(Key)) & GDITF_INTERNAL_MASK)
  216. DEFTK(ALWAYS, 0, 0, 0, ALWAYS)
  217. DEFTK(ANYTRACE, 0, 0, 0, ANYTRACE)
  218. DEFTK(NEVER, 0, 0, 0, IGNORE_CLASS)
  219. DEFTK(HANDLETRACE, 0, 0, 0, IGNORE_CLASS)
  220. DEFTK(TEMP, 0, 0, TEMP, 0)
  221. DEFTK(ATTRIBUTE, 0, 0, ATTRIBUTE, 0)
  222. DEFTK( GreGetBkColor, 0x0001, 0, ATTRIBUTE, 0)
  223. DEFTK( GreSetBkColor, 0x0002, 0, ATTRIBUTE, 0)
  224. DEFTK(BLT, 0, 0, BLT, 0)
  225. DEFTK( NtGdiAlphaBlend, 0x0001, 0, BLT, 0)
  226. DEFTK( NtGdiBitBlt, 0x0002, 0, BLT, 0)
  227. DEFTK( GreGradientFill, 0x0004, 0, BLT, 0)
  228. DEFTK( GreMaskBlt, 0x0008, 0, BLT, 0)
  229. DEFTK( NtGdiMaskBlt, 0x0008, 0, BLT, 0)
  230. DEFTK( NtGdiPatBlt, 0x0010, 0, BLT, 0)
  231. DEFTK( GrePlgBlt, 0x0020, 0, BLT, 0)
  232. DEFTK( NtGdiPlgBlt, 0x0020, 0, BLT, 0)
  233. DEFTK( GrePolyPatBlt, 0x0040, 0, BLT, 0)
  234. DEFTK( NtGdiPolyPatBlt, 0x0040, 0, BLT, 0)
  235. DEFTK( GrePolyPatBltInternal, 0x0040, 0, BLT, INTERNAL)
  236. DEFTK( GreStretchBlt, 0x0080, 0, BLT, 0)
  237. DEFTK( NtGdiStretchBlt, 0x0080, 0, BLT, 0)
  238. DEFTK( NtGdiTransparentBlt, 0x0100, 0, BLT, 0)
  239. DEFTK(BRUSH, 0, 0, BRUSH, 0)
  240. DEFTK(CLIP, 0, 0, CLIP, 0)
  241. DEFTK( GreExcludeClipRect, 0x0001, 0, CLIP, 0)
  242. DEFTK( NtGdiExcludeClipRect, 0x0001, 0, CLIP, 0)
  243. DEFTK( GreGetAppClipBox, 0x0002, 0, CLIP, 0)
  244. DEFTK( NtGdiGetAppClipBox, 0x0002, 0, CLIP, 0)
  245. DEFTK( GreGetClipBox, 0x0004, 0, CLIP, 0)
  246. DEFTK( GreIntersectClipRect, 0x0008, 0, CLIP, 0)
  247. DEFTK( NtGdiIntersectClipRect, 0x0008, 0, CLIP, 0)
  248. DEFTK( NtGdiOffsetClipRgn, 0x0010, 0, CLIP, 0)
  249. DEFTK( NtGdiSelectClipPath, 0x0020, 0, CLIP, 0)
  250. DEFTK( GreExtSelectClipRgn, 0x0040, 0, CLIP, 0)
  251. DEFTK(NtGdiExtSelectClipRgn, 0x0040, 0, CLIP, 0)
  252. DEFTK(CURVE, 0, 0, CURVE, 0)
  253. DEFTK(DC, 0, 0, DC, 0)
  254. DEFTK(DRV, 0, 0, DRV, 0)
  255. DEFTK(ENG, 0, 0, ENG, 0)
  256. DEFTK(FILL, 0, 0, FILL, 0)
  257. DEFTK( NtGdiFillRgn, 0x000, 0, FILL, 0)
  258. DEFTK( NtGdiFrameRgn, 0x000, 0, FILL, 0)
  259. DEFTK( NtGdiInvertRgn, 0x000, 0, FILL, 0)
  260. DEFTK(FONT, 0, 0, FONT, 0)
  261. DEFTK(LINE, 0, 0, LINE, 0)
  262. DEFTK(META, 0, 0, META, 0)
  263. DEFTK(PALETTE, 0, 0, PALETTE, 0)
  264. DEFTK(PATH, 0, 0, PATH, 0)
  265. DEFTK( NtGdiPathToRegion, 0x000, 0, PATH, 0)
  266. DEFTK(PEN, 0, 0, PEN, 0)
  267. DEFTK(REGION, 0, 0, REGION, 0)
  268. DEFTK( GreCombineRgn, 0x0001, 0, REGION, 0)
  269. DEFTK( NtGdiCombineRgn, 0x0001, 0, REGION, 0)
  270. DEFTK( NtGdiCreateEllipticRgn, 0x0002, 0, REGION, 0)
  271. DEFTK( GreCreatePolyPolygonRgnInternal, 0x0004, 0, REGION, 0)
  272. DEFTK( GreCreateRectRgn, 0x0008, 0, REGION, 0)
  273. DEFTK( NtGdiCreateRectRgn, 0x0008, 0, REGION, 0)
  274. DEFTK( GreCreateRectRgnIndirect,0x0010, 0, REGION, 0)
  275. DEFTK( GreExtCreateRegion, 0x0020, 0, REGION, 0)
  276. DEFTK(NtGdiExtCreateRegion, 0x0020, 0, REGION, 0)
  277. DEFTK( NtGdiCreateRoundRectRgn, 0x0040, 0, REGION, 0)
  278. DEFTK( NtGdiEqualRgn, 0x0080, 0, REGION, 0)
  279. DEFTK( GreGetRandomRgn, 0x0100, 0, REGION, 0)
  280. DEFTK( NtGdiGetRandomRgn, 0x0100, 0, REGION, 0)
  281. DEFTK( GreGetRegionData, 0x0200, 0, REGION, 0)
  282. DEFTK( NtGdiGetRegionData, 0x0200, 0, REGION, 0)
  283. DEFTK( GreGetRgnBox, 0x0400, 0, REGION, 0)
  284. DEFTK( NtGdiGetRgnBox, 0x0400, 0, REGION, 0)
  285. DEFTK( GreOffsetRgn, 0x0800, 0, REGION, 0)
  286. DEFTK( NtGdiOffsetRgn, 0x0800, 0, REGION, 0)
  287. DEFTK( GrePtInRegion, 0x1000, 0, REGION, 0)
  288. DEFTK( NtGdiPtInRegion, 0x1000, 0, REGION, 0)
  289. DEFTK( GreRectInRegion, 0x2000, 0, REGION, 0)
  290. DEFTK( NtGdiRectInRegion, 0x2000, 0, REGION, 0)
  291. DEFTK( GreSetRectRgn, 0x4000, 0, REGION, 0)
  292. DEFTK( NtGdiSetRectRgn, 0x4000, 0, REGION, 0)
  293. DEFTK( GreSubtractRgnRectList, 0x8000, 0, REGION, 0)
  294. DEFTK(SHAPE, 0, 0, SHAPE, 0)
  295. DEFTK(SPRITE, 0, 0, SPRITE, 0)
  296. DEFTK(SYSTEM, 0, 0, SYSTEM, 0)
  297. DEFTK( NtGdiFlushUserBatch, 0x0001, 0, SYSTEM, 0)
  298. DEFTK(TEXT, 0, 0, TEXT, 0)
  299. DEFTK(VIEW, 0, 0, VIEW, 0)
  300. DEFTK( GreGetViewportOrg, 0x000, 0, VIEW, 0)
  301. DEFTK( GreSetViewportOrg, 0x000, 0, VIEW, 0)
  302. __inline
  303. BOOL
  304. GDITraceEnabled()
  305. {
  306. int i;
  307. for (i = 0; i < GDITRACE_TOTAL_CLASS_MASKS; i++)
  308. if (gGDITraceClassMask[i]) return TRUE;
  309. for (i = 0; i < GDITRACE_TOTAL_KEY_MASKS; i++)
  310. if (gGDITraceKeyMask[i]) return TRUE;
  311. return FALSE;
  312. }
  313. #define GDITraceWrapCore(key, code) \
  314. if (!GDITFInternal(key) || \
  315. (GDITM(key) & gGDITraceInternalMask[GDITMIndex(key)]) \
  316. ) \
  317. { \
  318. code; \
  319. }
  320. #define GDITraceWrap(key, code) \
  321. do { \
  322. BOOL GDITraceSuccess; \
  323. GDITraceWrapCore(key, code) \
  324. } while ( 0 )
  325. #define GDITracePrint(prefix, msg, arglist) \
  326. do { \
  327. if (GDIFunctionName) \
  328. { \
  329. DbgPrint(prefix); \
  330. EngDebugPrint((PCHAR)GDIFunctionName, msg, arglist); \
  331. } \
  332. else \
  333. { \
  334. EngDebugPrint(prefix, msg, arglist); \
  335. } \
  336. } while ( 0 )
  337. #define GDITraceCore(ss, key, msg, arglist) \
  338. if (GDITFAlways(key) || GDITFAnytrace(key)) \
  339. { \
  340. if (GDITFAlways(key) || GDITraceEnabled()) \
  341. { \
  342. GreAcquireSemaphore(ghsemDEBUG); \
  343. GDITracePrint("GDI: ", msg, arglist); \
  344. GreReleaseSemaphore(ghsemDEBUG); \
  345. if (ss) GDITraceSuccess = TRUE; \
  346. } \
  347. } \
  348. else if ((GDITM(key) != 0) && \
  349. ((GDITM(key) & gGDITraceKeyMask[GDITMIndex(key)]) || \
  350. ((! GDITFIgnoreC(key)) && \
  351. ((1 << GDITCBit(key)) & gGDITraceClassMask[GDITCIndex(key)])))) \
  352. { \
  353. GreAcquireSemaphore(ghsemDEBUG); \
  354. if (ss) { \
  355. GDITracePrint("GDI: ", msg, arglist); \
  356. GDITraceSuccess = TRUE; \
  357. } else { \
  358. EngDebugPrint("GDI: " #key, msg, arglist); \
  359. } \
  360. GreReleaseSemaphore(ghsemDEBUG); \
  361. } \
  362. else if ((! GDITFIgnoreC(key)) && \
  363. ((1 << GDITCBit(key)) & gGDITraceClassMask[GDITCIndex(key)])) \
  364. { \
  365. GreAcquireSemaphore(ghsemDEBUG); \
  366. EngDebugPrint("GDI: " #key " Trace ", msg, arglist); \
  367. GreReleaseSemaphore(ghsemDEBUG); \
  368. if (ss) GDITraceSuccess = TRUE; \
  369. }
  370. #define GDITraceHandleMatch(ss, key, msg, arglist) \
  371. do { \
  372. GreAcquireSemaphore(ghsemDEBUG); \
  373. if (ss) { \
  374. GDITracePrint("GDI: hMatch: ", msg, arglist); \
  375. GDITraceSuccess = TRUE; \
  376. } else { \
  377. EngDebugPrint("GDI: hMatch: " #key, msg, arglist); \
  378. } \
  379. if (gGDITraceHandleBreak) \
  380. { \
  381. EngDebugBreak(); \
  382. } \
  383. GreReleaseSemaphore(ghsemDEBUG); \
  384. } while ( 0 )
  385. #define GDITraceHandleCore(ss, key, msg, arglist, handle) \
  386. HANDLE Handle = (HANDLE)(handle); \
  387. if ((Handle != NULL) && \
  388. ((gGDITraceHandle1 == Handle) || \
  389. (gGDITraceHandle2 == Handle))) \
  390. { \
  391. GDITraceHandleMatch(ss, key, msg, arglist); \
  392. }
  393. /*
  394. #define GDITraceHandle2Core(ss, key, msg, arglist, handle1, handle2) \
  395. HANDLE Handle1 = (HANDLE)(handle1); \
  396. HANDLE Handle2 = (HANDLE)(handle2); \
  397. if (((gGDITraceHandle1 != NULL) && \
  398. ((gGDITraceHandle1 == Handle1) || \
  399. (gGDITraceHandle1 == Handle2)) \
  400. ) || \
  401. ((gGDITraceHandle2 != NULL) && \
  402. ((gGDITraceHandle2 == Handle1) || \
  403. (gGDITraceHandle2 == Handle2)) \
  404. )) \
  405. { \
  406. GDITraceHandleMatch(ss, key, msg, arglist); \
  407. }
  408. */
  409. #define GDITraceHandle3Core(ss, key, msg, arglist, handle1, handle2, handle3)\
  410. HANDLE Handle1 = (HANDLE)(handle1); \
  411. HANDLE Handle2 = (HANDLE)(handle2); \
  412. HANDLE Handle3 = (HANDLE)(handle3); \
  413. if (((gGDITraceHandle1 != NULL) && \
  414. ((gGDITraceHandle1 == Handle1) || \
  415. (gGDITraceHandle1 == Handle2) || \
  416. (gGDITraceHandle1 == Handle3)) \
  417. ) || \
  418. ((gGDITraceHandle2 != NULL) && \
  419. ((gGDITraceHandle2 == Handle1) || \
  420. (gGDITraceHandle2 == Handle2) || \
  421. (gGDITraceHandle2 == Handle3)) \
  422. )) \
  423. { \
  424. GDITraceHandleMatch(ss, key, msg, arglist); \
  425. }
  426. // GDITraceXxxx Parameters
  427. //
  428. // key - key setup by DEFTK or defined as GDITE_key
  429. // msg - msg printf formatted string
  430. // arglist - var arg pointer
  431. // handle - handle(s) used at this trace point
  432. // Test key key and print "GDI: <key><msg>"
  433. #define GDITrace(key, msg, arglist) \
  434. GDITraceWrap(key, \
  435. GDITraceCore(0, key, msg, arglist) \
  436. )
  437. // Test handle and print "GDI: hMatch: <key><msg>" or do GDITrace
  438. #define GDITraceHandle(key, msg, arglist, handle) \
  439. GDITraceWrap(key, \
  440. GDITraceHandleCore(0, key, msg, arglist, handle) \
  441. else GDITraceCore(0, key, msg, arglist) \
  442. )
  443. // Test handles and print "GDI: hMatch: <key><msg>" or do GDITrace
  444. #define GDITraceHandle2(key, msg, arglist, handle1, handle2) \
  445. GDITraceHandle3(key, msg, arglist, handle1, handle2, NULL)
  446. // Test handles and print "GDI: hMatch: <key><msg>" or do GDITrace
  447. #define GDITraceHandle3(key, msg, arglist, handle1, handle2, handle3) \
  448. GDITraceWrap(key, \
  449. GDITraceHandle3Core(0, key, msg, arglist, handle1, handle2, handle3) \
  450. else GDITraceCore(0, key, msg, arglist) \
  451. )
  452. // Mark beginning of trace with multiple tests
  453. // msg and arglist will be used in the print message for any
  454. // successful GDITraceMultiXxxx prior to GDITraceMultiEnd.
  455. // GDIFunctionName will be printed if GDIFunctionID is used.
  456. #define GDITraceMultiBegin(msg, arglist) \
  457. do { \
  458. BOOL GDITraceSuccess = FALSE; \
  459. const PCHAR MultiMsg = msg; \
  460. const va_list MultiList = arglist
  461. // Test key key and print "GDI: <GDIFunctionName><msg>"
  462. #define GDITraceMulti(key) \
  463. if (!GDITraceSuccess) \
  464. { \
  465. GDITraceWrapCore(key, \
  466. GDITraceCore(1, key, MultiMsg, MultiList) \
  467. ) \
  468. }
  469. // Test handle and print "GDI: hMatch: <GDIFunctionName><msg>"
  470. #define GDITraceMultiHandle(handle) \
  471. GDITraceMultiHandle3(handle, NULL, NULL)
  472. // Test handles and print "GDI: hMatch: <GDIFunctionName><msg>"
  473. #define GDITraceMultiHandle2(handle1, handle2) \
  474. GDITraceMultiHandle3(handle1, handle2, NULL)
  475. // Test handles and print "GDI: hMatch: <GDIFunctionName><msg>"
  476. #define GDITraceMultiHandle3(handle1, handle2, handle3) \
  477. if (!GDITraceSuccess) \
  478. { \
  479. GDITraceHandle3Core(1, HANDLETRACE, MultiMsg, MultiList, handle1, handle2, handle3) \
  480. }
  481. // Mark end of trace with multiple tests
  482. #define GDITraceMultiEnd() \
  483. } while ( 0 )
  484. #else
  485. #define GDITE(Key)
  486. #define DEFTK(Key, Mask, MaskWordIndex, Class, Flags)
  487. #define GDITrace(key, msg, arglist)
  488. #define GDITraceHandle(key, msg, arglist, handle)
  489. #define GDITraceHandle2(key, msg, arglist, handle1, handle2)
  490. #define GDITraceHandle3(key, msg, arglist, handle1, handle2, handle3)
  491. #define GDITraceMultiBegin(msg, arglist)
  492. #define GDITraceMulti(key)
  493. #define GDITraceMultiHandle(handle)
  494. #define GDITraceMultiHandle2(handle1, handle2)
  495. #define GDITraceMultiHandle3(handle1, handle2, handle3)
  496. #define GDITraceMultiEnd()
  497. #endif
  498. #endif _GDIDEBUG_H_