Home | History | Annotate | Line # | Download | only in rasops
rasops4.c revision 1.8
      1 /* 	$NetBSD: rasops4.c,v 1.8 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: rasops4.c,v 1.8 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	rasops4_copycols(void *, int, int, int, int);
     48 static void	rasops4_erasecols(void *, int, int, int, long);
     49 static void	rasops4_do_cursor(struct rasops_info *);
     50 static void	rasops4_putchar(void *, int, int col, u_int, long);
     51 #ifndef RASOPS_SMALL
     52 static void	rasops4_putchar8(void *, int, int col, u_int, long);
     53 static void	rasops4_putchar12(void *, int, int col, u_int, long);
     54 static void	rasops4_putchar16(void *, int, int col, u_int, long);
     55 static void	rasops4_makestamp(struct rasops_info *, long);
     56 
     57 /*
     58  * 4x1 stamp for optimized character blitting
     59  */
     60 static u_int16_t	stamp[16];
     61 static long	stamp_attr;
     62 static int	stamp_mutex;	/* XXX see note in README */
     63 #endif
     64 
     65 /*
     66  * Initialize rasops_info struct for this colordepth.
     67  */
     68 void
     69 rasops4_init(struct rasops_info *ri)
     70 {
     71 
     72 	switch (ri->ri_font->fontwidth) {
     73 #ifndef RASOPS_SMALL
     74 	case 8:
     75 		ri->ri_ops.putchar = rasops4_putchar8;
     76 		break;
     77 	case 12:
     78 		ri->ri_ops.putchar = rasops4_putchar12;
     79 		break;
     80 	case 16:
     81 		ri->ri_ops.putchar = rasops4_putchar16;
     82 		break;
     83 #endif	/* !RASOPS_SMALL */
     84 	default:
     85 		panic("fontwidth not 8/12/16 or RASOPS_SMALL - fixme!");
     86 		ri->ri_ops.putchar = rasops4_putchar;
     87 		break;
     88 	}
     89 
     90 	if ((ri->ri_font->fontwidth & 1) != 0) {
     91 		ri->ri_ops.erasecols = rasops4_erasecols;
     92 		ri->ri_ops.copycols = rasops4_copycols;
     93 		ri->ri_do_cursor = rasops4_do_cursor;
     94 	}
     95 }
     96 
     97 #ifdef notyet
     98 /*
     99  * Paint a single character. This is the generic version, this is ugly.
    100  */
    101 static void
    102 rasops4_putchar(cookie, row, col, uc, attr)
    103 	void *cookie;
    104 	int row, col;
    105 	u_int uc;
    106 	long attr;
    107 {
    108 	int height, width, fs, rs, fb, bg, fg, lmask, rmask;
    109 	struct rasops_info *ri;
    110 	int32_t *rp;
    111 	u_char *fr;
    112 
    113 	ri = (struct rasops_info *)cookie;
    114 
    115 #ifdef RASOPS_CLIPPING
    116 	/* Catches 'row < 0' case too */
    117 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    118 		return;
    119 
    120 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    121 		return;
    122 #endif
    123 
    124 	width = ri->ri_font->fontwidth << 1;
    125 	height = ri->ri_font->fontheight;
    126 	col *= width;
    127 	rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3));
    128 	col = col & 31;
    129 	rs = ri->ri_stride;
    130 
    131 	bg = ri->ri_devcmap[(attr >> 16) & 0xf];
    132 	fg = ri->ri_devcmap[(attr >> 24) & 0xf];
    133 
    134 	/* If fg and bg match this becomes a space character */
    135 	if (fg == bg || uc == ' ') {
    136 		uc = (u_int)-1;
    137 		fr = 0;		/* shutup gcc */
    138 		fs = 0;		/* shutup gcc */
    139 	} else {
    140 		uc -= ri->ri_font->firstchar;
    141 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    142 		fs = ri->ri_font->stride;
    143 	}
    144 
    145 	/* Single word, one mask */
    146 	if ((col + width) <= 32) {
    147 		rmask = rasops_pmask[col][width];
    148 		lmask = ~rmask;
    149 
    150 		if (uc == (u_int)-1) {
    151 			bg &= rmask;
    152 
    153 			while (height--) {
    154 				*rp = (*rp & lmask) | bg;
    155 				DELTA(rp, rs, int32_t *);
    156 			}
    157 		} else {
    158 			while (height--) {
    159 				/* get bits, mask */
    160 				/* compose sl */
    161 				/* mask sl */
    162 				/* put word */
    163 			}
    164 		}
    165 
    166 		/* Do underline */
    167 		if (attr & 1) {
    168 			DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    169 			*rp = (*rp & lmask) | (fg & rmask);
    170 		}
    171 	} else {
    172 		lmask = ~rasops_lmask[col];
    173 		rmask = ~rasops_rmask[(col + width) & 31];
    174 
    175 		if (uc == (u_int)-1) {
    176 			bg = bg & ~lmask;
    177 			width = bg & ~rmask;
    178 
    179 			while (height--) {
    180 				rp[0] = (rp[0] & lmask) | bg;
    181 				rp[1] = (rp[1] & rmask) | width;
    182 				DELTA(rp, rs, int32_t *);
    183 			}
    184 		} else {
    185 			width = 32 - col;
    186 
    187 			/* NOT fontbits if bg is white */
    188 			while (height--) {
    189 				fb = ~(fr[3] | (fr[2] << 8) |
    190 				    (fr[1] << 16) | (fr[0] << 24));
    191 
    192 				rp[0] = (rp[0] & lmask)
    193 				    | MBE((u_int)fb >> col);
    194 
    195 				rp[1] = (rp[1] & rmask)
    196 				   | (MBE((u_int)fb << width) & ~rmask);
    197 
    198 				fr += fs;
    199 				DELTA(rp, rs, int32_t *);
    200 			}
    201 		}
    202 
    203 		/* Do underline */
    204 		if (attr & 1) {
    205 			DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    206 			rp[0] = (rp[0] & lmask) | (fg & ~lmask);
    207 			rp[1] = (rp[1] & rmask) | (fg & ~rmask);
    208 		}
    209 	}
    210 }
    211 #endif
    212 
    213 /*
    214  * Put a single character. This is the generic version.
    215  */
    216 static void
    217 rasops4_putchar(cookie, row, col, uc, attr)
    218 	void *cookie;
    219 	int row, col;
    220 	u_int uc;
    221 	long attr;
    222 {
    223 
    224 	/* XXX punt */
    225 }
    226 
    227 #ifndef RASOPS_SMALL
    228 /*
    229  * Recompute the blitting stamp.
    230  */
    231 static void
    232 rasops4_makestamp(struct rasops_info *ri, long attr)
    233 {
    234 	int i, fg, bg;
    235 
    236 	fg = ri->ri_devcmap[(attr >> 24) & 0xf] & 0xf;
    237 	bg = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xf;
    238 	stamp_attr = attr;
    239 
    240 	for (i = 0; i < 16; i++) {
    241 		stamp[i] =  (i & 1 ? fg : bg) << 8;
    242 		stamp[i] |= (i & 2 ? fg : bg) << 12;
    243 		stamp[i] |= (i & 4 ? fg : bg) << 0;
    244 		stamp[i] |= (i & 8 ? fg : bg) << 4;
    245 	}
    246 }
    247 
    248 /*
    249  * Put a single character. This is for 8-pixel wide fonts.
    250  */
    251 static void
    252 rasops4_putchar8(cookie, row, col, uc, attr)
    253 	void *cookie;
    254 	int row, col;
    255 	u_int uc;
    256 	long attr;
    257 {
    258 	struct rasops_info *ri;
    259 	int height, fs, rs;
    260 	u_char *fr;
    261 	u_int16_t *rp;
    262 
    263 	/* Can't risk remaking the stamp if it's already in use */
    264 	if (stamp_mutex++) {
    265 		stamp_mutex--;
    266 		rasops4_putchar(cookie, row, col, uc, attr);
    267 		return;
    268 	}
    269 
    270 	ri = (struct rasops_info *)cookie;
    271 
    272 #ifdef RASOPS_CLIPPING
    273 	/* Catches 'row < 0' case too */
    274 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    275 		stamp_mutex--;
    276 		return;
    277 	}
    278 
    279 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    280 		stamp_mutex--;
    281 		return;
    282 	}
    283 #endif
    284 
    285 	rp = (u_int16_t *)(ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale);
    286 	height = ri->ri_font->fontheight;
    287 	rs = ri->ri_stride / sizeof(*rp);
    288 
    289 	/* Recompute stamp? */
    290 	if (attr != stamp_attr)
    291 		rasops4_makestamp(ri, attr);
    292 
    293 	if (uc == ' ') {
    294 		u_int16_t c = stamp[0];
    295 		while (height--) {
    296 			rp[0] = c;
    297 			rp[1] = c;
    298 			rp += rs;
    299 		}
    300 	} else {
    301 		uc -= ri->ri_font->firstchar;
    302 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    303 		fs = ri->ri_font->stride;
    304 
    305 		while (height--) {
    306 			rp[0] = stamp[(*fr >> 4) & 0xf];
    307 			rp[1] = stamp[*fr & 0xf];
    308 			fr += fs;
    309 			rp += rs;
    310 		}
    311 	}
    312 
    313 	/* Do underline */
    314 	if ((attr & 1) != 0) {
    315 		rp -= (rs << 1);
    316 		rp[0] = stamp[15];
    317 		rp[1] = stamp[15];
    318 	}
    319 
    320 	stamp_mutex--;
    321 }
    322 
    323 /*
    324  * Put a single character. This is for 12-pixel wide fonts.
    325  */
    326 static void
    327 rasops4_putchar12(cookie, row, col, uc, attr)
    328 	void *cookie;
    329 	int row, col;
    330 	u_int uc;
    331 	long attr;
    332 {
    333 	struct rasops_info *ri;
    334 	int height, fs, rs;
    335 	u_char *fr;
    336 	u_int16_t *rp;
    337 
    338 	/* Can't risk remaking the stamp if it's already in use */
    339 	if (stamp_mutex++) {
    340 		stamp_mutex--;
    341 		rasops4_putchar(cookie, row, col, uc, attr);
    342 		return;
    343 	}
    344 
    345 	ri = (struct rasops_info *)cookie;
    346 
    347 #ifdef RASOPS_CLIPPING
    348 	/* Catches 'row < 0' case too */
    349 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    350 		stamp_mutex--;
    351 		return;
    352 	}
    353 
    354 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    355 		stamp_mutex--;
    356 		return;
    357 	}
    358 #endif
    359 
    360 	rp = (u_int16_t *)(ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale);
    361 	height = ri->ri_font->fontheight;
    362 	rs = ri->ri_stride / sizeof(*rp);
    363 
    364 	/* Recompute stamp? */
    365 	if (attr != stamp_attr)
    366 		rasops4_makestamp(ri, attr);
    367 
    368 	if (uc == ' ') {
    369 		u_int16_t c = stamp[0];
    370 		while (height--) {
    371 			rp[0] = c;
    372 			rp[1] = c;
    373 			rp[2] = c;
    374 			rp += rs;
    375 		}
    376 	} else {
    377 		uc -= ri->ri_font->firstchar;
    378 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    379 		fs = ri->ri_font->stride;
    380 
    381 		while (height--) {
    382 			rp[0] = stamp[(fr[0] >> 4) & 0xf];
    383 			rp[1] = stamp[fr[0] & 0xf];
    384 			rp[2] = stamp[(fr[1] >> 4) & 0xf];
    385 			fr += fs;
    386 			rp += rs;
    387 		}
    388 	}
    389 
    390 	/* Do underline */
    391 	if ((attr & 1) != 0) {
    392 		rp -= (rs << 1);
    393 		rp[0] = stamp[15];
    394 		rp[1] = stamp[15];
    395 		rp[2] = stamp[15];
    396 	}
    397 
    398 	stamp_mutex--;
    399 }
    400 
    401 /*
    402  * Put a single character. This is for 16-pixel wide fonts.
    403  */
    404 static void
    405 rasops4_putchar16(cookie, row, col, uc, attr)
    406 	void *cookie;
    407 	int row, col;
    408 	u_int uc;
    409 	long attr;
    410 {
    411 	struct rasops_info *ri;
    412 	int height, fs, rs;
    413 	u_char *fr;
    414 	u_int16_t *rp;
    415 
    416 	/* Can't risk remaking the stamp if it's already in use */
    417 	if (stamp_mutex++) {
    418 		stamp_mutex--;
    419 		rasops4_putchar(cookie, row, col, uc, attr);
    420 		return;
    421 	}
    422 
    423 	ri = (struct rasops_info *)cookie;
    424 
    425 #ifdef RASOPS_CLIPPING
    426 	/* Catches 'row < 0' case too */
    427 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    428 		stamp_mutex--;
    429 		return;
    430 	}
    431 
    432 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    433 		stamp_mutex--;
    434 		return;
    435 	}
    436 #endif
    437 
    438 	rp = (u_int16_t *)(ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale);
    439 	height = ri->ri_font->fontheight;
    440 	rs = ri->ri_stride / sizeof(*rp);
    441 
    442 	/* Recompute stamp? */
    443 	if (attr != stamp_attr)
    444 		rasops4_makestamp(ri, attr);
    445 
    446 	if (uc == ' ') {
    447 		u_int16_t c = stamp[0];
    448 		while (height--) {
    449 			rp[0] = c;
    450 			rp[1] = c;
    451 			rp[2] = c;
    452 			rp[3] = c;
    453 			rp += rs;
    454 		}
    455 	} else {
    456 		uc -= ri->ri_font->firstchar;
    457 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    458 		fs = ri->ri_font->stride;
    459 
    460 		while (height--) {
    461 			rp[0] = stamp[(fr[0] >> 4) & 0xf];
    462 			rp[1] = stamp[fr[0] & 0xf];
    463 			rp[2] = stamp[(fr[1] >> 4) & 0xf];
    464 			rp[3] = stamp[fr[1] & 0xf];
    465 			fr += fs;
    466 			rp += rs;
    467 		}
    468 	}
    469 
    470 	/* Do underline */
    471 	if ((attr & 1) != 0) {
    472 		rp -= (rs << 1);
    473 		rp[0] = stamp[15];
    474 		rp[1] = stamp[15];
    475 		rp[2] = stamp[15];
    476 		rp[3] = stamp[15];
    477 	}
    478 
    479 	stamp_mutex--;
    480 }
    481 #endif	/* !RASOPS_SMALL */
    482 
    483 /*
    484  * Grab routines common to depths where (bpp < 8)
    485  */
    486 #define NAME(ident)	rasops4_##ident
    487 #define PIXEL_SHIFT	3
    488 
    489 #include <dev/rasops/rasops_bitops.h>
    490