take two
[profile/ivi/xorg-x11-drv-intel.git] / src / sna / fb / fbrop.h
1 /*
2  * Copyright © 1998 Keith Packard
3  * Copyright © 2012 Intel Corporation
4  *
5  * Permission to use, copy, modify, distribute, and sell this software and its
6  * documentation for any purpose is hereby granted without fee, provided that
7  * the above copyright notice appear in all copies and that both that
8  * copyright notice and this permission notice appear in supporting
9  * documentation, and that the name of Keith Packard not be used in
10  * advertising or publicity pertaining to distribution of the software without
11  * specific, written prior permission.  Keith Packard makes no
12  * representations about the suitability of this software for any purpose.  It
13  * is provided "as is" without express or implied warranty.
14  *
15  * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17  * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21  * PERFORMANCE OF THIS SOFTWARE.
22  */
23
24 #ifndef _FBROP_H_
25 #define _FBROP_H_
26
27 #define FbDestInvarientRop(alu,pm)  ((pm) == FB_ALLONES && \
28                                      (((alu) >> 1 & 5) == ((alu) & 5)))
29
30 #define FbDestInvarientMergeRop()   (_ca1 == 0 && _cx1 == 0)
31
32 /* AND has higher precedence than XOR */
33
34 #define FbDoMergeRop(src, dst) \
35     (((dst) & (((src) & _ca1) ^ _cx1)) ^ (((src) & _ca2) ^ _cx2))
36
37 #define FbDoDestInvarientMergeRop(src)  (((src) & _ca2) ^ _cx2)
38
39 #define FbDoMaskMergeRop(src, dst, mask) \
40     (((dst) & ((((src) & _ca1) ^ _cx1) | ~(mask))) ^ ((((src) & _ca2) ^ _cx2) & (mask)))
41
42 #define FbDoLeftMaskByteMergeRop(dst, src, lb, l) { \
43     FbBits  __xor = ((src) & _ca2) ^ _cx2; \
44     FbDoLeftMaskByteRRop(dst,lb,l,((src) & _ca1) ^ _cx1,__xor); \
45 }
46
47 #define FbDoRightMaskByteMergeRop(dst, src, rb, r) { \
48     FbBits  __xor = ((src) & _ca2) ^ _cx2; \
49     FbDoRightMaskByteRRop(dst,rb,r,((src) & _ca1) ^ _cx1,__xor); \
50 }
51
52 #define FbDoRRop(dst, and, xor) (((dst) & (and)) ^ (xor))
53
54 #define FbDoMaskRRop(dst, and, xor, mask) \
55     (((dst) & ((and) | ~(mask))) ^ (xor & mask))
56
57 /*
58  * Take a single bit (0 or 1) and generate a full mask
59  */
60 #define fbFillFromBit(b,t)      (~((t) ((b) & 1)-1))
61
62 #define fbXorT(rop,fg,pm,t) ((((fg) & fbFillFromBit((rop) >> 1,t)) | \
63                               (~(fg) & fbFillFromBit((rop) >> 3,t))) & (pm))
64
65 #define fbAndT(rop,fg,pm,t) ((((fg) & fbFillFromBit (rop ^ (rop>>1),t)) | \
66                               (~(fg) & fbFillFromBit((rop>>2) ^ (rop>>3),t))) | \
67                              ~(pm))
68
69 #define fbXor(rop,fg,pm)        fbXorT(rop,fg,pm,FbBits)
70
71 #define fbAnd(rop,fg,pm)        fbAndT(rop,fg,pm,FbBits)
72
73 #define fbXorStip(rop,fg,pm)    fbXorT(rop,fg,pm,FbStip)
74
75 #define fbAndStip(rop,fg,pm)    fbAndT(rop,fg,pm,FbStip)
76
77 /*
78  * Stippling operations; 
79  */
80 extern const FbBits *const fbStippleTable[];
81
82 #define FbStippleRRop(dst, b, fa, fx, ba, bx) \
83     (FbDoRRop(dst, fa, fx) & b) | (FbDoRRop(dst, ba, bx) & ~b)
84
85 #define FbStippleRRopMask(dst, b, fa, fx, ba, bx, m) \
86     (FbDoMaskRRop(dst, fa, fx, m) & (b)) | (FbDoMaskRRop(dst, ba, bx, m) & ~(b))
87
88 #define FbDoLeftMaskByteStippleRRop(dst, b, fa, fx, ba, bx, lb, l) { \
89     FbBits  __xor = ((fx) & (b)) | ((bx) & ~(b)); \
90     FbDoLeftMaskByteRRop(dst, lb, l, ((fa) & (b)) | ((ba) & ~(b)), __xor); \
91 }
92
93 #define FbDoRightMaskByteStippleRRop(dst, b, fa, fx, ba, bx, rb, r) { \
94     FbBits  __xor = ((fx) & (b)) | ((bx) & ~(b)); \
95     FbDoRightMaskByteRRop(dst, rb, r, ((fa) & (b)) | ((ba) & ~(b)), __xor); \
96 }
97
98 #define FbOpaqueStipple(b, fg, bg) (((fg) & (b)) | ((bg) & ~(b)))
99
100 /*
101  * Compute rop for using tile code for 1-bit dest stipples; modifies
102  * existing rop to flip depending on pixel values
103  */
104 #define FbStipple1RopPick(alu,b)    (((alu) >> (2 - (((b) & 1) << 1))) & 3)
105
106 #define FbOpaqueStipple1Rop(alu,fg,bg)    (FbStipple1RopPick(alu,fg) | \
107                                            (FbStipple1RopPick(alu,bg) << 2))
108
109 #define FbStipple1Rop(alu,fg)       (FbStipple1RopPick(alu,fg) | 4)
110
111 #endif