Module Name:    src
Committed By:   rin
Date:           Mon Jul 29 03:01:09 UTC 2019

Modified Files:
        src/sys/dev/rasops: rasops2.c rasops4.c rasops_putchar_width.h

Log Message:
Convert rasops2.c and rasops4.c to use rasops_putchar_width.h.
Style.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/dev/rasops/rasops2.c
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/rasops/rasops4.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/rasops/rasops_putchar_width.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/rasops/rasops2.c
diff -u src/sys/dev/rasops/rasops2.c:1.25 src/sys/dev/rasops/rasops2.c:1.26
--- src/sys/dev/rasops/rasops2.c:1.25	Sun Jul 28 12:06:10 2019
+++ src/sys/dev/rasops/rasops2.c	Mon Jul 29 03:01:09 2019
@@ -1,4 +1,4 @@
-/* 	$NetBSD: rasops2.c,v 1.25 2019/07/28 12:06:10 rin Exp $	*/
+/* 	$NetBSD: rasops2.c,v 1.26 2019/07/29 03:01:09 rin Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops2.c,v 1.25 2019/07/28 12:06:10 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops2.c,v 1.26 2019/07/29 03:01:09 rin Exp $");
 
 #include "opt_rasops.h"
 
@@ -63,6 +63,14 @@ static int	stamp_mutex;	/* XXX see note 
 #endif
 
 /*
+ * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
+ * destination = STAMP_READ(offset)
+ */
+#define	STAMP_SHIFT(fb, n)	((n) ? (fb) >> 4 : (fb))
+#define	STAMP_MASK		0xf
+#define	STAMP_READ(o)		stamp[o]
+
+/*
  * Initialize rasops_info struct for this colordepth.
  */
 void
@@ -94,117 +102,6 @@ rasops2_init(struct rasops_info *ri)
 	}
 }
 
-#ifdef notyet
-/*
- * Paint a single character. This is the generic version, this is ugly.
- */
-static void
-rasops2_putchar(void *cookie, int row, int col, u_int uc, long attr)
-{
-	int height, width, fs, rs, fb, bg, fg, lmask, rmask;
-	struct rasops_info *ri = (struct rasops_info *)cookie;
-	struct wsdisplay_font *font = PICK_FONT(ri, uc);
-	uint32_t *rp;
-	uint8_t *fr;
-
-#ifdef RASOPS_CLIPPING
-	/* Catches 'row < 0' case too */
-	if ((unsigned)row >= (unsigned)ri->ri_rows)
-		return;
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols)
-		return;
-#endif
-
-	width = font->fontwidth << 1;
-	height = font->fontheight;
-	col *= width;
-	rp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale +
-	    ((col >> 3) & ~3));
-	col = col & 31;
-	rs = ri->ri_stride;
-
-	bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
-	fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf];
-
-	/* If fg and bg match this becomes a space character */
-	if (fg == bg || uc == ' ') {
-		uc = (u_int)-1;
-		fr = 0;		/* shutup gcc */
-		fs = 0;		/* shutup gcc */
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-	}
-
-	/* Single word, one mask */
-	if ((col + width) <= 32) {
-		rmask = rasops_pmask[col][width];
-		lmask = ~rmask;
-
-		if (uc == (u_int)-1) {
-			bg &= rmask;
-
-			while (height--) {
-				*rp = (*rp & lmask) | bg;
-				DELTA(rp, rs, uint32_t *);
-			}
-		} else {
-			while (height--) {
-				/* get bits, mask */
-				/* compose sl */
-				/* mask sl */
-				/* put word */
-			}
-		}
-
-		/* Do underline */
-		if (attr & WSATTR_UNDERLINE) {
-			DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
-			*rp = (*rp & lmask) | (fg & rmask);
-		}
-	} else {
-		lmask = ~rasops_lmask[col];
-		rmask = ~rasops_rmask[(col + width) & 31];
-
-		if (uc == (u_int)-1) {
-			bg = bg & ~lmask;
-			width = bg & ~rmask;
-
-			while (height--) {
-				rp[0] = (rp[0] & lmask) | bg;
-				rp[1] = (rp[1] & rmask) | width;
-				DELTA(rp, rs, uint32_t *);
-			}
-		} else {
-			width = 32 - col;
-
-			/* NOT fontbits if bg is white */
-			while (height--) {
-				fb = ~(fr[3] | (fr[2] << 8) |
-				    (fr[1] << 16) | (fr[0] << 24));
-
-				rp[0] = (rp[0] & lmask)
-				    | MBE((u_int)fb >> col);
-
-				rp[1] = (rp[1] & rmask)
-				   | (MBE((u_int)fb << width) & ~rmask);
-
-				fr += fs;
-				DELTA(rp, rs, uint32_t *);
-			}
-		}
-
-		/* Do underline */
-		if (attr & WSATTR_UNDERLINE) {
-			DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
-			rp[0] = (rp[0] & lmask) | (fg & ~lmask);
-			rp[1] = (rp[1] & rmask) | (fg & ~rmask);
-		}
-	}
-}
-#endif
-
 /*
  * Put a single character. This is the generic version.
  */
