Home | History | Annotate | Line # | Download | only in rasops
rasops1.c revision 1.19
      1 /* 	$NetBSD: rasops1.c,v 1.19 2009/03/14 15:36:20 dsl 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.19 2009/03/14 15:36:20 dsl 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(cookie, row, col, uc, attr)
     89 	void *cookie;
     90 	int row, col;
     91 	u_int uc;
     92 	long attr;
     93 {
     94 	u_int fs, rs, fb, bg, fg, lmask, rmask;
     95 	u_int32_t height, width;
     96 	struct rasops_info *ri;
     97 	int32_t *rp;
     98 	u_char *fr;
     99 
    100 	ri = (struct rasops_info *)cookie;
    101 
    102 #ifdef RASOPS_CLIPPING
    103 	/* Catches 'row < 0' case too */
    104 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    105 		return;
    106 
    107 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    108 		return;
    109 #endif
    110 
    111 	col *= ri->ri_font->fontwidth;
    112 	rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3));
    113 	height = ri->ri_font->fontheight;
    114 	width = ri->ri_font->fontwidth;
    115 	col = col & 31;
    116 	rs = ri->ri_stride;
    117 
    118 	bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
    119 	fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
    120 
    121 	/* If fg and bg match this becomes a space character */
    122 	if (fg == bg || uc == ' ') {
    123 		uc = (u_int)-1;
    124 		fr = 0;		/* shutup gcc */
    125 		fs = 0;		/* shutup gcc */
    126 	} else {
    127 		uc -= ri->ri_font->firstchar;
    128 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    129 		fs = ri->ri_font->stride;
    130 	}
    131 
    132 	/* Single word, one mask */
    133 	if ((col + width) <= 32) {
    134 		rmask = rasops_pmask[col][width];
    135 		lmask = ~rmask;
    136 
    137 		if (uc == (u_int)-1) {
    138 			bg &= rmask;
    139 
    140 			while (height--) {
    141 				*rp = (*rp & lmask) | bg;
    142 				DELTA(rp, rs, int32_t *);
    143 			}
    144 		} else {
    145 			/* NOT fontbits if bg is white */
    146 			if (bg) {
    147 				while (height--) {
    148 					fb = ~(fr[3] | (fr[2] << 8) |
    149 					    (fr[1] << 16) | (fr[0] << 24));
    150 					*rp = (*rp & lmask)
    151 					    | (MBE(fb >> col) & rmask);
    152 
    153 					fr += fs;
    154 					DELTA(rp, rs, int32_t *);
    155 				}
    156 			} else {
    157 				while (height--) {
    158 					fb = (fr[3] | (fr[2] << 8) |
    159 					    (fr[1] << 16) | (fr[0] << 24));
    160 					*rp = (*rp & lmask)
    161 					    | (MBE(fb >> col) & rmask);
    162 
    163 					fr += fs;
    164 					DELTA(rp, rs, int32_t *);
    165 				}
    166 			}
    167 		}
    168 
    169 		/* Do underline */
    170 		if ((attr & 1) != 0) {
    171 			DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    172 			*rp = (*rp & lmask) | (fg & rmask);
    173 		}
    174 	} else {
    175 		lmask = ~rasops_lmask[col];
    176 		rmask = ~rasops_rmask[(col + width) & 31];
    177 
    178 		if (uc == (u_int)-1) {
    179 			width = bg & ~rmask;
    180 			bg = bg & ~lmask;
    181 
    182 			while (height--) {
    183 				rp[0] = (rp[0] & lmask) | bg;
    184 				rp[1] = (rp[1] & rmask) | width;
    185 				DELTA(rp, rs, int32_t *);
    186 			}
    187 		} else {
    188 			width = 32 - col;
    189 
    190 			/* NOT fontbits if bg is white */
    191 			if (bg) {
    192 				while (height--) {
    193 					fb = ~(fr[3] | (fr[2] << 8) |
    194 					    (fr[1] << 16) | (fr[0] << 24));
    195 
    196 					rp[0] = (rp[0] & lmask)
    197 					    | MBE((u_int)fb >> col);
    198 
    199 					rp[1] = (rp[1] & rmask)
    200 					    | (MBE((u_int)fb << width) & ~rmask);
    201 
    202 					fr += fs;
    203 					DELTA(rp, rs, int32_t *);
    204 				}
    205 			} else {
    206 				while (height--) {
    207 					fb = (fr[3] | (fr[2] << 8) |
    208 					    (fr[1] << 16) | (fr[0] << 24));
    209 
    210 					rp[0] = (rp[0] & lmask)
    211 					    | MBE(fb >> col);
    212 
    213 					rp[1] = (rp[1] & rmask)
    214 					    | (MBE(fb << width) & ~rmask);
    215 
    216 					fr += fs;
    217 					DELTA(rp, rs, int32_t *);
    218 				}
    219 			}
    220 		}
    221 
    222 		/* Do underline */
    223 		if ((attr & 1) != 0) {
    224 			DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    225 			rp[0] = (rp[0] & lmask) | (fg & ~lmask);
    226 			rp[1] = (rp[1] & rmask) | (fg & ~rmask);
    227 		}
    228 	}
    229 }
    230 
    231 #ifndef RASOPS_SMALL
    232 /*
    233  * Paint a single character. This is for 8-pixel wide fonts.
    234  */
    235 static void
    236 rasops1_putchar8(cookie, row, col, uc, attr)
    237 	void *cookie;
    238 	int row, col;
    239 	u_int uc;
    240 	long attr;
    241 {
    242 	int height, fs, rs, bg, fg;
    243 	struct rasops_info *ri;
    244 	u_char *fr, *rp;
    245 
    246 	ri = (struct rasops_info *)cookie;
    247 
    248 #ifdef RASOPS_CLIPPING
    249 	/* Catches 'row < 0' case too */
    250 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    251 		return;
    252 
    253 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    254 		return;
    255 #endif
    256 
    257 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    258 	height = ri->ri_font->fontheight;
    259 	rs = ri->ri_stride;
    260 
    261 	bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
    262 	fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
    263 
    264 	/* If fg and bg match this becomes a space character */
    265 	if (fg == bg || uc == ' ') {
    266 		while (height--) {
    267 			*rp = bg;
    268 			rp += rs;
    269 		}
    270 	} else {
    271 		uc -= ri->ri_font->firstchar;
    272 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    273 		fs = ri->ri_font->stride;
    274 
    275 		/* NOT fontbits if bg is white */
    276 		if (bg) {
    277 			while (height--) {
    278 				*rp = ~*fr;
    279 				fr += fs;
    280 				rp += rs;
    281 			}
    282 		} else {
    283 			while (height--) {
    284 				*rp = *fr;
    285 				fr += fs;
    286 				rp += rs;
    287 			}
    288 		}
    289 
    290 	}
    291 
    292 	/* Do underline */
    293 	if ((attr & 1) != 0)
    294 		rp[-(ri->ri_stride << 1)] = fg;
    295 }
    296 
    297 /*
    298  * Paint a single character. This is for 16-pixel wide fonts.
    299  */
    300 static void
    301 rasops1_putchar16(cookie, row, col, uc, attr)
    302 	void *cookie;
    303 	int row, col;
    304 	u_int uc;
    305 	long attr;
    306 {
    307 	int height, fs, rs, bg, fg;
    308 	struct rasops_info *ri;
    309 	u_char *fr, *rp;
    310 
    311 	ri = (struct rasops_info *)cookie;
    312 
    313 #ifdef RASOPS_CLIPPING
    314 	/* Catches 'row < 0' case too */
    315 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    316 		return;
    317 
    318 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    319 		return;
    320 #endif
    321 
    322 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    323 	height = ri->ri_font->fontheight;
    324 	rs = ri->ri_stride;
    325 
    326 	bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
    327 	fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
    328 
    329 	/* If fg and bg match this becomes a space character */
    330 	if (fg == bg || uc == ' ') {
    331 		while (height--) {
    332 			*(int16_t *)rp = bg;
    333 			rp += rs;
    334 		}
    335 	} else {
    336 		uc -= ri->ri_font->firstchar;
    337 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    338 		fs = ri->ri_font->stride;
    339 
    340 		/* NOT fontbits if bg is white */
    341 		if (bg) {
    342 			while (height--) {
    343 				rp[0] = ~fr[0];
    344 				rp[1] = ~fr[1];
    345 				fr += fs;
    346 				rp += rs;
    347 			}
    348 		} else {
    349 			while (height--) {
    350 				rp[0] = fr[0];
    351 				rp[1] = fr[1];
    352 				fr += fs;
    353 				rp += rs;
    354 			}
    355 		}
    356 	}
    357 
    358 	/* Do underline */
    359 	if ((attr & 1) != 0)
    360 		*(int16_t *)(rp - (ri->ri_stride << 1)) = fg;
    361 }
    362 #endif	/* !RASOPS_SMALL */
    363 
    364 /*
    365  * Grab routines common to depths where (bpp < 8)
    366  */
    367 #define NAME(ident)	rasops1_##ident
    368 #define PIXEL_SHIFT	0
    369 
    370 #include <dev/rasops/rasops_bitops.h>
    371