Source code of Windows XP (NT5)
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.

414 lines
10 KiB

  1. #include <windows.h>
  2. #define _INC_VFW
  3. #define VFWAPI FAR PASCAL _loadds
  4. #include "dva.h"
  5. #include "lockbm.h"
  6. /****************************************************************************
  7. ***************************************************************************/
  8. extern BOOL vga_get_surface(HDC, int, DVASURFACEINFO FAR *);
  9. extern BOOL ati_get_surface(HDC, int, DVASURFACEINFO FAR *);
  10. extern BOOL dib_get_surface(HDC, int, DVASURFACEINFO FAR *);
  11. extern BOOL thun_get_surface(HDC,int, DVASURFACEINFO FAR *);
  12. extern BOOL vlb_get_surface(HDC, int, DVASURFACEINFO FAR *);
  13. #define GetDS() SELECTOROF((LPVOID)&ScreenSel)
  14. static short ScreenSel;
  15. static BOOL InitSurface(DVASURFACEINFO FAR *pdva);
  16. static BOOL TestSurface(DVASURFACEINFO FAR *pdva);
  17. static void SetSelLimit(UINT sel, DWORD limit);
  18. /****************************************************************************
  19. ***************************************************************************/
  20. void FAR PASCAL DVAInit()
  21. {
  22. }
  23. /****************************************************************************
  24. ***************************************************************************/
  25. void FAR PASCAL DVATerm()
  26. {
  27. //
  28. // free screen alias
  29. //
  30. if (ScreenSel)
  31. {
  32. SetSelLimit(ScreenSel, 0);
  33. FreeSelector(ScreenSel);
  34. ScreenSel = 0;
  35. }
  36. }
  37. /****************************************************************************
  38. ***************************************************************************/
  39. BOOL FAR PASCAL _loadds DVAGetSurface(HDC hdc, int nSurface, DVASURFACEINFO FAR *pdva)
  40. {
  41. int i;
  42. i = Escape(hdc, DVAGETSURFACE,sizeof(int),(LPCSTR)&nSurface,(LPVOID)pdva);
  43. //
  44. // should this be a function table? list?
  45. //
  46. if (i <= 0 &&
  47. !dib_get_surface(hdc, nSurface, pdva) &&
  48. !ati_get_surface(hdc, nSurface, pdva) &&
  49. #ifdef DEBUG
  50. !vlb_get_surface(hdc, nSurface, pdva) &&
  51. !thun_get_surface(hdc, nSurface, pdva) &&
  52. #endif
  53. !vga_get_surface(hdc, nSurface, pdva))
  54. return FALSE;
  55. return InitSurface(pdva);
  56. }
  57. #if 0
  58. /****************************************************************************
  59. ***************************************************************************/
  60. HDVA FAR PASCAL DVAOpenSurface(HDC hdc, int nSurface)
  61. {
  62. PDVA pdva;
  63. pdva = (PDVA)GlobalAllocPtr(GHND|GMEM_SHARE, sizeof(DVASURFACEINFO));
  64. if (pdva == NULL)
  65. return NULL;
  66. if (!DVAGetSurface(hdc, nSurface, pdva) ||
  67. !pdva->OpenSurface(pdva->lpSurface))
  68. {
  69. GlobalFreePtr(pdva);
  70. return NULL;
  71. }
  72. return pdva;
  73. }
  74. /****************************************************************************
  75. ***************************************************************************/
  76. void FAR PASCAL DVACloseSurface(HDVA pdva)
  77. {
  78. if (pdva == NULL)
  79. return;
  80. pdva->CloseSurface(pdva->lpSurface);
  81. GlobalFreePtr(pdva);
  82. }
  83. #endif
  84. /****************************************************************************
  85. ***************************************************************************/
  86. BOOL CALLBACK default_open_surface(LPVOID pv)
  87. {
  88. return TRUE;
  89. }
  90. /****************************************************************************
  91. ***************************************************************************/
  92. void CALLBACK default_close_surface(LPVOID pv)
  93. {
  94. }
  95. /****************************************************************************
  96. ***************************************************************************/
  97. BOOL CALLBACK default_begin_access(LPVOID pv, int x, int y, int dx, int dy)
  98. {
  99. return TRUE;
  100. }
  101. /****************************************************************************
  102. ***************************************************************************/
  103. void CALLBACK default_end_access(LPVOID pv)
  104. {
  105. }
  106. /****************************************************************************
  107. ***************************************************************************/
  108. UINT CALLBACK default_show_surface(LPVOID pv, HWND hwnd, LPRECT src, LPRECT dst)
  109. {
  110. return 1;
  111. }
  112. /****************************************************************************
  113. ***************************************************************************/
  114. static BOOL InitSurface(DVASURFACEINFO FAR *pdva)
  115. {
  116. LPBITMAPINFOHEADER lpbi;
  117. if (pdva->Version != 0x0100)
  118. return FALSE;
  119. lpbi = &pdva->BitmapInfo;
  120. if (lpbi->biSize != sizeof(BITMAPINFOHEADER))
  121. return FALSE;
  122. if (lpbi->biPlanes != 1)
  123. return FALSE;
  124. //
  125. // make the pointer a 16:16 pointer
  126. //
  127. if (pdva->offSurface >= 0x10000 &&
  128. !(pdva->Flags & DVAF_1632_ACCESS))
  129. {
  130. if (ScreenSel == NULL)
  131. ScreenSel = AllocSelector(GetDS());
  132. if (pdva->selSurface != 0)
  133. pdva->offSurface += GetSelectorBase(pdva->selSurface);
  134. SetSelectorBase(ScreenSel,pdva->offSurface);
  135. SetSelLimit(ScreenSel,lpbi->biSizeImage-1);
  136. pdva->offSurface = 0;
  137. pdva->selSurface = ScreenSel;
  138. }
  139. //
  140. // fill in defaults.
  141. //
  142. if (pdva->OpenSurface == NULL)
  143. pdva->OpenSurface = default_open_surface;
  144. if (pdva->CloseSurface == NULL)
  145. pdva->CloseSurface = default_close_surface;
  146. if (pdva->ShowSurface == NULL)
  147. pdva->ShowSurface = default_show_surface;
  148. if (pdva->BeginAccess == NULL)
  149. {
  150. pdva->BeginAccess = default_begin_access;
  151. pdva->EndAccess = default_end_access;
  152. }
  153. //
  154. // only test RGB surfaces.
  155. //
  156. if (lpbi->biCompression == 0 ||
  157. lpbi->biCompression == BI_BITFIELDS ||
  158. lpbi->biCompression == BI_1632)
  159. {
  160. if (!TestSurface(pdva))
  161. return FALSE;
  162. }
  163. //
  164. // set BI_1632 if needed
  165. //
  166. if (pdva->Flags & DVAF_1632_ACCESS)
  167. {
  168. lpbi->biCompression = BI_1632;
  169. }
  170. return TRUE;
  171. }
  172. /****************************************************************************
  173. ***************************************************************************/
  174. #pragma optimize("", off)
  175. static void SetSelLimit(UINT sel, DWORD limit)
  176. {
  177. if (limit >= 1024*1024l)
  178. limit = ((limit+4096) & ~4095) - 1;
  179. _asm
  180. {
  181. mov ax,0008h ; DPMI set limit
  182. mov bx,sel
  183. mov dx,word ptr limit[0]
  184. mov cx,word ptr limit[2]
  185. int 31h
  186. }
  187. }
  188. #pragma optimize("", on)
  189. /****************************************************************************
  190. ***************************************************************************/
  191. #define ASM66 _asm _emit 0x66 _asm
  192. #define DB _asm _emit
  193. #pragma optimize("", off)
  194. static BYTE ReadByte(PDVA pdva, LPVOID lpBits, DWORD dw)
  195. {
  196. BYTE b=42;
  197. DVABeginAccess(pdva, 0, 0, 1024, 1024);
  198. _asm {
  199. ASM66 xor bx,bx
  200. les bx,lpBits
  201. ASM66 add bx,word ptr dw
  202. mov ax,es
  203. ASM66 lsl ax,ax
  204. ASM66 cmp bx,ax
  205. ja exit
  206. DB 26h ;mov al,es:[ebx]
  207. DB 67h
  208. DB 8Ah
  209. DB 03h
  210. mov b,al
  211. exit:
  212. }
  213. DVAEndAccess(pdva);
  214. return b;
  215. }
  216. #pragma optimize("", on)
  217. /////////////////////////////////////////////////////////////////////////////
  218. //
  219. // SetPixel
  220. //
  221. // some cards cant't seam to do SetPixel right it is amazing they work at all
  222. //
  223. /////////////////////////////////////////////////////////////////////////////
  224. static void SetPixelX(HDC hdc, int x, int y, COLORREF rgb)
  225. {
  226. RECT rc;
  227. rc.left = x;
  228. rc.top = y;
  229. rc.right = x+1;
  230. rc.bottom = y+1;
  231. SetBkColor(hdc, rgb);
  232. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
  233. }
  234. #define SetPixel SetPixelX
  235. /****************************************************************************
  236. ***************************************************************************/
  237. static BOOL TestSurface(DVASURFACEINFO FAR *pdva)
  238. {
  239. HDC hdc;
  240. int x,y,h,w,wb;
  241. COLORREF rgb,rgb0,rgb1,rgb2,rgb3,rgb4;
  242. DWORD dw;
  243. BYTE b0,b1;
  244. UINT uType=0;
  245. LPBITMAPINFOHEADER lpbi;
  246. LPVOID lpBits;
  247. HCURSOR hcur;
  248. if (!pdva->OpenSurface(pdva->lpSurface))
  249. return FALSE;
  250. lpbi = DVAGetSurfaceFmt(pdva);
  251. lpBits = DVAGetSurfacePtr(pdva);
  252. h = abs((int)lpbi->biHeight);
  253. w = (int)lpbi->biWidth;
  254. wb = (w * ((UINT)lpbi->biBitCount/8) + 3) & ~3;
  255. dw = (DWORD)(UINT)(h-1) * (DWORD)(UINT)wb;
  256. if ((int)lpbi->biHeight < 0)
  257. y = 0;
  258. else
  259. y = h-1;
  260. #ifdef XDEBUG
  261. x = (int)lpbi->biWidth - 5;
  262. ((LPBYTE)lpBits) += x * (UINT)lpbi->biBitCount/8;
  263. #else
  264. x = 0;
  265. #endif
  266. hcur = SetCursor(NULL);
  267. hdc = GetDC(NULL);
  268. rgb = GetPixel(hdc, x, h-1-y);
  269. SetPixel(hdc, x, h-1-y, RGB(0,0,0)); GetPixel(hdc, x, h-1-y); b0 = ReadByte(pdva, lpBits, dw);
  270. SetPixel(hdc, x, h-1-y, RGB(255,255,255)); GetPixel(hdc, x, h-1-y); b1 = ReadByte(pdva, lpBits, dw);
  271. SetPixel(hdc, x, h-1-y,rgb);
  272. if (b0 != 0x00 || b1 == 0x00)
  273. goto done;
  274. rgb0 = GetPixel(hdc, x+0, y);
  275. rgb1 = GetPixel(hdc, x+1, y);
  276. rgb2 = GetPixel(hdc, x+2, y);
  277. rgb3 = GetPixel(hdc, x+3, y);
  278. rgb4 = GetPixel(hdc, x+4, y);
  279. TestSurfaceType(hdc, x, y);
  280. DVABeginAccess(pdva, x, y, 5, 1);
  281. uType = GetSurfaceType(lpBits);
  282. DVAEndAccess(pdva);
  283. SetPixel(hdc, x+0, y,rgb0);
  284. SetPixel(hdc, x+1, y,rgb1);
  285. SetPixel(hdc, x+2, y,rgb2);
  286. SetPixel(hdc, x+3, y,rgb3);
  287. SetPixel(hdc, x+4, y,rgb4);
  288. done:
  289. ReleaseDC(NULL, hdc);
  290. SetCursor(hcur);
  291. pdva->CloseSurface(pdva->lpSurface);
  292. switch (uType)
  293. {
  294. case BM_8BIT:
  295. break;
  296. case BM_16555:
  297. ((LPDWORD)(lpbi+1))[0] = 0x007C00;
  298. ((LPDWORD)(lpbi+1))[1] = 0x0003E0;
  299. ((LPDWORD)(lpbi+1))[2] = 0x00001F;
  300. break;
  301. case BM_24BGR:
  302. case BM_32BGR:
  303. ((LPDWORD)(lpbi+1))[0] = 0xFF0000;
  304. ((LPDWORD)(lpbi+1))[1] = 0x00FF00;
  305. ((LPDWORD)(lpbi+1))[2] = 0x0000FF;
  306. break;
  307. case BM_16565:
  308. lpbi->biCompression = BI_BITFIELDS;
  309. ((LPDWORD)(lpbi+1))[0] = 0x00F800;
  310. ((LPDWORD)(lpbi+1))[1] = 0x0007E0;
  311. ((LPDWORD)(lpbi+1))[2] = 0x00001F;
  312. break;
  313. case BM_24RGB:
  314. case BM_32RGB:
  315. lpbi->biCompression = BI_BITFIELDS;
  316. ((LPDWORD)(lpbi+1))[0] = 0x0000FF;
  317. ((LPDWORD)(lpbi+1))[1] = 0x00FF00;
  318. ((LPDWORD)(lpbi+1))[2] = 0xFF0000;
  319. break;
  320. }
  321. return uType != 0;
  322. }