@@ -236,13 +133,13 @@ rasops2_makestamp(struct rasops_info *ri
 #endif
 		if ((ri->ri_flg & RI_BSWAP) == NEED_LITTLE_ENDIAN_STAMP) {
 			/* littel endian */
-			stamp[i] = (i & 8 ? fg : bg);
+			stamp[i]  = (i & 8 ? fg : bg);
 			stamp[i] |= (i & 4 ? fg : bg) << 2;
 			stamp[i] |= (i & 2 ? fg : bg) << 4;
 			stamp[i] |= (i & 1 ? fg : bg) << 6;
 		} else {
 			/* big endian */
-			stamp[i] = (i & 1 ? fg : bg);
+			stamp[i]  = (i & 1 ? fg : bg);
 			stamp[i] |= (i & 2 ? fg : bg) << 2;
 			stamp[i] |= (i & 4 ? fg : bg) << 4;
 			stamp[i] |= (i & 8 ? fg : bg) << 6;
@@ -250,203 +147,20 @@ rasops2_makestamp(struct rasops_info *ri
 	}
 }
 
-/*
- * Put a single character. This is for 8-pixel wide fonts.
- */
-static void
-rasops2_putchar8(void *cookie, int row, int col, u_int uc, long attr)
-{
-	struct rasops_info *ri = (struct rasops_info *)cookie;
-	struct wsdisplay_font *font = PICK_FONT(ri, uc);
-	int height, fs, rs;
-	uint8_t *fr, *rp;
-
-	/* Can't risk remaking the stamp if it's already in use */
-	if (stamp_mutex++) {
-		stamp_mutex--;
-		rasops2_putchar(cookie, row, col, uc, attr);
-		return;
-	}
-
-#ifdef RASOPS_CLIPPING
-	/* Catches 'row < 0' case too */
-	if ((unsigned)row >= (unsigned)ri->ri_rows) {
-		stamp_mutex--;
-		return;
-	}
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols) {
-		stamp_mutex--;
-		return;
-	}
-#endif
-
-	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
-	height = font->fontheight;
-	rs = ri->ri_stride;
-
-	/* Recompute stamp? */
-	if (attr != stamp_attr)
-		rasops2_makestamp(ri, attr);
-
-	if (uc == ' ') {
-		while (height--) {
-			rp[0] = rp[1] = stamp[0];
-			rp += rs;
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-
-		while (height--) {
-			rp[0] = stamp[(*fr >> 4) & 0xf];
-			rp[1] = stamp[*fr & 0xf];
-			fr += fs;
-			rp += rs;
-		}
-	}
-
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		rp -= ri->ri_stride << 1;
-		rp[0] = rp[1] = stamp[15];
-	}
-
-	stamp_mutex--;
-}
-
-/*
- * Put a single character. This is for 12-pixel wide fonts.
- */
-static void
-rasops2_putchar12(void *cookie, int row, int col, u_int uc, long attr)
-{
-	struct rasops_info *ri = (struct rasops_info *)cookie;
-	struct wsdisplay_font *font = PICK_FONT(ri, uc);
-	int height, fs, rs;
-	uint8_t *fr, *rp;
-
-	/* Can't risk remaking the stamp if it's already in use */
-	if (stamp_mutex++) {
-		stamp_mutex--;
-		rasops2_putchar(cookie, row, col, uc, attr);
-		return;
-	}
-
-#ifdef RASOPS_CLIPPING
-	/* Catches 'row < 0' case too */
-	if ((unsigned)row >= (unsigned)ri->ri_rows) {
-		stamp_mutex--;
-		return;
-	}
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols) {
-		stamp_mutex--;
-		return;
-	}
-#endif
-
-	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
-	height = font->fontheight;
-	rs = ri->ri_stride;
-
-	/* Recompute stamp? */
-	if (attr != stamp_attr)
-		rasops2_makestamp(ri, attr);
-
-	if (uc == ' ') {
-		while (height--) {
-			rp[0] = rp[1] = rp[2] = stamp[0];
-			rp += rs;
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-
-		while (height--) {
-			rp[0] = stamp[(fr[0] >> 4) & 0xf];
-			rp[1] = stamp[fr[0] & 0xf];
-			rp[2] = stamp[(fr[1] >> 4) & 0xf];
-			fr += fs;
-			rp += rs;
-		}
-	}
-
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		rp -= ri->ri_stride << 1;
-		rp[0] = rp[1] = rp[2] = stamp[15];
-	}
-
-	stamp_mutex--;
-}
-
-/*
- * Put a single character. This is for 16-pixel wide fonts.
- */
-static void
-rasops2_putchar16(void *cookie, int row, int col, u_int uc, long attr)
-{
-	struct rasops_info *ri = (struct rasops_info *)cookie;
-	struct wsdisplay_font *font = PICK_FONT(ri, uc);
-	int height, fs, rs;
-	uint8_t *fr, *rp;
-
-	/* Can't risk remaking the stamp if it's already in use */
-	if (stamp_mutex++) {
-		stamp_mutex--;
-		rasops2_putchar(cookie, row, col, uc, attr);
-		return;
-	}
-
-#ifdef RASOPS_CLIPPING
-	/* Catches 'row < 0' case too */
-	if ((unsigned)row >= (unsigned)ri->ri_rows) {
-		stamp_mutex--;
-		return;
-	}
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols) {
-		stamp_mutex--;
-		return;
-	}
-#endif
-
-	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
-	height = font->fontheight;
-	rs = ri->ri_stride;
-
-	/* Recompute stamp? */
-	if (attr != stamp_attr)
-		rasops2_makestamp(ri, attr);
-
-	if (uc == ' ') {
-		while (height--) {
-			rp[0] = rp[1] = rp[2] = rp[3] = stamp[0];
-			rp += rs;
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-
-		while (height--) {
-			rp[0] = stamp[(fr[0] >> 4) & 0xf];
-			rp[1] = stamp[fr[0] & 0xf];
-			rp[2] = stamp[(fr[1] >> 4) & 0xf];
-			rp[3] = stamp[fr[1] & 0xf];
-			fr += fs;
-			rp += rs;
-		}
-	}
+#define	RASOPS_DEPTH	2
 
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		rp -= ri->ri_stride << 1;
-		rp[0] = rp[1] = stamp[15];
-	}
+#define	RASOPS_WIDTH	8
+#include "rasops_putchar_width.h"
+#undef	RASOPS_WIDTH
+
+#define	RASOPS_WIDTH	12
+#include "rasops_putchar_width.h"
+#undef	RASOPS_WIDTH
+
+#define	RASOPS_WIDTH	16
+#include "rasops_putchar_width.h"
+#undef	RASOPS_WIDTH
 
