
From: Simon Glass <sjg@chromium.org> Move fixed-font, character-rendering from console_normal.c into a shared function in console_core.c. This will allow truetype to use the fixed fonts as well as its own. Co-developed-by: Claude <noreply@anthropic.com> --- drivers/video/console_core.c | 33 ++++++++++++++++++++++++ drivers/video/console_normal.c | 39 ++++++----------------------- drivers/video/vidconsole_internal.h | 24 ++++++++++++++++++ 3 files changed, 64 insertions(+), 32 deletions(-) diff --git a/drivers/video/console_core.c b/drivers/video/console_core.c index 939363653f6..4b75a5b6e12 100644 --- a/drivers/video/console_core.c +++ b/drivers/video/console_core.c @@ -228,6 +228,39 @@ int console_simple_get_font(struct udevice *dev, int seq, struct vidfont_info *i return info->name ? 0 : -ENOENT; } +int console_fixed_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp, + struct video_fontdata *fontdata) +{ + struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct udevice *vid = dev->parent; + struct video_priv *vid_priv = dev_get_uclass_priv(vid); + int pbytes = VNBYTES(vid_priv->bpix); + int x, linenum, ret; + void *start, *line; + u8 ch = console_utf_to_cp437(cp); + uchar *pfont = fontdata->video_fontdata + + ch * fontdata->char_pixel_bytes; + + if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) + return -EAGAIN; + linenum = y; + x = VID_TO_PIXEL(x_frac); + start = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes; + line = start; + + ret = fill_char_vertically(pfont, &line, vid_priv, fontdata, NORMAL_DIRECTION); + if (ret) + return ret; + + video_damage(dev->parent, + x, + y, + fontdata->width, + fontdata->height); + + return VID_TO_POS(fontdata->width); +} + int console_simple_select_font(struct udevice *dev, const char *name, uint size) { struct video_fontdata *font; diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c index a39b04bd73c..9509f81f40f 100644 --- a/drivers/video/console_normal.c +++ b/drivers/video/console_normal.c @@ -68,41 +68,11 @@ static int console_move_rows(struct udevice *dev, uint rowdst, return 0; } -static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp) +int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp) { - struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); - struct udevice *vid = dev->parent; - struct video_priv *vid_priv = dev_get_uclass_priv(vid); struct console_simple_priv *priv = dev_get_priv(dev); - struct video_fontdata *fontdata = priv->fontdata; - int pbytes = VNBYTES(vid_priv->bpix); - int x, linenum, ret; - void *start, *line; - u8 ch = console_utf_to_cp437(cp); - uchar *pfont = fontdata->video_fontdata + - ch * fontdata->char_pixel_bytes; - - if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) - return -EAGAIN; - linenum = y; - x = VID_TO_PIXEL(x_frac); - start = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes; - line = start; - if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) - return -EAGAIN; - - ret = fill_char_vertically(pfont, &line, vid_priv, fontdata, NORMAL_DIRECTION); - if (ret) - return ret; - - video_damage(dev->parent, - x, - y, - fontdata->width, - fontdata->height); - - return VID_TO_POS(fontdata->width); + return console_fixed_putc_xy(dev, x_frac, y, cp, priv->fontdata); } static int __maybe_unused console_set_cursor_visible(struct udevice *dev, @@ -134,6 +104,11 @@ static int __maybe_unused console_set_cursor_visible(struct udevice *dev, return 0; } +static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp) +{ + return console_normal_putc_xy(dev, x_frac, y, cp); +} + struct vidconsole_ops console_ops = { .putc_xy = console_putc_xy, .move_rows = console_move_rows, diff --git a/drivers/video/vidconsole_internal.h b/drivers/video/vidconsole_internal.h index bb0277ee451..af2cca8791c 100644 --- a/drivers/video/vidconsole_internal.h +++ b/drivers/video/vidconsole_internal.h @@ -146,6 +146,30 @@ int console_simple_get_font(struct udevice *dev, int seq, struct vidfont_info *i **/ int console_simple_select_font(struct udevice *dev, const char *name, uint size); +/** + * Normal console putc_xy function that can be called by other console drivers + * + * @param dev console device + * @param x_frac fractional X position + * @param y Y position in pixels + * @param cp Unicode code point + * @returns width in fractional pixels, or -ve on error + */ +int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp); + +/** + * Fixed font putc_xy function that can be called with explicit font data + * + * @param dev console device + * @param x_frac fractional X position + * @param y Y position in pixels + * @param cp Unicode code point + * @param fontdata font data to use for rendering + * @returns width in fractional pixels, or -ve on error + */ +int console_fixed_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp, + struct video_fontdata *fontdata); + /** * Internal function to convert Unicode code points to code page 437. * Used by video consoles using bitmap fonts. -- 2.43.0