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.

277 lines
8.9 KiB

  1. /******************************Module*Header*******************************\
  2. *
  3. * *******************
  4. * * GDI SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: screen.c
  8. *
  9. * Initializes the GDIINFO and DEVINFO structures for DrvEnablePDEV.
  10. *
  11. * Copyright (c) 1992-1998 Microsoft Corporation
  12. \**************************************************************************/
  13. #include "driver.h"
  14. #define SYSTM_LOGFONT {16,7,0,0,700,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,VARIABLE_PITCH | FF_DONTCARE,L"System"}
  15. #define HELVE_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_STROKE_PRECIS,PROOF_QUALITY,VARIABLE_PITCH | FF_DONTCARE,L"MS Sans Serif"}
  16. #define COURI_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_STROKE_PRECIS,PROOF_QUALITY,FIXED_PITCH | FF_DONTCARE, L"Courier"}
  17. // This is the basic devinfo for a default driver. This is used as a base and customized based
  18. // on information passed back from the miniport driver.
  19. const DEVINFO gDevInfoFrameBuffer = {
  20. ( GCAPS_OPAQUERECT
  21. | GCAPS_LAYERED
  22. ), /* Graphics capabilities */
  23. SYSTM_LOGFONT, /* Default font description */
  24. HELVE_LOGFONT, /* ANSI variable font description */
  25. COURI_LOGFONT, /* ANSI fixed font description */
  26. 0, /* Count of device fonts */
  27. 0, /* Preferred DIB format */
  28. 8, /* Width of color dither */
  29. 8, /* Height of color dither */
  30. 0 /* Default palette to use for this device */
  31. };
  32. // This is default palette from Win 3.1
  33. #define NUMPALCOLORS 256
  34. #define NUMPALRESERVED 20
  35. ULONG palColors[NUMPALCOLORS][4] =
  36. {
  37. { 0, 0, 0, 0 }, // 0
  38. { 0x80,0, 0, 0 }, // 1
  39. { 0, 0x80,0, 0 }, // 2
  40. { 0x80,0x80,0, 0 }, // 3
  41. { 0, 0, 0x80,0 }, // 4
  42. { 0x80,0, 0x80,0 }, // 5
  43. { 0, 0x80,0x80,0 }, // 6
  44. { 0xC0,0xC0,0xC0,0 }, // 7
  45. { 192, 220, 192, 0 }, // 8
  46. { 166, 202, 240, 0 }, // 9
  47. { 255, 251, 240, 0 }, // 10
  48. { 160, 160, 164, 0 }, // 11
  49. { 0x80,0x80,0x80,0 }, // 12
  50. { 0xFF,0, 0, 0 }, // 13
  51. { 0, 0xFF,0, 0 }, // 14
  52. { 0xFF,0xFF,0, 0 }, // 15
  53. { 0, 0, 0xFF,0 }, // 16
  54. { 0xFF,0, 0xFF,0 }, // 17
  55. { 0, 0xFF,0xFF,0 }, // 18
  56. { 0xFF,0xFF,0xFF,0 } // 19
  57. };
  58. /******************************Public*Routine******************************\
  59. * bInitPDEV
  60. *
  61. * Determine the mode we should be in based on the DEVMODE passed in.
  62. * For mirrored devices we don't bother querying the miniport.
  63. *
  64. \**************************************************************************/
  65. BOOL bInitPDEV(
  66. PPDEV ppdev,
  67. DEVMODEW *pDevMode,
  68. GDIINFO *pGdiInfo,
  69. DEVINFO *pDevInfo)
  70. {
  71. ULONG cModes;
  72. PVIDEO_MODE_INFORMATION pVideoBuffer, pVideoModeSelected, pVideoTemp;
  73. VIDEO_COLOR_CAPABILITIES colorCapabilities;
  74. ULONG ulTemp;
  75. BOOL bSelectDefault;
  76. ULONG cbModeSize;
  77. ULONG red, green, blue;
  78. INT i;
  79. //
  80. // Fill in the GDIINFO data structure with the information returned from
  81. // the kernel driver.
  82. //
  83. ppdev->ulMode = 0;
  84. ppdev->cxScreen = pDevMode->dmPelsWidth;
  85. ppdev->cyScreen = pDevMode->dmPelsHeight;
  86. ppdev->ulBitCount = pDevMode->dmBitsPerPel;
  87. ppdev->lDeltaScreen = 0;
  88. ppdev->flRed = 0x00FF0000;
  89. ppdev->flGreen = 0x000FF00;
  90. ppdev->flBlue = 0x00000FF;
  91. pGdiInfo->ulVersion = GDI_DRIVER_VERSION;
  92. pGdiInfo->ulTechnology = DT_RASDISPLAY;
  93. pGdiInfo->ulHorzSize = 0;
  94. pGdiInfo->ulVertSize = 0;
  95. pGdiInfo->ulHorzRes = ppdev->cxScreen;
  96. pGdiInfo->ulVertRes = ppdev->cyScreen;
  97. pGdiInfo->ulPanningHorzRes = 0;
  98. pGdiInfo->ulPanningVertRes = 0;
  99. pGdiInfo->cBitsPixel = 8;
  100. pGdiInfo->cPlanes = 1;
  101. pGdiInfo->ulVRefresh = 1; // not used
  102. pGdiInfo->ulBltAlignment = 1; // We don't have accelerated screen-
  103. // to-screen blts, and any
  104. // window alignment is okay
  105. pGdiInfo->ulLogPixelsX = pDevMode->dmLogPixels;
  106. pGdiInfo->ulLogPixelsY = pDevMode->dmLogPixels;
  107. pGdiInfo->flTextCaps = TC_RA_ABLE;
  108. pGdiInfo->flRaster = 0; // flRaster is reserved by DDI
  109. pGdiInfo->ulDACRed = 8;
  110. pGdiInfo->ulDACGreen = 8;
  111. pGdiInfo->ulDACBlue = 8;
  112. pGdiInfo->ulAspectX = 0x24; // One-to-one aspect ratio
  113. pGdiInfo->ulAspectY = 0x24;
  114. pGdiInfo->ulAspectXY = 0x33;
  115. pGdiInfo->xStyleStep = 1; // A style unit is 3 pels
  116. pGdiInfo->yStyleStep = 1;
  117. pGdiInfo->denStyleStep = 3;
  118. pGdiInfo->ptlPhysOffset.x = 0;
  119. pGdiInfo->ptlPhysOffset.y = 0;
  120. pGdiInfo->szlPhysSize.cx = 0;
  121. pGdiInfo->szlPhysSize.cy = 0;
  122. // RGB and CMY color info.
  123. pGdiInfo->ciDevice.Red.x = 6700;
  124. pGdiInfo->ciDevice.Red.y = 3300;
  125. pGdiInfo->ciDevice.Red.Y = 0;
  126. pGdiInfo->ciDevice.Green.x = 2100;
  127. pGdiInfo->ciDevice.Green.y = 7100;
  128. pGdiInfo->ciDevice.Green.Y = 0;
  129. pGdiInfo->ciDevice.Blue.x = 1400;
  130. pGdiInfo->ciDevice.Blue.y = 800;
  131. pGdiInfo->ciDevice.Blue.Y = 0;
  132. pGdiInfo->ciDevice.AlignmentWhite.x = 3127;
  133. pGdiInfo->ciDevice.AlignmentWhite.y = 3290;
  134. pGdiInfo->ciDevice.AlignmentWhite.Y = 0;
  135. pGdiInfo->ciDevice.RedGamma = 20000;
  136. pGdiInfo->ciDevice.GreenGamma = 20000;
  137. pGdiInfo->ciDevice.BlueGamma = 20000;
  138. pGdiInfo->ciDevice.Cyan.x = 0;
  139. pGdiInfo->ciDevice.Cyan.y = 0;
  140. pGdiInfo->ciDevice.Cyan.Y = 0;
  141. pGdiInfo->ciDevice.Magenta.x = 0;
  142. pGdiInfo->ciDevice.Magenta.y = 0;
  143. pGdiInfo->ciDevice.Magenta.Y = 0;
  144. pGdiInfo->ciDevice.Yellow.x = 0;
  145. pGdiInfo->ciDevice.Yellow.y = 0;
  146. pGdiInfo->ciDevice.Yellow.Y = 0;
  147. // No dye correction for raster displays.
  148. pGdiInfo->ciDevice.MagentaInCyanDye = 0;
  149. pGdiInfo->ciDevice.YellowInCyanDye = 0;
  150. pGdiInfo->ciDevice.CyanInMagentaDye = 0;
  151. pGdiInfo->ciDevice.YellowInMagentaDye = 0;
  152. pGdiInfo->ciDevice.CyanInYellowDye = 0;
  153. pGdiInfo->ciDevice.MagentaInYellowDye = 0;
  154. pGdiInfo->ulDevicePelsDPI = 0; // For printers only
  155. pGdiInfo->ulPrimaryOrder = PRIMARY_ORDER_CBA;
  156. // Note: this should be modified later to take into account the size
  157. // of the display and the resolution.
  158. pGdiInfo->ulHTPatternSize = HT_PATSIZE_4x4_M;
  159. pGdiInfo->flHTFlags = HT_FLAG_ADDITIVE_PRIMS;
  160. // Fill in the basic devinfo structure
  161. *pDevInfo = gDevInfoFrameBuffer;
  162. // Fill in the rest of the devinfo and GdiInfo structures.
  163. if (ppdev->ulBitCount == 8)
  164. {
  165. // It is Palette Managed.
  166. pGdiInfo->ulNumColors = 20;
  167. pGdiInfo->ulNumPalReg = 1 << ppdev->ulBitCount;
  168. pDevInfo->flGraphicsCaps |= (GCAPS_PALMANAGED | GCAPS_COLOR_DITHER);
  169. pGdiInfo->ulHTOutputFormat = HT_FORMAT_8BPP;
  170. pDevInfo->iDitherFormat = BMF_8BPP;
  171. // Assuming palette is orthogonal - all colors are same size.
  172. ppdev->cPaletteShift = 8 - pGdiInfo->ulDACRed;
  173. }
  174. else
  175. {
  176. pGdiInfo->ulNumColors = (ULONG) (-1);
  177. pGdiInfo->ulNumPalReg = 0;
  178. if (ppdev->ulBitCount == 16)
  179. {
  180. pGdiInfo->ulHTOutputFormat = HT_FORMAT_16BPP;
  181. pDevInfo->iDitherFormat = BMF_16BPP;
  182. }
  183. else if (ppdev->ulBitCount == 24)
  184. {
  185. pGdiInfo->ulHTOutputFormat = HT_FORMAT_24BPP;
  186. pDevInfo->iDitherFormat = BMF_24BPP;
  187. }
  188. else
  189. {
  190. pGdiInfo->ulHTOutputFormat = HT_FORMAT_32BPP;
  191. pDevInfo->iDitherFormat = BMF_32BPP;
  192. }
  193. }
  194. // create remaining palette entries, simple loop to create uniformly
  195. // distributed color values.
  196. red = 0, green = 0, blue = 0;
  197. for (i = NUMPALRESERVED; i < NUMPALCOLORS; i++) {
  198. palColors[i][0] = red;
  199. palColors[i][1] = green;
  200. palColors[i][2] = blue;
  201. palColors[i][3] = 0;
  202. if (!(red += 32))
  203. if (!(green += 32))
  204. blue += 64;
  205. }
  206. if (ppdev->ulBitCount == 8)
  207. {
  208. pDevInfo->hpalDefault = ppdev->hpalDefault =
  209. EngCreatePalette(PAL_INDEXED,
  210. NUMPALCOLORS, // cColors
  211. (ULONG*)&palColors[0], // pulColors
  212. 0,
  213. 0,
  214. 0); // flRed, flGreen, flBlue [not used]
  215. }
  216. else
  217. {
  218. pDevInfo->hpalDefault = ppdev->hpalDefault =
  219. EngCreatePalette(PAL_BITFIELDS, 0,NULL,
  220. ppdev->flRed,ppdev->flBlue,ppdev->flGreen);
  221. }
  222. return(TRUE);
  223. }