svn commit: r352681 - in head/sys/dev/vt: . hw/fb

Toomas Soome tsoome at FreeBSD.org
Wed Sep 25 13:24:33 UTC 2019


Author: tsoome
Date: Wed Sep 25 13:24:31 2019
New Revision: 352681
URL: https://svnweb.freebsd.org/changeset/base/352681

Log:
  vt: use colors from terminal emulator
  
  Instead of hardcoded colors, use terminal state. This also means,
  we need to record the pointer to terminal state with vtbuf.

Modified:
  head/sys/dev/vt/hw/fb/vt_fb.c
  head/sys/dev/vt/vt.h
  head/sys/dev/vt/vt_buf.c
  head/sys/dev/vt/vt_core.c
  head/sys/dev/vt/vt_cpulogos.c

Modified: head/sys/dev/vt/hw/fb/vt_fb.c
==============================================================================
--- head/sys/dev/vt/hw/fb/vt_fb.c	Wed Sep 25 13:21:07 2019	(r352680)
+++ head/sys/dev/vt/hw/fb/vt_fb.c	Wed Sep 25 13:24:31 2019	(r352681)
@@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/malloc.h>
 #include <sys/queue.h>
 #include <sys/fbio.h>
+#include <sys/kernel.h>
 #include <dev/vt/vt.h>
 #include <dev/vt/hw/fb/vt_fb.h>
 #include <dev/vt/colors/vt_termcolors.h>
@@ -453,7 +454,8 @@ vt_fb_init(struct vt_device *vd)
 {
 	struct fb_info *info;
 	u_int margin;
-	int err;
+	int bg, err;
+	term_color_t c;
 
 	info = vd->vd_softc;
 	vd->vd_height = MIN(VT_FB_MAX_HEIGHT, info->fb_height);
@@ -477,8 +479,15 @@ vt_fb_init(struct vt_device *vd)
 		info->fb_cmsize = 16;
 	}
 
+	c = TC_BLACK;
+	TUNABLE_INT_FETCH("teken.bg_color", &bg);
+	if (bg != -1) {
+		if (bg == TC_WHITE)
+			bg |= TC_LIGHT;
+		c = bg;
+	}
 	/* Clear the screen. */
-	vd->vd_driver->vd_blank(vd, TC_BLACK);
+	vd->vd_driver->vd_blank(vd, c);
 
 	/* Wakeup screen. KMS need this. */
 	vt_fb_postswitch(vd);

