fbedgeimp.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. *
  3. * Copyright © 2004 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. #ifndef rasterizeSpan
  27. #endif
  28. static void
  29. rasterizeEdges(FbBits * buf,
  30. int width,
  31. int stride, RenderEdge * l, RenderEdge * r, xFixed t, xFixed b)
  32. {
  33. xFixed y = t;
  34. FbBits *line;
  35. line = buf + xFixedToInt(y) * stride;
  36. for (;;) {
  37. xFixed lx, rx;
  38. int lxi, rxi;
  39. /* clip X */
  40. lx = l->x;
  41. if (lx < 0)
  42. lx = 0;
  43. rx = r->x;
  44. if (xFixedToInt(rx) >= width)
  45. rx = IntToxFixed(width);
  46. /* Skip empty (or backwards) sections */
  47. if (rx > lx) {
  48. /* Find pixel bounds for span */
  49. lxi = xFixedToInt(lx);
  50. rxi = xFixedToInt(rx);
  51. #if N_BITS == 1
  52. {
  53. FbBits *a = line;
  54. FbBits startmask, endmask;
  55. int nmiddle;
  56. int width = rxi - lxi;
  57. int x = lxi;
  58. a += x >> FB_SHIFT;
  59. x &= FB_MASK;
  60. FbMaskBits(x, width, startmask, nmiddle, endmask);
  61. if (startmask)
  62. *a++ |= startmask;
  63. while (nmiddle--)
  64. *a++ = FB_ALLONES;
  65. if (endmask)
  66. *a |= endmask;
  67. }
  68. #else
  69. {
  70. DefineAlpha(line, lxi);
  71. int lxs, rxs;
  72. /* Sample coverage for edge pixels */
  73. lxs = RenderSamplesX(lx, N_BITS);
  74. rxs = RenderSamplesX(rx, N_BITS);
  75. /* Add coverage across row */
  76. if (lxi == rxi) {
  77. AddAlpha(rxs - lxs);
  78. }
  79. else {
  80. int xi;
  81. AddAlpha(N_X_FRAC(N_BITS) - lxs);
  82. StepAlpha;
  83. for (xi = lxi + 1; xi < rxi; xi++) {
  84. AddAlpha(N_X_FRAC(N_BITS));
  85. StepAlpha;
  86. }
  87. /* Do not add in a 0 alpha here. This check is necessary
  88. * to avoid a buffer overrun when rx is exactly on a pixel
  89. * boundary.
  90. */
  91. if (rxs != 0)
  92. AddAlpha(rxs);
  93. }
  94. }
  95. #endif
  96. }
  97. if (y == b)
  98. break;
  99. #if N_BITS > 1
  100. if (xFixedFrac(y) != Y_FRAC_LAST(N_BITS)) {
  101. RenderEdgeStepSmall(l);
  102. RenderEdgeStepSmall(r);
  103. y += STEP_Y_SMALL(N_BITS);
  104. }
  105. else
  106. #endif
  107. {
  108. RenderEdgeStepBig(l);
  109. RenderEdgeStepBig(r);
  110. y += STEP_Y_BIG(N_BITS);
  111. line += stride;
  112. }
  113. }
  114. }
  115. #undef rasterizeSpan