Home | History | Annotate | Line # | Download | only in rasops
rasops1.c revision 1.17.74.1
      1  1.17.74.1   yamt /* 	$NetBSD: rasops1.c,v 1.17.74.1 2008/05/16 02:25:01 yamt Exp $	*/
      2        1.1     ad 
      3        1.5     ad /*-
      4        1.5     ad  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5        1.1     ad  * All rights reserved.
      6        1.1     ad  *
      7        1.5     ad  * This code is derived from software contributed to The NetBSD Foundation
      8       1.12     ad  * by Andrew Doran.
      9        1.5     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.5     ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.5     ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.5     ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.5     ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.5     ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.5     ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.5     ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.5     ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.5     ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.5     ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.5     ad  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1     ad  */
     31        1.2     ad 
     32       1.14  lukem #include <sys/cdefs.h>
     33  1.17.74.1   yamt __KERNEL_RCSID(0, "$NetBSD: rasops1.c,v 1.17.74.1 2008/05/16 02:25:01 yamt Exp $");
     34       1.14  lukem 
     35        1.1     ad #include "opt_rasops.h"
     36        1.1     ad 
     37        1.1     ad #include <sys/param.h>
     38        1.1     ad #include <sys/systm.h>
     39        1.1     ad #include <sys/time.h>
     40        1.1     ad #include <machine/endian.h>
     41        1.1     ad 
     42        1.1     ad #include <dev/wscons/wsdisplayvar.h>
     43        1.3     ad #include <dev/wscons/wsconsio.h>
     44        1.1     ad #include <dev/rasops/rasops.h>
     45        1.4     ad #include <dev/rasops/rasops_masks.h>
     46        1.1     ad 
     47       1.16  perry static void	rasops1_copycols(void *, int, int, int, int);
     48       1.16  perry static void	rasops1_erasecols(void *, int, int, int, long);
     49       1.16  perry static void	rasops1_do_cursor(struct rasops_info *);
     50       1.16  perry static void	rasops1_putchar(void *, int, int col, u_int, long);
     51       1.10     ad #ifndef RASOPS_SMALL
     52       1.16  perry static void	rasops1_putchar8(void *, int, int col, u_int, long);
     53       1.16  perry static void	rasops1_putchar16(void *, int, int col, u_int, long);
     54       1.10     ad #endif
     55        1.1     ad 
     56        1.1     ad /*
     57       1.13    wiz  * Initialize rasops_info struct for this colordepth.
     58        1.1     ad  */
     59        1.1     ad void
     60        1.1     ad rasops1_init(ri)
     61        1.1     ad 	struct rasops_info *ri;
     62        1.1     ad {
     63        1.1     ad 
     64        1.1     ad 	switch (ri->ri_font->fontwidth) {
     65       1.10     ad #ifndef RASOPS_SMALL
     66        1.1     ad 	case 8:
     67        1.1     ad 		ri->ri_ops.putchar = rasops1_putchar8;
     68        1.1     ad 		break;
     69        1.1     ad 	case 16:
     70        1.1     ad 		ri->ri_ops.putchar = rasops1_putchar16;
     71        1.1     ad 		break;
     72       1.10     ad #endif
     73        1.1     ad 	default:
     74        1.1     ad 		ri->ri_ops.putchar = rasops1_putchar;
     75        1.1     ad 		break;
     76        1.1     ad 	}
     77       1.11     pk 
     78        1.6     ad 	if ((ri->ri_font->fontwidth & 7) != 0) {
     79        1.1     ad 		ri->ri_ops.erasecols = rasops1_erasecols;
     80        1.1     ad 		ri->ri_ops.copycols = rasops1_copycols;
     81        1.1     ad 		ri->ri_do_cursor = rasops1_do_cursor;
     82        1.1     ad 	}
     83        1.1     ad }
     84        1.1     ad 
     85        1.1     ad /*
     86        1.4     ad  * Paint a single character. This is the generic version, this is ugly.
     87        1.1     ad  */
     88        1.1     ad static void
     89        1.1     ad rasops1_putchar(cookie, row, col, uc, attr)
     90        1.1     ad 	void *cookie;
     91        1.1     ad 	int row, col;
     92        1.1     ad 	u_int uc;
     93        1.1     ad 	long attr;
     94        1.1     ad {
     95       1.10     ad 	u_int fs, rs, fb, bg, fg, lmask, rmask;
     96       1.10     ad 	u_int32_t height, width;
     97        1.4     ad 	struct rasops_info *ri;
     98        1.4     ad 	int32_t *rp;
     99        1.4     ad 	u_char *fr;
    100       1.11     pk 
    101        1.4     ad 	ri = (struct rasops_info *)cookie;
    102        1.4     ad 
    103       1.11     pk #ifdef RASOPS_CLIPPING
    104       1.11     pk 	/* Catches 'row < 0' case too */
    105        1.4     ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    106        1.4     ad 		return;
    107        1.4     ad 
    108        1.4     ad 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    109        1.4     ad 		return;
    110        1.4     ad #endif
    111        1.4     ad 
    112        1.4     ad 	col *= ri->ri_font->fontwidth;
    113        1.4     ad 	rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3));
    114        1.4     ad 	height = ri->ri_font->fontheight;
    115        1.4     ad 	width = ri->ri_font->fontwidth;
    116        1.4     ad 	col = col & 31;
    117        1.4     ad 	rs = ri->ri_stride;
    118       1.11     pk 
    119        1.9     ad 	bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
    120        1.9     ad 	fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
    121        1.4     ad 
    122        1.4     ad 	/* If fg and bg match this becomes a space character */
    123        1.4     ad 	if (fg == bg || uc == ' ') {
    124        1.4     ad 		uc = (u_int)-1;
    125        1.4     ad 		fr = 0;		/* shutup gcc */
    126        1.4     ad 		fs = 0;		/* shutup gcc */
    127        1.4     ad 	} else {
    128        1.4     ad 		uc -= ri->ri_font->firstchar;
    129        1.4     ad 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    130        1.4     ad 		fs = ri->ri_font->stride;
    131        1.4     ad 	}
    132       1.11     pk 
    133        1.4     ad 	/* Single word, one mask */
    134        1.4     ad 	if ((col + width) <= 32) {
    135        1.4     ad 		rmask = rasops_pmask[col][width];
    136        1.4     ad 		lmask = ~rmask;
    137       1.11     pk 
    138        1.4     ad 		if (uc == (u_int)-1) {
    139        1.4     ad 			bg &= rmask;
    140       1.11     pk 
    141        1.4     ad 			while (height--) {
    142        1.4     ad 				*rp = (*rp & lmask) | bg;
    143        1.4     ad 				DELTA(rp, rs, int32_t *);
    144        1.4     ad 			}
    145        1.4     ad 		} else {
    146        1.4     ad 			/* NOT fontbits if bg is white */
    147        1.4     ad 			if (bg) {
    148        1.4     ad 				while (height--) {
    149       1.11     pk 					fb = ~(fr[3] | (fr[2] << 8) |
    150        1.4     ad 					    (fr[1] << 16) | (fr[0] << 24));
    151        1.4     ad 					*rp = (*rp & lmask)
    152        1.4     ad 					    | (MBE(fb >> col) & rmask);
    153        1.4     ad 
    154        1.4     ad 					fr += fs;
    155        1.4     ad 					DELTA(rp, rs, int32_t *);
    156        1.4     ad 				}
    157        1.4     ad 			} else {
    158        1.4     ad 				while (height--) {
    159       1.11     pk 					fb = (fr[3] | (fr[2] << 8) |
    160        1.4     ad 					    (fr[1] << 16) | (fr[0] << 24));
    161        1.4     ad 					*rp = (*rp & lmask)
    162        1.4     ad 					    | (MBE(fb >> col) & rmask);
    163       1.11     pk 
    164        1.4     ad 					fr += fs;
    165        1.4     ad 					DELTA(rp, rs, int32_t *);
    166        1.4     ad 				}
    167        1.4     ad 			}
    168        1.4     ad 		}
    169       1.11     pk 
    170        1.4     ad 		/* Do underline */
    171       1.10     ad 		if ((attr & 1) != 0) {
    172        1.4     ad 			DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    173        1.4     ad 			*rp = (*rp & lmask) | (fg & rmask);
    174        1.4     ad 		}
    175        1.4     ad 	} else {
    176        1.4     ad 		lmask = ~rasops_lmask[col];
    177        1.4     ad 		rmask = ~rasops_rmask[(col + width) & 31];
    178       1.11     pk 
    179        1.4     ad 		if (uc == (u_int)-1) {
    180        1.8  mouse 			width = bg & ~rmask;
    181        1.4     ad 			bg = bg & ~lmask;
    182       1.11     pk 
    183        1.4     ad 			while (height--) {
    184        1.4     ad 				rp[0] = (rp[0] & lmask) | bg;
    185        1.4     ad 				rp[1] = (rp[1] & rmask) | width;
    186        1.4     ad 				DELTA(rp, rs, int32_t *);
    187        1.4     ad 			}
    188        1.4     ad 		} else {
    189        1.4     ad 			width = 32 - col;
    190       1.11     pk 
    191        1.4     ad 			/* NOT fontbits if bg is white */
    192        1.4     ad 			if (bg) {
    193        1.4     ad 				while (height--) {
    194       1.11     pk 					fb = ~(fr[3] | (fr[2] << 8) |
    195        1.4     ad 					    (fr[1] << 16) | (fr[0] << 24));
    196       1.11     pk 
    197        1.4     ad 					rp[0] = (rp[0] & lmask)
    198        1.4     ad 					    | MBE((u_int)fb >> col);
    199        1.4     ad 
    200        1.4     ad 					rp[1] = (rp[1] & rmask)
    201        1.4     ad 					    | (MBE((u_int)fb << width) & ~rmask);
    202        1.4     ad 
    203        1.4     ad 					fr += fs;
    204        1.4     ad 					DELTA(rp, rs, int32_t *);
    205        1.4     ad 				}
    206        1.4     ad 			} else {
    207        1.4     ad 				while (height--) {
    208       1.11     pk 					fb = (fr[3] | (fr[2] << 8) |
    209        1.4     ad 					    (fr[1] << 16) | (fr[0] << 24));
    210        1.4     ad 
    211        1.4     ad 					rp[0] = (rp[0] & lmask)
    212        1.4     ad 					    | MBE(fb >> col);
    213        1.4     ad 
    214        1.4     ad 					rp[1] = (rp[1] & rmask)
    215        1.4     ad 					    | (MBE(fb << width) & ~rmask);
    216       1.11     pk 
    217        1.4     ad 					fr += fs;
    218        1.4     ad 					DELTA(rp, rs, int32_t *);
    219        1.4     ad 				}
    220        1.4     ad 			}
    221        1.4     ad 		}
    222        1.1     ad 
    223        1.4     ad 		/* Do underline */
    224       1.10     ad 		if ((attr & 1) != 0) {
    225        1.4     ad 			DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    226        1.4     ad 			rp[0] = (rp[0] & lmask) | (fg & ~lmask);
    227        1.4     ad 			rp[1] = (rp[1] & rmask) | (fg & ~rmask);
    228        1.4     ad 		}
    229        1.4     ad 	}
    230        1.1     ad }
    231        1.1     ad 
    232       1.10     ad #ifndef RASOPS_SMALL
    233        1.1     ad /*
    234        1.1     ad  * Paint a single character. This is for 8-pixel wide fonts.
    235        1.1     ad  */
    236        1.1     ad static void
    237        1.1     ad rasops1_putchar8(cookie, row, col, uc, attr)
    238        1.1     ad 	void *cookie;
    239        1.1     ad 	int row, col;
    240        1.1     ad 	u_int uc;
    241        1.1     ad 	long attr;
    242        1.1     ad {
    243        1.1     ad 	int height, fs, rs, bg, fg;
    244        1.1     ad 	struct rasops_info *ri;
    245        1.1     ad 	u_char *fr, *rp;
    246       1.11     pk 
    247        1.1     ad 	ri = (struct rasops_info *)cookie;
    248        1.1     ad 
    249       1.11     pk #ifdef RASOPS_CLIPPING
    250       1.11     pk 	/* Catches 'row < 0' case too */
    251        1.3     ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    252        1.1     ad 		return;
    253        1.1     ad 
    254        1.3     ad 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    255        1.1     ad 		return;
    256        1.1     ad #endif
    257        1.1     ad 
    258        1.3     ad 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    259        1.1     ad 	height = ri->ri_font->fontheight;
    260        1.1     ad 	rs = ri->ri_stride;
    261       1.11     pk 
    262        1.9     ad 	bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
    263        1.9     ad 	fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
    264       1.11     pk 
    265        1.1     ad 	/* If fg and bg match this becomes a space character */
    266        1.1     ad 	if (fg == bg || uc == ' ') {
    267        1.1     ad 		while (height--) {
    268        1.1     ad 			*rp = bg;
    269        1.1     ad 			rp += rs;
    270        1.1     ad 		}
    271        1.1     ad 	} else {
    272        1.1     ad 		uc -= ri->ri_font->firstchar;
    273        1.1     ad 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    274        1.1     ad 		fs = ri->ri_font->stride;
    275       1.11     pk 
    276        1.1     ad 		/* NOT fontbits if bg is white */
    277        1.1     ad 		if (bg) {
    278        1.1     ad 			while (height--) {
    279        1.1     ad 				*rp = ~*fr;
    280        1.1     ad 				fr += fs;
    281        1.1     ad 				rp += rs;
    282        1.1     ad 			}
    283        1.1     ad 		} else {
    284        1.1     ad 			while (height--) {
    285        1.1     ad 				*rp = *fr;
    286        1.1     ad 				fr += fs;
    287        1.1     ad 				rp += rs;
    288        1.1     ad 			}
    289        1.1     ad 		}
    290        1.4     ad 
    291        1.1     ad 	}
    292        1.1     ad 
    293        1.1     ad 	/* Do underline */
    294       1.10     ad 	if ((attr & 1) != 0)
    295        1.1     ad 		rp[-(ri->ri_stride << 1)] = fg;
    296        1.1     ad }
    297        1.1     ad 
    298        1.1     ad /*
    299        1.1     ad  * Paint a single character. This is for 16-pixel wide fonts.
    300        1.1     ad  */
    301        1.1     ad static void
    302        1.1     ad rasops1_putchar16(cookie, row, col, uc, attr)
    303        1.1     ad 	void *cookie;
    304        1.1     ad 	int row, col;
    305        1.1     ad 	u_int uc;
    306        1.1     ad 	long attr;
    307        1.1     ad {
    308        1.1     ad 	int height, fs, rs, bg, fg;
    309        1.1     ad 	struct rasops_info *ri;
    310        1.1     ad 	u_char *fr, *rp;
    311       1.11     pk 
    312        1.1     ad 	ri = (struct rasops_info *)cookie;
    313        1.1     ad 
    314       1.11     pk #ifdef RASOPS_CLIPPING
    315       1.11     pk 	/* Catches 'row < 0' case too */
    316        1.3     ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    317        1.1     ad 		return;
    318        1.1     ad 
    319        1.3     ad 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    320        1.1     ad 		return;
    321        1.1     ad #endif
    322        1.1     ad 
    323        1.3     ad 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    324        1.1     ad 	height = ri->ri_font->fontheight;
    325        1.1     ad 	rs = ri->ri_stride;
    326       1.11     pk 
    327        1.9     ad 	bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
    328        1.9     ad 	fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
    329        1.9     ad 
    330        1.1     ad 	/* If fg and bg match this becomes a space character */
    331        1.1     ad 	if (fg == bg || uc == ' ') {
    332        1.1     ad 		while (height--) {
    333        1.1     ad 			*(int16_t *)rp = bg;
    334        1.1     ad 			rp += rs;
    335        1.1     ad 		}
    336        1.1     ad 	} else {
    337        1.1     ad 		uc -= ri->ri_font->firstchar;
    338        1.1     ad 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    339        1.1     ad 		fs = ri->ri_font->stride;
    340       1.11     pk 
    341        1.1     ad 		/* NOT fontbits if bg is white */
    342        1.1     ad 		if (bg) {
    343        1.1     ad 			while (height--) {
    344        1.1     ad 				rp[0] = ~fr[0];
    345        1.1     ad 				rp[1] = ~fr[1];
    346        1.1     ad 				fr += fs;
    347        1.1     ad 				rp += rs;
    348        1.1     ad 			}
    349        1.1     ad 		} else {
    350        1.1     ad 			while (height--) {
    351        1.1     ad 				rp[0] = fr[0];
    352        1.1     ad 				rp[1] = fr[1];
    353        1.1     ad 				fr += fs;
    354        1.1     ad 				rp += rs;
    355        1.1     ad 			}
    356        1.1     ad 		}
    357        1.1     ad 	}
    358        1.1     ad 
    359        1.1     ad 	/* Do underline */
    360       1.10     ad 	if ((attr & 1) != 0)
    361        1.1     ad 		*(int16_t *)(rp - (ri->ri_stride << 1)) = fg;
    362        1.1     ad }
    363       1.10     ad #endif	/* !RASOPS_SMALL */
    364        1.1     ad 
    365        1.1     ad /*
    366        1.4     ad  * Grab routines common to depths where (bpp < 8)
    367        1.1     ad  */
    368        1.4     ad #define NAME(ident)	rasops1_##ident
    369        1.4     ad #define PIXEL_SHIFT	0
    370        1.1     ad 
    371        1.4     ad #include <dev/rasops/rasops_bitops.h>
    372