Modified: head/sys/dev/vt/vt.h
==============================================================================
--- head/sys/dev/vt/vt.h	Wed Sep 25 13:21:07 2019	(r352680)
+++ head/sys/dev/vt/vt.h	Wed Sep 25 13:24:31 2019	(r352681)
@@ -192,6 +192,7 @@ void vt_suspend(struct vt_device *vd);
 
 struct vt_buf {
 	struct mtx		 vb_lock;	/* Buffer lock. */
+	struct terminal		*vb_terminal;
 	term_pos_t		 vb_scr_size;	/* (b) Screen dimensions. */
 	int			 vb_flags;	/* (b) Flags. */
 #define	VBF_CURSOR	0x1	/* Cursor visible. */

Modified: head/sys/dev/vt/vt_buf.c
==============================================================================
--- head/sys/dev/vt/vt_buf.c	Wed Sep 25 13:21:07 2019	(r352680)
+++ head/sys/dev/vt/vt_buf.c	Wed Sep 25 13:24:31 2019	(r352681)
@@ -420,6 +420,8 @@ void
 vtbuf_init_early(struct vt_buf *vb)
 {
 	term_rect_t rect;
+	const teken_attr_t *a;
+	term_char_t c;
 
 	vb->vb_flags |= VBF_CURSOR;
 	vb->vb_roffset = 0;
@@ -433,7 +435,11 @@ vtbuf_init_early(struct vt_buf *vb)
 	rect.tr_begin.tp_row = rect.tr_begin.tp_col = 0;
 	rect.tr_end.tp_col = vb->vb_scr_size.tp_col;
 	rect.tr_end.tp_row = vb->vb_history_size;
-	vtbuf_do_fill(vb, &rect, VTBUF_SPACE_CHAR(TERMINAL_NORM_ATTR));
+
+	a = teken_get_curattr(&vb->vb_terminal->tm_emulator);
+	c = TCOLOR_FG((term_char_t)a->ta_fgcolor) | 
+	    TCOLOR_BG((term_char_t)a->ta_bgcolor);
+	vtbuf_do_fill(vb, &rect, VTBUF_SPACE_CHAR(c));
 	vtbuf_make_undirty(vb);
 	if ((vb->vb_flags & VBF_MTX_INIT) == 0) {
 		mtx_init(&vb->vb_lock, "vtbuf", NULL, MTX_SPIN);
@@ -478,7 +484,12 @@ vtbuf_grow(struct vt_buf *vb, const term_pos_t *p, uns
 	unsigned int w, h, c, r, old_history_size;
 	size_t bufsize, rowssize;
 	int history_full;
+	const teken_attr_t *a;
+	term_char_t ch;
 
+	a = teken_get_curattr(&vb->vb_terminal->tm_emulator);
+	ch = TCOLOR_FG(a->ta_fgcolor) | TCOLOR_BG(a->ta_bgcolor);
+
 	history_size = MAX(history_size, p->tp_row);
 
 	/* Allocate new buffer. */
@@ -544,7 +555,7 @@ vtbuf_grow(struct vt_buf *vb, const term_pos_t *p, uns
 			 * background color.
 			 */
 			for (c = MIN(p->tp_col, w); c < p->tp_col; c++) {
-				row[c] = VTBUF_SPACE_CHAR(TERMINAL_NORM_ATTR);
+				row[c] = VTBUF_SPACE_CHAR(ch);
 			}
 		}
 
@@ -552,7 +563,7 @@ vtbuf_grow(struct vt_buf *vb, const term_pos_t *p, uns
 		for (r = old_history_size; r < history_size; r++) {
 			row = rows[r];
 			for (c = MIN(p->tp_col, w); c < p->tp_col; c++) {
-				row[c] = VTBUF_SPACE_CHAR(TERMINAL_NORM_ATTR);
+				row[c] = VTBUF_SPACE_CHAR(ch);
 			}
 		}
 
@@ -601,7 +612,7 @@ vtbuf_grow(struct vt_buf *vb, const term_pos_t *p, uns
 			 * background color.
 			 */
 			for (c = MIN(p->tp_col, w); c < p->tp_col; c++) {
-				row[c] = VTBUF_SPACE_CHAR(TERMINAL_NORM_ATTR);
+				row[c] = VTBUF_SPACE_CHAR(ch);
 			}
 		}
 

Modified: head/sys/dev/vt/vt_core.c
==============================================================================
--- head/sys/dev/vt/vt_core.c	Wed Sep 25 13:21:07 2019	(r352680)
+++ head/sys/dev/vt/vt_core.c	Wed Sep 25 13:24:31 2019	(r352681)
@@ -1241,7 +1241,7 @@ vt_mark_mouse_position_as_dirty(struct vt_device *vd, 
 
 static void
 vt_set_border(struct vt_device *vd, const term_rect_t *area,
-    const term_color_t c)
+    term_color_t c)
 {
 	vd_drawrect_t *drawrect = vd->vd_driver->vd_drawrect;
 
@@ -1334,9 +1334,12 @@ vt_flush(struct vt_device *vd)
 
 	/* Force a full redraw when the screen contents might be invalid. */
 	if (vd->vd_flags & (VDF_INVALID | VDF_SUSPENDED)) {
+		const teken_attr_t *a;
+
 		vd->vd_flags &= ~VDF_INVALID;
 
-		vt_set_border(vd, &vw->vw_draw_area, TC_BLACK);
+		a = teken_get_curattr(&vw->vw_terminal->tm_emulator);
+		vt_set_border(vd, &vw->vw_draw_area, a->ta_bgcolor);
 		vt_termrect(vd, vf, &tarea);
 		if (vd->vd_driver->vd_invalidate_text)
 			vd->vd_driver->vd_invalidate_text(vd, &tarea);
@@ -1440,8 +1443,7 @@ vtterm_cnprobe(struct terminal *tm, struct consdev *cp
 	struct vt_window *vw = tm->tm_softc;
 	struct vt_device *vd = vw->vw_device;
 	struct winsize wsz;
-	term_attr_t attr;
-	term_char_t c;
+	const term_attr_t *a;
 
 	if (!vty_enabled(VTY_VT))
 		return;
@@ -1494,14 +1496,12 @@ vtterm_cnprobe(struct terminal *tm, struct consdev *cp
 	if (vd->vd_width != 0 && vd->vd_height != 0)
 		vt_termsize(vd, vw->vw_font, &vw->vw_buf.vb_scr_size);
 
+	/* We need to access terminal attributes from vtbuf */
+	vw->vw_buf.vb_terminal = tm;
 	vtbuf_init_early(&vw->vw_buf);
 	vt_winsize(vd, vw->vw_font, &wsz);
-	c = (boothowto & RB_MUTE) == 0 ? TERMINAL_KERN_ATTR :
-	    TERMINAL_NORM_ATTR;
-	attr.ta_format = TCHAR_FORMAT(c);
-	attr.ta_fgcolor = TCHAR_FGCOLOR(c);
-	attr.ta_bgcolor = TCHAR_BGCOLOR(c);
-	terminal_set_winsize_blank(tm, &wsz, 1, &attr);
+	a = teken_get_curattr(&tm->tm_emulator);
+	terminal_set_winsize_blank(tm, &wsz, 1, a);
 
 	if (vtdbest != NULL) {
 #ifdef DEV_SPLASH
@@ -2691,9 +2691,10 @@ vt_allocate_window(struct vt_device *vd, unsigned int 
 
 	vt_termsize(vd, vw->vw_font, &size);
 	vt_winsize(vd, vw->vw_font, &wsz);
+	tm = vw->vw_terminal = terminal_alloc(&vt_termclass, vw);
+	vw->vw_buf.vb_terminal = tm;	/* must be set before vtbuf_init() */
 	vtbuf_init(&vw->vw_buf, &size);
 
-	tm = vw->vw_terminal = terminal_alloc(&vt_termclass, vw);
 	terminal_set_winsize(tm, &wsz);
 	vd->vd_windows[window] = vw;
 	callout_init(&vw->vw_proc_dead_timer, 0);

Modified: head/sys/dev/vt/vt_cpulogos.c
==============================================================================
--- head/sys/dev/vt/vt_cpulogos.c	Wed Sep 25 13:21:07 2019	(r352680)
+++ head/sys/dev/vt/vt_cpulogos.c	Wed Sep 25 13:24:31 2019	(r352681)
@@ -121,6 +121,8 @@ vtterm_draw_cpu_logos(struct vt_device *vd)
 {
 	unsigned int ncpu, i;
 	vt_axis_t left;
+	struct terminal *tm = vd->vd_curwindow->vw_terminal;
+	const teken_attr_t *a;
 
 	if (vt_splash_ncpu)
 		ncpu = vt_splash_ncpu;
@@ -130,15 +132,16 @@ vtterm_draw_cpu_logos(struct vt_device *vd)
 			ncpu = 1;
 	}
 
+	a = teken_get_curattr(&tm->tm_emulator);
 	if (vd->vd_driver->vd_drawrect)
 		vd->vd_driver->vd_drawrect(vd, 0, 0, vd->vd_width,
-		    vt_logo_sprite_height, 1, TC_BLACK);
+		    vt_logo_sprite_height, 1, a->ta_bgcolor);
 	/*
 	 * Blank is okay because we only ever draw beasties on full screen
 	 * refreshes.
 	 */
 	else if (vd->vd_driver->vd_blank)
-		vd->vd_driver->vd_blank(vd, TC_BLACK);
+		vd->vd_driver->vd_blank(vd, a->ta_bgcolor);
 
 	ncpu = MIN(ncpu, vd->vd_width / vt_logo_sprite_width);
 	for (i = 0, left = 0; i < ncpu; left += vt_logo_sprite_width, i++)


More information about the svn-src-all mailing list