a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/*
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Copyright © 1998 Keith Packard
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Permission to use, copy, modify, distribute, and sell this software and its
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * documentation for any purpose is hereby granted without fee, provided that
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * the above copyright notice appear in all copies and that both that
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * copyright notice and this permission notice appear in supporting
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * documentation, and that the name of Keith Packard not be used in
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * advertising or publicity pertaining to distribution of the software without
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * specific, written prior permission. Keith Packard makes no
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * representations about the suitability of this software for any purpose. It
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * is provided "as is" without express or implied warranty.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * PERFORMANCE OF THIS SOFTWARE.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#ifndef _FBROP_H_
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define _FBROP_H_
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsynctypedef struct _mergeRopBits {
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync FbBits ca1, cx1, ca2, cx2;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync} FbMergeRopRec, *FbMergeRopPtr;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncextern _X_EXPORT const FbMergeRopRec FbMergeRopBits[16];
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbDeclareMergeRop() FbBits _ca1, _cx1, _ca2, _cx2;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbDeclarePrebuiltMergeRop() FbBits _cca, _ccx;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbInitializeMergeRop(alu,pm) {\
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync const FbMergeRopRec *_bits; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync _bits = &FbMergeRopBits[alu]; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync _ca1 = _bits->ca1 & pm; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync _cx1 = _bits->cx1 | ~pm; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync _ca2 = _bits->ca2 & pm; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync _cx2 = _bits->cx2 & pm; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync}
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbDestInvarientRop(alu,pm) ((pm) == FB_ALLONES && \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync (((alu) >> 1 & 5) == ((alu) & 5)))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbDestInvarientMergeRop() (_ca1 == 0 && _cx1 == 0)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/* AND has higher precedence than XOR */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbDoMergeRop(src, dst) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync (((dst) & (((src) & _ca1) ^ _cx1)) ^ (((src) & _ca2) ^ _cx2))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbDoDestInvarientMergeRop(src) (((src) & _ca2) ^ _cx2)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbDoMaskMergeRop(src, dst, mask) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync (((dst) & ((((src) & _ca1) ^ _cx1) | ~(mask))) ^ ((((src) & _ca2) ^ _cx2) & (mask)))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbDoLeftMaskByteMergeRop(dst, src, lb, l) { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync FbBits __xor = ((src) & _ca2) ^ _cx2; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync FbDoLeftMaskByteRRop(dst,lb,l,((src) & _ca1) ^ _cx1,__xor); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync}
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbDoRightMaskByteMergeRop(dst, src, rb, r) { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync FbBits __xor = ((src) & _ca2) ^ _cx2; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync FbDoRightMaskByteRRop(dst,rb,r,((src) & _ca1) ^ _cx1,__xor); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync}
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbDoRRop(dst, and, xor) (((dst) & (and)) ^ (xor))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbDoMaskRRop(dst, and, xor, mask) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync (((dst) & ((and) | ~(mask))) ^ (xor & mask))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/*
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Take a single bit (0 or 1) and generate a full mask
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define fbFillFromBit(b,t) (~((t) ((b) & 1)-1))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define fbXorT(rop,fg,pm,t) ((((fg) & fbFillFromBit((rop) >> 1,t)) | \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync (~(fg) & fbFillFromBit((rop) >> 3,t))) & (pm))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define fbAndT(rop,fg,pm,t) ((((fg) & fbFillFromBit (rop ^ (rop>>1),t)) | \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync (~(fg) & fbFillFromBit((rop>>2) ^ (rop>>3),t))) | \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ~(pm))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define fbXor(rop,fg,pm) fbXorT(rop,fg,pm,FbBits)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define fbAnd(rop,fg,pm) fbAndT(rop,fg,pm,FbBits)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define fbXorStip(rop,fg,pm) fbXorT(rop,fg,pm,FbStip)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define fbAndStip(rop,fg,pm) fbAndT(rop,fg,pm,FbStip)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/*
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Stippling operations;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbStippleRRop(dst, b, fa, fx, ba, bx) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync (FbDoRRop(dst, fa, fx) & b) | (FbDoRRop(dst, ba, bx) & ~b)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbStippleRRopMask(dst, b, fa, fx, ba, bx, m) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync (FbDoMaskRRop(dst, fa, fx, m) & (b)) | (FbDoMaskRRop(dst, ba, bx, m) & ~(b))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbDoLeftMaskByteStippleRRop(dst, b, fa, fx, ba, bx, lb, l) { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync FbBits __xor = ((fx) & (b)) | ((bx) & ~(b)); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync FbDoLeftMaskByteRRop(dst, lb, l, ((fa) & (b)) | ((ba) & ~(b)), __xor); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync}
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbDoRightMaskByteStippleRRop(dst, b, fa, fx, ba, bx, rb, r) { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync FbBits __xor = ((fx) & (b)) | ((bx) & ~(b)); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync FbDoRightMaskByteRRop(dst, rb, r, ((fa) & (b)) | ((ba) & ~(b)), __xor); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync}
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbOpaqueStipple(b, fg, bg) (((fg) & (b)) | ((bg) & ~(b)))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/*
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Compute rop for using tile code for 1-bit dest stipples; modifies
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * existing rop to flip depending on pixel values
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbStipple1RopPick(alu,b) (((alu) >> (2 - (((b) & 1) << 1))) & 3)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbOpaqueStipple1Rop(alu,fg,bg) (FbStipple1RopPick(alu,fg) | \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync (FbStipple1RopPick(alu,bg) << 2))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FbStipple1Rop(alu,fg) (FbStipple1RopPick(alu,fg) | 4)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif