fbtile.c 4.5 KB

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