Imported Upstream version 1.15.1
[deb_xorg-server.git] / fb / fbsolid.c
CommitLineData
a09e091a
JB
1/*
2 * Copyright © 1998 Keith Packard
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Keith Packard not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Keith Packard makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
13 *
14 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 */
22
23#define FbSelectPart(xor,o,t) xor
24
25#ifdef HAVE_DIX_CONFIG_H
26#include <dix-config.h>
27#endif
28
29#include "fb.h"
30
31void
32fbSolid(FbBits * dst,
33 FbStride dstStride,
34 int dstX, int bpp, int width, int height, FbBits and, FbBits xor)
35{
36 FbBits startmask, endmask;
37 int n, nmiddle;
38 int startbyte, endbyte;
39
40 if (bpp == 24 && (!FbCheck24Pix(and) || !FbCheck24Pix(xor))) {
41 fbSolid24(dst, dstStride, dstX, width, height, and, xor);
42 return;
43 }
44 dst += dstX >> FB_SHIFT;
45 dstX &= FB_MASK;
46 FbMaskBitsBytes(dstX, width, and == 0, startmask, startbyte,
47 nmiddle, endmask, endbyte);
48 if (startmask)
49 dstStride--;
50 dstStride -= nmiddle;
51 while (height--) {
52 if (startmask) {
53 FbDoLeftMaskByteRRop(dst, startbyte, startmask, and, xor);
54 dst++;
55 }
56 n = nmiddle;
57 if (!and)
58 while (n--)
59 WRITE(dst++, xor);
60 else
61 while (n--) {
62 WRITE(dst, FbDoRRop(READ(dst), and, xor));
63 dst++;
64 }
65 if (endmask)
66 FbDoRightMaskByteRRop(dst, endbyte, endmask, and, xor);
67 dst += dstStride;
68 }
69}
70
71void
72fbSolid24(FbBits * dst,
73 FbStride dstStride,
74 int dstX, int width, int height, FbBits and, FbBits xor)
75{
76 FbBits startmask, endmask;
77 FbBits xor0 = 0, xor1 = 0, xor2 = 0;
78 FbBits and0 = 0, and1 = 0, and2 = 0;
79 FbBits xorS = 0, andS = 0, xorE = 0, andE = 0;
80 int n, nmiddle;
81 int rotS, rot;
82
83 dst += dstX >> FB_SHIFT;
84 dstX &= FB_MASK;
85 /*
86 * Rotate pixel values this far across the word to align on
87 * screen pixel boundaries
88 */
89 rot = FbFirst24Rot(dstX);
90 FbMaskBits(dstX, width, startmask, nmiddle, endmask);
91 if (startmask)
92 dstStride--;
93 dstStride -= nmiddle;
94
95 /*
96 * Precompute rotated versions of the rasterop values
97 */
98 rotS = rot;
99 xor = FbRot24(xor, rotS);
100 and = FbRot24(and, rotS);
101 if (startmask) {
102 xorS = xor;
103 andS = and;
104 xor = FbNext24Pix(xor);
105 and = FbNext24Pix(and);
106 }
107
108 if (nmiddle) {
109 xor0 = xor;
110 and0 = and;
111 xor1 = FbNext24Pix(xor0);
112 and1 = FbNext24Pix(and0);
113 xor2 = FbNext24Pix(xor1);
114 and2 = FbNext24Pix(and1);
115 }
116
117 if (endmask) {
118 switch (nmiddle % 3) {
119 case 0:
120 xorE = xor;
121 andE = and;
122 break;
123 case 1:
124 xorE = xor1;
125 andE = and1;
126 break;
127 case 2:
128 xorE = xor2;
129 andE = and2;
130 break;
131 }
132 }
133
134 while (height--) {
135 if (startmask) {
136 WRITE(dst, FbDoMaskRRop(READ(dst), andS, xorS, startmask));
137 dst++;
138 }
139 n = nmiddle;
140 if (!and0) {
141 while (n >= 3) {
142 WRITE(dst++, xor0);
143 WRITE(dst++, xor1);
144 WRITE(dst++, xor2);
145 n -= 3;
146 }
147 if (n) {
148 WRITE(dst++, xor0);
149 n--;
150 if (n) {
151 WRITE(dst++, xor1);
152 }
153 }
154 }
155 else {
156 while (n >= 3) {
157 WRITE(dst, FbDoRRop(READ(dst), and0, xor0));
158 dst++;
159 WRITE(dst, FbDoRRop(READ(dst), and1, xor1));
160 dst++;
161 WRITE(dst, FbDoRRop(READ(dst), and2, xor2));
162 dst++;
163 n -= 3;
164 }
165 if (n) {
166 WRITE(dst, FbDoRRop(READ(dst), and0, xor0));
167 dst++;
168 n--;
169 if (n) {
170 WRITE(dst, FbDoRRop(READ(dst), and1, xor1));
171 dst++;
172 }
173 }
174 }
175 if (endmask)
176 WRITE(dst, FbDoMaskRRop(READ(dst), andE, xorE, endmask));
177 dst += dstStride;
178 }
179}