fbfill.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. fbFill(DrawablePtr pDrawable, GCPtr pGC, int x, int y, int width, int height)
  29. {
  30. FbBits *dst;
  31. FbStride dstStride;
  32. int dstBpp;
  33. int dstXoff, dstYoff;
  34. FbGCPrivPtr pPriv = fbGetGCPrivate(pGC);
  35. fbGetDrawable(pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
  36. switch (pGC->fillStyle) {
  37. case FillSolid:
  38. fbSolid(dst + (y + dstYoff) * dstStride,
  39. dstStride,
  40. (x + dstXoff) * dstBpp,
  41. dstBpp, width * dstBpp, height, pPriv->and, pPriv->xor);
  42. break;
  43. case FillStippled:
  44. case FillOpaqueStippled:{
  45. PixmapPtr pStip = pGC->stipple;
  46. int stipWidth = pStip->drawable.width;
  47. int stipHeight = pStip->drawable.height;
  48. if (dstBpp == 1) {
  49. int alu;
  50. FbBits *stip;
  51. FbStride stipStride;
  52. int stipBpp;
  53. int stipXoff _X_UNUSED, stipYoff _X_UNUSED;
  54. if (pGC->fillStyle == FillStippled)
  55. alu = FbStipple1Rop(pGC->alu, pGC->fgPixel);
  56. else
  57. alu = FbOpaqueStipple1Rop(pGC->alu, pGC->fgPixel, pGC->bgPixel);
  58. fbGetDrawable(&pStip->drawable, stip, stipStride, stipBpp, stipXoff,
  59. stipYoff);
  60. fbTile(dst + (y + dstYoff) * dstStride, dstStride, x + dstXoff,
  61. width, height, stip, stipStride, stipWidth, stipHeight, alu,
  62. pPriv->pm, dstBpp, (pGC->patOrg.x + pDrawable->x + dstXoff),
  63. pGC->patOrg.y + pDrawable->y - y);
  64. }
  65. else {
  66. FbStip *stip;
  67. FbStride stipStride;
  68. int stipBpp;
  69. int stipXoff _X_UNUSED, stipYoff _X_UNUSED;
  70. FbBits fgand, fgxor, bgand, bgxor;
  71. fgand = pPriv->and;
  72. fgxor = pPriv->xor;
  73. if (pGC->fillStyle == FillStippled) {
  74. bgand = fbAnd(GXnoop, (FbBits) 0, FB_ALLONES);
  75. bgxor = fbXor(GXnoop, (FbBits) 0, FB_ALLONES);
  76. }
  77. else {
  78. bgand = pPriv->bgand;
  79. bgxor = pPriv->bgxor;
  80. }
  81. fbGetStipDrawable(&pStip->drawable, stip, stipStride, stipBpp,
  82. stipXoff, stipYoff);
  83. fbStipple(dst + (y + dstYoff) * dstStride, dstStride,
  84. (x + dstXoff) * dstBpp, dstBpp, width * dstBpp, height,
  85. stip, stipStride, stipWidth, stipHeight,
  86. pPriv->evenStipple, fgand, fgxor, bgand, bgxor,
  87. pGC->patOrg.x + pDrawable->x + dstXoff,
  88. pGC->patOrg.y + pDrawable->y - y);
  89. }
  90. break;
  91. }
  92. case FillTiled:{
  93. PixmapPtr pTile = pGC->tile.pixmap;
  94. FbBits *tile;
  95. FbStride tileStride;
  96. int tileBpp;
  97. int tileWidth;
  98. int tileHeight;
  99. int tileXoff _X_UNUSED, tileYoff _X_UNUSED; /* XXX assumed to be zero */
  100. fbGetDrawable(&pTile->drawable, tile, tileStride, tileBpp, tileXoff,
  101. tileYoff);
  102. tileWidth = pTile->drawable.width;
  103. tileHeight = pTile->drawable.height;
  104. fbTile(dst + (y + dstYoff) * dstStride,
  105. dstStride,
  106. (x + dstXoff) * dstBpp,
  107. width * dstBpp, height,
  108. tile,
  109. tileStride,
  110. tileWidth * tileBpp,
  111. tileHeight,
  112. pGC->alu,
  113. pPriv->pm,
  114. dstBpp,
  115. (pGC->patOrg.x + pDrawable->x + dstXoff) * dstBpp,
  116. pGC->patOrg.y + pDrawable->y - y);
  117. break;
  118. }
  119. }
  120. fbValidateDrawable(pDrawable);
  121. }
  122. void
  123. fbSolidBoxClipped(DrawablePtr pDrawable,
  124. RegionPtr pClip,
  125. int x1, int y1, int x2, int y2, FbBits and, FbBits xor)
  126. {
  127. FbBits *dst;
  128. FbStride dstStride;
  129. int dstBpp;
  130. int dstXoff, dstYoff;
  131. BoxPtr pbox;
  132. int nbox;
  133. int partX1, partX2, partY1, partY2;
  134. fbGetDrawable(pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
  135. for (nbox = REGION_NUM_RECTS(pClip), pbox = REGION_RECTS(pClip);
  136. nbox--; pbox++) {
  137. partX1 = pbox->x1;
  138. if (partX1 < x1)
  139. partX1 = x1;
  140. partX2 = pbox->x2;
  141. if (partX2 > x2)
  142. partX2 = x2;
  143. if (partX2 <= partX1)
  144. continue;
  145. partY1 = pbox->y1;
  146. if (partY1 < y1)
  147. partY1 = y1;
  148. partY2 = pbox->y2;
  149. if (partY2 > y2)
  150. partY2 = y2;
  151. if (partY2 <= partY1)
  152. continue;
  153. fbSolid(dst + (partY1 + dstYoff) * dstStride,
  154. dstStride,
  155. (partX1 + dstXoff) * dstBpp,
  156. dstBpp,
  157. (partX2 - partX1) * dstBpp, (partY2 - partY1), and, xor);
  158. }
  159. }