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

(cherry picked from commit c43de099d0)
This commit is contained in:
Kyle Evans committed 2026-04-12 08:43:37 -05:00
1 parent fd67a7587c
commit 4bb6ec63da
4 files changed
+34 -42

No files matched your search

+31
View File
@@ -223,6 +223,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)
+1
View File
@@ -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);
+1 -22
View File
@@ -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);
}
}
+1 -20
View File
@@ -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)