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