fbpush.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. fbPushPattern(DrawablePtr pDrawable,
  29. GCPtr pGC,
  30. FbStip * src,
  31. FbStride srcStride, int srcX, int x, int y, int width, int height)
  32. {
  33. FbStip *s, bitsMask, bitsMask0, bits;
  34. int xspan;
  35. int w;
  36. int lenspan;
  37. src += srcX >> FB_STIP_SHIFT;
  38. srcX &= FB_STIP_MASK;
  39. bitsMask0 = FbStipMask(srcX, 1);
  40. while (height--) {
  41. bitsMask = bitsMask0;
  42. w = width;
  43. s = src;
  44. src += srcStride;
  45. bits = *s++;
  46. xspan = x;
  47. while (w) {
  48. if (bits & bitsMask) {
  49. lenspan = 0;
  50. do {
  51. lenspan++;
  52. if (lenspan == w)
  53. break;
  54. bitsMask = FbStipRight(bitsMask, 1);
  55. if (!bitsMask) {
  56. bits = *s++;
  57. bitsMask = FbBitsMask(0, 1);
  58. }
  59. } while (bits & bitsMask);
  60. fbFill(pDrawable, pGC, xspan, y, lenspan, 1);
  61. xspan += lenspan;
  62. w -= lenspan;
  63. }
  64. else {
  65. do {
  66. w--;
  67. xspan++;
  68. if (!w)
  69. break;
  70. bitsMask = FbStipRight(bitsMask, 1);
  71. if (!bitsMask) {
  72. bits = *s++;
  73. bitsMask = FbBitsMask(0, 1);
  74. }
  75. } while (!(bits & bitsMask));
  76. }
  77. }
  78. y++;
  79. }
  80. }
  81. void
  82. fbPushFill(DrawablePtr pDrawable,
  83. GCPtr pGC,
  84. FbStip * src,
  85. FbStride srcStride, int srcX, int x, int y, int width, int height)
  86. {
  87. FbGCPrivPtr pPriv = fbGetGCPrivate(pGC);
  88. if (pGC->fillStyle == FillSolid) {
  89. FbBits *dst;
  90. FbStride dstStride;
  91. int dstBpp;
  92. int dstXoff, dstYoff;
  93. int dstX;
  94. int dstWidth;
  95. fbGetDrawable(pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
  96. dst = dst + (y + dstYoff) * dstStride;
  97. dstX = (x + dstXoff) * dstBpp;
  98. dstWidth = width * dstBpp;
  99. if (dstBpp == 1) {
  100. fbBltStip(src,
  101. srcStride,
  102. srcX,
  103. (FbStip *) dst,
  104. FbBitsStrideToStipStride(dstStride),
  105. dstX,
  106. dstWidth,
  107. height,
  108. FbStipple1Rop(pGC->alu, pGC->fgPixel), pPriv->pm, dstBpp);
  109. }
  110. else {
  111. fbBltOne(src,
  112. srcStride,
  113. srcX,
  114. dst,
  115. dstStride,
  116. dstX,
  117. dstBpp,
  118. dstWidth,
  119. height,
  120. pPriv->and, pPriv->xor,
  121. fbAnd(GXnoop, (FbBits) 0, FB_ALLONES),
  122. fbXor(GXnoop, (FbBits) 0, FB_ALLONES));
  123. }
  124. }
  125. else {
  126. fbPushPattern(pDrawable, pGC, src, srcStride, srcX,
  127. x, y, width, height);
  128. }
  129. }
  130. void
  131. fbPushImage(DrawablePtr pDrawable,
  132. GCPtr pGC,
  133. FbStip * src,
  134. FbStride srcStride, int srcX, int x, int y, int width, int height)
  135. {
  136. RegionPtr pClip = fbGetCompositeClip(pGC);
  137. int nbox;
  138. BoxPtr pbox;
  139. int x1, y1, x2, y2;
  140. for (nbox = REGION_NUM_RECTS(pClip),
  141. pbox = REGION_RECTS(pClip); nbox--; pbox++) {
  142. x1 = x;
  143. y1 = y;
  144. x2 = x + width;
  145. y2 = y + height;
  146. if (x1 < pbox->x1)
  147. x1 = pbox->x1;
  148. if (y1 < pbox->y1)
  149. y1 = pbox->y1;
  150. if (x2 > pbox->x2)
  151. x2 = pbox->x2;
  152. if (y2 > pbox->y2)
  153. y2 = pbox->y2;
  154. if (x1 >= x2 || y1 >= y2)
  155. continue;
  156. fbPushFill(pDrawable,
  157. pGC,
  158. src + (y1 - y) * srcStride,
  159. srcStride, srcX + (x1 - x), x1, y1, x2 - x1, y2 - y1);
  160. }
  161. }
  162. void
  163. fbPushPixels(GCPtr pGC,
  164. PixmapPtr pBitmap,
  165. DrawablePtr pDrawable, int dx, int dy, int xOrg, int yOrg)
  166. {
  167. FbStip *stip;
  168. FbStride stipStride;
  169. int stipBpp;
  170. int stipXoff _X_UNUSED, stipYoff _X_UNUSED; /* Assumed to be zero */
  171. fbGetStipDrawable(&pBitmap->drawable, stip, stipStride, stipBpp, stipXoff,
  172. stipYoff);
  173. fbPushImage(pDrawable, pGC, stip, stipStride, 0, xOrg, yOrg, dx, dy);
  174. }