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.

532 lines
19 KiB

  1. /******************************Module*Header**********************************\
  2. *
  3. * *******************
  4. * * GDI SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: gdi.h
  8. *
  9. * Contains all the gdi related stuff
  10. *
  11. * Copyright (c) 1994-1998 3Dlabs Inc. Ltd. All rights reserved.
  12. * Copyright (c) 1995-1999 Microsoft Corporation. All rights reserved.
  13. \*****************************************************************************/
  14. #ifndef __GDI__H__
  15. #define __GDI__H__
  16. typedef struct _PDev PDev;
  17. #define CLIP_LIMIT 50 // We'll take 800 bytes of stack space
  18. typedef struct _ClipEnum
  19. {
  20. LONG c;
  21. RECTL arcl[CLIP_LIMIT]; // Space for enumerating complex clipping
  22. } ClipEnum; /* ce, pce */
  23. //
  24. // Text stuff. Specifies foreground and background colours for faking a 1bpp
  25. // XLATEOBJ
  26. //
  27. typedef struct _XlateColors
  28. {
  29. ULONG iBackColor;
  30. ULONG iForeColor;
  31. } XlateColors;
  32. #define SF_VM 0x01 // kept in video memory
  33. #define SF_SM 0x02 // kept in system memory
  34. #define SF_AGP 0x04 // kept in AGP memory
  35. #define SF_LIST 0x08 // in surface list
  36. #define SF_ALLOCATED 0x10 // surface memory allocated by us
  37. #define SF_DIRECTDRAW 0x20 // wrapper of a Direct Draw surface
  38. typedef ULONG SurfFlags;
  39. typedef struct _Surf
  40. {
  41. SurfFlags flags; // Type (video memory or system memory)
  42. PDev* ppdev; // Need this for deleting the bitmap
  43. struct _Surf* psurfNext;
  44. struct _Surf* psurfPrev;
  45. ULONG cBlt; // Counts down the number of blts necessary
  46. // at the current uniqueness before we'll
  47. // consider putting the DIB back into
  48. // off-screen memory
  49. ULONG iUniq; // Tells us whether there have been any
  50. // heap 'free's since the last time we
  51. // looked at
  52. LONG cx; // Bitmap width in pixels
  53. LONG cy; // Bitmap height in pixels
  54. union
  55. {
  56. ULONG ulByteOffset; // Offset from start of video memory if
  57. // DT_VM
  58. VOID* pvScan0; // pointer to system memory if DT_SM
  59. };
  60. LONG lDelta; // Stride in bytes for this bitmap
  61. VIDEOMEMORY* pvmHeap; // DirectDraw heap this was allocated from
  62. HSURF hsurf; // Handle to associated GDI surface (if any)
  63. // this DIB
  64. // New fields to support linear heap allocation of surface
  65. // Only valid if dt == DT_VM
  66. ULONG ulPackedPP; // padcked partial products needed by
  67. // Permedia hardware for given surface
  68. // lDelta
  69. ULONG ulPixOffset; // Pixel Offset from start of video memory
  70. ULONG ulPixDelta; // stride in pixels
  71. ULONG ulChecksum;
  72. } Surf; // dsurf, pdsurf
  73. #define NUM_BUFFER_POINTS 96 // Maximum number of points in a path
  74. // for which we'll attempt to join
  75. // all the path records so that the
  76. // path may still be drawn by FastFill
  77. #define FIX_SHIFT 4L
  78. #define FIX_MASK (- (1 << FIX_SHIFT))
  79. //
  80. // Maximum number of rects we'll fill per call to the fill code
  81. //
  82. #define MAX_PATH_RECTS 50
  83. #define RECT_BYTES (MAX_PATH_RECTS * sizeof(RECTL))
  84. #define EDGE_BYTES (TMP_BUFFER_SIZE - RECT_BYTES)
  85. #define MAX_EDGES (EDGE_BYTES/sizeof(EDGE))
  86. #define RIGHT 0
  87. #define LEFT 1
  88. #define NEARLY_ONE 0x0000FFFF
  89. //
  90. // Describe a single non-horizontal edge of a path to fill.
  91. //
  92. typedef struct _EDGE
  93. {
  94. PVOID pNext;
  95. INT iScansLeft;
  96. INT X;
  97. INT Y;
  98. INT iErrorTerm;
  99. INT iErrorAdjustUp;
  100. INT iErrorAdjustDown;
  101. INT iXWhole;
  102. INT iXDirection;
  103. INT iWindingDirection;
  104. } EDGE, *PEDGE;
  105. typedef struct _EDGEDATA
  106. {
  107. LONG lCurrentXPos; // Current x position
  108. LONG lXAdvance; // Number of pixels to advance x on each scan
  109. LONG lError; // Current DDA error
  110. LONG lErrorUp; // DDA error increment on each scan
  111. LONG lErrorDown; // DDA error adjustment
  112. POINTFIX* pptfx; // Points to start of current edge
  113. LONG lPtfxDelta; // Delta (in bytes) from pptfx to next point
  114. LONG lNumOfScanToGo; // Number of scans to go for this edge
  115. } EDGEDATA; // Ed, pEd
  116. //
  117. //
  118. // The x86 C compiler insists on making a divide and modulus operation
  119. // into two DIVs, when it can in fact be done in one. So we use this
  120. // macro.
  121. //
  122. // Note: QUOTIENT_REMAINDER implicitly takes unsigned arguments.
  123. #if defined(i386)
  124. #define QUOTIENT_REMAINDER(ulNumerator, ulDenominator, ulQuotient, ulRemainder) \
  125. { \
  126. __asm mov eax, ulNumerator \
  127. __asm sub edx, edx \
  128. __asm div ulDenominator \
  129. __asm mov ulQuotient, eax \
  130. __asm mov ulRemainder, edx \
  131. }
  132. #else
  133. #define QUOTIENT_REMAINDER(ulNumerator, ulDenominator, ulQuotient, ulRemainder) \
  134. { \
  135. ulQuotient = (ULONG) ulNumerator / (ULONG) ulDenominator; \
  136. ulRemainder = (ULONG) ulNumerator % (ULONG) ulDenominator; \
  137. }
  138. #endif
  139. //
  140. // Rendering constant definition
  141. //
  142. #define __RENDER_TEXTURE_ENABLE (1 << 13)
  143. #define __FX_TEXREADMODE_SWRAP_REPEAT (1 << 1)
  144. #define __FX_TEXREADMODE_TWRAP_REPEAT (1 << 3)
  145. #define __FX_TEXREADMODE_8HIGH (3 << 13)
  146. #define __FX_TEXREADMODE_8WIDE (3 << 9)
  147. #define __FX_TEXREADMODE_2048HIGH (11 << 13)
  148. #define __FX_TEXREADMODE_2048WIDE (11 << 9)
  149. #define __FX_TEXTUREREADMODE_PACKED_DATA (1 << 24)
  150. #define __FX_8x8REPEAT_TEXTUREREADMODE ( __PERMEDIA_ENABLE \
  151. | __FX_TEXREADMODE_TWRAP_REPEAT \
  152. | __FX_TEXREADMODE_SWRAP_REPEAT \
  153. | __FX_TEXREADMODE_8HIGH \
  154. | __FX_TEXREADMODE_8WIDE)
  155. #define __FX_TEXTUREDATAFORMAT_32BIT_RGBA 0x00
  156. #define __FX_TEXTUREDATAFORMAT_32BIT 0x10
  157. #define __FX_TEXTUREDATAFORMAT_8BIT 0xe
  158. #define __FX_TEXTUREDATAFORMAT_16BIT 0x11
  159. #define __FX_TEXTUREDATAFORMAT_4BIT 0xf
  160. #define __P2_TEXTURE_DATAFORMAT_FLIP (1 << 9)
  161. #define __FX_TEXLUTMODE_DIRECT_ENTRY (1 << 1)
  162. #define __FX_TEXLUTMODE_4PIXELS_PER_ENTRY (2 << 10) //log2
  163. #define __FX_TEXLUTMODE_2PIXELS_PER_ENTRY (1 << 10) //log2
  164. #define __FX_TEXLUTMODE_1PIXEL_PER_ENTRY 0 //log2
  165. #define STRETCH_MAX_EXTENT 32767
  166. //
  167. //-----------------------Function***Prototypes--------------------------------
  168. //
  169. // Low-level blt function prototypes
  170. //
  171. //----------------------------------------------------------------------------
  172. typedef struct _GFNPB
  173. {
  174. VOID (*pgfn)(struct _GFNPB *); // pointer to graphics function
  175. PDev * ppdev; // driver ppdev
  176. Surf * psurfDst; // destination surface
  177. RECTL * prclDst; // original unclipped destination rectangle
  178. Surf * psurfSrc; // source surface
  179. RECTL * prclSrc; // original unclipped source rectangle
  180. POINTL * pptlSrc; // original unclipped source point
  181. // NOTE: pdsurfSrc must be null if
  182. // there is no source. If there is
  183. // a source either (pptlSrc must be
  184. // valid) or (pptlSrc is NULL and prclSrc
  185. // is valid).
  186. RECTL * pRects; // rectangle list
  187. LONG lNumRects; // number of rectangles in list
  188. ULONG colorKey; // colorKey for transparent operations
  189. ULONG solidColor; // solid color used in fills
  190. RBrush * prbrush; // pointer to brush
  191. POINTL * pptlBrush; // brush origin
  192. CLIPOBJ * pco; // clipping object
  193. XLATEOBJ * pxlo; // color translatoin object
  194. POINTL * pptlMask; // original uncliped mask origin
  195. ULONG ulRop4; // original rop4
  196. UCHAR ucAlpha; // alpha value for constant blends
  197. TRIVERTEX * ptvrt; // verticies used for gradient fills
  198. ULONG ulNumTvrt; // number of verticies
  199. PVOID pvMesh; // connectivity for gradient fills
  200. ULONG ulNumMesh; // number of connectivity elements
  201. ULONG ulMode; // drawing mode
  202. SURFOBJ * psoSrc; // GDI managed surface source
  203. SURFOBJ * psoDst; // GDI managed surface destination
  204. } GFNPB;
  205. long flt_to_fix_1_30(float f);
  206. BOOL bConstructGET(EDGE* pGETHead,
  207. EDGE* pFreeEdges,
  208. PATHOBJ* ppo,
  209. PATHDATA* pd,
  210. BOOL bMore,
  211. RECTL* pClipRect);
  212. EDGE* pAddEdgeToGET(EDGE* pGETHead,
  213. EDGE* pFreeEdge,
  214. POINTFIX* ppfxEdgeStart,
  215. POINTFIX* ppfxEdgeEnd,
  216. RECTL* pClipRect);
  217. void vAdjustErrorTerm(INT* pErrorTerm,
  218. INT iErrorAdjustUp,
  219. INT iErrorAdjustDown,
  220. INT yJump,
  221. INT* pXStart,
  222. INT iXDirection);
  223. VOID vAdvanceAETEdges(EDGE* pAETHead);
  224. VOID vMoveNewEdges(EDGE* pGETHead,
  225. EDGE* pAETHead,
  226. INT iCurrentY);
  227. VOID vXSortAETEdges(EDGE* pAETHead);
  228. //
  229. // Prototypes for lower level rendering functions
  230. //
  231. BOOL bFillPolygon(PDev* ppdev,
  232. Surf* pSurfDst,
  233. LONG lEdges,
  234. POINTFIX* pptfxFirst,
  235. ULONG ulSolidColor,
  236. ULONG ulRop4,
  237. CLIPOBJ* pco,
  238. RBrush* prb,
  239. POINTL* pptlBrush);
  240. BOOL bFillSpans(PDev* ppdev,
  241. Surf* pSurfDst,
  242. LONG lEdges,
  243. POINTFIX* pptfxFirst,
  244. POINTFIX* pptfxTop,
  245. POINTFIX* pptfxLast,
  246. ULONG ulSolidColor,
  247. ULONG ulRop4,
  248. CLIPOBJ* pco,
  249. RBrush* prb,
  250. POINTL* pptlBrush);
  251. BOOL bInitializeStrips(PDev* ppdev,
  252. ULONG iSolidColor,
  253. DWORD logicop,
  254. RECTL* prclClip);
  255. void vAlphaBlend(GFNPB * ppb);
  256. void vAlphaBlendDownload(GFNPB * ppb);
  257. void vConstantAlphaBlend(GFNPB * ppb);
  258. void vConstantAlphaBlendDownload(GFNPB * ppb);
  259. void vCopyBlt(GFNPB * ppb);
  260. void vCopyBltNative(GFNPB * ppb);
  261. void vGradientFillRect(GFNPB * ppb);
  262. void vGradientFillTri(GFNPB * ppb);
  263. void vImageDownload(GFNPB * ppb);
  264. void vInvert(GFNPB * ppb);
  265. void vMonoDownload(GFNPB * ppb);
  266. void vMonoOffset(GFNPB * ppb);
  267. void vMonoPatFill(GFNPB * ppb);
  268. void vPatFill(GFNPB * ppb);
  269. void vPatternFillRects(GFNPB * ppb);
  270. void vPatRealize(GFNPB * ppb);
  271. void vResetStrips(PDev* ppdev);
  272. void vRop2Blt(GFNPB * ppb);
  273. void vSolidFill(GFNPB * ppb);
  274. void vSolidFillWithRop(GFNPB * ppb);
  275. void vTransparentBlt(GFNPB * ppb);
  276. //
  277. // Text stuff
  278. //
  279. BOOL bEnableText(PDev* ppdev);
  280. VOID vDisableText(PDev* ppdev);
  281. VOID vAssertModeText(PDev* ppdev, BOOL bEnable);
  282. //
  283. // Palette stuff
  284. //
  285. BOOL bEnablePalette(PDev* ppdev);
  286. BOOL bInitializePalette(PDev* ppdev, DEVINFO* pdi);
  287. VOID vDisablePalette(PDev* ppdev);
  288. VOID vUninitializePalette(PDev* ppdev);
  289. //
  290. // Upload and download functions
  291. //
  292. VOID vDownloadNative(GFNPB* ppb);
  293. VOID vUploadNative(GFNPB* ppb);
  294. //
  295. // StretchBlt stuff
  296. //
  297. DWORD dwGetPixelSize(ULONG ulBitmapFormat,
  298. DWORD* pdwFormatBits,
  299. DWORD* pdwFormatExtention);
  300. BOOL bStretchInit(SURFOBJ* psoDst,
  301. SURFOBJ* psoSrc);
  302. VOID vStretchBlt(SURFOBJ* psoDst,
  303. SURFOBJ* psoSrc,
  304. RECTL* rDest,
  305. RECTL* rSrc,
  306. RECTL* prclClip);
  307. VOID vStretchReset(PDev* ppdev);
  308. //
  309. // Work in progress
  310. //
  311. VOID vCheckGdiContext(PPDev ppdev);
  312. VOID vOldStyleDMA(PPDev ppdev);
  313. VOID vNewStyleDMA(PPDev ppdev);
  314. // Input buffer access methods
  315. //
  316. // InputBufferStart/InputBufferContinue/InputBufferCommit
  317. //
  318. // This method is used when the caller does not know
  319. // the upper limit of the amount of space that needs to be reserved
  320. // or needs to reserve space that exceeds that maximum allowed to
  321. // be reserved MAX_FIFO_RESERVATION.
  322. //
  323. // InputBufferStart() is used to get a pointer to the first available entry in
  324. // the input fifo, a pointer to the end of the reservation and
  325. // a pointer to the end of the usable area of the buffer.
  326. //
  327. // InputBufferContinue() is called to extend the current reservation.
  328. //
  329. // InputBufferCommit() is called when the caller is done using the reserved space.
  330. //
  331. // Please see textout.c for an example usage of these methods.
  332. //
  333. // InputBufferReserve/InputBufferCommit
  334. //
  335. // This method is used when the caller needs to make only one
  336. // reservation of some small known quantity.
  337. //
  338. // InputBufferReserve() is called to establish the reservation.
  339. //
  340. // InputBufferCommit() is called when the caller is done using the reserved space.
  341. //
  342. // Please see textout.c for the usage of InputBufferReserve/InputBufferCommit.
  343. //
  344. // A caller is free to use these access methods at any time. Once either
  345. // InputBufferStart or InputBufferReserve is called, the caller must pair the
  346. // call with either a InputBufferFinish or a InputBufferCommit before making
  347. // another reservation.
  348. //
  349. // A caller is free to use either of these methods at any time.
  350. //
  351. // Before calling any of the CPermedia class access methods, the caller
  352. // must call InputBufferFlush (see below). Because of this, a caller must
  353. // call InputBufferFlush or InputBufferExecute before returning to GDI.
  354. //
  355. // When the caller is done and wishes to initial the transmission of what
  356. // has been placed in the input fifo, the caller can call InputBufferExecute
  357. // (see below).
  358. //
  359. // InputBufferFlush
  360. //
  361. // InputBufferFlush is a neccessary evil only as long as these macros are not
  362. // part of the official input buffer access schemes. Flush is really
  363. // the means we sync up our copy of the input buffer state to the
  364. // CPermedia class. If these methods were instead part of the fundamental
  365. // input fifo mechanism, then we could do away with the need for Flush.
  366. //
  367. // InputBufferExecute
  368. //
  369. // Flush is a neccessary evil only as long as these macros are not
  370. // part of the official input buffer access schemes. If and when these
  371. // new access schemes are made part of the official input fifo buffer
  372. // mechanism, then it can be replaced by that mechanism's input fifo
  373. // execute method.
  374. //
  375. //
  376. // InputBufferMakeSpace
  377. //
  378. // This is a private call and no one should find need to call it directly.
  379. //
  380. //
  381. // Other Notes:
  382. //
  383. // We will play with making the access routines inline functions instead
  384. // of macros taking a look at the code generated. If acceptable,
  385. // these macros may turn into function calls in the non-Debug build.
  386. //
  387. // The InputBufferStart/InputBufferContinue mechansism keeps state on the stack
  388. // to avoid the dereferences to ppdev freeing up a register in cases where ppdev
  389. // references are not needed in the inner loop that contains InputBufferContinue.
  390. //
  391. // MAX_IN_FIFO_RESERVATION should be bumped up considerably when we add an
  392. // emulation buffer for the non-DMA case
  393. #define MAX_INPUT_BUFFER_RESERVATION (INPUT_BUFFER_SIZE>>3) // in longs
  394. #if DBG
  395. extern
  396. void InputBufferStart(
  397. PPDev ppdev,
  398. ULONG ulLongs,
  399. PULONG* ppulBuffer,
  400. PULONG* ppulBufferEnd,
  401. PULONG* ppulReservationEnd);
  402. extern
  403. void InputBufferContinue(
  404. PPDev ppdev,
  405. ULONG ulLongs,
  406. PULONG* ppulBuffer,
  407. PULONG* ppulBufferEnd,
  408. PULONG* ppulReservationEnd);
  409. extern
  410. void InputBufferReserve(
  411. PPDev ppdev,
  412. ULONG ulLongs,
  413. PULONG* ppulBuffer);
  414. extern
  415. void InputBufferCommit(
  416. PPDev ppdev,
  417. PULONG pulBuffer);
  418. #else
  419. #define InputBufferStart(ppdev, ulLongs, ppulBuffer, ppulBufferEnd, ppulReservationEnd) \
  420. { \
  421. *(ppulBuffer) = ppdev->pulInFifoPtr; \
  422. *(ppulReservationEnd) = *(ppulBuffer) + ulLongs; \
  423. *(ppulBufferEnd) = ppdev->pulInFifoEnd; \
  424. if(*(ppulReservationEnd) > *(ppulBufferEnd)) \
  425. { \
  426. InputBufferSwap(ppdev); \
  427. *(ppulBuffer) = ppdev->pulInFifoPtr; \
  428. *(ppulReservationEnd) = *(ppulBuffer) + ulLongs; \
  429. *(ppulBufferEnd) = ppdev->pulInFifoEnd; \
  430. } \
  431. }
  432. #define InputBufferContinue(ppdev, ulLongs, ppulBuffer, ppulBufferEnd, ppulReservationEnd) \
  433. { \
  434. *(ppulReservationEnd) = *(ppulBuffer) + ulLongs; \
  435. if(*(ppulReservationEnd) > *(ppulBufferEnd)) \
  436. { \
  437. ppdev->pulInFifoPtr = *(ppulBuffer); \
  438. InputBufferSwap(ppdev); \
  439. *(ppulBuffer) = ppdev->pulInFifoPtr; \
  440. *(ppulReservationEnd) = *(ppulBuffer) + ulLongs; \
  441. *(ppulBufferEnd) = ppdev->pulInFifoEnd; \
  442. } \
  443. }
  444. #define InputBufferReserve(ppdev, ulLongs, ppulBuffer) \
  445. { \
  446. if(ppdev->pulInFifoPtr + ulLongs > ppdev->pulInFifoEnd) \
  447. { \
  448. InputBufferSwap(ppdev); \
  449. } \
  450. *(ppulBuffer) = ppdev->pulInFifoPtr; \
  451. }
  452. #define InputBufferCommit(ppdev, pulBuffer) ppdev->pulInFifoPtr = pulBuffer
  453. #endif
  454. void FASTCALL InputBufferFlush(PPDev ppdev);
  455. void FASTCALL InputBufferSwap(PPDev ppdev);
  456. void InputBufferSync(PPDev ppdev);
  457. extern BOOL bGdiContext;
  458. #endif // __GDI__H__