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