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