1706f2543Smrg/*
2706f2543Smrg * Copyright © 1998 Keith Packard
3706f2543Smrg *
4706f2543Smrg * Permission to use, copy, modify, distribute, and sell this software and its
5706f2543Smrg * documentation for any purpose is hereby granted without fee, provided that
6706f2543Smrg * the above copyright notice appear in all copies and that both that
7706f2543Smrg * copyright notice and this permission notice appear in supporting
8706f2543Smrg * documentation, and that the name of Keith Packard not be used in
9706f2543Smrg * advertising or publicity pertaining to distribution of the software without
10706f2543Smrg * specific, written prior permission.  Keith Packard makes no
11706f2543Smrg * representations about the suitability of this software for any purpose.  It
12706f2543Smrg * is provided "as is" without express or implied warranty.
13706f2543Smrg *
14706f2543Smrg * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15706f2543Smrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16706f2543Smrg * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17706f2543Smrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18706f2543Smrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19706f2543Smrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20706f2543Smrg * PERFORMANCE OF THIS SOFTWARE.
21706f2543Smrg */
22706f2543Smrg
23706f2543Smrg#ifndef _FBROP_H_
24706f2543Smrg#define _FBROP_H_
25706f2543Smrg
26706f2543Smrgtypedef struct _mergeRopBits {
27706f2543Smrg    FbBits   ca1, cx1, ca2, cx2;
28706f2543Smrg} FbMergeRopRec, *FbMergeRopPtr;
29706f2543Smrg
30706f2543Smrgextern _X_EXPORT const FbMergeRopRec	FbMergeRopBits[16];
31706f2543Smrg
32706f2543Smrg#define FbDeclareMergeRop() FbBits   _ca1, _cx1, _ca2, _cx2;
33706f2543Smrg#define FbDeclarePrebuiltMergeRop()	FbBits	_cca, _ccx;
34706f2543Smrg
35706f2543Smrg#define FbInitializeMergeRop(alu,pm) {\
36706f2543Smrg    const FbMergeRopRec  *_bits; \
37706f2543Smrg    _bits = &FbMergeRopBits[alu]; \
38706f2543Smrg    _ca1 = _bits->ca1 &  pm; \
39706f2543Smrg    _cx1 = _bits->cx1 | ~pm; \
40706f2543Smrg    _ca2 = _bits->ca2 &  pm; \
41706f2543Smrg    _cx2 = _bits->cx2 &  pm; \
42706f2543Smrg}
43706f2543Smrg
44706f2543Smrg#define FbDestInvarientRop(alu,pm)  ((pm) == FB_ALLONES && \
45706f2543Smrg				     (((alu) >> 1 & 5) == ((alu) & 5)))
46706f2543Smrg
47706f2543Smrg#define FbDestInvarientMergeRop()   (_ca1 == 0 && _cx1 == 0)
48706f2543Smrg
49706f2543Smrg/* AND has higher precedence than XOR */
50706f2543Smrg
51706f2543Smrg#define FbDoMergeRop(src, dst) \
52706f2543Smrg    (((dst) & (((src) & _ca1) ^ _cx1)) ^ (((src) & _ca2) ^ _cx2))
53706f2543Smrg
54706f2543Smrg#define FbDoDestInvarientMergeRop(src)	(((src) & _ca2) ^ _cx2)
55706f2543Smrg
56706f2543Smrg#define FbDoMaskMergeRop(src, dst, mask) \
57706f2543Smrg    (((dst) & ((((src) & _ca1) ^ _cx1) | ~(mask))) ^ ((((src) & _ca2) ^ _cx2) & (mask)))
58706f2543Smrg
59706f2543Smrg#define FbDoLeftMaskByteMergeRop(dst, src, lb, l) { \
60706f2543Smrg    FbBits  __xor = ((src) & _ca2) ^ _cx2; \
61706f2543Smrg    FbDoLeftMaskByteRRop(dst,lb,l,((src) & _ca1) ^ _cx1,__xor); \
62706f2543Smrg}
63706f2543Smrg
64706f2543Smrg#define FbDoRightMaskByteMergeRop(dst, src, rb, r) { \
65706f2543Smrg    FbBits  __xor = ((src) & _ca2) ^ _cx2; \
66706f2543Smrg    FbDoRightMaskByteRRop(dst,rb,r,((src) & _ca1) ^ _cx1,__xor); \
67706f2543Smrg}
68706f2543Smrg
69706f2543Smrg#define FbDoRRop(dst, and, xor)	(((dst) & (and)) ^ (xor))
70706f2543Smrg
71706f2543Smrg#define FbDoMaskRRop(dst, and, xor, mask) \
72706f2543Smrg    (((dst) & ((and) | ~(mask))) ^ (xor & mask))
73706f2543Smrg
74706f2543Smrg/*
75706f2543Smrg * Take a single bit (0 or 1) and generate a full mask
76706f2543Smrg */
77706f2543Smrg#define fbFillFromBit(b,t)	(~((t) ((b) & 1)-1))
78706f2543Smrg
79706f2543Smrg#define fbXorT(rop,fg,pm,t) ((((fg) & fbFillFromBit((rop) >> 1,t)) | \
80706f2543Smrg			      (~(fg) & fbFillFromBit((rop) >> 3,t))) & (pm))
81706f2543Smrg
82706f2543Smrg#define fbAndT(rop,fg,pm,t) ((((fg) & fbFillFromBit (rop ^ (rop>>1),t)) | \
83706f2543Smrg			      (~(fg) & fbFillFromBit((rop>>2) ^ (rop>>3),t))) | \
84706f2543Smrg			     ~(pm))
85706f2543Smrg
86706f2543Smrg#define fbXor(rop,fg,pm)	fbXorT(rop,fg,pm,FbBits)
87706f2543Smrg
88706f2543Smrg#define fbAnd(rop,fg,pm)	fbAndT(rop,fg,pm,FbBits)
89706f2543Smrg
90706f2543Smrg#define fbXorStip(rop,fg,pm)    fbXorT(rop,fg,pm,FbStip)
91706f2543Smrg
92706f2543Smrg#define fbAndStip(rop,fg,pm)	fbAndT(rop,fg,pm,FbStip)
93706f2543Smrg
94706f2543Smrg/*
95706f2543Smrg * Stippling operations;
96706f2543Smrg */
97706f2543Smrg
98706f2543Smrgextern _X_EXPORT const FbBits	fbStipple16Bits[256];	/* half of table */
99706f2543Smrg#define FbStipple16Bits(b) \
100706f2543Smrg    (fbStipple16Bits[(b)&0xff] | fbStipple16Bits[(b) >> 8] << FB_HALFUNIT)
101706f2543Smrgextern _X_EXPORT const FbBits	fbStipple8Bits[256];
102706f2543Smrgextern _X_EXPORT const FbBits	fbStipple4Bits[16];
103706f2543Smrgextern _X_EXPORT const FbBits	fbStipple2Bits[4];
104706f2543Smrgextern _X_EXPORT const FbBits	fbStipple1Bits[2];
105706f2543Smrgextern _X_EXPORT const FbBits	*const fbStippleTable[];
106706f2543Smrg
107706f2543Smrg#define FbStippleRRop(dst, b, fa, fx, ba, bx) \
108706f2543Smrg    (FbDoRRop(dst, fa, fx) & b) | (FbDoRRop(dst, ba, bx) & ~b)
109706f2543Smrg
110706f2543Smrg#define FbStippleRRopMask(dst, b, fa, fx, ba, bx, m) \
111706f2543Smrg    (FbDoMaskRRop(dst, fa, fx, m) & (b)) | (FbDoMaskRRop(dst, ba, bx, m) & ~(b))
112706f2543Smrg
113706f2543Smrg#define FbDoLeftMaskByteStippleRRop(dst, b, fa, fx, ba, bx, lb, l) { \
114706f2543Smrg    FbBits  __xor = ((fx) & (b)) | ((bx) & ~(b)); \
115706f2543Smrg    FbDoLeftMaskByteRRop(dst, lb, l, ((fa) & (b)) | ((ba) & ~(b)), __xor); \
116706f2543Smrg}
117706f2543Smrg
118706f2543Smrg#define FbDoRightMaskByteStippleRRop(dst, b, fa, fx, ba, bx, rb, r) { \
119706f2543Smrg    FbBits  __xor = ((fx) & (b)) | ((bx) & ~(b)); \
120706f2543Smrg    FbDoRightMaskByteRRop(dst, rb, r, ((fa) & (b)) | ((ba) & ~(b)), __xor); \
121706f2543Smrg}
122706f2543Smrg
123706f2543Smrg#define FbOpaqueStipple(b, fg, bg) (((fg) & (b)) | ((bg) & ~(b)))
124706f2543Smrg
125706f2543Smrg/*
126706f2543Smrg * Compute rop for using tile code for 1-bit dest stipples; modifies
127706f2543Smrg * existing rop to flip depending on pixel values
128706f2543Smrg */
129706f2543Smrg#define FbStipple1RopPick(alu,b)    (((alu) >> (2 - (((b) & 1) << 1))) & 3)
130706f2543Smrg
131706f2543Smrg#define FbOpaqueStipple1Rop(alu,fg,bg)    (FbStipple1RopPick(alu,fg) | \
132706f2543Smrg					   (FbStipple1RopPick(alu,bg) << 2))
133706f2543Smrg
134706f2543Smrg#define FbStipple1Rop(alu,fg)	    (FbStipple1RopPick(alu,fg) | 4)
135706f2543Smrg
136706f2543Smrg#endif
137