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