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.

445 lines
13 KiB

  1. /*
  2. ** Copyright (c) 1991 Microsoft Corporation
  3. */
  4. //===========================================================================
  5. // FILE HRE.C
  6. //
  7. // MODULE Host Resource Executor
  8. //
  9. // PURPOSE Convert A-form to B-form for jumbo driver
  10. //
  11. // DESCRIBED IN Resource Executor design spec.
  12. //
  13. // MNEMONICS n/a
  14. //
  15. // HISTORY 1/17/92 mslin created
  16. // 3/30/92 mslin Pre-compiled brush generated for each job.
  17. // ideal case would be initialize PcrBrush in
  18. // HRE.DLL loading, and free up when HRE
  19. // terminate. but we had problem in Dumbo, ???
  20. // Expanded Brush Buffer allocated for each job.
  21. // lpgBrush will be set to lpREState->lpBrushBuf
  22. // in DoRpl().
  23. // 4/15/92 mslin added uiHREExecuteRPL() for dumbo.
  24. // 9/27/93 mslin added a new bit of wFlags in hHREOpen() for
  25. // 300/600 dpi:
  26. // bit2: 0 -- 300 dpi
  27. // bit2: 1 -- 600 dpi
  28. // also remove DUMBO compiler switch.
  29. // 2/09/94 rajeevd Undid all of the above changes.
  30. //===========================================================================
  31. // include file
  32. #include <windows.h>
  33. #include <windowsx.h>
  34. #include <resexec.h>
  35. #include "constant.h"
  36. #include "jtypes.h" // type definition used in cartridge
  37. #include "jres.h" // cartridge resource data type definition
  38. #include "hretype.h" // define data structure used by hre.c and rpgen.c
  39. #include "hreext.h"
  40. #include "multbyte.h" // define macros to take care of byte ordering
  41. #define HRE_SUCCESS 0x0 // successful return from HRE
  42. #define HRE_EXECUTED_RPL 0x01 // Executed the final RP in an RPL
  43. #define HRE_EXECUTED_ONE 0x02 // Executed only one RP from an RPL
  44. // (not the last one)
  45. #define HRE_ERROR 0x03 // General HRE failure
  46. // PRIVATE functions
  47. static UINT PutRPL(LPHRESTATE lpHREState, LPFRAME lpFrameArray,
  48. UINT uiCount);
  49. static UINT FreeRPL(LPRPLLIST lpRPL);
  50. #ifdef DEBUG
  51. DWORD dwrgTime[MAXBAND];
  52. SHORT sCurrentLine;
  53. ULONG ulgPageId = 0;
  54. ULONG ulgTimes[1000] = {0};
  55. #endif
  56. #include "windows.h"
  57. //==============================================================================
  58. #ifndef WIN32
  59. BOOL WINAPI LibMain
  60. (HANDLE hInst, WORD wSeg, WORD wHeap, LPSTR lpszCmd)
  61. { return 1; }
  62. int WINAPI WEP (int nParam);
  63. #pragma alloc_text(INIT_TEXT,WEP)
  64. int WINAPI WEP (int nParam)
  65. { return 1; }
  66. #endif
  67. //==============================================================================
  68. HANDLE // context handle (NULL on failure)
  69. WINAPI hHREOpen
  70. (
  71. LPVOID lpBrushPat, // array of 32x32 brush patterns
  72. UINT cbLine, // maximum page width in bytes
  73. UINT cResDir // entries in resource directory
  74. )
  75. {
  76. HANDLE hHREState;
  77. LPHRESTATE lpHREState;
  78. LPRESTATE lpREState;
  79. LPRESDIR lpDlResDir;
  80. // create a handle for the new session
  81. if (!(hHREState = GlobalAlloc(GMEM_MOVEABLE, sizeof(HRESTATE))))
  82. return (NULL);
  83. lpHREState = (LPHRESTATE) GlobalLock (hHREState);
  84. // allocate Download ResDir Table
  85. if (!(lpDlResDir = (LPRESDIR) GlobalAllocPtr (GMEM_ZEROINIT, sizeof(RESDIR) * cResDir)))
  86. {
  87. // unlock and free HRESTATE
  88. GlobalUnlock(hHREState);
  89. GlobalFree(hHREState);
  90. return(NULL);
  91. }
  92. // allocate RESTATE data structure and Initialize it
  93. // this is graphic state of rendering
  94. if (!(lpREState = (LPRESTATE) GlobalAllocPtr (GMEM_ZEROINIT, sizeof(RESTATE))))
  95. {
  96. GlobalUnlock(hHREState);
  97. GlobalFree(hHREState);
  98. GlobalFreePtr (lpDlResDir);
  99. return (NULL);
  100. }
  101. #ifdef WIN32
  102. lpREState->lpBrushBuf = NULL;
  103. #else
  104. if (!(lpREState->lpBrushBuf = (LPSTR) GlobalAllocPtr(GMEM_MOVEABLE, (cbLine + 4) * 16)))
  105. {
  106. GlobalUnlock(hHREState);
  107. GlobalFree(hHREState);
  108. GlobalFreePtr (lpDlResDir);
  109. GlobalFreePtr (lpREState);
  110. return (NULL);
  111. }
  112. #endif
  113. // Initialize RESTATE
  114. lpREState->lpBrushPat = lpBrushPat;
  115. // Initialize HRESTATE
  116. lpHREState->hHREState = hHREState;
  117. lpHREState->scDlResDir = (USHORT)cResDir;
  118. lpHREState->lpDlResDir = lpDlResDir;
  119. lpHREState->lpRPLHead= NULL;
  120. lpHREState->lpRPLTail= NULL;
  121. lpHREState->lpREState = lpREState;
  122. GlobalUnlock(hHREState);
  123. return(hHREState);
  124. }
  125. //---------------------------------------------------------------------------
  126. UINT // will be zero (0) if resource is processed
  127. // succesfully, otherwise it will be an error
  128. // code as defined above.
  129. WINAPI uiHREWrite
  130. (
  131. HANDLE hHREState, // handle returned previously by hREOpen
  132. LPFRAME lpFrameArray, // FAR pointer to an array of FRAME structs
  133. UINT uiCount // Number of FRAME structs pointed to by
  134. // lpFrameArray
  135. )
  136. // PURPOSE To add a resource block (RPLK) to the
  137. // HRE state hash table for the context
  138. // identified by hHREState.
  139. //
  140. // ASSUMPTIONS & ASSERTIONS The memory for the RBLK has allready been
  141. // Allocated and locked. HRE will not copy the
  142. // data, just the pointers.
  143. // The lpFrameArray does not point to an SPL.
  144. // All SPL's will be handled externally to HRE.
  145. //
  146. // INTERNAL STRUCTURES
  147. //
  148. // UNRESOLVED ISSUES
  149. //
  150. //---------------------------------------------------------------------------
  151. {
  152. LPHRESTATE lpHREState;
  153. LPJG_RES_HDR lpResHdr;
  154. LPRESDIR lpResDir;
  155. ULONG ulUID;
  156. USHORT usClass;
  157. HANDLE hFrame;
  158. LPFRAME lpFrameArrayDup, lpFrame;
  159. UINT uiLoopCount;
  160. lpHREState = (LPHRESTATE) GlobalLock (hHREState);
  161. // get resource class
  162. lpResHdr = (LPJG_RES_HDR )lpFrameArray->lpData;
  163. usClass = GETUSHORT(&lpResHdr->usClass);
  164. switch(usClass)
  165. {
  166. case JG_RS_RPL: /*0x4*/
  167. // store into RPL list
  168. if( PutRPL(lpHREState, lpFrameArray, uiCount) != HRE_SUCCESS )
  169. {
  170. GlobalUnlock(hHREState);
  171. return(HRE_ERROR); // out of memory
  172. }
  173. break;
  174. case JG_RS_GLYPH: /*0x1*/
  175. case JG_RS_BRUSH: /*0x2*/
  176. case JG_RS_BITMAP: /*0x3*/
  177. // check to see if uid >= size of hash table then reallocate
  178. ulUID = GETULONG(&lpResHdr->ulUid);
  179. lpResDir = lpHREState->lpDlResDir;
  180. if (ulUID >= lpHREState->scDlResDir)
  181. {
  182. return(HRE_ERROR);
  183. }
  184. // Free frame array of previous resource block
  185. lpFrameArrayDup = lpResDir[ulUID].lpFrameArray;
  186. if(lpFrameArrayDup)
  187. GlobalFreePtr (lpFrameArrayDup);
  188. // copy frame array
  189. if (!(hFrame = GlobalAlloc(GMEM_MOVEABLE, uiCount * sizeof(FRAME))))
  190. return (HRE_ERROR);
  191. if (!(lpFrameArrayDup = (LPFRAME)GlobalLock(hFrame)))
  192. {
  193. GlobalFree(hFrame);
  194. return (HRE_ERROR);
  195. }
  196. lpFrame = lpFrameArrayDup;
  197. for(uiLoopCount=0; uiLoopCount<uiCount; uiLoopCount++)
  198. {
  199. *lpFrame++ = *lpFrameArray++;
  200. }
  201. // put into hash table
  202. lpResDir[ulUID].lpFrameArray = lpFrameArrayDup;
  203. lpResDir[ulUID].uiCount = uiCount;
  204. break;
  205. default:
  206. // error return
  207. break;
  208. }
  209. GlobalUnlock(hHREState);
  210. return(HRE_SUCCESS);
  211. }
  212. //---------------------------------------------------------------------------
  213. UINT WINAPI uiHREExecute
  214. (
  215. HANDLE hHREState, // resource executor context
  216. LPBITMAP lpbmBand, // output band buffer
  217. LPVOID lpBrushPat // array of 32x32 brush patterns
  218. )
  219. {
  220. LPHRESTATE lpHREState;
  221. LPRESTATE lpRE;
  222. LPRPLLIST lpRPL, lpRPLSave;
  223. lpHREState = (LPHRESTATE) GlobalLock (hHREState);
  224. // Record parameters in RESTATE.
  225. lpRE = lpHREState->lpREState;
  226. lpRE->lpBandBuffer = lpbmBand;
  227. lpRE->lpBrushPat = lpBrushPat;
  228. lpRPL = lpHREState->lpRPLHead;
  229. do
  230. {
  231. DoRPL(lpHREState, lpRPL);
  232. lpRPLSave = lpRPL;
  233. lpRPL=lpRPL->lpNextRPL;
  234. FreeRPL(lpRPLSave);
  235. }
  236. while(lpRPL);
  237. // if last RP executed then update lpRPLHead
  238. lpHREState->lpRPLHead = lpRPL;
  239. GlobalUnlock(hHREState);
  240. return(HRE_EXECUTED_RPL);
  241. }
  242. //---------------------------------------------------------------------------
  243. UINT // will be zero (0) if HRE context is closed
  244. // succesfully, otherwise it will be an error
  245. // code as defined above.
  246. WINAPI uiHREClose
  247. (
  248. HANDLE hHREState // handle returned previously by hREOpen
  249. )
  250. // PURPOSE To close a previously opened context in the
  251. // HRE. All memory and state information
  252. // associated with the context will be freed.
  253. //
  254. // ASSUMPTIONS & ASSERTIONS None.
  255. //
  256. // INTERNAL STRUCTURES None.
  257. //
  258. // UNRESOLVED ISSUES programmer development notes
  259. //
  260. // --------------------------------------------------------------------------
  261. {
  262. LPHRESTATE lpHREState;
  263. LPRESTATE lpRE;
  264. LPRESDIR lpDlResDir;
  265. SCOUNT scDlResDir;
  266. SCOUNT sc;
  267. LPFRAME lpFrameArray;
  268. if (!(lpHREState = (LPHRESTATE) GlobalLock (hHREState)))
  269. return HRE_ERROR;
  270. lpDlResDir = lpHREState->lpDlResDir;
  271. if(lpDlResDir != NULL) // mslin, 4/15/92 for dumbo
  272. {
  273. scDlResDir = lpHREState->scDlResDir;
  274. // free frame array of DlResDir
  275. for(sc = 0; sc < scDlResDir; sc++)
  276. {
  277. if( (lpFrameArray = lpDlResDir[sc].lpFrameArray) != NULL)
  278. GlobalFreePtr (lpFrameArray);
  279. }
  280. // unlock and free DlResDir
  281. GlobalFreePtr(lpDlResDir);
  282. }
  283. lpRE = lpHREState->lpREState;
  284. #ifndef WIN32
  285. GlobalFreePtr (lpRE->lpBrushBuf);
  286. #endif
  287. GlobalFreePtr (lpRE);
  288. GlobalUnlock(hHREState);
  289. GlobalFree(hHREState);
  290. return(HRE_SUCCESS);
  291. }
  292. // ------------------------------------------------------------------------
  293. static
  294. UINT // HRE_SUCCESS if allocate memory OK
  295. // HRE_ERROR if allocate memory failure
  296. PutRPL
  297. (
  298. LPHRESTATE lpHREState,
  299. LPFRAME lpFrameArray,
  300. UINT uiCount
  301. )
  302. // PURPOSE
  303. // Allocate a RPL entry and then put RPL into
  304. // tail of RPL list.
  305. //
  306. //
  307. // ------------------------------------------------------------------------
  308. {
  309. HANDLE hRPL;
  310. LPRPLLIST lpRPL;
  311. HANDLE hFrame;
  312. LPFRAME lpFrameArrayDup, lpFrame;
  313. UINT uiLoopCount;
  314. BOOL fAllocMemory = FALSE;
  315. if (hRPL = GlobalAlloc(GMEM_MOVEABLE, sizeof(RPLLIST)))
  316. {
  317. if (lpRPL = (LPRPLLIST)GlobalLock(hRPL))
  318. {
  319. if (hFrame = GlobalAlloc(GMEM_MOVEABLE, uiCount * sizeof(FRAME)))
  320. {
  321. if (lpFrameArrayDup = (LPFRAME)GlobalLock(hFrame))
  322. {
  323. // all allocations are ok:
  324. fAllocMemory = TRUE;
  325. }
  326. else
  327. {
  328. GlobalFree(hFrame);
  329. GlobalUnlock(hRPL);
  330. GlobalFree(hRPL);
  331. }
  332. }
  333. else
  334. {
  335. GlobalUnlock(hRPL);
  336. GlobalFree(hRPL);
  337. }
  338. }
  339. else
  340. {
  341. GlobalFree(hRPL);
  342. }
  343. }
  344. if (!fAllocMemory)
  345. {
  346. return (HRE_ERROR);
  347. }
  348. lpFrame = lpFrameArrayDup;
  349. for(uiLoopCount=0; uiLoopCount<uiCount; uiLoopCount++)
  350. {
  351. *lpFrame++ = *lpFrameArray++;
  352. }
  353. lpRPL->uiCount = uiCount;
  354. lpRPL->lpFrame = lpFrameArrayDup;
  355. lpRPL->lpNextRPL = NULL;
  356. if(lpHREState->lpRPLHead == NULL)
  357. {
  358. // first RPL
  359. lpHREState->lpRPLHead = lpHREState->lpRPLTail = lpRPL;
  360. }
  361. else
  362. {
  363. lpHREState->lpRPLTail->lpNextRPL = lpRPL;
  364. lpHREState->lpRPLTail = lpRPL;
  365. }
  366. return(HRE_SUCCESS);
  367. }
  368. // ------------------------------------------------------------------------
  369. static
  370. UINT // HRE_SUCCESS if allocate memory OK
  371. // HRE_ERROR if allocate memory failure
  372. FreeRPL
  373. (
  374. LPRPLLIST lpRPL
  375. )
  376. // PURPOSE
  377. // Free a RPL entry and its frame array
  378. //
  379. // ------------------------------------------------------------------------
  380. {
  381. GlobalFreePtr (lpRPL->lpFrame);
  382. GlobalFreePtr (lpRPL);
  383. return HRE_SUCCESS;
  384. }