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.

613 lines
16 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: MISC.CXX *
  3. * *
  4. * _HYDRA_ routines *
  5. * *
  6. * Copyright (c) 1997-1999 Microsoft *
  7. \**************************************************************************/
  8. #include "precomp.hxx"
  9. #pragma hdrstop
  10. BOOL G_fDoubleDpi = FALSE;
  11. BOOL G_fConsole = TRUE;
  12. PFILE_OBJECT G_RemoteVideoFileObject = NULL;
  13. PFILE_OBJECT G_RemoteConnectionFileObject = NULL;
  14. HANDLE G_RemoteConnectionChannel = NULL;
  15. PBYTE G_PerformanceStatistics = NULL;
  16. LPWSTR G_DisplayDriverNames = L"vgastub\0";
  17. PFILE_OBJECT G_SaveRemoteVideoFileObject = NULL;
  18. PFILE_OBJECT G_SaveRemoteConnectionFileObject = NULL;
  19. HANDLE G_SaveRemoteConnectionChannel = NULL;
  20. PBYTE G_SavePerformanceStatistics = NULL;
  21. /******************************Exported*Routine****************************\
  22. *
  23. * GreConsoleShadowStart( )
  24. *
  25. *
  26. * Saves remote channel handles and swicth to channel handles for Console Shadow
  27. *
  28. \**************************************************************************/
  29. BOOL GreConsoleShadowStart( HANDLE hRemoteConnectionChannel,
  30. PBYTE pPerformanceStatistics,
  31. PFILE_OBJECT pVideoFile,
  32. PFILE_OBJECT pRemoteConnectionFileObject
  33. )
  34. {
  35. G_SaveRemoteVideoFileObject = G_RemoteVideoFileObject;
  36. G_SaveRemoteConnectionFileObject = G_RemoteConnectionFileObject;
  37. G_SavePerformanceStatistics = G_PerformanceStatistics;
  38. G_SaveRemoteConnectionChannel = G_RemoteConnectionChannel;
  39. G_RemoteVideoFileObject = pVideoFile;
  40. G_RemoteConnectionFileObject = pRemoteConnectionFileObject;
  41. G_PerformanceStatistics = pPerformanceStatistics;
  42. G_RemoteConnectionChannel = hRemoteConnectionChannel;
  43. return TRUE;
  44. }
  45. /******************************Exported*Routine****************************\
  46. *
  47. * GreConsoleShadowStop( )
  48. *
  49. *
  50. * Restores remote channel handles after Console Shadow
  51. *
  52. \**************************************************************************/
  53. BOOL GreConsoleShadowStop( VOID )
  54. {
  55. G_RemoteVideoFileObject = G_SaveRemoteVideoFileObject;
  56. G_RemoteConnectionFileObject = G_SaveRemoteConnectionFileObject;
  57. G_PerformanceStatistics = G_SavePerformanceStatistics;
  58. G_RemoteConnectionChannel = G_SaveRemoteConnectionChannel;
  59. return TRUE;
  60. }
  61. /******************************Exported*Routine****************************\
  62. *
  63. * GreMultiUserInitSession( )
  64. *
  65. *
  66. * Initialize the multi-user session gre library
  67. *
  68. \**************************************************************************/
  69. BOOL GreMultiUserInitSession( HANDLE hRemoteConnectionChannel,
  70. PBYTE pPerformanceStatistics,
  71. PFILE_OBJECT pVideoFile,
  72. PFILE_OBJECT pRemoteConnectionFileObject,
  73. ULONG DisplayDriverNameLength,
  74. PWCHAR DisplayDriverName
  75. )
  76. {
  77. BOOL bRet = FALSE;
  78. G_RemoteVideoFileObject = pVideoFile;
  79. G_RemoteConnectionFileObject = pRemoteConnectionFileObject;
  80. G_PerformanceStatistics = pPerformanceStatistics;
  81. G_RemoteConnectionChannel = hRemoteConnectionChannel;
  82. G_DisplayDriverNames = (LPWSTR)GdiAllocPool(
  83. (DisplayDriverNameLength + 1) * sizeof(WCHAR),
  84. 'yssU');
  85. if (G_DisplayDriverNames)
  86. {
  87. wcsncpy(G_DisplayDriverNames, DisplayDriverName, DisplayDriverNameLength + 1);
  88. bRet = TRUE;
  89. }
  90. return bRet;
  91. }
  92. /******************************Exported*Routine****************************\
  93. * HDXDrvEscape( hdev, iEsc, pInbuffer, cbInbuffer )
  94. *
  95. * Tell the TShare display driver to perform the specified operation.
  96. *
  97. * hdev (input)
  98. * Identifies the device
  99. *
  100. * iEsc (input)
  101. * Specifies the Operation to be performed
  102. *
  103. * ESC_FLUSH_FRAME_BUFFER Flush the frame buffer
  104. * ESC_SET_WD_TIMEROBJ Pass the timer object to the WD
  105. *
  106. * pInbuffer (input)
  107. * Data buffer
  108. *
  109. * cbInbuffer (input)
  110. * Data buffer length
  111. *
  112. \**************************************************************************/
  113. BOOL HDXDrvEscape( HDEV hdev, ULONG iEsc, PVOID pInbuffer, ULONG cbInbuffer )
  114. {
  115. BOOL Result;
  116. PDEVOBJ po(hdev);
  117. if (!po.bValid())
  118. return(FALSE);;
  119. //
  120. // If this is not a DISPLAY, return error
  121. //
  122. if (!po.bDisplayPDEV())
  123. return(FALSE);;
  124. //
  125. // Wait for the display to become available and lock it.
  126. //
  127. GreAcquireSemaphoreEx(po.hsemDevLock(), SEMORDER_DEVLOCK, NULL);
  128. {
  129. SEMOBJ so(po.hsemPointer());
  130. //
  131. // The device may have something going on, synchronize with it first
  132. //
  133. po.vSync(po.pSurface()->pSurfobj(),NULL,0);
  134. //
  135. // Call the driver to perform the specified operation
  136. //
  137. if ( PPFNVALID(po,Escape) )
  138. Result = (*PPFNDRV(po,Escape))(&po.pSurface()->so, iEsc, cbInbuffer, pInbuffer, 0, NULL );
  139. else
  140. Result = TRUE;
  141. }
  142. GreReleaseSemaphoreEx(po.hsemDevLock());
  143. return(Result);
  144. }
  145. /******************************Exported*Routine****************************\
  146. *
  147. * bDrvReconnect( hDev, RemoteConnectionChannel )
  148. *
  149. * This is done for reconnects.
  150. *
  151. * Notify the display driver of a new connection (not a shadow connection)
  152. *
  153. * hdev (input)
  154. * Identifies device to be connected
  155. * RemoteConnectionChannel (input)
  156. * Remote channel handle
  157. * pRemoteConnectionFileObject (input)
  158. * Remote connection channel file object
  159. *
  160. \**************************************************************************/
  161. BOOL bDrvReconnect( HDEV hdev,
  162. HANDLE RemoteConnectionChannel,
  163. PFILE_OBJECT pRemoteConnectionFileObject,
  164. BOOL bSetPalette )
  165. {
  166. BOOL Result;
  167. PDEVOBJ po(hdev);
  168. if (!po.bValid())
  169. return(FALSE);
  170. //
  171. // If this is not a DISPLAY, return error
  172. //
  173. if (!po.bDisplayPDEV())
  174. return(FALSE);
  175. //
  176. // Wait for the display to become available and lock it.
  177. //
  178. GreAcquireSemaphoreEx(po.hsemDevLock(), SEMORDER_DEVLOCK, NULL);
  179. {
  180. SEMOBJ so(po.hsemPointer());
  181. //
  182. // The device may have something going on, synchronize with it first
  183. //
  184. po.vSync(po.pSurface()->pSurfobj(),NULL,0);
  185. //
  186. // Call the driver connect function (if defined)
  187. //
  188. if ( PPFNVALID(po,Reconnect) )
  189. Result = (*PPFNDRV(po,Reconnect))( RemoteConnectionChannel, pRemoteConnectionFileObject );
  190. else
  191. Result = TRUE;
  192. if ( bSetPalette == TRUE ) {
  193. //
  194. // Set the palette
  195. //
  196. XEPALOBJ pal(po.ppalSurf());
  197. ASSERTGDI(pal.bValid(), "EPALOBJ failure\n");
  198. if ((Result == TRUE) && pal.bIsPalManaged())
  199. {
  200. ASSERTGDI(PPFNVALID(po,SetPalette), "ERROR palette is not managed");
  201. (*PPFNDRV(po,SetPalette))(po.dhpdev(),
  202. (PALOBJ *) &pal,
  203. 0,
  204. 0,
  205. pal.cEntries());
  206. }
  207. }
  208. }
  209. GreReleaseSemaphoreEx(po.hsemDevLock());
  210. return( Result );
  211. }
  212. /******************************Exported*Routine****************************\
  213. * bDrvDisconnect(hdev)
  214. *
  215. * Notify the display driver that the connection is going away.
  216. * This is the primary connection.
  217. *
  218. * hdev (input)
  219. * Identifies device to be disabled
  220. *
  221. * RemoteConnectionChannel (input)
  222. * Channel being disconnected
  223. *
  224. * pRemoteConnectionFileObject (input)
  225. * File object pointer to Channel being disconnected
  226. *
  227. \**************************************************************************/
  228. BOOL bDrvDisconnect( HDEV hdev, HANDLE RemoteConnectionChannel, PFILE_OBJECT pRemoteConnectionFileObject )
  229. {
  230. BOOL Result;
  231. PDEVOBJ po(hdev);
  232. if (!po.bValid())
  233. return(FALSE);
  234. //
  235. // If this is not a DISPLAY, return error
  236. //
  237. if (!po.bDisplayPDEV())
  238. return(FALSE);
  239. //
  240. // Wait for the display to become available and lock it.
  241. //
  242. GreAcquireSemaphoreEx(po.hsemDevLock(), SEMORDER_DEVLOCK, NULL);
  243. {
  244. SEMOBJ so(po.hsemPointer());
  245. //
  246. // The device may have something going on, synchronize with it first
  247. //
  248. po.vSync(po.pSurface()->pSurfobj(),NULL,0);
  249. //
  250. // Call the driver disconnect function (if defined)
  251. //
  252. if ( PPFNVALID(po,Disconnect) )
  253. Result = (*PPFNDRV(po,Disconnect))( RemoteConnectionChannel, pRemoteConnectionFileObject );
  254. else
  255. Result = TRUE;
  256. }
  257. GreReleaseSemaphoreEx(po.hsemDevLock());
  258. return( Result );
  259. }
  260. /******************************Exported*Routine****************************\
  261. *
  262. * bDrvShadowConnect( hDev, RemoteConnectionChannel, pRemoteConnectionFileObject )
  263. *
  264. * This is done for new shadow connections.
  265. *
  266. * hdev (input)
  267. * Identifies device to be connected
  268. * RemoteConnectionChannel ( input )
  269. * Remote connection channel of shadow (for modes)
  270. * pRemoteConnectionFileObject ( input )
  271. * Remote Connection file object pointer of shadow (for modes)
  272. *
  273. \**************************************************************************/
  274. BOOL bDrvShadowConnect( HDEV hdev, PVOID pRemoteConnectionData, ULONG RemoteConnectionDataLength )
  275. {
  276. BOOL Result;
  277. PDEVOBJ po(hdev);
  278. if (!po.bValid())
  279. return(FALSE);
  280. //
  281. // If this is not a DISPLAY, return error
  282. //
  283. if (!po.bDisplayPDEV())
  284. return(FALSE);
  285. //
  286. // Wait for the display to become available and lock it.
  287. //
  288. GreAcquireSemaphoreEx(po.hsemDevLock(), SEMORDER_DEVLOCK, NULL);
  289. {
  290. SEMOBJ so(po.hsemPointer());
  291. //
  292. // The device may have something going on, synchronize with it first
  293. //
  294. po.vSync(po.pSurface()->pSurfobj(),NULL,0);
  295. //
  296. // Call the driver connect function (if defined)
  297. //
  298. if ( PPFNVALID(po,ShadowConnect) )
  299. Result = (*PPFNDRV(po,ShadowConnect))( pRemoteConnectionData, RemoteConnectionDataLength );
  300. else
  301. Result = TRUE;
  302. //
  303. // Set the palette
  304. //
  305. XEPALOBJ pal(po.ppalSurf());
  306. ASSERTGDI(pal.bValid(), "EPALOBJ failure\n");
  307. if ((Result == TRUE) && pal.bIsPalManaged())
  308. {
  309. ASSERTGDI(PPFNVALID(po,SetPalette), "ERROR palette is not managed");
  310. (*PPFNDRV(po,SetPalette))(po.dhpdev(),
  311. (PALOBJ *) &pal,
  312. 0,
  313. 0,
  314. pal.cEntries());
  315. }
  316. }
  317. GreReleaseSemaphoreEx(po.hsemDevLock());
  318. return( Result );
  319. }
  320. /******************************Exported*Routine****************************\
  321. * bDrvShadowDisconnect(hdev, RemoteConnectionChannel, pRemoteConnectionFileObject)
  322. *
  323. * Notify the display driver that the shadow connection is going away.
  324. *
  325. * hdev (input)
  326. * Identifies device to be disabled
  327. *
  328. * RemoteConnectionChannel (input)
  329. * Shadow Channel being disconnected
  330. * pRemoteConnectionFileObject (input)
  331. * Shadow Channel being disconnected
  332. *
  333. \**************************************************************************/
  334. BOOL bDrvShadowDisconnect( HDEV hdev, PVOID pRemoteConnectionData, ULONG RemoteConnectionDataLength )
  335. {
  336. BOOL Result;
  337. PDEVOBJ po(hdev);
  338. if (!po.bValid())
  339. return(FALSE);
  340. //
  341. // If this is not a DISPLAY, return error
  342. //
  343. if (!po.bDisplayPDEV())
  344. return(FALSE);
  345. //
  346. // Wait for the display to become available and lock it.
  347. //
  348. GreAcquireSemaphoreEx(po.hsemDevLock(), SEMORDER_DEVLOCK, NULL);
  349. {
  350. SEMOBJ so(po.hsemPointer());
  351. //
  352. // The device may have something going on, synchronize with it first
  353. //
  354. po.vSync(po.pSurface()->pSurfobj(),NULL,0);
  355. //
  356. // Call the driver disconnect function (if defined)
  357. //
  358. if ( PPFNVALID(po,ShadowDisconnect) )
  359. Result = (*PPFNDRV(po,ShadowDisconnect))( pRemoteConnectionData, RemoteConnectionDataLength );
  360. else
  361. Result = TRUE;
  362. //
  363. // Reset the palette
  364. //
  365. XEPALOBJ pal(po.ppalSurf());
  366. ASSERTGDI(pal.bValid(), "EPALOBJ failure\n");
  367. if ((Result == TRUE) && pal.bIsPalManaged())
  368. {
  369. ASSERTGDI(PPFNVALID(po,SetPalette), "ERROR palette is not managed");
  370. (*PPFNDRV(po,SetPalette))(po.dhpdev(),
  371. (PALOBJ *) &pal,
  372. 0,
  373. 0,
  374. pal.cEntries());
  375. }
  376. }
  377. GreReleaseSemaphoreEx(po.hsemDevLock());
  378. return( Result );
  379. }
  380. /******************************Exported*Routine****************************\
  381. * vDrvInvalidateRect( hdev, prcl )
  382. *
  383. * Tell the display driver to invalidate the specified rect.
  384. *
  385. * hdev (input)
  386. * Identifies the device
  387. *
  388. * prcl (input)
  389. * Identifies the rectangle to invalidate
  390. *
  391. \**************************************************************************/
  392. VOID vDrvInvalidateRect( HDEV hdev, PRECT prcl )
  393. {
  394. GDIFunctionID(vDrvInvalidateRect);
  395. PDEVOBJ po(hdev);
  396. if (!po.bValid())
  397. return;
  398. //
  399. // If this is not a DISPLAY, return error
  400. //
  401. if (!po.bDisplayPDEV())
  402. return;
  403. //
  404. // Wait for the display to become available and lock it.
  405. //
  406. GreAcquireSemaphoreEx(po.hsemDevLock(), SEMORDER_DEVLOCK, NULL);
  407. GreEnterMonitoredSection(po.ppdev, WD_DEVLOCK);
  408. {
  409. SEMOBJ so(po.hsemPointer());
  410. //
  411. // The device may have something going on, synchronize with it first
  412. //
  413. po.vSync(po.pSurface()->pSurfobj(),NULL,0);
  414. //
  415. // Call the driver invalidate rect function (if defined)
  416. //
  417. if ( PPFNVALID(po,InvalidateRect) )
  418. (*PPFNDRV(po,InvalidateRect))( prcl );
  419. }
  420. GreExitMonitoredSection(po.ppdev, WD_DEVLOCK);
  421. GreReleaseSemaphore(po.hsemDevLock());
  422. }
  423. /******************************Exported*Routine****************************\
  424. * vDrvDispalyIOCtl( hdev, pbuffer, cbbuffer )
  425. *
  426. * Tell the display driver to invalidate the specified rect.
  427. *
  428. * hdev (input)
  429. * Identifies the device
  430. *
  431. * pbuffer (input)
  432. * IOCtl data buffer
  433. *
  434. * cbbuffer (input)
  435. * IOCtl data buffer length
  436. *
  437. \**************************************************************************/
  438. BOOL bDrvDisplayIOCtl( HDEV hdev, PVOID pbuffer, ULONG cbbuffer )
  439. {
  440. BOOL Result;
  441. PDEVOBJ po(hdev);
  442. if (!po.bValid())
  443. return(FALSE);;
  444. //
  445. // If this is not a DISPLAY, return error
  446. //
  447. if (!po.bDisplayPDEV())
  448. return(FALSE);;
  449. //
  450. // Wait for the display to become available and lock it.
  451. //
  452. GreAcquireSemaphoreEx(po.hsemDevLock(), SEMORDER_DEVLOCK, NULL);
  453. GreEnterMonitoredSection(po.ppdev, WD_DEVLOCK);
  454. {
  455. SEMOBJ so(po.hsemPointer());
  456. //
  457. // The device may have something going on, synchronize with it first
  458. //
  459. po.vSync(po.pSurface()->pSurfobj(),NULL,0);
  460. //
  461. // Call the driver invalidate rect function (if defined)
  462. //
  463. if ( PPFNVALID(po,DisplayIOCtl) )
  464. Result = (*PPFNDRV(po,DisplayIOCtl))( pbuffer, cbbuffer );
  465. else
  466. Result = TRUE;
  467. }
  468. GreExitMonitoredSection(po.ppdev, WD_DEVLOCK);
  469. GreReleaseSemaphoreEx(po.hsemDevLock());
  470. return(Result);
  471. }