The branch main has been updated by kevans:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=c43de099d0138b369b705b3af2c3254d3f3afc6e

commit c43de099d0138b369b705b3af2c3254d3f3afc6e
Author:     Kyle Evans <kev...@freebsd.org>
AuthorDate: 2025-08-22 03:48:14 +0000
Commit:     Kyle Evans <kev...@freebsd.org>
CommitDate: 2025-08-22 03:48:28 +0000

    stand: use a common function in gfx_fb for setting up teken colors
    
    These are basically identical, with exception to the hook installed
    which is specific to the loader we're building by necessity.  Pull these
    out into common/gfx_fb.c and just parameterize the hooks to make it
    easier to change the logic.
    
    Reviewed by:    imp
    Differential Revision:  https://reviews.freebsd.org/D50886
---
 stand/common/gfx_fb.c           | 31 +++++++++++++++++++++++++++++++
 stand/common/gfx_fb.h           |  1 +
 stand/efi/libefi/efi_console.c  | 23 +----------------------
 stand/i386/libi386/vidconsole.c | 21 +--------------------
 4 files changed, 34 insertions(+), 42 deletions(-)

diff --git a/stand/common/gfx_fb.c b/stand/common/gfx_fb.c
index af72ab1a4c99..1d2f22649955 100644
--- a/stand/common/gfx_fb.c
+++ b/stand/common/gfx_fb.c
@@ -232,6 +232,37 @@ gfx_parse_mode_str(char *str, int *x, int *y, int *depth)
        return (true);
 }
 
+void
+gfx_fb_setcolors(teken_attr_t *attr, ev_sethook_t sethook,
+     ev_unsethook_t unsethook)
+{
+       const char *ptr;
+       char env[10];
+
+       /*
+        * On first run, we setup an environment hook to process any color
+        * changes.  If the env is already set, we pick up fg and bg color
+        * values from the environment.
+        */
+       ptr = getenv("teken.fg_color");
+       if (ptr != NULL) {
+               attr->ta_fgcolor = strtol(ptr, NULL, 10);
+               ptr = getenv("teken.bg_color");
+               attr->ta_bgcolor = strtol(ptr, NULL, 10);
+
+               teken_set_defattr(&gfx_state.tg_teken, attr);
+       } else {
+               snprintf(env, sizeof(env), "%d",
+                   attr->ta_fgcolor);
+               env_setenv("teken.fg_color", EV_VOLATILE, env,
+                   sethook, unsethook);
+               snprintf(env, sizeof(env), "%d",
+                   attr->ta_bgcolor);
+               env_setenv("teken.bg_color", EV_VOLATILE, env,
+                   sethook, unsethook);
+       }
+}
+
 static uint32_t
 rgb_color_map(uint8_t index, uint32_t rmax, int roffset,
     uint32_t gmax, int goffset, uint32_t bmax, int boffset)
diff --git a/stand/common/gfx_fb.h b/stand/common/gfx_fb.h
index 17e419d8ffd3..d12bcd76b7fa 100644
--- a/stand/common/gfx_fb.h
+++ b/stand/common/gfx_fb.h
@@ -277,6 +277,7 @@ void gfx_fb_bezier(uint32_t, uint32_t, uint32_t, uint32_t, 
uint32_t, uint32_t,
 
 int gfx_fb_putimage(png_t *, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
 bool gfx_parse_mode_str(char *, int *, int *, int *);
+void gfx_fb_setcolors(teken_attr_t *, ev_sethook_t, ev_unsethook_t);
 void term_image_display(teken_gfx_t *, const teken_rect_t *);
 
 void reset_font_flags(void);
diff --git a/stand/efi/libefi/efi_console.c b/stand/efi/libefi/efi_console.c
index cbb4dd01d1fb..46a3c957f151 100644
--- a/stand/efi/libefi/efi_console.c
+++ b/stand/efi/libefi/efi_console.c
@@ -1041,28 +1041,7 @@ cons_update_mode(bool use_gfx_mode)
                        a = teken_get_defattr(&gfx_state.tg_teken);
                        attr = *a;
 
-                       /*
-                        * On first run, we set up the efi_set_colors()
-                        * callback. If the env is already set, we
-                        * pick up fg and bg color values from the environment.
-                        */
-                       ptr = getenv("teken.fg_color");
-                       if (ptr != NULL) {
-                               attr.ta_fgcolor = strtol(ptr, NULL, 10);
-                               ptr = getenv("teken.bg_color");
-                               attr.ta_bgcolor = strtol(ptr, NULL, 10);
-
-                               teken_set_defattr(&gfx_state.tg_teken, &attr);
-                       } else {
-                               snprintf(env, sizeof(env), "%d",
-                                   attr.ta_fgcolor);
-                               env_setenv("teken.fg_color", EV_VOLATILE, env,
-                                   efi_set_colors, env_nounset);
-                               snprintf(env, sizeof(env), "%d",
-                                   attr.ta_bgcolor);
-                               env_setenv("teken.bg_color", EV_VOLATILE, env,
-                                   efi_set_colors, env_nounset);
-                       }
+                       gfx_fb_setcolors(&attr, efi_set_colors, env_nounset);
                }
        }
 
diff --git a/stand/i386/libi386/vidconsole.c b/stand/i386/libi386/vidconsole.c
index 414803e9af3d..3938bd7822ea 100644
--- a/stand/i386/libi386/vidconsole.c
+++ b/stand/i386/libi386/vidconsole.c
@@ -956,26 +956,7 @@ cons_update_mode(bool use_gfx_mode)
        a = teken_get_defattr(&gfx_state.tg_teken);
        attr = *a;
 
-       /*
-        * On first run, we set up the vidc_set_colors()
-        * callback. If the env is already set, we
-        * pick up fg and bg color values from the environment.
-        */
-       ptr = getenv("teken.fg_color");
-       if (ptr != NULL) {
-               attr.ta_fgcolor = strtol(ptr, NULL, 10);
-               ptr = getenv("teken.bg_color");
-               attr.ta_bgcolor = strtol(ptr, NULL, 10);
-
-               teken_set_defattr(&gfx_state.tg_teken, &attr);
-       } else {
-               snprintf(env, sizeof(env), "%d", attr.ta_fgcolor);
-               env_setenv("teken.fg_color", EV_VOLATILE, env,
-                   vidc_set_colors, env_nounset);
-               snprintf(env, sizeof(env), "%d", attr.ta_bgcolor);
-               env_setenv("teken.bg_color", EV_VOLATILE, env,
-                   vidc_set_colors, env_nounset);
-       }
+       gfx_fb_setcolors(&attr, vidc_set_colors, env_nounset);
 
        /* Improve visibility */
        if (attr.ta_bgcolor == TC_WHITE)

Reply via email to