fbbltone.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  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. #ifdef __clang__
  27. /* shift overflow is intentional */
  28. #pragma clang diagnostic ignored "-Wshift-overflow"
  29. #endif
  30. /*
  31. * Example: srcX = 13 dstX = 8 (FB unit 32 dstBpp 8)
  32. *
  33. * **** **** **** **** **** **** **** ****
  34. * ^
  35. * ******** ******** ******** ********
  36. * ^
  37. * leftShift = 12
  38. * rightShift = 20
  39. *
  40. * Example: srcX = 0 dstX = 8 (FB unit 32 dstBpp 8)
  41. *
  42. * **** **** **** **** **** **** **** ****
  43. * ^
  44. * ******** ******** ******** ********
  45. * ^
  46. *
  47. * leftShift = 24
  48. * rightShift = 8
  49. */
  50. #define LoadBits {\
  51. if (leftShift) { \
  52. bitsRight = (src < srcEnd ? READ(src++) : 0); \
  53. bits = (FbStipLeft (bitsLeft, leftShift) | \
  54. FbStipRight(bitsRight, rightShift)); \
  55. bitsLeft = bitsRight; \
  56. } else \
  57. bits = (src < srcEnd ? READ(src++) : 0); \
  58. }
  59. #define LaneCases1(n,a) case n: FbLaneCase(n,a); break
  60. #define LaneCases2(n,a) LaneCases1(n,a); LaneCases1(n+1,a)
  61. #define LaneCases4(n,a) LaneCases2(n,a); LaneCases2(n+2,a)
  62. #define LaneCases8(n,a) LaneCases4(n,a); LaneCases4(n+4,a)
  63. #define LaneCases16(n,a) LaneCases8(n,a); LaneCases8(n+8,a)
  64. #define LaneCases32(n,a) LaneCases16(n,a); LaneCases16(n+16,a)
  65. #define LaneCases64(n,a) LaneCases32(n,a); LaneCases32(n+32,a)
  66. #define LaneCases128(n,a) LaneCases64(n,a); LaneCases64(n+64,a)
  67. #define LaneCases256(n,a) LaneCases128(n,a); LaneCases128(n+128,a)
  68. #if FB_SHIFT == 6
  69. #define LaneCases(a) LaneCases256(0,a)
  70. #endif
  71. #if FB_SHIFT == 5
  72. #define LaneCases(a) LaneCases16(0,a)
  73. #endif
  74. #if FB_SHIFT == 6
  75. CARD8 fb8Lane[256] = {
  76. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
  77. 21,
  78. 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
  79. 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
  80. 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
  81. 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
  82. 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
  83. 113, 114, 115,
  84. 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130,
  85. 131, 132, 133,
  86. 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148,
  87. 149, 150, 151,
  88. 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166,
  89. 167, 168, 169,
  90. 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
  91. 185, 186, 187,
  92. 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202,
  93. 203, 204, 205,
  94. 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220,
  95. 221, 222, 223,
  96. 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238,
  97. 239, 240, 241,
  98. 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
  99. };
  100. CARD8 fb16Lane[256] = {
  101. 0x00, 0x03, 0x0c, 0x0f,
  102. 0x30, 0x33, 0x3c, 0x3f,
  103. 0xc0, 0xc3, 0xcc, 0xcf,
  104. 0xf0, 0xf3, 0xfc, 0xff,
  105. };
  106. CARD8 fb32Lane[16] = {
  107. 0x00, 0x0f, 0xf0, 0xff,
  108. };
  109. #endif
  110. #if FB_SHIFT == 5
  111. CARD8 fb8Lane[16] = {
  112. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
  113. };
  114. CARD8 fb16Lane[16] = {
  115. 0, 3, 12, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116. };
  117. CARD8 fb32Lane[16] = {
  118. 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119. };
  120. #endif
  121. CARD8 *fbLaneTable[33] = {
  122. 0, 0, 0, 0, 0, 0, 0, 0,
  123. fb8Lane, 0, 0, 0, 0, 0, 0, 0,
  124. fb16Lane, 0, 0, 0, 0, 0, 0, 0,
  125. 0, 0, 0, 0, 0, 0, 0, 0,
  126. fb32Lane
  127. };
  128. void
  129. fbBltOne(FbStip * src, FbStride srcStride, /* FbStip units per scanline */
  130. int srcX, /* bit position of source */
  131. FbBits * dst, FbStride dstStride, /* FbBits units per scanline */
  132. int dstX, /* bit position of dest */
  133. int dstBpp, /* bits per destination unit */
  134. int width, /* width in bits of destination */
  135. int height, /* height in scanlines */
  136. FbBits fgand, /* rrop values */
  137. FbBits fgxor, FbBits bgand, FbBits bgxor)
  138. {
  139. const FbBits *fbBits;
  140. FbBits *srcEnd;
  141. int pixelsPerDst; /* dst pixels per FbBits */
  142. int unitsPerSrc; /* src patterns per FbStip */
  143. int leftShift, rightShift; /* align source with dest */
  144. FbBits startmask, endmask; /* dest scanline masks */
  145. FbStip bits = 0, bitsLeft, bitsRight; /* source bits */
  146. FbStip left;
  147. FbBits mask;
  148. int nDst; /* dest longwords (w.o. end) */
  149. int w;
  150. int n, nmiddle;
  151. int dstS; /* stipple-relative dst X coordinate */
  152. Bool copy; /* accelerate dest-invariant */
  153. Bool transparent; /* accelerate 0 nop */
  154. int srcinc; /* source units consumed */
  155. Bool endNeedsLoad = FALSE; /* need load for endmask */
  156. CARD8 *fbLane;
  157. int startbyte, endbyte;
  158. if (dstBpp == 24) {
  159. fbBltOne24(src, srcStride, srcX,
  160. dst, dstStride, dstX, dstBpp,
  161. width, height, fgand, fgxor, bgand, bgxor);
  162. return;
  163. }
  164. /*
  165. * Do not read past the end of the buffer!
  166. */
  167. srcEnd = src + height * srcStride;
  168. /*
  169. * Number of destination units in FbBits == number of stipple pixels
  170. * used each time
  171. */
  172. pixelsPerDst = FB_UNIT / dstBpp;
  173. /*
  174. * Number of source stipple patterns in FbStip
  175. */
  176. unitsPerSrc = FB_STIP_UNIT / pixelsPerDst;
  177. copy = FALSE;
  178. transparent = FALSE;
  179. if (bgand == 0 && fgand == 0)
  180. copy = TRUE;
  181. else if (bgand == FB_ALLONES && bgxor == 0)
  182. transparent = TRUE;
  183. /*
  184. * Adjust source and dest to nearest FbBits boundary
  185. */
  186. src += srcX >> FB_STIP_SHIFT;
  187. dst += dstX >> FB_SHIFT;
  188. srcX &= FB_STIP_MASK;
  189. dstX &= FB_MASK;
  190. FbMaskBitsBytes(dstX, width, copy,
  191. startmask, startbyte, nmiddle, endmask, endbyte);
  192. /*
  193. * Compute effective dest alignment requirement for
  194. * source -- must align source to dest unit boundary
  195. */
  196. dstS = dstX / dstBpp;
  197. /*
  198. * Compute shift constants for effective alignement
  199. */
  200. if (srcX >= dstS) {
  201. leftShift = srcX - dstS;
  202. rightShift = FB_STIP_UNIT - leftShift;
  203. }
  204. else {
  205. rightShift = dstS - srcX;
  206. leftShift = FB_STIP_UNIT - rightShift;
  207. }
  208. /*
  209. * Get pointer to stipple mask array for this depth
  210. */
  211. fbBits = 0; /* unused */
  212. if (pixelsPerDst <= 8)
  213. fbBits = fbStippleTable[pixelsPerDst];
  214. fbLane = 0;
  215. if (transparent && fgand == 0 && dstBpp >= 8)
  216. fbLane = fbLaneTable[dstBpp];
  217. /*
  218. * Compute total number of destination words written, but
  219. * don't count endmask
  220. */
  221. nDst = nmiddle;
  222. if (startmask)
  223. nDst++;
  224. dstStride -= nDst;
  225. /*
  226. * Compute total number of source words consumed
  227. */
  228. srcinc = (nDst + unitsPerSrc - 1) / unitsPerSrc;
  229. if (srcX > dstS)
  230. srcinc++;
  231. if (endmask) {
  232. endNeedsLoad = nDst % unitsPerSrc == 0;
  233. if (endNeedsLoad)
  234. srcinc++;
  235. }
  236. srcStride -= srcinc;
  237. /*
  238. * Copy rectangle
  239. */
  240. while (height--) {
  241. w = nDst; /* total units across scanline */
  242. n = unitsPerSrc; /* units avail in single stipple */
  243. if (n > w)
  244. n = w;
  245. bitsLeft = 0;
  246. if (srcX > dstS)
  247. bitsLeft = READ(src++);
  248. if (n) {
  249. /*
  250. * Load first set of stipple bits
  251. */
  252. LoadBits;
  253. /*
  254. * Consume stipple bits for startmask
  255. */
  256. if (startmask) {
  257. #if FB_UNIT > 32
  258. if (pixelsPerDst == 16)
  259. mask = FbStipple16Bits(FbLeftStipBits(bits, 16));
  260. else
  261. #endif
  262. mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
  263. if (fbLane) {
  264. fbTransparentSpan(dst, mask & startmask, fgxor, 1);
  265. }
  266. else {
  267. if (mask || !transparent)
  268. FbDoLeftMaskByteStippleRRop(dst, mask,
  269. fgand, fgxor, bgand, bgxor,
  270. startbyte, startmask);
  271. }
  272. bits = FbStipLeft(bits, pixelsPerDst);
  273. dst++;
  274. n--;
  275. w--;
  276. }
  277. /*
  278. * Consume stipple bits across scanline
  279. */
  280. for (;;) {
  281. w -= n;
  282. if (copy) {
  283. while (n--) {
  284. #if FB_UNIT > 32
  285. if (pixelsPerDst == 16)
  286. mask = FbStipple16Bits(FbLeftStipBits(bits, 16));
  287. else
  288. #endif
  289. mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
  290. WRITE(dst, FbOpaqueStipple(mask, fgxor, bgxor));
  291. dst++;
  292. bits = FbStipLeft(bits, pixelsPerDst);
  293. }
  294. }
  295. else {
  296. if (fbLane) {
  297. while (bits && n) {
  298. switch (fbLane[FbLeftStipBits(bits, pixelsPerDst)]) {
  299. LaneCases((CARD8 *) dst);
  300. }
  301. bits = FbStipLeft(bits, pixelsPerDst);
  302. dst++;
  303. n--;
  304. }
  305. dst += n;
  306. }
  307. else {
  308. while (n--) {
  309. left = FbLeftStipBits(bits, pixelsPerDst);
  310. if (left || !transparent) {
  311. mask = fbBits[left];
  312. WRITE(dst, FbStippleRRop(READ(dst), mask,
  313. fgand, fgxor, bgand,
  314. bgxor));
  315. }
  316. dst++;
  317. bits = FbStipLeft(bits, pixelsPerDst);
  318. }
  319. }
  320. }
  321. if (!w)
  322. break;
  323. /*
  324. * Load another set and reset number of available units
  325. */
  326. LoadBits;
  327. n = unitsPerSrc;
  328. if (n > w)
  329. n = w;
  330. }
  331. }
  332. /*
  333. * Consume stipple bits for endmask
  334. */
  335. if (endmask) {
  336. if (endNeedsLoad) {
  337. LoadBits;
  338. }
  339. #if FB_UNIT > 32
  340. if (pixelsPerDst == 16)
  341. mask = FbStipple16Bits(FbLeftStipBits(bits, 16));
  342. else
  343. #endif
  344. mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
  345. if (fbLane) {
  346. fbTransparentSpan(dst, mask & endmask, fgxor, 1);
  347. }
  348. else {
  349. if (mask || !transparent)
  350. FbDoRightMaskByteStippleRRop(dst, mask,
  351. fgand, fgxor, bgand, bgxor,
  352. endbyte, endmask);
  353. }
  354. }
  355. dst += dstStride;
  356. src += srcStride;
  357. }
  358. }
  359. /*
  360. * Crufty macros to initialize the mask array, most of this
  361. * is to avoid compile-time warnings about shift overflow
  362. */
  363. #if BITMAP_BIT_ORDER == MSBFirst
  364. #define Mask24Pos(x,r) ((x)*24-(r))
  365. #else
  366. #define Mask24Pos(x,r) ((x)*24-((r) ? 24 - (r) : 0))
  367. #endif
  368. #define Mask24Neg(x,r) (Mask24Pos(x,r) < 0 ? -Mask24Pos(x,r) : 0)
  369. #define Mask24Check(x,r) (Mask24Pos(x,r) < 0 ? 0 : \
  370. Mask24Pos(x,r) >= FB_UNIT ? 0 : Mask24Pos(x,r))
  371. #define Mask24(x,r) (Mask24Pos(x,r) < FB_UNIT ? \
  372. (Mask24Pos(x,r) < 0 ? \
  373. 0xffffffU >> Mask24Neg (x,r) : \
  374. 0xffffffU << Mask24Check(x,r)) : 0)
  375. #define SelMask24(b,n,r) ((((b) >> n) & 1) * Mask24(n,r))
  376. /*
  377. * Untested for MSBFirst or FB_UNIT == 32
  378. */
  379. #if FB_UNIT == 64
  380. #define C4_24(b,r) \
  381. (SelMask24(b,0,r) | \
  382. SelMask24(b,1,r) | \
  383. SelMask24(b,2,r) | \
  384. SelMask24(b,3,r))
  385. #define FbStip24New(rot) (2 + (rot != 0))
  386. #define FbStip24Len 4
  387. const FbBits fbStipple24Bits[3][1 << FbStip24Len] = {
  388. /* rotate 0 */
  389. {
  390. C4_24(0, 0), C4_24(1, 0), C4_24(2, 0), C4_24(3, 0),
  391. C4_24(4, 0), C4_24(5, 0), C4_24(6, 0), C4_24(7, 0),
  392. C4_24(8, 0), C4_24(9, 0), C4_24(10, 0), C4_24(11, 0),
  393. C4_24(12, 0), C4_24(13, 0), C4_24(14, 0), C4_24(15, 0),
  394. },
  395. /* rotate 8 */
  396. {
  397. C4_24(0, 8), C4_24(1, 8), C4_24(2, 8), C4_24(3, 8),
  398. C4_24(4, 8), C4_24(5, 8), C4_24(6, 8), C4_24(7, 8),
  399. C4_24(8, 8), C4_24(9, 8), C4_24(10, 8), C4_24(11, 8),
  400. C4_24(12, 8), C4_24(13, 8), C4_24(14, 8), C4_24(15, 8),
  401. },
  402. /* rotate 16 */
  403. {
  404. C4_24(0, 16), C4_24(1, 16), C4_24(2, 16), C4_24(3, 16),
  405. C4_24(4, 16), C4_24(5, 16), C4_24(6, 16), C4_24(7, 16),
  406. C4_24(8, 16), C4_24(9, 16), C4_24(10, 16), C4_24(11, 16),
  407. C4_24(12, 16), C4_24(13, 16), C4_24(14, 16), C4_24(15, 16),
  408. }
  409. };
  410. #endif
  411. #if FB_UNIT == 32
  412. #define C2_24(b,r) \
  413. (SelMask24(b,0,r) | \
  414. SelMask24(b,1,r))
  415. #define FbStip24Len 2
  416. #if BITMAP_BIT_ORDER == MSBFirst
  417. #define FbStip24New(rot) (1 + (rot == 0))
  418. #else
  419. #define FbStip24New(rot) (1 + (rot == 8))
  420. #endif
  421. const FbBits fbStipple24Bits[3][1 << FbStip24Len] = {
  422. /* rotate 0 */
  423. {
  424. C2_24(0, 0), C2_24(1, 0), C2_24(2, 0), C2_24(3, 0),
  425. },
  426. /* rotate 8 */
  427. {
  428. C2_24(0, 8), C2_24(1, 8), C2_24(2, 8), C2_24(3, 8),
  429. },
  430. /* rotate 16 */
  431. {
  432. C2_24(0, 16), C2_24(1, 16), C2_24(2, 16), C2_24(3, 16),
  433. }
  434. };
  435. #endif
  436. #if BITMAP_BIT_ORDER == LSBFirst
  437. #define FbMergeStip24Bits(left, right, new) \
  438. (FbStipLeft (left, new) | FbStipRight ((right), (FbStip24Len - (new))))
  439. #define FbMergePartStip24Bits(left, right, llen, rlen) \
  440. (left | FbStipRight(right, llen))
  441. #else
  442. #define FbMergeStip24Bits(left, right, new) \
  443. ((FbStipLeft (left, new) & ((1 << FbStip24Len) - 1)) | right)
  444. #define FbMergePartStip24Bits(left, right, llen, rlen) \
  445. (FbStipLeft(left, rlen) | right)
  446. #endif
  447. #define fbFirstStipBits(len,stip) {\
  448. int __len = (len); \
  449. if (len <= remain) { \
  450. stip = FbLeftStipBits(bits, len); \
  451. } else { \
  452. stip = FbLeftStipBits(bits, remain); \
  453. bits = (src < srcEnd ? READ(src++) : 0); \
  454. __len = (len) - remain; \
  455. stip = FbMergePartStip24Bits(stip, FbLeftStipBits(bits, __len), \
  456. remain, __len); \
  457. remain = FB_STIP_UNIT; \
  458. } \
  459. bits = FbStipLeft (bits, __len); \
  460. remain -= __len; \
  461. }
  462. #define fbInitStipBits(offset,len,stip) {\
  463. bits = FbStipLeft (READ(src++),offset); \
  464. remain = FB_STIP_UNIT - offset; \
  465. fbFirstStipBits(len,stip); \
  466. stip = FbMergeStip24Bits (0, stip, len); \
  467. }
  468. #define fbNextStipBits(rot,stip) {\
  469. int __new = FbStip24New(rot); \
  470. FbStip __right; \
  471. fbFirstStipBits(__new, __right); \
  472. stip = FbMergeStip24Bits (stip, __right, __new); \
  473. rot = FbNext24Rot (rot); \
  474. }
  475. /*
  476. * Use deep mask tables that incorporate rotation, pull
  477. * a variable number of bits out of the stipple and
  478. * reuse the right bits as needed for the next write
  479. *
  480. * Yes, this is probably too much code, but most 24-bpp screens
  481. * have no acceleration so this code is used for stipples, copyplane
  482. * and text
  483. */
  484. void
  485. fbBltOne24(FbStip * srcLine, FbStride srcStride, /* FbStip units per scanline */
  486. int srcX, /* bit position of source */
  487. FbBits * dst, FbStride dstStride, /* FbBits units per scanline */
  488. int dstX, /* bit position of dest */
  489. int dstBpp, /* bits per destination unit */
  490. int width, /* width in bits of destination */
  491. int height, /* height in scanlines */
  492. FbBits fgand, /* rrop values */
  493. FbBits fgxor, FbBits bgand, FbBits bgxor)
  494. {
  495. FbStip *src, *srcEnd;
  496. FbBits leftMask, rightMask, mask;
  497. int nlMiddle, nl;
  498. FbStip stip, bits;
  499. int remain;
  500. int dstS;
  501. int firstlen;
  502. int rot0, rot;
  503. int nDst;
  504. /*
  505. * Do not read past the end of the buffer!
  506. */
  507. srcEnd = srcLine + height * srcStride;
  508. srcLine += srcX >> FB_STIP_SHIFT;
  509. dst += dstX >> FB_SHIFT;
  510. srcX &= FB_STIP_MASK;
  511. dstX &= FB_MASK;
  512. rot0 = FbFirst24Rot(dstX);
  513. FbMaskBits(dstX, width, leftMask, nlMiddle, rightMask);
  514. dstS = (dstX + 23) / 24;
  515. firstlen = FbStip24Len - dstS;
  516. nDst = nlMiddle;
  517. if (leftMask)
  518. nDst++;
  519. dstStride -= nDst;
  520. /* opaque copy */
  521. if (bgand == 0 && fgand == 0) {
  522. while (height--) {
  523. rot = rot0;
  524. src = srcLine;
  525. srcLine += srcStride;
  526. fbInitStipBits(srcX, firstlen, stip);
  527. if (leftMask) {
  528. mask = fbStipple24Bits[rot >> 3][stip];
  529. WRITE(dst, (READ(dst) & ~leftMask) |
  530. (FbOpaqueStipple(mask,
  531. FbRot24(fgxor, rot), FbRot24(bgxor, rot))
  532. & leftMask));
  533. dst++;
  534. fbNextStipBits(rot, stip);
  535. }
  536. nl = nlMiddle;
  537. while (nl--) {
  538. mask = fbStipple24Bits[rot >> 3][stip];
  539. WRITE(dst, FbOpaqueStipple(mask,
  540. FbRot24(fgxor, rot),
  541. FbRot24(bgxor, rot)));
  542. dst++;
  543. fbNextStipBits(rot, stip);
  544. }
  545. if (rightMask) {
  546. mask = fbStipple24Bits[rot >> 3][stip];
  547. WRITE(dst, (READ(dst) & ~rightMask) |
  548. (FbOpaqueStipple(mask,
  549. FbRot24(fgxor, rot), FbRot24(bgxor, rot))
  550. & rightMask));
  551. }
  552. dst += dstStride;
  553. src += srcStride;
  554. }
  555. }
  556. /* transparent copy */
  557. else if (bgand == FB_ALLONES && bgxor == 0 && fgand == 0) {
  558. while (height--) {
  559. rot = rot0;
  560. src = srcLine;
  561. srcLine += srcStride;
  562. fbInitStipBits(srcX, firstlen, stip);
  563. if (leftMask) {
  564. if (stip) {
  565. mask = fbStipple24Bits[rot >> 3][stip] & leftMask;
  566. WRITE(dst,
  567. (READ(dst) & ~mask) | (FbRot24(fgxor, rot) & mask));
  568. }
  569. dst++;
  570. fbNextStipBits(rot, stip);
  571. }
  572. nl = nlMiddle;
  573. while (nl--) {
  574. if (stip) {
  575. mask = fbStipple24Bits[rot >> 3][stip];
  576. WRITE(dst,
  577. (READ(dst) & ~mask) | (FbRot24(fgxor, rot) & mask));
  578. }
  579. dst++;
  580. fbNextStipBits(rot, stip);
  581. }
  582. if (rightMask) {
  583. if (stip) {
  584. mask = fbStipple24Bits[rot >> 3][stip] & rightMask;
  585. WRITE(dst,
  586. (READ(dst) & ~mask) | (FbRot24(fgxor, rot) & mask));
  587. }
  588. }
  589. dst += dstStride;
  590. }
  591. }
  592. else {
  593. while (height--) {
  594. rot = rot0;
  595. src = srcLine;
  596. srcLine += srcStride;
  597. fbInitStipBits(srcX, firstlen, stip);
  598. if (leftMask) {
  599. mask = fbStipple24Bits[rot >> 3][stip];
  600. WRITE(dst, FbStippleRRopMask(READ(dst), mask,
  601. FbRot24(fgand, rot),
  602. FbRot24(fgxor, rot),
  603. FbRot24(bgand, rot),
  604. FbRot24(bgxor, rot), leftMask));
  605. dst++;
  606. fbNextStipBits(rot, stip);
  607. }
  608. nl = nlMiddle;
  609. while (nl--) {
  610. mask = fbStipple24Bits[rot >> 3][stip];
  611. WRITE(dst, FbStippleRRop(READ(dst), mask,
  612. FbRot24(fgand, rot),
  613. FbRot24(fgxor, rot),
  614. FbRot24(bgand, rot),
  615. FbRot24(bgxor, rot)));
  616. dst++;
  617. fbNextStipBits(rot, stip);
  618. }
  619. if (rightMask) {
  620. mask = fbStipple24Bits[rot >> 3][stip];
  621. WRITE(dst, FbStippleRRopMask(READ(dst), mask,
  622. FbRot24(fgand, rot),
  623. FbRot24(fgxor, rot),
  624. FbRot24(bgand, rot),
  625. FbRot24(bgxor, rot), rightMask));
  626. }
  627. dst += dstStride;
  628. }
  629. }
  630. }
  631. /*
  632. * Not very efficient, but simple -- copy a single plane
  633. * from an N bit image to a 1 bit image
  634. */
  635. void
  636. fbBltPlane(FbBits * src,
  637. FbStride srcStride,
  638. int srcX,
  639. int srcBpp,
  640. FbStip * dst,
  641. FbStride dstStride,
  642. int dstX,
  643. int width,
  644. int height,
  645. FbStip fgand,
  646. FbStip fgxor, FbStip bgand, FbStip bgxor, Pixel planeMask)
  647. {
  648. FbBits *s;
  649. FbBits pm;
  650. FbBits srcMask;
  651. FbBits srcMaskFirst;
  652. FbBits srcMask0 = 0;
  653. FbBits srcBits;
  654. FbStip dstBits;
  655. FbStip *d;
  656. FbStip dstMask;
  657. FbStip dstMaskFirst;
  658. FbStip dstUnion;
  659. int w;
  660. int wt;
  661. int rot0;
  662. if (!width)
  663. return;
  664. src += srcX >> FB_SHIFT;
  665. srcX &= FB_MASK;
  666. dst += dstX >> FB_STIP_SHIFT;
  667. dstX &= FB_STIP_MASK;
  668. w = width / srcBpp;
  669. pm = fbReplicatePixel(planeMask, srcBpp);
  670. if (srcBpp == 24) {
  671. int tmpw = 24;
  672. rot0 = FbFirst24Rot(srcX);
  673. if (srcX + tmpw > FB_UNIT)
  674. tmpw = FB_UNIT - srcX;
  675. srcMaskFirst = FbRot24(pm, rot0) & FbBitsMask(srcX, tmpw);
  676. }
  677. else {
  678. rot0 = 0;
  679. srcMaskFirst = pm & FbBitsMask(srcX, srcBpp);
  680. srcMask0 = pm & FbBitsMask(0, srcBpp);
  681. }
  682. dstMaskFirst = FbStipMask(dstX, 1);
  683. while (height--) {
  684. d = dst;
  685. dst += dstStride;
  686. s = src;
  687. src += srcStride;
  688. srcMask = srcMaskFirst;
  689. if (srcBpp == 24)
  690. srcMask0 = FbRot24(pm, rot0) & FbBitsMask(0, srcBpp);
  691. srcBits = READ(s++);
  692. dstMask = dstMaskFirst;
  693. dstUnion = 0;
  694. dstBits = 0;
  695. wt = w;
  696. while (wt--) {
  697. if (!srcMask) {
  698. srcBits = READ(s++);
  699. if (srcBpp == 24)
  700. srcMask0 = FbNext24Pix(srcMask0) & FbBitsMask(0, 24);
  701. srcMask = srcMask0;
  702. }
  703. if (!dstMask) {
  704. WRITE(d, FbStippleRRopMask(READ(d), dstBits,
  705. fgand, fgxor, bgand, bgxor,
  706. dstUnion));
  707. d++;
  708. dstMask = FbStipMask(0, 1);
  709. dstUnion = 0;
  710. dstBits = 0;
  711. }
  712. if (srcBits & srcMask)
  713. dstBits |= dstMask;
  714. dstUnion |= dstMask;
  715. if (srcBpp == FB_UNIT)
  716. srcMask = 0;
  717. else
  718. srcMask = FbScrRight(srcMask, srcBpp);
  719. dstMask = FbStipRight(dstMask, 1);
  720. }
  721. if (dstUnion)
  722. WRITE(d, FbStippleRRopMask(READ(d), dstBits,
  723. fgand, fgxor, bgand, bgxor, dstUnion));
  724. }
  725. }