-	stamp_mutex--;
-}
 #endif	/* !RASOPS_SMALL */
 
 /*

Index: src/sys/dev/rasops/rasops4.c
diff -u src/sys/dev/rasops/rasops4.c:1.19 src/sys/dev/rasops/rasops4.c:1.20
--- src/sys/dev/rasops/rasops4.c:1.19	Sun Jul 28 12:06:10 2019
+++ src/sys/dev/rasops/rasops4.c	Mon Jul 29 03:01:09 2019
@@ -1,4 +1,4 @@
-/* 	$NetBSD: rasops4.c,v 1.19 2019/07/28 12:06:10 rin Exp $	*/
+/* 	$NetBSD: rasops4.c,v 1.20 2019/07/29 03:01:09 rin Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops4.c,v 1.19 2019/07/28 12:06:10 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops4.c,v 1.20 2019/07/29 03:01:09 rin Exp $");
 
 #include "opt_rasops.h"
 
@@ -63,12 +63,26 @@ static int	stamp_mutex;	/* XXX see note 
 #endif
 
 /*
+ * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
+ * destination = STAMP_READ(offset)
+ */
+#define STAMP_SHIFT(fb, n)	((n) ? (fb) >> 4 : (fb))
+#define STAMP_MASK		0xf
+#define STAMP_READ(o)		stamp[o]
+
+/*
  * Initialize rasops_info struct for this colordepth.
  */
 void
 rasops4_init(struct rasops_info *ri)
 {
 
+	if ((ri->ri_font->fontwidth & 1) != 0) {
+		ri->ri_ops.erasecols = rasops4_erasecols;
+		ri->ri_ops.copycols = rasops4_copycols;
+		ri->ri_do_cursor = rasops4_do_cursor;
+	}
+
 	switch (ri->ri_font->fontwidth) {
 #ifndef RASOPS_SMALL
 	case 8:
@@ -86,124 +100,7 @@ rasops4_init(struct rasops_info *ri)
 		ri->ri_ops.putchar = rasops4_putchar;
 		break;
 	}
-
-	if ((ri->ri_font->fontwidth & 1) != 0) {
-		ri->ri_ops.erasecols = rasops4_erasecols;
-		ri->ri_ops.copycols = rasops4_copycols;
-		ri->ri_do_cursor = rasops4_do_cursor;
-	}
-}
-
-#ifdef notyet
-/*
- * Paint a single character. This is the generic version, this is ugly.
- */
-static void
-rasops4_putchar(void *cookie, int row, int col, u_int uc, long attr)
-{
-	int height, width, fs, rs, fb, bg, fg, lmask, rmask;
-	struct rasops_info *ri = (struct rasops_info *)cookie;
-	struct wsdisplay_font *font = PICK_FONT(ri, uc);
-	uint32_t *rp;
-	uint8_t *fr;
-
-#ifdef RASOPS_CLIPPING
-	/* Catches 'row < 0' case too */
-	if ((unsigned)row >= (unsigned)ri->ri_rows)
-		return;
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols)
-		return;
-#endif
-
-	width = font->fontwidth << 1;
-	height = font->fontheight;
-	col *= width;
-	rp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale +
-	    ((col >> 3) & ~3));
-	col = col & 31;
-	rs = ri->ri_stride;
-
-	bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
-	fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf];
-
-	/* If fg and bg match this becomes a space character */
-	if (fg == bg || uc == ' ') {
-		uc = (u_int)-1;
-		fr = 0;		/* shutup gcc */
-		fs = 0;		/* shutup gcc */
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-	}
-
-	/* Single word, one mask */
-	if ((col + width) <= 32) {
-		rmask = rasops_pmask[col][width];
-		lmask = ~rmask;
-
-		if (uc == (u_int)-1) {
-			bg &= rmask;
-
-			while (height--) {
-				*rp = (*rp & lmask) | bg;
-				DELTA(rp, rs, uint32_t *);
-			}
-		} else {
-			while (height--) {
-				/* get bits, mask */
-				/* compose sl */
-				/* mask sl */
-				/* put word */
-			}
-		}
-
-		/* Do underline */
-		if (attr & WSATTR_UNDERLINE) {
-			DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
-			*rp = (*rp & lmask) | (fg & rmask);
-		}
-	} else {
-		lmask = ~rasops_lmask[col];
-		rmask = ~rasops_rmask[(col + width) & 31];
-
-		if (uc == (u_int)-1) {
-			bg = bg & ~lmask;
-			width = bg & ~rmask;
-
-			while (height--) {
-				rp[0] = (rp[0] & lmask) | bg;
-				rp[1] = (rp[1] & rmask) | width;
-				DELTA(rp, rs, uint32_t *);
-			}
-		} else {
-			width = 32 - col;
-
-			/* NOT fontbits if bg is white */
-			while (height--) {
-				fb = ~(fr[3] | (fr[2] << 8) |
-				    (fr[1] << 16) | (fr[0] << 24));
-
-				rp[0] = (rp[0] & lmask)
-				    | MBE((u_int)fb >> col);
-
-				rp[1] = (rp[1] & rmask)
-				   | (MBE((u_int)fb << width) & ~rmask);
-
-				fr += fs;
-				DELTA(rp, rs, uint32_t *);
-			}
-		}
-
-		/* Do underline */
-		if (attr & WSATTR_UNDERLINE) {
-			DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
-			rp[0] = (rp[0] & lmask) | (fg & ~lmask);
-			rp[1] = (rp[1] & rmask) | (fg & ~rmask);
-		}
-	}
 }
