fbrop.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #ifndef _FBROP_H_
  23. #define _FBROP_H_
  24. typedef struct _mergeRopBits {
  25. FbBits ca1, cx1, ca2, cx2;
  26. } FbMergeRopRec, *FbMergeRopPtr;
  27. extern _X_EXPORT const FbMergeRopRec FbMergeRopBits[16];
  28. #define FbDeclareMergeRop() FbBits _ca1, _cx1, _ca2, _cx2;
  29. #define FbDeclarePrebuiltMergeRop() FbBits _cca, _ccx;
  30. #define FbInitializeMergeRop(alu,pm) {\
  31. const FbMergeRopRec *_bits; \
  32. _bits = &FbMergeRopBits[alu]; \
  33. _ca1 = _bits->ca1 & pm; \
  34. _cx1 = _bits->cx1 | ~pm; \
  35. _ca2 = _bits->ca2 & pm; \
  36. _cx2 = _bits->cx2 & pm; \
  37. }
  38. #define FbDestInvarientRop(alu,pm) ((pm) == FB_ALLONES && \
  39. (((alu) >> 1 & 5) == ((alu) & 5)))
  40. #define FbDestInvarientMergeRop() (_ca1 == 0 && _cx1 == 0)
  41. /* AND has higher precedence than XOR */
  42. #define FbDoMergeRop(src, dst) \
  43. (((dst) & (((src) & _ca1) ^ _cx1)) ^ (((src) & _ca2) ^ _cx2))
  44. #define FbDoDestInvarientMergeRop(src) (((src) & _ca2) ^ _cx2)
  45. #define FbDoMaskMergeRop(src, dst, mask) \
  46. (((dst) & ((((src) & _ca1) ^ _cx1) | ~(mask))) ^ ((((src) & _ca2) ^ _cx2) & (mask)))
  47. #define FbDoLeftMaskByteMergeRop(dst, src, lb, l) { \
  48. FbBits __xor = ((src) & _ca2) ^ _cx2; \
  49. FbDoLeftMaskByteRRop(dst,lb,l,((src) & _ca1) ^ _cx1,__xor); \
  50. }
  51. #define FbDoRightMaskByteMergeRop(dst, src, rb, r) { \
  52. FbBits __xor = ((src) & _ca2) ^ _cx2; \
  53. FbDoRightMaskByteRRop(dst,rb,r,((src) & _ca1) ^ _cx1,__xor); \
  54. }
  55. #define FbDoRRop(dst, and, xor) (((dst) & (and)) ^ (xor))
  56. #define FbDoMaskRRop(dst, and, xor, mask) \
  57. (((dst) & ((and) | ~(mask))) ^ (xor & mask))
  58. /*
  59. * Take a single bit (0 or 1) and generate a full mask
  60. */
  61. #define fbFillFromBit(b,t) (~((t) ((b) & 1)-1))
  62. #define fbXorT(rop,fg,pm,t) ((((fg) & fbFillFromBit((rop) >> 1,t)) | \
  63. (~(fg) & fbFillFromBit((rop) >> 3,t))) & (pm))
  64. #define fbAndT(rop,fg,pm,t) ((((fg) & fbFillFromBit (rop ^ (rop>>1),t)) | \
  65. (~(fg) & fbFillFromBit((rop>>2) ^ (rop>>3),t))) | \
  66. ~(pm))
  67. #define fbXor(rop,fg,pm) fbXorT(rop,fg,pm,FbBits)
  68. #define fbAnd(rop,fg,pm) fbAndT(rop,fg,pm,FbBits)
  69. #define fbXorStip(rop,fg,pm) fbXorT(rop,fg,pm,FbStip)
  70. #define fbAndStip(rop,fg,pm) fbAndT(rop,fg,pm,FbStip)
  71. /*
  72. * Stippling operations;
  73. */
  74. extern _X_EXPORT const FbBits fbStipple16Bits[256]; /* half of table */
  75. #define FbStipple16Bits(b) \
  76. (fbStipple16Bits[(b)&0xff] | fbStipple16Bits[(b) >> 8] << FB_HALFUNIT)
  77. extern _X_EXPORT const FbBits fbStipple8Bits[256];
  78. extern _X_EXPORT const FbBits fbStipple4Bits[16];
  79. extern _X_EXPORT const FbBits fbStipple2Bits[4];
  80. extern _X_EXPORT const FbBits fbStipple1Bits[2];
  81. extern _X_EXPORT const FbBits *const fbStippleTable[];
  82. #define FbStippleRRop(dst, b, fa, fx, ba, bx) \
  83. (FbDoRRop(dst, fa, fx) & b) | (FbDoRRop(dst, ba, bx) & ~b)
  84. #define FbStippleRRopMask(dst, b, fa, fx, ba, bx, m) \
  85. (FbDoMaskRRop(dst, fa, fx, m) & (b)) | (FbDoMaskRRop(dst, ba, bx, m) & ~(b))
  86. #define FbDoLeftMaskByteStippleRRop(dst, b, fa, fx, ba, bx, lb, l) { \
  87. FbBits __xor = ((fx) & (b)) | ((bx) & ~(b)); \
  88. FbDoLeftMaskByteRRop(dst, lb, l, ((fa) & (b)) | ((ba) & ~(b)), __xor); \
  89. }
  90. #define FbDoRightMaskByteStippleRRop(dst, b, fa, fx, ba, bx, rb, r) { \
  91. FbBits __xor = ((fx) & (b)) | ((bx) & ~(b)); \
  92. FbDoRightMaskByteRRop(dst, rb, r, ((fa) & (b)) | ((ba) & ~(b)), __xor); \
  93. }
  94. #define FbOpaqueStipple(b, fg, bg) (((fg) & (b)) | ((bg) & ~(b)))
  95. /*
  96. * Compute rop for using tile code for 1-bit dest stipples; modifies
  97. * existing rop to flip depending on pixel values
  98. */
  99. #define FbStipple1RopPick(alu,b) (((alu) >> (2 - (((b) & 1) << 1))) & 3)
  100. #define FbOpaqueStipple1Rop(alu,fg,bg) (FbStipple1RopPick(alu,fg) | \
  101. (FbStipple1RopPick(alu,bg) << 2))
  102. #define FbStipple1Rop(alu,fg) (FbStipple1RopPick(alu,fg) | 4)
  103. #endif