summaryrefslogtreecommitdiff
path: root/sys/dev/rasops
diff options
context:
space:
mode:
authorrin <rin@NetBSD.org>2019-08-02 04:39:09 +0000
committerrin <rin@NetBSD.org>2019-08-02 04:39:09 +0000
commit83574402ecb13bb64fa0cb6c97e083d9f5cd271e (patch)
treeca64402c3abd153c7c81393951cc901924b8fcc2 /sys/dev/rasops
parentb48903a4a4618b1027721633554922649b585497 (diff)
Add general putchar functions for 2 and 4bpp.
Note that 1bpp continues to use its local version in rasops1.c, which is much faster and simpler.
Diffstat (limited to 'sys/dev/rasops')
-rw-r--r--sys/dev/rasops/rasops1.c8
-rw-r--r--sys/dev/rasops/rasops2.c21
-rw-r--r--sys/dev/rasops/rasops24.c6
-rw-r--r--sys/dev/rasops/rasops4.c21
-rw-r--r--sys/dev/rasops/rasops_bitops.h233
5 files changed, 244 insertions, 45 deletions
diff --git a/sys/dev/rasops/rasops1.c b/sys/dev/rasops/rasops1.c
index 9dcb9ba795d..8fa66ad0b0d 100644
--- a/sys/dev/rasops/rasops1.c
+++ b/sys/dev/rasops/rasops1.c
@@ -1,4 +1,4 @@
-/* $NetBSD: rasops1.c,v 1.33 2019/08/02 04:23:20 rin Exp $ */
+/* $NetBSD: rasops1.c,v 1.34 2019/08/02 04:39:09 rin Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops1.c,v 1.33 2019/08/02 04:23:20 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops1.c,v 1.34 2019/08/02 04:39:09 rin Exp $");
#include "opt_rasops.h"
@@ -43,6 +43,7 @@ __KERNEL_RCSID(0, "$NetBSD: rasops1.c,v 1.33 2019/08/02 04:23:20 rin Exp $");
#include <dev/wscons/wsconsio.h>
#define _RASOPS_PRIVATE
+#define RASOPS_DEPTH 1
#include <dev/rasops/rasops.h>
#include <dev/rasops/rasops_masks.h>
@@ -251,7 +252,4 @@ rasops1_putchar(void *cookie, int row, int col, u_int uc, long attr)
/*
* Grab routines common to depths where (bpp < 8)
*/
-#define NAME(ident) rasops1_##ident
-#define PIXEL_SHIFT 0
-
#include <dev/rasops/rasops_bitops.h>
diff --git a/sys/dev/rasops/rasops2.c b/sys/dev/rasops/rasops2.c
index 704ae1a92ca..3ca10eee1d1 100644
--- a/sys/dev/rasops/rasops2.c
+++ b/sys/dev/rasops/rasops2.c
@@ -1,4 +1,4 @@
-/* $NetBSD: rasops2.c,v 1.28 2019/07/31 02:04:14 rin Exp $ */
+/* $NetBSD: rasops2.c,v 1.29 2019/08/02 04:39: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.28 2019/07/31 02:04:14 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops2.c,v 1.29 2019/08/02 04:39:09 rin Exp $");
#include "opt_rasops.h"
@@ -43,6 +43,7 @@ __KERNEL_RCSID(0, "$NetBSD: rasops2.c,v 1.28 2019/07/31 02:04:14 rin Exp $");
#include <dev/wscons/wsconsio.h>
#define _RASOPS_PRIVATE
+#define RASOPS_DEPTH 2
#include <dev/rasops/rasops.h>
#include <dev/rasops/rasops_masks.h>
@@ -91,7 +92,6 @@ rasops2_init(struct rasops_info *ri)
break;
#endif /* !RASOPS_SMALL */
default:
- panic("fontwidth not 8/12/16 or RASOPS_SMALL - fixme!");
ri->ri_ops.putchar = rasops2_putchar;
return;
}
@@ -101,16 +101,6 @@ rasops2_init(struct rasops_info *ri)
#endif
}
-/*
- * Put a single character. This is the generic version.
- */
-static void
-rasops2_putchar(void *cookie, int row, int col, u_int uc, long attr)
-{
-
- /* XXX punt */
-}
-
#ifndef RASOPS_SMALL
/*
* Recompute the blitting stamp.
@@ -147,8 +137,6 @@ rasops2_makestamp(struct rasops_info *ri, long attr)
}
}
-#define RASOPS_DEPTH 2
-
#define RASOPS_WIDTH 8
#include "rasops_putchar_width.h"
#undef RASOPS_WIDTH
@@ -166,7 +154,4 @@ rasops2_makestamp(struct rasops_info *ri, long attr)
/*
* Grab routines common to depths where (bpp < 8)
*/
-#define NAME(ident) rasops2_##ident
-#define PIXEL_SHIFT 1
-
#include <dev/rasops/rasops_bitops.h>
diff --git a/sys/dev/rasops/rasops24.c b/sys/dev/rasops/rasops24.c
index 4c3a69b6ab1..19baac0c6d2 100644
--- a/sys/dev/rasops/rasops24.c
+++ b/sys/dev/rasops/rasops24.c
@@ -1,4 +1,4 @@
-/* $NetBSD: rasops24.c,v 1.43 2019/07/31 05:08:10 rin Exp $ */
+/* $NetBSD: rasops24.c,v 1.44 2019/08/02 04:39:09 rin Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops24.c,v 1.43 2019/07/31 05:08:10 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops24.c,v 1.44 2019/08/02 04:39:09 rin Exp $");
#include "opt_rasops.h"
@@ -45,6 +45,7 @@ __KERNEL_RCSID(0, "$NetBSD: rasops24.c,v 1.43 2019/07/31 05:08:10 rin Exp $");
#include <dev/wscons/wsconsio.h>
#define _RASOPS_PRIVATE
+#define RASOPS_DEPTH 24
#include <dev/rasops/rasops.h>
static void rasops24_erasecols(void *, int, int, int, long);
@@ -116,7 +117,6 @@ rasops24_init(struct rasops_info *ri)
#endif
}
-#define RASOPS_DEPTH 24
#include "rasops_putchar.h"
#include "rasops_putchar_aa.h"
diff --git a/sys/dev/rasops/rasops4.c b/sys/dev/rasops/rasops4.c
index 201b3f8a257..68241dffcfa 100644
--- a/sys/dev/rasops/rasops4.c
+++ b/sys/dev/rasops/rasops4.c
@@ -1,4 +1,4 @@
-/* $NetBSD: rasops4.c,v 1.23 2019/08/01 03:38:12 rin Exp $ */
+/* $NetBSD: rasops4.c,v 1.24 2019/08/02 04:39: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.23 2019/08/01 03:38:12 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops4.c,v 1.24 2019/08/02 04:39:09 rin Exp $");
#include "opt_rasops.h"
@@ -43,6 +43,7 @@ __KERNEL_RCSID(0, "$NetBSD: rasops4.c,v 1.23 2019/08/01 03:38:12 rin Exp $");
#include <dev/wscons/wsconsio.h>
#define _RASOPS_PRIVATE
+#define RASOPS_DEPTH 4
#include <dev/rasops/rasops.h>
#include <dev/rasops/rasops_masks.h>
@@ -91,7 +92,6 @@ rasops4_init(struct rasops_info *ri)
break;
#endif /* !RASOPS_SMALL */
default:
- panic("fontwidth not 8/12/16 or RASOPS_SMALL - fixme!");
ri->ri_ops.putchar = rasops4_putchar;
return;
}
@@ -101,16 +101,6 @@ rasops4_init(struct rasops_info *ri)
#endif
}
-/*
- * Put a single character. This is the generic version.
- */
-static void
-rasops4_putchar(void *cookie, int row, int col, u_int uc, long attr)
-{
-
- /* XXX punt */
-}
-
#ifndef RASOPS_SMALL
/*
* Recompute the blitting stamp.
@@ -147,8 +137,6 @@ rasops4_makestamp(struct rasops_info *ri, long attr)
}
}
-#define RASOPS_DEPTH 4
-
#define RASOPS_WIDTH 8
#include "rasops_putchar_width.h"
#undef RASOPS_WIDTH
@@ -166,7 +154,4 @@ rasops4_makestamp(struct rasops_info *ri, long attr)
/*
* Grab routines common to depths where (bpp < 8)
*/
-#define NAME(ident) rasops4_##ident
-#define PIXEL_SHIFT 2
-
#include <dev/rasops/rasops_bitops.h>
diff --git a/sys/dev/rasops/rasops_bitops.h b/sys/dev/rasops/rasops_bitops.h
index e1615c8e961..1dcb48af095 100644
--- a/sys/dev/rasops/rasops_bitops.h
+++ b/sys/dev/rasops/rasops_bitops.h
@@ -1,4 +1,4 @@
-/* $NetBSD: rasops_bitops.h,v 1.22 2019/08/02 04:35:54 rin Exp $ */
+/* $NetBSD: rasops_bitops.h,v 1.23 2019/08/02 04:39:09 rin Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -32,6 +32,233 @@
#ifndef _RASOPS_BITOPS_H_
#define _RASOPS_BITOPS_H_ 1
+#define NAME(name) NAME1(RASOPS_DEPTH, name)
+#define NAME1(depth, name) NAME2(depth, name)
+#define NAME2(depth, name) rasops ## depth ## _ ## name
+
+#if RASOPS_DEPTH == 1
+#define PIXEL_SHIFT 0
+#elif RASOPS_DEPTH == 2
+#define PIXEL_SHIFT 1
+#elif RASOPS_DEPTH == 4
+#define PIXEL_SHIFT 2
+#else
+#error "Depth not supported"
+#endif
+
+#define PIXEL_BITS RASOPS_DEPTH
+#define COLOR_MASK __BITS(32 - PIXEL_BITS, 31)
+
+#if RASOPS_DEPTH != 1
+/*
+ * Paint a single character. This function is also applicable to
+ * monochrome, but that in rasops1.c is much simpler and faster.
+ */
+static void
+NAME(putchar)(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 full, cnt, bit;
+ uint32_t fs, rs, fb, bg, fg, lmask, rmask, lbg, rbg, clr[2];
+ uint32_t height, width;
+ uint32_t *rp, *bp, *hp, tmp;
+ uint8_t *fr;
+ bool space;
+
+ hp = NULL; /* XXX GCC */
+
+#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 << PIXEL_SHIFT;
+ col *= width;
+ height = font->fontheight;
+ rp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale +
+ ((col >> 3) & ~3));
+ if (ri->ri_hwbits)
+ hp = (uint32_t *)(ri->ri_hwbits + row * ri->ri_yscale +
+ ((col >> 3) & ~3));
+ 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 (uc == ' ' || __predict_false(fg == bg)) {
+ space = true;
+ fr = NULL; /* XXX GCC */
+ fs = 0; /* XXX GCC */
+ } else {
+ space = false;
+ fr = FONT_GLYPH(uc, font, ri);
+ fs = font->stride;
+ }
+
+ if (col + width <= 32) {
+ /* Single word, only one mask */
+
+ rmask = rasops_pmask[col][width & 31];
+ lmask = ~rmask;
+
+ if (space) {
+ bg &= rmask;
+ while (height--) {
+ tmp = (*rp & lmask) | bg;
+ *rp = tmp;
+ DELTA(rp, rs, uint32_t *);
+ if (ri->ri_hwbits) {
+ *hp = tmp;
+ DELTA(hp, rs, uint32_t *);
+ }
+ }
+ } else {
+ clr[0] = bg & COLOR_MASK;
+ clr[1] = fg & COLOR_MASK;
+ while (height--) {
+ fb = be32uatoh(fr);
+ fr += fs;
+ tmp = 0;
+ for (bit = col; bit < col + width;
+ bit += PIXEL_BITS) {
+ tmp |= clr[(fb >> 31) & 1] >> bit;
+ fb <<= 1;
+ }
+ tmp = (*rp & lmask) | MBE(tmp);
+ *rp = tmp;
+ DELTA(rp, rs, uint32_t *);
+ if (ri->ri_hwbits) {
+ *hp = tmp;
+ DELTA(hp, rs, uint32_t *);
+ }
+ }
+ }
+
+ /* Do underline */
+ if ((attr & WSATTR_UNDERLINE) != 0) {
+ DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
+ tmp = (*rp & lmask) | (fg & rmask);
+ *rp = tmp;
+ if (ri->ri_hwbits) {
+ DELTA(hp, -(ri->ri_stride << 1), uint32_t *);
+ *hp = tmp;
+ }
+ }
+
+ return;
+ }
+
+ /* Word boundary, two masks needed */
+
+ lmask = ~rasops_lmask[col];
+ rmask = ~rasops_rmask[(col + width) & 31];
+
+ if (lmask != -1)
+ width -= 32 - col;
+ full = width / 32;
+ width -= full * 32;
+
+ if (space) {
+ lbg = bg & ~lmask;
+ rbg = bg & ~rmask;
+
+ while (height--) {
+ bp = rp;
+
+ if (lmask != -1) {
+ *bp = (*bp & lmask) | lbg;
+ bp++;
+ }
+
+ for (cnt = full; cnt; cnt--)
+ *bp++ = bg;
+
+ if (rmask != -1)
+ *bp = (*bp & rmask) | rbg;
+
+ if (ri->ri_hwbits) {
+ memcpy(hp, rp, ((lmask != -1) + full +
+ (rmask != -1)) << 2);
+ DELTA(hp, rs, uint32_t *);
+ }
+ DELTA(rp, rs, uint32_t *);
+ }
+ } else {
+ clr[0] = bg & COLOR_MASK;
+ clr[1] = fg & COLOR_MASK;
+
+ while (height--) {
+ bp = rp;
+
+ fb = be32uatoh(fr);
+ fr += fs;
+
+ if (lmask != -1) {
+ tmp = 0;
+ for (bit = col; bit < 32; bit += PIXEL_BITS) {
+ tmp |= clr[(fb >> 31) & 1] >> bit;
+ fb <<= 1;
+ }
+ *bp = (*bp & lmask) | MBE(tmp);
+ bp++;
+ }
+
+ for (cnt = full; cnt; cnt--) {
+ tmp = 0;
+ for (bit = 0; bit < 32; bit += PIXEL_BITS) {
+ tmp |= clr[(fb >> 31) & 1] >> bit;
+ fb <<= 1;
+ }
+ *bp++ = MBE(tmp);
+ }
+
+ if (rmask != -1) {
+ tmp = 0;
+ for (bit = 0; bit < width; bit += PIXEL_BITS) {
+ tmp |= clr[(fb >> 31) & 1] >> bit;
+ fb <<= 1;
+ }
+ *bp = (*bp & rmask) | MBE(tmp);
+ }
+
+ if (ri->ri_hwbits) {
+ memcpy(hp, rp, ((lmask != -1) + full +
+ (rmask != -1)) << 2);
+ DELTA(hp, rs, uint32_t *);
+ }
+
+ DELTA(rp, rs, uint32_t *);
+ }
+ }
+
+ /* Do underline */
+ if ((attr & WSATTR_UNDERLINE) != 0) {
+ DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
+ bp = rp;
+ if (lmask != -1) {
+ *bp = (*bp & lmask) | (fg & ~lmask);
+ bp++;
+ }
+ for (cnt = full; cnt; cnt--)
+ *bp++ = fg;
+ if (rmask != -1)
+ *bp = (*bp & rmask) | (fg & ~rmask);
+ if (ri->ri_hwbits) {
+ DELTA(hp, -(ri->ri_stride << 1), uint32_t *);
+ memcpy(hp, rp, ((lmask != -1) + full +
+ (rmask != -1)) << 2);
+ }
+ }
+}
+#endif /* RASOPS_DEPTH != 1 */
+
/*
* Erase columns.
*/
@@ -379,4 +606,8 @@ NAME(copycols)(void *cookie, int row, int src, int dst, int num)
}
}
+#undef PIXEL_SHIFT
+#undef PIXEL_BITS
+#undef COLOR_MASK
+
#endif /* _RASOPS_BITOPS_H_ */