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.

600 lines
15 KiB

  1. /******************************Module*Header*******************************\
  2. *
  3. * *******************
  4. * * GDI SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: log.c
  8. *
  9. *
  10. * Copyright (c) 1992-1999 Microsoft Corporation. All rights reserved.
  11. **************************************************************************/
  12. #include "precomp.h"
  13. #include "gdi.h"
  14. #include "log.h"
  15. // Logging support
  16. #define MAX_LOG_FILE_NAME_SIZE 80
  17. #define LF_PUNTED 0x1
  18. #define LF_DSTVM 0x2
  19. #define LF_SRCVM 0x4
  20. #define LF_CALLDEPTHMASK 0xf0
  21. #define LE_NULL 0
  22. #define LE_BITBLT 1
  23. #define LE_COPYBITS 2
  24. #define LE_SURFCREATED 3
  25. #define LE_SURFMOVEDTOSM 4
  26. #define LE_SURFMOVEDTOVM 5
  27. #define LE_LOGOPENED 6
  28. #define LE_LOGCLOSED 7
  29. #define LE_ALPHABLEND 8
  30. #define LE_TRANSPARENTBLT 9
  31. #define LE_TEXTOUT 10
  32. #define LE_FILLPATH 11
  33. #define LE_STROKEPATH 12
  34. #define LE_LINETO 13
  35. #define LE_SURFDELETED 14
  36. #define LE_GRADIENTFILL 15
  37. typedef struct LogEntry
  38. {
  39. USHORT elapsedTime;
  40. BYTE flags;
  41. BYTE event;
  42. ULONG_PTR src; // format or pdsurf
  43. ULONG_PTR dst; // format or pdsurf
  44. USHORT rop4;
  45. } LogEntry;
  46. LogEntry * gLog = NULL; // pointer to mapped log file
  47. ULONG_PTR giFile = NULL;
  48. LogEntry * gLogPos; // current position in log file
  49. LogEntry * gLogSentinel; // end of log file
  50. wchar_t gLogFileName[MAX_LOG_FILE_NAME_SIZE+1];
  51. BOOL gPunted = FALSE;
  52. ULONG ulLogOpen(LPWSTR pwsz, ULONG ulSize)
  53. {
  54. ULONG ulResult = 0;
  55. // Make sure the log the log will be big enough to store atleast the log
  56. // open and the log close events
  57. if(gLog == NULL && ulSize >= (sizeof(LogEntry) * 2))
  58. {
  59. if(wcslen(pwsz) <= MAX_LOG_FILE_NAME_SIZE)
  60. {
  61. wcscpy(gLogFileName, pwsz);
  62. gLog = (LogEntry *) EngMapFile(gLogFileName, ulSize, &giFile);
  63. if (gLog != NULL)
  64. {
  65. // NOTE: we subtract one to save room for the close event
  66. gLogSentinel = gLog + ((ulSize / sizeof(LogEntry)) - 1);
  67. memset(gLog, 0, ulSize);
  68. gLogPos = gLog;
  69. gLogPos->event = LE_LOGOPENED;
  70. {
  71. LONGLONG frequency;
  72. EngQueryPerformanceFrequency(&frequency);
  73. if(frequency < 0xFFFFFFFF)
  74. gLogPos->dst = (ULONG) (frequency & 0xFFFFFFFF);
  75. }
  76. gLogPos++;
  77. ulResult = TRUE;
  78. }
  79. }
  80. }
  81. return ulResult;
  82. }
  83. ULONG ulLogClose(void)
  84. {
  85. ULONG ulResult = 0;
  86. if(gLog != NULL)
  87. {
  88. // there is always room for the closed event
  89. gLogPos->event = LE_LOGCLOSED;
  90. ulResult = (ULONG) EngUnmapFile((ULONG_PTR) giFile);
  91. }
  92. gLog = NULL;
  93. return ulResult;
  94. }
  95. void vLogPunt(void)
  96. {
  97. if(gLog != NULL)
  98. gLogPos->flags |= LF_PUNTED;
  99. }
  100. void
  101. vLogBitBlt(
  102. SURFOBJ* psoDst,
  103. SURFOBJ* psoSrc,
  104. SURFOBJ* psoMsk,
  105. CLIPOBJ* pco,
  106. XLATEOBJ* pxlo,
  107. RECTL* prclDst,
  108. POINTL* pptlSrc,
  109. POINTL* pptlMsk,
  110. BRUSHOBJ* pbo,
  111. POINTL* pptlBrush,
  112. ROP4 rop4,
  113. LONGLONG elapsedTime,
  114. ULONG ulCallDepth)
  115. {
  116. if(gLog != NULL && gLogPos < gLogSentinel)
  117. {
  118. if(psoDst->dhsurf != NULL)
  119. {
  120. Surf * surf = (Surf *) psoDst->dhsurf;
  121. gLogPos->dst = (ULONG_PTR) surf;
  122. if(surf->flags & SF_VM)
  123. gLogPos->flags |= LF_DSTVM;
  124. }
  125. else
  126. {
  127. gLogPos->dst = (ULONG) psoDst->iBitmapFormat;
  128. }
  129. if(psoSrc != NULL)
  130. {
  131. if(psoSrc->dhsurf != NULL)
  132. {
  133. Surf * surf = (Surf *) psoSrc->dhsurf;
  134. gLogPos->src = (ULONG_PTR) surf;
  135. if(surf->flags & SF_VM)
  136. gLogPos->flags |= LF_SRCVM;
  137. }
  138. else
  139. {
  140. gLogPos->src = (ULONG) psoSrc->iBitmapFormat;
  141. }
  142. }
  143. else
  144. {
  145. gLogPos->src = 0;
  146. }
  147. gLogPos->rop4 = (USHORT) rop4;
  148. gLogPos->elapsedTime = (elapsedTime > 0xFFFF ? 0xFFFF
  149. : (USHORT) elapsedTime);
  150. gLogPos->event = LE_BITBLT;
  151. gLogPos->flags |=(ulCallDepth >= 15 ? 0xF0 : (BYTE) (ulCallDepth << 4));
  152. gLogPos++;
  153. }
  154. }
  155. void
  156. vLogCopyBits(
  157. SURFOBJ* psoDst,
  158. SURFOBJ* psoSrc,
  159. CLIPOBJ* pco,
  160. XLATEOBJ* pxlo,
  161. RECTL* prclDst,
  162. POINTL* pptlSrc,
  163. LONGLONG elapsedTime,
  164. ULONG ulCallDepth)
  165. {
  166. if(gLog != NULL && gLogPos < gLogSentinel)
  167. {
  168. if(psoDst->dhsurf != NULL)
  169. {
  170. Surf * surf = (Surf *) psoDst->dhsurf;
  171. gLogPos->dst = (ULONG_PTR) surf;
  172. if(surf->flags & SF_VM)
  173. gLogPos->flags |= LF_DSTVM;
  174. }
  175. else
  176. {
  177. gLogPos->dst = (ULONG) psoDst->iBitmapFormat;
  178. }
  179. if(psoSrc != NULL)
  180. {
  181. if(psoSrc->dhsurf != NULL)
  182. {
  183. Surf * surf = (Surf *) psoSrc->dhsurf;
  184. gLogPos->src = (ULONG_PTR) surf;
  185. if(surf->flags & SF_VM)
  186. gLogPos->flags |= LF_SRCVM;
  187. }
  188. else
  189. {
  190. gLogPos->src = (ULONG) psoSrc->iBitmapFormat;
  191. }
  192. }
  193. else
  194. {
  195. gLogPos->src = 0;
  196. }
  197. gLogPos->elapsedTime = (elapsedTime > 0xFFFF ? 0xFFFF
  198. : (USHORT) elapsedTime);
  199. gLogPos->event = LE_COPYBITS;
  200. gLogPos->flags |=(ulCallDepth >= 15 ? 0xF0 : (BYTE) (ulCallDepth << 4));
  201. gLogPos++;
  202. }
  203. }
  204. void
  205. vLogTransparentBlt(
  206. SURFOBJ * psoDst,
  207. SURFOBJ * psoSrc,
  208. CLIPOBJ * pco,
  209. XLATEOBJ * pxlo,
  210. RECTL * prclDst,
  211. RECTL * prclSrc,
  212. ULONG iTransColor,
  213. LONGLONG elapsedTime,
  214. ULONG ulCallDepth)
  215. {
  216. if(gLog != NULL && gLogPos < gLogSentinel)
  217. {
  218. if(psoDst->dhsurf != NULL)
  219. {
  220. Surf * surf = (Surf *) psoDst->dhsurf;
  221. gLogPos->dst = (ULONG_PTR) surf;
  222. if(surf->flags & SF_VM)
  223. gLogPos->flags |= LF_DSTVM;
  224. }
  225. else
  226. {
  227. gLogPos->dst = (ULONG) psoDst->iBitmapFormat;
  228. }
  229. if(psoSrc != NULL)
  230. {
  231. if(psoSrc->dhsurf != NULL)
  232. {
  233. Surf * surf = (Surf *) psoSrc->dhsurf;
  234. gLogPos->src = (ULONG_PTR) surf;
  235. if(surf->flags & SF_VM)
  236. gLogPos->flags |= LF_SRCVM;
  237. }
  238. else
  239. {
  240. gLogPos->src = (ULONG) psoSrc->iBitmapFormat;
  241. }
  242. }
  243. else
  244. {
  245. gLogPos->src = 0;
  246. }
  247. gLogPos->elapsedTime = (elapsedTime > 0xFFFF ? 0xFFFF
  248. : (USHORT) elapsedTime);
  249. gLogPos->event = LE_TRANSPARENTBLT;
  250. gLogPos->flags |=(ulCallDepth >= 15 ? 0xF0 : (BYTE) (ulCallDepth << 4));
  251. gLogPos++;
  252. }
  253. }
  254. void
  255. vLogAlphaBlend(
  256. SURFOBJ *psoDst,
  257. SURFOBJ *psoSrc,
  258. CLIPOBJ *pco,
  259. XLATEOBJ *pxlo,
  260. RECTL *prclDst,
  261. RECTL *prclSrc,
  262. BLENDOBJ *pBlendObj,
  263. LONGLONG elapsedTime,
  264. ULONG ulCallDepth)
  265. {
  266. if(gLog != NULL && gLogPos < gLogSentinel)
  267. {
  268. if(psoDst->dhsurf != NULL)
  269. {
  270. Surf * surf = (Surf *) psoDst->dhsurf;
  271. gLogPos->dst = (ULONG_PTR) surf;
  272. if(surf->flags & SF_VM)
  273. gLogPos->flags |= LF_DSTVM;
  274. }
  275. else
  276. {
  277. gLogPos->dst = (ULONG) psoDst->iBitmapFormat;
  278. }
  279. if(psoSrc != NULL)
  280. {
  281. if(psoSrc->dhsurf != NULL)
  282. {
  283. Surf * surf = (Surf *) psoSrc->dhsurf;
  284. gLogPos->src = (ULONG_PTR) surf;
  285. if(surf->flags & SF_VM)
  286. gLogPos->flags |= LF_SRCVM;
  287. }
  288. else
  289. {
  290. gLogPos->src = (ULONG_PTR) psoSrc->iBitmapFormat;
  291. }
  292. }
  293. else
  294. {
  295. gLogPos->src = 0;
  296. }
  297. gLogPos->elapsedTime = (elapsedTime > 0xFFFF ? 0xFFFF
  298. : (USHORT) elapsedTime);
  299. gLogPos->event = LE_ALPHABLEND;
  300. gLogPos->flags |=(ulCallDepth >= 15 ? 0xF0 : (BYTE) (ulCallDepth << 4));
  301. gLogPos++;
  302. }
  303. }
  304. void
  305. vLogGradientFill(
  306. SURFOBJ *psoDst,
  307. CLIPOBJ *pco,
  308. XLATEOBJ *pxlo,
  309. TRIVERTEX *pVertex,
  310. ULONG nVertex,
  311. PVOID pMesh,
  312. ULONG nMesh,
  313. RECTL *prclExtents,
  314. POINTL *pptlDitherOrg,
  315. ULONG ulMode,
  316. LONGLONG elapsedTime,
  317. ULONG ulCallDepth)
  318. {
  319. if(gLog != NULL && gLogPos < gLogSentinel)
  320. {
  321. if(psoDst->dhsurf != NULL)
  322. {
  323. Surf * surf = (Surf *) psoDst->dhsurf;
  324. gLogPos->dst = (ULONG_PTR) surf;
  325. if(surf->flags & SF_VM)
  326. gLogPos->flags |= LF_DSTVM;
  327. }
  328. else
  329. {
  330. gLogPos->dst = (ULONG) psoDst->iBitmapFormat;
  331. }
  332. gLogPos->elapsedTime = (elapsedTime > 0xFFFF ? 0xFFFF
  333. : (USHORT) elapsedTime);
  334. gLogPos->event = LE_GRADIENTFILL;
  335. gLogPos->flags |=(ulCallDepth >= 15 ? 0xF0 : (BYTE) (ulCallDepth << 4));
  336. gLogPos++;
  337. }
  338. }
  339. void
  340. vLogTextOut(
  341. SURFOBJ* psoDst,
  342. STROBJ* pstro,
  343. FONTOBJ* pfo,
  344. CLIPOBJ* pco,
  345. RECTL* prclExtra,
  346. RECTL* prclOpaque,
  347. BRUSHOBJ* pboFore,
  348. BRUSHOBJ* pboOpaque,
  349. POINTL* pptlBrush,
  350. MIX mix,
  351. LONGLONG elapsedTime,
  352. ULONG ulCallDepth)
  353. {
  354. if(gLog != NULL && gLogPos < gLogSentinel)
  355. {
  356. if(psoDst->dhsurf != NULL)
  357. {
  358. Surf * surf = (Surf *) psoDst->dhsurf;
  359. gLogPos->dst = (ULONG_PTR) surf;
  360. if(surf->flags & SF_VM)
  361. gLogPos->flags |= LF_DSTVM;
  362. }
  363. else
  364. {
  365. gLogPos->dst = (ULONG) psoDst->iBitmapFormat;
  366. }
  367. gLogPos->elapsedTime = (elapsedTime > 0xFFFF ? 0xFFFF
  368. : (USHORT) elapsedTime);
  369. gLogPos->event = LE_TEXTOUT;
  370. gLogPos->flags |=(ulCallDepth >= 15 ? 0xF0 : (BYTE) (ulCallDepth << 4));
  371. gLogPos++;
  372. }
  373. }
  374. void
  375. vLogLineTo(
  376. SURFOBJ* psoDst,
  377. CLIPOBJ* pco,
  378. BRUSHOBJ* pbo,
  379. LONG x1,
  380. LONG y1,
  381. LONG x2,
  382. LONG y2,
  383. RECTL* prclBounds,
  384. MIX mix,
  385. LONGLONG elapsedTime,
  386. ULONG ulCallDepth)
  387. {
  388. if(gLog != NULL && gLogPos < gLogSentinel)
  389. {
  390. if(psoDst->dhsurf != NULL)
  391. {
  392. Surf * surf = (Surf *) psoDst->dhsurf;
  393. gLogPos->dst = (ULONG_PTR) surf;
  394. if(surf->flags & SF_VM )
  395. gLogPos->flags |= LF_DSTVM;
  396. }
  397. else
  398. {
  399. gLogPos->dst = (ULONG) psoDst->iBitmapFormat;
  400. }
  401. gLogPos->elapsedTime = (elapsedTime > 0xFFFF ? 0xFFFF
  402. : (USHORT) elapsedTime);
  403. gLogPos->event = LE_LINETO;
  404. gLogPos->flags |=(ulCallDepth >= 15 ? 0xF0 : (BYTE) (ulCallDepth << 4));
  405. gLogPos++;
  406. }
  407. }
  408. void
  409. vLogFillPath(
  410. SURFOBJ* psoDst,
  411. PATHOBJ* ppo,
  412. CLIPOBJ* pco,
  413. BRUSHOBJ* pbo,
  414. POINTL* pptlBrush,
  415. MIX mix,
  416. FLONG flOptions,
  417. LONGLONG elapsedTime,
  418. ULONG ulCallDepth)
  419. {
  420. if(gLog != NULL && gLogPos < gLogSentinel)
  421. {
  422. if(psoDst->dhsurf != NULL)
  423. {
  424. Surf * surf = (Surf *) psoDst->dhsurf;
  425. gLogPos->dst = (ULONG_PTR) surf;
  426. if(surf->flags & SF_VM )
  427. gLogPos->flags |= LF_DSTVM;
  428. }
  429. else
  430. {
  431. gLogPos->dst = (ULONG) psoDst->iBitmapFormat;
  432. }
  433. gLogPos->elapsedTime = (elapsedTime > 0xFFFF ? 0xFFFF
  434. : (USHORT) elapsedTime);
  435. gLogPos->event = LE_FILLPATH;
  436. gLogPos->flags |=(ulCallDepth >= 15 ? 0xF0 : (BYTE) (ulCallDepth << 4));
  437. gLogPos++;
  438. }
  439. }
  440. void
  441. vLogStrokePath(
  442. SURFOBJ* psoDst,
  443. PATHOBJ* ppo,
  444. CLIPOBJ* pco,
  445. XFORMOBJ* pxo,
  446. BRUSHOBJ* pbo,
  447. POINTL* pptlBrush,
  448. LINEATTRS* pla,
  449. MIX mix,
  450. LONGLONG elapsedTime,
  451. ULONG ulCallDepth)
  452. {
  453. if(gLog != NULL && gLogPos < gLogSentinel)
  454. {
  455. if(psoDst->dhsurf != NULL)
  456. {
  457. Surf * surf = (Surf *) psoDst->dhsurf;
  458. gLogPos->dst = (ULONG_PTR) surf;
  459. if(surf->flags & SF_VM )
  460. gLogPos->flags |= LF_DSTVM;
  461. }
  462. else
  463. {
  464. gLogPos->dst = (ULONG) psoDst->iBitmapFormat;
  465. }
  466. gLogPos->elapsedTime = (elapsedTime > 0xFFFF ? 0xFFFF
  467. : (USHORT) elapsedTime);
  468. gLogPos->event = LE_STROKEPATH;
  469. gLogPos->flags |=(ulCallDepth >= 15 ? 0xF0 : (BYTE) (ulCallDepth << 4));
  470. gLogPos++;
  471. }
  472. }
  473. void
  474. vLogSurfMovedToVM(
  475. Surf* psurf)
  476. {
  477. if(gLog != NULL && gLogPos < gLogSentinel)
  478. {
  479. gLogPos->dst = (ULONG_PTR) psurf;
  480. gLogPos->event = LE_SURFMOVEDTOVM;
  481. gLogPos++;
  482. }
  483. }
  484. void
  485. vLogSurfMovedToSM(
  486. Surf* psurf)
  487. {
  488. if(gLog != NULL && gLogPos < gLogSentinel)
  489. {
  490. gLogPos->dst = (ULONG_PTR) psurf;
  491. gLogPos->event = LE_SURFMOVEDTOSM;
  492. gLogPos++;
  493. }
  494. }
  495. void
  496. vLogSurfCreated(
  497. Surf* psurf)
  498. {
  499. if(gLog != NULL && gLogPos < gLogSentinel)
  500. {
  501. gLogPos->dst = (ULONG_PTR) psurf;
  502. gLogPos->event = LE_SURFCREATED;
  503. gLogPos++;
  504. }
  505. }
  506. void
  507. vLogSurfDeleted(
  508. Surf* psurf)
  509. {
  510. if(gLog != NULL && gLogPos < gLogSentinel)
  511. {
  512. gLogPos->dst = (ULONG_PTR) psurf;
  513. gLogPos->event = LE_SURFDELETED;
  514. gLogPos++;
  515. }
  516. }