-#endif
 
 /*
  * Put a single character. This is the generic version.
@@ -236,13 +133,13 @@ rasops4_makestamp(struct rasops_info *ri
 #endif
 		if ((ri->ri_flg & RI_BSWAP) == NEED_LITTLE_ENDIAN_STAMP) {
 			/* little endian */
-			stamp[i] =  (i & 1 ? fg : bg) << 12;
+			stamp[i]  = (i & 1 ? fg : bg) << 12;
 			stamp[i] |= (i & 2 ? fg : bg) << 8;
 			stamp[i] |= (i & 4 ? fg : bg) << 4;
 			stamp[i] |= (i & 8 ? fg : bg) << 0;
 		} else {
 			/* big endian */
-			stamp[i] =  (i & 1 ? fg : bg) << 0;
+			stamp[i]  = (i & 1 ? fg : bg) << 0;
 			stamp[i] |= (i & 2 ? fg : bg) << 4;
 			stamp[i] |= (i & 4 ? fg : bg) << 8;
 			stamp[i] |= (i & 8 ? fg : bg) << 12;
@@ -250,209 +147,20 @@ rasops4_makestamp(struct rasops_info *ri
 	}
 }
 
-/*
- * Put a single character. This is for 8-pixel wide fonts.
- */
-static void
-rasops4_putchar8(void *cookie, int row, int col, u_int uc, long attr)
-{
-	struct rasops_info *ri = (struct rasops_info *)cookie;
-	struct wsdisplay_font *font = PICK_FONT(ri, uc);
-	int height, fs, rs;
-	uint8_t *fr;
-	uint16_t *rp;
-
-	/* Can't risk remaking the stamp if it's already in use */
-	if (stamp_mutex++) {
-		stamp_mutex--;
-		rasops4_putchar(cookie, row, col, uc, attr);
-		return;
-	}
-
-#ifdef RASOPS_CLIPPING
-	/* Catches 'row < 0' case too */
-	if ((unsigned)row >= (unsigned)ri->ri_rows) {
-		stamp_mutex--;
-		return;
-	}
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols) {
-		stamp_mutex--;
-		return;
-	}
-#endif
-
-	rp = (uint16_t *)(ri->ri_bits + row * ri->ri_yscale +
-	    col * ri->ri_xscale);
-	height = font->fontheight;
-	rs = ri->ri_stride / sizeof(*rp);
-
-	/* Recompute stamp? */
-	if (attr != stamp_attr)
-		rasops4_makestamp(ri, attr);
-
-	if (uc == ' ') {
-		while (height--) {
-			rp[0] = rp[1] = stamp[0];
-			rp += rs;
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-
-		while (height--) {
-			rp[0] = stamp[(*fr >> 4) & 0xf];
-			rp[1] = stamp[*fr & 0xf];
-			fr += fs;
-			rp += rs;
-		}
-	}
-
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		rp -= (rs << 1);
-		rp[0] = rp[1] = stamp[15];
-	}
-
-	stamp_mutex--;
-}
-
-/*
- * Put a single character. This is for 12-pixel wide fonts.
- */
-static void
-rasops4_putchar12(void *cookie, int row, int col, u_int uc, long attr)
-{
-	struct rasops_info *ri = (struct rasops_info *)cookie;
-	struct wsdisplay_font *font = PICK_FONT(ri, uc);
-	int height, fs, rs;
-	uint8_t *fr;
-	uint16_t *rp;
-
-	/* Can't risk remaking the stamp if it's already in use */
-	if (stamp_mutex++) {
-		stamp_mutex--;
-		rasops4_putchar(cookie, row, col, uc, attr);
-		return;
-	}
-
-#ifdef RASOPS_CLIPPING
-	/* Catches 'row < 0' case too */
-	if ((unsigned)row >= (unsigned)ri->ri_rows) {
-		stamp_mutex--;
-		return;
-	}
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols) {
-		stamp_mutex--;
-		return;
-	}
-#endif
-
-	rp = (uint16_t *)(ri->ri_bits + row * ri->ri_yscale +
-	    col * ri->ri_xscale);
-	height = font->fontheight;
-	rs = ri->ri_stride / sizeof(*rp);
-
-	/* Recompute stamp? */
-	if (attr != stamp_attr)
-		rasops4_makestamp(ri, attr);
-
-	if (uc == ' ') {
-		while (height--) {
-			rp[0] = rp[1] = rp[2] = stamp[0];
-			rp += rs;
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-
-		while (height--) {
-			rp[0] = stamp[(fr[0] >> 4) & 0xf];
-			rp[1] = stamp[fr[0] & 0xf];
-			rp[2] = stamp[(fr[1] >> 4) & 0xf];
-			fr += fs;
-			rp += rs;
-		}
-	}
-
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		rp -= (rs << 1);
-		rp[0] = rp[1] = rp[2] = stamp[15];
-	}
-
-	stamp_mutex--;
-}
-
-/*
- * Put a single character. This is for 16-pixel wide fonts.
- */
-static void
-rasops4_putchar16(void *cookie, int row, int col, u_int uc, long attr)
-{
-	struct rasops_info *ri = (struct rasops_info *)cookie;
-	struct wsdisplay_font *font = PICK_FONT(ri, uc);
-	int height, fs, rs;
-	uint8_t *fr;
-	uint16_t *rp;
-
-	/* Can't risk remaking the stamp if it's already in use */
-	if (stamp_mutex++) {
-		stamp_mutex--;
-		rasops4_putchar(cookie, row, col, uc, attr);
-		return;
-	}
+#define	RASOPS_DEPTH	4
 
-#ifdef RASOPS_CLIPPING
-	/* Catches 'row < 0' case too */
-	if ((unsigned)row >= (unsigned)ri->ri_rows) {
-		stamp_mutex--;
-		return;
-	}
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols) {
-		stamp_mutex--;
-		return;
-	}
-#endif
+#define	RASOPS_WIDTH	8
+#include "rasops_putchar_width.h"
+#undef	RASOPS_WIDTH
+
+#define	RASOPS_WIDTH	12
+#include "rasops_putchar_width.h"
+#undef	RASOPS_WIDTH
+
+#define	RASOPS_WIDTH	16
+#include "rasops_putchar_width.h"
+#undef	RASOPS_WIDTH
 
