103b705cfSriastradh/* 203b705cfSriastradh * Copyright © 1998 Keith Packard 303b705cfSriastradh * Copyright © 2012 Intel Corporation 403b705cfSriastradh * 503b705cfSriastradh * Permission to use, copy, modify, distribute, and sell this software and its 603b705cfSriastradh * documentation for any purpose is hereby granted without fee, provided that 703b705cfSriastradh * the above copyright notice appear in all copies and that both that 803b705cfSriastradh * copyright notice and this permission notice appear in supporting 903b705cfSriastradh * documentation, and that the name of Keith Packard not be used in 1003b705cfSriastradh * advertising or publicity pertaining to distribution of the software without 1103b705cfSriastradh * specific, written prior permission. Keith Packard makes no 1203b705cfSriastradh * representations about the suitability of this software for any purpose. It 1303b705cfSriastradh * is provided "as is" without express or implied warranty. 1403b705cfSriastradh * 1503b705cfSriastradh * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 1603b705cfSriastradh * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 1703b705cfSriastradh * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR 1803b705cfSriastradh * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 1903b705cfSriastradh * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 2003b705cfSriastradh * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 2103b705cfSriastradh * PERFORMANCE OF THIS SOFTWARE. 2203b705cfSriastradh */ 2303b705cfSriastradh 2403b705cfSriastradh#ifndef _FBROP_H_ 2503b705cfSriastradh#define _FBROP_H_ 2603b705cfSriastradh 2703b705cfSriastradh#define FbDestInvarientRop(alu,pm) ((pm) == FB_ALLONES && \ 2803b705cfSriastradh (((alu) >> 1 & 5) == ((alu) & 5))) 2903b705cfSriastradh 3003b705cfSriastradh#define FbDestInvarientMergeRop() (_ca1 == 0 && _cx1 == 0) 3103b705cfSriastradh 3203b705cfSriastradh/* AND has higher precedence than XOR */ 3303b705cfSriastradh 3403b705cfSriastradh#define FbDoMergeRop(src, dst) \ 3503b705cfSriastradh (((dst) & (((src) & _ca1) ^ _cx1)) ^ (((src) & _ca2) ^ _cx2)) 3603b705cfSriastradh 3703b705cfSriastradh#define FbDoDestInvarientMergeRop(src) (((src) & _ca2) ^ _cx2) 3803b705cfSriastradh 3903b705cfSriastradh#define FbDoMaskMergeRop(src, dst, mask) \ 4003b705cfSriastradh (((dst) & ((((src) & _ca1) ^ _cx1) | ~(mask))) ^ ((((src) & _ca2) ^ _cx2) & (mask))) 4103b705cfSriastradh 4203b705cfSriastradh#define FbDoLeftMaskByteMergeRop(dst, src, lb, l) { \ 4303b705cfSriastradh FbBits __xor = ((src) & _ca2) ^ _cx2; \ 4403b705cfSriastradh FbDoLeftMaskByteRRop(dst,lb,l,((src) & _ca1) ^ _cx1,__xor); \ 4503b705cfSriastradh} 4603b705cfSriastradh 4703b705cfSriastradh#define FbDoRightMaskByteMergeRop(dst, src, rb, r) { \ 4803b705cfSriastradh FbBits __xor = ((src) & _ca2) ^ _cx2; \ 4903b705cfSriastradh FbDoRightMaskByteRRop(dst,rb,r,((src) & _ca1) ^ _cx1,__xor); \ 5003b705cfSriastradh} 5103b705cfSriastradh 5203b705cfSriastradh#define FbDoRRop(dst, and, xor) (((dst) & (and)) ^ (xor)) 5303b705cfSriastradh 5403b705cfSriastradh#define FbDoMaskRRop(dst, and, xor, mask) \ 5503b705cfSriastradh (((dst) & ((and) | ~(mask))) ^ (xor & mask)) 5603b705cfSriastradh 5703b705cfSriastradh/* 5803b705cfSriastradh * Take a single bit (0 or 1) and generate a full mask 5903b705cfSriastradh */ 6003b705cfSriastradh#define fbFillFromBit(b,t) (~((t) ((b) & 1)-1)) 6103b705cfSriastradh 6203b705cfSriastradh#define fbXorT(rop,fg,pm,t) ((((fg) & fbFillFromBit((rop) >> 1,t)) | \ 6303b705cfSriastradh (~(fg) & fbFillFromBit((rop) >> 3,t))) & (pm)) 6403b705cfSriastradh 6503b705cfSriastradh#define fbAndT(rop,fg,pm,t) ((((fg) & fbFillFromBit (rop ^ (rop>>1),t)) | \ 6603b705cfSriastradh (~(fg) & fbFillFromBit((rop>>2) ^ (rop>>3),t))) | \ 6703b705cfSriastradh ~(pm)) 6803b705cfSriastradh 6903b705cfSriastradh#define fbXor(rop,fg,pm) fbXorT(rop,fg,pm,FbBits) 7003b705cfSriastradh 7103b705cfSriastradh#define fbAnd(rop,fg,pm) fbAndT(rop,fg,pm,FbBits) 7203b705cfSriastradh 7303b705cfSriastradh#define fbXorStip(rop,fg,pm) fbXorT(rop,fg,pm,FbStip) 7403b705cfSriastradh 7503b705cfSriastradh#define fbAndStip(rop,fg,pm) fbAndT(rop,fg,pm,FbStip) 7603b705cfSriastradh 7703b705cfSriastradh/* 7803b705cfSriastradh * Stippling operations; 7903b705cfSriastradh */ 8003b705cfSriastradhextern const FbBits *const fbStippleTable[]; 8103b705cfSriastradh 8203b705cfSriastradh#define FbStippleRRop(dst, b, fa, fx, ba, bx) \ 8303b705cfSriastradh (FbDoRRop(dst, fa, fx) & b) | (FbDoRRop(dst, ba, bx) & ~b) 8403b705cfSriastradh 8503b705cfSriastradh#define FbStippleRRopMask(dst, b, fa, fx, ba, bx, m) \ 8603b705cfSriastradh (FbDoMaskRRop(dst, fa, fx, m) & (b)) | (FbDoMaskRRop(dst, ba, bx, m) & ~(b)) 8703b705cfSriastradh 8803b705cfSriastradh#define FbDoLeftMaskByteStippleRRop(dst, b, fa, fx, ba, bx, lb, l) { \ 8903b705cfSriastradh FbBits __xor = ((fx) & (b)) | ((bx) & ~(b)); \ 9003b705cfSriastradh FbDoLeftMaskByteRRop(dst, lb, l, ((fa) & (b)) | ((ba) & ~(b)), __xor); \ 9103b705cfSriastradh} 9203b705cfSriastradh 9303b705cfSriastradh#define FbDoRightMaskByteStippleRRop(dst, b, fa, fx, ba, bx, rb, r) { \ 9403b705cfSriastradh FbBits __xor = ((fx) & (b)) | ((bx) & ~(b)); \ 9503b705cfSriastradh FbDoRightMaskByteRRop(dst, rb, r, ((fa) & (b)) | ((ba) & ~(b)), __xor); \ 9603b705cfSriastradh} 9703b705cfSriastradh 9803b705cfSriastradh#define FbOpaqueStipple(b, fg, bg) (((fg) & (b)) | ((bg) & ~(b))) 9903b705cfSriastradh 10003b705cfSriastradh/* 10103b705cfSriastradh * Compute rop for using tile code for 1-bit dest stipples; modifies 10203b705cfSriastradh * existing rop to flip depending on pixel values 10303b705cfSriastradh */ 10403b705cfSriastradh#define FbStipple1RopPick(alu,b) (((alu) >> (2 - (((b) & 1) << 1))) & 3) 10503b705cfSriastradh 10603b705cfSriastradh#define FbOpaqueStipple1Rop(alu,fg,bg) (FbStipple1RopPick(alu,fg) | \ 10703b705cfSriastradh (FbStipple1RopPick(alu,bg) << 2)) 10803b705cfSriastradh 10903b705cfSriastradh#define FbStipple1Rop(alu,fg) (FbStipple1RopPick(alu,fg) | 4) 11003b705cfSriastradh 11103b705cfSriastradh#endif 112