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.

205 lines
5.3 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: misc.c
  3. *
  4. * Miscellaneous common routines.
  5. *
  6. * Copyright (c) 1992-1995 Microsoft Corporation
  7. *
  8. \**************************************************************************/
  9. #include "precomp.h"
  10. /******************************Public*Routine******************************\
  11. * VOID vResetClipping
  12. \**************************************************************************/
  13. VOID vResetClipping(
  14. PDEV* ppdev)
  15. {
  16. BYTE* pjBase;
  17. pjBase = ppdev->pjBase;
  18. CP_WAIT(ppdev, pjBase);
  19. CP_ABS_WMIN(ppdev, pjBase, 0, 0);
  20. CP_ABS_WMAX(ppdev, pjBase, MAX_COORD, MAX_COORD);
  21. }
  22. /******************************Public*Routine******************************\
  23. * VOID vSetClipping
  24. \**************************************************************************/
  25. VOID vSetClipping(
  26. PDEV* ppdev,
  27. RECTL* prclClip) // In relative coordinates
  28. {
  29. BYTE* pjBase;
  30. pjBase = ppdev->pjBase;
  31. CP_WAIT(ppdev, pjBase);
  32. CP_WMIN(ppdev, pjBase, prclClip->left, prclClip->top);
  33. CP_WMAX(ppdev, pjBase, prclClip->right - 1, prclClip->bottom - 1);
  34. }
  35. /******************************Public*Routine******************************\
  36. * VOID vGetBits
  37. *
  38. * Copies the bits to the given surface from the screen, using the memory
  39. * aperture. Must be pre-clipped.
  40. *
  41. \**************************************************************************/
  42. VOID vGetBits(
  43. PDEV* ppdev,
  44. SURFOBJ* psoDst,
  45. RECTL* prclDst, // Absolute coordinates!
  46. POINTL* pptlSrc) // Absolute coordinates!
  47. {
  48. LONG lSrcDelta;
  49. LONG lDstDelta;
  50. BYTE* pjSrc;
  51. BYTE* pjDst;
  52. LONG cjScan;
  53. LONG cyScan;
  54. LONG cjStartPhase;
  55. LONG cjMiddle;
  56. LONG i;
  57. CP_WAIT(ppdev, ppdev->pjBase);
  58. lSrcDelta = ppdev->lDelta;
  59. pjSrc = ppdev->pjScreen
  60. + (pptlSrc->y * lSrcDelta)
  61. + (pptlSrc->x * ppdev->cjPel);
  62. lDstDelta = psoDst->lDelta;
  63. pjDst = (BYTE*) psoDst->pvScan0
  64. + (prclDst->top * lDstDelta)
  65. + (prclDst->left * ppdev->cjPel);
  66. cjScan = (prclDst->right - prclDst->left) * ppdev->cjPel;
  67. cyScan = (prclDst->bottom - prclDst->top);
  68. // We want to do aligned dword reads from the frame buffer:
  69. cjStartPhase = (LONG)((0 - (LONG_PTR)pjSrc) & 3);
  70. cjMiddle = cjScan - cjStartPhase;
  71. if (cjMiddle < 0)
  72. {
  73. cjStartPhase += cjMiddle;
  74. cjMiddle = 0;
  75. }
  76. lSrcDelta -= cjStartPhase;
  77. lDstDelta -= cjStartPhase;
  78. do {
  79. for (i = cjStartPhase; i > 0; i--)
  80. {
  81. *pjDst++ = *pjSrc++;
  82. }
  83. memcpy(pjDst, pjSrc, cjMiddle);
  84. pjDst += lDstDelta;
  85. pjSrc += lSrcDelta;
  86. } while (--cyScan != 0);
  87. }
  88. /******************************Public*Routine******************************\
  89. * VOID vPutBits
  90. *
  91. * Copies the bits from the given surface to the screen, using the memory
  92. * aperture. Must be pre-clipped.
  93. *
  94. \**************************************************************************/
  95. VOID vPutBits(
  96. PDEV* ppdev,
  97. SURFOBJ* psoSrc,
  98. RECTL* prclDst, // Absolute coordinates!
  99. POINTL* pptlSrc) // Absolute coordinates!
  100. {
  101. LONG lSrcDelta;
  102. LONG lDstDelta;
  103. BYTE* pjSrc;
  104. BYTE* pjDst;
  105. LONG cjScan;
  106. LONG cyScan;
  107. LONG cjStartPhase;
  108. LONG cjMiddle;
  109. LONG i;
  110. CP_WAIT(ppdev, ppdev->pjBase);
  111. lSrcDelta = psoSrc->lDelta;
  112. pjSrc = (BYTE*) psoSrc->pvScan0
  113. + (pptlSrc->y * lSrcDelta)
  114. + (pptlSrc->x * ppdev->cjPel);
  115. lDstDelta = ppdev->lDelta;
  116. pjDst = ppdev->pjScreen
  117. + (prclDst->top * lDstDelta)
  118. + (prclDst->left * ppdev->cjPel);
  119. cjScan = (prclDst->right - prclDst->left) * ppdev->cjPel;
  120. cyScan = (prclDst->bottom - prclDst->top);
  121. // We want to do aligned dword reads from the frame buffer:
  122. cjStartPhase = (LONG)((0 - (LONG_PTR)pjDst) & 3);
  123. cjMiddle = cjScan - cjStartPhase;
  124. if (cjMiddle < 0)
  125. {
  126. cjStartPhase += cjMiddle;
  127. cjMiddle = 0;
  128. }
  129. lSrcDelta -= cjStartPhase;
  130. lDstDelta -= cjStartPhase; // Account for start
  131. do {
  132. for (i = cjStartPhase; i > 0; i--)
  133. {
  134. *pjDst++ = *pjSrc++;
  135. }
  136. memcpy(pjDst, pjSrc, cjMiddle);
  137. pjSrc += lSrcDelta;
  138. pjDst += lDstDelta;
  139. } while (--cyScan != 0);
  140. }
  141. /******************************Public*Routine******************************\
  142. * VOID DrvSynchronize
  143. *
  144. * Waits for all accelerator functions to finish so that GDI can draw
  145. * on the frame buffer.
  146. \**************************************************************************/
  147. VOID DrvSynchronize(
  148. DHPDEV dhpdev,
  149. RECTL* prcl)
  150. {
  151. PDEV* ppdev;
  152. ppdev = (PDEV*) dhpdev;
  153. // !!! Don't think this is true!
  154. //
  155. // We have to synchronize for off-screen device bitmaps as well as the
  156. // screen. Unfortunately, GDI only gives us a 'dhpdev,' not a SURFOBJ
  157. // pointer, so we don't know whether it device bitmap is in off-screen,
  158. // or has been moved to a DIB (because we obviously don't have to
  159. // synchronize the hardware to draw to a DIB). So we'll do extra,
  160. // unneeded synchronization.
  161. if (ppdev->bEnabled)
  162. {
  163. CP_WAIT(ppdev, ppdev->pjBase);
  164. }
  165. }