-	rp = (uint16_t *)(ri->ri_bits + row * ri->ri_yscale +
-	    col * ri->ri_xscale);
-	height = font->fontheight;
-	rs = ri->ri_stride / sizeof(*rp);
-
-	/* Recompute stamp? */
-	if (attr != stamp_attr)
-		rasops4_makestamp(ri, attr);
-
-	if (uc == ' ') {
-		while (height--) {
-			rp[0] = rp[1] = rp[2] = rp[3] = stamp[0];
-			rp += rs;
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-
-		while (height--) {
-			rp[0] = stamp[(fr[0] >> 4) & 0xf];
-			rp[1] = stamp[fr[0] & 0xf];
-			rp[2] = stamp[(fr[1] >> 4) & 0xf];
-			rp[3] = stamp[fr[1] & 0xf];
-			fr += fs;
-			rp += rs;
-		}
-	}
-
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		rp -= (rs << 1);
-		rp[0] = rp[1] = rp[2] = rp[3] = stamp[15];
-	}
-
-	stamp_mutex--;
-}
 #endif	/* !RASOPS_SMALL */
 
 /*

Index: src/sys/dev/rasops/rasops_putchar_width.h
diff -u src/sys/dev/rasops/rasops_putchar_width.h:1.6 src/sys/dev/rasops/rasops_putchar_width.h:1.7
--- src/sys/dev/rasops/rasops_putchar_width.h:1.6	Sun Jul 28 12:06:10 2019
+++ src/sys/dev/rasops/rasops_putchar_width.h	Mon Jul 29 03:01:09 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: rasops_putchar_width.h,v 1.6 2019/07/28 12:06:10 rin Exp $ */
+/* $NetBSD: rasops_putchar_width.h,v 1.7 2019/07/29 03:01:09 rin Exp $ */
 
 /* NetBSD: rasops8.c,v 1.41 2019/07/25 03:02:44 rin Exp  */
 /*-
@@ -30,8 +30,8 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#if RASOPS_DEPTH != 8 && RASOPS_DEPTH != 15 && RASOPS_DEPTH != 24 && \
-    RASOPS_DEPTH != 32
+#if RASOPS_DEPTH !=  2 && RASOPS_DEPTH !=  4 && RASOPS_DEPTH !=  8 &&	\
+    RASOPS_DEPTH != 15 && RASOPS_DEPTH != 24 && RASOPS_DEPTH != 32
 #error "Depth not supported"
 #endif
 
@@ -39,14 +39,6 @@
 #error "Width not supported"
 #endif
 
-#if   RASOPS_DEPTH == 8
-#define	FILLED_STAMP	15
-#elif RASOPS_DEPTH == 15
-#define	FILLED_STAMP	30
-#else
-#define	FILLED_STAMP	60
-#endif
-
 #define	PUTCHAR_WIDTH1(depth, width)	rasops ## depth ## _putchar ## width
 #define	PUTCHAR_WIDTH(depth, width)	PUTCHAR_WIDTH1(depth, width)
 
@@ -56,9 +48,25 @@
 #define	MAKESTAMP1(depth)		rasops ## depth ## _makestamp
 #define	MAKESTAMP(depth)		MAKESTAMP1(depth)
 
+#if   RASOPS_DEPTH == 2
+#define	STAMP_TYPE	uint8_t
+#elif RASOPS_DEPTH == 4
+#define	STAMP_TYPE	uint16_t
+#else
+#define	STAMP_TYPE	uint32_t
+#endif
+
+#if   RASOPS_DEPTH <= 8
+#define	FILLED_STAMP	15
+#elif RASOPS_DEPTH == 15
+#define	FILLED_STAMP	30
+#else
+#define	FILLED_STAMP	60
+#endif
+
 /* ################################################################### */
 
