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.

447 lines
18 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: driver.h
  3. *
  4. * Contains prototypes for the 256 colour VGA driver.
  5. *
  6. * NOTE: Must mirror driver.inc!
  7. *
  8. * Copyright (c) 1992-1995 Microsoft Corporation
  9. \**************************************************************************/
  10. #ifndef _DRIVER_
  11. #define _DRIVER_
  12. #include "stdlib.h"
  13. #include "stddef.h"
  14. #include "windows.h"
  15. #include "winddi.h"
  16. #include "devioctl.h"
  17. #include "ntddvdeo.h"
  18. #include "debug.h"
  19. typedef struct _PDEV PDEV, *PPDEV;
  20. //
  21. // A mode requires broken rasters if the stride is a power of 2 and the video ram
  22. // accessed is greater than 64K.
  23. //
  24. #define POW2(stride) (!((stride) & ((stride)-1))) // TRUE if stride is power of 2
  25. #define BROKEN_RASTERS(stride,cy) ((!(POW2(stride))) && ((stride*cy) > 0x10000))
  26. //
  27. // Sizes assumed for 1-window and 2 RW-window banks.
  28. //
  29. #define BANK_SIZE_1_WINDOW 0x10000L
  30. #define BANK_SIZE_2RW_WINDOW 0x08000L
  31. //
  32. // This will be used by everyone who needs a temporary working buffer
  33. //
  34. #define PAGE_SIZE 4096
  35. #define NUM_GLOBAL_PAGES 2
  36. #define GLOBAL_BUFFER_SIZE (PAGE_SIZE * NUM_GLOBAL_PAGES)
  37. #define PELS_PER_DWORD 4
  38. /**************************************************************************\
  39. *
  40. * Specifies desired justification for requestion scan line within bank window
  41. *
  42. \**************************************************************************/
  43. typedef enum {
  44. JustifyTop = 0,
  45. JustifyBottom,
  46. } BANK_JUST;
  47. /**************************************************************************\
  48. *
  49. * Specifies which window is to be mapped by two-window bank handler.
  50. *
  51. \**************************************************************************/
  52. typedef enum {
  53. MapSourceBank = 0,
  54. MapDestBank,
  55. } BANK_JUST;
  56. /**************************************************************************\
  57. *
  58. * Bank clipping info
  59. *
  60. \**************************************************************************/
  61. typedef struct {
  62. RECTL rclBankBounds; // describes pixels addressable in this bank
  63. ULONG ulBankOffset; // offset of bank start from bitmap start, if
  64. // the bitmap were linearly addressable
  65. } BANK_INFO, *PBANK_INFO;
  66. /**************************************************************************\
  67. *
  68. * Bank control function vector
  69. *
  70. \**************************************************************************/
  71. typedef VOID (*PFN_PlanarEnable)();
  72. typedef VOID (*PFN_PlanarDisable)();
  73. typedef VOID (*PFN_PlanarControl)(PPDEV, ULONG, BANK_JUST);
  74. typedef VOID (*PFN_PlanarControl2)(PPDEV, ULONG, BANK_JUST, ULONG);
  75. typedef VOID (*PFN_PlanarNext)(PPDEV);
  76. typedef VOID (*PFN_PlanarNext2)(PPDEV, ULONG);
  77. typedef VOID (*PFN_BankControl)(PPDEV, ULONG, BANK_JUST);
  78. typedef VOID (*PFN_BankControl2)(PPDEV, ULONG, BANK_JUST, ULONG);
  79. typedef VOID (*PFN_BankNext)(PPDEV);
  80. typedef VOID (*PFN_BankNext2)(PPDEV, ULONG);
  81. /**************************************************************************\
  82. *
  83. * Miscellaneous driver flags
  84. *
  85. \**************************************************************************/
  86. #define DRIVER_PLANAR_CAPABLE 0x01L
  87. #define DRIVER_OFFSCREEN_REFRESHED 0x02L // if not set, don't use offscreen
  88. // memory for long operations
  89. // (because the memory won't be
  90. // refreshed)
  91. #define DRIVER_HAS_OFFSCREEN 0x04L // if not set, can't use any offscreen
  92. // memory
  93. /**************************************************************************\
  94. *
  95. * Bank status flags
  96. *
  97. \**************************************************************************/
  98. #define BANK_BROKEN_RASTER1 0x01L // If bank1 or read bank has broken raster
  99. #define BANK_BROKEN_RASTER2 0x02L // If bank2 or write bank has broken raster
  100. #define BANK_BROKEN_RASTERS (BANK_BROKEN_RASTER1 | BANK_BROKEN_RASTER2)
  101. #define BANK_PLANAR 0x04L // If in planar mode
  102. /**************************************************************************\
  103. *
  104. * Structure for maintaining a realized brush:
  105. *
  106. \**************************************************************************/
  107. extern const ULONG gaaulPlanarPat[][8]; // Hatch brushes in preferred format
  108. #define RBRUSH_BLACKWHITE 0x001L // Black and white brush
  109. #define RBRUSH_2COLOR 0x002L // 2 color brush
  110. #define RBRUSH_NCOLOR 0x004L // n color brush
  111. #define RBRUSH_4PELS_WIDE 0x008L // Brush is 4xN
  112. #define BRUSH_SIZE 64 // An 8x8 8bpp brush needs 64 bytes
  113. #define BRUSH_MAX_CACHE_SCANS 2 // Maximum # of scans used by brush cache
  114. typedef struct _RBRUSH
  115. {
  116. FLONG fl; // Flags
  117. LONG xBrush; // Realized brush's x brush origin
  118. // Info for 2 color brushes:
  119. ULONG ulFgColor; // Foreground color
  120. ULONG ulBkColor; // Background color
  121. // Info for n color brushes:
  122. LONG cy; // Height of pattern
  123. LONG cyLog2; // log2 of the height
  124. LONG iCache; // Cache entry index. Zero is not
  125. // a valid index.
  126. // Pattern in preferred format:
  127. ULONG aulPattern[BRUSH_SIZE / sizeof(ULONG)];
  128. } RBRUSH; /* rb */
  129. typedef struct _BRUSHCACHEENTRY
  130. {
  131. RBRUSH* prbVerifyRealization; // We never dereference this pointer
  132. // to find a brush realization;
  133. // it is only ever used in a compare
  134. // to verify that for a realized brush,
  135. // its off-screen cache entry is still
  136. // valid.
  137. LONG yCache; // Scan where entry's bits live
  138. LONG ulCache; // Offset to cache entry from screen
  139. // start (assuming planar format --
  140. // if you want the non-planar offset,
  141. // multiply by 4)
  142. } BRUSHCACHEENTRY; /* bce */
  143. /**************************************************************************\
  144. *
  145. * Physical device data structure
  146. *
  147. \**************************************************************************/
  148. // ***********************************************************
  149. // *** MUST match the assembler version in i386\driver.inc ***
  150. // ***********************************************************
  151. typedef struct _PDEV
  152. {
  153. FLONG fl; // Driver flags (DRIVER_xxx)
  154. HANDLE hDriver; // Handle to \Device\Screen
  155. HDEV hdevEng; // Engine's handle to PDEV
  156. HSURF hsurfEng; // Engine's handle to surface
  157. HANDLE hsurfBm; // Handle to the "punt" surface
  158. SURFOBJ* pSurfObj; // pointer to the locked "punt" surface
  159. HPALETTE hpalDefault; // Handle to the default palette for device.
  160. PBYTE pjScreen; // This is pointer to base screen address
  161. ULONG cxScreen; // Visible screen width
  162. ULONG cyScreen; // Visible screen height
  163. ULONG ulMode; // Mode the mini-port driver is in.
  164. LONG lDeltaScreen; // Distance from one scan to the next.
  165. FLONG flRed; // For bitfields device, Red Mask
  166. FLONG flGreen; // For bitfields device, Green Mask
  167. FLONG flBlue; // For bitfields device, Blue Mask
  168. ULONG cPaletteShift; // number of bits the 8-8-8 palette must
  169. // be shifted by to fit in the hardware
  170. // palette.
  171. ULONG ulBitCount; // # of bits per pel -- can be only 8
  172. ULONG ulrm0_wmX; // Four values (one per byte) to set
  173. // GC5 to to select read mode 0
  174. // together with write modes 0-3
  175. BYTE* pjGlyphFlipTableBase; // Base allocated address for flip
  176. // table; the pointer we use is this
  177. // pointer rounded up to the nearest
  178. // 256-byte boundary
  179. BYTE* pjGlyphFlipTable; // Pointer to table used to flip glyph
  180. // bits 0-3 and 4-7
  181. PALETTEENTRY* pPal; // If this is pal managed, this is the pal
  182. HBITMAP hbmTmp; // Handle to temporary buffer
  183. SURFOBJ* psoTmp; // Temporary surface
  184. //-----------------------------------------------------------------------------
  185. // DCI stuff:
  186. BOOL bSupportDCI; // True if miniport supports DCI
  187. //-----------------------------------------------------------------------------
  188. // Off screen stuff:
  189. // Brush cache:
  190. LONG iCache; // Index for next brush to be allocated
  191. LONG iCacheLast; // Last valid cache index (so the
  192. // number of entries in cache is
  193. // iCacheLast + 1)
  194. BRUSHCACHEENTRY* pbceCache; // Pointer to allocated cache
  195. // Saved screen bits stuff
  196. RECTL rclSavedBitsRight; // right rect of vga memory that's
  197. // not visible
  198. RECTL rclSavedBitsBottom; // bottom rect of vga memory that's
  199. // not visible
  200. BOOL bBitsSaved; // TRUE if bits are currently saved
  201. //-----------------------------------------------------------------------------
  202. // Bank manager stuff common between planar and non-planar modes:
  203. LONG cTotalScans; // Number of usable on and off-screen
  204. // scans
  205. PVIDEO_BANK_SELECT pBankInfo; // Bank info for current mode returned
  206. // by miniport
  207. FLONG flBank; // Flags for current bank state
  208. ULONG ulBitmapSize; // Length of bitmap if there were no
  209. // banking, in CPU addressable bytes
  210. ULONG ulWindowBank[2]; // Current banks mapped into windows
  211. // 0 & 1
  212. PVOID pvBitmapStart; // Single-window bitmap start pointer
  213. // (adjusted as necessary to make
  214. // window map in at proper offset)
  215. PVOID pvBitmapStart2Window[2];// Double-window window 0 and 1 bitmap
  216. // start
  217. // Non-planar mode specific bank management control stuff:
  218. VIDEO_BANK_TYPE vbtBankingType; // Type of banking
  219. PFN pfnBankSwitchCode; // Pointer to bank switch code
  220. LONG lNextScan; // Offset to next bank in bytes
  221. BYTE* pjJustifyTopBank; // Pointer to lookup table for
  222. // converting scans to banks
  223. BANK_INFO* pbiBankInfo; // Array of bank clip info
  224. ULONG ulJustifyBottomOffset; // # of scans from top to bottom
  225. // of bank, for bottom justifying
  226. ULONG iLastBank; // Index of last valid bank in
  227. // pbiBankInfo table
  228. ULONG ulBank2RWSkip; // Offset from one bank index to next
  229. // to make two 32K banks appear to be
  230. // one seamless 64K bank
  231. PFN_BankControl pfnBankControl; // Pointer to bank control function
  232. PFN_BankControl2 pfnBankControl2Window; // Pointer to double-window bank
  233. // control function
  234. PFN_BankNext pfnBankNext; // Pointer to next bank function
  235. PFN_BankNext2 pfnBankNext2Window; // Pointer to double-window next
  236. // bank function
  237. RECTL rcl1WindowClip; // Single-window banking clip rect
  238. RECTL rcl2WindowClip[2]; // Double-window banking clip rects for
  239. // windows 0 & 1
  240. // Planar mode specific bank management control stuff:
  241. VIDEO_BANK_TYPE vbtPlanarType; // Type of planar banking
  242. PFN pfnPlanarSwitchCode; // Pointer to planar bank switch
  243. // code
  244. LONG lPlanarNextScan; // Offset to next planar bank in
  245. // bytes
  246. BYTE* pjJustifyTopPlanar; // Pointer to lookup table for
  247. // converting scans to banks
  248. BANK_INFO* pbiPlanarInfo; // Array of bank clip info
  249. ULONG ulPlanarBottomOffset;// # of scans from top to bottom
  250. // of bank, for bottom justifying
  251. ULONG iLastPlanar; // Index of last valid bank in
  252. // pbiPlanarInfo table
  253. ULONG ulPlanar2RWSkip; // Offset from one bank index to next
  254. // to make two 32K banks appear to be
  255. // one seamless 64K bank
  256. PFN_PlanarControl pfnPlanarControl; // Planar one window bank control
  257. PFN_PlanarControl2 pfnPlanarControl2; // Planar two window bank control
  258. PFN_PlanarNext pfnPlanarNext; // Planar one window next bank
  259. PFN_PlanarNext2 pfnPlanarNext2; // Planar two window next bank
  260. RECTL rcl1PlanarClip; // Single-window banking clip rect
  261. RECTL rcl2PlanarClip[2]; // Double-window banking clip rects for
  262. // windows 0 & 1
  263. PFN_PlanarEnable pfnPlanarEnable; // Function to enable planar mode
  264. PFN_PlanarDisable pfnPlanarDisable; // Function to disable planar mode
  265. // Smart bank manager stuff:
  266. LONG iLastScan; // Last scan we want to enumerate
  267. PVOID pvSaveScan0; // Surface's original pvScan0
  268. RECTL rclSaveBounds; // Clip Object's original bounds
  269. CLIPOBJ* pcoNull; // Points to an empty clip object
  270. // we can use when we're given a
  271. // NULL CLIPOBJ pointer
  272. BYTE iSaveDComplexity; // Clip Object's original complexity
  273. BYTE fjSaveOptions; // Clip Object's original flags
  274. BYTE ajFiller[2]; // Pack dword alignment
  275. PVOID pvTmpBuf; // Ptr to buffer attached to pdev
  276. BOOLEAN BankIoctlSupported; // Does the miniport support ioclt
  277. // based banking?
  278. }; /* pdev */
  279. // Palette stuff:
  280. #define MAX_CLUT_SIZE (sizeof(VIDEO_CLUT) + (sizeof(ULONG) * 256))
  281. // Size of the driver extra information in the DEVMODe structure passed
  282. // to and from the display driver
  283. #define DRIVER_EXTRA_SIZE 0
  284. #define DLL_NAME L"VGA256" // Name of the DLL in UNICODE
  285. #define STANDARD_DEBUG_PREFIX "VGA256: " // All debug output is prefixed
  286. #define ALLOC_TAG '2gvD' // 4 byte TAG for memory allocations
  287. // When calling vEnumStart, make sure you set bAll to FALSE. This will tell
  288. // the Engine to only enumerate rectangles in rclBounds.
  289. // Hooks and Driver function table.
  290. #define HOOKS_BMF8BPP (HOOK_BITBLT | HOOK_TEXTOUT | HOOK_FILLPATH | \
  291. HOOK_COPYBITS | HOOK_STROKEPATH | HOOK_PAINT | \
  292. HOOK_STRETCHBLT)
  293. #define BB_RECT_LIMIT 50
  294. typedef struct _BBENUM
  295. {
  296. ULONG c;
  297. RECTL arcl[BB_RECT_LIMIT];
  298. } BBENUM;
  299. #define TO_RECT_LIMIT 20
  300. typedef struct _TEXTENUM
  301. {
  302. ULONG c;
  303. RECTL arcl[TO_RECT_LIMIT];
  304. } TEXTENUM;
  305. // Initialization stuff:
  306. BOOL bEnableBanking(PPDEV);
  307. VOID vDisableBanking(PPDEV);
  308. BOOL bInitPDEV(PPDEV,PDEVMODEW,GDIINFO *, DEVINFO *);
  309. BOOL bInitSURF(PPDEV,BOOL);
  310. BOOL bInitPaletteInfo(PPDEV, DEVINFO *);
  311. BOOL bInit256ColorPalette(PPDEV);
  312. BOOL bInitPatterns(PPDEV, INT);
  313. VOID vInitBrushCache(PPDEV);
  314. VOID vInitSavedBits(PPDEV);
  315. VOID vDisablePalette(PPDEV);
  316. VOID vDisablePatterns(PPDEV);
  317. VOID vDisableSURF(PPDEV);
  318. VOID vDisableBrushCache(PPDEV);
  319. VOID vResetBrushCache(PPDEV);
  320. VOID vInitRegs(PPDEV);
  321. DWORD getAvailableModes(HANDLE, PVIDEO_MODE_INFORMATION *, DWORD *);
  322. // Smart bank manager stuff:
  323. CLIPOBJ* pcoBankStart(PPDEV, RECTL*, SURFOBJ*, CLIPOBJ*);
  324. BOOL bBankEnum(PPDEV, SURFOBJ*, CLIPOBJ*);
  325. VOID vBankStartBltSrc(PPDEV, SURFOBJ*, POINTL*, RECTL*, POINTL*, RECTL*);
  326. BOOL bBankEnumBltSrc(PPDEV, SURFOBJ*, POINTL*, RECTL*, POINTL*, RECTL*);
  327. VOID vBankStartBltDest(PPDEV, SURFOBJ*, POINTL*, RECTL*, POINTL*, RECTL*);
  328. BOOL bBankEnumBltDest(PPDEV, SURFOBJ*, POINTL*, RECTL*, POINTL*, RECTL*);
  329. // Fill routines:
  330. typedef union _RBRUSH_COLOR {
  331. RBRUSH* prb;
  332. ULONG iSolidColor;
  333. } RBRUSH_COLOR; /* rbc */
  334. typedef VOID (*PFNFILL)(PPDEV, ULONG, PRECTL, MIX, RBRUSH_COLOR, POINTL*);
  335. VOID vTrgBlt(PPDEV, ULONG, PRECTL, MIX, RBRUSH_COLOR, POINTL*);
  336. VOID vMonoPat(PPDEV, ULONG, PRECTL, MIX, RBRUSH_COLOR, POINTL*);
  337. VOID vColorPat(PPDEV, ULONG, PRECTL, MIX, RBRUSH_COLOR, POINTL*);
  338. // Other prototypes:
  339. BOOL b2ColorBrush(ULONG* pvBits, BYTE* pjFgColor, BYTE* pjBkColor);
  340. VOID vPlanarCopyBits(PPDEV, RECTL*, POINTL*);
  341. BOOL bIntersectRect(RECTL*, RECTL*, RECTL*);
  342. VOID vSetWriteModes(ULONG *);
  343. VOID vClearMemDword(PULONG * pulBuffer, ULONG ulDwordCount);
  344. VOID vSrcCopy8bpp(PPDEV, RECTL*, POINTL*, LONG, VOID*);
  345. VOID vFastLine(PPDEV, PATHOBJ*, LONG, ULONG);
  346. #endif // _DRIVER_