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.

528 lines
21 KiB

  1. /*++
  2. Copyright (c) 1996 - 1999 Microsoft Corporation
  3. Module Name:
  4. pdev.h
  5. Abstract:
  6. Unidrv PDEV and related info header file.
  7. Environment:
  8. Windows NT Unidrv driver
  9. Revision History:
  10. 10/14/96 -amandan-
  11. Created
  12. 03/31/97 -zhanw-
  13. Added OEM customization support
  14. --*/
  15. #include "oemkm.h"
  16. #include "state.h"
  17. #ifndef _PDEV_H_
  18. #define _PDEV_H_
  19. #define CCHNAME 32 // length of port names.
  20. #define CCHMAXBUF 128 // size of local buffer
  21. #define CCHSPOOL 4096 // Size of spool buffer
  22. #define PDEV_ID 0x72706476 // "rpdv" in ASCII
  23. #define BBITS 8 // Bits per BYTE
  24. #define WBITS (sizeof( WORD ) * BBITS)
  25. #define WBYTES (sizeof( WORD ))
  26. #define DWBITS (sizeof( DWORD ) * BBITS)
  27. #define DWBYTES (sizeof( DWORD ))
  28. #define NOOCD -1 // Command does not exist
  29. #define MIN(x, y) ((x) < (y) ? (x) : (y))
  30. #define MAX(x, y) ((x) < (y) ? (y) : (x))
  31. //
  32. // Possible personality types
  33. //
  34. typedef enum _EPERSONALITY {
  35. kNoPersonality,
  36. kPCLXL,
  37. kHPGL2,
  38. kPCLXL_RASTER,
  39. } EPERSONALITY;
  40. //
  41. // SHRINK_FACTOR is used to reduce the number of scan lines in the
  42. // drawing surface bitmap when we cannot create a full sized version.
  43. // Each iteration of the "try this size" loop will reduce the number
  44. // of scan lines by this factor.
  45. //
  46. #define SHRINK_FACTOR 2 // Bitmap reduction size
  47. #define ONE_MBYTE (1024L * 1024L)
  48. #define MAX_SIZE_OF_BITMAP (6L * ONE_MBYTE)
  49. #define MIN_SIZE_OF_BITMAP (ONE_MBYTE / 2L)
  50. #define MAX_COLUMM 8
  51. #define LINESPERBLOCK 32 // scans per bitmap block for erasing surface
  52. #define MAX_NUM_RULES 256
  53. //
  54. // OUTPUTCTL is included in PDEVICE for controlling the state of the output
  55. // device during banding
  56. //
  57. typedef struct _OUTPUTCTL {
  58. POINT ptCursor; // current cursor position (printer's CAP)
  59. // (in master units), use this for
  60. // absolute x,y move cmds
  61. POINT ptRelativePos; // The desired relative cursor position,
  62. // relative to current
  63. // cursor position
  64. POINT ptAbsolutePos; // The absolute cursor postion
  65. DWORD dwMode; // flags for controling printer state.
  66. LONG lLineSpacing; // last line spacing chosen
  67. ULONG ulBrushColor; // Current Brush Color.
  68. //
  69. // The following fields are initialized and update by
  70. // the Raster module
  71. //
  72. SHORT sColor; // Last color chosen
  73. SHORT sBytesPerPinPass; // number of bytes per row of printhead.
  74. SHORT sPad; // Padding for alignment
  75. } OUTPUTCTL;
  76. //
  77. // flags for OUTPUTCTL.dwCursorMode
  78. //
  79. #define MODE_CURSOR_X_UNINITIALIZED 0x00000001
  80. #define MODE_CURSOR_Y_UNINITIALIZED 0x00000002
  81. #define MODE_CURSOR_UNINITIALIZED 0x00000003 // both X and Y
  82. #define MODE_BRUSH_RESET_COLOR 0x00000004 // Reset the brush color by
  83. // by sending the command.
  84. typedef struct _PAPERFORMAT {
  85. //
  86. // All paper units are in Master units. All fields are in Portrait orientation.
  87. //
  88. SIZEL szPhysSizeM; // Physical size, in Portrait
  89. SIZEL szImageAreaM; // Imageable area of paper, in Portrait
  90. POINT ptImageOriginM; // X, Y origin of imageable area, in Portrait
  91. } PAPERFORMAT, *PPAPERFORMAT;
  92. typedef struct _SURFACEFORMAT {
  93. //
  94. // all fields in this structure are in the current orientation.
  95. // Fields end with 'M' are in master units; and those end with 'G' are in graphics
  96. // device units.
  97. POINT ptPrintOffsetM; // X, Y offset of image origin relative to cursor origin
  98. SIZEL szPhysPaperG;
  99. SIZEL szImageAreaG;
  100. POINT ptImageOriginG;
  101. } SURFACEFORMAT, * PSURFACEFORMAT;
  102. //
  103. // PDEVICE structure for Unidrv
  104. //
  105. typedef struct _PDEV {
  106. //
  107. // the first field must be DEVOBJ, defined in <printoem.h>.
  108. //
  109. DEVOBJ devobj; // the first field of DEVOBJ is the pointer
  110. // to PDEV itself.
  111. //
  112. // General information
  113. //
  114. PVOID pvStartSig; // Signature at the start
  115. ULONG ulID; // For PDEV verification
  116. HANDLE hUniResDLL; // Handle to resource DLL
  117. HBITMAP hbm; // The bitmap handle from EngCreateBitmap
  118. HSURF hSurface; // The surface handle from EngCreateDeviceSurface
  119. SURFOBJ *pso; // Pointer to driver managed surface
  120. DWORD fMode; // Device context flags
  121. DWORD fMode2; // Device context flags
  122. DWORD fHooks; // Hook flag for EngAssociateSurface
  123. WINRESDATA WinResData; // Struct for resource data loading
  124. // WINRESDATA localWinResData; // references unires.dll
  125. BOOL bTTY; // Set if the printer is TTY
  126. PDRIVER_INFO_3 pDriverInfo3; // pointer to DRIVER_INFO_3 structure
  127. DWORD dwDelta; // Size of each columm for z-ordering fix
  128. PBYTE pbScanBuf; // Array representing # of scan lines on the band
  129. PBYTE pbRasterScanBuf; // Array representing # of scan lines block on the band
  130. #ifndef DISABLE_NEWRULES
  131. PRECTL pbRulesArray; // Array containing pseudo vector rectangles
  132. DWORD dwRulesCount; // Number of pseudo vector rectangles
  133. #endif
  134. DWORD dwHTPatSize; // Size of halftone pattern
  135. PFORM_INFO_1 pSplForms; // Array of forms registered in forms database.
  136. DWORD dwSplForms ; // Number of forms in the array.
  137. //
  138. // OEM info
  139. //
  140. POEM_PLUGINS pOemPlugins;
  141. POEM_PLUGINS pOemEntry; // the Plugin that supports the selected OEM entry point
  142. POEM_HOOK_INFO pOemHookInfo;
  143. DWORD dwCallingFuncID;
  144. PFN_OEMCommandCallback pfnOemCmdCallback; // cache the function ptr, if any
  145. //
  146. // Graphic State Info
  147. //
  148. GSTATE GState;
  149. //
  150. // Personality
  151. //
  152. EPERSONALITY ePersonality;
  153. //
  154. // Memory related information
  155. //
  156. DWORD dwFreeMem; // Memory available on printer
  157. //
  158. // Banding related information
  159. //
  160. BOOL bBanding; // Flag to indicate banding
  161. INT iBandDirection; // Banding direction
  162. SIZEL szBand; // Dimensions of the band in Graphic units
  163. RECTL rcClipRgn; // Clipping region
  164. //
  165. // Binary data related information
  166. //
  167. GPDDRIVERINFO *pDriverInfo; // Pointer to GPDDRVINFO
  168. RAWBINARYDATA *pRawData; // Pointer to RAWBINARYDATA
  169. INFOHEADER *pInfoHeader; // Pointer to INFOHEADER
  170. UIINFO *pUIInfo; // Pointer to UIINFO
  171. PRINTERDATA PrinterData; // PRINTERDATA struct
  172. POPTSELECT pOptionsArray; // Pointer to combined option array
  173. SHORT sBitsPixel; // Bits per pixel selected, from COLORMODEEX
  174. PDWORD arStdPtrs[SV_MAX]; // Array of PDWORD , where the
  175. // pointers points to the standard variables
  176. GLOBALS * pGlobals; // Pointer to GLOBALS struct
  177. PCOMMAND arCmdTable[CMD_MAX]; // Table containing pointers
  178. // to each predefined command index as
  179. // enumerated in gpd.h, CMDINDEX
  180. //
  181. // The following fields are use by the standard variable table.
  182. //
  183. //
  184. // Control module items
  185. //
  186. SHORT sCopies; // SV_COPIES
  187. // SV_DESTX, SV_DESTY,
  188. // SV_DESTXREL, SV_DESTYREL,
  189. // SV_LINEFEED
  190. // are in OUTPUTCTL
  191. // SV_PHYSPAPERLENGTH, SV_PHYSPAPERWIDTH,
  192. // are in PAPERFORMAT
  193. DWORD dwRop3; // SV_ROP3
  194. // SV_TEXTXRES , SV_TEXTYRES are
  195. // in ptTextRes
  196. DWORD dwPageNumber ; // SV_PAGENUMBER of a document - may not be accurate
  197. // if multiple copies is simulated.
  198. //
  199. // Brush specific standard variables
  200. //
  201. DWORD dwPatternBrushType; // SV_PATTERNBRUSH_TYPE
  202. DWORD dwPatternBrushID; // SV_PATTERNBRUSH_ID
  203. DWORD dwPatternBrushSize; // SV_PATTERNBRUSH_SIZE
  204. //
  205. // Palette specific standard variables.
  206. //
  207. DWORD dwRedValue; // SV_REDVALUE
  208. DWORD dwGreenValue; // SV_GREENVALUE
  209. DWORD dwBlueValue ; // SV_BLUEVALUE
  210. DWORD dwPaletteIndexToProgram; // SV_PALETTEINDEXTOPROGRAM
  211. DWORD dwCurrentPaletteIndex ; // SV_CURRENTPALETTEINDEX
  212. //
  213. // Raster module items
  214. //
  215. DWORD dwNumOfDataBytes; // SV_NUMDATABYTES
  216. DWORD dwWidthInBytes; // SV_WIDTHINBYTES
  217. DWORD dwHeightInPixels; // SV_HEIGHTINPIXELS
  218. DWORD dwRectXSize; // SV_RECTXSIZE
  219. DWORD dwRectYSize; // SV_RECTYSIZE
  220. DWORD dwGrayPercentage; // SV_GRAYPERCENT
  221. //
  222. // Font module items
  223. //
  224. DWORD dwPrintDirection; // SV_PRINTDIR
  225. DWORD dwNextFontID; // SV_NEXTFONTID
  226. DWORD dwNextGlyph; // SV_NEXTGLYPH
  227. DWORD dwFontHeight; // SV_FONTHEIGHT
  228. DWORD dwFontWidth; // SV_FONTWIDTH
  229. DWORD dwFontMaxWidth; // SV_FONTMAXWIDTH
  230. DWORD dwFontBold; // SV_FONTBOLD
  231. DWORD dwFontItalic; // SV_FONTITALIC
  232. DWORD dwFontUnderline; // SV_FONTUNDERLINE
  233. DWORD dwFontStrikeThru; // SV_FONTSTRIKETHU
  234. DWORD dwCurrentFontID; // SV_CURRENTFONTID
  235. //
  236. // The following are the pointers to the options selected
  237. // as indicated in the pOptionsArray
  238. //
  239. PORIENTATION pOrientation; // Pointer to ORIENTATION option
  240. PRESOLUTION pResolution; // Pointer to RESOLUTION option
  241. PRESOLUTIONEX pResolutionEx; // Pointer to RESOLUTIONEX option
  242. PCOLORMODE pColorMode; // Pointer to COLORMODE option
  243. PCOLORMODEEX pColorModeEx; // Pointer to COLORMODEEX option
  244. PDUPLEX pDuplex; // Pointer to DUPLEX option
  245. PPAGESIZE pPageSize; // Pointer to PAGESIZE option
  246. PPAGESIZEEX pPageSizeEx; // Pointer to PAGESIZEEX option
  247. PINPUTSLOT pInputSlot; // Pointer to INPUTSLOT option
  248. PMEMOPTION pMemOption; // Pointer to MEMOPTION option
  249. PHALFTONING pHalftone; // Pointer to HALFTONING option
  250. PPAGEPROTECT pPageProtect; // Pointer to PAGEPROTECT option
  251. // PMEDIATYPE pMediaType; // Pointer to MEDIATYPE option
  252. // POPTION pOutputBin; // Pointer to OUTPUTBIN option
  253. // POPTION pCollate; // Pointer to COLLATE option
  254. //
  255. // Text and Graphics Resolution
  256. //
  257. POINT ptGrxRes; // Graphics resolution selected
  258. POINT ptTextRes; // Text resolution selected
  259. POINT ptGrxScale; // Scale between Master and Graphics Units
  260. POINT ptDeviceFac; // Factor to convert from Device to Master Units
  261. //
  262. // UNIDRV devmode
  263. //
  264. PDEVMODE pdm; // current devmode
  265. PUNIDRVEXTRA pdmPrivate; // pointer to driver private portion
  266. //
  267. // Output Control Information, Paper Format and Palette
  268. //
  269. OUTPUTCTL ctl; // State of the printer
  270. PAPERFORMAT pf; // PAPERFORMAT struct
  271. SURFACEFORMAT sf; // SURFACEFORMAT struct
  272. DWORD fYMove; // Fields saved from looking
  273. // ast YMoveAttributes keyword
  274. PVOID pPalData; // Pointer to PAL_DATA structure
  275. //
  276. // Spool buffer
  277. //
  278. INT iSpool; // offset into the spool buffer
  279. PBYTE pbOBuf; // Output buffer base address
  280. //
  281. // Text Specific Information
  282. //
  283. INT iFonts; // Number of Device Fonts
  284. DWORD dwLookAhead; // Look ahead region:DskJet type
  285. POINT ptDefaultFont; // Default font width & height.
  286. PVOID pFontPDev; // Font Module PDEV
  287. PVOID pFontProcs; // Table of font functions
  288. PVOID pFileList; // Pointer to Font File List
  289. //
  290. // Raster Specific Information
  291. //
  292. PVOID pRasterPDEV; // Raster Module PDEV
  293. PVOID pRasterProcs; // Table of raster functions
  294. //
  295. // Vector Specific Information
  296. //
  297. PVOID pVectorPDEV; // Vector Module PDEV
  298. PVOID pVectorProcs; // Table of vector functions
  299. DWORD dwVMCallingFuncID; // ID of vector function.
  300. //
  301. // Temporary copies due to the fact that we unload
  302. // the binary data at DrvEnablePDEV and reloads it at
  303. // DrvEnableSurface
  304. //
  305. DWORD dwMaxCopies;
  306. DWORD dwMaxGrayFill;
  307. DWORD dwMinGrayFill;
  308. CURSORXAFTERRECTFILL cxafterfill; // *CursorXAfterRectFill
  309. CURSORYAFTERRECTFILL cyafterfill; // *CursorYAfterRectFill
  310. //
  311. // DMS
  312. //
  313. DWORD dwDMSInfo;
  314. PVOID pvEndSig; // Signature at the end
  315. } PDEV, *PPDEV;
  316. #define SW_DOWN 0
  317. #define SW_LTOR 1
  318. #define SW_RTOL 2
  319. #define SW_UP 4 // enum bottom band first and work towards top
  320. //
  321. // Flags for fMode
  322. //
  323. #define PF_ABORTED 0x00000001 // Output aborted
  324. #define PF_DOCSTARTED 0x00000002 // Document Started
  325. #define PF_DOC_SENT 0x00000004 // Indicates start doc cmds sent,
  326. // this flag is propagated during a resetPDEV.
  327. #define PF_PAGEPROTECT 0x00000008 // PageProtection
  328. // Set in DrvResetPDEV for not sending cmds that cause page eject.
  329. #define PF_SEND_ONLY_NOEJECT_CMDS 0x00000010
  330. #define PF_NOEMFSPOOL 0x00000020 // No EMF Spooling
  331. #define PF_CCW_ROTATE90 0x00000040 // Rotation is 90 degress ccw
  332. #define PF_ROTATE 0x00000080 // We are doing L->P rotation ourselves since device cannot rotate grx data
  333. #define PF_NO_RELX_MOVE 0x00000100 // No relative X move cmd
  334. #define PF_NO_RELY_MOVE 0x00000200 // No relative Y move cmd
  335. #define PF_NO_XMOVE_CMD 0x00000400 // No X move cmd
  336. #define PF_NO_YMOVE_CMD 0x00000800 // No Y move cmd
  337. #define PF_FORCE_BANDING 0x00001000 // Force banding
  338. #define PF_ENUM_TEXT 0x00002000 // This is a delayed Text Band
  339. #define PF_REPLAY_BAND 0x00004000 // Enumerate the same band again
  340. #define PF_ENUM_GRXTXT 0x00008000 // This is a Graphics/Text Band.
  341. #define PF_RECT_FILL 0x00010000 // device support rect area fill
  342. #define PF_RESTORE_WHITE_ENTRY 0x00020000 // Restore palette Last entry to original color.
  343. #define PF_ANYCOLOR_BRUSH 0x00040000 // Device supports programmable color brush.
  344. #define PF_DOWNLOADED_TEXT 0x00080000 // To indicate we have seen downloaded or device font for the page
  345. #define PF_WHITEBLACK_BRUSH 0x00100000 // To indicate white/black brush selection cmds
  346. #define PF_DOWNLOAD_PATTERN 0x00200000 // To indicate support user defined download patter
  347. #define PF_SHADING_PATTERN 0x00400000 // To indicate support pattern shading
  348. #define PF_SURFACE_USED 0x00800000 // Indicates the bitmap surface has been used
  349. #define PF_RECTWHITE_FILL 0x01000000
  350. #define PF_SURFACE_ERASED 0x02000000 // Indicates entire surface has been cleared
  351. #define PF_RESELECTFONT_AFTER_GRXDATA 0x04000000 // Reset font after Graphics
  352. #define PF_RESELECTFONT_AFTER_XMOVE 0x08000000 // Reset Font after XMOVE
  353. #define PF_RESELECTFONT_AFTER_FF 0x10000000 // Reset Font after FF
  354. #define PF_DEVICE_MANAGED 0x20000000 // Indicates a device surface driver
  355. #define PF_JOB_SENT 0x40000000 // Indicates job cmds sent, this flag is
  356. // propagated during a resetPDEV.
  357. #define PF_SINGLEDOT_FILTER 0x80000000 // Enables filter to expand single pixels
  358. //
  359. // Flags for fMode2
  360. //
  361. #define PF2_MIRRORING_ENABLED 0x00000001 // Indicates to mirror output raster
  362. #define PF2_WRITE_PRINTER_HOOKED 0x00000002 // One of plug-ins hooks WritePrinter
  363. #define PF2_CALLING_OEM_WRITE_PRINTER 0x00000004 // a call to an OEM WRitePrinter is in process
  364. #define PF2_PASSTHROUGH_CALLED_FOR_TTY 0x00000008// DrvEscape with passthrough
  365. // is called for TTY drv.
  366. // TTY driver.
  367. #define PF2_DRVTEXTOUT_CALLED_FOR_TTY 0x00000010 // DrvText is called for TTY.
  368. #define PF2_INVERTED_ROP_MODE 0x00000020 // Indicates ROPs should be inverted for CMY vs RGB
  369. #define PF2_WHITEN_SURFACE 0x00000040 // If you want psoDst to be Whitened when
  370. // psoSrc=STYPE_DEVICE, psoDst=STYPE_BITMAP
  371. // in DrvCopyBits
  372. #define PF2_SURFACE_WHITENED 0x00000080 // Just tells that surface has been whitened
  373. //
  374. // Flags for fYMove
  375. //
  376. #define FYMOVE_FAVOR_LINEFEEDSPACING 0x00000001
  377. #define FYMOVE_SEND_CR_FIRST 0x00000002
  378. //
  379. // MACROS
  380. //
  381. #define VALID_PDEV(pdev) \
  382. ((pdev) && ((pdev) == (pdev)->pvStartSig) && \
  383. ((pdev) == (pdev)->pvEndSig) && \
  384. ((pdev)->ulID == PDEV_ID))
  385. #if DBG
  386. #define ASSERT_VALID_PDEV(pdev) ASSERT(VALID_PDEV(pdev))
  387. #else // ! DBG
  388. #define ASSERT_VALID_PDEV(pdev) \
  389. if (!(VALID_PDEV(pdev))) \
  390. { \
  391. SetLastError(ERROR_INVALID_PARAMETER); \
  392. return 0; \
  393. }
  394. #endif // end !DBG
  395. //
  396. // checks for device managed surface
  397. //
  398. #define DRIVER_DEVICEMANAGED(pPDev) ((pPDev->fMode) & PF_DEVICE_MANAGED)
  399. #ifndef USERMODE_DRIVER
  400. extern HSEMAPHORE ghUniSemaphore;
  401. #define DECLARE_CRITICAL_SECTION HSEMAPHORE ghUniSemaphore
  402. #define INIT_CRITICAL_SECTION() ghUniSemaphore = EngCreateSemaphore()
  403. #define ENTER_CRITICAL_SECTION() EngAcquireSemaphore(ghUniSemaphore)
  404. #define LEAVE_CRITICAL_SECTION() EngReleaseSemaphore(ghUniSemaphore)
  405. #define DELETE_CRITICAL_SECTION() EngDeleteSemaphore(ghUniSemaphore)
  406. #define IS_VALID_DRIVER_SEMAPHORE() (ghUniSemaphore ? TRUE : FALSE)
  407. #else // USERMODE_DRIVER
  408. extern CRITICAL_SECTION gUniCritSection;
  409. #define DECLARE_CRITICAL_SECTION CRITICAL_SECTION gUniCritSection
  410. #define INIT_CRITICAL_SECTION() InitializeCriticalSection(&gUniCritSection)
  411. #define ENTER_CRITICAL_SECTION() EnterCriticalSection(&gUniCritSection)
  412. #define LEAVE_CRITICAL_SECTION() LeaveCriticalSection(&gUniCritSection)
  413. #define DELETE_CRITICAL_SECTION() DeleteCriticalSection(&gUniCritSection)
  414. #endif // USERMODE_DRIVER
  415. #endif // !_PDEV_H_