diff options
author | Quinn Stephens <quinn@osmora.org> | 2025-02-14 21:31:53 -0500 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-02-14 22:26:52 -0500 |
commit | 97fa59f389778fb7257a71ad1015a3eb2234a084 (patch) | |
tree | 022385b9f419f0024f223755a86f396af1b629b9 /sys/dev/cons/cons.c | |
parent | d8fd1be4f13f8f744b3a6eae1e4e633b405a8419 (diff) |
kernel: cons: Optimize console drawing
From c7130585ba891d7049d274331783ecc62a15bca3 Mon Sep 17 00:00:00 2001
From: Quinn Stephens <quinn@osmora.org>
Date: Fri, 14 Feb 2025 21:18:34 -0500
Subject: [PATCH] kernel: cons: Optimize console drawing
Prevents the cursor from being cleared right before a character is drawn
or right after the screen is cleared. Also optimized the cursor drawing
routine to just draw a rectangle instead of rendering a space character.
Additionally renamed `cons_render_char()` to `cons_draw_char()` and
fixed all characters being drawn one pixel too far to the right.
Signed-off-by: Quinn Stephens <quinn@osmora.org>
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/dev/cons/cons.c')
-rw-r--r-- | sys/dev/cons/cons.c | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/sys/dev/cons/cons.c b/sys/dev/cons/cons.c index bf03469..3132fc5 100644 --- a/sys/dev/cons/cons.c +++ b/sys/dev/cons/cons.c @@ -66,10 +66,9 @@ cons_make_char(char c, uint32_t fg, uint32_t bg) * @y: Y position of char. */ static void -cons_render_char(struct cons_screen *scr, struct cons_char ch, +cons_draw_char(struct cons_screen *scr, struct cons_char ch, uint32_t x, uint32_t y) { - char c = ch.c; size_t idx; const uint8_t *glyph; @@ -77,10 +76,10 @@ cons_render_char(struct cons_screen *scr, struct cons_char ch, return; } - glyph = &CONS_FONT[(int)c*16]; + glyph = &CONS_FONT[(int)ch.c*16]; for (uint32_t cy = 0; cy < FONT_HEIGHT; ++cy) { for (uint32_t cx = 0; cx < FONT_WIDTH; ++cx) { - idx = fbdev_get_index(&scr->fbdev, x+FONT_WIDTH-cx, y+cy); + idx = fbdev_get_index(&scr->fbdev, x + (FONT_WIDTH - 1) - cx, y + cy); scr->fb_mem[idx] = ISSET(glyph[cy], BIT(cx)) ? ch.fg : ch.bg; } } @@ -89,22 +88,14 @@ cons_render_char(struct cons_screen *scr, struct cons_char ch, static void cons_draw_cursor(struct cons_screen *scr, uint32_t color) { - struct cons_char cursor_chr; - - cursor_chr.fg = scr->fg; - cursor_chr.bg = color; - cursor_chr.c = ' '; - cons_render_char(scr, cursor_chr, scr->curs_col * FONT_WIDTH, - scr->curs_row * FONT_HEIGHT); -} - -static void -cons_move_cursor(struct cons_screen *scr, uint32_t col, uint32_t row) -{ - cons_draw_cursor(scr, scr->bg); - scr->curs_col = col; - scr->curs_row = row; - cons_draw_cursor(scr, scr->last_chr.fg); + size_t idx; + + for (uint32_t cy = 0; cy < FONT_HEIGHT; ++cy) { + for (uint32_t cx = 0; cx < FONT_WIDTH; ++cx) { + idx = fbdev_get_index(&scr->fbdev, (scr->curs_col * FONT_WIDTH) + cx, (scr->curs_row * FONT_HEIGHT) + cy); + scr->fb_mem[idx] = color; + } + } } /* @@ -139,7 +130,11 @@ cons_handle_special(struct cons_screen *scr, char c) /* Make a newline */ scr->ch_col = 0; ++scr->ch_row; - cons_move_cursor(scr, 0, scr->curs_row + 1); + + cons_draw_cursor(scr, scr->bg); + scr->curs_col = 0; + scr->curs_row++; + cons_draw_cursor(scr, scr->last_chr.fg); return 0; } @@ -166,10 +161,14 @@ cons_putch(struct cons_screen *scr, char c) if (scr->curs_row >= scr->nrows) { /* Went over the screen size */ + /* TODO: Scroll instead of just clearing the screen */ scr->ch_col = 0; scr->ch_row = 0; cons_clear_scr(scr, scr->bg); - cons_move_cursor(scr, 0, 0); + + scr->curs_col = 0; + scr->curs_row = 0; + cons_draw_cursor(scr, scr->last_chr.fg); } /* @@ -184,8 +183,9 @@ cons_putch(struct cons_screen *scr, char c) scr->last_chr = cons_chr; /* Draw cursor and character */ - cons_move_cursor(scr, scr->curs_col + 1, scr->curs_row); - cons_render_char(scr, cons_chr, scr->ch_col * FONT_WIDTH, + scr->curs_col++; + cons_draw_cursor(scr, scr->last_chr.fg); + cons_draw_char(scr, cons_chr, scr->ch_col * FONT_WIDTH, scr->ch_row * FONT_HEIGHT); ++scr->ch_col; |