rasops_bitops.h revision 1.18 1 1.18 rin /* $NetBSD: rasops_bitops.h,v 1.18 2019/07/30 15:29:40 rin Exp $ */
2 1.1 ad
3 1.3 ad /*-
4 1.3 ad * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 1.1 ad * All rights reserved.
6 1.1 ad *
7 1.3 ad * This code is derived from software contributed to The NetBSD Foundation
8 1.7 ad * by Andrew Doran.
9 1.3 ad *
10 1.1 ad * Redistribution and use in source and binary forms, with or without
11 1.1 ad * modification, are permitted provided that the following conditions
12 1.1 ad * are met:
13 1.1 ad * 1. Redistributions of source code must retain the above copyright
14 1.1 ad * notice, this list of conditions and the following disclaimer.
15 1.1 ad * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 ad * notice, this list of conditions and the following disclaimer in the
17 1.1 ad * documentation and/or other materials provided with the distribution.
18 1.1 ad *
19 1.3 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.3 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.3 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.3 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.3 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.3 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.3 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.3 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.3 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.3 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.3 ad * POSSIBILITY OF SUCH DAMAGE.
30 1.1 ad */
31 1.1 ad
32 1.1 ad #ifndef _RASOPS_BITOPS_H_
33 1.1 ad #define _RASOPS_BITOPS_H_ 1
34 1.1 ad
35 1.1 ad /*
36 1.1 ad * Erase columns.
37 1.1 ad */
38 1.1 ad static void
39 1.11 cegger NAME(erasecols)(void *cookie, int row, int col, int num, long attr)
40 1.1 ad {
41 1.15 tsutsui int lclr, rclr, clr;
42 1.1 ad struct rasops_info *ri;
43 1.18 rin uint32_t *dp, *rp, *hp, tmp, lmask, rmask;
44 1.1 ad int height, cnt;
45 1.6 pk
46 1.18 rin hp = NULL; /* XXX GCC */
47 1.18 rin
48 1.1 ad ri = (struct rasops_info *)cookie;
49 1.1 ad
50 1.6 pk #ifdef RASOPS_CLIPPING
51 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
52 1.1 ad return;
53 1.1 ad
54 1.1 ad if (col < 0) {
55 1.1 ad num += col;
56 1.1 ad col = 0;
57 1.1 ad }
58 1.1 ad
59 1.1 ad if ((col + num) > ri->ri_cols)
60 1.1 ad num = ri->ri_cols - col;
61 1.6 pk
62 1.1 ad if (num <= 0)
63 1.1 ad return;
64 1.1 ad #endif
65 1.1 ad col *= ri->ri_font->fontwidth << PIXEL_SHIFT;
66 1.1 ad num *= ri->ri_font->fontwidth << PIXEL_SHIFT;
67 1.1 ad height = ri->ri_font->fontheight;
68 1.17 rin clr = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
69 1.15 tsutsui rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + ((col >> 3) & ~3));
70 1.12 macallan if (ri->ri_hwbits)
71 1.18 rin hp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
72 1.12 macallan ((col >> 3) & ~3));
73 1.1 ad if ((col & 31) + num <= 32) {
74 1.1 ad lmask = ~rasops_pmask[col & 31][num];
75 1.1 ad lclr = clr & ~lmask;
76 1.1 ad
77 1.1 ad while (height--) {
78 1.1 ad dp = rp;
79 1.15 tsutsui DELTA(rp, ri->ri_stride, uint32_t *);
80 1.1 ad
81 1.12 macallan tmp = (*dp & lmask) | lclr;
82 1.12 macallan *dp = tmp;
83 1.12 macallan if (ri->ri_hwbits) {
84 1.18 rin *hp = tmp;
85 1.18 rin DELTA(hp, ri->ri_stride, uint32_t *);
86 1.12 macallan }
87 1.1 ad }
88 1.1 ad } else {
89 1.1 ad lmask = rasops_rmask[col & 31];
90 1.1 ad rmask = rasops_lmask[(col + num) & 31];
91 1.6 pk
92 1.1 ad if (lmask)
93 1.1 ad num = (num - (32 - (col & 31))) >> 5;
94 1.1 ad else
95 1.1 ad num = num >> 5;
96 1.6 pk
97 1.1 ad lclr = clr & ~lmask;
98 1.1 ad rclr = clr & ~rmask;
99 1.1 ad
100 1.1 ad while (height--) {
101 1.1 ad dp = rp;
102 1.1 ad
103 1.8 thorpej if (lmask) {
104 1.18 rin *dp = (*dp & lmask) | lclr;
105 1.8 thorpej dp++;
106 1.8 thorpej }
107 1.1 ad
108 1.1 ad for (cnt = num; cnt > 0; cnt--)
109 1.1 ad *dp++ = clr;
110 1.18 rin
111 1.18 rin if (rmask)
112 1.18 rin *dp = (*dp & rmask) | rclr;
113 1.18 rin
114 1.12 macallan if (ri->ri_hwbits) {
115 1.18 rin memcpy(hp, rp, ((lmask != 0) + num +
116 1.18 rin (rmask != 0)) << 2);
117 1.18 rin DELTA(hp, ri->ri_stride, uint32_t *);
118 1.12 macallan }
119 1.18 rin DELTA(rp, ri->ri_stride, uint32_t *);
120 1.1 ad }
121 1.1 ad }
122 1.1 ad }
123 1.1 ad
124 1.1 ad /*
125 1.1 ad * Actually paint the cursor.
126 1.1 ad */
127 1.1 ad static void
128 1.11 cegger NAME(do_cursor)(struct rasops_info *ri)
129 1.1 ad {
130 1.15 tsutsui int height, row, col, num;
131 1.18 rin uint32_t *dp, *rp, *hrp, *hp, tmp, lmask, rmask;
132 1.18 rin
133 1.18 rin hrp = hp = NULL; /* XXX GCC */
134 1.6 pk
135 1.1 ad row = ri->ri_crow;
136 1.1 ad col = ri->ri_ccol * ri->ri_font->fontwidth << PIXEL_SHIFT;
137 1.1 ad height = ri->ri_font->fontheight;
138 1.1 ad num = ri->ri_font->fontwidth << PIXEL_SHIFT;
139 1.16 rin rp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale +
140 1.16 rin ((col >> 3) & ~3));
141 1.12 macallan if (ri->ri_hwbits)
142 1.15 tsutsui hrp = (uint32_t *)(ri->ri_hwbits + row * ri->ri_yscale +
143 1.12 macallan ((col >> 3) & ~3));
144 1.6 pk
145 1.1 ad if ((col & 31) + num <= 32) {
146 1.1 ad lmask = rasops_pmask[col & 31][num];
147 1.1 ad
148 1.1 ad while (height--) {
149 1.18 rin tmp = *rp ^ lmask;
150 1.18 rin *rp = tmp;
151 1.18 rin if (ri->ri_hwbits) {
152 1.18 rin *hrp = tmp;
153 1.15 tsutsui DELTA(hrp, ri->ri_stride, uint32_t *);
154 1.12 macallan }
155 1.18 rin DELTA(rp, ri->ri_stride, uint32_t *);
156 1.12 macallan }
157 1.1 ad } else {
158 1.1 ad lmask = ~rasops_rmask[col & 31];
159 1.1 ad rmask = ~rasops_lmask[(col + num) & 31];
160 1.1 ad
161 1.1 ad while (height--) {
162 1.1 ad dp = rp;
163 1.15 tsutsui DELTA(rp, ri->ri_stride, uint32_t *);
164 1.12 macallan if (ri->ri_hwbits) {
165 1.12 macallan hp = hrp;
166 1.15 tsutsui DELTA(hrp, ri->ri_stride, uint32_t *);
167 1.12 macallan }
168 1.18 rin
169 1.12 macallan if (lmask != -1) {
170 1.12 macallan tmp = *dp ^ lmask;
171 1.12 macallan *dp = tmp;
172 1.12 macallan dp++;
173 1.12 macallan if (ri->ri_hwbits) {
174 1.12 macallan *hp = tmp;
175 1.12 macallan hp++;
176 1.12 macallan }
177 1.12 macallan }
178 1.1 ad
179 1.12 macallan if (rmask != -1) {
180 1.12 macallan tmp = *dp ^ rmask;
181 1.12 macallan *dp = tmp;
182 1.12 macallan if (ri->ri_hwbits)
183 1.12 macallan *hp = tmp;
184 1.12 macallan }
185 1.1 ad }
186 1.1 ad }
187 1.1 ad }
188 1.1 ad
189 1.1 ad /*
190 1.4 ad * Copy columns. Ick!
191 1.1 ad */
192 1.1 ad static void
193 1.11 cegger NAME(copycols)(void *cookie, int row, int src, int dst, int num)
194 1.1 ad {
195 1.18 rin struct rasops_info *ri = (struct rasops_info *)cookie;
196 1.15 tsutsui int height, lnum, rnum, sb, db, cnt, full;
197 1.15 tsutsui uint32_t tmp, lmask, rmask;
198 1.18 rin uint32_t *sp, *dp, *srp, *drp, *dhp, *hp;
199 1.6 pk
200 1.18 rin dhp = hp = NULL; /* XXX GCC */
201 1.1 ad
202 1.1 ad #ifdef RASOPS_CLIPPING
203 1.1 ad if (dst == src)
204 1.1 ad return;
205 1.6 pk
206 1.1 ad /* Catches < 0 case too */
207 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
208 1.1 ad return;
209 1.6 pk
210 1.1 ad if (src < 0) {
211 1.1 ad num += src;
212 1.1 ad src = 0;
213 1.1 ad }
214 1.1 ad
215 1.18 rin if (src + num > ri->ri_cols)
216 1.1 ad num = ri->ri_cols - src;
217 1.1 ad
218 1.1 ad if (dst < 0) {
219 1.1 ad num += dst;
220 1.1 ad dst = 0;
221 1.1 ad }
222 1.1 ad
223 1.18 rin if (dst + num > ri->ri_cols)
224 1.1 ad num = ri->ri_cols - dst;
225 1.6 pk
226 1.1 ad if (num <= 0)
227 1.1 ad return;
228 1.1 ad #endif
229 1.6 pk
230 1.1 ad cnt = ri->ri_font->fontwidth << PIXEL_SHIFT;
231 1.1 ad src *= cnt;
232 1.1 ad dst *= cnt;
233 1.1 ad num *= cnt;
234 1.1 ad row *= ri->ri_yscale;
235 1.1 ad height = ri->ri_font->fontheight;
236 1.4 ad db = dst & 31;
237 1.1 ad
238 1.6 pk if (db + num <= 32) {
239 1.4 ad /* Destination is contained within a single word */
240 1.15 tsutsui srp = (uint32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
241 1.15 tsutsui drp = (uint32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
242 1.12 macallan if (ri->ri_hwbits)
243 1.15 tsutsui dhp = (uint32_t *)(ri->ri_hwbits + row +
244 1.12 macallan ((dst >> 3) & ~3));
245 1.1 ad sb = src & 31;
246 1.1 ad
247 1.1 ad while (height--) {
248 1.1 ad GETBITS(srp, sb, num, tmp);
249 1.1 ad PUTBITS(tmp, db, num, drp);
250 1.12 macallan if (ri->ri_hwbits) {
251 1.12 macallan PUTBITS(tmp, db, num, dhp);
252 1.15 tsutsui DELTA(dhp, ri->ri_stride, uint32_t *);
253 1.12 macallan }
254 1.15 tsutsui DELTA(srp, ri->ri_stride, uint32_t *);
255 1.15 tsutsui DELTA(drp, ri->ri_stride, uint32_t *);
256 1.1 ad }
257 1.6 pk
258 1.1 ad return;
259 1.1 ad }
260 1.1 ad
261 1.4 ad lmask = rasops_rmask[db];
262 1.1 ad rmask = rasops_lmask[(dst + num) & 31];
263 1.4 ad lnum = (32 - db) & 31;
264 1.6 pk rnum = (dst + num) & 31;
265 1.6 pk
266 1.1 ad if (lmask)
267 1.1 ad full = (num - (32 - (dst & 31))) >> 5;
268 1.1 ad else
269 1.1 ad full = num >> 5;
270 1.1 ad
271 1.4 ad if (src < dst && src + num > dst) {
272 1.4 ad /* Copy right-to-left */
273 1.15 tsutsui bool sbover;
274 1.15 tsutsui int sboff;
275 1.15 tsutsui
276 1.15 tsutsui srp = (uint32_t *)(ri->ri_bits + row +
277 1.15 tsutsui (((src + num) >> 3) & ~3));
278 1.15 tsutsui drp = (uint32_t *)(ri->ri_bits + row +
279 1.15 tsutsui (((dst + num) >> 3) & ~3));
280 1.12 macallan if (ri->ri_hwbits)
281 1.15 tsutsui dhp = (uint32_t *)(ri->ri_hwbits + row +
282 1.15 tsutsui (((dst + num) >> 3) & ~3));
283 1.1 ad
284 1.15 tsutsui sb = src & 31;
285 1.15 tsutsui sbover = (sb + lnum) >= 32;
286 1.15 tsutsui sboff = (src + num) & 31;
287 1.15 tsutsui if ((sboff -= rnum) < 0) {
288 1.14 tsutsui srp--;
289 1.15 tsutsui sboff += 32;
290 1.4 ad }
291 1.6 pk
292 1.1 ad while (height--) {
293 1.1 ad sp = srp;
294 1.1 ad dp = drp;
295 1.15 tsutsui DELTA(srp, ri->ri_stride, uint32_t *);
296 1.15 tsutsui DELTA(drp, ri->ri_stride, uint32_t *);
297 1.6 pk
298 1.15 tsutsui if (rnum) {
299 1.15 tsutsui GETBITS(sp, sboff, rnum, tmp);
300 1.15 tsutsui PUTBITS(tmp, 0, rnum, dp);
301 1.1 ad }
302 1.1 ad
303 1.4 ad /* Now aligned to 32-bits wrt dp */
304 1.15 tsutsui for (cnt = full; cnt; cnt--) {
305 1.15 tsutsui --dp;
306 1.15 tsutsui --sp;
307 1.15 tsutsui GETBITS(sp, sboff, 32, tmp);
308 1.15 tsutsui *dp = tmp;
309 1.1 ad }
310 1.1 ad
311 1.1 ad if (lmask) {
312 1.15 tsutsui if (sbover)
313 1.15 tsutsui --sp;
314 1.15 tsutsui --dp;
315 1.4 ad GETBITS(sp, sb, lnum, tmp);
316 1.15 tsutsui PUTBITS(tmp, db, lnum, dp);
317 1.1 ad }
318 1.18 rin
319 1.18 rin if (ri->ri_hwbits) {
320 1.18 rin hp = dhp;
321 1.18 rin hp -= full + (lmask != 0);
322 1.18 rin memcpy(hp, dp, ((rmask != 0) + cnt +
323 1.18 rin (lmask != 0)) << 2);
324 1.18 rin DELTA(dhp, ri->ri_stride, uint32_t *);
325 1.18 rin }
326 1.1 ad }
327 1.1 ad } else {
328 1.4 ad /* Copy left-to-right */
329 1.15 tsutsui srp = (uint32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
330 1.15 tsutsui drp = (uint32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
331 1.12 macallan if (ri->ri_hwbits)
332 1.15 tsutsui dhp = (uint32_t *)(ri->ri_hwbits + row +
333 1.12 macallan ((dst >> 3) & ~3));
334 1.1 ad db = dst & 31;
335 1.1 ad
336 1.1 ad while (height--) {
337 1.1 ad sb = src & 31;
338 1.1 ad sp = srp;
339 1.1 ad dp = drp;
340 1.6 pk
341 1.1 ad if (lmask) {
342 1.1 ad GETBITS(sp, sb, lnum, tmp);
343 1.1 ad PUTBITS(tmp, db, lnum, dp);
344 1.1 ad dp++;
345 1.6 pk
346 1.18 rin if (sb += lnum > 31) {
347 1.1 ad sp++;
348 1.1 ad sb -= 32;
349 1.1 ad }
350 1.1 ad }
351 1.6 pk
352 1.4 ad /* Now aligned to 32-bits wrt dp */
353 1.4 ad for (cnt = full; cnt; cnt--, sp++) {
354 1.1 ad GETBITS(sp, sb, 32, tmp);
355 1.1 ad *dp++ = tmp;
356 1.1 ad }
357 1.1 ad
358 1.1 ad if (rmask) {
359 1.1 ad GETBITS(sp, sb, rnum, tmp);
360 1.1 ad PUTBITS(tmp, 0, rnum, dp);
361 1.1 ad }
362 1.18 rin
363 1.18 rin if (ri->ri_hwbits) {
364 1.18 rin memcpy(dhp, drp, ((lmask != 0) + full +
365 1.18 rin (rmask != 0)) << 2);
366 1.18 rin DELTA(dhp, ri->ri_stride, uint32_t *);
367 1.18 rin }
368 1.18 rin
369 1.18 rin DELTA(srp, ri->ri_stride, uint32_t *);
370 1.18 rin DELTA(drp, ri->ri_stride, uint32_t *);
371 1.1 ad }
372 1.1 ad }
373 1.1 ad }
374 1.5 ad
375 1.1 ad #endif /* _RASOPS_BITOPS_H_ */
376