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.

384 lines
12 KiB

  1. /*----------------------------------------------------------------------+
  2. | |
  3. | drvproc.c - driver procedure |
  4. | |
  5. | Copyright (c) 1993 Microsoft Corporation. |
  6. | All Rights Reserved. |
  7. | |
  8. +----------------------------------------------------------------------*/
  9. #include <windows.h>
  10. #include <windowsx.h>
  11. #include <mmsystem.h>
  12. #include "msyuv.h"
  13. HMODULE ghModule; // Our DLL module handle
  14. /***************************************************************************
  15. * DriverProc - The entry point for an installable driver.
  16. *
  17. * PARAMETERS
  18. * dwDriverId: For most messages, <dwDriverId> is the DWORD
  19. * value that the driver returns in response to a <DRV_OPEN> message.
  20. * Each time that the driver is opened, through the <DrvOpen> API,
  21. * the driver receives a <DRV_OPEN> message and can return an
  22. * arbitrary, non-zero value. The installable driver interface
  23. * saves this value and returns a unique driver handle to the
  24. * application. Whenever the application sends a message to the
  25. * driver using the driver handle, the interface routes the message
  26. * to this entry point and passes the corresponding <dwDriverId>.
  27. * This mechanism allows the driver to use the same or different
  28. * identifiers for multiple opens but ensures that driver handles
  29. * are unique at the application interface layer.
  30. *
  31. * The following messages are not related to a particular open
  32. * instance of the driver. For these messages, the dwDriverId
  33. * will always be zero.
  34. *
  35. * DRV_LOAD, DRV_FREE, DRV_ENABLE, DRV_DISABLE, DRV_OPEN
  36. *
  37. * hDriver: This is the handle returned to the application by the
  38. * driver interface.
  39. *
  40. * uiMessage: The requested action to be performed. Message
  41. * values below <DRV_RESERVED> are used for globally defined messages.
  42. * Message values from <DRV_RESERVED> to <DRV_USER> are used for
  43. * defined driver protocols. Messages above <DRV_USER> are used
  44. * for driver specific messages.
  45. *
  46. * lParam1: Data for this message. Defined separately for
  47. * each message
  48. *
  49. * lParam2: Data for this message. Defined separately for
  50. * each message
  51. *
  52. * RETURNS
  53. * Defined separately for each message.
  54. *
  55. ***************************************************************************/
  56. LRESULT DriverProc(PINSTINFO pi, HDRVR hDriver, UINT uiMessage, LPARAM lParam1, LPARAM lParam2)
  57. {
  58. switch (uiMessage)
  59. {
  60. case DRV_LOAD:
  61. dprintf2((TEXT("DRV_LOAD:\n")));
  62. #ifdef _WIN32
  63. if (ghModule) {
  64. // AVI explicitly loads us as well, but does not pass the
  65. // correct (as known by WINMM) driver handle.
  66. } else {
  67. ghModule = (HANDLE) GetDriverModuleHandle(hDriver);
  68. }
  69. #endif
  70. return (LRESULT) 1L;
  71. case DRV_FREE:
  72. dprintf2((TEXT("DRV_FREE:\n")));
  73. return (LRESULT)1L;
  74. case DRV_OPEN:
  75. dprintf2((TEXT("DRV_OPEN\n")));
  76. // if being opened with no open struct, then return a non-zero
  77. // value without actually opening
  78. if (lParam2 == 0L)
  79. return 0xFFFF0000;
  80. return (LRESULT)(DWORD_PTR) Open((ICOPEN FAR *) lParam2);
  81. case DRV_CLOSE:
  82. dprintf2((TEXT("DRV_CLOSE:\n")));
  83. #ifdef _WIN32
  84. if (pi != (PINSTINFO)(ULONG_PTR)0xFFFF0000)
  85. #else
  86. if (pi)
  87. #endif
  88. Close(pi);
  89. return (LRESULT)1L;
  90. /*********************************************************************
  91. state messages
  92. *********************************************************************/
  93. case DRV_QUERYCONFIGURE: // configuration from drivers applet
  94. dprintf2((TEXT("DRV_QUERYCONFIGURE:\n")));
  95. return (LRESULT)0L;
  96. case DRV_CONFIGURE:
  97. dprintf2((TEXT("DRV_CONFIGURE:\n")));
  98. return DRV_OK;
  99. case ICM_CONFIGURE:
  100. dprintf2((TEXT("ICM_CONFIGURE:\n")));
  101. //
  102. // return ICERR_OK if you will do a configure box, error otherwise
  103. //
  104. if (lParam1 == -1)
  105. return QueryConfigure(pi) ? ICERR_OK : ICERR_UNSUPPORTED;
  106. else
  107. return Configure(pi, (HWND)lParam1);
  108. case ICM_ABOUT:
  109. dprintf2((TEXT("ICM_ABOUT:\n")));
  110. //
  111. // return ICERR_OK if you will do a about box, error otherwise
  112. //
  113. if (lParam1 == -1)
  114. return QueryAbout(pi) ? ICERR_OK : ICERR_UNSUPPORTED;
  115. else
  116. return About(pi, (HWND)lParam1);
  117. case ICM_GETSTATE:
  118. dprintf1((TEXT("ICM_GETSTATE:\n")));
  119. return GetState(pi, (LPVOID)lParam1, (DWORD)lParam2);
  120. case ICM_SETSTATE:
  121. dprintf1((TEXT("ICM_SETSTATE:\n")));
  122. return SetState(pi, (LPVOID)lParam1, (DWORD)lParam2);
  123. case ICM_GETINFO:
  124. dprintf1((TEXT("ICM_GETINFO:\n")));
  125. return GetInfo(pi, (ICINFO FAR *)lParam1, (DWORD)lParam2);
  126. case ICM_GETDEFAULTQUALITY:
  127. dprintf2((TEXT("ICM_GETDEFAULTQUALITY:\n")));
  128. if (lParam1) {
  129. *((LPDWORD)lParam1) = 7500;
  130. return ICERR_OK;
  131. }
  132. break;
  133. #if 0
  134. // NOT SUPPORTED
  135. /*********************************************************************
  136. compression messages
  137. *********************************************************************/
  138. case ICM_COMPRESS_QUERY:
  139. dprintf2((TEXT("ICM_COMPRESS_QUERY:\n")));
  140. return CompressQuery(pi,
  141. (LPBITMAPINFOHEADER)lParam1,
  142. (LPBITMAPINFOHEADER)lParam2);
  143. case ICM_COMPRESS_BEGIN:
  144. dprintf2((TEXT("ICM_COMPRESS_BEGIN:\n")));
  145. return CompressBegin(pi,
  146. (LPBITMAPINFOHEADER)lParam1,
  147. (LPBITMAPINFOHEADER)lParam2);
  148. case ICM_COMPRESS_GET_FORMAT:
  149. dprintf2((TEXT("ICM_COMPRESS_GET_FORMAT:\n")));
  150. return CompressGetFormat(pi,
  151. (LPBITMAPINFOHEADER)lParam1,
  152. (LPBITMAPINFOHEADER)lParam2);
  153. case ICM_COMPRESS_GET_SIZE:
  154. dprintf2((TEXT("ICM_COMPRESS_GET_SIZE:\n")));
  155. return CompressGetSize(pi,
  156. (LPBITMAPINFOHEADER)lParam1,
  157. (LPBITMAPINFOHEADER)lParam2);
  158. case ICM_COMPRESS:
  159. dprintf2((TEXT("ICM_COMPRESS:\n")));
  160. return Compress(pi,
  161. (ICCOMPRESS FAR *)lParam1, (DWORD)lParam2);
  162. case ICM_COMPRESS_END:
  163. dprintf2((TEXT("ICM_COMPRESS_END:\n")));
  164. return CompressEnd(pi);
  165. #endif
  166. /*********************************************************************
  167. decompress messages
  168. *********************************************************************/
  169. case ICM_DECOMPRESS_QUERY:
  170. dprintf2((TEXT("\nICM_DECOMPRESS_QUERY:----------------\n")));
  171. return DecompressQuery(pi,
  172. (LPBITMAPINFOHEADER)lParam1,
  173. (LPBITMAPINFOHEADER)lParam2);
  174. case ICM_DECOMPRESS_BEGIN:
  175. dprintf2((TEXT("\nICM_DECOMPRESS_BEGIN:\n")));
  176. return DecompressBegin(pi,
  177. (LPBITMAPINFOHEADER)lParam1,
  178. (LPBITMAPINFOHEADER)lParam2);
  179. case ICM_DECOMPRESS_GET_FORMAT:
  180. dprintf2((TEXT("\nICM_DECOMPRESS_GET_FORMAT:================\n")));
  181. return DecompressGetFormat(pi,
  182. (LPBITMAPINFOHEADER)lParam1,
  183. (LPBITMAPINFOHEADER)lParam2);
  184. case ICM_DECOMPRESS_GET_PALETTE:
  185. dprintf2((TEXT("ICM_DECOMPRESS_GET_PALETTE:\n")));
  186. return DecompressGetPalette(pi,
  187. (LPBITMAPINFOHEADER)lParam1,
  188. (LPBITMAPINFOHEADER)lParam2);
  189. case ICM_DECOMPRESS:
  190. dprintf4((TEXT("ICM_DECOMPRESS:\n")));
  191. return Decompress(pi,
  192. (ICDECOMPRESS FAR *)lParam1, (DWORD)lParam2);
  193. case ICM_DECOMPRESS_END:
  194. dprintf2((TEXT("ICM_DECOMPRESS_END:\n")));
  195. return DecompressEnd(pi);
  196. // *EX
  197. case ICM_DECOMPRESSEX_QUERY:
  198. dprintf2((TEXT("\nICM_DECOMPRESSEX_QUERY:----------------\n")));
  199. return DecompressExQuery(pi, (ICDECOMPRESSEX *) lParam1,(DWORD) lParam2);
  200. case ICM_DECOMPRESSEX:
  201. dprintf4((TEXT("ICM_DECOMPRESSEX:\n")));
  202. return DecompressEx(pi, (ICDECOMPRESSEX *) lParam1, (DWORD) lParam2);
  203. case ICM_DECOMPRESSEX_BEGIN:
  204. dprintf2((TEXT("\nICM_DECOMPRESSEX_BEGIN:\n")));
  205. return DecompressExBegin(pi, (ICDECOMPRESSEX *) lParam1,(DWORD) lParam2);;
  206. case ICM_DECOMPRESSEX_END:
  207. dprintf2((TEXT("\nICM_DECOMPRESSEX_END:\n")));
  208. return DecompressExEnd(pi);;
  209. /*********************************************************************
  210. draw messages:
  211. *********************************************************************/
  212. #ifdef ICM_DRAW_SUPPORTED
  213. case ICM_DRAW_BEGIN:
  214. dprintf2((TEXT("ICM_DRAW_BEGIN:\n")));
  215. /*
  216. * sent when a sequence of draw calls are about to start -
  217. * enable hardware.
  218. */
  219. //return DrawBegin(pi,(ICDRAWBEGIN FAR *)lParam1, (DWORD)lParam2);
  220. return( (DWORD) ICERR_OK);
  221. case ICM_DRAW:
  222. dprintf2((TEXT("ICM_DRAW:\n")));
  223. /*
  224. * frame ready for decompress. Since we don't have any pre-buffering,
  225. * it is ok to render the frame at this time too. If we had
  226. * pre-buffer, we would queue now, and start clocking frames out
  227. * on the draw-start message.
  228. */
  229. return Draw(pi,(ICDRAW FAR *)lParam1, (DWORD)lParam2);
  230. case ICM_DRAW_END:
  231. dprintf2((TEXT("ICM_DRAW_END:\n")));
  232. /*
  233. * this message is sent when the sequence of draw calls has finished -
  234. * note that the final frame should remain rendered!! - so we can't
  235. * disable the hardware yet.
  236. */
  237. //return DrawEnd(pi);
  238. //return((DWORD) ICERR_OK);
  239. case ICM_DRAW_WINDOW:
  240. dprintf2(("ICM_DRAW_WINDOW:\n"));
  241. /*
  242. * the window has changed position or z-ordering. re-sync the
  243. * hardware rendering.
  244. */
  245. return(DrawWindow(pi, (PRECT)lParam1));
  246. case ICM_DRAW_QUERY:
  247. dprintf2((TEXT("ICM_DRAW_QUERY:\n")));
  248. /*
  249. * can we draw this format ? (lParam2 may (should?) be null)
  250. */
  251. return DrawQuery(pi,
  252. (LPBITMAPINFOHEADER)lParam1,
  253. (LPBITMAPINFOHEADER)lParam2);
  254. case ICM_DRAW_START:
  255. case ICM_DRAW_STOP:
  256. dprintf2((TEXT("ICM_DRAW_START/END:\n")));
  257. /*
  258. * only relevant if you have pre-buffering.
  259. */
  260. return( (DWORD) ICERR_OK);
  261. #endif
  262. /*********************************************************************
  263. standard driver messages
  264. *********************************************************************/
  265. case DRV_DISABLE:
  266. case DRV_ENABLE:
  267. dprintf2((TEXT("DRV_DISABLE/ENABLE:\n")));
  268. return (LRESULT)1L;
  269. case DRV_INSTALL:
  270. case DRV_REMOVE:
  271. dprintf2((TEXT("DRV_INSTALL/REMOVE:\n")));
  272. return (LRESULT)DRV_OK;
  273. }
  274. if (uiMessage < DRV_USER) {
  275. return DefDriverProc((UINT_PTR)pi, hDriver, uiMessage,lParam1,lParam2);
  276. } else {
  277. dprintf1((TEXT("DriverProc: ICM message ID (ICM_USER+%d) not supported.\n"), uiMessage-ICM_USER));
  278. return ICERR_UNSUPPORTED;
  279. }
  280. }
  281. #ifdef _WIN32
  282. #if 0 // done on DRV_LOAD
  283. BOOL DllInstanceInit(PVOID hModule, ULONG Reason, PCONTEXT pContext)
  284. {
  285. if (Reason == DLL_PROCESS_ATTACH) {
  286. ghModule = (HANDLE) hModule;
  287. DisableThreadLibraryCalls(hModule);
  288. }
  289. return TRUE;
  290. }
  291. #endif
  292. #endif
  293. // #else
  294. /****************************************************************************
  295. * LibMain - Library initialization code.
  296. *
  297. * PARAMETERS
  298. * hModule: Our module handle.
  299. *
  300. * wHeapSize: The heap size from the .def file.
  301. *
  302. * lpCmdLine: The command line.
  303. *
  304. * Returns 1 if the initialization was successful and 0 otherwise.
  305. ***************************************************************************/
  306. //int NEAR PASCAL LibMain(HMODULE hModule, WORD wHeapSize, LPSTR lpCmdLine)
  307. BOOL FAR PASCAL LibMain(HMODULE hModule, WORD wHeapSize, LPSTR lpCmdLine)
  308. {
  309. ghModule = hModule;
  310. return 1;
  311. }
  312. // #endif