Home | History | Annotate | Line # | Download | only in rasops
rasops24.c revision 1.5
      1  1.5  ad /* 	$NetBSD: rasops24.c,v 1.5 1999/04/26 04:29:12 ad Exp $ */
      2  1.1  ad 
      3  1.2  ad /*
      4  1.2  ad  * Copyright (c) 1999 Andy Doran <ad (at) NetBSD.org>
      5  1.1  ad  * All rights reserved.
      6  1.1  ad  *
      7  1.1  ad  * Redistribution and use in source and binary forms, with or without
      8  1.1  ad  * modification, are permitted provided that the following conditions
      9  1.1  ad  * are met:
     10  1.1  ad  * 1. Redistributions of source code must retain the above copyright
     11  1.1  ad  *    notice, this list of conditions and the following disclaimer.
     12  1.1  ad  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  ad  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  ad  *    documentation and/or other materials provided with the distribution.
     15  1.1  ad  *
     16  1.2  ad  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  1.2  ad  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  1.2  ad  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  1.2  ad  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  1.2  ad  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  1.2  ad  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  1.2  ad  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  1.2  ad  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  1.2  ad  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.2  ad  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.2  ad  * SUCH DAMAGE.
     27  1.2  ad  *
     28  1.1  ad  */
     29  1.2  ad 
     30  1.1  ad #include "opt_rasops.h"
     31  1.3  ad #include <sys/cdefs.h>
     32  1.5  ad __KERNEL_RCSID(0, "$NetBSD: rasops24.c,v 1.5 1999/04/26 04:29:12 ad Exp $");
     33  1.1  ad 
     34  1.1  ad #include <sys/types.h>
     35  1.1  ad #include <sys/param.h>
     36  1.1  ad #include <sys/systm.h>
     37  1.1  ad #include <sys/time.h>
     38  1.1  ad 
     39  1.4  ad #include <machine/endian.h>
     40  1.4  ad #include <machine/bswap.h>
     41  1.4  ad 
     42  1.1  ad #include <dev/wscons/wsdisplayvar.h>
     43  1.1  ad #include <dev/wscons/wsconsio.h>
     44  1.1  ad #include <dev/rasops/rasops.h>
     45  1.1  ad 
     46  1.1  ad static void 	rasops24_putchar __P((void *, int, int, u_int, long attr));
     47  1.4  ad static void 	rasops24_putchar8 __P((void *, int, int, u_int, long attr));
     48  1.4  ad static void 	rasops24_putchar12 __P((void *, int, int, u_int, long attr));
     49  1.4  ad static void 	rasops24_putchar16 __P((void *, int, int, u_int, long attr));
     50  1.1  ad static void 	rasops24_erasecols __P((void *, int, int, int, long));
     51  1.1  ad static void 	rasops24_eraserows __P((void *, int, int, long));
     52  1.4  ad static void	rasops24_makestamp __P((struct rasops_info *, long));
     53  1.1  ad 
     54  1.1  ad void	rasops24_init __P((struct rasops_info *ri));
     55  1.1  ad 
     56  1.4  ad /*
     57  1.4  ad  * 4x1 stamp for optimized character blitting
     58  1.4  ad  */
     59  1.4  ad static int32_t	stamp[64];
     60  1.4  ad static long	stamp_attr;
     61  1.4  ad static int	stamp_mutex;	/* XXX see note in readme */
     62  1.4  ad 
     63  1.4  ad /*
     64  1.4  ad  * XXX this confuses the hell out of gcc2 (not egcs) which always insists
     65  1.4  ad  * that the shift count is negative.
     66  1.4  ad  *
     67  1.4  ad  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
     68  1.4  ad  * destination int32_t[0] = STAMP_READ(offset)
     69  1.4  ad  * destination int32_t[1] = STAMP_READ(offset + 4)
     70  1.4  ad  * destination int32_t[2] = STAMP_READ(offset + 8)
     71  1.4  ad  */
     72  1.4  ad #define STAMP_SHIFT(fb,n)	((n*4-4) >= 0 ? (fb)>>(n*4-4):(fb)<<-(n*4-4))
     73  1.4  ad #define STAMP_MASK		(15 << 4)
     74  1.4  ad #define STAMP_READ(o)		(*(int32_t *)((caddr_t)stamp + (o)))
     75  1.4  ad 
     76  1.4  ad 
     77  1.1  ad /*
     78  1.1  ad  * Initalize rasops_info struct for this colordepth.
     79  1.1  ad  */
     80  1.1  ad void
     81  1.1  ad rasops24_init(ri)
     82  1.1  ad 	struct rasops_info *ri;
     83  1.1  ad {
     84  1.1  ad 
     85  1.1  ad 	switch (ri->ri_font->fontwidth) {
     86  1.1  ad 	case 8:
     87  1.4  ad 		ri->ri_ops.putchar = rasops24_putchar8;
     88  1.1  ad 		break;
     89  1.1  ad 
     90  1.1  ad 	case 12:
     91  1.4  ad 		ri->ri_ops.putchar = rasops24_putchar12;
     92  1.1  ad 		break;
     93  1.1  ad 
     94  1.1  ad 	case 16:
     95  1.4  ad 		ri->ri_ops.putchar = rasops24_putchar16;
     96  1.1  ad 		break;
     97  1.4  ad 
     98  1.1  ad 	default:
     99  1.4  ad 		ri->ri_ops.putchar = rasops24_putchar;
    100  1.1  ad 		break;
    101  1.1  ad 	}
    102  1.4  ad 
    103  1.1  ad 	if (ri->ri_rnum == 0) {
    104  1.1  ad 		ri->ri_rnum = 8;
    105  1.4  ad 		ri->ri_rpos = 0;
    106  1.1  ad 		ri->ri_gnum = 8;
    107  1.4  ad 		ri->ri_gpos = 8;
    108  1.1  ad 		ri->ri_bnum = 8;
    109  1.1  ad 		ri->ri_bpos = 16;
    110  1.1  ad 	}
    111  1.4  ad 
    112  1.4  ad 	ri->ri_ops.erasecols = rasops24_erasecols;
    113  1.4  ad 	ri->ri_ops.eraserows = rasops24_eraserows;
    114  1.1  ad }
    115  1.1  ad 
    116  1.4  ad 
    117  1.1  ad /*
    118  1.4  ad  * Recompute the blitting stamp.
    119  1.1  ad  */
    120  1.4  ad static void
    121  1.4  ad rasops24_makestamp(ri, attr)
    122  1.1  ad 	struct rasops_info *ri;
    123  1.1  ad 	long attr;
    124  1.1  ad {
    125  1.4  ad 	u_int32_t fg, bg, c1, c2, c3, c4;
    126  1.4  ad 	int i;
    127  1.1  ad 
    128  1.4  ad 	fg = ri->ri_devcmap[((u_int)attr >> 24) & 15] & 0xffffff;
    129  1.4  ad 	bg = ri->ri_devcmap[((u_int)attr >> 16) & 15] & 0xffffff;
    130  1.4  ad 	stamp_attr = attr;
    131  1.1  ad 
    132  1.4  ad 	for (i = 0; i < 64; i += 4) {
    133  1.4  ad #if BYTE_ORDER == LITTLE_ENDIAN
    134  1.4  ad 		c1 = (i & 32 ? fg : bg);
    135  1.4  ad 		c2 = (i & 16 ? fg : bg);
    136  1.4  ad 		c3 = (i & 8 ? fg : bg);
    137  1.4  ad 		c4 = (i & 4 ? fg : bg);
    138  1.4  ad #else
    139  1.4  ad 		c1 = (i & 8 ? fg : bg);
    140  1.4  ad 		c2 = (i & 4 ? fg : bg);
    141  1.4  ad 		c3 = (i & 16 ? fg : bg);
    142  1.4  ad 		c4 = (i & 32 ? fg : bg);
    143  1.4  ad #endif
    144  1.4  ad 		stamp[i+0] = (c1 <<  8) | (c2 >> 16);
    145  1.4  ad 		stamp[i+1] = (c2 << 16) | (c3 >>  8);
    146  1.4  ad 		stamp[i+2] = (c3 << 24) | c4;
    147  1.4  ad 
    148  1.4  ad #if BYTE_ORDER == LITTLE_ENDIAN
    149  1.4  ad 		if (!ri->ri_swab) {
    150  1.4  ad #else
    151  1.4  ad 		if (ri->ri_swab) {
    152  1.4  ad #endif
    153  1.4  ad 			stamp[i+0] = bswap32(stamp[i+0]);
    154  1.4  ad 			stamp[i+1] = bswap32(stamp[i+1]);
    155  1.4  ad 			stamp[i+2] = bswap32(stamp[i+2]);
    156  1.4  ad 		}
    157  1.4  ad 	}
    158  1.1  ad }
    159  1.1  ad 
    160  1.1  ad 
    161  1.1  ad /*
    162  1.4  ad  * Put a single character. This is the generic version.
    163  1.4  ad  * XXX this bites - we should use masks.
    164  1.1  ad  */
    165  1.4  ad static void
    166  1.4  ad rasops24_putchar(cookie, row, col, uc, attr)
    167  1.4  ad 	void *cookie;
    168  1.4  ad 	int row, col;
    169  1.4  ad 	u_int uc;
    170  1.1  ad 	long attr;
    171  1.1  ad {
    172  1.4  ad 	struct rasops_info *ri;
    173  1.4  ad 	int fb, width, height, cnt, clr[2];
    174  1.4  ad 	u_char *dp, *rp, *fr;
    175  1.1  ad 
    176  1.4  ad 	ri = (struct rasops_info *)cookie;
    177  1.1  ad 
    178  1.4  ad #ifdef RASOPS_CLIPPING
    179  1.4  ad 	/* Catches 'row < 0' case too */
    180  1.4  ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    181  1.4  ad 		return;
    182  1.1  ad 
    183  1.4  ad 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    184  1.4  ad 		return;
    185  1.4  ad #endif
    186  1.1  ad 
    187  1.1  ad 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    188  1.1  ad 	height = ri->ri_font->fontheight;
    189  1.4  ad 	width = ri->ri_font->fontwidth;
    190  1.1  ad 
    191  1.4  ad 	clr[1] = ri->ri_devcmap[((u_int)attr >> 24) & 15];
    192  1.4  ad 	clr[0] = ri->ri_devcmap[((u_int)attr >> 16) & 15];
    193  1.4  ad 
    194  1.4  ad 	if (uc == ' ') {
    195  1.4  ad 		while (height--) {
    196  1.4  ad 			dp = rp;
    197  1.4  ad 			rp += ri->ri_stride;
    198  1.4  ad 
    199  1.4  ad 			for (cnt = width; cnt; cnt--) {
    200  1.4  ad 				*dp++ = clr[0] >> 16;
    201  1.4  ad 				*dp++ = clr[0] >> 8;
    202  1.4  ad 				*dp++ = clr[0];
    203  1.4  ad 			}
    204  1.4  ad 		}
    205  1.4  ad 	} else {
    206  1.4  ad 		uc -= ri->ri_font->firstchar;
    207  1.4  ad 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    208  1.1  ad 
    209  1.4  ad 		while (height--) {
    210  1.4  ad 			dp = rp;
    211  1.4  ad 			fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) | (fr[0] << 24);
    212  1.4  ad 			fr += ri->ri_font->stride;
    213  1.4  ad 			rp += ri->ri_stride;
    214  1.4  ad 
    215  1.4  ad 			for (cnt = width; cnt; cnt--, fb <<= 1) {
    216  1.4  ad 				if ((fb >> 31) & 1) {
    217  1.4  ad 					*dp++ = clr[1] >> 16;
    218  1.4  ad 					*dp++ = clr[1] >> 8;
    219  1.4  ad 					*dp++ = clr[1];
    220  1.4  ad 				} else {
    221  1.4  ad 					*dp++ = clr[0] >> 16;
    222  1.4  ad 					*dp++ = clr[0] >> 8;
    223  1.4  ad 					*dp++ = clr[0];
    224  1.4  ad 				}
    225  1.4  ad 			}
    226  1.4  ad 		}
    227  1.4  ad 	}
    228  1.1  ad 
    229  1.4  ad 	/* Do underline */
    230  1.4  ad 	if (attr & 1) {
    231  1.4  ad 		rp -= ri->ri_stride << 1;
    232  1.4  ad 
    233  1.4  ad 		while (width--) {
    234  1.4  ad 			*rp++ = clr[1] >> 16;
    235  1.4  ad 			*rp++ = clr[1] >> 8;
    236  1.4  ad 			*rp++ = clr[1];
    237  1.1  ad 		}
    238  1.4  ad 	}
    239  1.1  ad }
    240  1.1  ad 
    241  1.1  ad 
    242  1.1  ad /*
    243  1.4  ad  * Put a single character. This is for 8-pixel wide fonts.
    244  1.1  ad  */
    245  1.1  ad static void
    246  1.4  ad rasops24_putchar8(cookie, row, col, uc, attr)
    247  1.1  ad 	void *cookie;
    248  1.4  ad 	int row, col;
    249  1.4  ad 	u_int uc;
    250  1.1  ad 	long attr;
    251  1.1  ad {
    252  1.1  ad 	struct rasops_info *ri;
    253  1.4  ad 	int height, so, fs;
    254  1.4  ad 	int32_t *rp;
    255  1.4  ad 	u_char *fr;
    256  1.4  ad 
    257  1.4  ad 	/* Can't risk remaking the stamp if it's already in use */
    258  1.4  ad 	if (stamp_mutex++) {
    259  1.4  ad 		stamp_mutex--;
    260  1.4  ad 		rasops24_putchar(cookie, row, col, uc, attr);
    261  1.4  ad 		return;
    262  1.4  ad 	}
    263  1.4  ad 
    264  1.1  ad 	ri = (struct rasops_info *)cookie;
    265  1.1  ad 
    266  1.1  ad #ifdef RASOPS_CLIPPING
    267  1.4  ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    268  1.4  ad 		stamp_mutex--;
    269  1.1  ad 		return;
    270  1.4  ad 	}
    271  1.1  ad 
    272  1.4  ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    273  1.4  ad 		stamp_mutex--;
    274  1.4  ad 		return;
    275  1.1  ad 	}
    276  1.4  ad #endif
    277  1.1  ad 
    278  1.4  ad 	/* Recompute stamp? */
    279  1.4  ad 	if (attr != stamp_attr)
    280  1.4  ad 		rasops24_makestamp(ri, attr);
    281  1.1  ad 
    282  1.4  ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    283  1.1  ad 	height = ri->ri_font->fontheight;
    284  1.1  ad 
    285  1.4  ad 	if (uc == (u_int)-1) {
    286  1.4  ad 		while (height--) {
    287  1.4  ad 			rp[0] = stamp[0];
    288  1.4  ad 			rp[1] = stamp[0];
    289  1.4  ad 			rp[2] = stamp[0];
    290  1.4  ad 			rp[3] = stamp[0];
    291  1.4  ad 			rp[4] = stamp[0];
    292  1.4  ad 			rp[5] = stamp[0];
    293  1.4  ad 			DELTA(rp, ri->ri_stride, int32_t *);
    294  1.4  ad 		}
    295  1.4  ad 	} else {
    296  1.4  ad 		uc -= ri->ri_font->firstchar;
    297  1.4  ad 		fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
    298  1.4  ad 		fs = ri->ri_font->stride;
    299  1.4  ad 
    300  1.4  ad 		while (height--) {
    301  1.4  ad 			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
    302  1.4  ad 			rp[0] = STAMP_READ(so);
    303  1.4  ad 			rp[1] = STAMP_READ(so + 4);
    304  1.4  ad 			rp[2] = STAMP_READ(so + 8);
    305  1.4  ad 
    306  1.4  ad 			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
    307  1.4  ad 			rp[3] = STAMP_READ(so);
    308  1.4  ad 			rp[4] = STAMP_READ(so + 4);
    309  1.4  ad 			rp[5] = STAMP_READ(so + 8);
    310  1.1  ad 
    311  1.4  ad 			fr += fs;
    312  1.4  ad 			DELTA(rp, ri->ri_stride, int32_t *);
    313  1.1  ad 		}
    314  1.4  ad 	}
    315  1.4  ad 
    316  1.4  ad 	/* Do underline */
    317  1.4  ad 	if (attr & 1) {
    318  1.4  ad 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    319  1.4  ad 		rp[0] = STAMP_READ(30);
    320  1.4  ad 		rp[1] = STAMP_READ(30);
    321  1.4  ad 		rp[2] = STAMP_READ(30);
    322  1.4  ad 		rp[3] = STAMP_READ(30);
    323  1.4  ad 		rp[4] = STAMP_READ(30);
    324  1.4  ad 		rp[5] = STAMP_READ(30);
    325  1.4  ad 	}
    326  1.1  ad 
    327  1.4  ad 	stamp_mutex--;
    328  1.1  ad }
    329  1.1  ad 
    330  1.1  ad 
    331  1.1  ad /*
    332  1.4  ad  * Put a single character. This is for 12-pixel wide fonts.
    333  1.1  ad  */
    334  1.1  ad static void
    335  1.4  ad rasops24_putchar12(cookie, row, col, uc, attr)
    336  1.1  ad 	void *cookie;
    337  1.1  ad 	int row, col;
    338  1.1  ad 	u_int uc;
    339  1.1  ad 	long attr;
    340  1.1  ad {
    341  1.1  ad 	struct rasops_info *ri;
    342  1.4  ad 	int height, so, fs;
    343  1.4  ad 	int32_t *rp;
    344  1.4  ad 	u_char *fr;
    345  1.4  ad 
    346  1.4  ad 	/* Can't risk remaking the stamp if it's already in use */
    347  1.4  ad 	if (stamp_mutex++) {
    348  1.4  ad 		stamp_mutex--;
    349  1.4  ad 		rasops24_putchar(cookie, row, col, uc, attr);
    350  1.1  ad 		return;
    351  1.1  ad 	}
    352  1.4  ad 
    353  1.1  ad 	ri = (struct rasops_info *)cookie;
    354  1.1  ad 
    355  1.1  ad #ifdef RASOPS_CLIPPING
    356  1.4  ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    357  1.4  ad 		stamp_mutex--;
    358  1.1  ad 		return;
    359  1.4  ad 	}
    360  1.1  ad 
    361  1.4  ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    362  1.4  ad 		stamp_mutex--;
    363  1.1  ad 		return;
    364  1.4  ad 	}
    365  1.1  ad #endif
    366  1.4  ad 
    367  1.4  ad 	/* Recompute stamp? */
    368  1.4  ad 	if (attr != stamp_attr)
    369  1.4  ad 		rasops24_makestamp(ri, attr);
    370  1.1  ad 
    371  1.4  ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    372  1.4  ad 	height = ri->ri_font->fontheight;
    373  1.1  ad 
    374  1.4  ad 	if (uc == (u_int)-1) {
    375  1.4  ad 		while (height--) {
    376  1.4  ad 			rp[0] = stamp[0];
    377  1.4  ad 			rp[1] = stamp[0];
    378  1.4  ad 			rp[2] = stamp[0];
    379  1.4  ad 			rp[3] = stamp[0];
    380  1.4  ad 			rp[4] = stamp[0];
    381  1.4  ad 			rp[5] = stamp[0];
    382  1.4  ad 			rp[6] = stamp[0];
    383  1.4  ad 			rp[7] = stamp[0];
    384  1.4  ad 			rp[8] = stamp[0];
    385  1.4  ad 			DELTA(rp, ri->ri_stride, int32_t *);
    386  1.4  ad 		}
    387  1.4  ad 	} else {
    388  1.4  ad 		uc -= ri->ri_font->firstchar;
    389  1.4  ad 		fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
    390  1.4  ad 		fs = ri->ri_font->stride;
    391  1.4  ad 
    392  1.4  ad 		while (height--) {
    393  1.4  ad 			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
    394  1.4  ad 			rp[0] = STAMP_READ(so);
    395  1.4  ad 			rp[1] = STAMP_READ(so + 4);
    396  1.4  ad 			rp[2] = STAMP_READ(so + 8);
    397  1.4  ad 
    398  1.4  ad 			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
    399  1.4  ad 			rp[3] = STAMP_READ(so);
    400  1.4  ad 			rp[4] = STAMP_READ(so + 4);
    401  1.4  ad 			rp[5] = STAMP_READ(so + 8);
    402  1.4  ad 
    403  1.4  ad 			so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
    404  1.4  ad 			rp[6] = STAMP_READ(so);
    405  1.4  ad 			rp[7] = STAMP_READ(so + 4);
    406  1.4  ad 			rp[8] = STAMP_READ(so + 8);
    407  1.1  ad 
    408  1.4  ad 			fr += fs;
    409  1.4  ad 			DELTA(rp, ri->ri_stride, int32_t *);
    410  1.1  ad 		}
    411  1.1  ad 	}
    412  1.4  ad 
    413  1.4  ad 	/* Do underline */
    414  1.4  ad 	if (attr & 1) {
    415  1.4  ad 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    416  1.4  ad 		rp[0] = STAMP_READ(30);
    417  1.4  ad 		rp[1] = STAMP_READ(30);
    418  1.4  ad 		rp[2] = STAMP_READ(30);
    419  1.4  ad 		rp[3] = STAMP_READ(30);
    420  1.4  ad 		rp[4] = STAMP_READ(30);
    421  1.4  ad 		rp[5] = STAMP_READ(30);
    422  1.4  ad 		rp[6] = STAMP_READ(30);
    423  1.4  ad 		rp[7] = STAMP_READ(30);
    424  1.4  ad 		rp[8] = STAMP_READ(30);
    425  1.4  ad 	}
    426  1.4  ad 
    427  1.4  ad 	stamp_mutex--;
    428  1.1  ad }
    429  1.1  ad 
    430  1.1  ad 
    431  1.1  ad /*
    432  1.4  ad  * Put a single character. This is for 16-pixel wide fonts.
    433  1.1  ad  */
    434  1.1  ad static void
    435  1.4  ad rasops24_putchar16(cookie, row, col, uc, attr)
    436  1.4  ad 	void *cookie;
    437  1.4  ad 	int row, col;
    438  1.4  ad 	u_int uc;
    439  1.4  ad 	long attr;
    440  1.1  ad {
    441  1.4  ad 	struct rasops_info *ri;
    442  1.4  ad 	int height, so, fs;
    443  1.4  ad 	int32_t *rp;
    444  1.4  ad 	u_char *fr;
    445  1.4  ad 
    446  1.4  ad 	/* Can't risk remaking the stamp if it's already in use */
    447  1.4  ad 	if (stamp_mutex++) {
    448  1.4  ad 		stamp_mutex--;
    449  1.4  ad 		rasops24_putchar(cookie, row, col, uc, attr);
    450  1.4  ad 		return;
    451  1.4  ad 	}
    452  1.4  ad 
    453  1.4  ad 	ri = (struct rasops_info *)cookie;
    454  1.4  ad 
    455  1.4  ad #ifdef RASOPS_CLIPPING
    456  1.4  ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    457  1.4  ad 		stamp_mutex--;
    458  1.4  ad 		return;
    459  1.4  ad 	}
    460  1.4  ad 
    461  1.4  ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    462  1.4  ad 		stamp_mutex--;
    463  1.4  ad 		return;
    464  1.4  ad 	}
    465  1.4  ad #endif
    466  1.4  ad 
    467  1.4  ad 	/* Recompute stamp? */
    468  1.5  ad 	if (attr != stamp_attr)
    469  1.4  ad 		rasops24_makestamp(ri, attr);
    470  1.5  ad 
    471  1.4  ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    472  1.4  ad 	height = ri->ri_font->fontheight;
    473  1.1  ad 
    474  1.4  ad 	if (uc == (u_int)-1) {
    475  1.4  ad 		while (height--) {
    476  1.4  ad 			rp[0] = stamp[0];
    477  1.4  ad 			rp[1] = stamp[0];
    478  1.4  ad 			rp[2] = stamp[0];
    479  1.4  ad 			rp[3] = stamp[0];
    480  1.4  ad 			rp[4] = stamp[0];
    481  1.4  ad 			rp[5] = stamp[0];
    482  1.4  ad 			rp[6] = stamp[0];
    483  1.4  ad 			rp[7] = stamp[0];
    484  1.4  ad 			rp[8] = stamp[0];
    485  1.4  ad 			rp[9] = stamp[0];
    486  1.4  ad 			rp[10] = stamp[0];
    487  1.4  ad 			rp[11] = stamp[0];
    488  1.4  ad 			DELTA(rp, ri->ri_stride, int32_t *);
    489  1.4  ad 		}
    490  1.4  ad 	} else {
    491  1.4  ad 		uc -= ri->ri_font->firstchar;
    492  1.4  ad 		fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
    493  1.4  ad 		fs = ri->ri_font->stride;
    494  1.4  ad 
    495  1.4  ad 		while (height--) {
    496  1.4  ad 			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
    497  1.4  ad 			rp[0] = STAMP_READ(so);
    498  1.4  ad 			rp[1] = STAMP_READ(so + 4);
    499  1.4  ad 			rp[2] = STAMP_READ(so + 8);
    500  1.4  ad 
    501  1.4  ad 			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
    502  1.4  ad 			rp[3] = STAMP_READ(so);
    503  1.4  ad 			rp[4] = STAMP_READ(so + 4);
    504  1.4  ad 			rp[5] = STAMP_READ(so + 8);
    505  1.4  ad 
    506  1.4  ad 			so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
    507  1.4  ad 			rp[6] = STAMP_READ(so);
    508  1.4  ad 			rp[7] = STAMP_READ(so + 4);
    509  1.4  ad 			rp[8] = STAMP_READ(so + 8);
    510  1.4  ad 
    511  1.4  ad 			so = STAMP_SHIFT(fr[1], 0) & STAMP_MASK;
    512  1.4  ad 			rp[9] = STAMP_READ(so);
    513  1.4  ad 			rp[10] = STAMP_READ(so + 4);
    514  1.4  ad 			rp[11] = STAMP_READ(so + 8);
    515  1.4  ad 
    516  1.4  ad 			DELTA(rp, ri->ri_stride, int32_t *);
    517  1.4  ad 			fr += fs;
    518  1.4  ad 		}
    519  1.4  ad 	}
    520  1.1  ad 
    521  1.4  ad 	/* Do underline */
    522  1.4  ad 	if (attr & 1) {
    523  1.4  ad 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    524  1.4  ad 		rp[0] = STAMP_READ(30);
    525  1.4  ad 		rp[1] = STAMP_READ(30);
    526  1.4  ad 		rp[2] = STAMP_READ(30);
    527  1.4  ad 		rp[3] = STAMP_READ(30);
    528  1.4  ad 		rp[4] = STAMP_READ(30);
    529  1.4  ad 		rp[5] = STAMP_READ(30);
    530  1.4  ad 		rp[6] = STAMP_READ(30);
    531  1.4  ad 		rp[7] = STAMP_READ(30);
    532  1.4  ad 		rp[8] = STAMP_READ(30);
    533  1.4  ad 		rp[9] = STAMP_READ(30);
    534  1.4  ad 		rp[10] = STAMP_READ(30);
    535  1.4  ad 		rp[11] = STAMP_READ(30);
    536  1.4  ad 	}
    537  1.4  ad 
    538  1.4  ad 	stamp_mutex--;
    539  1.1  ad }
    540  1.1  ad 
    541  1.1  ad 
    542  1.1  ad /*
    543  1.4  ad  * Erase rows. This is nice and easy due to alignment.
    544  1.1  ad  */
    545  1.1  ad static void
    546  1.1  ad rasops24_eraserows(cookie, row, num, attr)
    547  1.1  ad 	void *cookie;
    548  1.1  ad 	int row, num;
    549  1.1  ad 	long attr;
    550  1.1  ad {
    551  1.1  ad 	struct rasops_info *ri;
    552  1.4  ad 	u_int32_t *dp, clr, stamp[3];
    553  1.1  ad 	int n9, n3, n1, cnt;
    554  1.1  ad 
    555  1.4  ad 	/*
    556  1.4  ad 	 * If the color is gray, we can cheat and use the generic routines
    557  1.4  ad 	 * (which are faster, hopefully) since the r,g,b values are the same.
    558  1.4  ad 	 */
    559  1.4  ad 	if (attr & 4) {
    560  1.4  ad 		rasops_eraserows(cookie, row, num, attr);
    561  1.4  ad 		return;
    562  1.4  ad 	}
    563  1.4  ad 
    564  1.1  ad 	ri = (struct rasops_info *)cookie;
    565  1.1  ad 
    566  1.1  ad #ifdef RASOPS_CLIPPING
    567  1.1  ad 	if (row < 0) {
    568  1.1  ad 		num += row;
    569  1.1  ad 		row = 0;
    570  1.1  ad 	}
    571  1.1  ad 
    572  1.1  ad 	if ((row + num) > ri->ri_rows)
    573  1.1  ad 		num = ri->ri_rows - row;
    574  1.1  ad 
    575  1.1  ad 	if (num <= 0)
    576  1.1  ad 		return;
    577  1.1  ad #endif
    578  1.4  ad 
    579  1.4  ad 	clr = ri->ri_devcmap[(attr >> 16) & 15] & 0xffffff;
    580  1.4  ad 	stamp[0] = (clr <<  8) | (clr >> 16);
    581  1.4  ad 	stamp[1] = (clr << 16) | (clr >>  8);
    582  1.4  ad 	stamp[2] = (clr << 24) | clr;
    583  1.4  ad 
    584  1.4  ad #if BYTE_ORDER == LITTLE_ENDIAN
    585  1.4  ad 	if (!ri->ri_swab) {
    586  1.4  ad #else
    587  1.4  ad 	if (ri->ri_swab) {
    588  1.4  ad #endif
    589  1.4  ad 		stamp[0] = bswap32(stamp[0]);
    590  1.4  ad 		stamp[1] = bswap32(stamp[1]);
    591  1.4  ad 		stamp[2] = bswap32(stamp[2]);
    592  1.4  ad 	}
    593  1.4  ad 
    594  1.1  ad 	num *= ri->ri_font->fontheight;
    595  1.1  ad 	dp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale);
    596  1.4  ad 
    597  1.1  ad 	n9 = ri->ri_emustride / 36;
    598  1.1  ad 	cnt = (n9 << 5) + (n9 << 2); /* (32*n9) + (4*n9) */
    599  1.1  ad 	n3 = (ri->ri_emustride - cnt) / 12;
    600  1.1  ad 	cnt += (n3 << 3) + (n3 << 2); /* (8*n3) + (4*n3) */
    601  1.1  ad 	n1 = (ri->ri_emustride - cnt) >> 2;
    602  1.1  ad 
    603  1.4  ad 	while (num--) {
    604  1.4  ad 		for (cnt = n9; cnt; cnt--) {
    605  1.4  ad 			dp[0] = stamp[0];
    606  1.4  ad 			dp[1] = stamp[1];
    607  1.4  ad 			dp[2] = stamp[2];
    608  1.4  ad 			dp[3] = stamp[0];
    609  1.4  ad 			dp[4] = stamp[1];
    610  1.4  ad 			dp[5] = stamp[2];
    611  1.4  ad 			dp[6] = stamp[0];
    612  1.4  ad 			dp[7] = stamp[1];
    613  1.4  ad 			dp[8] = stamp[2];
    614  1.4  ad 			dp += 9;
    615  1.4  ad 		}
    616  1.1  ad 
    617  1.4  ad 		for (cnt = n3; cnt; cnt--) {
    618  1.4  ad 			dp[0] = stamp[0];
    619  1.4  ad 			dp[1] = stamp[1];
    620  1.4  ad 			dp[2] = stamp[2];
    621  1.4  ad 			dp += 3;
    622  1.4  ad 		}
    623  1.1  ad 
    624  1.4  ad 		for (cnt = 0; cnt < n1; cnt++)
    625  1.4  ad 			*dp++ = stamp[cnt];
    626  1.4  ad 
    627  1.4  ad 		DELTA(dp, ri->ri_delta, int32_t *);
    628  1.4  ad 	}
    629  1.4  ad }
    630  1.4  ad 
    631  1.4  ad 
    632  1.4  ad /*
    633  1.4  ad  * Erase columns.
    634  1.4  ad  */
    635  1.4  ad static void
    636  1.4  ad rasops24_erasecols(cookie, row, col, num, attr)
    637  1.4  ad 	void *cookie;
    638  1.4  ad 	int row, col, num;
    639  1.4  ad 	long attr;
    640  1.4  ad {
    641  1.4  ad 	int n12, n4, height, cnt, slop, clr, stamp[3];
    642  1.4  ad 	struct rasops_info *ri;
    643  1.4  ad 	int32_t *dp, *rp;
    644  1.4  ad 	u_char *dbp;
    645  1.4  ad 
    646  1.4  ad 	/*
    647  1.4  ad 	 * If the color is gray, we can cheat and use the generic routines
    648  1.4  ad 	 * (which are faster, hopefully) since the r,g,b values are the same.
    649  1.4  ad 	 */
    650  1.4  ad 	if (attr & 4) {
    651  1.4  ad 		rasops_erasecols(cookie, row, col, num, attr);
    652  1.4  ad 		return;
    653  1.4  ad 	}
    654  1.4  ad 
    655  1.4  ad 	ri = (struct rasops_info *)cookie;
    656  1.4  ad 
    657  1.4  ad #ifdef RASOPS_CLIPPING
    658  1.4  ad 	/* Catches 'row < 0' case too */
    659  1.4  ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    660  1.4  ad 		return;
    661  1.4  ad 
    662  1.4  ad 	if (col < 0) {
    663  1.4  ad 		num += col;
    664  1.4  ad 		col = 0;
    665  1.4  ad 	}
    666  1.4  ad 
    667  1.4  ad 	if ((col + num) > ri->ri_cols)
    668  1.4  ad 		num = ri->ri_cols - col;
    669  1.4  ad 
    670  1.4  ad 	if (num <= 0)
    671  1.4  ad 		return;
    672  1.4  ad #endif
    673  1.4  ad 
    674  1.4  ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    675  1.4  ad 	num *= ri->ri_font->fontwidth;
    676  1.4  ad 	height = ri->ri_font->fontheight;
    677  1.4  ad 
    678  1.4  ad 	clr = ri->ri_devcmap[(attr >> 16) & 15] & 0xffffff;
    679  1.4  ad 	stamp[0] = (clr <<  8) | (clr >> 16);
    680  1.4  ad 	stamp[1] = (clr << 16) | (clr >>  8);
    681  1.4  ad 	stamp[2] = (clr << 24) | clr;
    682  1.4  ad 
    683  1.4  ad #if BYTE_ORDER == LITTLE_ENDIAN
    684  1.4  ad 	if (!ri->ri_swab) {
    685  1.4  ad #else
    686  1.4  ad 	if (ri->ri_swab) {
    687  1.4  ad #endif
    688  1.4  ad 		stamp[0] = bswap32(stamp[0]);
    689  1.4  ad 		stamp[1] = bswap32(stamp[1]);
    690  1.4  ad 		stamp[2] = bswap32(stamp[2]);
    691  1.4  ad 	}
    692  1.4  ad 
    693  1.4  ad 	/*
    694  1.4  ad 	 * The current byte offset mod 4 tells us the number of 24-bit pels
    695  1.4  ad 	 * we need to write for alignment to 32-bits. Once we're aligned on
    696  1.4  ad 	 * a 32-bit boundary, we're also aligned on a 4 pixel boundary, so
    697  1.4  ad 	 * the stamp does not need to be rotated. The following shows the
    698  1.4  ad 	 * layout of 4 pels (a, b, and c) in a 3 word region and illustrates
    699  1.4  ad 	 * this:
    700  1.4  ad 	 *
    701  1.4  ad 	 *	aaab bbcc cddd
    702  1.4  ad 	 */
    703  1.4  ad 	slop = (int)rp & 3;	num -= slop;
    704  1.4  ad 	n12 = num / 12;		num -= (n12 << 3) + (n12 << 2);
    705  1.4  ad 	n4 = num >> 2;		num &= 3;
    706  1.4  ad 
    707  1.4  ad 	while (height--) {
    708  1.4  ad 		dbp = (u_char *)rp;
    709  1.4  ad 		DELTA(rp, ri->ri_stride, int32_t *);
    710  1.4  ad 
    711  1.4  ad 		/* Align to 4 bytes */
    712  1.4  ad 		/* XXX handle with masks, bring under control of ri_swab */
    713  1.4  ad 		for (cnt = slop; cnt; cnt--) {
    714  1.4  ad 			*dbp++ = (clr >> 16);
    715  1.4  ad 			*dbp++ = (clr >> 8);
    716  1.4  ad 			*dbp++ = clr;
    717  1.4  ad 		}
    718  1.4  ad 
    719  1.4  ad 		dp = (int32_t *)dbp;
    720  1.4  ad 
    721  1.4  ad 		/* 12 pels per loop */
    722  1.4  ad 		for (cnt = n12; cnt; cnt--) {
    723  1.4  ad 			dp[0] = stamp[0];
    724  1.4  ad 			dp[1] = stamp[1];
    725  1.4  ad 			dp[2] = stamp[2];
    726  1.4  ad 			dp[3] = stamp[0];
    727  1.4  ad 			dp[4] = stamp[1];
    728  1.4  ad 			dp[5] = stamp[2];
    729  1.4  ad 			dp[6] = stamp[0];
    730  1.4  ad 			dp[7] = stamp[1];
    731  1.4  ad 			dp[8] = stamp[2];
    732  1.4  ad 			dp += 9;
    733  1.1  ad 		}
    734  1.1  ad 
    735  1.4  ad 		/* 4 pels per loop */
    736  1.4  ad 		for (cnt = n4; cnt; cnt--) {
    737  1.4  ad 			dp[0] = stamp[0];
    738  1.4  ad 			dp[1] = stamp[1];
    739  1.4  ad 			dp[2] = stamp[2];
    740  1.4  ad 			dp += 3;
    741  1.4  ad 		}
    742  1.1  ad 
    743  1.4  ad 		/* Trailing slop */
    744  1.4  ad 		/* XXX handle with masks, bring under control of ri_swab */
    745  1.4  ad 		dbp = (u_char *)dp;
    746  1.4  ad 		for (cnt = num; cnt; cnt--) {
    747  1.4  ad 			*dbp++ = (clr >> 16);
    748  1.4  ad 			*dbp++ = (clr >> 8);
    749  1.4  ad 			*dbp++ = clr;
    750  1.4  ad 		}
    751  1.1  ad 	}
    752  1.1  ad }
    753