Home | History | Annotate | Line # | Download | only in rasops
rasops24.c revision 1.27.4.1
      1  1.27.4.1     rmind /* 	$NetBSD: rasops24.c,v 1.27.4.1 2010/05/30 05:17:41 rmind 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.4.1     rmind __KERNEL_RCSID(0, "$NetBSD: rasops24.c,v 1.27.4.1 2010/05/30 05:17:41 rmind 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.27.4.1     rmind 	struct rasops_info *ri = (struct rasops_info *)cookie;
    124  1.27.4.1     rmind 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    125       1.4        ad 	u_char *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.27.4.1     rmind 	height = font->fontheight;
    138  1.27.4.1     rmind 	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.12        pk 		u_char 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.27.4.1     rmind 		uc -= font->firstchar;
    157  1.27.4.1     rmind 		fr = (u_char *)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.27.4.1     rmind 			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.9        ad 	if ((attr & 1) != 0) {
    182      1.12        pk 		u_char 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.27.4.1     rmind 	struct rasops_info *ri = (struct rasops_info *)cookie;
    243  1.27.4.1     rmind 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    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.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.4        ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    272  1.27.4.1     rmind 	height = font->fontheight;
    273      1.12        pk 
    274       1.4        ad 	if (uc == (u_int)-1) {
    275      1.12        pk 		int32_t c = stamp[0];
    276       1.4        ad 		while (height--) {
    277      1.12        pk 			rp[0] = rp[1] = rp[2] = rp[3] = rp[4] = rp[5] = c;
    278       1.4        ad 			DELTA(rp, ri->ri_stride, int32_t *);
    279      1.12        pk 		}
    280       1.4        ad 	} else {
    281  1.27.4.1     rmind 		uc -= font->firstchar;
    282  1.27.4.1     rmind 		fr = (u_char *)font->data + uc*ri->ri_fontscale;
    283  1.27.4.1     rmind 		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.12        pk 			DELTA(rp, ri->ri_stride, int32_t *);
    298       1.1        ad 		}
    299      1.12        pk 	}
    300       1.4        ad 
    301       1.4        ad 	/* Do underline */
    302       1.9        ad 	if ((attr & 1) != 0) {
    303      1.12        pk 		int32_t c = STAMP_READ(52);
    304      1.12        pk 
    305       1.4        ad 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    306      1.12        pk 		rp[0] = rp[1] = rp[2] = rp[3] = rp[4] = rp[5] = c;
    307      1.12        pk 	}
    308      1.12        pk 
    309       1.4        ad 	stamp_mutex--;
    310       1.1        ad }
    311       1.1        ad 
    312       1.1        ad /*
    313       1.4        ad  * Put a single character. This is for 12-pixel wide fonts.
    314       1.1        ad  */
    315       1.1        ad static void
    316      1.27       dsl rasops24_putchar12(void *cookie, int row, int col, u_int uc, long attr)
    317       1.1        ad {
    318  1.27.4.1     rmind 	struct rasops_info *ri = (struct rasops_info *)cookie;
    319  1.27.4.1     rmind 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    320       1.4        ad 	int height, so, fs;
    321       1.4        ad 	int32_t *rp;
    322       1.4        ad 	u_char *fr;
    323      1.12        pk 
    324       1.4        ad 	/* Can't risk remaking the stamp if it's already in use */
    325       1.4        ad 	if (stamp_mutex++) {
    326       1.4        ad 		stamp_mutex--;
    327       1.4        ad 		rasops24_putchar(cookie, row, col, uc, attr);
    328       1.1        ad 		return;
    329       1.1        ad 	}
    330       1.4        ad 
    331      1.12        pk #ifdef RASOPS_CLIPPING
    332       1.4        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    333       1.4        ad 		stamp_mutex--;
    334       1.1        ad 		return;
    335       1.4        ad 	}
    336       1.1        ad 
    337       1.4        ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    338       1.4        ad 		stamp_mutex--;
    339       1.1        ad 		return;
    340       1.4        ad 	}
    341       1.1        ad #endif
    342       1.4        ad 
    343       1.4        ad 	/* Recompute stamp? */
    344       1.4        ad 	if (attr != stamp_attr)
    345       1.4        ad 		rasops24_makestamp(ri, attr);
    346      1.12        pk 
    347       1.4        ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    348  1.27.4.1     rmind 	height = font->fontheight;
    349       1.1        ad 
    350       1.4        ad 	if (uc == (u_int)-1) {
    351      1.12        pk 		int32_t c = stamp[0];
    352       1.4        ad 		while (height--) {
    353      1.19     perry 			rp[0] = rp[1] = rp[2] = rp[3] =
    354      1.12        pk 			rp[4] = rp[5] = rp[6] = rp[7] = rp[8] = c;
    355      1.12        pk 			DELTA(rp, ri->ri_stride, int32_t *);
    356      1.12        pk 		}
    357       1.4        ad 	} else {
    358  1.27.4.1     rmind 		uc -= font->firstchar;
    359  1.27.4.1     rmind 		fr = (u_char *)font->data + uc*ri->ri_fontscale;
    360  1.27.4.1     rmind 		fs = font->stride;
    361      1.12        pk 
    362       1.4        ad 		while (height--) {
    363       1.4        ad 			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
    364       1.4        ad 			rp[0] = STAMP_READ(so);
    365       1.4        ad 			rp[1] = STAMP_READ(so + 4);
    366       1.4        ad 			rp[2] = STAMP_READ(so + 8);
    367      1.12        pk 
    368       1.4        ad 			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
    369       1.4        ad 			rp[3] = STAMP_READ(so);
    370       1.4        ad 			rp[4] = STAMP_READ(so + 4);
    371       1.4        ad 			rp[5] = STAMP_READ(so + 8);
    372       1.4        ad 
    373       1.4        ad 			so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
    374       1.4        ad 			rp[6] = STAMP_READ(so);
    375       1.4        ad 			rp[7] = STAMP_READ(so + 4);
    376       1.4        ad 			rp[8] = STAMP_READ(so + 8);
    377       1.1        ad 
    378       1.4        ad 			fr += fs;
    379      1.12        pk 			DELTA(rp, ri->ri_stride, int32_t *);
    380       1.1        ad 		}
    381      1.12        pk 	}
    382       1.4        ad 
    383       1.4        ad 	/* Do underline */
    384       1.9        ad 	if ((attr & 1) != 0) {
    385      1.12        pk 		int32_t c = STAMP_READ(52);
    386      1.12        pk 
    387       1.4        ad 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    388      1.12        pk 		rp[0] = rp[1] = rp[2] = rp[3] =
    389      1.12        pk 		rp[4] = rp[5] = rp[6] = rp[7] = rp[8] = c;
    390      1.12        pk 	}
    391      1.12        pk 
    392       1.4        ad 	stamp_mutex--;
    393       1.1        ad }
    394       1.1        ad 
    395       1.1        ad /*
    396       1.4        ad  * Put a single character. This is for 16-pixel wide fonts.
    397       1.1        ad  */
    398       1.1        ad static void
    399      1.27       dsl rasops24_putchar16(void *cookie, int row, int col, u_int uc, long attr)
    400       1.1        ad {
    401  1.27.4.1     rmind 	struct rasops_info *ri = (struct rasops_info *)cookie;
    402  1.27.4.1     rmind 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    403       1.4        ad 	int height, so, fs;
    404       1.4        ad 	int32_t *rp;
    405       1.4        ad 	u_char *fr;
    406      1.12        pk 
    407       1.4        ad 	/* Can't risk remaking the stamp if it's already in use */
    408       1.4        ad 	if (stamp_mutex++) {
    409       1.4        ad 		stamp_mutex--;
    410       1.4        ad 		rasops24_putchar(cookie, row, col, uc, attr);
    411       1.4        ad 		return;
    412       1.4        ad 	}
    413       1.4        ad 
    414      1.12        pk #ifdef RASOPS_CLIPPING
    415       1.4        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    416       1.4        ad 		stamp_mutex--;
    417       1.4        ad 		return;
    418       1.4        ad 	}
    419       1.4        ad 
    420       1.4        ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    421       1.4        ad 		stamp_mutex--;
    422       1.4        ad 		return;
    423       1.4        ad 	}
    424       1.4        ad #endif
    425       1.4        ad 
    426       1.4        ad 	/* Recompute stamp? */
    427       1.5        ad 	if (attr != stamp_attr)
    428       1.4        ad 		rasops24_makestamp(ri, attr);
    429       1.5        ad 
    430       1.4        ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    431  1.27.4.1     rmind 	height = font->fontheight;
    432      1.12        pk 
    433       1.4        ad 	if (uc == (u_int)-1) {
    434      1.12        pk 		int32_t c = stamp[0];
    435       1.4        ad 		while (height--) {
    436      1.19     perry 			rp[0] = rp[1] = rp[2] = rp[3] =
    437      1.19     perry 			rp[4] = rp[5] = rp[6] = rp[7] =
    438      1.12        pk 			rp[8] = rp[9] = rp[10] = rp[11] = c;
    439      1.12        pk 			DELTA(rp, ri->ri_stride, int32_t *);
    440      1.12        pk 		}
    441       1.4        ad 	} else {
    442  1.27.4.1     rmind 		uc -= font->firstchar;
    443  1.27.4.1     rmind 		fr = (u_char *)font->data + uc*ri->ri_fontscale;
    444  1.27.4.1     rmind 		fs = font->stride;
    445      1.12        pk 
    446       1.4        ad 		while (height--) {
    447       1.4        ad 			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
    448       1.4        ad 			rp[0] = STAMP_READ(so);
    449       1.4        ad 			rp[1] = STAMP_READ(so + 4);
    450       1.4        ad 			rp[2] = STAMP_READ(so + 8);
    451      1.12        pk 
    452       1.4        ad 			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
    453       1.4        ad 			rp[3] = STAMP_READ(so);
    454       1.4        ad 			rp[4] = STAMP_READ(so + 4);
    455       1.4        ad 			rp[5] = STAMP_READ(so + 8);
    456       1.4        ad 
    457       1.4        ad 			so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
    458       1.4        ad 			rp[6] = STAMP_READ(so);
    459       1.4        ad 			rp[7] = STAMP_READ(so + 4);
    460       1.4        ad 			rp[8] = STAMP_READ(so + 8);
    461      1.12        pk 
    462       1.4        ad 			so = STAMP_SHIFT(fr[1], 0) & STAMP_MASK;
    463       1.4        ad 			rp[9] = STAMP_READ(so);
    464       1.4        ad 			rp[10] = STAMP_READ(so + 4);
    465       1.4        ad 			rp[11] = STAMP_READ(so + 8);
    466       1.4        ad 
    467      1.12        pk 			DELTA(rp, ri->ri_stride, int32_t *);
    468       1.4        ad 			fr += fs;
    469       1.4        ad 		}
    470      1.12        pk 	}
    471       1.1        ad 
    472       1.4        ad 	/* Do underline */
    473       1.9        ad 	if ((attr & 1) != 0) {
    474      1.12        pk 		int32_t c = STAMP_READ(52);
    475      1.12        pk 
    476       1.4        ad 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    477      1.19     perry 		rp[0] = rp[1] = rp[2] = rp[3] =
    478      1.19     perry 		rp[4] = rp[5] = rp[6] = rp[7] =
    479      1.12        pk 		rp[8] = rp[9] = rp[10] = rp[11] = c;
    480      1.12        pk 	}
    481      1.12        pk 
    482       1.4        ad 	stamp_mutex--;
    483       1.1        ad }
    484      1.11        ad #endif	/* !RASOPS_SMALL */
    485       1.1        ad 
    486       1.1        ad /*
    487       1.4        ad  * Erase rows. This is nice and easy due to alignment.
    488       1.1        ad  */
    489       1.1        ad static void
    490      1.27       dsl rasops24_eraserows(void *cookie, int row, int num, long attr)
    491       1.1        ad {
    492       1.8        ad 	int n9, n3, n1, cnt, stride, delta;
    493      1.20  christos 	u_int32_t *dp, clr, xstamp[3];
    494       1.1        ad 	struct rasops_info *ri;
    495      1.12        pk 
    496      1.12        pk 	/*
    497       1.4        ad 	 * If the color is gray, we can cheat and use the generic routines
    498       1.4        ad 	 * (which are faster, hopefully) since the r,g,b values are the same.
    499       1.4        ad 	 */
    500       1.9        ad 	if ((attr & 4) != 0) {
    501       1.4        ad 		rasops_eraserows(cookie, row, num, attr);
    502       1.4        ad 		return;
    503       1.4        ad 	}
    504       1.4        ad 
    505       1.1        ad 	ri = (struct rasops_info *)cookie;
    506       1.1        ad 
    507       1.1        ad #ifdef RASOPS_CLIPPING
    508       1.1        ad 	if (row < 0) {
    509       1.1        ad 		num += row;
    510       1.1        ad 		row = 0;
    511       1.1        ad 	}
    512       1.1        ad 
    513       1.1        ad 	if ((row + num) > ri->ri_rows)
    514       1.1        ad 		num = ri->ri_rows - row;
    515      1.12        pk 
    516       1.1        ad 	if (num <= 0)
    517       1.1        ad 		return;
    518       1.1        ad #endif
    519      1.12        pk 
    520      1.12        pk 	clr = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xffffff;
    521      1.20  christos 	xstamp[0] = (clr <<  8) | (clr >> 16);
    522      1.20  christos 	xstamp[1] = (clr << 16) | (clr >>  8);
    523      1.20  christos 	xstamp[2] = (clr << 24) | clr;
    524       1.4        ad 
    525       1.4        ad #if BYTE_ORDER == LITTLE_ENDIAN
    526       1.7        ad 	if ((ri->ri_flg & RI_BSWAP) == 0) {
    527       1.4        ad #else
    528       1.7        ad 	if ((ri->ri_flg & RI_BSWAP) != 0) {
    529       1.4        ad #endif
    530      1.20  christos 		xstamp[0] = bswap32(xstamp[0]);
    531      1.20  christos 		xstamp[1] = bswap32(xstamp[1]);
    532      1.20  christos 		xstamp[2] = bswap32(xstamp[2]);
    533       1.4        ad 	}
    534       1.4        ad 
    535      1.12        pk 	/*
    536       1.7        ad 	 * XXX the wsdisplay_emulops interface seems a little deficient in
    537      1.12        pk 	 * that there is no way to clear the *entire* screen. We provide a
    538      1.12        pk 	 * workaround here: if the entire console area is being cleared, and
    539       1.7        ad 	 * the RI_FULLCLEAR flag is set, clear the entire display.
    540      1.12        pk 	 */
    541       1.7        ad 	if (num == ri->ri_rows && (ri->ri_flg & RI_FULLCLEAR) != 0) {
    542       1.7        ad 		stride = ri->ri_stride;
    543       1.7        ad 		num = ri->ri_height;
    544       1.8        ad 		dp = (int32_t *)ri->ri_origbits;
    545       1.8        ad 		delta = 0;
    546       1.7        ad 	} else {
    547       1.7        ad 		stride = ri->ri_emustride;
    548       1.7        ad 		num *= ri->ri_font->fontheight;
    549       1.8        ad 		dp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale);
    550       1.8        ad 		delta = ri->ri_delta;
    551       1.7        ad 	}
    552       1.7        ad 
    553       1.7        ad 	n9 = stride / 36;
    554       1.1        ad 	cnt = (n9 << 5) + (n9 << 2); /* (32*n9) + (4*n9) */
    555       1.7        ad 	n3 = (stride - cnt) / 12;
    556       1.1        ad 	cnt += (n3 << 3) + (n3 << 2); /* (8*n3) + (4*n3) */
    557       1.7        ad 	n1 = (stride - cnt) >> 2;
    558      1.12        pk 
    559       1.4        ad 	while (num--) {
    560       1.4        ad 		for (cnt = n9; cnt; cnt--) {
    561      1.20  christos 			dp[0] = xstamp[0];
    562      1.20  christos 			dp[1] = xstamp[1];
    563      1.20  christos 			dp[2] = xstamp[2];
    564      1.20  christos 			dp[3] = xstamp[0];
    565      1.20  christos 			dp[4] = xstamp[1];
    566      1.20  christos 			dp[5] = xstamp[2];
    567      1.20  christos 			dp[6] = xstamp[0];
    568      1.20  christos 			dp[7] = xstamp[1];
    569      1.20  christos 			dp[8] = xstamp[2];
    570       1.4        ad 			dp += 9;
    571       1.4        ad 		}
    572       1.1        ad 
    573       1.4        ad 		for (cnt = n3; cnt; cnt--) {
    574      1.20  christos 			dp[0] = xstamp[0];
    575      1.20  christos 			dp[1] = xstamp[1];
    576      1.20  christos 			dp[2] = xstamp[2];
    577       1.4        ad 			dp += 3;
    578       1.4        ad 		}
    579      1.12        pk 
    580       1.4        ad 		for (cnt = 0; cnt < n1; cnt++)
    581      1.20  christos 			*dp++ = xstamp[cnt];
    582      1.12        pk 
    583       1.8        ad 		DELTA(dp, delta, int32_t *);
    584       1.4        ad 	}
    585       1.4        ad }
    586       1.4        ad 
    587       1.4        ad /*
    588       1.4        ad  * Erase columns.
    589       1.4        ad  */
    590       1.4        ad static void
    591      1.27       dsl rasops24_erasecols(void *cookie, int row, int col, int num, long attr)
    592       1.4        ad {
    593      1.20  christos 	int n12, n4, height, cnt, slop, clr, xstamp[3];
    594       1.4        ad 	struct rasops_info *ri;
    595       1.4        ad 	int32_t *dp, *rp;
    596       1.4        ad 	u_char *dbp;
    597       1.4        ad 
    598      1.12        pk 	/*
    599       1.4        ad 	 * If the color is gray, we can cheat and use the generic routines
    600       1.4        ad 	 * (which are faster, hopefully) since the r,g,b values are the same.
    601       1.4        ad 	 */
    602       1.9        ad 	if ((attr & 4) != 0) {
    603       1.4        ad 		rasops_erasecols(cookie, row, col, num, attr);
    604       1.4        ad 		return;
    605       1.4        ad 	}
    606      1.12        pk 
    607       1.4        ad 	ri = (struct rasops_info *)cookie;
    608       1.4        ad 
    609      1.12        pk #ifdef RASOPS_CLIPPING
    610      1.12        pk 	/* Catches 'row < 0' case too */
    611       1.4        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    612       1.4        ad 		return;
    613       1.4        ad 
    614       1.4        ad 	if (col < 0) {
    615       1.4        ad 		num += col;
    616       1.4        ad 		col = 0;
    617       1.4        ad 	}
    618       1.4        ad 
    619       1.4        ad 	if ((col + num) > ri->ri_cols)
    620       1.4        ad 		num = ri->ri_cols - col;
    621      1.12        pk 
    622       1.4        ad 	if (num <= 0)
    623       1.4        ad 		return;
    624       1.4        ad #endif
    625      1.12        pk 
    626       1.4        ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    627       1.4        ad 	num *= ri->ri_font->fontwidth;
    628       1.4        ad 	height = ri->ri_font->fontheight;
    629       1.4        ad 
    630      1.12        pk 	clr = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xffffff;
    631      1.20  christos 	xstamp[0] = (clr <<  8) | (clr >> 16);
    632      1.20  christos 	xstamp[1] = (clr << 16) | (clr >>  8);
    633      1.20  christos 	xstamp[2] = (clr << 24) | clr;
    634       1.4        ad 
    635       1.4        ad #if BYTE_ORDER == LITTLE_ENDIAN
    636       1.7        ad 	if ((ri->ri_flg & RI_BSWAP) == 0) {
    637       1.4        ad #else
    638       1.7        ad 	if ((ri->ri_flg & RI_BSWAP) != 0) {
    639       1.4        ad #endif
    640      1.20  christos 		xstamp[0] = bswap32(xstamp[0]);
    641      1.20  christos 		xstamp[1] = bswap32(xstamp[1]);
    642      1.20  christos 		xstamp[2] = bswap32(xstamp[2]);
    643       1.4        ad 	}
    644      1.12        pk 
    645      1.12        pk 	/*
    646       1.4        ad 	 * The current byte offset mod 4 tells us the number of 24-bit pels
    647       1.4        ad 	 * we need to write for alignment to 32-bits. Once we're aligned on
    648       1.4        ad 	 * a 32-bit boundary, we're also aligned on a 4 pixel boundary, so
    649       1.4        ad 	 * the stamp does not need to be rotated. The following shows the
    650       1.9        ad 	 * layout of 4 pels in a 3 word region and illustrates this:
    651       1.4        ad 	 *
    652       1.4        ad 	 *	aaab bbcc cddd
    653       1.4        ad 	 */
    654      1.17    petrov 	slop = (int)(long)rp & 3;	num -= slop;
    655       1.4        ad 	n12 = num / 12;		num -= (n12 << 3) + (n12 << 2);
    656       1.4        ad 	n4 = num >> 2;		num &= 3;
    657      1.12        pk 
    658       1.4        ad 	while (height--) {
    659       1.4        ad 		dbp = (u_char *)rp;
    660       1.4        ad 		DELTA(rp, ri->ri_stride, int32_t *);
    661       1.4        ad 
    662       1.4        ad 		/* Align to 4 bytes */
    663       1.7        ad 		/* XXX handle with masks, bring under control of RI_BSWAP */
    664       1.4        ad 		for (cnt = slop; cnt; cnt--) {
    665       1.4        ad 			*dbp++ = (clr >> 16);
    666       1.4        ad 			*dbp++ = (clr >> 8);
    667      1.12        pk 			*dbp++ = clr;
    668      1.12        pk 		}
    669       1.4        ad 
    670       1.4        ad 		dp = (int32_t *)dbp;
    671      1.12        pk 
    672       1.4        ad 		/* 12 pels per loop */
    673       1.4        ad 		for (cnt = n12; cnt; cnt--) {
    674      1.20  christos 			dp[0] = xstamp[0];
    675      1.20  christos 			dp[1] = xstamp[1];
    676      1.20  christos 			dp[2] = xstamp[2];
    677      1.20  christos 			dp[3] = xstamp[0];
    678      1.20  christos 			dp[4] = xstamp[1];
    679      1.20  christos 			dp[5] = xstamp[2];
    680      1.20  christos 			dp[6] = xstamp[0];
    681      1.20  christos 			dp[7] = xstamp[1];
    682      1.20  christos 			dp[8] = xstamp[2];
    683       1.4        ad 			dp += 9;
    684       1.1        ad 		}
    685       1.1        ad 
    686       1.4        ad 		/* 4 pels per loop */
    687       1.4        ad 		for (cnt = n4; cnt; cnt--) {
    688      1.20  christos 			dp[0] = xstamp[0];
    689      1.20  christos 			dp[1] = xstamp[1];
    690      1.20  christos 			dp[2] = xstamp[2];
    691       1.4        ad 			dp += 3;
    692       1.4        ad 		}
    693      1.12        pk 
    694       1.4        ad 		/* Trailing slop */
    695       1.7        ad 		/* XXX handle with masks, bring under control of RI_BSWAP */
    696       1.4        ad 		dbp = (u_char *)dp;
    697       1.4        ad 		for (cnt = num; cnt; cnt--) {
    698       1.4        ad 			*dbp++ = (clr >> 16);
    699       1.4        ad 			*dbp++ = (clr >> 8);
    700      1.12        pk 			*dbp++ = clr;
    701      1.12        pk 		}
    702       1.1        ad 	}
    703       1.1        ad }
    704