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