From owner-svn-src-stable-11@freebsd.org Wed Feb 14 23:51:45 2018 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 70161F076C2; Wed, 14 Feb 2018 23:51:45 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2151A740CB; Wed, 14 Feb 2018 23:51:45 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1BC7216D3C; Wed, 14 Feb 2018 23:51:45 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1ENpij8009991; Wed, 14 Feb 2018 23:51:44 GMT (envelope-from gonzo@FreeBSD.org) Received: (from gonzo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1ENpi1u009989; Wed, 14 Feb 2018 23:51:44 GMT (envelope-from gonzo@FreeBSD.org) Message-Id: <201802142351.w1ENpi1u009989@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: gonzo set sender to gonzo@FreeBSD.org using -f From: Oleksandr Tymoshenko Date: Wed, 14 Feb 2018 23:51:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r329283 - in stable/11: share/man/man4 sys/dev/vt/colors X-SVN-Group: stable-11 X-SVN-Commit-Author: gonzo X-SVN-Commit-Paths: in stable/11: share/man/man4 sys/dev/vt/colors X-SVN-Commit-Revision: 329283 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Feb 2018 23:51:45 -0000 Author: gonzo Date: Wed Feb 14 23:51:44 2018 New Revision: 329283 URL: https://svnweb.freebsd.org/changeset/base/329283 Log: MFC r327444, r327449, r327454 r327444: vt(4): add support for configurable console palette Introduce new set of loader tunables kern.vt.color.N.rgb, where N is a number from 0 to 15. The value is either comma-separated list decimal numbers ranging from 0 to 255 that represent values of red, green, and blue components respectively (i.e. "128,128,128") or 6-digit hex triplet commonly used to represent colors in HTML or xterm settings (i.e. #808080) Each tunable overrides one of the 16 hardcoded palette codes and can be set in loader.conf(5) Reviewed by: bcr(docs), jilles, manu, ray Differential Revision: https://reviews.freebsd.org/D13645 r327449: Unbreak build broken by r327444 During review iterations function signature has changed in definition but not in actual call. Fix call to match the definition. Reported by: Herbert J. Skuhra Pointyhat to: gonzo r327454: Fix GCC build broken by r32744 Indicate in function declaration that vt_palette_init does not take any arguments Modified: stable/11/share/man/man4/vt.4 stable/11/sys/dev/vt/colors/vt_termcolors.c Directory Properties: stable/11/ (props changed) Modified: stable/11/share/man/man4/vt.4 ============================================================================== --- stable/11/share/man/man4/vt.4 Wed Feb 14 23:47:04 2018 (r329282) +++ stable/11/share/man/man4/vt.4 Wed Feb 14 23:51:44 2018 (r329283) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 19, 2016 +.Dd December 28, 2017 .Dt "VT" 4 .Os .Sh NAME @@ -45,6 +45,7 @@ In .Xr loader.conf 5 : .Cd hw.vga.textmode=1 .Cd kern.vty=vt +.Cd kern.vt.color..rgb="" .Cd kern.vt.fb.default_mode="x" .Cd kern.vt.fb.modes.="x" .Pp @@ -205,6 +206,16 @@ If not set, the default in the .Pa GENERIC kernel is .Nm . +.It Va kern.vt.color. Ns Ar colornum Ns Va .rgb +Set this value to override default palette entry for color +.Pa colornum +which should be in a range from 0 to 15 inclusive. +The value should be either a comma-separated triplet of +red, green, and blue values in a range from 0 to 255 or +HTML-like hex triplet. +See +.Sx EXAMPLES +below. .It Va kern.vt.fb.default_mode Set this value to a graphic mode to override the default mode picked by the .Nm @@ -309,6 +320,11 @@ The connector name was found in .Dl info: [drm] Connector LVDS-1: get mode from tunables: .Dl info: [drm] - kern.vt.fb.modes.LVDS-1 .Dl info: [drm] - kern.vt.fb.default_mode +.Pp +To set black and white colors of console palette +.Pp +.Dl kern.vt.color.0.rgb="10,10,10" +.Dl kern.vt.color.15.rgb="#f0f0f0" .Sh SEE ALSO .Xr kbdcontrol 1 , .Xr login 1 , Modified: stable/11/sys/dev/vt/colors/vt_termcolors.c ============================================================================== --- stable/11/sys/dev/vt/colors/vt_termcolors.c Wed Feb 14 23:47:04 2018 (r329282) +++ stable/11/sys/dev/vt/colors/vt_termcolors.c Wed Feb 14 23:51:44 2018 (r329283) @@ -31,14 +31,18 @@ __FBSDID("$FreeBSD$"); #include +#include +#include #include -static const struct { +#define NCOLORS 16 + +static struct { unsigned char r; /* Red percentage value. */ unsigned char g; /* Green percentage value. */ unsigned char b; /* Blue percentage value. */ -} color_def[16] = { +} color_def[NCOLORS] = { {0, 0, 0}, /* black */ {50, 0, 0}, /* dark red */ {0, 50, 0}, /* dark green */ @@ -63,19 +67,112 @@ static const struct { * - blue and red are swapped (1 <-> 4) * - yellow ad cyan are swapped (3 <-> 6) */ -static const int cons_to_vga_colors[16] = { +static const int cons_to_vga_colors[NCOLORS] = { 0, 4, 2, 6, 1, 5, 3, 7, 0, 4, 2, 6, 1, 5, 3, 7 }; +static int +vt_parse_rgb_triplet(const char *rgb, unsigned char *r, + unsigned char *g, unsigned char *b) +{ + unsigned long v; + const char *ptr; + char *endptr; + + ptr = rgb; + + /* Handle #rrggbb case */ + if (*ptr == '#') { + if (strlen(ptr) != 7) + return (-1); + v = strtoul(ptr + 1, &endptr, 16); + if (*endptr != '\0') + return (-1); + + *r = (v >> 16) & 0xff; + *g = (v >> 8) & 0xff; + *b = v & 0xff; + + return (0); + } + + /* "r, g, b" case */ + v = strtoul(ptr, &endptr, 10); + if (ptr == endptr) + return (-1); + if (v > 255) + return (-1); + *r = v & 0xff; + ptr = endptr; + + /* skip separator */ + while (*ptr == ',' || *ptr == ' ') + ptr++; + + v = strtoul(ptr, &endptr, 10); + if (ptr == endptr) + return (-1); + if (v > 255) + return (-1); + *g = v & 0xff; + ptr = endptr; + + /* skip separator */ + while (*ptr == ',' || *ptr == ' ') + ptr++; + + v = strtoul(ptr, &endptr, 10); + if (ptr == endptr) + return (-1); + if (v > 255) + return (-1); + *b = v & 0xff; + ptr = endptr; + + /* skip trailing spaces */ + while (*ptr == ' ') + ptr++; + + /* unexpected characters at the end of the string */ + if (*ptr != 0) + return (-1); + + return (0); +} + +static void +vt_palette_init(void) +{ + int i; + char rgb[32]; + char tunable[32]; + unsigned char r, g, b; + + for (i = 0; i < NCOLORS; i++) { + snprintf(tunable, sizeof(tunable), + "kern.vt.color.%d.rgb", i); + if (TUNABLE_STR_FETCH(tunable, rgb, sizeof(rgb))) { + if (vt_parse_rgb_triplet(rgb, &r, &g, &b) == 0) { + /* convert to percentages */ + color_def[i].r = r*100/255; + color_def[i].g = g*100/255; + color_def[i].b = b*100/255; + } + } + } +} + int vt_generate_cons_palette(uint32_t *palette, int format, uint32_t rmax, int roffset, uint32_t gmax, int goffset, uint32_t bmax, int boffset) { int i; + vt_palette_init(); + #define CF(_f, _i) ((_f ## max * color_def[(_i)]._f / 100) << _f ## offset) - for (i = 0; i < 16; i++) { + for (i = 0; i < NCOLORS; i++) { switch (format) { case COLOR_FORMAT_VGA: palette[i] = cons_to_vga_colors[i];