fbpoint.c 4.4 KB

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