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.

182 lines
4.8 KiB

  1. /****************************************************************************
  2. DVA surface provider for SVGA card, using dva.386
  3. ***************************************************************************/
  4. #include <windows.h>
  5. #include "dva.h"
  6. #include "lockbm.h"
  7. extern UINT PASCAL __A000h;
  8. #define A000h (WORD)(&__A000h)
  9. // stuff in VFlat.asm
  10. //
  11. extern LPVOID NEAR PASCAL VFlatInit(void);
  12. extern void NEAR PASCAL VFlatBegin(void);
  13. extern void NEAR PASCAL VFlatEnd(void);
  14. #define GETAPI(mod, api) GetProcAddress(GetModuleHandle(mod),MAKEINTATOM(api))
  15. static HCURSOR hcur;
  16. static FARPROC CheckCursor;
  17. HDC hdcScreen;
  18. static int open_count;
  19. static BOOL (FAR PASCAL *XIsWinoldAppTask)(HTASK hTask);
  20. #define IsWinoldAppTask XIsWinoldAppTask
  21. /****************************************************************************
  22. ***************************************************************************/
  23. BOOL FAR PASCAL _loadds vga_open_surface(LPVOID pv)
  24. {
  25. if (open_count++ == 0)
  26. {
  27. (FARPROC)CheckCursor = GETAPI("DISPLAY", MAKEINTATOM(104));
  28. (FARPROC)XIsWinoldAppTask = GETAPI("KERNEL", MAKEINTATOM(158));
  29. hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL);
  30. }
  31. return TRUE;
  32. }
  33. /****************************************************************************
  34. ***************************************************************************/
  35. void FAR PASCAL _loadds vga_close_surface(LPVOID pv)
  36. {
  37. if (open_count && --open_count == 0)
  38. {
  39. DeleteDC(hdcScreen);
  40. hdcScreen = NULL;
  41. }
  42. }
  43. /****************************************************************************
  44. ***************************************************************************/
  45. BOOL FAR PASCAL _loadds vga_begin_access(LPVOID pv, int x, int y, int dx, int dy)
  46. {
  47. RECT rc;
  48. POINT pt;
  49. HWND hwndA;
  50. //
  51. // if windows is in the background dont draw to the screen.
  52. //
  53. hwndA = GetActiveWindow();
  54. if (IsWinoldAppTask(GetWindowTask(hwndA)) && IsIconic(hwndA))
  55. return FALSE;
  56. //
  57. // on some SVGAs with 8514 like accelerators, a command Que may need to
  58. // be flushed before touching video memory.
  59. //
  60. if (hdcScreen)
  61. GetPixel(hdcScreen, x, y);
  62. //!!! we realy should hook the mouse callback.
  63. GetCursorPos(&pt);
  64. #define CUR 40
  65. if ((pt.x >= x-CUR && pt.x <= x+dx+CUR) &&
  66. (pt.y >= y-CUR && pt.y <= y+dy+CUR))
  67. {
  68. hcur = SetCursor(NULL);
  69. }
  70. else
  71. {
  72. hcur = NULL;
  73. rc.left = pt.x;
  74. rc.top = pt.y;
  75. rc.right = pt.x+1;
  76. rc.bottom = pt.y+1;
  77. ClipCursor(&rc);
  78. }
  79. if (CheckCursor)
  80. CheckCursor();
  81. VFlatBegin();
  82. return TRUE;
  83. }
  84. /****************************************************************************
  85. ***************************************************************************/
  86. void FAR PASCAL _loadds vga_end_access(LPVOID pv)
  87. {
  88. VFlatEnd();
  89. if (hcur)
  90. SetCursor(hcur);
  91. else
  92. ClipCursor(NULL);
  93. }
  94. /****************************************************************************
  95. ***************************************************************************/
  96. BOOL vga_get_surface(HDC hdc, int nSurface, DVASURFACEINFO FAR *pdva)
  97. {
  98. LPBITMAPINFOHEADER lpbi;
  99. int BitDepth;
  100. LPVOID lpScreen=NULL;
  101. IBITMAP FAR *pbm;
  102. if (nSurface != 0)
  103. return FALSE;
  104. BitDepth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL);
  105. if (BitDepth < 8) // forget VGA or mono.
  106. return FALSE;
  107. pbm = GetPDevice(hdc);
  108. if (pbm == NULL || pbm->bmType == 0)
  109. return FALSE;
  110. if (HIWORD(pbm->bmBits) != A000h)
  111. return FALSE;
  112. lpScreen = VFlatInit();
  113. if (lpScreen == NULL)
  114. return FALSE;
  115. lpbi = &pdva->BitmapInfo;
  116. lpbi->biSize = sizeof(BITMAPINFOHEADER);
  117. lpbi->biWidth = pbm->bmWidthBytes*8/pbm->bmBitsPixel;
  118. lpbi->biHeight = -(int)pbm->bmHeight;
  119. lpbi->biPlanes = pbm->bmPlanes;
  120. lpbi->biBitCount = pbm->bmBitsPixel;
  121. lpbi->biCompression = 0;
  122. lpbi->biSizeImage = (DWORD)pbm->bmWidthBytes * (DWORD)pbm->bmHeight;
  123. lpbi->biXPelsPerMeter = pbm->bmWidthBytes;
  124. lpbi->biYPelsPerMeter = 0;
  125. lpbi->biClrUsed = 0;
  126. lpbi->biClrImportant = 0;
  127. pdva->selSurface = SELECTOROF(lpScreen);
  128. pdva->offSurface = OFFSETOF(lpScreen);
  129. pdva->Version = 0x0100;
  130. pdva->Flags = DVAF_1632_ACCESS;
  131. pdva->lpSurface = (LPVOID)(DWORD)pbm->bmHeight;
  132. (FARPROC)pdva->OpenSurface = (FARPROC)vga_open_surface;
  133. (FARPROC)pdva->CloseSurface = (FARPROC)vga_close_surface;
  134. (FARPROC)pdva->BeginAccess = (FARPROC)vga_begin_access;
  135. (FARPROC)pdva->EndAccess = (FARPROC)vga_end_access;
  136. (FARPROC)pdva->ShowSurface = (FARPROC)NULL;
  137. return TRUE;
  138. }