fbsolid.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. #define FbSelectPart(xor,o,t) xor
  24. #ifdef HAVE_DIX_CONFIG_H
  25. #include <dix-config.h>
  26. #endif
  27. #include "fb.h"
  28. void
  29. fbSolid(FbBits * dst,
  30. FbStride dstStride,
  31. int dstX, int bpp, int width, int height, FbBits and, FbBits xor)
  32. {
  33. FbBits startmask, endmask;
  34. int n, nmiddle;
  35. int startbyte, endbyte;
  36. if (bpp == 24 && (!FbCheck24Pix(and) || !FbCheck24Pix(xor))) {
  37. fbSolid24(dst, dstStride, dstX, width, height, and, xor);
  38. return;
  39. }
  40. dst += dstX >> FB_SHIFT;
  41. dstX &= FB_MASK;
  42. FbMaskBitsBytes(dstX, width, and == 0, startmask, startbyte,
  43. nmiddle, endmask, endbyte);
  44. if (startmask)
  45. dstStride--;
  46. dstStride -= nmiddle;
  47. while (height--) {
  48. if (startmask) {
  49. FbDoLeftMaskByteRRop(dst, startbyte, startmask, and, xor);
  50. dst++;
  51. }
  52. n = nmiddle;
  53. if (!and)
  54. while (n--)
  55. *dst++ = xor;
  56. else
  57. while (n--) {
  58. *dst = FbDoRRop(*dst, and, xor);
  59. dst++;
  60. }
  61. if (endmask)
  62. FbDoRightMaskByteRRop(dst, endbyte, endmask, and, xor);
  63. dst += dstStride;
  64. }
  65. }
  66. void
  67. fbSolid24(FbBits * dst,
  68. FbStride dstStride,
  69. int dstX, int width, int height, FbBits and, FbBits xor)
  70. {
  71. FbBits startmask, endmask;
  72. FbBits xor0 = 0, xor1 = 0, xor2 = 0;
  73. FbBits and0 = 0, and1 = 0, and2 = 0;
  74. FbBits xorS = 0, andS = 0, xorE = 0, andE = 0;
  75. int n, nmiddle;
  76. int rotS, rot;
  77. dst += dstX >> FB_SHIFT;
  78. dstX &= FB_MASK;
  79. /*
  80. * Rotate pixel values this far across the word to align on
  81. * screen pixel boundaries
  82. */
  83. rot = FbFirst24Rot(dstX);
  84. FbMaskBits(dstX, width, startmask, nmiddle, endmask);
  85. if (startmask)
  86. dstStride--;
  87. dstStride -= nmiddle;
  88. /*
  89. * Precompute rotated versions of the rasterop values
  90. */
  91. rotS = rot;
  92. xor = FbRot24(xor, rotS);
  93. and = FbRot24(and, rotS);
  94. if (startmask) {
  95. xorS = xor;
  96. andS = and;
  97. xor = FbNext24Pix(xor);
  98. and = FbNext24Pix(and);
  99. }
  100. if (nmiddle) {
  101. xor0 = xor;
  102. and0 = and;
  103. xor1 = FbNext24Pix(xor0);
  104. and1 = FbNext24Pix(and0);
  105. xor2 = FbNext24Pix(xor1);
  106. and2 = FbNext24Pix(and1);
  107. }
  108. if (endmask) {
  109. switch (nmiddle % 3) {
  110. case 0:
  111. xorE = xor;
  112. andE = and;
  113. break;
  114. case 1:
  115. xorE = xor1;
  116. andE = and1;
  117. break;
  118. case 2:
  119. xorE = xor2;
  120. andE = and2;
  121. break;
  122. }
  123. }
  124. while (height--) {
  125. if (startmask) {
  126. *dst = FbDoMaskRRop(*dst, andS, xorS, startmask);
  127. dst++;
  128. }
  129. n = nmiddle;
  130. if (!and0) {
  131. while (n >= 3) {
  132. *dst++ = xor0;
  133. *dst++ = xor1;
  134. *dst++ = xor2;
  135. n -= 3;
  136. }
  137. if (n) {
  138. *dst++ = xor0;
  139. n--;
  140. if (n) {
  141. *dst++ = xor1;
  142. }
  143. }
  144. }
  145. else {
  146. while (n >= 3) {
  147. *dst = FbDoRRop(*dst, and0, xor0);
  148. dst++;
  149. *dst = FbDoRRop(*dst, and1, xor1);
  150. dst++;
  151. *dst = FbDoRRop(*dst, and2, xor2);
  152. dst++;
  153. n -= 3;
  154. }
  155. if (n) {
  156. *dst = FbDoRRop(*dst, and0, xor0);
  157. dst++;
  158. n--;
  159. if (n) {
  160. *dst = FbDoRRop(*dst, and1, xor1);
  161. dst++;
  162. }
  163. }
  164. }
  165. if (endmask)
  166. *dst = FbDoMaskRRop(*dst, andE, xorE, endmask);
  167. dst += dstStride;
  168. }
  169. }