rasops_bitops.h revision 1.19 1 1.19 rin /* $NetBSD: rasops_bitops.h,v 1.19 2019/08/01 03:43:54 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.19 rin struct rasops_info *ri = (struct rasops_info *)cookie;
42 1.19 rin uint32_t lclr, rclr, clr;
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
49 1.6 pk #ifdef RASOPS_CLIPPING
50 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
51 1.1 ad return;
52 1.1 ad
53 1.1 ad if (col < 0) {
54 1.1 ad num += col;
55 1.1 ad col = 0;
56 1.1 ad }
57 1.1 ad
58 1.19 rin if (col + num > ri->ri_cols)
59 1.1 ad num = ri->ri_cols - col;
60 1.6 pk
61 1.1 ad if (num <= 0)
62 1.1 ad return;
63 1.1 ad #endif
64 1.1 ad col *= ri->ri_font->fontwidth << PIXEL_SHIFT;
65 1.1 ad num *= ri->ri_font->fontwidth << PIXEL_SHIFT;
66 1.1 ad height = ri->ri_font->fontheight;
67 1.17 rin clr = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
68 1.15 tsutsui rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + ((col >> 3) & ~3));
69 1.12 macallan if (ri->ri_hwbits)
70 1.18 rin hp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
71 1.12 macallan ((col >> 3) & ~3));
72 1.19 rin col &= 31;
73 1.19 rin
74 1.19 rin if (col + num <= 32) {
75 1.19 rin lmask = ~rasops_pmask[col][num & 31];
76 1.1 ad lclr = clr & ~lmask;
77 1.1 ad
78 1.1 ad while (height--) {
79 1.1 ad dp = rp;
80 1.15 tsutsui DELTA(rp, ri->ri_stride, uint32_t *);
81 1.1 ad
82 1.12 macallan tmp = (*dp & lmask) | lclr;
83 1.12 macallan *dp = tmp;
84 1.12 macallan if (ri->ri_hwbits) {
85 1.18 rin *hp = tmp;
86 1.18 rin DELTA(hp, ri->ri_stride, uint32_t *);
87 1.12 macallan }
88 1.1 ad }
89 1.1 ad } else {
90 1.19 rin lmask = rasops_rmask[col];
91 1.1 ad rmask = rasops_lmask[(col + num) & 31];
92 1.6 pk
93 1.1 ad if (lmask)
94 1.19 rin num = (num - (32 - col)) >> 5;
95 1.1 ad else
96 1.1 ad num = num >> 5;
97 1.6 pk
98 1.1 ad lclr = clr & ~lmask;
99 1.1 ad rclr = clr & ~rmask;
100 1.1 ad
101 1.1 ad while (height--) {
102 1.1 ad dp = rp;
103 1.1 ad
104 1.8 thorpej if (lmask) {
105 1.18 rin *dp = (*dp & lmask) | lclr;
106 1.8 thorpej dp++;
107 1.8 thorpej }
108 1.1 ad
109 1.1 ad for (cnt = num; cnt > 0; cnt--)
110 1.1 ad *dp++ = clr;
111 1.18 rin
112 1.18 rin if (rmask)
113 1.18 rin *dp = (*dp & rmask) | rclr;
114 1.18 rin
115 1.12 macallan if (ri->ri_hwbits) {
116 1.18 rin memcpy(hp, rp, ((lmask != 0) + num +
117 1.18 rin (rmask != 0)) << 2);
118 1.18 rin DELTA(hp, ri->ri_stride, uint32_t *);
119 1.12 macallan }
120 1.18 rin DELTA(rp, ri->ri_stride, uint32_t *);
121 1.1 ad }
122 1.1 ad }
123 1.1 ad }
124 1.1 ad
125 1.1 ad /*
126 1.1 ad * Actually paint the cursor.
127 1.1 ad */
128 1.1 ad static void
129 1.11 cegger NAME(do_cursor)(struct rasops_info *ri)
130 1.1 ad {
131 1.19 rin int height, row, col, num, cnt;
132 1.19 rin uint32_t *dp, *rp, *hp, tmp, lmask, rmask;
133 1.18 rin
134 1.19 rin hp = NULL; /* XXX GCC */
135 1.6 pk
136 1.1 ad row = ri->ri_crow;
137 1.1 ad col = ri->ri_ccol * ri->ri_font->fontwidth << PIXEL_SHIFT;
138 1.1 ad height = ri->ri_font->fontheight;
139 1.1 ad num = ri->ri_font->fontwidth << PIXEL_SHIFT;
140 1.16 rin rp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale +
141 1.16 rin ((col >> 3) & ~3));
142 1.12 macallan if (ri->ri_hwbits)
143 1.19 rin hp = (uint32_t *)(ri->ri_hwbits + row * ri->ri_yscale +
144 1.12 macallan ((col >> 3) & ~3));
145 1.19 rin col &= 31;
146 1.6 pk
147 1.19 rin if (col + num <= 32) {
148 1.19 rin lmask = rasops_pmask[col][num & 31];
149 1.1 ad
150 1.1 ad while (height--) {
151 1.18 rin tmp = *rp ^ lmask;
152 1.18 rin *rp = tmp;
153 1.18 rin if (ri->ri_hwbits) {
154 1.19 rin *hp = tmp;
155 1.19 rin DELTA(hp, ri->ri_stride, uint32_t *);
156 1.12 macallan }
157 1.18 rin DELTA(rp, ri->ri_stride, uint32_t *);
158 1.12 macallan }
159 1.1 ad } else {
160 1.19 rin lmask = ~rasops_rmask[col];
161 1.1 ad rmask = ~rasops_lmask[(col + num) & 31];
162 1.1 ad
163 1.19 rin if (lmask != -1)
164 1.19 rin num = (num - (32 - col)) >> 5;
165 1.19 rin else
166 1.19 rin num = num >> 5;
167 1.19 rin
168 1.1 ad while (height--) {
169 1.1 ad dp = rp;
170 1.19 rin
171 1.19 rin if (lmask != -1) {
172 1.19 rin *dp = *dp ^ lmask;
173 1.19 rin dp++;
174 1.12 macallan }
175 1.18 rin
176 1.19 rin for (cnt = num; cnt; cnt--) {
177 1.19 rin *dp = ~*dp;
178 1.12 macallan dp++;
179 1.12 macallan }
180 1.1 ad
181 1.19 rin if (rmask != -1)
182 1.19 rin *dp = *dp ^ rmask;
183 1.19 rin
184 1.19 rin if (ri->ri_hwbits) {
185 1.19 rin memcpy(hp, rp, ((lmask != -1) + num +
186 1.19 rin (rmask != -1)) << 2);
187 1.19 rin DELTA(hp, ri->ri_stride, uint32_t *);
188 1.12 macallan }
189 1.19 rin DELTA(rp, ri->ri_stride, uint32_t *);
190 1.1 ad }
191 1.1 ad }
192 1.1 ad }
193 1.1 ad
194 1.1 ad /*
195 1.4 ad * Copy columns. Ick!
196 1.1 ad */
197 1.1 ad static void
198 1.11 cegger NAME(copycols)(void *cookie, int row, int src, int dst, int num)
199 1.1 ad {
200 1.18 rin struct rasops_info *ri = (struct rasops_info *)cookie;
201 1.15 tsutsui int height, lnum, rnum, sb, db, cnt, full;
202 1.15 tsutsui uint32_t tmp, lmask, rmask;
203 1.18 rin uint32_t *sp, *dp, *srp, *drp, *dhp, *hp;
204 1.6 pk
205 1.18 rin dhp = hp = NULL; /* XXX GCC */
206 1.1 ad
207 1.1 ad #ifdef RASOPS_CLIPPING
208 1.1 ad if (dst == src)
209 1.1 ad return;
210 1.6 pk
211 1.1 ad /* Catches < 0 case too */
212 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
213 1.1 ad return;
214 1.6 pk
215 1.1 ad if (src < 0) {
216 1.1 ad num += src;
217 1.1 ad src = 0;
218 1.1 ad }
219 1.1 ad
220 1.18 rin if (src + num > ri->ri_cols)
221 1.1 ad num = ri->ri_cols - src;
222 1.1 ad
223 1.1 ad if (dst < 0) {
224 1.1 ad num += dst;
225 1.1 ad dst = 0;
226 1.1 ad }
227 1.1 ad
228 1.18 rin if (dst + num > ri->ri_cols)
229 1.1 ad num = ri->ri_cols - dst;
230 1.6 pk
231 1.1 ad if (num <= 0)
232 1.1 ad return;
233 1.1 ad #endif
234 1.6 pk
235 1.1 ad cnt = ri->ri_font->fontwidth << PIXEL_SHIFT;
236 1.1 ad src *= cnt;
237 1.1 ad dst *= cnt;
238 1.1 ad num *= cnt;
239 1.1 ad row *= ri->ri_yscale;
240 1.1 ad height = ri->ri_font->fontheight;
241 1.4 ad db = dst & 31;
242 1.1 ad
243 1.6 pk if (db + num <= 32) {
244 1.4 ad /* Destination is contained within a single word */
245 1.15 tsutsui srp = (uint32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
246 1.15 tsutsui drp = (uint32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
247 1.12 macallan if (ri->ri_hwbits)
248 1.15 tsutsui dhp = (uint32_t *)(ri->ri_hwbits + row +
249 1.12 macallan ((dst >> 3) & ~3));
250 1.1 ad sb = src & 31;
251 1.1 ad
252 1.1 ad while (height--) {
253 1.1 ad GETBITS(srp, sb, num, tmp);
254 1.1 ad PUTBITS(tmp, db, num, drp);
255 1.12 macallan if (ri->ri_hwbits) {
256 1.12 macallan PUTBITS(tmp, db, num, dhp);
257 1.15 tsutsui DELTA(dhp, ri->ri_stride, uint32_t *);
258 1.12 macallan }
259 1.15 tsutsui DELTA(srp, ri->ri_stride, uint32_t *);
260 1.15 tsutsui DELTA(drp, ri->ri_stride, uint32_t *);
261 1.1 ad }
262 1.6 pk
263 1.1 ad return;
264 1.1 ad }
265 1.1 ad
266 1.4 ad lmask = rasops_rmask[db];
267 1.1 ad rmask = rasops_lmask[(dst + num) & 31];
268 1.4 ad lnum = (32 - db) & 31;
269 1.6 pk rnum = (dst + num) & 31;
270 1.6 pk
271 1.1 ad if (lmask)
272 1.1 ad full = (num - (32 - (dst & 31))) >> 5;
273 1.1 ad else
274 1.1 ad full = num >> 5;
275 1.1 ad
276 1.4 ad if (src < dst && src + num > dst) {
277 1.4 ad /* Copy right-to-left */
278 1.15 tsutsui bool sbover;
279 1.15 tsutsui int sboff;
280 1.15 tsutsui
281 1.15 tsutsui srp = (uint32_t *)(ri->ri_bits + row +
282 1.15 tsutsui (((src + num) >> 3) & ~3));
283 1.15 tsutsui drp = (uint32_t *)(ri->ri_bits + row +
284 1.15 tsutsui (((dst + num) >> 3) & ~3));
285 1.12 macallan if (ri->ri_hwbits)
286 1.15 tsutsui dhp = (uint32_t *)(ri->ri_hwbits + row +
287 1.15 tsutsui (((dst + num) >> 3) & ~3));
288 1.1 ad
289 1.15 tsutsui sb = src & 31;
290 1.15 tsutsui sbover = (sb + lnum) >= 32;
291 1.15 tsutsui sboff = (src + num) & 31;
292 1.15 tsutsui if ((sboff -= rnum) < 0) {
293 1.14 tsutsui srp--;
294 1.15 tsutsui sboff += 32;
295 1.4 ad }
296 1.6 pk
297 1.1 ad while (height--) {
298 1.1 ad sp = srp;
299 1.1 ad dp = drp;
300 1.15 tsutsui DELTA(srp, ri->ri_stride, uint32_t *);
301 1.15 tsutsui DELTA(drp, ri->ri_stride, uint32_t *);
302 1.6 pk
303 1.15 tsutsui if (rnum) {
304 1.15 tsutsui GETBITS(sp, sboff, rnum, tmp);
305 1.15 tsutsui PUTBITS(tmp, 0, rnum, dp);
306 1.1 ad }
307 1.1 ad
308 1.4 ad /* Now aligned to 32-bits wrt dp */
309 1.15 tsutsui for (cnt = full; cnt; cnt--) {
310 1.15 tsutsui --dp;
311 1.15 tsutsui --sp;
312 1.15 tsutsui GETBITS(sp, sboff, 32, tmp);
313 1.15 tsutsui *dp = tmp;
314 1.1 ad }
315 1.1 ad
316 1.1 ad if (lmask) {
317 1.15 tsutsui if (sbover)
318 1.15 tsutsui --sp;
319 1.15 tsutsui --dp;
320 1.4 ad GETBITS(sp, sb, lnum, tmp);
321 1.15 tsutsui PUTBITS(tmp, db, lnum, dp);
322 1.1 ad }
323 1.18 rin
324 1.18 rin if (ri->ri_hwbits) {
325 1.18 rin hp = dhp;
326 1.18 rin hp -= full + (lmask != 0);
327 1.18 rin memcpy(hp, dp, ((rmask != 0) + cnt +
328 1.18 rin (lmask != 0)) << 2);
329 1.18 rin DELTA(dhp, ri->ri_stride, uint32_t *);
330 1.18 rin }
331 1.1 ad }
332 1.1 ad } else {
333 1.4 ad /* Copy left-to-right */
334 1.15 tsutsui srp = (uint32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
335 1.15 tsutsui drp = (uint32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
336 1.12 macallan if (ri->ri_hwbits)
337 1.15 tsutsui dhp = (uint32_t *)(ri->ri_hwbits + row +
338 1.12 macallan ((dst >> 3) & ~3));
339 1.1 ad db = dst & 31;
340 1.1 ad
341 1.1 ad while (height--) {
342 1.1 ad sb = src & 31;
343 1.1 ad sp = srp;
344 1.1 ad dp = drp;
345 1.6 pk
346 1.1 ad if (lmask) {
347 1.1 ad GETBITS(sp, sb, lnum, tmp);
348 1.1 ad PUTBITS(tmp, db, lnum, dp);
349 1.1 ad dp++;
350 1.6 pk
351 1.18 rin if (sb += lnum > 31) {
352 1.1 ad sp++;
353 1.1 ad sb -= 32;
354 1.1 ad }
355 1.1 ad }
356 1.6 pk
357 1.4 ad /* Now aligned to 32-bits wrt dp */
358 1.4 ad for (cnt = full; cnt; cnt--, sp++) {
359 1.1 ad GETBITS(sp, sb, 32, tmp);
360 1.1 ad *dp++ = tmp;
361 1.1 ad }
362 1.1 ad
363 1.1 ad if (rmask) {
364 1.1 ad GETBITS(sp, sb, rnum, tmp);
365 1.1 ad PUTBITS(tmp, 0, rnum, dp);
366 1.1 ad }
367 1.18 rin
368 1.18 rin if (ri->ri_hwbits) {
369 1.18 rin memcpy(dhp, drp, ((lmask != 0) + full +
370 1.18 rin (rmask != 0)) << 2);
371 1.18 rin DELTA(dhp, ri->ri_stride, uint32_t *);
372 1.18 rin }
373 1.18 rin
374 1.18 rin DELTA(srp, ri->ri_stride, uint32_t *);
375 1.18 rin DELTA(drp, ri->ri_stride, uint32_t *);
376 1.1 ad }
377 1.1 ad }
378 1.1 ad }
379 1.5 ad
380 1.1 ad #endif /* _RASOPS_BITOPS_H_ */
381