fbline.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. void
  28. fbZeroLine(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt, DDXPointPtr ppt)
  29. {
  30. int x1, y1, x2, y2;
  31. int x, y;
  32. int dashOffset;
  33. x = pDrawable->x;
  34. y = pDrawable->y;
  35. x1 = ppt->x;
  36. y1 = ppt->y;
  37. dashOffset = pGC->dashOffset;
  38. while (--npt) {
  39. ++ppt;
  40. x2 = ppt->x;
  41. y2 = ppt->y;
  42. if (mode == CoordModePrevious) {
  43. x2 += x1;
  44. y2 += y1;
  45. }
  46. fbSegment(pDrawable, pGC, x1 + x, y1 + y,
  47. x2 + x, y2 + y,
  48. npt == 1 && pGC->capStyle != CapNotLast, &dashOffset);
  49. x1 = x2;
  50. y1 = y2;
  51. }
  52. }
  53. void
  54. fbZeroSegment(DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment * pSegs)
  55. {
  56. int dashOffset;
  57. int x, y;
  58. Bool drawLast = pGC->capStyle != CapNotLast;
  59. x = pDrawable->x;
  60. y = pDrawable->y;
  61. while (nseg--) {
  62. dashOffset = pGC->dashOffset;
  63. fbSegment(pDrawable, pGC,
  64. pSegs->x1 + x, pSegs->y1 + y,
  65. pSegs->x2 + x, pSegs->y2 + y, drawLast, &dashOffset);
  66. pSegs++;
  67. }
  68. }
  69. void
  70. fbFixCoordModePrevious(int npt, DDXPointPtr ppt)
  71. {
  72. int x, y;
  73. x = ppt->x;
  74. y = ppt->y;
  75. npt--;
  76. while (npt--) {
  77. ppt++;
  78. x = (ppt->x += x);
  79. y = (ppt->y += y);
  80. }
  81. }
  82. void
  83. fbPolyLine(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt, DDXPointPtr ppt)
  84. {
  85. void (*line) (DrawablePtr, GCPtr, int mode, int npt, DDXPointPtr ppt);
  86. if (pGC->lineWidth == 0) {
  87. line = fbZeroLine;
  88. if (pGC->fillStyle == FillSolid &&
  89. pGC->lineStyle == LineSolid &&
  90. REGION_NUM_RECTS(fbGetCompositeClip(pGC)) == 1) {
  91. switch (pDrawable->bitsPerPixel) {
  92. case 8:
  93. line = fbPolyline8;
  94. break;
  95. case 16:
  96. line = fbPolyline16;
  97. break;
  98. case 24:
  99. line = fbPolyline24;
  100. break;
  101. case 32:
  102. line = fbPolyline32;
  103. break;
  104. }
  105. }
  106. }
  107. else {
  108. if (pGC->lineStyle != LineSolid)
  109. line = miWideDash;
  110. else
  111. line = miWideLine;
  112. }
  113. (*line) (pDrawable, pGC, mode, npt, ppt);
  114. }
  115. void
  116. fbPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment * pseg)
  117. {
  118. void (*seg) (DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment * pseg);
  119. if (pGC->lineWidth == 0) {
  120. seg = fbZeroSegment;
  121. if (pGC->fillStyle == FillSolid &&
  122. pGC->lineStyle == LineSolid &&
  123. REGION_NUM_RECTS(fbGetCompositeClip(pGC)) == 1) {
  124. switch (pDrawable->bitsPerPixel) {
  125. case 8:
  126. seg = fbPolySegment8;
  127. break;
  128. case 16:
  129. seg = fbPolySegment16;
  130. break;
  131. case 24:
  132. seg = fbPolySegment24;
  133. break;
  134. case 32:
  135. seg = fbPolySegment32;
  136. break;
  137. }
  138. }
  139. }
  140. else {
  141. seg = miPolySegment;
  142. }
  143. (*seg) (pDrawable, pGC, nseg, pseg);
  144. }