fbpoint.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright © 1998 Keith Packard
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and its
  5. * documentation for any purpose is hereby granted without fee, provided that
  6. * the above copyright notice appear in all copies and that both that
  7. * copyright notice and this permission notice appear in supporting
  8. * documentation, and that the name of Keith Packard not be used in
  9. * advertising or publicity pertaining to distribution of the software without
  10. * specific, written prior permission. Keith Packard makes no
  11. * representations about the suitability of this software for any purpose. It
  12. * is provided "as is" without express or implied warranty.
  13. *
  14. * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16. * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  20. * PERFORMANCE OF THIS SOFTWARE.
  21. */
  22. #ifdef HAVE_DIX_CONFIG_H
  23. #include <dix-config.h>
  24. #endif
  25. #include "fb.h"
  26. typedef void (*FbDots) (FbBits * dst,
  27. FbStride dstStride,
  28. int dstBpp,
  29. BoxPtr pBox,
  30. xPoint * pts,
  31. int npt,
  32. int xorg,
  33. int yorg, int xoff, int yoff, FbBits and, FbBits xor);
  34. void
  35. fbDots(FbBits * dstOrig,
  36. FbStride dstStride,
  37. int dstBpp,
  38. BoxPtr pBox,
  39. xPoint * pts,
  40. int npt,
  41. int xorg, int yorg, int xoff, int yoff, FbBits andOrig, FbBits xorOrig)
  42. {
  43. FbStip *dst = (FbStip *) dstOrig;
  44. int x1, y1, x2, y2;
  45. int x, y;
  46. FbStip *d;
  47. FbStip and = andOrig;
  48. FbStip xor = xorOrig;
  49. dstStride = FbBitsStrideToStipStride(dstStride);
  50. x1 = pBox->x1;
  51. y1 = pBox->y1;
  52. x2 = pBox->x2;
  53. y2 = pBox->y2;
  54. while (npt--) {
  55. x = pts->x + xorg;
  56. y = pts->y + yorg;
  57. pts++;
  58. if (x1 <= x && x < x2 && y1 <= y && y < y2) {
  59. x = (x + xoff) * dstBpp;
  60. d = dst + ((y + yoff) * dstStride) + (x >> FB_STIP_SHIFT);
  61. x &= FB_STIP_MASK;
  62. if (dstBpp == 24) {
  63. FbStip leftMask, rightMask;
  64. int n, rot;
  65. FbStip andT, xorT;
  66. rot = FbFirst24Rot(x);
  67. andT = FbRot24Stip(and, rot);
  68. xorT = FbRot24Stip(xor, rot);
  69. FbMaskStip(x, 24, leftMask, n, rightMask);
  70. if (leftMask) {
  71. WRITE(d, FbDoMaskRRop(READ(d), andT, xorT, leftMask));
  72. andT = FbNext24Stip(andT);
  73. xorT = FbNext24Stip(xorT);
  74. d++;
  75. }
  76. if (rightMask)
  77. WRITE(d, FbDoMaskRRop(READ(d), andT, xorT, rightMask));
  78. }
  79. else {
  80. FbStip mask;
  81. mask = FbStipMask(x, dstBpp);
  82. WRITE(d, FbDoMaskRRop(READ(d), and, xor, mask));
  83. }
  84. }
  85. }
  86. }
  87. void
  88. fbPolyPoint(DrawablePtr pDrawable,
  89. GCPtr pGC, int mode, int nptInit, xPoint * pptInit)
  90. {
  91. FbGCPrivPtr pPriv = fbGetGCPrivate(pGC);
  92. RegionPtr pClip = fbGetCompositeClip(pGC);
  93. FbBits *dst;
  94. FbStride dstStride;
  95. int dstBpp;
  96. int dstXoff, dstYoff;
  97. FbDots dots;
  98. FbBits and, xor;
  99. xPoint *ppt;
  100. int npt;
  101. BoxPtr pBox;
  102. int nBox;
  103. /* make pointlist origin relative */
  104. ppt = pptInit;
  105. npt = nptInit;
  106. if (mode == CoordModePrevious) {
  107. npt--;
  108. while (npt--) {
  109. ppt++;
  110. ppt->x += (ppt - 1)->x;
  111. ppt->y += (ppt - 1)->y;
  112. }
  113. }
  114. fbGetDrawable(pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
  115. and = pPriv->and;
  116. xor = pPriv->xor;
  117. dots = fbDots;
  118. switch (dstBpp) {
  119. case 8:
  120. dots = fbDots8;
  121. break;
  122. case 16:
  123. dots = fbDots16;
  124. break;
  125. case 24:
  126. dots = fbDots24;
  127. break;
  128. case 32:
  129. dots = fbDots32;
  130. break;
  131. }
  132. for (nBox = RegionNumRects(pClip), pBox = RegionRects(pClip);
  133. nBox--; pBox++)
  134. (*dots) (dst, dstStride, dstBpp, pBox, pptInit, nptInit,
  135. pDrawable->x, pDrawable->y, dstXoff, dstYoff, and, xor);
  136. fbFinishAccess(pDrawable);
  137. }