fbpush.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * Copyright © 1998 Keith Packard
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and its
  5. * documentation for any purpose is hereby granted without fee, provided that
  6. * the above copyright notice appear in all copies and that both that
  7. * copyright notice and this permission notice appear in supporting
  8. * documentation, and that the name of Keith Packard not be used in
  9. * advertising or publicity pertaining to distribution of the software without
  10. * specific, written prior permission. Keith Packard makes no
  11. * representations about the suitability of this software for any purpose. It
  12. * is provided "as is" without express or implied warranty.
  13. *
  14. * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16. * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  20. * PERFORMANCE OF THIS SOFTWARE.
  21. */
  22. #ifdef HAVE_DIX_CONFIG_H
  23. #include <dix-config.h>
  24. #endif
  25. #include "fb.h"
  26. void
  27. fbPushPattern(DrawablePtr pDrawable,
  28. GCPtr pGC,
  29. FbStip * src,
  30. FbStride srcStride, int srcX, int x, int y, int width, int height)
  31. {
  32. FbStip *s, bitsMask, bitsMask0, bits;
  33. int xspan;
  34. int w;
  35. int lenspan;
  36. src += srcX >> FB_STIP_SHIFT;
  37. srcX &= FB_STIP_MASK;
  38. bitsMask0 = FbStipMask(srcX, 1);
  39. while (height--) {
  40. bitsMask = bitsMask0;
  41. w = width;
  42. s = src;
  43. src += srcStride;
  44. bits = READ(s++);
  45. xspan = x;
  46. while (w) {
  47. if (bits & bitsMask) {
  48. lenspan = 0;
  49. do {
  50. lenspan++;
  51. if (lenspan == w)
  52. break;
  53. bitsMask = FbStipRight(bitsMask, 1);
  54. if (!bitsMask) {
  55. bits = READ(s++);
  56. bitsMask = FbBitsMask(0, 1);
  57. }
  58. } while (bits & bitsMask);
  59. fbFill(pDrawable, pGC, xspan, y, lenspan, 1);
  60. xspan += lenspan;
  61. w -= lenspan;
  62. }
  63. else {
  64. do {
  65. w--;
  66. xspan++;
  67. if (!w)
  68. break;
  69. bitsMask = FbStipRight(bitsMask, 1);
  70. if (!bitsMask) {
  71. bits = READ(s++);
  72. bitsMask = FbBitsMask(0, 1);
  73. }
  74. } while (!(bits & bitsMask));
  75. }
  76. }
  77. y++;
  78. }
  79. }
  80. void
  81. fbPushFill(DrawablePtr pDrawable,
  82. GCPtr pGC,
  83. FbStip * src,
  84. FbStride srcStride, int srcX, int x, int y, int width, int height)
  85. {
  86. FbGCPrivPtr pPriv = fbGetGCPrivate(pGC);
  87. if (pGC->fillStyle == FillSolid) {
  88. FbBits *dst;
  89. FbStride dstStride;
  90. int dstBpp;
  91. int dstXoff, dstYoff;
  92. int dstX;
  93. int dstWidth;
  94. fbGetDrawable(pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
  95. dst = dst + (y + dstYoff) * dstStride;
  96. dstX = (x + dstXoff) * dstBpp;
  97. dstWidth = width * dstBpp;
  98. if (dstBpp == 1) {
  99. fbBltStip(src,
  100. srcStride,
  101. srcX,
  102. (FbStip *) dst,
  103. FbBitsStrideToStipStride(dstStride),
  104. dstX,
  105. dstWidth,
  106. height,
  107. FbStipple1Rop(pGC->alu, pGC->fgPixel), pPriv->pm, dstBpp);
  108. }
  109. else {
  110. fbBltOne(src,
  111. srcStride,
  112. srcX,
  113. dst,
  114. dstStride,
  115. dstX,
  116. dstBpp,
  117. dstWidth,
  118. height,
  119. pPriv->and, pPriv->xor,
  120. fbAnd(GXnoop, (FbBits) 0, FB_ALLONES),
  121. fbXor(GXnoop, (FbBits) 0, FB_ALLONES));
  122. }
  123. fbFinishAccess(pDrawable);
  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 = RegionNumRects(pClip),
  141. pbox = RegionRects(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. _X_UNUSED int stipXoff, stipYoff;
  171. fbGetStipDrawable(&pBitmap->drawable, stip, stipStride, stipBpp, stipXoff,
  172. stipYoff);
  173. fbPushImage(pDrawable, pGC, stip, stipStride, 0, xOrg, yOrg, dx, dy);
  174. }