rasops1.c revision 1.22 1 /* $NetBSD: rasops1.c,v 1.22 2010/04/13 20:10:38 macallan Exp $ */
2
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: rasops1.c,v 1.22 2010/04/13 20:10:38 macallan Exp $");
34
35 #include "opt_rasops.h"
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/time.h>
40 #include <machine/endian.h>
41
42 #include <dev/wscons/wsdisplayvar.h>
43 #include <dev/wscons/wsconsio.h>
44 #include <dev/rasops/rasops.h>
45 #include <dev/rasops/rasops_masks.h>
46
47 static void rasops1_copycols(void *, int, int, int, int);
48 static void rasops1_erasecols(void *, int, int, int, long);
49 static void rasops1_do_cursor(struct rasops_info *);
50 static void rasops1_putchar(void *, int, int col, u_int, long);
51 #ifndef RASOPS_SMALL
52 static void rasops1_putchar8(void *, int, int col, u_int, long);
53 static void rasops1_putchar16(void *, int, int col, u_int, long);
54 #endif
55
56 /*
57 * Initialize rasops_info struct for this colordepth.
58 */
59 void
60 rasops1_init(struct rasops_info *ri)
61 {
62
63 switch (ri->ri_font->fontwidth) {
64 #ifndef RASOPS_SMALL
65 case 8:
66 ri->ri_ops.putchar = rasops1_putchar8;
67 break;
68 case 16:
69 ri->ri_ops.putchar = rasops1_putchar16;
70 break;
71 #endif
72 default:
73 ri->ri_ops.putchar = rasops1_putchar;
74 break;
75 }
76
77 if ((ri->ri_font->fontwidth & 7) != 0) {
78 ri->ri_ops.erasecols = rasops1_erasecols;
79 ri->ri_ops.copycols = rasops1_copycols;
80 ri->ri_do_cursor = rasops1_do_cursor;
81 }
82 }
83
84 /*
85 * Paint a single character. This is the generic version, this is ugly.
86 */
87 static void
88 rasops1_putchar(void *cookie, int row, int col, u_int uc, long attr)
89 {
90 u_int fs, rs, fb, bg, fg, lmask, rmask;
91 u_int32_t height, width;
92 struct rasops_info *ri;
93 int32_t *rp, *hrp = NULL, tmp, tmp2;
94 u_char *fr;
95
96 ri = (struct rasops_info *)cookie;
97
98 #ifdef RASOPS_CLIPPING
99 /* Catches 'row < 0' case too */
100 if ((unsigned)row >= (unsigned)ri->ri_rows)
101 return;
102
103 if ((unsigned)col >= (unsigned)ri->ri_cols)
104 return;
105 #endif
106
107 col *= ri->ri_font->fontwidth;
108 rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3));
109 if (ri->ri_hwbits)
110 hrp = (int32_t *)(ri->ri_hwbits + row * ri->ri_yscale +
111 ((col >> 3) & ~3));
112 height = ri->ri_font->fontheight;
113 width = ri->ri_font->fontwidth;
114 col = col & 31;
115 rs = ri->ri_stride;
116
117 bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
118 fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
119
120 /* If fg and bg match this becomes a space character */
121 if (fg == bg || uc == ' ') {
122 uc = (u_int)-1;
123 fr = 0; /* shutup gcc */
124 fs = 0; /* shutup gcc */
125 } else {
126 uc -= ri->ri_font->firstchar;
127 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
128 fs = ri->ri_font->stride;
129 }
130
131 /* Single word, one mask */
132 if ((col + width) <= 32) {
133 rmask = rasops_pmask[col][width];
134 lmask = ~rmask;
135
136 if (uc == (u_int)-1) {
137 bg &= rmask;
138
139 while (height--) {
140 tmp = (*rp & lmask) | bg;
141 *rp = tmp;
142 DELTA(rp, rs, int32_t *);
143 if (ri->ri_hwbits) {
144 *hrp = tmp;
145 DELTA(hrp, rs, int32_t *);
146 }
147 }
148 } else {
149 /* NOT fontbits if bg is white */
150 if (bg) {
151 while (height--) {
152 fb = ~(fr[3] | (fr[2] << 8) |
153 (fr[1] << 16) | (fr[0] << 24));
154 tmp = (*rp & lmask)
155 | (MBE(fb >> col) & rmask);
156 *rp = tmp;
157
158 fr += fs;
159 DELTA(rp, rs, int32_t *);
160 if (ri->ri_hwbits) {
161 *hrp = tmp;
162 DELTA(hrp, rs, int32_t *);
163 }
164 }
165 } else {
166 while (height--) {
167 fb = (fr[3] | (fr[2] << 8) |
168 (fr[1] << 16) | (fr[0] << 24));
169 tmp = (*rp & lmask)
170 | (MBE(fb >> col) & rmask);
171 *rp = tmp;
172
173 fr += fs;
174 DELTA(rp, rs, int32_t *);
175 if (ri->ri_hwbits) {
176 *hrp = tmp;
177 DELTA(hrp, rs, int32_t *);
178 }
179 }
180 }
181 }
182
183 /* Do underline */
184 if ((attr & 1) != 0) {
185 DELTA(rp, -(ri->ri_stride << 1), int32_t *);
186 tmp = (*rp & lmask) | (fg & rmask);
187 *rp = tmp;
188 if (ri->ri_hwbits) {
189 DELTA(hrp, -(ri->ri_stride << 1), int32_t *);
190 *hrp = tmp;
191 }
192 }
193 } else {
194 lmask = ~rasops_lmask[col];
195 rmask = ~rasops_rmask[(col + width) & 31];
196
197 if (uc == (u_int)-1) {
198 width = bg & ~rmask;
199 bg = bg & ~lmask;
200
201 while (height--) {
202 tmp = (rp[0] & lmask) | bg;
203 tmp2 = (rp[1] & rmask) | width;
204 rp[0] = tmp;
205 rp[1] = tmp2;
206 DELTA(rp, rs, int32_t *);
207 if (ri->ri_hwbits) {
208 hrp[0] = tmp;
209 hrp[1] = tmp2;
210 DELTA(hrp, rs, int32_t *);
211 }
212 }
213 } else {
214 width = 32 - col;
215
216 /* NOT fontbits if bg is white */
217 if (bg) {
218 while (height--) {
219 fb = ~(fr[3] | (fr[2] << 8) |
220 (fr[1] << 16) | (fr[0] << 24));
221
222 tmp = (rp[0] & lmask)
223 | MBE((u_int)fb >> col);
224
225 tmp2 = (rp[1] & rmask)
226 | (MBE((u_int)fb << width) & ~rmask);
227 rp[0] = tmp;
228 rp[1] = tmp2;
229 fr += fs;
230 DELTA(rp, rs, int32_t *);
231 if (ri->ri_hwbits) {
232 hrp[0] = tmp;
233 hrp[1] = tmp2;
234 DELTA(hrp, rs, int32_t *);
235 }
236 }
237 } else {
238 while (height--) {
239 fb = (fr[3] | (fr[2] << 8) |
240 (fr[1] << 16) | (fr[0] << 24));
241
242 tmp = (rp[0] & lmask)
243 | MBE(fb >> col);
244
245 tmp2 = (rp[1] & rmask)
246 | (MBE(fb << width) & ~rmask);
247 rp[0] = tmp;
248 rp[1] = tmp2;
249 fr += fs;
250 DELTA(rp, rs, int32_t *);
251 if (ri->ri_hwbits) {
252 hrp[0] = tmp;
253 hrp[1] = tmp2;
254 DELTA(hrp, rs, int32_t *);
255 }
256 }
257 }
258 }
259
260 /* Do underline */
261 if ((attr & 1) != 0) {
262 DELTA(rp, -(ri->ri_stride << 1), int32_t *);
263 tmp = (rp[0] & lmask) | (fg & ~lmask);
264 tmp2 = (rp[1] & rmask) | (fg & ~rmask);
265 rp[0] = tmp;
266 rp[1] = tmp2;
267 if (ri->ri_hwbits) {
268 DELTA(hrp, -(ri->ri_stride << 1), int32_t *);
269 hrp[0] = tmp;
270 hrp[1] = tmp2;
271 }
272 }
273 }
274 }
275
276 #ifndef RASOPS_SMALL
277 /*
278 * Paint a single character. This is for 8-pixel wide fonts.
279 */
280 static void
281 rasops1_putchar8(void *cookie, int row, int col, u_int uc, long attr)
282 {
283 int height, fs, rs, bg, fg;
284 struct rasops_info *ri;
285 u_char *fr, *rp, *hrp = NULL;
286
287 ri = (struct rasops_info *)cookie;
288
289 #ifdef RASOPS_CLIPPING
290 /* Catches 'row < 0' case too */
291 if ((unsigned)row >= (unsigned)ri->ri_rows)
292 return;
293
294 if ((unsigned)col >= (unsigned)ri->ri_cols)
295 return;
296 #endif
297
298 rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
299 if (ri->ri_hwbits)
300 hrp = ri->ri_hwbits + row * ri->ri_yscale + col * ri->ri_xscale;
301 height = ri->ri_font->fontheight;
302 rs = ri->ri_stride;
303
304 bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
305 fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
306
307 /* If fg and bg match this becomes a space character */
308 if (fg == bg || uc == ' ') {
309 while (height--) {
310 *rp = bg;
311 rp += rs;
312 if (ri->ri_hwbits) {
313 *hrp = bg;
314 hrp += rs;
315 }
316 }
317 } else {
318 uc -= ri->ri_font->firstchar;
319 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
320 fs = ri->ri_font->stride;
321
322 /* NOT fontbits if bg is white */
323 if (bg) {
324 while (height--) {
325 *rp = ~*fr;
326 rp += rs;
327 if (ri->ri_hwbits) {
328 *hrp = ~*fr;
329 hrp += rs;
330 }
331 fr += fs;
332
333 }
334 } else {
335 while (height--) {
336 *rp = *fr;
337 rp += rs;
338 if (ri->ri_hwbits) {
339 *hrp = *fr;
340 hrp += rs;
341 }
342 fr += fs;
343 }
344 }
345
346 }
347
348 /* Do underline */
349 if ((attr & 1) != 0) {
350 rp[-(ri->ri_stride << 1)] = fg;
351 if (ri->ri_hwbits) {
352 hrp[-(ri->ri_stride << 1)] = fg;
353 }
354 }
355 }
356
357 /*
358 * Paint a single character. This is for 16-pixel wide fonts.
359 */
360 static void
361 rasops1_putchar16(void *cookie, int row, int col, u_int uc, long attr)
362 {
363 int height, fs, rs, bg, fg;
364 struct rasops_info *ri;
365 u_char *fr, *rp, *hrp = NULL;
366
367 ri = (struct rasops_info *)cookie;
368
369 #ifdef RASOPS_CLIPPING
370 /* Catches 'row < 0' case too */
371 if ((unsigned)row >= (unsigned)ri->ri_rows)
372 return;
373
374 if ((unsigned)col >= (unsigned)ri->ri_cols)
375 return;
376 #endif
377
378 rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
379 if (ri->ri_hwbits)
380 hrp = ri->ri_hwbits + row * ri->ri_yscale + col * ri->ri_xscale;
381 height = ri->ri_font->fontheight;
382 rs = ri->ri_stride;
383
384 bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
385 fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
386
387 /* If fg and bg match this becomes a space character */
388 if (fg == bg || uc == ' ') {
389 while (height--) {
390 /* XXX alignment?! */
391 *(int16_t *)rp = bg;
392 rp += rs;
393 if (ri->ri_hwbits) {
394 *(int16_t *)hrp = bg;
395 hrp += rs;
396 }
397 }
398 } else {
399 uc -= ri->ri_font->firstchar;
400 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
401 fs = ri->ri_font->stride;
402
403 /* NOT fontbits if bg is white */
404 if (bg) {
405 while (height--) {
406 rp[0] = ~fr[0];
407 rp[1] = ~fr[1];
408 rp += rs;
409 if (ri->ri_hwbits) {
410 hrp[0] = ~fr[0];
411 hrp[1] = ~fr[1];
412 hrp += rs;
413 }
414 fr += fs;
415 }
416 } else {
417 while (height--) {
418 rp[0] = fr[0];
419 rp[1] = fr[1];
420 rp += rs;
421 if (ri->ri_hwbits) {
422 hrp[0] = fr[0];
423 hrp[1] = fr[1];
424 hrp += rs;
425 }
426 fr += fs;
427 }
428 }
429 }
430
431 /* Do underline */
432 if ((attr & 1) != 0)
433 /* XXX alignment?! */
434 *(int16_t *)(rp - (ri->ri_stride << 1)) = fg;
435 if (ri->ri_hwbits)
436 *(int16_t *)(hrp - (ri->ri_stride << 1)) = fg;
437 }
438 #endif /* !RASOPS_SMALL */
439
440 /*
441 * Grab routines common to depths where (bpp < 8)
442 */
443 #define NAME(ident) rasops1_##ident
444 #define PIXEL_SHIFT 0
445
446 #include <dev/rasops/rasops_bitops.h>
447