Module Name: src
Committed By: rin
Date: Mon Jul 29 10:55:56 UTC 2019
Modified Files:
src/sys/dev/rasops: rasops15.c rasops32.c rasops8.c
Added Files:
src/sys/dev/rasops: rasops_putchar_aa.h
Log Message:
Factor out putchar_aa functions into rasops_putchar_aa.h, which includes
the following fixes:
- stop using memset to framebuffer for depth 8
- correctly support non-standard positions/lengths of RGB bits in pixel
To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/dev/rasops/rasops15.c
cvs rdiff -u -r1.38 -r1.39 src/sys/dev/rasops/rasops32.c
cvs rdiff -u -r1.43 -r1.44 src/sys/dev/rasops/rasops8.c
cvs rdiff -u -r0 -r1.1 src/sys/dev/rasops/rasops_putchar_aa.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/rasops15.c
diff -u src/sys/dev/rasops/rasops15.c:1.30 src/sys/dev/rasops/rasops15.c:1.31
--- src/sys/dev/rasops/rasops15.c:1.30 Sun Jul 28 12:06:10 2019
+++ src/sys/dev/rasops/rasops15.c Mon Jul 29 10:55:56 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: rasops15.c,v 1.30 2019/07/28 12:06:10 rin Exp $ */
+/* $NetBSD: rasops15.c,v 1.31 2019/07/29 10:55:56 rin Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops15.c,v 1.30 2019/07/28 12:06:10 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops15.c,v 1.31 2019/07/29 10:55:56 rin Exp $");
#include "opt_rasops.h"
@@ -110,97 +110,7 @@ rasops15_init(struct rasops_info *ri)
#define RASOPS_DEPTH 15
#include "rasops_putchar.h"
-
-static void
-rasops15_putchar_aa(void *cookie, int row, int col, u_int uc, long attr)
-{
- int width, height, cnt, clr[2];
- struct rasops_info *ri = (struct rasops_info *)cookie;
- struct wsdisplay_font *font = PICK_FONT(ri, uc);
- uint16_t *dp, *rp;
- uint8_t *rrp;
- uint8_t *fr;
- uint16_t buffer[64]; /* XXX */
- int x, y, r, g, b, aval;
- int r1, g1, b1, r0, g0, b0, fgo, bgo;
-
-#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
-
- /* check if character fits into font limits */
- if (!CHAR_IN_FONT(uc, font))
- return;
-
- rrp = (ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
- rp = (uint16_t *)rrp;
-
- height = font->fontheight;
- width = font->fontwidth;
-
- clr[0] = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
- clr[1] = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf];
-
- if (uc == ' ') {
- for (cnt = 0; cnt < width; cnt++)
- buffer[cnt] = clr[0];
- for (y = 0; y < height; y++) {
- dp = rp;
- DELTA(rp, ri->ri_stride, uint16_t *);
- memcpy(dp, buffer, width << 1);
- }
- } else {
- fr = FONT_GLYPH(uc, font, ri);
-
- fgo = (((uint32_t)attr >> 24) & 0xf) * 3;
- bgo = (((uint32_t)attr >> 16) & 0xf) * 3;
-
- r0 = rasops_cmap[bgo];
- r1 = rasops_cmap[fgo];
- g0 = rasops_cmap[bgo + 1];
- g1 = rasops_cmap[fgo + 1];
- b0 = rasops_cmap[bgo + 2];
- b1 = rasops_cmap[fgo + 2];
-
- for (y = 0; y < height; y++) {
- dp = (uint16_t *)(rrp + ri->ri_stride * y);
- for (x = 0; x < width; x++) {
- aval = *fr;
- if (aval == 0) {
- buffer[x] = clr[0];
- } else if (aval == 255) {
- buffer[x] = clr[1];
- } else {
- r = aval * r1 + (255 - aval) * r0;
- g = aval * g1 + (255 - aval) * g0;
- b = aval * b1 + (255 - aval) * b0;
- buffer[x] =
- ((r >> (16 - ri->ri_rnum)) <<
- ri->ri_rpos) |
- ((g >> (16 - ri->ri_gnum)) <<
- ri->ri_gpos) |
- ((b >> (16 - ri->ri_bnum)) <<
- ri->ri_bpos);
- }
- fr++;
- }
- memcpy(dp, buffer, width << 1);
- }
- }
-
- /* Do underline */
- if ((attr & WSATTR_UNDERLINE) != 0) {
- rp = (uint16_t *)rrp;
- DELTA(rp, (ri->ri_stride * (height - 2)), uint16_t *);
- while (width--)
- *rp++ = clr[1];
- }
-}
+#include "rasops_putchar_aa.h"
#ifndef RASOPS_SMALL
/*
Index: src/sys/dev/rasops/rasops32.c
diff -u src/sys/dev/rasops/rasops32.c:1.38 src/sys/dev/rasops/rasops32.c:1.39
--- src/sys/dev/rasops/rasops32.c:1.38 Sun Jul 28 12:06:10 2019
+++ src/sys/dev/rasops/rasops32.c Mon Jul 29 10:55:56 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: rasops32.c,v 1.38 2019/07/28 12:06:10 rin Exp $ */
+/* $NetBSD: rasops32.c,v 1.39 2019/07/29 10:55:56 rin Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.38 2019/07/28 12:06:10 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.39 2019/07/29 10:55:56 rin Exp $");
#include "opt_rasops.h"
@@ -109,91 +109,7 @@ rasops32_init(struct rasops_info *ri)
#define RASOPS_DEPTH 32
#include "rasops_putchar.h"
-
-static void
-rasops32_putchar_aa(void *cookie, int row, int col, u_int uc, long attr)
-{
- int width, height, cnt, clr[2];
- struct rasops_info *ri = (struct rasops_info *)cookie;
- struct wsdisplay_font *font = PICK_FONT(ri, uc);
- uint32_t *dp, *rp;
- uint8_t *rrp;
- uint8_t *fr;
- uint32_t buffer[64]; /* XXX */
- int x, y, r, g, b, aval;
- int r1, g1, b1, r0, g0, b0;
-
-#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
-
- /* check if character fits into font limits */
- if (!CHAR_IN_FONT(uc, font))
- return;
-
- rrp = (ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
- rp = (uint32_t *)rrp;
-
- height = font->fontheight;
- width = font->fontwidth;
-
- clr[0] = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
- clr[1] = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf];
-
- if (uc == ' ') {
- for (cnt = 0; cnt < width; cnt++)
- buffer[cnt] = clr[0];
- while (height--) {
- dp = rp;
- DELTA(rp, ri->ri_stride, uint32_t *);
- memcpy(dp, buffer, width << 2);
- }
- } else {
- fr = FONT_GLYPH(uc, font, ri);
-
- r0 = (clr[0] >> 16) & 0xff;
- r1 = (clr[1] >> 16) & 0xff;
- g0 = (clr[0] >> 8) & 0xff;
- g1 = (clr[1] >> 8) & 0xff;
- b0 = clr[0] & 0xff;
- b1 = clr[1] & 0xff;
-
- for (y = 0; y < height; y++) {
- dp = (uint32_t *)(rrp + ri->ri_stride * y);
- for (x = 0; x < width; x++) {
- aval = *fr;
- if (aval == 0) {
- buffer[x] = clr[0];
- } else if (aval == 255) {
- buffer[x] = clr[1];
- } else {
- r = aval * r1 + (255 - aval) * r0;
- g = aval * g1 + (255 - aval) * g0;
- b = aval * b1 + (255 - aval) * b0;
- buffer[x] = (r & 0xff00) << 8 |
- (g & 0xff00) |
- (b & 0xff00) >> 8;
- }
- fr++;
- }
- memcpy(dp, buffer, width << 2);
- }
- }
-
- /* Do underline */
- if ((attr & WSATTR_UNDERLINE) != 0) {
- rp = (uint32_t *)rrp;
- height = font->fontheight;
- DELTA(rp, (ri->ri_stride * (height - 2)), uint32_t *);
- while (width--)
- *rp++ = clr[1];
- }
-}
+#include "rasops_putchar_aa.h"
#ifndef RASOPS_SMALL
/*
Index: src/sys/dev/rasops/rasops8.c
diff -u src/sys/dev/rasops/rasops8.c:1.43 src/sys/dev/rasops/rasops8.c:1.44
--- src/sys/dev/rasops/rasops8.c:1.43 Sun Jul 28 12:06:10 2019
+++ src/sys/dev/rasops/rasops8.c Mon Jul 29 10:55:56 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: rasops8.c,v 1.43 2019/07/28 12:06:10 rin Exp $ */
+/* $NetBSD: rasops8.c,v 1.44 2019/07/29 10:55:56 rin Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops8.c,v 1.43 2019/07/28 12:06:10 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops8.c,v 1.44 2019/07/29 10:55:56 rin Exp $");
#include "opt_rasops.h"
@@ -107,108 +107,7 @@ rasops8_init(struct rasops_info *ri)
#define RASOPS_DEPTH 8
#include "rasops_putchar.h"
-
-static void
-rasops8_putchar_aa(void *cookie, int row, int col, u_int uc, long attr)
-{
- int width, height;
- uint8_t *rp, *hrp, *fr, bg, fg, pixel;
- struct rasops_info *ri = (struct rasops_info *)cookie;
- struct wsdisplay_font *font = PICK_FONT(ri, uc);
- int x, y, r, g, b, aval;
- int r1, g1, b1, r0, g0, b0, fgo, bgo;
- uint8_t scanline[32] __attribute__ ((aligned(8)));
-
- hrp = NULL; /* XXX GCC */
-
- if (!CHAR_IN_FONT(uc, font))
- return;
-
-#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
- rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
- if (ri->ri_hwbits)
- hrp = ri->ri_hwbits + row * ri->ri_yscale + col *
- ri->ri_xscale;
-
- height = font->fontheight;
- width = font->fontwidth;
- bg = (uint8_t)ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
- fg = (uint8_t)ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf];
-
- if (uc == ' ') {
-
- while (height--) {
- memset(rp, bg, width);
- if (ri->ri_hwbits) {
- memset(hrp, bg, width);
- hrp += ri->ri_stride;
- }
- rp += ri->ri_stride;
- }
- } else {
- fr = FONT_GLYPH(uc, font, ri);
- /*
- * we need the RGB colours here, get offsets into rasops_cmap
- */
- fgo = (((uint32_t)attr >> 24) & 0xf) * 3;
- bgo = (((uint32_t)attr >> 16) & 0xf) * 3;
-
- r0 = rasops_cmap[bgo];
- r1 = rasops_cmap[fgo];
- g0 = rasops_cmap[bgo + 1];
- g1 = rasops_cmap[fgo + 1];
- b0 = rasops_cmap[bgo + 2];
- b1 = rasops_cmap[fgo + 2];
-
- for (y = 0; y < height; y++) {
- for (x = 0; x < width; x++) {
- aval = *fr;
- fr++;
- if (aval == 0) {
- pixel = bg;
- } else if (aval == 255) {
- pixel = fg;
- } else {
- r = aval * r1 + (255 - aval) * r0;
- g = aval * g1 + (255 - aval) * g0;
- b = aval * b1 + (255 - aval) * b0;
- pixel = ((r & 0xe000) >> 8) |
- ((g & 0xe000) >> 11) |
- ((b & 0xc000) >> 14);
- }
- scanline[x] = pixel;
- }
- memcpy(rp, scanline, width);
- if (ri->ri_hwbits) {
- memcpy(hrp, scanline, width);
- hrp += ri->ri_stride;
- }
- rp += ri->ri_stride;
-
- }
- }
-
- /* Do underline */
- if ((attr & WSATTR_UNDERLINE) != 0) {
-
- rp -= (ri->ri_stride << 1);
- if (ri->ri_hwbits)
- hrp -= (ri->ri_stride << 1);
-
- while (width--) {
- *rp++ = fg;
- if (ri->ri_hwbits)
- *hrp++ = fg;
- }
- }
-}
+#include "rasops_putchar_aa.h"
#ifndef RASOPS_SMALL
/*
Added files:
Index: src/sys/dev/rasops/rasops_putchar_aa.h
diff -u /dev/null src/sys/dev/rasops/rasops_putchar_aa.h:1.1
--- /dev/null Mon Jul 29 10:55:56 2019
+++ src/sys/dev/rasops/rasops_putchar_aa.h Mon Jul 29 10:55:56 2019
@@ -0,0 +1,180 @@
+/* $NetBSD: rasops_putchar_aa.h,v 1.1 2019/07/29 10:55:56 rin Exp $ */
+
+/* NetBSD: rasops8.c,v 1.43 2019/07/28 12:06:10 rin Exp */
+/*-
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if RASOPS_DEPTH != 8 && RASOPS_DEPTH != 15 && /* RASOPS_DEPTH != 24 && */ \
+ RASOPS_DEPTH != 32
+#error "Depth not supported"
+#endif
+
+#define PUTCHAR_AA(depth) PUTCHAR_AA1(depth)
+#define PUTCHAR_AA1(depth) rasops ## depth ## _putchar_aa
+
+#if RASOPS_DEPTH == 8
+#define PIXEL_TYPE uint8_t
+#define PIXEL_BITS 8
+#elif RASOPS_DEPTH == 15
+#define PIXEL_TYPE uint16_t
+#define PIXEL_BITS 16
+#elif RASOPS_DEPTH == 32
+#define PIXEL_TYPE uint32_t
+#define PIXEL_BITS 32
+#endif
+
+#define MAX_WIDTH 64 /* XXX */
+
+static void
+PUTCHAR_AA(RASOPS_DEPTH)(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, width, bgo, fgo, x, y;
+ uint8_t *fr, r0, r1, g0, g1, b0, b1, aval;
+#if RASOPS_DEPTH == 8
+ uint16_t r, g, b;
+#else
+ PIXEL_TYPE r, g, b;
+#endif
+ PIXEL_TYPE *rp, *hp, bg, fg, pixel;
+ PIXEL_TYPE buf[MAX_WIDTH] __attribute__ ((aligned(8))); /* XXX */
+
+ hp = NULL; /* XXX GCC */
+
+ if (!CHAR_IN_FONT(uc, font))
+ return;
+
+#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
+
+ rp = (PIXEL_TYPE *)(ri->ri_bits + row * ri->ri_yscale +
+ col * ri->ri_xscale);
+ if (ri->ri_hwbits)
+ hp = (PIXEL_TYPE *)(ri->ri_hwbits + row * ri->ri_yscale +
+ col * ri->ri_xscale);
+
+ height = font->fontheight;
+
+ /* XXX */
+ width = font->fontwidth;
+ if (__predict_false(width > MAX_WIDTH))
+ width = MAX_WIDTH;
+
+ bg = (PIXEL_TYPE)ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
+ fg = (PIXEL_TYPE)ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf];
+
+ if (uc == ' ') {
+#if RASOPS_DEPTH == 8
+ memset(buf, bg, width);
+#else
+ for (x = 0; x < width; x++)
+ buf[x] = bg;
+#endif
+ while (height--) {
+ memcpy(rp, buf, width * sizeof(PIXEL_TYPE));
+ DELTA(rp, ri->ri_stride, PIXEL_TYPE *);
+ if (ri->ri_hwbits) {
+ memcpy(hp, buf, width * sizeof(PIXEL_TYPE));
+ DELTA(hp, ri->ri_stride, PIXEL_TYPE *);
+ }
+ }
+ } else {
+ fr = FONT_GLYPH(uc, font, ri);
+
+ /*
+ * This is independent to positions/lengths of RGB in pixel.
+ */
+ bgo = (((uint32_t)attr >> 16) & 0xf) * 3;
+ fgo = (((uint32_t)attr >> 24) & 0xf) * 3;
+
+ r0 = rasops_cmap[bgo];
+ r1 = rasops_cmap[fgo];
+ g0 = rasops_cmap[bgo + 1];
+ g1 = rasops_cmap[fgo + 1];
+ b0 = rasops_cmap[bgo + 2];
+ b1 = rasops_cmap[fgo + 2];
+
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++) {
+ aval = *fr;
+ fr++;
+ if (aval == 0) {
+ pixel = bg;
+ } else if (aval == 255) {
+ pixel = fg;
+ } else {
+ r = aval * r1 + (0xff - aval) * r0;
+ g = aval * g1 + (0xff - aval) * g0;
+ b = aval * b1 + (0xff - aval) * b0;
+#define RGB2PIXEL(r, g, b) \
+ ((((r) & 0xff00) >> (8 + 8 - ri->ri_rnum)) << ri->ri_rpos) | \
+ ((((g) & 0xff00) >> (8 + 8 - ri->ri_gnum)) << ri->ri_gpos) | \
+ ((((b) & 0xff00) >> (8 + 8 - ri->ri_bnum)) << ri->ri_bpos)
+ pixel = RGB2PIXEL(r, g, b);
+#undef RGB2PIXEL
+ }
+ buf[x] = pixel;
+ }
+ memcpy(rp, buf, width * sizeof(PIXEL_TYPE));
+ DELTA(rp, ri->ri_stride, PIXEL_TYPE *);
+ if (ri->ri_hwbits) {
+ memcpy(hp, buf, width * sizeof(PIXEL_TYPE));
+ DELTA(hp, ri->ri_stride, PIXEL_TYPE *);
+ }
+ }
+ }
+
+ /* Do underline */
+ if ((attr & WSATTR_UNDERLINE) != 0) {
+ DELTA(rp, -(ri->ri_stride << 1), PIXEL_TYPE *);
+ if (ri->ri_hwbits) {
+ DELTA(hp, -(ri->ri_stride << 1), PIXEL_TYPE *);
+ }
+ while (width--) {
+ *rp++ = fg;
+ if (ri->ri_hwbits)
+ *hp++ = fg;
+ }
+ }
+}
+
+#undef PUTCHAR_AA
+#undef PUTCHAR_AA1
+
+#undef PIXEL_TYPE
+#undef PIXEL_BITS
+
+#undef MAX_WIDTH