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.

390 lines
13 KiB

  1. /******************************Module*Header**********************************\
  2. *
  3. * *******************
  4. * * GDI SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: thunks.c
  8. *
  9. * This module contains the routines for dynamically loading the newly
  10. * added GDI exported APIs in the NT5.0 environment. By dynamic loading
  11. * we enable the usage of the same binary on NT4.0.
  12. *
  13. * All the functions in this module should only be called on NT5.0. If called
  14. * on NT4.0 in debug builds they will bugcheck.
  15. *
  16. * Copyright (c) 1994-1998 3Dlabs Inc. Ltd. All rights reserved.
  17. * Copyright (c) 1995-1999 Microsoft Corporation. All rights reserved.
  18. *
  19. \*****************************************************************************/
  20. #include "precomp.h"
  21. #include "gdi.h"
  22. #include "directx.h"
  23. #include "log.h"
  24. #include "heap.h"
  25. typedef BOOL
  26. (*_EngAlphaBlend)(IN SURFOBJ *psoDest,
  27. IN SURFOBJ *psoSrc,
  28. IN CLIPOBJ *pco,
  29. IN XLATEOBJ *pxlo,
  30. IN RECTL *prclDest,
  31. IN RECTL *prclSrc,
  32. IN BLENDOBJ *pBlendObj);
  33. typedef BOOL
  34. (*_EngGradientFill)(IN SURFOBJ *psoDest,
  35. IN CLIPOBJ *pco,
  36. IN XLATEOBJ *pxlo,
  37. IN TRIVERTEX *pVertex,
  38. IN ULONG nVertex,
  39. IN PVOID pMesh,
  40. IN ULONG nMesh,
  41. IN RECTL *prclExtents,
  42. IN POINTL *pptlDitherOrg,
  43. IN ULONG ulMode);
  44. typedef BOOL
  45. (*_EngTransparentBlt)(IN SURFOBJ *psoDst,
  46. IN SURFOBJ *psoSrc,
  47. IN CLIPOBJ *pco,
  48. IN XLATEOBJ *pxlo,
  49. IN RECTL *prclDst,
  50. IN RECTL *prclSrc,
  51. IN ULONG iTransparentColor,
  52. IN ULONG ulReserved);
  53. typedef PVOID
  54. (*_EngMapFile)(IN LPWSTR pwsz,
  55. IN ULONG cjSize,
  56. IN ULONG_PTR *piFile);
  57. typedef BOOL
  58. (*_EngUnmapFile)(IN ULONG_PTR iFile);
  59. typedef BOOL
  60. (*_EngQuerySystemAttribute)(ENG_SYSTEM_ATTRIBUTE CapNum,
  61. PDWORD pCapability);
  62. typedef ULONG
  63. (*_EngDitherColor)(HDEV hDev,
  64. ULONG iMode,
  65. ULONG rgb,
  66. ULONG *pul);
  67. typedef BOOL
  68. (*_EngModifySurface)(HSURF hsurf,
  69. HDEV hdev,
  70. FLONG flHooks,
  71. FLONG flSurface,
  72. DHSURF dhSurf,
  73. VOID* pvScan0,
  74. LONG lDelta,
  75. VOID* pvReserved);
  76. typedef BOOL
  77. (*_EngQueryDeviceAttribute)(HDEV hdev,
  78. ENG_DEVICE_ATTRIBUTE devAttr,
  79. VOID *pvIn,
  80. ULONG ulInSize,
  81. VOID *pvOut,
  82. ULONG ulOutSize);
  83. typedef FLATPTR
  84. (*_HeapVidMemAllocAligned)(LPVIDMEM lpVidMem,
  85. DWORD dwWidth,
  86. DWORD dwHeight,
  87. LPSURFACEALIGNMENT lpAlignment,
  88. LPLONG lpNewPitch);
  89. typedef void
  90. (*_VidMemFree)(LPVMEMHEAP pvmh, FLATPTR ptr);
  91. typedef ULONG
  92. (*_EngHangNotification)(HDEV hdev,
  93. PVOID Reserved);
  94. static _EngAlphaBlend pfnEngAlphaBlend = 0;
  95. static _EngGradientFill pfnEngGradientFill = 0;
  96. static _EngTransparentBlt pfnEngTransparentBlt = 0;
  97. static _EngMapFile pfnEngMapFile = 0;
  98. static _EngUnmapFile pfnEngUnmapFile = 0;
  99. static _EngQuerySystemAttribute pfnEngQuerySystemAttribute = 0;
  100. static _EngDitherColor pfnEngDitherColor = 0;
  101. static _EngModifySurface pfnEngModifySurface = 0;
  102. static _EngQueryDeviceAttribute pfnEngQueryDeviceAttribute = 0;
  103. static _HeapVidMemAllocAligned pfnHeapVidMemAllocAligned = 0;
  104. static _VidMemFree pfnVidMemFree = 0;
  105. static _EngHangNotification pfnEngHangNotification = 0;
  106. #define LOADTHUNKFUNC(x)\
  107. pfn##x = (_##x)EngFindImageProcAddress(0,#x);\
  108. ASSERTDD(pfn##x != 0, #x"thunk NULL");\
  109. if(pfn##x == 0)\
  110. return FALSE;
  111. //-----------------------------------------------------------------------------
  112. //
  113. // void bEnableThunks
  114. //
  115. //-----------------------------------------------------------------------------
  116. BOOL
  117. bEnableThunks()
  118. {
  119. ASSERTDD(g_bOnNT40 == FALSE, "bEnableThunks: called on NT4.0");
  120. LOADTHUNKFUNC(EngAlphaBlend);
  121. LOADTHUNKFUNC(EngGradientFill);
  122. LOADTHUNKFUNC(EngTransparentBlt);
  123. LOADTHUNKFUNC(EngMapFile);
  124. LOADTHUNKFUNC(EngUnmapFile);
  125. LOADTHUNKFUNC(EngQuerySystemAttribute);
  126. LOADTHUNKFUNC(EngDitherColor);
  127. LOADTHUNKFUNC(EngModifySurface);
  128. LOADTHUNKFUNC(EngQueryDeviceAttribute);
  129. LOADTHUNKFUNC(HeapVidMemAllocAligned);
  130. LOADTHUNKFUNC(VidMemFree);
  131. pfnEngHangNotification =
  132. (_EngHangNotification)EngFindImageProcAddress(0,"EngHangNotification");
  133. return TRUE;
  134. }
  135. //-----------------------------------------------------------------------------
  136. //
  137. // BOOL THUNK_EngAlphaBlend
  138. //
  139. //-----------------------------------------------------------------------------
  140. BOOL
  141. THUNK_EngAlphaBlend(IN SURFOBJ *psoDest,
  142. IN SURFOBJ *psoSrc,
  143. IN CLIPOBJ *pco,
  144. IN XLATEOBJ *pxlo,
  145. IN RECTL *prclDest,
  146. IN RECTL *prclSrc,
  147. IN BLENDOBJ *pBlendObj)
  148. {
  149. ASSERTDD(g_bOnNT40 == FALSE, "EngAlphaBlend called on NT4.0");
  150. return (*pfnEngAlphaBlend)(psoDest,
  151. psoSrc,
  152. pco,
  153. pxlo,
  154. prclDest,
  155. prclSrc,
  156. pBlendObj);
  157. }
  158. //-----------------------------------------------------------------------------
  159. //
  160. // BOOL THUNK_EngGradientFill
  161. //
  162. //-----------------------------------------------------------------------------
  163. BOOL
  164. THUNK_EngGradientFill(IN SURFOBJ *psoDest,
  165. IN CLIPOBJ *pco,
  166. IN XLATEOBJ *pxlo,
  167. IN TRIVERTEX *pVertex,
  168. IN ULONG nVertex,
  169. IN PVOID pMesh,
  170. IN ULONG nMesh,
  171. IN RECTL *prclExtents,
  172. IN POINTL *pptlDitherOrg,
  173. IN ULONG ulMode)
  174. {
  175. ASSERTDD(g_bOnNT40 == FALSE, "EngGradientFill called on NT4.0");
  176. return (*pfnEngGradientFill)(psoDest,
  177. pco,
  178. pxlo,
  179. pVertex,
  180. nVertex,
  181. pMesh,
  182. nMesh,
  183. prclExtents,
  184. pptlDitherOrg,
  185. ulMode);
  186. }
  187. //-----------------------------------------------------------------------------
  188. //
  189. // BOOL THUNK_EngTransparentBlt
  190. //
  191. //-----------------------------------------------------------------------------
  192. BOOL
  193. THUNK_EngTransparentBlt(IN SURFOBJ *psoDst,
  194. IN SURFOBJ *psoSrc,
  195. IN CLIPOBJ *pco,
  196. IN XLATEOBJ *pxlo,
  197. IN RECTL *prclDst,
  198. IN RECTL *prclSrc,
  199. IN ULONG iTransparentColor,
  200. IN ULONG ulReserved)
  201. {
  202. ASSERTDD(g_bOnNT40 == FALSE, "EngTransparentBlt called on NT4.0");
  203. return (*pfnEngTransparentBlt)(psoDst,
  204. psoSrc,
  205. pco,
  206. pxlo,
  207. prclDst,
  208. prclSrc,
  209. iTransparentColor,
  210. ulReserved);
  211. }
  212. //-----------------------------------------------------------------------------
  213. //
  214. // PVOID THUNK_EngMapFile
  215. //
  216. //-----------------------------------------------------------------------------
  217. PVOID
  218. THUNK_EngMapFile(IN LPWSTR pwsz,
  219. IN ULONG cjSize,
  220. IN ULONG_PTR *piFile)
  221. {
  222. ASSERTDD(g_bOnNT40 == FALSE, "EngMapFile called on NT4.0");
  223. return (*pfnEngMapFile)(pwsz,cjSize,piFile);
  224. }
  225. //-----------------------------------------------------------------------------
  226. //
  227. // BOOL THUNK_EngUnmapFile
  228. //
  229. //-----------------------------------------------------------------------------
  230. BOOL
  231. THUNK_EngUnmapFile(IN ULONG_PTR iFile)
  232. {
  233. ASSERTDD(g_bOnNT40 == FALSE, "EngUnmapFile called on NT4.0");
  234. return (*pfnEngUnmapFile)(iFile);
  235. }
  236. //-----------------------------------------------------------------------------
  237. //
  238. // BOOL THUNK_EngQuerySystemAttribute
  239. //
  240. //-----------------------------------------------------------------------------
  241. BOOL
  242. THUNK_EngQuerySystemAttribute(ENG_SYSTEM_ATTRIBUTE CapNum,
  243. PDWORD pCapability)
  244. {
  245. ASSERTDD(g_bOnNT40 == 0, "EngQuerySystemAttribute called on NT4.0");
  246. return (*pfnEngQuerySystemAttribute)(CapNum,pCapability);
  247. }
  248. //-----------------------------------------------------------------------------
  249. //
  250. // ULONG THUNK_EngDitherColor
  251. //
  252. //-----------------------------------------------------------------------------
  253. ULONG
  254. THUNK_EngDitherColor(HDEV hDev,
  255. ULONG iMode,
  256. ULONG rgb,
  257. ULONG *pul)
  258. {
  259. ASSERTDD(g_bOnNT40 == FALSE, "EngDitherColor called on NT4.0");
  260. return (*pfnEngDitherColor)(hDev,
  261. iMode,
  262. rgb,
  263. pul);
  264. }
  265. //-----------------------------------------------------------------------------
  266. //
  267. // BOOL THUNK_EngModifySurface
  268. //
  269. //-----------------------------------------------------------------------------
  270. BOOL
  271. THUNK_EngModifySurface(HSURF hsurf,
  272. HDEV hdev,
  273. FLONG flHooks,
  274. FLONG flSurface,
  275. DHSURF dhSurf,
  276. VOID* pvScan0,
  277. LONG lDelta,
  278. VOID* pvReserved)
  279. {
  280. ASSERTDD(g_bOnNT40 == FALSE, "EngModifySurface called on NT4.0");
  281. return (*pfnEngModifySurface)(hsurf,
  282. hdev,
  283. flHooks,
  284. flSurface,
  285. dhSurf,
  286. pvScan0,
  287. lDelta,
  288. pvReserved);
  289. }
  290. //-----------------------------------------------------------------------------
  291. //
  292. // BOOL THUNK_EngQueryDeviceAttribute
  293. //
  294. //-----------------------------------------------------------------------------
  295. BOOL
  296. THUNK_EngQueryDeviceAttribute(HDEV hdev,
  297. ENG_DEVICE_ATTRIBUTE devAttr,
  298. VOID *pvIn,
  299. ULONG ulInSize,
  300. VOID *pvOut,
  301. ULONG ulOutSize)
  302. {
  303. ASSERTDD(g_bOnNT40 == FALSE, "EngQueryDeviceAttribute called on NT4.0");
  304. return (*pfnEngQueryDeviceAttribute)(hdev,
  305. devAttr,
  306. pvIn,
  307. ulInSize,
  308. pvOut,
  309. ulOutSize);
  310. }
  311. //-----------------------------------------------------------------------------
  312. //
  313. // FLATPTR THUNK_HeapVidMemAllocAligned
  314. //
  315. //-----------------------------------------------------------------------------
  316. FLATPTR
  317. THUNK_HeapVidMemAllocAligned(LPVIDMEM lpVidMem,
  318. DWORD dwWidth,
  319. DWORD dwHeight,
  320. LPSURFACEALIGNMENT lpAlignment,
  321. LPLONG lpNewPitch)
  322. {
  323. ASSERTDD(g_bOnNT40 == FALSE, "HeapVidMemAllocAligned called on NT4.0");
  324. return (*pfnHeapVidMemAllocAligned)(lpVidMem,
  325. dwWidth,
  326. dwHeight,
  327. lpAlignment,
  328. lpNewPitch);
  329. }
  330. //-----------------------------------------------------------------------------
  331. //
  332. // void THUNK_VidMemFree
  333. //
  334. //-----------------------------------------------------------------------------
  335. void
  336. THUNK_VidMemFree(LPVMEMHEAP pvmh,
  337. FLATPTR ptr)
  338. {
  339. ASSERTDD(g_bOnNT40 == FALSE, "VidMemFree called on NT4.0");
  340. (*pfnVidMemFree)(pvmh,ptr);
  341. }
  342. //-----------------------------------------------------------------------------
  343. //
  344. // ULONG THUNK_EngHangNotifiation
  345. //
  346. //-----------------------------------------------------------------------------
  347. ULONG
  348. THUNK_EngHangNotification(HDEV hdev,
  349. PVOID Reserved)
  350. {
  351. return (pfnEngHangNotification != NULL) ?
  352. (*pfnEngHangNotification)(hdev,
  353. Reserved) :
  354. EHN_ERROR;
  355. }