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.

933 lines
42 KiB

  1. /******************************Module*Header*******************************\
  2. *
  3. * *******************
  4. * * GDI SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: driver.h
  8. *
  9. * Contains prototypes for the display driver.
  10. *
  11. * Copyright (c) 1992-1998 Microsoft Corporation
  12. \**************************************************************************/
  13. //////////////////////////////////////////////////////////////////////
  14. // Put all the conditional-compile constants here. There had better
  15. // not be many!
  16. //////////////////////////////////////////////////////////////////////
  17. // Miscellaneous shared stuff
  18. #define DLL_NAME L"s3" // Name of the DLL in UNICODE
  19. #define STANDARD_DEBUG_PREFIX "S3: " // All debug output is prefixed
  20. // by this string
  21. #define ALLOC_TAG ' 3S' // Four byte tag used for tracking
  22. // memory allocations (characters
  23. // are in reverse order)
  24. #define CLIP_LIMIT 50 // We'll be taking 800 bytes of stack space
  25. #define DRIVER_EXTRA_SIZE 0 // Size of the DriverExtra information in the
  26. // DEVMODE structure
  27. #define TMP_BUFFER_SIZE 8192 // Size in bytes of 'pvTmpBuffer'. Has to
  28. // be at least enough to store an entire
  29. // scan line (i.e., 6400 for 1600x1200x32).
  30. #if defined(_ALPHA_)
  31. #define XFER_BUFFERS 16 // Defines the maximum number of write buffers
  32. // possible on any Alpha. Must be a power
  33. #else // of two.
  34. #define XFER_BUFFERS 1 // On non-alpha systems, we don't have to
  35. // worry about the chip caching our bus
  36. #endif // writes.
  37. #define XFER_MASK (XFER_BUFFERS - 1)
  38. typedef struct _CLIPENUM {
  39. LONG c;
  40. RECTL arcl[CLIP_LIMIT]; // Space for enumerating complex clipping
  41. } CLIPENUM; /* ce, pce */
  42. typedef struct _PDEV PDEV; // Handy forward declaration
  43. VOID vSetClipping(PDEV*, RECTL*);
  44. VOID vResetClipping(PDEV*);
  45. //////////////////////////////////////////////////////////////////////
  46. // Text stuff
  47. #define GLYPH_CACHE_HEIGHT 48 // Number of scans to allocate for glyph cache,
  48. // divided by pel size
  49. #define GLYPH_CACHE_CX 64 // Maximal width of glyphs that we'll consider
  50. // caching
  51. #define GLYPH_CACHE_CY 64 // Maximum height of glyphs that we'll consider
  52. // caching
  53. #define MAX_GLYPH_SIZE ((GLYPH_CACHE_CX * GLYPH_CACHE_CY + 31) / 8)
  54. // Maximum amount of off-screen memory required
  55. // to cache a glyph, in bytes
  56. #define GLYPH_ALLOC_SIZE 8100
  57. // Do all cached glyph memory allocations
  58. // in 8k chunks
  59. #define HGLYPH_SENTINEL ((ULONG) -1)
  60. // GDI will never give us a glyph with a
  61. // handle value of 0xffffffff, so we can
  62. // use this as a sentinel for the end of
  63. // our linked lists
  64. #define GLYPH_HASH_SIZE 256
  65. #define GLYPH_HASH_FUNC(x) ((x) & (GLYPH_HASH_SIZE - 1))
  66. typedef struct _CACHEDGLYPH CACHEDGLYPH;
  67. typedef struct _CACHEDGLYPH
  68. {
  69. CACHEDGLYPH* pcgNext; // Points to next glyph that was assigned
  70. // to the same hash table bucket
  71. HGLYPH hg; // Handles in the bucket-list are kept in
  72. // increasing order
  73. POINTL ptlOrigin; // Origin of glyph bits
  74. // Device specific fields below here:
  75. LONG cxLessOne; // Glyph width less one
  76. LONG cyLessOne; // Glyph height less one
  77. LONG cxcyLessOne;// Packed width and height, less one
  78. LONG cw; // Number of words to be transferred
  79. LONG cd; // Number of dwords to be transferred
  80. ULONG ad[1]; // Start of glyph bits
  81. } CACHEDGLYPH; /* cg, pcg */
  82. typedef struct _GLYPHALLOC GLYPHALLOC;
  83. typedef struct _GLYPHALLOC
  84. {
  85. GLYPHALLOC* pgaNext; // Points to next glyph structure that
  86. // was allocated for this font
  87. CACHEDGLYPH acg[1]; // This array is a bit misleading, because
  88. // the CACHEDGLYPH structures are actually
  89. // variable sized
  90. } GLYPHAALLOC; /* ga, pga */
  91. typedef struct _CACHEDFONT CACHEDFONT;
  92. typedef struct _CACHEDFONT
  93. {
  94. CACHEDFONT* pcfNext; // Points to next entry in CACHEDFONT list
  95. CACHEDFONT* pcfPrev; // Points to previous entry in CACHEDFONT list
  96. GLYPHALLOC* pgaChain; // Points to start of allocated memory list
  97. CACHEDGLYPH* pcgNew; // Points to where in the current glyph
  98. // allocation structure a new glyph should
  99. // be placed
  100. LONG cjAlloc; // Bytes remaining in current glyph allocation
  101. // structure
  102. CACHEDGLYPH cgSentinel; // Sentinel entry of the end of our bucket
  103. // lists, with a handle of HGLYPH_SENTINEL
  104. CACHEDGLYPH* apcg[GLYPH_HASH_SIZE];
  105. // Hash table for glyphs
  106. } CACHEDFONT; /* cf, pcf */
  107. typedef struct _XLATECOLORS { // Specifies foreground and background
  108. ULONG iBackColor; // colours for faking a 1bpp XLATEOBJ
  109. ULONG iForeColor;
  110. } XLATECOLORS; /* xlc, pxlc */
  111. BOOL bEnableText(PDEV*);
  112. VOID vDisableText(PDEV*);
  113. VOID vAssertModeText(PDEV*, BOOL);
  114. VOID vFastText(GLYPHPOS*, ULONG, BYTE*, ULONG, ULONG, RECTL*, RECTL*,
  115. FLONG, RECTL*, RECTL*);
  116. VOID vClearMemDword(ULONG*, ULONG);
  117. //////////////////////////////////////////////////////////////////////
  118. // Brush stuff
  119. // 'Slow' brushes are used when we don't have hardware pattern capability,
  120. // and we have to handle patterns using screen-to-screen blts:
  121. #define SLOW_BRUSH_CACHE_DIM 3 // Controls the number of brushes cached
  122. // in off-screen memory, when we don't
  123. // have the S3 hardware pattern support.
  124. // We allocate 3 x 3 brushes, so we can
  125. // cache a total of 9 brushes:
  126. #define SLOW_BRUSH_COUNT (SLOW_BRUSH_CACHE_DIM * SLOW_BRUSH_CACHE_DIM)
  127. #define SLOW_BRUSH_DIMENSION 64 // After alignment is taken care of,
  128. // every off-screen brush cache entry
  129. // will be 64 pels in both dimensions
  130. #define SLOW_BRUSH_ALLOCATION (SLOW_BRUSH_DIMENSION + 8)
  131. // Actually allocate 72x72 pels for each
  132. // pattern, using the 8 extra for brush
  133. // alignment
  134. // 'Fast' brushes are used when we have hardware pattern capability:
  135. #define FAST_BRUSH_COUNT 16 // Total number of non-hardware brushes
  136. // cached off-screen
  137. #define FAST_BRUSH_DIMENSION 8 // Every off-screen brush cache entry
  138. // is 8 pels in both dimensions
  139. #define FAST_BRUSH_ALLOCATION 16 // We have to align ourselves, so this is
  140. // the dimension of each brush allocation
  141. // Common to both implementations:
  142. #define RBRUSH_2COLOR 1 // For RBRUSH flags
  143. #define TOTAL_BRUSH_COUNT max(FAST_BRUSH_COUNT, SLOW_BRUSH_COUNT)
  144. // This is the maximum number of brushes
  145. // we can possibly have cached off-screen
  146. #define TOTAL_BRUSH_SIZE 64 // We'll only ever handle 8x8 patterns,
  147. // and this is the number of pels
  148. typedef struct _BRUSHENTRY BRUSHENTRY;
  149. // NOTE: Changes to the RBRUSH or BRUSHENTRY structures must be reflected
  150. // in strucs.inc!
  151. typedef struct _RBRUSH {
  152. FLONG fl; // Type flags
  153. BOOL bTransparent; // TRUE if brush was realized for a transparent
  154. // blt (meaning colours are white and black),
  155. // FALSE if not (meaning it's already been
  156. // colour-expanded to the correct colours).
  157. // Value is undefined if the brush isn't
  158. // 2 colour.
  159. ULONG ulForeColor; // Foreground colour if 1bpp
  160. ULONG ulBackColor; // Background colour if 1bpp
  161. POINTL ptlBrushOrg; // Brush origin of cached pattern. Initial
  162. // value should be -1
  163. BRUSHENTRY* pbe; // Points to brush-entry that keeps track
  164. // of the cached off-screen brush bits
  165. ULONG aulPattern[1]; // Open-ended array for keeping copy of the
  166. // Don't put anything // actual pattern bits in case the brush
  167. // after here, or // origin changes, or someone else steals
  168. // you'll be sorry! // our brush entry (declared as a ULONG
  169. // for proper dword alignment)
  170. } RBRUSH; /* rb, prb */
  171. typedef struct _BRUSHENTRY {
  172. RBRUSH* prbVerify; // We never dereference this pointer to
  173. // find a brush realization; it is only
  174. // ever used in a compare to verify
  175. // that for a given realized brush, our
  176. // off-screen brush entry is still valid.
  177. LONG x; // x-position of cached pattern
  178. LONG y; // y-position of cached pattern
  179. } BRUSHENTRY; /* be, pbe */
  180. typedef union _RBRUSH_COLOR {
  181. RBRUSH* prb;
  182. ULONG iSolidColor;
  183. } RBRUSH_COLOR; /* rbc, prbc */
  184. BOOL bEnableBrushCache(PDEV*);
  185. VOID vDisableBrushCache(PDEV*);
  186. VOID vAssertModeBrushCache(PDEV*, BOOL);
  187. //////////////////////////////////////////////////////////////////////
  188. // Stretch stuff
  189. typedef struct _STR_BLT {
  190. PDEV* ppdev;
  191. PBYTE pjSrcScan;
  192. LONG lDeltaSrc;
  193. LONG XSrcStart;
  194. PBYTE pjDstScan;
  195. LONG lDeltaDst;
  196. LONG XDstStart;
  197. LONG XDstEnd;
  198. LONG YDstStart;
  199. LONG YDstCount;
  200. ULONG ulXDstToSrcIntCeil;
  201. ULONG ulXDstToSrcFracCeil;
  202. ULONG ulYDstToSrcIntCeil;
  203. ULONG ulYDstToSrcFracCeil;
  204. ULONG ulXFracAccumulator;
  205. ULONG ulYFracAccumulator;
  206. } STR_BLT;
  207. typedef VOID (*PFN_DIRSTRETCH)(STR_BLT*);
  208. VOID vDirectStretch8Narrow(STR_BLT*);
  209. VOID vDirectStretch8(STR_BLT*);
  210. VOID vDirectStretch16(STR_BLT*);
  211. VOID vDirectStretch32(STR_BLT*);
  212. /////////////////////////////////////////////////////////////////////////
  213. // Heap stuff
  214. typedef struct _DSURF DSURF;
  215. typedef enum {
  216. DT_DIB = 0x1, // Surface is really a DIB, not in off-screen
  217. // memory
  218. DT_DIRECTDRAW = 0x2, // Surface is really a DirectDraw surface
  219. } DSURFTYPE; /* dt, pdt */
  220. typedef struct _DSURF
  221. {
  222. DSURFTYPE dt; // DSURF status flags
  223. PDEV* ppdev; // Points to our PDEV
  224. LONG x; // x pixel coordinate of left edge of allocation
  225. // if not DT_DIB
  226. LONG y; // y pixel coordinate of right edge of allocation
  227. // if not DT_DIB
  228. LONG cx; // Bitmap width in pixels
  229. LONG cy; // Bitmap height in pixels
  230. union {
  231. FLATPTR fpVidMem; // Offset from start of video-memory if not DT_DIB
  232. VOID* pvScan0; // Bits location in system-memory if DT_DIB
  233. };
  234. VIDEOMEMORY* pvmHeap; // DirectDraw heap this was allocated from if
  235. // not DT_DIB and not DT_DIRECTDRAW
  236. DSURF* pdsurfDiscardableNext;
  237. // Linked list of discardable surface allocations.
  238. // This list is traversed from the start to
  239. // throw out any allocations
  240. HSURF hsurf; // Handle to associated GDI surface (if any)
  241. // The following are used for DT_DIB only...
  242. ULONG cBlt; // Counts down the number of blts necessary at
  243. // the current uniqueness before we'll consider
  244. // putting the DIB back into off-screen memory
  245. ULONG iUniq; // Tells us whether there have been any heap
  246. // 'free's since the last time we looked at
  247. // this DIB
  248. } DSURF; /* dsurf, pdsurf */
  249. // Number of blts necessary before we'll consider putting a DIB DFB back
  250. // into off-screen memory:
  251. #define HEAP_COUNT_DOWN 6
  252. DSURF* pVidMemAllocate(PDEV*, LONG, LONG);
  253. VOID vVidMemFree(DSURF*);
  254. BOOL bMoveDibToOffscreenDfbIfRoom(PDEV*, DSURF*);
  255. BOOL bMoveOldestOffscreenDfbToDib(PDEV*);
  256. BOOL bEnableOffscreenHeap(PDEV*);
  257. VOID vDisableOffscreenHeap(PDEV*);
  258. BOOL bAssertModeOffscreenHeap(PDEV*, BOOL);
  259. /////////////////////////////////////////////////////////////////////////
  260. // Bank manager stuff
  261. #define BANK_DATA_SIZE 80 // Number of bytes to allocate for the
  262. // miniport down-loaded bank code working
  263. // space
  264. typedef struct _BANK
  265. {
  266. // Private data:
  267. RECTL rclDraw; // Rectangle describing the remaining undrawn
  268. // portion of the drawing operation
  269. RECTL rclSaveBounds; // Saved from original CLIPOBJ for restoration
  270. BYTE iSaveDComplexity; // Saved from original CLIPOBJ for restoration
  271. BYTE fjSaveOptions; // Saved from original CLIPOBJ for restoration
  272. LONG iBank; // Current bank
  273. PDEV* ppdev; // Saved copy
  274. // Public data:
  275. SURFOBJ* pso; // Surface wrapped around the bank. Has to be
  276. // passed as the surface in any banked call-
  277. // back.
  278. CLIPOBJ* pco; // Clip object that is the intersection of the
  279. // original clip object with the bounds of the
  280. // current bank. Has to be passed as the clip
  281. // object in any banked call-back.
  282. } BANK; /* bnk, pbnk */
  283. // Note: BANK_MODE is duplicated in i386\strucs.inc!
  284. typedef enum {
  285. BANK_OFF = 0, // We've finished using the memory aperture
  286. BANK_ON, // We're about to use the memory aperture
  287. BANK_ON_NO_WAIT, // We're about to use the memory aperture, and are
  288. // doing our own hardware synchronization
  289. BANK_DISABLE, // We're about to enter full-screen; shut down banking
  290. BANK_ENABLE, // We've exited full-screen; re-enable banking
  291. } BANK_MODE; /* bankm, pbankm */
  292. typedef struct _BANKDATA {
  293. // Common to both old and new bank schemes:
  294. ULONG ulGp_stat_cmd; // Port number of status register
  295. ULONG ulRegisterLock_35; // Default for index 35
  296. // Only applies to new bank schemes:
  297. ULONG ulSystemConfiguration_40; // Default for index 40
  298. ULONG ulExtendedSystemControl2_51; // Default for index 51
  299. ULONG ulExtendedMemoryControl_53; // Default for index 53
  300. ULONG ulLinearAddressWindowControl_58; // Default for index 58
  301. ULONG ulExtendedSystemControl4_6a; // Default for index 6a
  302. ULONG ulEnableMemoryMappedIo; // Bit mask to enable MM IO
  303. } BANKDATA; /* bd, pbd */
  304. typedef VOID (FNBANKMAP)(PDEV*, BANKDATA*, LONG);
  305. typedef VOID (FNBANKSELECTMODE)(PDEV*, BANKDATA*, BANK_MODE);
  306. typedef VOID (FNBANKINITIALIZE)(PDEV*, BANKDATA*, BOOL);
  307. typedef BOOL (FNBANKCOMPUTE)(PDEV*, RECTL*, RECTL*, LONG*, LONG*);
  308. VOID vBankStart(PDEV*, RECTL*, CLIPOBJ*, BANK*);
  309. BOOL bBankEnum(BANK*);
  310. FNBANKCOMPUTE bBankComputeNonPower2;
  311. FNBANKCOMPUTE bBankComputePower2;
  312. BOOL bEnableBanking(PDEV*);
  313. VOID vDisableBanking(PDEV*);
  314. VOID vAssertModeBanking(PDEV*, BOOL);
  315. /////////////////////////////////////////////////////////////////////////
  316. // Pointer stuff
  317. #define POINTER_DATA_SIZE 40 // Number of bytes to allocate for the
  318. // miniport down-loaded pointer code
  319. // working space
  320. #define HW_INVISIBLE_OFFSET 2 // Offset from 'ppdev->yPointerBuffer'
  321. // to the invisible pointer
  322. #define HW_POINTER_DIMENSION 64 // Maximum dimension of default
  323. // (built-in) hardware pointer
  324. #define HW_POINTER_HIDE 63 // Hardware pointer start pixel
  325. // position used to hide the pointer
  326. #define HW_POINTER_TOTAL_SIZE 1024 // Total size in bytes required
  327. // to define the hardware pointer
  328. // (must be a power of 2 for
  329. // allocating space for the shape)
  330. typedef VOID (FNSHOWPOINTER)(PDEV*, VOID*, BOOL);
  331. typedef VOID (FNMOVEPOINTER)(PDEV*, VOID*, LONG, LONG);
  332. typedef BOOL (FNSETPOINTERSHAPE)(PDEV*, VOID*, LONG, LONG, LONG, LONG, LONG,
  333. LONG, BYTE*);
  334. typedef VOID (FNENABLEPOINTER)(PDEV*, VOID*, BOOL);
  335. BOOL bEnablePointer(PDEV*);
  336. VOID vDisablePointer(PDEV*);
  337. VOID vAssertModePointer(PDEV*, BOOL);
  338. /////////////////////////////////////////////////////////////////////////
  339. // Palette stuff
  340. BOOL bEnablePalette(PDEV*);
  341. VOID vDisablePalette(PDEV*);
  342. VOID vAssertModePalette(PDEV*, BOOL);
  343. BOOL bInitializePalette(PDEV*, DEVINFO*);
  344. VOID vUninitializePalette(PDEV*);
  345. #define MAX_CLUT_SIZE (sizeof(VIDEO_CLUT) + (sizeof(ULONG) * 256))
  346. /////////////////////////////////////////////////////////////////////////
  347. // DirectDraw stuff
  348. DWORD DdBlt(PDD_BLTDATA);
  349. DWORD DdFlip(PDD_FLIPDATA);
  350. DWORD DdLock(PDD_LOCKDATA);
  351. DWORD DdGetBltStatus(PDD_GETBLTSTATUSDATA);
  352. DWORD DdMapMemory(PDD_MAPMEMORYDATA);
  353. DWORD DdGetFlipStatus(PDD_GETFLIPSTATUSDATA);
  354. DWORD DdWaitForVerticalBlank(PDD_WAITFORVERTICALBLANKDATA);
  355. DWORD DdCanCreateSurface(PDD_CANCREATESURFACEDATA);
  356. DWORD DdCreateSurface(PDD_CREATESURFACEDATA);
  357. DWORD DdSetColorKey(PDD_SETCOLORKEYDATA);
  358. DWORD DdUpdateOverlay(PDD_UPDATEOVERLAYDATA);
  359. DWORD DdSetOverlayPosition(PDD_SETOVERLAYPOSITIONDATA);
  360. DWORD DdGetDriverInfo(PDD_GETDRIVERINFODATA);
  361. // FourCC formats are encoded in reverse because we're little endian:
  362. #define FOURCC_YUY2 '2YUY' // Encoded in reverse because we're little
  363. // There's a 64K granularity that applies to the mapping of the frame
  364. // buffer into the application's address space:
  365. #define ROUND_UP_TO_64K(x) (((ULONG)(x) + 0x10000 - 1) & ~(0x10000 - 1))
  366. typedef struct _FLIPRECORD
  367. {
  368. FLATPTR fpFlipFrom; // Surface we last flipped from
  369. LONGLONG liFlipTime; // Time at which last flip
  370. // occured
  371. LONGLONG liFlipDuration; // Precise amount of time it
  372. // takes from vblank to vblank
  373. BOOL bHaveEverCrossedVBlank; // True if we noticed that we
  374. // switched from inactive to
  375. // vblank
  376. BOOL bWasEverInDisplay; // True if we ever noticed that
  377. // we were inactive
  378. BOOL bFlipFlag; // True if we think a flip is
  379. // still pending
  380. } FLIPRECORD;
  381. BOOL bEnableDirectDraw(PDEV*);
  382. VOID vDisableDirectDraw(PDEV*);
  383. VOID vAssertModeDirectDraw(PDEV*, BOOL);
  384. //////////////////////////////////////////////////////////////////////
  385. // Low-level blt function prototypes
  386. typedef VOID (FNFILL)(PDEV*, LONG, RECTL*, ULONG, RBRUSH_COLOR, POINTL*);
  387. typedef VOID (FNXFER)(PDEV*, LONG, RECTL*, ULONG, SURFOBJ*, POINTL*,
  388. RECTL*, XLATEOBJ*);
  389. typedef VOID (FNCOPY)(PDEV*, LONG, RECTL*, ULONG, POINTL*, RECTL*);
  390. typedef VOID (FNFASTPATREALIZE)(PDEV*, RBRUSH*, POINTL*, BOOL);
  391. typedef VOID (FNIMAGETRANSFER)(PDEV*, BYTE*, LONG, LONG, LONG, ULONG);
  392. typedef BOOL (FNTEXTOUT)(SURFOBJ*, STROBJ*, FONTOBJ*, CLIPOBJ*, RECTL*,
  393. BRUSHOBJ*, BRUSHOBJ*);
  394. typedef VOID (FNLINETOTRIVIAL)(PDEV*, LONG, LONG, LONG, LONG, ULONG, MIX);
  395. typedef VOID (FNLINETOCLIPPED)(PDEV*, LONG, LONG, LONG, LONG, ULONG, MIX, RECTL*);
  396. typedef VOID (FNCOPYTRANSPARENT)(PDEV*, LONG, RECTL*, POINTL*, RECTL*, ULONG);
  397. FNFILL vIoFillPatFast;
  398. FNFILL vIoFillPatSlow;
  399. FNFILL vIoFillSolid;
  400. FNXFER vIoXfer1bpp;
  401. FNXFER vIoXfer4bpp;
  402. FNXFER vIoXferNative;
  403. FNXFER vXferNativeSrccopy;
  404. FNCOPY vIoCopyBlt;
  405. FNFASTPATREALIZE vIoFastPatRealize;
  406. FNIMAGETRANSFER vIoImageTransferIo16;
  407. FNIMAGETRANSFER vIoImageTransferMm16;
  408. FNTEXTOUT bIoTextOut;
  409. FNLINETOTRIVIAL vIoLineToTrivial;
  410. FNLINETOCLIPPED vIoLineToClipped;
  411. FNCOPYTRANSPARENT vIoCopyTransparent;
  412. FNFILL vMmFillPatFast;
  413. FNFILL vMmFillPatSlow;
  414. FNFILL vMmFillSolid;
  415. FNXFER vMmXfer1bpp;
  416. FNXFER vMmXfer4bpp;
  417. FNXFER vMmXferNative;
  418. FNCOPY vMmCopyBlt;
  419. FNFASTPATREALIZE vMmFastPatRealize;
  420. FNIMAGETRANSFER vMmImageTransferMm16;
  421. FNIMAGETRANSFER vMmImageTransferMm32;
  422. FNTEXTOUT bMmTextOut;
  423. FNLINETOTRIVIAL vMmLineToTrivial;
  424. FNLINETOCLIPPED vMmLineToClipped;
  425. FNCOPYTRANSPARENT vMmCopyTransparent;
  426. FNTEXTOUT bNwTextOut;
  427. FNLINETOTRIVIAL vNwLineToTrivial;
  428. FNLINETOCLIPPED vNwLineToClipped;
  429. VOID vPutBits(PDEV*, SURFOBJ*, RECTL*, POINTL*);
  430. VOID vGetBits(PDEV*, SURFOBJ*, RECTL*, POINTL*);
  431. VOID vIoSlowPatRealize(PDEV*, RBRUSH*, BOOL);
  432. ////////////////////////////////////////////////////////////////////////
  433. // Capabilities flags
  434. //
  435. // These are private flags passed to us from the S3 miniport. They
  436. // come from the 'DriverSpecificAttributeFlags' field of the
  437. // 'VIDEO_MODE_INFORMATION' structure (found in 'ntddvdeo.h') passed
  438. // to us via an 'VIDEO_QUERY_AVAIL_MODES' or 'VIDEO_QUERY_CURRENT_MODE'
  439. // IOCTL.
  440. //
  441. // NOTE: These definitions must match those in the S3 miniport's 's3.h'!
  442. typedef enum {
  443. CAPS_STREAMS_CAPABLE = 0x00000040, // Has overlay streams processor
  444. CAPS_FORCE_DWORD_REREADS= 0x00000080, // Dword reads occasionally return
  445. // an incorrect result, so always
  446. // retry the reads
  447. CAPS_NEW_MMIO = 0x00000100, // Can use 'new memory-mapped
  448. // I/O' scheme introduced with
  449. // 868/968
  450. CAPS_POLYGON = 0x00000200, // Can do polygons in hardware
  451. CAPS_24BPP = 0x00000400, // Has 24bpp capability
  452. CAPS_BAD_24BPP = 0x00000800, // Has 868/968 early rev chip bugs
  453. // when at 24bpp
  454. CAPS_PACKED_EXPANDS = 0x00001000, // Can do 'new 32-bit transfers'
  455. CAPS_PIXEL_FORMATTER = 0x00002000, // Can do colour space conversions,
  456. // and one-dimensional hardware
  457. // stretches
  458. CAPS_BAD_DWORD_READS = 0x00004000, // Dword or word reads from the
  459. // frame buffer will occasionally
  460. // return an incorrect result,
  461. // so always do byte reads
  462. CAPS_NO_DIRECT_ACCESS = 0x00008000, // Frame buffer can't be directly
  463. // accessed by GDI or DCI --
  464. // because dword or word reads
  465. // would crash system, or Alpha
  466. // is running in sparse space
  467. CAPS_HW_PATTERNS = 0x00010000, // 8x8 hardware pattern support
  468. CAPS_MM_TRANSFER = 0x00020000, // Memory-mapped image transfers
  469. CAPS_MM_IO = 0x00040000, // Memory-mapped I/O
  470. CAPS_MM_32BIT_TRANSFER = 0x00080000, // Can do 32bit bus size transfers
  471. CAPS_16_ENTRY_FIFO = 0x00100000, // At least 16 entries in FIFO
  472. CAPS_SW_POINTER = 0x00200000, // No hardware pointer; use software
  473. // simulation
  474. CAPS_BT485_POINTER = 0x00400000, // Use Brooktree 485 pointer
  475. CAPS_TI025_POINTER = 0x00800000, // Use TI TVP3020/3025 pointer
  476. CAPS_SCALE_POINTER = 0x01000000, // Set if the S3 hardware pointer
  477. // x position has to be scaled by
  478. // two
  479. CAPS_SPARSE_SPACE = 0x02000000, // Frame buffer is mapped in sparse
  480. // space on the Alpha
  481. CAPS_NEW_BANK_CONTROL = 0x04000000, // Set if 801/805/928 style banking
  482. CAPS_NEWER_BANK_CONTROL = 0x08000000, // Set if 864/964 style banking
  483. CAPS_RE_REALIZE_PATTERN = 0x10000000, // Set if we have to work around the
  484. // 864/964 hardware pattern bug
  485. CAPS_SLOW_MONO_EXPANDS = 0x20000000, // Set if we have to slow down
  486. // monochrome expansions
  487. CAPS_MM_GLYPH_EXPAND = 0x40000000, // Use memory-mapped I/O glyph-
  488. // expand method of drawing text
  489. } CAPS;
  490. #define CAPS_DAC_POINTER (CAPS_BT485_POINTER | CAPS_TI025_POINTER)
  491. #define CAPS_LINEAR_FRAMEBUFFER CAPS_NEW_MMIO
  492. // For now, we're linear only
  493. // when using with 'New MM I/O'
  494. // DIRECT_ACCESS(ppdev) returns TRUE if GDI and DCI can directly access
  495. // the frame buffer. It returns FALSE if there are hardware bugs
  496. // when reading words or dwords from the frame buffer that cause non-x86
  497. // systems to crash. It will also return FALSE is the Alpha frame buffer
  498. // is mapped in using 'sparse space'.
  499. #if defined(_X86_)
  500. #define DIRECT_ACCESS(ppdev) 1
  501. #else
  502. #define DIRECT_ACCESS(ppdev) \
  503. (!(ppdev->flCaps & (CAPS_NO_DIRECT_ACCESS | CAPS_SPARSE_SPACE)))
  504. #endif
  505. // DENSE(ppdev) returns TRUE if the normal 'dense space' mapping of the
  506. // frame buffer is being used. It returns FALSE only on the Alpha when
  507. // the frame buffer is mapped in using 'sparse space,' meaning that all
  508. // reads and writes to and from the frame buffer must be done through the
  509. // funky 'ioaccess.h' macros.
  510. #if defined(_ALPHA_)
  511. #define DENSE(ppdev) (!(ppdev->flCaps & CAPS_SPARSE_SPACE))
  512. #else
  513. #define DENSE(ppdev) 1
  514. #endif
  515. ////////////////////////////////////////////////////////////////////////
  516. // Status flags
  517. typedef enum {
  518. STAT_GLYPH_CACHE = 0x0001, // Glyph cache successfully allocated
  519. STAT_BRUSH_CACHE = 0x0002, // Brush cache successfully allocated
  520. STAT_DIRECTDRAW_CAPABLE = 0x0004, // Card is DirectDraw capable
  521. STAT_STREAMS_ENABLED = 0x0010, // Streams processor is enabled
  522. } STATUS;
  523. ////////////////////////////////////////////////////////////////////////
  524. // The Physical Device data structure
  525. typedef struct _PDEV
  526. {
  527. // -------------------------------------------------------------------
  528. // NOTE: Changes between here and NOTE1 in the PDEV structure must be
  529. // reflected in i386\strucs.inc (assuming you're on an x86, of course)!
  530. LONG xOffset; // Pixel offset from (0, 0) to current
  531. LONG yOffset; // DFB located in off-screen memory
  532. BYTE* pjMmBase; // Start of memory mapped I/O
  533. BYTE* pjScreen; // Points to base screen address
  534. LONG lDelta; // Distance from one scan to the next.
  535. LONG cjPelSize; // 1 if 8bpp, 2 if 16bpp, 3 if 24bpp,
  536. // 4 if 32bpp
  537. ULONG iBitmapFormat; // BMF_8BPP or BMF_16BPP or BMF_32BPP
  538. // (our current colour depth)
  539. // Enhanced mode register addresses.
  540. VOID* ioCur_y;
  541. VOID* ioCur_x;
  542. VOID* ioDesty_axstp;
  543. VOID* ioDestx_diastp;
  544. VOID* ioErr_term;
  545. VOID* ioMaj_axis_pcnt;
  546. VOID* ioGp_stat_cmd;
  547. VOID* ioShort_stroke;
  548. VOID* ioBkgd_color;
  549. VOID* ioFrgd_color;
  550. VOID* ioWrt_mask;
  551. VOID* ioRd_mask;
  552. VOID* ioColor_cmp;
  553. VOID* ioBkgd_mix;
  554. VOID* ioFrgd_mix;
  555. VOID* ioMulti_function;
  556. VOID* ioPix_trans;
  557. // Important data for accessing the frame buffer.
  558. VOID* pvBankData; // Points to aulBankData[0]
  559. FNBANKSELECTMODE* pfnBankSelectMode; // Routine to enable or disable
  560. // direct frame buffer access
  561. BANK_MODE bankmOnOverlapped; // BANK_ON or BANK_ON_NO_WAIT,
  562. // depending on whether card
  563. // can handle simulataneous
  564. // frame buffer and accelerator
  565. // access
  566. BOOL bMmIo; // Can do CAPS_MM_IO
  567. // -------------------------------------------------------------------
  568. // NOTE1: Changes up to here in the PDEV structure must be reflected in
  569. // i386\strucs.inc (assuming you're on an x86, of course)!
  570. CAPS flCaps; // Capabilities flags
  571. STATUS flStatus; // Status flags
  572. BOOL bEnabled; // In graphics mode (not full-screen)
  573. HANDLE hDriver; // Handle to \Device\Screen
  574. HDEV hdevEng; // Engine's handle to PDEV
  575. HSURF hsurfScreen; // Engine's handle to screen surface
  576. LONG cxScreen; // Visible screen width
  577. LONG cyScreen; // Visible screen height
  578. LONG cxMemory; // Width of Video RAM
  579. LONG cyHeap; // Height of Video RAM available to
  580. // DirectDraw heap (cyScreen
  581. // <= cyHeap <= cyMemory),
  582. // including primary surface
  583. LONG cxHeap; // Width of Video RAM available to
  584. // DirectDraw heap, including
  585. // primary surface
  586. LONG cyMemory; // Height of Video RAM
  587. LONG cBitsPerPel; // Bits per pel (8, 15, 16, 24 or 32)
  588. ULONG ulMode; // Mode the mini-port driver is in.
  589. FLONG flHooks; // What we're hooking from GDI
  590. UCHAR* pjIoBase; // Mapped IO port base for this PDEV
  591. VOID* pvTmpBuffer; // General purpose temporary buffer,
  592. // TMP_BUFFER_SIZE bytes in size
  593. // (Remember to synchronize if you
  594. // use this for device bitmaps or
  595. // async pointers)
  596. USHORT* apwMmXfer[XFER_BUFFERS];// Pre-computed array of unique
  597. ULONG* apdMmXfer[XFER_BUFFERS];// addresses for doing memory-mapped
  598. // transfers without memory barriers
  599. // Note that the 868/968 chips have a
  600. // hardware bug and can't do byte
  601. // transfers
  602. HSEMAPHORE csCrtc; // Used for synchronizing access to
  603. // the CRTC register
  604. DSURF dsurfScreen; // We stash here our private surface
  605. // structure that represents the
  606. // primary GDI surface
  607. ////////// Low-level blt function pointers:
  608. FNFILL* pfnFillSolid;
  609. FNFILL* pfnFillPat;
  610. FNXFER* pfnXfer1bpp;
  611. FNXFER* pfnXfer4bpp;
  612. FNXFER* pfnXferNative;
  613. FNCOPY* pfnCopyBlt;
  614. FNFASTPATREALIZE* pfnFastPatRealize;
  615. FNIMAGETRANSFER* pfnImageTransfer;
  616. FNTEXTOUT* pfnTextOut;
  617. FNLINETOTRIVIAL* pfnLineToTrivial;
  618. FNLINETOCLIPPED* pfnLineToClipped;
  619. FNCOPYTRANSPARENT* pfnCopyTransparent;
  620. ////////// Palette stuff:
  621. PALETTEENTRY* pPal; // The palette if palette managed
  622. HPALETTE hpalDefault; // GDI handle to the default palette.
  623. FLONG flRed; // Red mask for 16/32bpp bitfields
  624. FLONG flGreen; // Green mask for 16/32bpp bitfields
  625. FLONG flBlue; // Blue mask for 16/32bpp bitfields
  626. ULONG cPaletteShift; // number of bits the 8-8-8 palette must
  627. // be shifted by to fit in the hardware
  628. // palette.
  629. ////////// Heap stuff:
  630. VIDEOMEMORY* pvmList; // Points to the video-memory heap list
  631. // as supplied by DirectDraw, needed
  632. // for heap allocations
  633. ULONG cHeaps; // Count of video-memory heaps
  634. ULONG iHeapUniq; // Incremented every time room is freed
  635. // in the off-screen heap
  636. SURFOBJ* psoPunt; // Wrapper surface for having GDI draw
  637. // on off-screen bitmaps
  638. SURFOBJ* psoPunt2; // Another one for off-screen to off-
  639. // screen blts
  640. DSURF* pdsurfDiscardableList; // Linked list of discardable bitmaps,
  641. // in order of oldest to newest
  642. ////////// Banking stuff:
  643. LONG cjBank; // Size of a bank, in bytes
  644. LONG cPower2ScansPerBank; // Used by 'bBankComputePower2'
  645. LONG cPower2BankSizeInBytes; // Used by 'bBankComputePower2'
  646. CLIPOBJ* pcoBank; // Clip object for banked call backs
  647. SURFOBJ* psoBank; // Surface object for banked call backs
  648. ULONG aulBankData[BANK_DATA_SIZE / 4];
  649. // Private work area for downloaded
  650. // miniport banking code
  651. FNBANKMAP* pfnBankMap;
  652. FNBANKCOMPUTE* pfnBankCompute;
  653. ////////// Pointer stuff:
  654. BOOL bHwPointerActive; // Currently using the h/w pointer?
  655. LONG xPointerHot; // xHot of current hardware pointer
  656. LONG yPointerHot; // yHot of current hardware pointer
  657. LONG cjPointerOffset; // Byte offset from start of frame
  658. // buffer to off-screen memory where
  659. // we stored the pointer shape
  660. LONG xPointerShape; // x-coordinate
  661. LONG yPointerShape; // y-coordinate
  662. LONG iPointerBank; // Bank containing pointer shape
  663. VOID* pvPointerShape; // Points to pointer shape when bank
  664. // is mapped in
  665. LONG xPointer; // Start x-position for the current
  666. // S3 pointer
  667. LONG yPointer; // Start y-position for the current
  668. // S3 pointer
  669. LONG dxPointer; // Start x-pixel position for the
  670. // current S3 pointer
  671. LONG dyPointer; // Start y-pixel position for the
  672. // current S3 pointer
  673. LONG cPointerShift; // Horizontal scaling factor for
  674. // hardware pointer position
  675. ULONG ulHwGraphicsCursorModeRegister_45;
  676. // Default value for index 45
  677. VOID* pvPointerData; // Points to ajPointerData[0]
  678. BYTE ajPointerData[POINTER_DATA_SIZE];
  679. // Private work area for downloaded
  680. // miniport pointer code
  681. FNSHOWPOINTER* pfnShowPointer;
  682. FNMOVEPOINTER* pfnMovePointer;
  683. FNSETPOINTERSHAPE* pfnSetPointerShape;
  684. FNENABLEPOINTER* pfnEnablePointer;
  685. ////////// Brush stuff:
  686. LONG iBrushCache; // Index for next brush to be allocated
  687. LONG cBrushCache; // Total number of brushes cached
  688. BRUSHENTRY abe[TOTAL_BRUSH_COUNT]; // Keeps track of brush cache
  689. POINTL ptlReRealize; // Work area for 864/964 pattern
  690. // hardware bug work-around
  691. ////////// Text stuff:
  692. SURFOBJ* psoText; // 1bpp surface to which we will have
  693. // GDI draw our glyphs for us
  694. /////////// DirectDraw stuff:
  695. FLIPRECORD flipRecord; // Used to track vertical blank status
  696. ULONG ulRefreshRate; // Refresh rate in Hz
  697. ULONG ulMinOverlayStretch; // Minimum stretch ratio for this mode,
  698. // expressed as a multiple of 1000
  699. ULONG ulFifoValue; // Optimial FIFO value for this mode
  700. ULONG ulExtendedSystemControl3Register_69;
  701. // Masked original contents of
  702. // S3 register 0x69, in high byte
  703. ULONG ulMiscState; // Default state of the MULT_MISC
  704. // register
  705. DSURF* pdsurfVideoEngineScratch;// Location of one entire scan line that
  706. // can be used for temporary memory
  707. // by the 868/968 pixel formatter
  708. BYTE jSavedCR2; // Saved contents of register CR2
  709. FLATPTR fpVisibleOverlay; // Frame buffer offset to currently
  710. // visible overlay; will be zero if
  711. // no overlay is visible
  712. DWORD dwOverlayFlipOffset; // Overlay flip offset
  713. DWORD dwVEstep; // 868 video engine step value
  714. DWORD ulColorKey; // color key value to be set when streams
  715. // processor is enabled
  716. } PDEV;
  717. /////////////////////////////////////////////////////////////////////////
  718. // Miscellaneous prototypes:
  719. BOOL bIntersect(RECTL*, RECTL*, RECTL*);
  720. LONG cIntersect(RECTL*, RECTL*, LONG);
  721. DWORD getAvailableModes(HANDLE, PVIDEO_MODE_INFORMATION*, DWORD*);
  722. BOOL bInitializeModeFields(PDEV*, GDIINFO*, DEVINFO*, DEVMODEW*);
  723. BOOL bFastFill(PDEV*, LONG, POINTFIX*, ULONG, ULONG, RBRUSH*, POINTL*, RECTL*);
  724. BOOL bEnableHardware(PDEV*);
  725. VOID vDisableHardware(PDEV*);
  726. BOOL bAssertModeHardware(PDEV*, BOOL);
  727. extern BYTE gajHwMixFromMix[];
  728. extern BYTE gaRop3FromMix[];
  729. extern ULONG gaulHwMixFromRop2[];
  730. /////////////////////////////////////////////////////////////////////////
  731. // The x86 C compiler insists on making a divide and modulus operation
  732. // into two DIVs, when it can in fact be done in one. So we use this
  733. // macro.
  734. //
  735. // Note: QUOTIENT_REMAINDER implicitly takes unsigned arguments.
  736. #if defined(_X86_)
  737. #define QUOTIENT_REMAINDER(ulNumerator, ulDenominator, ulQuotient, ulRemainder) \
  738. { \
  739. __asm mov eax, ulNumerator \
  740. __asm sub edx, edx \
  741. __asm div ulDenominator \
  742. __asm mov ulQuotient, eax \
  743. __asm mov ulRemainder, edx \
  744. }
  745. #else
  746. #define QUOTIENT_REMAINDER(ulNumerator, ulDenominator, ulQuotient, ulRemainder) \
  747. { \
  748. ulQuotient = (ULONG) ulNumerator / (ULONG) ulDenominator; \
  749. ulRemainder = (ULONG) ulNumerator % (ULONG) ulDenominator; \
  750. }
  751. #endif
  752. /////////////////////////////////////////////////////////////////////////
  753. // OVERLAP - Returns TRUE if the same-size lower-right exclusive
  754. // rectangles defined by 'pptl' and 'prcl' overlap:
  755. #define OVERLAP(prcl, pptl) \
  756. (((prcl)->right > (pptl)->x) && \
  757. ((prcl)->bottom > (pptl)->y) && \
  758. ((prcl)->left < ((pptl)->x + (prcl)->right - (prcl)->left)) && \
  759. ((prcl)->top < ((pptl)->y + (prcl)->bottom - (prcl)->top)))
  760. /////////////////////////////////////////////////////////////////////////
  761. // SWAP - Swaps the value of two variables, using a temporary variable
  762. #define SWAP(a, b, tmp) { (tmp) = (a); (a) = (b); (b) = (tmp); }
  763. /////////////////////////////////////////////////////////////////////////
  764. // CONVERT_TO_BYTES - Converts to byte count.
  765. #define CONVERT_TO_BYTES(x, pdev) ( (x) * pdev->cjPelSize)
  766. /////////////////////////////////////////////////////////////////////////
  767. // CONVERT_FROM_BYTES - Converts to byte count.
  768. #define CONVERT_FROM_BYTES(x, pdev) ( (x) / pdev->cjPelSize)