-#if RASOPS_DEPTH == 8
+#if RASOPS_DEPTH <= 8
 
 #define	SUBST_STAMP1(p, off, base)					\
 	(p)[(off) * 1 + 0] = stamp[base]
@@ -72,7 +80,7 @@
 		}							\
 	} while (0 /* CONSTCOND */)
 
-#endif /* RASOPS_DEPTH == 8 */
+#endif /* RASOPS_DEPTH <= 8 */
 
 /* ################################################################### */
 
@@ -203,7 +211,7 @@ PUTCHAR_WIDTH(RASOPS_DEPTH, RASOPS_WIDTH
 	struct rasops_info *ri = (struct rasops_info *)cookie;
 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
 	int height, fs;
-	uint32_t *rp, *hrp;
+	STAMP_TYPE *rp, *hrp;
 	uint8_t *fr;
 
 	hrp = NULL; /* XXX GCC */
@@ -232,20 +240,23 @@ PUTCHAR_WIDTH(RASOPS_DEPTH, RASOPS_WIDTH
 	if (attr != stamp_attr)
 		MAKESTAMP(RASOPS_DEPTH)(ri, attr);
 
-	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
+	rp = (STAMP_TYPE *)(ri->ri_bits + row * ri->ri_yscale +
+	    col * ri->ri_xscale);
 	if (ri->ri_hwbits)
-		hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
-		    col*ri->ri_xscale);
+		hrp = (STAMP_TYPE *)(ri->ri_hwbits + row * ri->ri_yscale +
+		    col * ri->ri_xscale);
 
 	height = font->fontheight;
 
 	if (uc == ' ') {
 		while (height--) {
 			SUBST_STAMP(rp, 0);
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits) {
+			DELTA(rp, ri->ri_stride, STAMP_TYPE *);
+		}
+		if (ri->ri_hwbits) {
+			while (height--) {
 				SUBST_STAMP(hrp, 0);
-				DELTA(hrp, ri->ri_stride, uint32_t *);
+				DELTA(hrp, ri->ri_stride, STAMP_TYPE *);
 			}
 		}
 	} else {
@@ -256,18 +267,18 @@ PUTCHAR_WIDTH(RASOPS_DEPTH, RASOPS_WIDTH
 			SUBST_GLYPH;
 
 			fr += fs;
-			DELTA(rp, ri->ri_stride, uint32_t *);
+			DELTA(rp, ri->ri_stride, STAMP_TYPE *);
 			if (ri->ri_hwbits)
-				DELTA(hrp, ri->ri_stride, uint32_t *);
+				DELTA(hrp, ri->ri_stride, STAMP_TYPE *);
 		}
 	}
 
 	/* Do underline */
 	if ((attr & WSATTR_UNDERLINE) != 0) {
-		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
+		DELTA(rp, -(ri->ri_stride << 1), STAMP_TYPE *);
 		SUBST_STAMP(rp, FILLED_STAMP);
 		if (ri->ri_hwbits) {
-			DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
+			DELTA(hrp, -(ri->ri_stride << 1), STAMP_TYPE *);
 			SUBST_STAMP(hrp, FILLED_STAMP);
 		}
 	}
@@ -275,6 +286,8 @@ PUTCHAR_WIDTH(RASOPS_DEPTH, RASOPS_WIDTH
 	stamp_mutex--;
 }
 
+#undef	STAMP_TYPE
+
 #undef	FILLED_STAMP
 
 #undef	PUTCHAR_WIDTH1

Reply via email to