fbtile.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. /*
  27. * Accelerated tile fill -- tile width is a power of two not greater
  28. * than FB_UNIT
  29. */
  30. void
  31. fbEvenTile(FbBits * dst,
  32. FbStride dstStride,
  33. int dstX,
  34. int width,
  35. int height,
  36. FbBits * tile,
  37. FbStride tileStride,
  38. int tileHeight, int alu, FbBits pm, int xRot, int yRot)
  39. {
  40. FbBits *t, *tileEnd, bits;
  41. FbBits startmask, endmask;
  42. FbBits and, xor;
  43. int n, nmiddle;
  44. int tileX, tileY;
  45. int rot;
  46. int startbyte, endbyte;
  47. dst += dstX >> FB_SHIFT;
  48. dstX &= FB_MASK;
  49. FbMaskBitsBytes(dstX, width, FbDestInvarientRop(alu, pm),
  50. startmask, startbyte, nmiddle, endmask, endbyte);
  51. if (startmask)
  52. dstStride--;
  53. dstStride -= nmiddle;
  54. /*
  55. * Compute tile start scanline and rotation parameters
  56. */
  57. tileEnd = tile + tileHeight * tileStride;
  58. modulus(-yRot, tileHeight, tileY);
  59. t = tile + tileY * tileStride;
  60. modulus(-xRot, FB_UNIT, tileX);
  61. rot = tileX;
  62. while (height--) {
  63. /*
  64. * Pick up bits for this scanline
  65. */
  66. bits = READ(t);
  67. t += tileStride;
  68. if (t >= tileEnd)
  69. t = tile;
  70. bits = FbRotLeft(bits, rot);
  71. and = fbAnd(alu, bits, pm);
  72. xor = fbXor(alu, bits, pm);
  73. if (startmask) {
  74. FbDoLeftMaskByteRRop(dst, startbyte, startmask, and, xor);
  75. dst++;
  76. }
  77. n = nmiddle;
  78. if (!and)
  79. while (n--)
  80. WRITE(dst++, xor);
  81. else
  82. while (n--) {
  83. WRITE(dst, FbDoRRop(READ(dst), and, xor));
  84. dst++;
  85. }
  86. if (endmask)
  87. FbDoRightMaskByteRRop(dst, endbyte, endmask, and, xor);
  88. dst += dstStride;
  89. }
  90. }
  91. void
  92. fbOddTile(FbBits * dst,
  93. FbStride dstStride,
  94. int dstX,
  95. int width,
  96. int height,
  97. FbBits * tile,
  98. FbStride tileStride,
  99. int tileWidth,
  100. int tileHeight, int alu, FbBits pm, int bpp, int xRot, int yRot)
  101. {
  102. int tileX, tileY;
  103. int widthTmp;
  104. int h, w;
  105. int x, y;
  106. modulus(-yRot, tileHeight, tileY);
  107. y = 0;
  108. while (height) {
  109. h = tileHeight - tileY;
  110. if (h > height)
  111. h = height;
  112. height -= h;
  113. widthTmp = width;
  114. x = dstX;
  115. modulus(dstX - xRot, tileWidth, tileX);
  116. while (widthTmp) {
  117. w = tileWidth - tileX;
  118. if (w > widthTmp)
  119. w = widthTmp;
  120. widthTmp -= w;
  121. fbBlt(tile + tileY * tileStride,
  122. tileStride,
  123. tileX,
  124. dst + y * dstStride,
  125. dstStride, x, w, h, alu, pm, bpp, FALSE, FALSE);
  126. x += w;
  127. tileX = 0;
  128. }
  129. y += h;
  130. tileY = 0;
  131. }
  132. }
  133. void
  134. fbTile(FbBits * dst,
  135. FbStride dstStride,
  136. int dstX,
  137. int width,
  138. int height,
  139. FbBits * tile,
  140. FbStride tileStride,
  141. int tileWidth,
  142. int tileHeight, int alu, FbBits pm, int bpp, int xRot, int yRot)
  143. {
  144. if (FbEvenTile(tileWidth))
  145. fbEvenTile(dst, dstStride, dstX, width, height,
  146. tile, tileStride, tileHeight, alu, pm, xRot, yRot);
  147. else
  148. fbOddTile(dst, dstStride, dstX, width, height,
  149. tile, tileStride, tileWidth, tileHeight,
  150. alu, pm, bpp, xRot, yRot);
  151. }