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.

240 lines
8.0 KiB

  1. /******************************Module*Header*******************************\
  2. *
  3. * *******************
  4. * * GDI SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: misc.c
  8. *
  9. * Miscellaneous common routines.
  10. *
  11. * Copyright (c) 1992-1998 Microsoft Corporation
  12. *
  13. \**************************************************************************/
  14. #include "precomp.h"
  15. /******************************Public*Table********************************\
  16. * BYTE gaulHwMixFromRop2[]
  17. *
  18. * Table to convert from a Source and Destination Rop2 to the hardware's
  19. * mix.
  20. \**************************************************************************/
  21. ULONG gaulHwMixFromRop2[] = {
  22. LOGICAL_0, // 00 -- 0 BLACKNESS
  23. NOT_SCREEN_AND_NOT_NEW, // 11 -- DSon NOTSRCERASE
  24. SCREEN_AND_NOT_NEW, // 22 -- DSna
  25. NOT_NEW, // 33 -- Sn NOSRCCOPY
  26. NOT_SCREEN_AND_NEW, // 44 -- SDna SRCERASE
  27. NOT_SCREEN, // 55 -- Dn DSTINVERT
  28. SCREEN_XOR_NEW, // 66 -- DSx SRCINVERT
  29. NOT_SCREEN_OR_NOT_NEW, // 77 -- DSan
  30. SCREEN_AND_NEW, // 88 -- DSa SRCAND
  31. NOT_SCREEN_XOR_NEW, // 99 -- DSxn
  32. LEAVE_ALONE, // AA -- D
  33. SCREEN_OR_NOT_NEW, // BB -- DSno MERGEPAINT
  34. OVERPAINT, // CC -- S SRCCOPY
  35. NOT_SCREEN_OR_NEW, // DD -- SDno
  36. SCREEN_OR_NEW, // EE -- DSo SRCPAINT
  37. LOGICAL_1 // FF -- 1 WHITENESS
  38. };
  39. /******************************Public*Table********************************\
  40. * BYTE gajHwMixFromMix[]
  41. *
  42. * Table to convert from a GDI mix value to the hardware's mix.
  43. *
  44. * Ordered so that the mix may be calculated from gajHwMixFromMix[mix & 0xf]
  45. * or gajHwMixFromMix[mix & 0xff].
  46. \**************************************************************************/
  47. BYTE gajHwMixFromMix[] = {
  48. LOGICAL_1, // 0 -- 1
  49. LOGICAL_0, // 1 -- 0
  50. NOT_SCREEN_AND_NOT_NEW, // 2 -- DPon
  51. SCREEN_AND_NOT_NEW, // 3 -- DPna
  52. NOT_NEW, // 4 -- Pn
  53. NOT_SCREEN_AND_NEW, // 5 -- PDna
  54. NOT_SCREEN, // 6 -- Dn
  55. SCREEN_XOR_NEW, // 7 -- DPx
  56. NOT_SCREEN_OR_NOT_NEW, // 8 -- DPan
  57. SCREEN_AND_NEW, // 9 -- DPa
  58. NOT_SCREEN_XOR_NEW, // 10 -- DPxn
  59. LEAVE_ALONE, // 11 -- D
  60. SCREEN_OR_NOT_NEW, // 12 -- DPno
  61. OVERPAINT, // 13 -- P
  62. NOT_SCREEN_OR_NEW, // 14 -- PDno
  63. SCREEN_OR_NEW, // 15 -- DPo
  64. LOGICAL_1 // 16 -- 1
  65. };
  66. /******************************Public*Data*********************************\
  67. * MIX translation table
  68. *
  69. * Translates a mix 1-16, into an old style Rop 0-255.
  70. *
  71. \**************************************************************************/
  72. BYTE gaRop3FromMix[] =
  73. {
  74. 0xFF, // R2_WHITE - Allow rop = gaRop3FromMix[mix & 0x0F]
  75. 0x00, // R2_BLACK
  76. 0x05, // R2_NOTMERGEPEN
  77. 0x0A, // R2_MASKNOTPEN
  78. 0x0F, // R2_NOTCOPYPEN
  79. 0x50, // R2_MASKPENNOT
  80. 0x55, // R2_NOT
  81. 0x5A, // R2_XORPEN
  82. 0x5F, // R2_NOTMASKPEN
  83. 0xA0, // R2_MASKPEN
  84. 0xA5, // R2_NOTXORPEN
  85. 0xAA, // R2_NOP
  86. 0xAF, // R2_MERGENOTPEN
  87. 0xF0, // R2_COPYPEN
  88. 0xF5, // R2_MERGEPENNOT
  89. 0xFA, // R2_MERGEPEN
  90. 0xFF // R2_WHITE - Allow rop = gaRop3FromMix[mix & 0xFF]
  91. };
  92. /******************************Public*Routine******************************\
  93. * BOOL bIntersect
  94. *
  95. * If 'prcl1' and 'prcl2' intersect, has a return value of TRUE and returns
  96. * the intersection in 'prclResult'. If they don't intersect, has a return
  97. * value of FALSE, and 'prclResult' is undefined.
  98. *
  99. \**************************************************************************/
  100. BOOL bIntersect(
  101. RECTL* prcl1,
  102. RECTL* prcl2,
  103. RECTL* prclResult)
  104. {
  105. prclResult->left = max(prcl1->left, prcl2->left);
  106. prclResult->right = min(prcl1->right, prcl2->right);
  107. if (prclResult->left < prclResult->right)
  108. {
  109. prclResult->top = max(prcl1->top, prcl2->top);
  110. prclResult->bottom = min(prcl1->bottom, prcl2->bottom);
  111. if (prclResult->top < prclResult->bottom)
  112. {
  113. return(TRUE);
  114. }
  115. }
  116. return(FALSE);
  117. }
  118. /******************************Public*Routine******************************\
  119. * LONG cIntersect
  120. *
  121. * This routine takes a list of rectangles from 'prclIn' and clips them
  122. * in-place to the rectangle 'prclClip'. The input rectangles don't
  123. * have to intersect 'prclClip'; the return value will reflect the
  124. * number of input rectangles that did intersect, and the intersecting
  125. * rectangles will be densely packed.
  126. *
  127. \**************************************************************************/
  128. LONG cIntersect(
  129. RECTL* prclClip,
  130. RECTL* prclIn, // List of rectangles
  131. LONG c) // Can be zero
  132. {
  133. LONG cIntersections;
  134. RECTL* prclOut;
  135. cIntersections = 0;
  136. prclOut = prclIn;
  137. for (; c != 0; prclIn++, c--)
  138. {
  139. prclOut->left = max(prclIn->left, prclClip->left);
  140. prclOut->right = min(prclIn->right, prclClip->right);
  141. if (prclOut->left < prclOut->right)
  142. {
  143. prclOut->top = max(prclIn->top, prclClip->top);
  144. prclOut->bottom = min(prclIn->bottom, prclClip->bottom);
  145. if (prclOut->top < prclOut->bottom)
  146. {
  147. prclOut++;
  148. cIntersections++;
  149. }
  150. }
  151. }
  152. return(cIntersections);
  153. }
  154. /******************************Public*Routine******************************\
  155. * VOID vResetClipping
  156. \**************************************************************************/
  157. VOID vResetClipping(
  158. PDEV* ppdev)
  159. {
  160. IO_FIFO_WAIT(ppdev, 4);
  161. IO_ABS_SCISSORS_L(ppdev, 0);
  162. IO_ABS_SCISSORS_T(ppdev, 0);
  163. IO_ABS_SCISSORS_R(ppdev, ppdev->cxMemory - 1);
  164. IO_ABS_SCISSORS_B(ppdev, ppdev->cyMemory - 1);
  165. }
  166. /******************************Public*Routine******************************\
  167. * VOID vSetClipping
  168. \**************************************************************************/
  169. VOID vSetClipping(
  170. PDEV* ppdev,
  171. RECTL* prclClip) // In relative coordinates
  172. {
  173. LONG xOffset;
  174. LONG yOffset;
  175. ASSERTDD(prclClip->left + ppdev->xOffset >= 0,
  176. "Can't have a negative left!");
  177. ASSERTDD(prclClip->top + ppdev->yOffset >= 0,
  178. "Can't have a negative top!");
  179. IO_FIFO_WAIT(ppdev, 4);
  180. xOffset = ppdev->xOffset;
  181. IO_ABS_SCISSORS_L(ppdev, prclClip->left + xOffset);
  182. IO_ABS_SCISSORS_R(ppdev, prclClip->right - 1 + xOffset);
  183. yOffset = ppdev->yOffset;
  184. IO_ABS_SCISSORS_T(ppdev, prclClip->top + yOffset);
  185. IO_ABS_SCISSORS_B(ppdev, prclClip->bottom - 1 + yOffset);
  186. }
  187. /******************************Public*Routine******************************\
  188. * VOID DrvSynchronize
  189. *
  190. * This routine is called by GDI to synchronize on the accelerator before
  191. * it draws directly to the driver's surface. This function must be hooked
  192. * by the driver when:
  193. *
  194. * 1. The primary surface is a GDI-managed surface, which simply means
  195. * that GDI can directly draw on the primary surface. This happens
  196. * when DrvEnableSurface returns a handle created by EngCreateBitmap
  197. * instead of EngCreateDeviceSurface.
  198. *
  199. * 2. A device-bitmap is made into a GDI-managed surface by calling
  200. * EngModifySurface with a pointer directly to the bits.
  201. *
  202. \**************************************************************************/
  203. VOID DrvSynchronize(
  204. IN DHPDEV dhpdev,
  205. IN RECTL *prcl)
  206. {
  207. PDEV *ppdev = (PDEV *)dhpdev;
  208. IO_GP_WAIT(ppdev);
  209. }