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.

522 lines
14 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1995 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: ddhal.c
  6. * Content: 16-bit DirectDraw HAL
  7. * These routines redirect the callbacks from the 32-bit
  8. * side to the driver
  9. * History:
  10. * Date By Reason
  11. * ==== == ======
  12. * 20-jan-95 craige initial implementation
  13. * 03-feb-95 craige performance tuning, ongoing work
  14. * 03-mar-95 craige added WaitForVerticalBlank
  15. * 11-mar-95 craige palette stuff
  16. * 16-mar-95 craige added DD16_SelectPalette
  17. * 24-mar-95 craige added DD16_GetTimeSel
  18. * 04-apr-95 craige call display driver for get/set palette
  19. * 14-may-95 craige added DD16_EnableReboot; cleaned up obsolete junk
  20. * 23-may-95 craige removed DD16_GetTimeSel; cleaned up more obsolete junk
  21. * 28-may-95 craige cleaned up HAL: added DDThunk16_GetBltStatus;
  22. * DDThunk16_GetFlipStatus; DDThunk16_GetScanLine
  23. * 13-jul-95 toddla remove _export from thunk functions
  24. * 13-apr-96 colinmc Bug 17736: No driver notification of flip to GDI
  25. * 01-oct-96 ketand added GetAvailDriverMemory
  26. * 21-jan-97 ketand Fix SetEntries for multimon.
  27. * 27-jan-97 ketand Remove unused DD16_GetPaletteEntries; it didn't work for multi-mon
  28. * and wasn't worth fixing.
  29. * 03-feb-97 ketand Fix DC leak w.r.t. MakeObjectPrivate.
  30. *
  31. ***************************************************************************/
  32. #include "ddraw16.h"
  33. #define DPF_MODNAME "DDRAW16"
  34. /****************************************************************************
  35. *
  36. * DRIVER CALLBACK HELPER FNS
  37. *
  38. ***************************************************************************/
  39. /*
  40. * DDThunk16_CreatePalette
  41. */
  42. DWORD DDAPI DDThunk16_CreatePalette( LPDDHAL_CREATEPALETTEDATA lpCreatePaletteData )
  43. {
  44. return lpCreatePaletteData->CreatePalette( lpCreatePaletteData );
  45. } /* DDThunk16_CreateSurface */
  46. /*
  47. * DDThunk16_CreateSurface
  48. */
  49. DWORD DDAPI DDThunk16_CreateSurface( LPDDHAL_CREATESURFACEDATA lpCreateSurfaceData )
  50. {
  51. return lpCreateSurfaceData->CreateSurface( lpCreateSurfaceData );
  52. } /* DDThunk16_CreateSurface */
  53. /*
  54. * DDThunk16_CanCreateSurface
  55. */
  56. DWORD DDAPI DDThunk16_CanCreateSurface( LPDDHAL_CANCREATESURFACEDATA lpCanCreateSurfaceData )
  57. {
  58. return lpCanCreateSurfaceData->CanCreateSurface( lpCanCreateSurfaceData );
  59. } /* DDThunk16_CanCreateSurface */
  60. /*
  61. * DDThunk16_WaitForVerticalBlank
  62. */
  63. DWORD DDAPI DDThunk16_WaitForVerticalBlank( LPDDHAL_WAITFORVERTICALBLANKDATA lpWaitForVerticalBlankData )
  64. {
  65. return lpWaitForVerticalBlankData->WaitForVerticalBlank( lpWaitForVerticalBlankData );
  66. } /* DDThunk16_WaitForVerticalBlank */
  67. /*
  68. * DDThunk16_DestroyDriver
  69. */
  70. DWORD DDAPI DDThunk16_DestroyDriver( LPDDHAL_DESTROYDRIVERDATA lpDestroyDriverData )
  71. {
  72. return lpDestroyDriverData->DestroyDriver( lpDestroyDriverData );
  73. } /* DDThunk16_DestroyDriver */
  74. /*
  75. * DDThunk16_SetMode
  76. */
  77. DWORD DDAPI DDThunk16_SetMode( LPDDHAL_SETMODEDATA lpSetModeData )
  78. {
  79. return lpSetModeData->SetMode( lpSetModeData );
  80. } /* DDThunk16_SetMode */
  81. /*
  82. * DDThunk16_GetScanLine
  83. */
  84. DWORD DDAPI DDThunk16_GetScanLine( LPDDHAL_GETSCANLINEDATA lpGetScanLineData )
  85. {
  86. return lpGetScanLineData->GetScanLine( lpGetScanLineData );
  87. } /* DDThunk16_GetScanLine */
  88. /*
  89. * DDThunk16_SetExclusiveMode
  90. */
  91. DWORD DDAPI DDThunk16_SetExclusiveMode( LPDDHAL_SETEXCLUSIVEMODEDATA lpSetExclusiveModeData )
  92. {
  93. return lpSetExclusiveModeData->SetExclusiveMode( lpSetExclusiveModeData );
  94. } /* DDThunk16_SetExclusiveMode */
  95. /*
  96. * DDThunk16_FlipToGDISurface
  97. */
  98. DWORD DDAPI DDThunk16_FlipToGDISurface( LPDDHAL_FLIPTOGDISURFACEDATA lpFlipToGDISurfaceData )
  99. {
  100. return lpFlipToGDISurfaceData->FlipToGDISurface( lpFlipToGDISurfaceData );
  101. } /* DDThunk16_FlipToGDISurface */
  102. /*
  103. * DDThunk16_GetAvailDriverMemory
  104. */
  105. DWORD DDAPI DDThunk16_GetAvailDriverMemory( LPDDHAL_GETAVAILDRIVERMEMORYDATA lpGetAvailDriverMemoryData )
  106. {
  107. return lpGetAvailDriverMemoryData->GetAvailDriverMemory( lpGetAvailDriverMemoryData );
  108. } /* DDThunk16_GetAvailDriverMemory */
  109. /*
  110. * DDThunk16_UpdateNonLocalHeap
  111. */
  112. DWORD DDAPI DDThunk16_UpdateNonLocalHeap( LPDDHAL_UPDATENONLOCALHEAPDATA lpUpdateNonLocalHeapData )
  113. {
  114. return lpUpdateNonLocalHeapData->UpdateNonLocalHeap( lpUpdateNonLocalHeapData );
  115. } /* DDThunk16_UpdateNonLocalHeap */
  116. /****************************************************************************
  117. *
  118. * SURFACE CALLBACK HELPER FNS
  119. *
  120. ***************************************************************************/
  121. /*
  122. * DDThunk16_DestroySurface
  123. */
  124. DWORD DDAPI DDThunk16_DestroySurface( LPDDHAL_DESTROYSURFACEDATA lpDestroySurfaceData )
  125. {
  126. return lpDestroySurfaceData->DestroySurface( lpDestroySurfaceData );
  127. } /* DDThunk16_DestroySurface */
  128. /*
  129. * DDThunk16_Flip
  130. */
  131. DWORD DDAPI DDThunk16_Flip( LPDDHAL_FLIPDATA lpFlipData )
  132. {
  133. return lpFlipData->Flip( lpFlipData );
  134. } /* DDThunk16_Flip */
  135. /*
  136. * DDThunk16_Blt
  137. */
  138. DWORD DDAPI DDThunk16_Blt( LPDDHAL_BLTDATA lpBltData )
  139. {
  140. return lpBltData->Blt( lpBltData );
  141. } /* DDThunk16_Blt */
  142. /*
  143. * DDThunk16_Lock
  144. */
  145. DWORD DDAPI DDThunk16_Lock( LPDDHAL_LOCKDATA lpLockData )
  146. {
  147. return lpLockData->Lock( lpLockData );
  148. } /* DDThunk16_Lock */
  149. /*
  150. * DDThunk16_Unlock
  151. */
  152. DWORD DDAPI DDThunk16_Unlock( LPDDHAL_UNLOCKDATA lpUnlockData )
  153. {
  154. return lpUnlockData->Unlock( lpUnlockData );
  155. } /* DDThunk16_Unlock */
  156. /*
  157. * DDThunk16_AddAttachedSurface
  158. */
  159. DWORD DDAPI DDThunk16_AddAttachedSurface( LPDDHAL_ADDATTACHEDSURFACEDATA lpAddAttachedSurfaceData )
  160. {
  161. return lpAddAttachedSurfaceData->AddAttachedSurface( lpAddAttachedSurfaceData );
  162. } /* DDThunk16_AddAttachedSurface */
  163. /*
  164. * DDThunk16_SetColorKey
  165. */
  166. DWORD DDAPI DDThunk16_SetColorKey( LPDDHAL_SETCOLORKEYDATA lpSetColorKeyData )
  167. {
  168. return lpSetColorKeyData->SetColorKey( lpSetColorKeyData );
  169. } /* DDThunk16_SetColorKey */
  170. /*
  171. * DDThunk16_SetClipList
  172. */
  173. DWORD DDAPI DDThunk16_SetClipList( LPDDHAL_SETCLIPLISTDATA lpSetClipListData )
  174. {
  175. return lpSetClipListData->SetClipList( lpSetClipListData );
  176. } /* DDThunk16_ClipList */
  177. /*
  178. * DDThunk16_UpdateOverlay
  179. */
  180. DWORD DDAPI DDThunk16_UpdateOverlay( LPDDHAL_UPDATEOVERLAYDATA lpUpdateOverlayData )
  181. {
  182. return lpUpdateOverlayData->UpdateOverlay( lpUpdateOverlayData );
  183. } /* DDThunk16_UpdateOverlay */
  184. /*
  185. * DDThunk16_SetOverlayPosition
  186. */
  187. DWORD DDAPI DDThunk16_SetOverlayPosition( LPDDHAL_SETOVERLAYPOSITIONDATA lpSetOverlayPositionData )
  188. {
  189. return lpSetOverlayPositionData->SetOverlayPosition( lpSetOverlayPositionData );
  190. } /* DDThunk16_SetOverlayPosition */
  191. /*
  192. * DDThunk16_SetPalette
  193. */
  194. DWORD DDAPI DDThunk16_SetPalette( LPDDHAL_SETPALETTEDATA lpSetPaletteData )
  195. {
  196. return lpSetPaletteData->SetPalette( lpSetPaletteData );
  197. } /* DDThunk16_SetPalette */
  198. /*
  199. * DDThunk16_GetBltStatus
  200. */
  201. DWORD DDAPI DDThunk16_GetBltStatus( LPDDHAL_GETBLTSTATUSDATA lpGetBltStatusData )
  202. {
  203. return lpGetBltStatusData->GetBltStatus( lpGetBltStatusData );
  204. } /* DDThunk16_GetBltStatus */
  205. /*
  206. * DDThunk16_GetFlipStatus
  207. */
  208. DWORD DDAPI DDThunk16_GetFlipStatus( LPDDHAL_GETFLIPSTATUSDATA lpGetFlipStatusData )
  209. {
  210. return lpGetFlipStatusData->GetFlipStatus( lpGetFlipStatusData );
  211. } /* DDThunk16_GetFlipStatus */
  212. /****************************************************************************
  213. *
  214. * PALETTE CALLBACK HELPER FNS
  215. *
  216. ***************************************************************************/
  217. /*
  218. * DDThunk16_DestroyPalette
  219. */
  220. DWORD DDAPI DDThunk16_DestroyPalette( LPDDHAL_DESTROYPALETTEDATA lpDestroyPaletteData )
  221. {
  222. return lpDestroyPaletteData->DestroyPalette( lpDestroyPaletteData );
  223. } /* DDThunk16_CreateSurface */
  224. /*
  225. * DDThunk16_SetEntries
  226. */
  227. DWORD DDAPI DDThunk16_SetEntries( LPDDHAL_SETENTRIESDATA lpSetEntriesData )
  228. {
  229. return lpSetEntriesData->SetEntries( lpSetEntriesData );
  230. } /* DDThunk16_CreateSurface */
  231. /****************************************************************************
  232. *
  233. * PRIVATE HELPER FNS TO CALL PRIVATE 16-BIT SERVICES
  234. *
  235. ***************************************************************************/
  236. /*
  237. * DD16_SelectPalette
  238. */
  239. void DDAPI DD16_SelectPalette( HDC hdc, HPALETTE hpal, BOOL f )
  240. {
  241. extern HANDLE FAR PASCAL GDISelectPalette(HDC,HANDLE,BOOL);
  242. extern DWORD FAR PASCAL GDIRealizePalette(HDC);
  243. GDISelectPalette( hdc, hpal, f );
  244. GDIRealizePalette( hdc );
  245. } /* DD16_SelectPalette */
  246. BOOL (FAR PASCAL *OEMSetPalette)( WORD wStartIndex, WORD wNumEntries, LPPALETTEENTRY lpPalette );
  247. // Special hooks so we can do the right thing on Multi-mon systems
  248. // And also so we can get the PDevice from the Dc.
  249. #define SD_GETPDEV 0x000F // this constant lives in testing.h!
  250. extern DWORD PASCAL GDISeeGDIDo(WORD wMsg, WORD wParam, LONG lParam);
  251. #define GethModuleFromDC(hdc) (HMODULE)HIWORD(GDISeeGDIDo(SD_GETPDEV, (WORD)hdc, 0))
  252. #define GetPDeviceFromDC(hdc) (UINT)LOWORD(GDISeeGDIDo(SD_GETPDEV, (WORD)hdc, 0))
  253. /*
  254. * DD16_SetPaletteEntries
  255. */
  256. BOOL DDAPI DD16_SetPaletteEntries(
  257. HDC hdc,
  258. DWORD dwBase,
  259. DWORD dwNumEntries,
  260. LPPALETTEENTRY lpColorTable,
  261. BOOL fPrimary )
  262. {
  263. HMODULE hmod;
  264. #ifdef DEBUG
  265. UINT rc;
  266. rc = GetDeviceCaps( hdc, RASTERCAPS );
  267. if( !(rc & RC_PALETTE) )
  268. {
  269. DPF_ERR( "DD16_SetPaletteEntries: not a paletized mode" );
  270. _asm int 3
  271. return FALSE;
  272. }
  273. if( lpColorTable == NULL )
  274. {
  275. DPF_ERR( "DD16_SetPaletteEntries: lpColorTable == NULL" );
  276. _asm int 3
  277. return FALSE;
  278. }
  279. if( dwBase >= 256 || dwBase + dwNumEntries > 256 || dwNumEntries == 0 )
  280. {
  281. DPF_ERR( "DD16_SetPaletteEntries: bad params passed" );
  282. _asm int 3
  283. return FALSE;
  284. }
  285. #endif
  286. if( fPrimary )
  287. {
  288. DWORD pDevice = 0;
  289. if( OEMSetPalette == NULL )
  290. {
  291. hmod = GetModuleHandle( "DISPLAY" );
  292. if( hmod == NULL )
  293. {
  294. return FALSE;
  295. }
  296. OEMSetPalette = (LPVOID) GetProcAddress( hmod, MAKEINTATOM(22) );
  297. if( OEMSetPalette == NULL )
  298. {
  299. return FALSE;
  300. }
  301. }
  302. // WARNING: Don't change anything from here to the end of the function without
  303. // checking the assembly!
  304. // ToddLa says that we need to put the pdevice into EDX before
  305. // making this call. It will matter for advanced video hardware
  306. // that supports multiple different external ports.
  307. pDevice = (DWORD) GetPDevice(hdc);
  308. _asm
  309. {
  310. ;; The following line of code is actually
  311. ;; mov edx, dword ptr pDevice
  312. ;; The 16-bit compiler we have can't deal with such complexities
  313. _emit 66h _asm mov dx, word ptr pDevice ;edx = pDevice
  314. }
  315. return OEMSetPalette( (WORD) dwBase, (WORD) dwNumEntries, lpColorTable );
  316. }
  317. else
  318. {
  319. BOOL (FAR PASCAL *OEMSetPaletteTmp)( WORD wStartIndex, WORD wNumEntries, LPPALETTEENTRY lpPalette );
  320. DWORD pDevice = 0;
  321. DWORD dwGDI;
  322. BOOL wasPrivate;
  323. extern BOOL WINAPI MakeObjectPrivate(HANDLE hObj, BOOL bPrivate);
  324. // Not the primary? Then we need to get the module handle
  325. // by asking GDI. (This doesn't work in Win95 however, so this should
  326. // only be happening on Multi-mon systems.)
  327. DPF( 4, "About to set the palette for non-primary device." );
  328. wasPrivate = MakeObjectPrivate( hdc, TRUE );
  329. dwGDI = GDISeeGDIDo(SD_GETPDEV, (WORD)hdc, 0);
  330. MakeObjectPrivate( hdc, wasPrivate );
  331. if( dwGDI == -1 )
  332. {
  333. DPF_ERR( "GDIGetModuleHandle failed!. Couldn't set palette" );
  334. return FALSE;
  335. }
  336. hmod = (HMODULE)HIWORD(dwGDI);
  337. // Got the module?
  338. if( hmod == NULL )
  339. {
  340. DPF_ERR( "GDIGetModuleHandle failed!. Couldn't set palette" );
  341. return FALSE;
  342. }
  343. // Now go get the entrypoint:
  344. OEMSetPaletteTmp = (LPVOID) GetProcAddress( hmod, MAKEINTATOM(22) );
  345. if( OEMSetPaletteTmp == NULL )
  346. {
  347. DPF_ERR( "GetProcAddress failed!. Couldn't set palette" );
  348. return FALSE;
  349. }
  350. // WARNING: Don't change anything from here to the end of the function without
  351. // checking the assembly!
  352. // ToddLa says that we need to put the pdevice into EDX before
  353. // making this call. It will matter for advanced video hardware
  354. // that supports multiple different external ports.
  355. pDevice = (DWORD)(UINT)LOWORD(dwGDI) << 16;
  356. _asm
  357. {
  358. ;; The following line of code is actually
  359. ;; mov edx, dword ptr pDevice
  360. ;; The 16-bit compiler we have can't deal with such complexities
  361. _emit 66h _asm mov dx, word ptr pDevice ;edx = pDevice
  362. }
  363. return OEMSetPaletteTmp( (WORD) dwBase, (WORD) dwNumEntries, lpColorTable );
  364. }
  365. } /* DD16_SetPaletteEntries */
  366. #define REBOOT_DEVICE_ID 9
  367. #define REBOOT_DISABLE 0x0101
  368. #define REBOOT_ENABLE 0x0102
  369. /*
  370. * doEnableReboot
  371. */
  372. static void PASCAL doEnableReboot( UINT EnableDisableFlag )
  373. {
  374. _asm
  375. {
  376. xor di,di
  377. mov es,di
  378. mov ax,1684h
  379. mov bx,REBOOT_DEVICE_ID
  380. int 2fh
  381. mov ax,es
  382. or ax,di
  383. jz exit
  384. push cs
  385. push offset exit
  386. push es
  387. push di
  388. mov ax, EnableDisableFlag
  389. retf
  390. exit:
  391. }
  392. } /* doEnableReboot */
  393. /*
  394. * DD16_EnableReboot
  395. */
  396. void DDAPI DD16_EnableReboot( BOOL enable )
  397. {
  398. if( enable )
  399. {
  400. doEnableReboot( REBOOT_ENABLE );
  401. }
  402. else
  403. {
  404. doEnableReboot( REBOOT_DISABLE );
  405. }
  406. } /* DD16_EnableReboot */
  407. /*
  408. * DD16_InquireVisRgn
  409. */
  410. HRGN DDAPI DD16_InquireVisRgn( HDC hdc )
  411. {
  412. extern HRGN WINAPI InquireVisRgn(HDC hdc);
  413. return InquireVisRgn( hdc );
  414. } /* DD16_InquireVisRgn */
  415. /*
  416. * DDThunk16_ColorControl
  417. */
  418. DWORD DDAPI DDThunk16_ColorControl( LPDDHAL_COLORCONTROLDATA lpColorData )
  419. {
  420. return lpColorData->ColorControl( lpColorData );
  421. } /* DDThunk16_ColorControl */