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.

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