Home | History | Annotate | Line # | Download | only in rasops
rasops15.c revision 1.1
      1  1.1  ad /*	$NetBSD: rasops15.c,v 1.1 1999/04/13 00:18:00 ad Exp $ */
      2  1.1  ad 
      3  1.1  ad /*-
      4  1.1  ad  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  1.1  ad  * All rights reserved.
      6  1.1  ad  *
      7  1.1  ad  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  ad  * by Andy Doran <ad (at) NetBSD.org>.
      9  1.1  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  * 3. All advertising materials mentioning features or use of this software
     19  1.1  ad  *    must display the following acknowledgement:
     20  1.1  ad  *        This product includes software developed by the NetBSD
     21  1.1  ad  *        Foundation, Inc. and its contributors.
     22  1.1  ad  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  ad  *    contributors may be used to endorse or promote products derived
     24  1.1  ad  *    from this software without specific prior written permission.
     25  1.1  ad  *
     26  1.1  ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  ad  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  ad  */
     38  1.1  ad #include "opt_rasops.h"
     39  1.1  ad #ifdef RASOPS15
     40  1.1  ad 
     41  1.1  ad #include <sys/cdefs.h>
     42  1.1  ad __KERNEL_RCSID(0, "$NetBSD: rasops15.c,v 1.1 1999/04/13 00:18:00 ad Exp $");
     43  1.1  ad 
     44  1.1  ad #include <sys/types.h>
     45  1.1  ad #include <sys/param.h>
     46  1.1  ad #include <sys/systm.h>
     47  1.1  ad #include <sys/time.h>
     48  1.1  ad 
     49  1.1  ad #include <dev/wscons/wsdisplayvar.h>
     50  1.1  ad #include <dev/wscons/wsconsio.h>
     51  1.1  ad #include <dev/rasops/rasops.h>
     52  1.1  ad 
     53  1.1  ad static void 	rasops15_putchar __P((void *, int, int, u_int, long attr));
     54  1.1  ad static void 	rasops15_putchar8 __P((void *, int, int, u_int, long attr));
     55  1.1  ad static void 	rasops15_putchar12 __P((void *, int, int, u_int, long attr));
     56  1.1  ad static void 	rasops15_putchar16 __P((void *, int, int, u_int, long attr));
     57  1.1  ad static void 	rasops15_erasecols __P((void *, int, int, int, long));
     58  1.1  ad static void 	rasops15_eraserows __P((void *, int, int, long));
     59  1.1  ad static void	rasops15_makestamp __P((struct rasops_info *, long));
     60  1.1  ad static int32_t	rasops15_bg_color __P((struct rasops_info *, long));
     61  1.1  ad static void	rasops15_do_cursor __P((struct rasops_info *));
     62  1.1  ad 
     63  1.1  ad void	rasops15_init __P((struct rasops_info *ri));
     64  1.1  ad 
     65  1.1  ad /*
     66  1.1  ad  * (2x2)x1 stamp for optimized character blitting
     67  1.1  ad  */
     68  1.1  ad static int32_t	stamp[32];
     69  1.1  ad static long	stamp_attr;
     70  1.1  ad static int	stamp_mutex;	/* XXX see note in readme */
     71  1.1  ad 
     72  1.1  ad /*
     73  1.1  ad  * XXX this confuses the hell out of gcc2 (not egcs) which always insists
     74  1.1  ad  * that the shift count is negative.
     75  1.1  ad  *
     76  1.1  ad  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
     77  1.1  ad  * destination int32_t[0] = STAMP_READ(offset)
     78  1.1  ad  * destination int32_t[1] = STAMP_READ(offset + 4)
     79  1.1  ad  */
     80  1.1  ad #define STAMP_SHIFT(fb,n)	((n*4-3) >= 0 ? (fb)>>(n*4-3):(fb)<<-(n*4-3))
     81  1.1  ad #define STAMP_MASK		(15 << 3)
     82  1.1  ad #define STAMP_READ(o)		(*(int32_t *)((caddr_t)stamp + (o)))
     83  1.1  ad 
     84  1.1  ad 
     85  1.1  ad /*
     86  1.1  ad  * Initalize rasops_info struct for this colordepth.
     87  1.1  ad  */
     88  1.1  ad void
     89  1.1  ad rasops15_init(ri)
     90  1.1  ad 	struct rasops_info *ri;
     91  1.1  ad {
     92  1.1  ad 
     93  1.1  ad 	switch (ri->ri_font->fontwidth) {
     94  1.1  ad 	case 8:
     95  1.1  ad 		ri->ri_ops.putchar = rasops15_putchar8;
     96  1.1  ad 		break;
     97  1.1  ad 
     98  1.1  ad 	case 12:
     99  1.1  ad 		ri->ri_ops.putchar = rasops15_putchar12;
    100  1.1  ad 		break;
    101  1.1  ad 
    102  1.1  ad 	case 16:
    103  1.1  ad 		ri->ri_ops.putchar = rasops15_putchar16;
    104  1.1  ad 		break;
    105  1.1  ad 
    106  1.1  ad 	default:
    107  1.1  ad 		ri->ri_ops.putchar = rasops15_putchar;
    108  1.1  ad 		break;
    109  1.1  ad 	}
    110  1.1  ad 
    111  1.1  ad 	/* Select defaults for color masks if none selected */
    112  1.1  ad 	if (ri->ri_rnum == 0) {
    113  1.1  ad 		ri->ri_rnum = 5;
    114  1.1  ad 		ri->ri_rpos = 0;
    115  1.1  ad 		ri->ri_gnum = 5 + (ri->ri_depth == 16);
    116  1.1  ad 		ri->ri_gpos = 5;
    117  1.1  ad 		ri->ri_bnum = 5;
    118  1.1  ad 		ri->ri_bpos = 10 + (ri->ri_depth == 16);
    119  1.1  ad 	}
    120  1.1  ad 
    121  1.1  ad 	ri->ri_ops.erasecols = rasops15_erasecols;
    122  1.1  ad 	ri->ri_ops.eraserows = rasops15_eraserows;
    123  1.1  ad 	ri->ri_do_cursor = rasops15_do_cursor;
    124  1.1  ad 	rasops_init_devcmap(ri);
    125  1.1  ad }
    126  1.1  ad 
    127  1.1  ad 
    128  1.1  ad /*
    129  1.1  ad  * Get background color from attribute and copy across all 4 bytes
    130  1.1  ad  * in a int32_t.
    131  1.1  ad  */
    132  1.1  ad static __inline__ int32_t
    133  1.1  ad rasops15_bg_color(ri, attr)
    134  1.1  ad 	struct rasops_info *ri;
    135  1.1  ad 	long attr;
    136  1.1  ad {
    137  1.1  ad 	int32_t bg;
    138  1.1  ad 
    139  1.1  ad 	bg = ri->ri_devcmap[((u_int)attr >> 16) & 15];
    140  1.1  ad 	return bg | (bg << 16);
    141  1.1  ad }
    142  1.1  ad 
    143  1.1  ad 
    144  1.1  ad /*
    145  1.1  ad  * Actually turn the cursor on or off. This does the dirty work for
    146  1.1  ad  * rasops_cursor().
    147  1.1  ad  */
    148  1.1  ad static void
    149  1.1  ad rasops15_do_cursor(ri)
    150  1.1  ad 	struct rasops_info *ri;
    151  1.1  ad {
    152  1.1  ad 	u_char *rp, *dp;
    153  1.1  ad 	int full1, height, cnt, slop1, slop2, row, col;
    154  1.1  ad 	int32_t planemask;
    155  1.1  ad 
    156  1.1  ad 	row = ri->ri_crow;
    157  1.1  ad 	col = ri->ri_ccol;
    158  1.1  ad 
    159  1.1  ad 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    160  1.1  ad 	height = ri->ri_font->fontheight;
    161  1.1  ad 
    162  1.1  ad 	slop1 = (int)rp & 2;
    163  1.1  ad 	slop2 = (ri->ri_xscale - slop1) & 2;
    164  1.1  ad 	full1 = (ri->ri_xscale - slop1 - slop2) >> 2;
    165  1.1  ad 	planemask = ri->ri_devcmap[15] | (ri->ri_devcmap[15] << 16);
    166  1.1  ad 
    167  1.1  ad 	while (height--) {
    168  1.1  ad 		dp = rp;
    169  1.1  ad 		rp += ri->ri_stride;
    170  1.1  ad 
    171  1.1  ad 		if (slop1) {
    172  1.1  ad 			*(int16_t *)dp ^= (int16_t)planemask;
    173  1.1  ad 			dp += 2;
    174  1.1  ad 		}
    175  1.1  ad 
    176  1.1  ad 		for (cnt = full1; cnt; cnt--) {
    177  1.1  ad 			*(int32_t *)dp ^= planemask;
    178  1.1  ad 			dp += 4;
    179  1.1  ad 		}
    180  1.1  ad 
    181  1.1  ad 		if (slop2)
    182  1.1  ad 			*(int16_t *)dp ^= (int16_t)planemask;
    183  1.1  ad 	}
    184  1.1  ad }
    185  1.1  ad 
    186  1.1  ad 
    187  1.1  ad /*
    188  1.1  ad  * Erase columns.
    189  1.1  ad  */
    190  1.1  ad static void
    191  1.1  ad rasops15_erasecols(cookie, row, col, num, attr)
    192  1.1  ad 	void *cookie;
    193  1.1  ad 	int row, num;
    194  1.1  ad 	long attr;
    195  1.1  ad {
    196  1.1  ad 	int n8, clr, height, cnt, slop1, slop2;
    197  1.1  ad 	struct rasops_info *ri;
    198  1.1  ad 	int32_t *dp;
    199  1.1  ad 	u_char *rp;
    200  1.1  ad 
    201  1.1  ad 	ri = (struct rasops_info *)cookie;
    202  1.1  ad 
    203  1.1  ad #ifdef RASOPS_CLIPPING
    204  1.1  ad 	/* Catches 'row < 0' case too */
    205  1.1  ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    206  1.1  ad 		return;
    207  1.1  ad 
    208  1.1  ad 	if (col < 0) {
    209  1.1  ad 		num += col;
    210  1.1  ad 		col = 0;
    211  1.1  ad 	}
    212  1.1  ad 
    213  1.1  ad 	if ((col + num) > ri->ri_cols)
    214  1.1  ad 		num = ri->ri_cols - col;
    215  1.1  ad 
    216  1.1  ad 	if (num <= 0)
    217  1.1  ad 		return;
    218  1.1  ad #endif
    219  1.1  ad 
    220  1.1  ad 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    221  1.1  ad 	num *= ri->ri_xscale;
    222  1.1  ad 	clr = rasops15_bg_color(ri, attr);
    223  1.1  ad 	height = ri->ri_font->fontheight;
    224  1.1  ad 
    225  1.1  ad 	slop1 = (int)rp & 2;
    226  1.1  ad 	slop2 = (num - slop1) & 2;
    227  1.1  ad 	num = num - slop1 - slop2;
    228  1.1  ad 	n8 = num >> 5;
    229  1.1  ad 	num = (num >> 2) & 7;
    230  1.1  ad 
    231  1.1  ad 	while (height--) {
    232  1.1  ad 		dp = (u_int32_t *)rp;
    233  1.1  ad 		rp += ri->ri_stride;
    234  1.1  ad 
    235  1.1  ad 		/* Align span to 4 bytes */
    236  1.1  ad 		if (slop1) {
    237  1.1  ad 			*(int16_t *)dp = (int16_t)clr;
    238  1.1  ad 			DELTA(dp, 2, int32_t *);
    239  1.1  ad 		}
    240  1.1  ad 
    241  1.1  ad 		/* Write 32 bytes per loop */
    242  1.1  ad 		for (cnt = n8; cnt; cnt--) {
    243  1.1  ad 			dp[0] = clr;
    244  1.1  ad 			dp[1] = clr;
    245  1.1  ad 			dp[2] = clr;
    246  1.1  ad 			dp[3] = clr;
    247  1.1  ad 			dp[4] = clr;
    248  1.1  ad 			dp[5] = clr;
    249  1.1  ad 			dp[6] = clr;
    250  1.1  ad 			dp[7] = clr;
    251  1.1  ad 			dp += 8;
    252  1.1  ad 		}
    253  1.1  ad 
    254  1.1  ad 		/* Write 4 bytes per loop */
    255  1.1  ad 		for (cnt = num; cnt; cnt--)
    256  1.1  ad 			*dp++ = clr;
    257  1.1  ad 
    258  1.1  ad 		/* Write unaligned trailing slop */
    259  1.1  ad 		if (slop2)
    260  1.1  ad 			*(int16_t *)dp = (int16_t)clr;
    261  1.1  ad 	}
    262  1.1  ad }
    263  1.1  ad 
    264  1.1  ad 
    265  1.1  ad /*
    266  1.1  ad  * Paint a single character.
    267  1.1  ad  */
    268  1.1  ad static void
    269  1.1  ad rasops15_putchar(cookie, row, col, uc, attr)
    270  1.1  ad 	void *cookie;
    271  1.1  ad 	int row, col;
    272  1.1  ad 	u_int uc;
    273  1.1  ad 	long attr;
    274  1.1  ad {
    275  1.1  ad 	struct rasops_info *ri;
    276  1.1  ad 	int fb, width, height, cnt, clr[2];
    277  1.1  ad 	u_char *dp, *rp, *fr;
    278  1.1  ad 
    279  1.1  ad 	if (uc == (u_int)-1) {
    280  1.1  ad 		rasops15_erasecols(cookie, row, col, 1, attr);
    281  1.1  ad 		return;
    282  1.1  ad 	}
    283  1.1  ad 
    284  1.1  ad 	ri = (struct rasops_info *)cookie;
    285  1.1  ad 
    286  1.1  ad #ifdef RASOPS_CLIPPING
    287  1.1  ad 	/* Catches 'row < 0' case too */
    288  1.1  ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    289  1.1  ad 		return;
    290  1.1  ad 
    291  1.1  ad 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    292  1.1  ad 		return;
    293  1.1  ad #endif
    294  1.1  ad 
    295  1.1  ad 	uc -= ri->ri_font->firstchar;
    296  1.1  ad 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    297  1.1  ad 	fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    298  1.1  ad 
    299  1.1  ad 	height = ri->ri_font->fontheight;
    300  1.1  ad 	width = ri->ri_font->fontwidth;
    301  1.1  ad 
    302  1.1  ad 	clr[1] = ri->ri_devcmap[((u_int)attr >> 24) & 15];
    303  1.1  ad 	clr[0] = ri->ri_devcmap[((u_int)attr >> 16) & 15];
    304  1.1  ad 
    305  1.1  ad 	while (height--) {
    306  1.1  ad 		dp = rp;
    307  1.1  ad 		fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) | (fr[0] << 24);
    308  1.1  ad 		fr += ri->ri_font->stride;
    309  1.1  ad 		rp += ri->ri_stride;
    310  1.1  ad 
    311  1.1  ad 		for (cnt = width; cnt; cnt--) {
    312  1.1  ad 			*(int16_t *)dp = (int16_t)clr[(fb >> 31) & 1];
    313  1.1  ad 			fb <<= 1;
    314  1.1  ad 			dp += 2;
    315  1.1  ad 		}
    316  1.1  ad 	}
    317  1.1  ad }
    318  1.1  ad 
    319  1.1  ad 
    320  1.1  ad /*
    321  1.1  ad  * Recompute the (2x2)x1 blitting stamp.
    322  1.1  ad  */
    323  1.1  ad static void
    324  1.1  ad rasops15_makestamp(ri, attr)
    325  1.1  ad 	struct rasops_info *ri;
    326  1.1  ad 	long attr;
    327  1.1  ad {
    328  1.1  ad 	int32_t fg, bg;
    329  1.1  ad 	int i;
    330  1.1  ad 
    331  1.1  ad 	fg = ri->ri_devcmap[((u_int)attr >> 24) & 15];
    332  1.1  ad 	bg = ri->ri_devcmap[((u_int)attr >> 16) & 15];
    333  1.1  ad 	stamp_attr = attr;
    334  1.1  ad 
    335  1.1  ad 	for (i = 0; i < 16; i++) {
    336  1.1  ad #if BYTE_ORDER == LITTLE_ENDIAN
    337  1.1  ad 		stamp[i << 1] = (i & 8 ? fg : bg);
    338  1.1  ad 		stamp[i << 1] |= ((i & 4 ? fg : bg) << 16);
    339  1.1  ad 		stamp[(i << 1) + 1] = (i & 2 ? fg : bg);
    340  1.1  ad 		stamp[(i << 1) + 1] |= ((i & 1 ? fg : bg) << 16);
    341  1.1  ad #else
    342  1.1  ad 		stamp[i << 1] = (i & 1 ? fg : bg);
    343  1.1  ad 		stamp[i << 1] |= ((i & 2 ? fg : bg) << 16);
    344  1.1  ad 		stamp[(i << 1) + 1] = (i & 4 ? fg : bg);
    345  1.1  ad 		stamp[(i << 1) + 1] |= ((i & 8 ? fg : bg) << 16);
    346  1.1  ad #endif
    347  1.1  ad 	}
    348  1.1  ad }
    349  1.1  ad 
    350  1.1  ad 
    351  1.1  ad /*
    352  1.1  ad  * Paint a single character. This is for 8-pixel wide fonts.
    353  1.1  ad  */
    354  1.1  ad static void
    355  1.1  ad rasops15_putchar8(cookie, row, col, uc, attr)
    356  1.1  ad 	void *cookie;
    357  1.1  ad 	int row, col;
    358  1.1  ad 	u_int uc;
    359  1.1  ad 	long attr;
    360  1.1  ad {
    361  1.1  ad 	struct rasops_info *ri;
    362  1.1  ad 	int height, so, fs;
    363  1.1  ad 	int32_t *rp;
    364  1.1  ad 	u_char *fr;
    365  1.1  ad 
    366  1.1  ad 	/* Can't risk remaking the stamp if it's already in use */
    367  1.1  ad 	if (stamp_mutex++) {
    368  1.1  ad 		stamp_mutex--;
    369  1.1  ad 		rasops15_putchar(cookie, row, col, uc, attr);
    370  1.1  ad 		return;
    371  1.1  ad 	}
    372  1.1  ad 
    373  1.1  ad 	ri = (struct rasops_info *)cookie;
    374  1.1  ad 
    375  1.1  ad #ifdef RASOPS_CLIPPING
    376  1.1  ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    377  1.1  ad 		stamp_mutex--;
    378  1.1  ad 		return;
    379  1.1  ad 	}
    380  1.1  ad 
    381  1.1  ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    382  1.1  ad 		stamp_mutex--;
    383  1.1  ad 		return;
    384  1.1  ad 	}
    385  1.1  ad #endif
    386  1.1  ad 
    387  1.1  ad 	/* Recompute stamp? */
    388  1.1  ad 	if (attr != stamp_attr)
    389  1.1  ad 		rasops15_makestamp(ri, attr);
    390  1.1  ad 
    391  1.1  ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    392  1.1  ad 	height = ri->ri_font->fontheight;
    393  1.1  ad 
    394  1.1  ad 	if (uc == (u_int)-1) {
    395  1.1  ad 		while (height--) {
    396  1.1  ad 			rp[0] = stamp[0];
    397  1.1  ad 			rp[1] = stamp[0];
    398  1.1  ad 			rp[2] = stamp[0];
    399  1.1  ad 			rp[3] = stamp[0];
    400  1.1  ad 			DELTA(rp, ri->ri_stride, int32_t *);
    401  1.1  ad 		}
    402  1.1  ad 	} else {
    403  1.1  ad 		uc -= ri->ri_font->firstchar;
    404  1.1  ad 		fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
    405  1.1  ad 		fs = ri->ri_font->stride;
    406  1.1  ad 
    407  1.1  ad 		while (height--) {
    408  1.1  ad 			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
    409  1.1  ad 			rp[0] = STAMP_READ(so);
    410  1.1  ad 			rp[1] = STAMP_READ(so + 4);
    411  1.1  ad 
    412  1.1  ad 			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
    413  1.1  ad 			rp[2] = STAMP_READ(so);
    414  1.1  ad 			rp[3] = STAMP_READ(so + 4);
    415  1.1  ad 
    416  1.1  ad 			fr += fs;
    417  1.1  ad 			DELTA(rp, ri->ri_stride, int32_t *);
    418  1.1  ad 		}
    419  1.1  ad 	}
    420  1.1  ad 
    421  1.1  ad 	stamp_mutex--;
    422  1.1  ad }
    423  1.1  ad 
    424  1.1  ad 
    425  1.1  ad /*
    426  1.1  ad  * Paint a single character. This is for 12-pixel wide fonts.
    427  1.1  ad  */
    428  1.1  ad static void
    429  1.1  ad rasops15_putchar12(cookie, row, col, uc, attr)
    430  1.1  ad 	void *cookie;
    431  1.1  ad 	int row, col;
    432  1.1  ad 	u_int uc;
    433  1.1  ad 	long attr;
    434  1.1  ad {
    435  1.1  ad 	struct rasops_info *ri;
    436  1.1  ad 	int height, so, fs;
    437  1.1  ad 	int32_t *rp;
    438  1.1  ad 	u_char *fr;
    439  1.1  ad 
    440  1.1  ad 	/* Can't risk remaking the stamp if it's already in use */
    441  1.1  ad 	if (stamp_mutex++) {
    442  1.1  ad 		stamp_mutex--;
    443  1.1  ad 		rasops15_putchar(cookie, row, col, uc, attr);
    444  1.1  ad 		return;
    445  1.1  ad 	}
    446  1.1  ad 
    447  1.1  ad 	ri = (struct rasops_info *)cookie;
    448  1.1  ad 
    449  1.1  ad #ifdef RASOPS_CLIPPING
    450  1.1  ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    451  1.1  ad 		stamp_mutex--;
    452  1.1  ad 		return;
    453  1.1  ad 	}
    454  1.1  ad 
    455  1.1  ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    456  1.1  ad 		stamp_mutex--;
    457  1.1  ad 		return;
    458  1.1  ad 	}
    459  1.1  ad #endif
    460  1.1  ad 
    461  1.1  ad 	/* Recompute stamp? */
    462  1.1  ad 	if (attr != stamp_attr)
    463  1.1  ad 		rasops15_makestamp(ri, attr);
    464  1.1  ad 
    465  1.1  ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    466  1.1  ad 	height = ri->ri_font->fontheight;
    467  1.1  ad 
    468  1.1  ad 	if (uc == (u_int)-1) {
    469  1.1  ad 		while (height--) {
    470  1.1  ad 			rp[0] = stamp[0];
    471  1.1  ad 			rp[1] = stamp[0];
    472  1.1  ad 			rp[2] = stamp[0];
    473  1.1  ad 			rp[3] = stamp[0];
    474  1.1  ad 			rp[4] = stamp[0];
    475  1.1  ad 			rp[5] = stamp[0];
    476  1.1  ad 			DELTA(rp, ri->ri_stride, int32_t *);
    477  1.1  ad 		}
    478  1.1  ad 	} else {
    479  1.1  ad 		uc -= ri->ri_font->firstchar;
    480  1.1  ad 		fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
    481  1.1  ad 		fs = ri->ri_font->stride;
    482  1.1  ad 
    483  1.1  ad 		while (height--) {
    484  1.1  ad 			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
    485  1.1  ad 			rp[0] = STAMP_READ(so);
    486  1.1  ad 			rp[1] = STAMP_READ(so + 4);
    487  1.1  ad 
    488  1.1  ad 			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
    489  1.1  ad 			rp[2] = STAMP_READ(so);
    490  1.1  ad 			rp[3] = STAMP_READ(so + 4);
    491  1.1  ad 
    492  1.1  ad 			so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
    493  1.1  ad 			rp[4] = STAMP_READ(so);
    494  1.1  ad 			rp[5] = STAMP_READ(so + 4);
    495  1.1  ad 
    496  1.1  ad 			fr += fs;
    497  1.1  ad 			DELTA(rp, ri->ri_stride, int32_t *);
    498  1.1  ad 		}
    499  1.1  ad 	}
    500  1.1  ad 
    501  1.1  ad 	stamp_mutex--;
    502  1.1  ad }
    503  1.1  ad 
    504  1.1  ad 
    505  1.1  ad /*
    506  1.1  ad  * Paint a single character. This is for 16-pixel wide fonts.
    507  1.1  ad  */
    508  1.1  ad static void
    509  1.1  ad rasops15_putchar16(cookie, row, col, uc, attr)
    510  1.1  ad 	void *cookie;
    511  1.1  ad 	int row, col;
    512  1.1  ad 	u_int uc;
    513  1.1  ad 	long attr;
    514  1.1  ad {
    515  1.1  ad 	struct rasops_info *ri;
    516  1.1  ad 	int height, so, fs;
    517  1.1  ad 	int32_t *rp;
    518  1.1  ad 	u_char *fr;
    519  1.1  ad 
    520  1.1  ad 	/* Can't risk remaking the stamp if it's already in use */
    521  1.1  ad 	if (stamp_mutex++) {
    522  1.1  ad 		stamp_mutex--;
    523  1.1  ad 		rasops15_putchar(cookie, row, col, uc, attr);
    524  1.1  ad 		return;
    525  1.1  ad 	}
    526  1.1  ad 
    527  1.1  ad 	ri = (struct rasops_info *)cookie;
    528  1.1  ad 
    529  1.1  ad #ifdef RASOPS_CLIPPING
    530  1.1  ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    531  1.1  ad 		stamp_mutex--;
    532  1.1  ad 		return;
    533  1.1  ad 	}
    534  1.1  ad 
    535  1.1  ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    536  1.1  ad 		stamp_mutex--;
    537  1.1  ad 		return;
    538  1.1  ad 	}
    539  1.1  ad #endif
    540  1.1  ad 
    541  1.1  ad 	/* Recompute stamp? */
    542  1.1  ad 	if (attr != stamp_attr)
    543  1.1  ad 		rasops15_makestamp(ri, attr);
    544  1.1  ad 
    545  1.1  ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    546  1.1  ad 	height = ri->ri_font->fontheight;
    547  1.1  ad 
    548  1.1  ad 	if (uc == (u_int)-1) {
    549  1.1  ad 		while (height--) {
    550  1.1  ad 			rp[0] = stamp[0];
    551  1.1  ad 			rp[1] = stamp[0];
    552  1.1  ad 			rp[2] = stamp[0];
    553  1.1  ad 			rp[3] = stamp[0];
    554  1.1  ad 			rp[4] = stamp[0];
    555  1.1  ad 			rp[5] = stamp[0];
    556  1.1  ad 			rp[6] = stamp[0];
    557  1.1  ad 			rp[7] = stamp[0];
    558  1.1  ad 			DELTA(rp, ri->ri_stride, int32_t *);
    559  1.1  ad 		}
    560  1.1  ad 	} else {
    561  1.1  ad 		uc -= ri->ri_font->firstchar;
    562  1.1  ad 		fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
    563  1.1  ad 		fs = ri->ri_font->stride;
    564  1.1  ad 
    565  1.1  ad 		while (height--) {
    566  1.1  ad 			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
    567  1.1  ad 			rp[0] = STAMP_READ(so);
    568  1.1  ad 			rp[1] = STAMP_READ(so + 4);
    569  1.1  ad 
    570  1.1  ad 			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
    571  1.1  ad 			rp[2] = STAMP_READ(so);
    572  1.1  ad 			rp[3] = STAMP_READ(so + 4);
    573  1.1  ad 
    574  1.1  ad 			so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
    575  1.1  ad 			rp[4] = STAMP_READ(so);
    576  1.1  ad 			rp[5] = STAMP_READ(so + 4);
    577  1.1  ad 
    578  1.1  ad 			so = STAMP_SHIFT(fr[1], 0) & STAMP_MASK;
    579  1.1  ad 			rp[6] = STAMP_READ(so);
    580  1.1  ad 			rp[7] = STAMP_READ(so + 4);
    581  1.1  ad 
    582  1.1  ad 			DELTA(rp, ri->ri_stride, int32_t *);
    583  1.1  ad 			fr += fs;
    584  1.1  ad 		}
    585  1.1  ad 	}
    586  1.1  ad 
    587  1.1  ad 	stamp_mutex--;
    588  1.1  ad }
    589  1.1  ad 
    590  1.1  ad 
    591  1.1  ad /*
    592  1.1  ad  * Erase rows.
    593  1.1  ad  */
    594  1.1  ad static void
    595  1.1  ad rasops15_eraserows(cookie, row, num, attr)
    596  1.1  ad 	void *cookie;
    597  1.1  ad 	int row, num;
    598  1.1  ad 	long attr;
    599  1.1  ad {
    600  1.1  ad 	struct rasops_info *ri;
    601  1.1  ad 	int32_t *dp, clr;
    602  1.1  ad 	int n8, n1, cnt;
    603  1.1  ad 
    604  1.1  ad 	ri = (struct rasops_info *)cookie;
    605  1.1  ad 
    606  1.1  ad #ifdef RASOPS_CLIPPING
    607  1.1  ad 	if (row < 0) {
    608  1.1  ad 		num += row;
    609  1.1  ad 		row = 0;
    610  1.1  ad 	}
    611  1.1  ad 
    612  1.1  ad 	if ((row + num) > ri->ri_rows)
    613  1.1  ad 		num = ri->ri_rows - row;
    614  1.1  ad 
    615  1.1  ad 	if (num <= 0)
    616  1.1  ad 		return;
    617  1.1  ad #endif
    618  1.1  ad 
    619  1.1  ad 	num *= ri->ri_font->fontheight;
    620  1.1  ad 	dp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale);
    621  1.1  ad 	clr = rasops15_bg_color(ri, attr);
    622  1.1  ad 
    623  1.1  ad 	n8 = ri->ri_emustride >> 5;
    624  1.1  ad 	n1 = (ri->ri_emustride >> 2) & 7;
    625  1.1  ad 
    626  1.1  ad 	while (num--) {
    627  1.1  ad 		for (cnt = n8; cnt; cnt--) {
    628  1.1  ad 			dp[0] = clr;
    629  1.1  ad 			dp[1] = clr;
    630  1.1  ad 			dp[2] = clr;
    631  1.1  ad 			dp[3] = clr;
    632  1.1  ad 			dp[4] = clr;
    633  1.1  ad 			dp[5] = clr;
    634  1.1  ad 			dp[6] = clr;
    635  1.1  ad 			dp[7] = clr;
    636  1.1  ad 			dp += 8;
    637  1.1  ad 		}
    638  1.1  ad 
    639  1.1  ad 		for (cnt = n1; cnt; cnt--)
    640  1.1  ad 			*dp++ = clr;
    641  1.1  ad 
    642  1.1  ad 		DELTA(dp, ri->ri_delta, int32_t *);
    643  1.1  ad 	}
    644  1.1  ad }
    645  1.1  ad 
    646  1.1  ad #endif /* RASOPS15 */
    647