Module Name:    src
Committed By:   riastradh
Date:           Sun Jul 17 10:28:09 UTC 2022

Modified Files:
        src/sys/arch/arm/omap: omapfb.c
        src/sys/arch/arm/ti: omap3_dss.c
        src/sys/dev/pci: wcfb.c
        src/sys/dev/wscons: wsdisplay_vcons.c wsdisplay_vconsvar.h

Log Message:
wsdisplay(4): Factor out WSDISPLAY_SCROLLSUPPORT logic.

Should find a way to avoid the #ifdefs in the .h file, but this makes
the code a good deal more legible and easier to maitain, at least.
No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/arm/omap/omapfb.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/ti/omap3_dss.c
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/pci/wcfb.c
cvs rdiff -u -r1.55 -r1.56 src/sys/dev/wscons/wsdisplay_vcons.c
cvs rdiff -u -r1.31 -r1.32 src/sys/dev/wscons/wsdisplay_vconsvar.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/arch/arm/omap/omapfb.c
diff -u src/sys/arch/arm/omap/omapfb.c:1.30 src/sys/arch/arm/omap/omapfb.c:1.31
--- src/sys/arch/arm/omap/omapfb.c:1.30	Sat Aug  7 16:18:45 2021
+++ src/sys/arch/arm/omap/omapfb.c	Sun Jul 17 10:28:09 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: omapfb.c,v 1.30 2021/08/07 16:18:45 thorpej Exp $	*/
+/*	$NetBSD: omapfb.c,v 1.31 2022/07/17 10:28:09 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2010 Michael Lorenz
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: omapfb.c,v 1.30 2021/08/07 16:18:45 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: omapfb.c,v 1.31 2022/07/17 10:28:09 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -980,9 +980,7 @@ omapfb_cursor(void *cookie, int on, int 
 	int pos;
 
 	pos = col + row * ri->ri_cols;
-#ifdef WSDISPLAY_SCROLLSUPPORT
-	pos += scr->scr_offset_to_zero;
-#endif
+	pos += vcons_offset_to_zero(scr);
 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
 		if (ri->ri_flg & RI_CURSOR) {
 			omapfb_putchar(cookie, row, col, scr->scr_chars[pos],

Index: src/sys/arch/arm/ti/omap3_dss.c
diff -u src/sys/arch/arm/ti/omap3_dss.c:1.5 src/sys/arch/arm/ti/omap3_dss.c:1.6
--- src/sys/arch/arm/ti/omap3_dss.c:1.5	Sat Aug  7 16:18:46 2021
+++ src/sys/arch/arm/ti/omap3_dss.c	Sun Jul 17 10:28:09 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: omap3_dss.c,v 1.5 2021/08/07 16:18:46 thorpej Exp $	*/
+/*	$NetBSD: omap3_dss.c,v 1.6 2022/07/17 10:28:09 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2010 Michael Lorenz
@@ -33,7 +33,7 @@
 #include "opt_wsdisplay_compat.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: omap3_dss.c,v 1.5 2021/08/07 16:18:46 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: omap3_dss.c,v 1.6 2022/07/17 10:28:09 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -993,9 +993,7 @@ omapfb_cursor(void *cookie, int on, int 
 	int pos;
 
 	pos = col + row * ri->ri_cols;
-#ifdef WSDISPLAY_SCROLLSUPPORT
-	pos += scr->scr_offset_to_zero;
-#endif
+	pos += vcons_offset_to_zero(scr);
 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
 		if (ri->ri_flg & RI_CURSOR) {
 			omapfb_putchar(cookie, row, col, scr->scr_chars[pos],

Index: src/sys/dev/pci/wcfb.c
diff -u src/sys/dev/pci/wcfb.c:1.20 src/sys/dev/pci/wcfb.c:1.21
--- src/sys/dev/pci/wcfb.c:1.20	Sat Aug  7 16:19:14 2021
+++ src/sys/dev/pci/wcfb.c	Sun Jul 17 10:28:09 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: wcfb.c,v 1.20 2021/08/07 16:19:14 thorpej Exp $ */
+/*	$NetBSD: wcfb.c,v 1.21 2022/07/17 10:28:09 riastradh Exp $ */
 
 /*
  * Copyright (c) 2007, 2008, 2009 Miodrag Vallat.
@@ -20,7 +20,7 @@
 /* a driver for (some) 3DLabs Wildcat cards, based on OpenBSD's ifb driver */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wcfb.c,v 1.20 2021/08/07 16:19:14 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wcfb.c,v 1.21 2022/07/17 10:28:09 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -590,9 +590,7 @@ wcfb_cursor(void *cookie, int on, int ro
 		if (ri->ri_flg & RI_CURSOR) {
 			/* remove cursor */
 			coffset = ri->ri_ccol + (ri->ri_crow * ri->ri_cols);
-#ifdef WSDISPLAY_SCROLLSUPPORT
-			coffset += scr->scr_offset_to_zero;
-#endif
+			coffset += vcons_offset_to_zero(scr);
 			wcfb_putchar(cookie, ri->ri_crow,
 			    ri->ri_ccol, scr->scr_chars[coffset],
 			    scr->scr_attrs[coffset]);

Index: src/sys/dev/wscons/wsdisplay_vcons.c
diff -u src/sys/dev/wscons/wsdisplay_vcons.c:1.55 src/sys/dev/wscons/wsdisplay_vcons.c:1.56
--- src/sys/dev/wscons/wsdisplay_vcons.c:1.55	Sun Jul 17 10:27:45 2022
+++ src/sys/dev/wscons/wsdisplay_vcons.c	Sun Jul 17 10:28:09 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: wsdisplay_vcons.c,v 1.55 2022/07/17 10:27:45 riastradh Exp $ */
+/*	$NetBSD: wsdisplay_vcons.c,v 1.56 2022/07/17 10:28:09 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2005, 2006 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wsdisplay_vcons.c,v 1.55 2022/07/17 10:27:45 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wsdisplay_vcons.c,v 1.56 2022/07/17 10:28:09 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -878,21 +878,12 @@ vcons_copycols_buffer(void *cookie, int 
 	struct vcons_screen *scr = ri->ri_hw;
 	int from = srccol + row * ri->ri_cols;
 	int to = dstcol + row * ri->ri_cols;
-
-#ifdef WSDISPLAY_SCROLLSUPPORT
-	int offset;
-	offset = scr->scr_offset_to_zero;
+	int offset = vcons_offset_to_zero(scr);
 
 	memmove(&scr->scr_attrs[offset + to], &scr->scr_attrs[offset + from],
 	    ncols * sizeof(long));
 	memmove(&scr->scr_chars[offset + to], &scr->scr_chars[offset + from],
 	    ncols * sizeof(uint32_t));
-#else
-	memmove(&scr->scr_attrs[to], &scr->scr_attrs[from],
-	    ncols * sizeof(long));
-	memmove(&scr->scr_chars[to], &scr->scr_chars[from],
-	    ncols * sizeof(uint32_t));
-#endif
 
 #ifdef VCONS_DRAW_INTR
 	atomic_inc_uint(&scr->scr_dirty);
@@ -973,21 +964,12 @@ vcons_erasecols_buffer(void *cookie, int
 	struct vcons_screen *scr = ri->ri_hw;
 	int start = startcol + row * ri->ri_cols;
 	int end = start + ncols, i;
-
-#ifdef WSDISPLAY_SCROLLSUPPORT
-	int offset;
-	offset = scr->scr_offset_to_zero;
+	int offset = vcons_offset_to_zero(scr);
 
 	for (i = start; i < end; i++) {
 		scr->scr_attrs[offset + i] = fillattr;
 		scr->scr_chars[offset + i] = 0x20;
 	}
-#else
-	for (i = start; i < end; i++) {
-		scr->scr_attrs[i] = fillattr;
-		scr->scr_chars[i] = 0x20;
-	}
-#endif
 
 #ifdef VCONS_DRAW_INTR
 	atomic_inc_uint(&scr->scr_dirty);
@@ -1042,30 +1024,22 @@ vcons_copyrows_buffer(void *cookie, int 
 	struct rasops_info *ri = cookie;
 	struct vcons_screen *scr = ri->ri_hw;
 	int from, to, len;
-
-#ifdef WSDISPLAY_SCROLLSUPPORT
-	int offset;
-	offset = scr->scr_offset_to_zero;
+	int offset = vcons_offset_to_zero(scr);
 
 	/* do we need to scroll the back buffer? */
-	if (dstrow == 0) {
+	if (dstrow == 0 && offset != 0) {
 		from = ri->ri_cols * srcrow;
 		to = ri->ri_cols * dstrow;
 
 		memmove(&scr->scr_attrs[to], &scr->scr_attrs[from],
-		    scr->scr_offset_to_zero * sizeof(long));
+		    offset * sizeof(long));
 		memmove(&scr->scr_chars[to], &scr->scr_chars[from],
-		    scr->scr_offset_to_zero * sizeof(uint32_t));
+		    offset * sizeof(uint32_t));
 	}
 	from = ri->ri_cols * srcrow + offset;
 	to = ri->ri_cols * dstrow + offset;
 	len = ri->ri_cols * nrows;
 
-#else
-	from = ri->ri_cols * srcrow;
-	to = ri->ri_cols * dstrow;
-	len = ri->ri_cols * nrows;
-#endif
 	memmove(&scr->scr_attrs[to], &scr->scr_attrs[from],
 	    len * sizeof(long));
 	memmove(&scr->scr_chars[to], &scr->scr_chars[from],
@@ -1148,18 +1122,11 @@ vcons_eraserows_buffer(void *cookie, int
 {
 	struct rasops_info *ri = cookie;
 	struct vcons_screen *scr = ri->ri_hw;
+	int offset = vcons_offset_to_zero(scr);
 	int start, end, i;
 
-#ifdef WSDISPLAY_SCROLLSUPPORT
-	int offset;
-	offset = scr->scr_offset_to_zero;
-
 	start = ri->ri_cols * row + offset;
 	end = ri->ri_cols * (row + nrows) + offset;
-#else
-	start = ri->ri_cols * row;
-	end = ri->ri_cols * (row + nrows);
-#endif
 
 	for (i = start; i < end; i++) {
 		scr->scr_attrs[i] = fillattr;
@@ -1217,26 +1184,15 @@ vcons_putchar_buffer(void *cookie, int r
 {
 	struct rasops_info *ri = cookie;
 	struct vcons_screen *scr = ri->ri_hw;
+	int offset = vcons_offset_to_zero(scr);
 	int pos;
 
-#ifdef WSDISPLAY_SCROLLSUPPORT
-	int offset;
-	offset = scr->scr_offset_to_zero;
-
 	if ((row >= 0) && (row < ri->ri_rows) && (col >= 0) &&
 	     (col < ri->ri_cols)) {
 		pos = col + row * ri->ri_cols;
 		scr->scr_attrs[pos + offset] = attr;
 		scr->scr_chars[pos + offset] = c;
 	}
-#else
-	if ((row >= 0) && (row < ri->ri_rows) && (col >= 0) &&
-	     (col < ri->ri_cols)) {
-		pos = col + row * ri->ri_cols;
-		scr->scr_attrs[pos] = attr;
-		scr->scr_chars[pos] = c;
-	}
-#endif
 
 #ifdef VCONS_DRAW_INTR
 	atomic_inc_uint(&scr->scr_dirty);
@@ -1428,9 +1384,7 @@ vcons_getwschar(struct vcons_screen *scr
 	}
 
 	offset = ri->ri_cols * wsc->row + wsc->col;
-#ifdef WSDISPLAY_SCROLLSUPPORT
-	offset += scr->scr_offset_to_zero;
-#endif
+	offset += vcons_offset_to_zero(scr);
 	wsc->letter = scr->scr_chars[offset];
 	attr = scr->scr_attrs[offset];
 

Index: src/sys/dev/wscons/wsdisplay_vconsvar.h
diff -u src/sys/dev/wscons/wsdisplay_vconsvar.h:1.31 src/sys/dev/wscons/wsdisplay_vconsvar.h:1.32
--- src/sys/dev/wscons/wsdisplay_vconsvar.h:1.31	Thu Jan 21 21:45:42 2021
+++ src/sys/dev/wscons/wsdisplay_vconsvar.h	Sun Jul 17 10:28:09 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: wsdisplay_vconsvar.h,v 1.31 2021/01/21 21:45:42 macallan Exp $ */
+/*	$NetBSD: wsdisplay_vconsvar.h,v 1.32 2022/07/17 10:28:09 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2005, 2006 Michael Lorenz
@@ -170,4 +170,14 @@ void	vcons_enable_polling(struct vcons_d
 void	vcons_disable_polling(struct vcons_data *);
 void	vcons_hard_switch(struct vcons_screen *);
 
+static inline int
+vcons_offset_to_zero(const struct vcons_screen *scr)
+{
+#ifdef WSDISPLAY_SCROLLSUPPORT
+	return scr->scr_offset_to_zero;
+#else
+	return 0;
+#endif
+}
+
 #endif /* _WSDISPLAY_VCONS_H_ */

Reply via email to