Home | History | Annotate | Line # | Download | only in rasops
rasops24.c revision 1.27
      1  1.27       dsl /* 	$NetBSD: rasops24.c,v 1.27 2009/03/14 21:04:22 dsl 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.27       dsl __KERNEL_RCSID(0, "$NetBSD: rasops24.c,v 1.27 2009/03/14 21:04:22 dsl 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.26       dsl rasops24_init(struct rasops_info *ri)
     83   1.1        ad {
     84   1.1        ad 
     85   1.1        ad 	switch (ri->ri_font->fontwidth) {
     86   1.9        ad #ifndef RASOPS_SMALL
     87   1.1        ad 	case 8:
     88   1.4        ad 		ri->ri_ops.putchar = rasops24_putchar8;
     89   1.1        ad 		break;
     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 	case 16:
     94   1.4        ad 		ri->ri_ops.putchar = rasops24_putchar16;
     95   1.1        ad 		break;
     96   1.9        ad #endif
     97   1.1        ad 	default:
     98   1.4        ad 		ri->ri_ops.putchar = rasops24_putchar;
     99   1.1        ad 		break;
    100   1.1        ad 	}
    101   1.4        ad 
    102   1.1        ad 	if (ri->ri_rnum == 0) {
    103   1.1        ad 		ri->ri_rnum = 8;
    104   1.4        ad 		ri->ri_rpos = 0;
    105   1.1        ad 		ri->ri_gnum = 8;
    106   1.4        ad 		ri->ri_gpos = 8;
    107   1.1        ad 		ri->ri_bnum = 8;
    108   1.1        ad 		ri->ri_bpos = 16;
    109   1.1        ad 	}
    110   1.4        ad 
    111   1.4        ad 	ri->ri_ops.erasecols = rasops24_erasecols;
    112   1.4        ad 	ri->ri_ops.eraserows = rasops24_eraserows;
    113   1.1        ad }
    114   1.1        ad 
    115   1.1        ad /*
    116   1.4        ad  * Put a single character. This is the generic version.
    117  1.12        pk  * XXX this bites - we should use masks.
    118   1.1        ad  */
    119   1.4        ad static void
    120  1.27       dsl rasops24_putchar(void *cookie, int row, int col, u_int uc, long attr)
    121   1.1        ad {
    122   1.9        ad 	int fb, width, height, cnt, clr[2];
    123   1.4        ad 	struct rasops_info *ri;
    124   1.4        ad 	u_char *dp, *rp, *fr;
    125  1.12        pk 
    126   1.4        ad 	ri = (struct rasops_info *)cookie;
    127   1.1        ad 
    128  1.12        pk #ifdef RASOPS_CLIPPING
    129  1.12        pk 	/* Catches 'row < 0' case too */
    130   1.4        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    131   1.4        ad 		return;
    132   1.1        ad 
    133   1.4        ad 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    134   1.4        ad 		return;
    135   1.4        ad #endif
    136  1.12        pk 
    137   1.1        ad 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    138   1.1        ad 	height = ri->ri_font->fontheight;
    139   1.4        ad 	width = ri->ri_font->fontwidth;
    140  1.12        pk 
    141  1.12        pk 	clr[1] = ri->ri_devcmap[((u_int)attr >> 24) & 0xf];
    142  1.12        pk 	clr[0] = ri->ri_devcmap[((u_int)attr >> 16) & 0xf];
    143   1.4        ad 
    144   1.4        ad 	if (uc == ' ') {
    145  1.12        pk 		u_char c = clr[0];
    146   1.4        ad 		while (height--) {
    147   1.4        ad 			dp = rp;
    148   1.4        ad 			rp += ri->ri_stride;
    149  1.12        pk 
    150   1.4        ad 			for (cnt = width; cnt; cnt--) {
    151  1.12        pk 				*dp++ = c >> 16;
    152  1.12        pk 				*dp++ = c >> 8;
    153  1.12        pk 				*dp++ = c;
    154   1.4        ad 			}
    155  1.12        pk 		}
    156   1.4        ad 	} else {
    157   1.4        ad 		uc -= ri->ri_font->firstchar;
    158   1.4        ad 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    159   1.1        ad 
    160   1.4        ad 		while (height--) {
    161   1.4        ad 			dp = rp;
    162   1.9        ad 			fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) |
    163   1.9        ad 			    (fr[0] << 24);
    164   1.4        ad 			fr += ri->ri_font->stride;
    165   1.4        ad 			rp += ri->ri_stride;
    166  1.12        pk 
    167   1.4        ad 			for (cnt = width; cnt; cnt--, fb <<= 1) {
    168   1.4        ad 				if ((fb >> 31) & 1) {
    169   1.4        ad 					*dp++ = clr[1] >> 16;
    170   1.4        ad 					*dp++ = clr[1] >> 8;
    171   1.4        ad 					*dp++ = clr[1];
    172   1.4        ad 				} else {
    173   1.4        ad 					*dp++ = clr[0] >> 16;
    174   1.4        ad 					*dp++ = clr[0] >> 8;
    175   1.4        ad 					*dp++ = clr[0];
    176   1.4        ad 				}
    177   1.4        ad 			}
    178  1.12        pk 		}
    179   1.4        ad 	}
    180  1.12        pk 
    181   1.4        ad 	/* Do underline */
    182   1.9        ad 	if ((attr & 1) != 0) {
    183  1.12        pk 		u_char c = clr[1];
    184  1.12        pk 
    185   1.4        ad 		rp -= ri->ri_stride << 1;
    186   1.4        ad 
    187   1.4        ad 		while (width--) {
    188  1.12        pk 			*rp++ = c >> 16;
    189  1.12        pk 			*rp++ = c >> 8;
    190  1.12        pk 			*rp++ = c;
    191   1.1        ad 		}
    192  1.12        pk 	}
    193   1.1        ad }
    194   1.1        ad 
    195   1.9        ad #ifndef RASOPS_SMALL
    196   1.9        ad /*
    197   1.9        ad  * Recompute the blitting stamp.
    198   1.9        ad  */
    199   1.9        ad static void
    200  1.26       dsl rasops24_makestamp(struct rasops_info *ri, long attr)
    201   1.9        ad {
    202   1.9        ad 	u_int fg, bg, c1, c2, c3, c4;
    203   1.9        ad 	int i;
    204  1.12        pk 
    205  1.12        pk 	fg = ri->ri_devcmap[((u_int)attr >> 24) & 0xf] & 0xffffff;
    206  1.12        pk 	bg = ri->ri_devcmap[((u_int)attr >> 16) & 0xf] & 0xffffff;
    207   1.9        ad 	stamp_attr = attr;
    208  1.12        pk 
    209   1.9        ad 	for (i = 0; i < 64; i += 4) {
    210   1.9        ad #if BYTE_ORDER == LITTLE_ENDIAN
    211   1.9        ad 		c1 = (i & 32 ? fg : bg);
    212   1.9        ad 		c2 = (i & 16 ? fg : bg);
    213   1.9        ad 		c3 = (i & 8 ? fg : bg);
    214   1.9        ad 		c4 = (i & 4 ? fg : bg);
    215   1.9        ad #else
    216   1.9        ad 		c1 = (i & 8 ? fg : bg);
    217   1.9        ad 		c2 = (i & 4 ? fg : bg);
    218   1.9        ad 		c3 = (i & 16 ? fg : bg);
    219   1.9        ad 		c4 = (i & 32 ? fg : bg);
    220   1.9        ad #endif
    221   1.9        ad 		stamp[i+0] = (c1 <<  8) | (c2 >> 16);
    222   1.9        ad 		stamp[i+1] = (c2 << 16) | (c3 >>  8);
    223   1.9        ad 		stamp[i+2] = (c3 << 24) | c4;
    224   1.9        ad 
    225   1.9        ad #if BYTE_ORDER == LITTLE_ENDIAN
    226   1.9        ad 		if ((ri->ri_flg & RI_BSWAP) == 0) {
    227   1.9        ad #else
    228   1.9        ad 		if ((ri->ri_flg & RI_BSWAP) != 0) {
    229   1.9        ad #endif
    230   1.9        ad 			stamp[i+0] = bswap32(stamp[i+0]);
    231   1.9        ad 			stamp[i+1] = bswap32(stamp[i+1]);
    232   1.9        ad 			stamp[i+2] = bswap32(stamp[i+2]);
    233   1.9        ad 		}
    234   1.9        ad 	}
    235   1.9        ad }
    236   1.1        ad 
    237   1.1        ad /*
    238   1.4        ad  * Put a single character. This is for 8-pixel wide fonts.
    239   1.1        ad  */
    240   1.1        ad static void
    241  1.27       dsl rasops24_putchar8(void *cookie, int row, int col, u_int uc, long attr)
    242   1.1        ad {
    243   1.1        ad 	struct rasops_info *ri;
    244   1.4        ad 	int height, so, fs;
    245   1.4        ad 	int32_t *rp;
    246   1.4        ad 	u_char *fr;
    247  1.12        pk 
    248   1.4        ad 	/* Can't risk remaking the stamp if it's already in use */
    249   1.4        ad 	if (stamp_mutex++) {
    250   1.4        ad 		stamp_mutex--;
    251   1.4        ad 		rasops24_putchar(cookie, row, col, uc, attr);
    252   1.4        ad 		return;
    253   1.4        ad 	}
    254   1.4        ad 
    255   1.1        ad 	ri = (struct rasops_info *)cookie;
    256   1.1        ad 
    257  1.12        pk #ifdef RASOPS_CLIPPING
    258   1.4        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    259   1.4        ad 		stamp_mutex--;
    260   1.1        ad 		return;
    261   1.4        ad 	}
    262   1.1        ad 
    263   1.4        ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    264   1.4        ad 		stamp_mutex--;
    265   1.4        ad 		return;
    266   1.1        ad 	}
    267   1.4        ad #endif
    268   1.1        ad 
    269   1.4        ad 	/* Recompute stamp? */
    270   1.4        ad 	if (attr != stamp_attr)
    271   1.4        ad 		rasops24_makestamp(ri, attr);
    272  1.12        pk 
    273   1.4        ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    274   1.1        ad 	height = ri->ri_font->fontheight;
    275  1.12        pk 
    276   1.4        ad 	if (uc == (u_int)-1) {
    277  1.12        pk 		int32_t c = stamp[0];
    278   1.4        ad 		while (height--) {
    279  1.12        pk 			rp[0] = rp[1] = rp[2] = rp[3] = rp[4] = rp[5] = c;
    280   1.4        ad 			DELTA(rp, ri->ri_stride, int32_t *);
    281  1.12        pk 		}
    282   1.4        ad 	} else {
    283   1.4        ad 		uc -= ri->ri_font->firstchar;
    284   1.4        ad 		fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
    285   1.4        ad 		fs = ri->ri_font->stride;
    286  1.12        pk 
    287   1.4        ad 		while (height--) {
    288   1.4        ad 			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
    289   1.4        ad 			rp[0] = STAMP_READ(so);
    290   1.4        ad 			rp[1] = STAMP_READ(so + 4);
    291   1.4        ad 			rp[2] = STAMP_READ(so + 8);
    292  1.12        pk 
    293   1.4        ad 			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
    294   1.4        ad 			rp[3] = STAMP_READ(so);
    295   1.4        ad 			rp[4] = STAMP_READ(so + 4);
    296   1.4        ad 			rp[5] = STAMP_READ(so + 8);
    297   1.1        ad 
    298   1.4        ad 			fr += fs;
    299  1.12        pk 			DELTA(rp, ri->ri_stride, int32_t *);
    300   1.1        ad 		}
    301  1.12        pk 	}
    302   1.4        ad 
    303   1.4        ad 	/* Do underline */
    304   1.9        ad 	if ((attr & 1) != 0) {
    305  1.12        pk 		int32_t c = STAMP_READ(52);
    306  1.12        pk 
    307   1.4        ad 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    308  1.12        pk 		rp[0] = rp[1] = rp[2] = rp[3] = rp[4] = rp[5] = c;
    309  1.12        pk 	}
    310  1.12        pk 
    311   1.4        ad 	stamp_mutex--;
    312   1.1        ad }
    313   1.1        ad 
    314   1.1        ad /*
    315   1.4        ad  * Put a single character. This is for 12-pixel wide fonts.
    316   1.1        ad  */
    317   1.1        ad static void
    318  1.27       dsl rasops24_putchar12(void *cookie, int row, int col, u_int uc, long attr)
    319   1.1        ad {
    320   1.1        ad 	struct rasops_info *ri;
    321   1.4        ad 	int height, so, fs;
    322   1.4        ad 	int32_t *rp;
    323   1.4        ad 	u_char *fr;
    324  1.12        pk 
    325   1.4        ad 	/* Can't risk remaking the stamp if it's already in use */
    326   1.4        ad 	if (stamp_mutex++) {
    327   1.4        ad 		stamp_mutex--;
    328   1.4        ad 		rasops24_putchar(cookie, row, col, uc, attr);
    329   1.1        ad 		return;
    330   1.1        ad 	}
    331   1.4        ad 
    332   1.1        ad 	ri = (struct rasops_info *)cookie;
    333   1.1        ad 
    334  1.12        pk #ifdef RASOPS_CLIPPING
    335   1.4        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    336   1.4        ad 		stamp_mutex--;
    337   1.1        ad 		return;
    338   1.4        ad 	}
    339   1.1        ad 
    340   1.4        ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    341   1.4        ad 		stamp_mutex--;
    342   1.1        ad 		return;
    343   1.4        ad 	}
    344   1.1        ad #endif
    345   1.4        ad 
    346   1.4        ad 	/* Recompute stamp? */
    347   1.4        ad 	if (attr != stamp_attr)
    348   1.4        ad 		rasops24_makestamp(ri, attr);
    349  1.12        pk 
    350   1.4        ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    351   1.4        ad 	height = ri->ri_font->fontheight;
    352   1.1        ad 
    353   1.4        ad 	if (uc == (u_int)-1) {
    354  1.12        pk 		int32_t c = stamp[0];
    355   1.4        ad 		while (height--) {
    356  1.19     perry 			rp[0] = rp[1] = rp[2] = rp[3] =
    357  1.12        pk 			rp[4] = rp[5] = rp[6] = rp[7] = rp[8] = c;
    358  1.12        pk 			DELTA(rp, ri->ri_stride, int32_t *);
    359  1.12        pk 		}
    360   1.4        ad 	} else {
    361   1.4        ad 		uc -= ri->ri_font->firstchar;
    362   1.4        ad 		fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
    363   1.4        ad 		fs = ri->ri_font->stride;
    364  1.12        pk 
    365   1.4        ad 		while (height--) {
    366   1.4        ad 			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
    367   1.4        ad 			rp[0] = STAMP_READ(so);
    368   1.4        ad 			rp[1] = STAMP_READ(so + 4);
    369   1.4        ad 			rp[2] = STAMP_READ(so + 8);
    370  1.12        pk 
    371   1.4        ad 			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
    372   1.4        ad 			rp[3] = STAMP_READ(so);
    373   1.4        ad 			rp[4] = STAMP_READ(so + 4);
    374   1.4        ad 			rp[5] = STAMP_READ(so + 8);
    375   1.4        ad 
    376   1.4        ad 			so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
    377   1.4        ad 			rp[6] = STAMP_READ(so);
    378   1.4        ad 			rp[7] = STAMP_READ(so + 4);
    379   1.4        ad 			rp[8] = STAMP_READ(so + 8);
    380   1.1        ad 
    381   1.4        ad 			fr += fs;
    382  1.12        pk 			DELTA(rp, ri->ri_stride, int32_t *);
    383   1.1        ad 		}
    384  1.12        pk 	}
    385   1.4        ad 
    386   1.4        ad 	/* Do underline */
    387   1.9        ad 	if ((attr & 1) != 0) {
    388  1.12        pk 		int32_t c = STAMP_READ(52);
    389  1.12        pk 
    390   1.4        ad 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    391  1.12        pk 		rp[0] = rp[1] = rp[2] = rp[3] =
    392  1.12        pk 		rp[4] = rp[5] = rp[6] = rp[7] = rp[8] = c;
    393  1.12        pk 	}
    394  1.12        pk 
    395   1.4        ad 	stamp_mutex--;
    396   1.1        ad }
    397   1.1        ad 
    398   1.1        ad /*
    399   1.4        ad  * Put a single character. This is for 16-pixel wide fonts.
    400   1.1        ad  */
    401   1.1        ad static void
    402  1.27       dsl rasops24_putchar16(void *cookie, int row, int col, u_int uc, long attr)
    403   1.1        ad {
    404   1.4        ad 	struct rasops_info *ri;
    405   1.4        ad 	int height, so, fs;
    406   1.4        ad 	int32_t *rp;
    407   1.4        ad 	u_char *fr;
    408  1.12        pk 
    409   1.4        ad 	/* Can't risk remaking the stamp if it's already in use */
    410   1.4        ad 	if (stamp_mutex++) {
    411   1.4        ad 		stamp_mutex--;
    412   1.4        ad 		rasops24_putchar(cookie, row, col, uc, attr);
    413   1.4        ad 		return;
    414   1.4        ad 	}
    415   1.4        ad 
    416   1.4        ad 	ri = (struct rasops_info *)cookie;
    417   1.4        ad 
    418  1.12        pk #ifdef RASOPS_CLIPPING
    419   1.4        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    420   1.4        ad 		stamp_mutex--;
    421   1.4        ad 		return;
    422   1.4        ad 	}
    423   1.4        ad 
    424   1.4        ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    425   1.4        ad 		stamp_mutex--;
    426   1.4        ad 		return;
    427   1.4        ad 	}
    428   1.4        ad #endif
    429   1.4        ad 
    430   1.4        ad 	/* Recompute stamp? */
    431   1.5        ad 	if (attr != stamp_attr)
    432   1.4        ad 		rasops24_makestamp(ri, attr);
    433   1.5        ad 
    434   1.4        ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    435   1.4        ad 	height = ri->ri_font->fontheight;
    436  1.12        pk 
    437   1.4        ad 	if (uc == (u_int)-1) {
    438  1.12        pk 		int32_t c = stamp[0];
    439   1.4        ad 		while (height--) {
    440  1.19     perry 			rp[0] = rp[1] = rp[2] = rp[3] =
    441  1.19     perry 			rp[4] = rp[5] = rp[6] = rp[7] =
    442  1.12        pk 			rp[8] = rp[9] = rp[10] = rp[11] = c;
    443  1.12        pk 			DELTA(rp, ri->ri_stride, int32_t *);
    444  1.12        pk 		}
    445   1.4        ad 	} else {
    446   1.4        ad 		uc -= ri->ri_font->firstchar;
    447   1.4        ad 		fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
    448   1.4        ad 		fs = ri->ri_font->stride;
    449  1.12        pk 
    450   1.4        ad 		while (height--) {
    451   1.4        ad 			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
    452   1.4        ad 			rp[0] = STAMP_READ(so);
    453   1.4        ad 			rp[1] = STAMP_READ(so + 4);
    454   1.4        ad 			rp[2] = STAMP_READ(so + 8);
    455  1.12        pk 
    456   1.4        ad 			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
    457   1.4        ad 			rp[3] = STAMP_READ(so);
    458   1.4        ad 			rp[4] = STAMP_READ(so + 4);
    459   1.4        ad 			rp[5] = STAMP_READ(so + 8);
    460   1.4        ad 
    461   1.4        ad 			so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
    462   1.4        ad 			rp[6] = STAMP_READ(so);
    463   1.4        ad 			rp[7] = STAMP_READ(so + 4);
    464   1.4        ad 			rp[8] = STAMP_READ(so + 8);
    465  1.12        pk 
    466   1.4        ad 			so = STAMP_SHIFT(fr[1], 0) & STAMP_MASK;
    467   1.4        ad 			rp[9] = STAMP_READ(so);
    468   1.4        ad 			rp[10] = STAMP_READ(so + 4);
    469   1.4        ad 			rp[11] = STAMP_READ(so + 8);
    470   1.4        ad 
    471  1.12        pk 			DELTA(rp, ri->ri_stride, int32_t *);
    472   1.4        ad 			fr += fs;
    473   1.4        ad 		}
    474  1.12        pk 	}
    475   1.1        ad 
    476   1.4        ad 	/* Do underline */
    477   1.9        ad 	if ((attr & 1) != 0) {
    478  1.12        pk 		int32_t c = STAMP_READ(52);
    479  1.12        pk 
    480   1.4        ad 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    481  1.19     perry 		rp[0] = rp[1] = rp[2] = rp[3] =
    482  1.19     perry 		rp[4] = rp[5] = rp[6] = rp[7] =
    483  1.12        pk 		rp[8] = rp[9] = rp[10] = rp[11] = c;
    484  1.12        pk 	}
    485  1.12        pk 
    486   1.4        ad 	stamp_mutex--;
    487   1.1        ad }
    488  1.11        ad #endif	/* !RASOPS_SMALL */
    489   1.1        ad 
    490   1.1        ad /*
    491   1.4        ad  * Erase rows. This is nice and easy due to alignment.
    492   1.1        ad  */
    493   1.1        ad static void
    494  1.27       dsl rasops24_eraserows(void *cookie, int row, int num, long attr)
    495   1.1        ad {
    496   1.8        ad 	int n9, n3, n1, cnt, stride, delta;
    497  1.20  christos 	u_int32_t *dp, clr, xstamp[3];
    498   1.1        ad 	struct rasops_info *ri;
    499  1.12        pk 
    500  1.12        pk 	/*
    501   1.4        ad 	 * If the color is gray, we can cheat and use the generic routines
    502   1.4        ad 	 * (which are faster, hopefully) since the r,g,b values are the same.
    503   1.4        ad 	 */
    504   1.9        ad 	if ((attr & 4) != 0) {
    505   1.4        ad 		rasops_eraserows(cookie, row, num, attr);
    506   1.4        ad 		return;
    507   1.4        ad 	}
    508   1.4        ad 
    509   1.1        ad 	ri = (struct rasops_info *)cookie;
    510   1.1        ad 
    511   1.1        ad #ifdef RASOPS_CLIPPING
    512   1.1        ad 	if (row < 0) {
    513   1.1        ad 		num += row;
    514   1.1        ad 		row = 0;
    515   1.1        ad 	}
    516   1.1        ad 
    517   1.1        ad 	if ((row + num) > ri->ri_rows)
    518   1.1        ad 		num = ri->ri_rows - row;
    519  1.12        pk 
    520   1.1        ad 	if (num <= 0)
    521   1.1        ad 		return;
    522   1.1        ad #endif
    523  1.12        pk 
    524  1.12        pk 	clr = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xffffff;
    525  1.20  christos 	xstamp[0] = (clr <<  8) | (clr >> 16);
    526  1.20  christos 	xstamp[1] = (clr << 16) | (clr >>  8);
    527  1.20  christos 	xstamp[2] = (clr << 24) | clr;
    528   1.4        ad 
    529   1.4        ad #if BYTE_ORDER == LITTLE_ENDIAN
    530   1.7        ad 	if ((ri->ri_flg & RI_BSWAP) == 0) {
    531   1.4        ad #else
    532   1.7        ad 	if ((ri->ri_flg & RI_BSWAP) != 0) {
    533   1.4        ad #endif
    534  1.20  christos 		xstamp[0] = bswap32(xstamp[0]);
    535  1.20  christos 		xstamp[1] = bswap32(xstamp[1]);
    536  1.20  christos 		xstamp[2] = bswap32(xstamp[2]);
    537   1.4        ad 	}
    538   1.4        ad 
    539  1.12        pk 	/*
    540   1.7        ad 	 * XXX the wsdisplay_emulops interface seems a little deficient in
    541  1.12        pk 	 * that there is no way to clear the *entire* screen. We provide a
    542  1.12        pk 	 * workaround here: if the entire console area is being cleared, and
    543   1.7        ad 	 * the RI_FULLCLEAR flag is set, clear the entire display.
    544  1.12        pk 	 */
    545   1.7        ad 	if (num == ri->ri_rows && (ri->ri_flg & RI_FULLCLEAR) != 0) {
    546   1.7        ad 		stride = ri->ri_stride;
    547   1.7        ad 		num = ri->ri_height;
    548   1.8        ad 		dp = (int32_t *)ri->ri_origbits;
    549   1.8        ad 		delta = 0;
    550   1.7        ad 	} else {
    551   1.7        ad 		stride = ri->ri_emustride;
    552   1.7        ad 		num *= ri->ri_font->fontheight;
    553   1.8        ad 		dp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale);
    554   1.8        ad 		delta = ri->ri_delta;
    555   1.7        ad 	}
    556   1.7        ad 
    557   1.7        ad 	n9 = stride / 36;
    558   1.1        ad 	cnt = (n9 << 5) + (n9 << 2); /* (32*n9) + (4*n9) */
    559   1.7        ad 	n3 = (stride - cnt) / 12;
    560   1.1        ad 	cnt += (n3 << 3) + (n3 << 2); /* (8*n3) + (4*n3) */
    561   1.7        ad 	n1 = (stride - cnt) >> 2;
    562  1.12        pk 
    563   1.4        ad 	while (num--) {
    564   1.4        ad 		for (cnt = n9; cnt; cnt--) {
    565  1.20  christos 			dp[0] = xstamp[0];
    566  1.20  christos 			dp[1] = xstamp[1];
    567  1.20  christos 			dp[2] = xstamp[2];
    568  1.20  christos 			dp[3] = xstamp[0];
    569  1.20  christos 			dp[4] = xstamp[1];
    570  1.20  christos 			dp[5] = xstamp[2];
    571  1.20  christos 			dp[6] = xstamp[0];
    572  1.20  christos 			dp[7] = xstamp[1];
    573  1.20  christos 			dp[8] = xstamp[2];
    574   1.4        ad 			dp += 9;
    575   1.4        ad 		}
    576   1.1        ad 
    577   1.4        ad 		for (cnt = n3; cnt; cnt--) {
    578  1.20  christos 			dp[0] = xstamp[0];
    579  1.20  christos 			dp[1] = xstamp[1];
    580  1.20  christos 			dp[2] = xstamp[2];
    581   1.4        ad 			dp += 3;
    582   1.4        ad 		}
    583  1.12        pk 
    584   1.4        ad 		for (cnt = 0; cnt < n1; cnt++)
    585  1.20  christos 			*dp++ = xstamp[cnt];
    586  1.12        pk 
    587   1.8        ad 		DELTA(dp, delta, int32_t *);
    588   1.4        ad 	}
    589   1.4        ad }
    590   1.4        ad 
    591   1.4        ad /*
    592   1.4        ad  * Erase columns.
    593   1.4        ad  */
    594   1.4        ad static void
    595  1.27       dsl rasops24_erasecols(void *cookie, int row, int col, int num, long attr)
    596   1.4        ad {
    597  1.20  christos 	int n12, n4, height, cnt, slop, clr, xstamp[3];
    598   1.4        ad 	struct rasops_info *ri;
    599   1.4        ad 	int32_t *dp, *rp;
    600   1.4        ad 	u_char *dbp;
    601   1.4        ad 
    602  1.12        pk 	/*
    603   1.4        ad 	 * If the color is gray, we can cheat and use the generic routines
    604   1.4        ad 	 * (which are faster, hopefully) since the r,g,b values are the same.
    605   1.4        ad 	 */
    606   1.9        ad 	if ((attr & 4) != 0) {
    607   1.4        ad 		rasops_erasecols(cookie, row, col, num, attr);
    608   1.4        ad 		return;
    609   1.4        ad 	}
    610  1.12        pk 
    611   1.4        ad 	ri = (struct rasops_info *)cookie;
    612   1.4        ad 
    613  1.12        pk #ifdef RASOPS_CLIPPING
    614  1.12        pk 	/* Catches 'row < 0' case too */
    615   1.4        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    616   1.4        ad 		return;
    617   1.4        ad 
    618   1.4        ad 	if (col < 0) {
    619   1.4        ad 		num += col;
    620   1.4        ad 		col = 0;
    621   1.4        ad 	}
    622   1.4        ad 
    623   1.4        ad 	if ((col + num) > ri->ri_cols)
    624   1.4        ad 		num = ri->ri_cols - col;
    625  1.12        pk 
    626   1.4        ad 	if (num <= 0)
    627   1.4        ad 		return;
    628   1.4        ad #endif
    629  1.12        pk 
    630   1.4        ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    631   1.4        ad 	num *= ri->ri_font->fontwidth;
    632   1.4        ad 	height = ri->ri_font->fontheight;
    633   1.4        ad 
    634  1.12        pk 	clr = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xffffff;
    635  1.20  christos 	xstamp[0] = (clr <<  8) | (clr >> 16);
    636  1.20  christos 	xstamp[1] = (clr << 16) | (clr >>  8);
    637  1.20  christos 	xstamp[2] = (clr << 24) | clr;
    638   1.4        ad 
    639   1.4        ad #if BYTE_ORDER == LITTLE_ENDIAN
    640   1.7        ad 	if ((ri->ri_flg & RI_BSWAP) == 0) {
    641   1.4        ad #else
    642   1.7        ad 	if ((ri->ri_flg & RI_BSWAP) != 0) {
    643   1.4        ad #endif
    644  1.20  christos 		xstamp[0] = bswap32(xstamp[0]);
    645  1.20  christos 		xstamp[1] = bswap32(xstamp[1]);
    646  1.20  christos 		xstamp[2] = bswap32(xstamp[2]);
    647   1.4        ad 	}
    648  1.12        pk 
    649  1.12        pk 	/*
    650   1.4        ad 	 * The current byte offset mod 4 tells us the number of 24-bit pels
    651   1.4        ad 	 * we need to write for alignment to 32-bits. Once we're aligned on
    652   1.4        ad 	 * a 32-bit boundary, we're also aligned on a 4 pixel boundary, so
    653   1.4        ad 	 * the stamp does not need to be rotated. The following shows the
    654   1.9        ad 	 * layout of 4 pels in a 3 word region and illustrates this:
    655   1.4        ad 	 *
    656   1.4        ad 	 *	aaab bbcc cddd
    657   1.4        ad 	 */
    658  1.17    petrov 	slop = (int)(long)rp & 3;	num -= slop;
    659   1.4        ad 	n12 = num / 12;		num -= (n12 << 3) + (n12 << 2);
    660   1.4        ad 	n4 = num >> 2;		num &= 3;
    661  1.12        pk 
    662   1.4        ad 	while (height--) {
    663   1.4        ad 		dbp = (u_char *)rp;
    664   1.4        ad 		DELTA(rp, ri->ri_stride, int32_t *);
    665   1.4        ad 
    666   1.4        ad 		/* Align to 4 bytes */
    667   1.7        ad 		/* XXX handle with masks, bring under control of RI_BSWAP */
    668   1.4        ad 		for (cnt = slop; cnt; cnt--) {
    669   1.4        ad 			*dbp++ = (clr >> 16);
    670   1.4        ad 			*dbp++ = (clr >> 8);
    671  1.12        pk 			*dbp++ = clr;
    672  1.12        pk 		}
    673   1.4        ad 
    674   1.4        ad 		dp = (int32_t *)dbp;
    675  1.12        pk 
    676   1.4        ad 		/* 12 pels per loop */
    677   1.4        ad 		for (cnt = n12; cnt; cnt--) {
    678  1.20  christos 			dp[0] = xstamp[0];
    679  1.20  christos 			dp[1] = xstamp[1];
    680  1.20  christos 			dp[2] = xstamp[2];
    681  1.20  christos 			dp[3] = xstamp[0];
    682  1.20  christos 			dp[4] = xstamp[1];
    683  1.20  christos 			dp[5] = xstamp[2];
    684  1.20  christos 			dp[6] = xstamp[0];
    685  1.20  christos 			dp[7] = xstamp[1];
    686  1.20  christos 			dp[8] = xstamp[2];
    687   1.4        ad 			dp += 9;
    688   1.1        ad 		}
    689   1.1        ad 
    690   1.4        ad 		/* 4 pels per loop */
    691   1.4        ad 		for (cnt = n4; cnt; cnt--) {
    692  1.20  christos 			dp[0] = xstamp[0];
    693  1.20  christos 			dp[1] = xstamp[1];
    694  1.20  christos 			dp[2] = xstamp[2];
    695   1.4        ad 			dp += 3;
    696   1.4        ad 		}
    697  1.12        pk 
    698   1.4        ad 		/* Trailing slop */
    699   1.7        ad 		/* XXX handle with masks, bring under control of RI_BSWAP */
    700   1.4        ad 		dbp = (u_char *)dp;
    701   1.4        ad 		for (cnt = num; cnt; cnt--) {
    702   1.4        ad 			*dbp++ = (clr >> 16);
    703   1.4        ad 			*dbp++ = (clr >> 8);
    704  1.12        pk 			*dbp++ = clr;
    705  1.12        pk 		}
    706   1.1        ad 	}
    707   1.1        ad }
    708