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