ui/console-vc: move cursor blinking logic into VT100 layer

Maintain a list of QemuVT100 instances so the cursor timer can directly
iterate over them and call vt100_refresh(), instead of going through
qemu_invalidate_text_consoles() which iterated over all consoles
(including graphic ones) and called back into the generic display layer.

This removes the qemu_invalidate_text_consoles() function from
console.c, further decoupling VT100 text rendering from the console
core.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau
2026-02-19 22:03:58 +01:00
parent 1e4ded80b1
commit cddc99e81c
5 changed files with 26 additions and 26 deletions

View File

@@ -416,7 +416,6 @@ void qemu_console_set_window_id(QemuConsole *con, int window_id);
void qemu_console_resize(QemuConsole *con, int width, int height);
DisplaySurface *qemu_console_surface(QemuConsole *con);
void coroutine_fn qemu_console_co_wait_update(QemuConsole *con);
int qemu_invalidate_text_consoles(void);
/* console-gl.c */
#ifdef CONFIG_OPENGL

View File

@@ -36,7 +36,7 @@ struct QemuConsole {
};
void qemu_text_console_update_size(QemuTextConsole *c);
void qemu_text_console_update_cursor(void);
void vt100_update_cursor(void);
void qemu_text_console_handle_keysym(QemuTextConsole *s, int keysym);
#endif

View File

@@ -14,7 +14,7 @@ void qemu_text_console_update_size(QemuTextConsole *c)
{
}
void qemu_text_console_update_cursor(void)
void vt100_update_cursor(void)
{
}

View File

@@ -8,6 +8,7 @@
#include "qapi/error.h"
#include "qemu/fifo8.h"
#include "qemu/option.h"
#include "qemu/queue.h"
#include "ui/console.h"
#include "trace.h"
@@ -68,8 +69,13 @@ struct QemuVT100 {
int update_y0;
int update_x1;
int update_y1;
QTAILQ_ENTRY(QemuVT100) list;
};
static QTAILQ_HEAD(QemuVT100Head, QemuVT100) vt100s =
QTAILQ_HEAD_INITIALIZER(vt100s);
typedef struct QemuTextConsole {
QemuConsole parent;
@@ -1042,20 +1048,28 @@ static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len)
return len;
}
void qemu_text_console_update_cursor(void)
void vt100_update_cursor(void)
{
QemuVT100 *vt;
cursor_visible_phase = !cursor_visible_phase;
if (qemu_invalidate_text_consoles()) {
timer_mod(cursor_timer,
qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + CONSOLE_CURSOR_PERIOD / 2);
if (QTAILQ_EMPTY(&vt100s)) {
return;
}
QTAILQ_FOREACH(vt, &vt100s, list) {
vt100_refresh(vt);
}
timer_mod(cursor_timer,
qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + CONSOLE_CURSOR_PERIOD / 2);
}
static void
cursor_timer_cb(void *opaque)
{
qemu_text_console_update_cursor();
vt100_update_cursor();
}
static void text_console_invalidate(void *opaque)
@@ -1071,6 +1085,9 @@ static void text_console_invalidate(void *opaque)
static void
qemu_text_console_finalize(Object *obj)
{
QemuTextConsole *s = QEMU_TEXT_CONSOLE(obj);
QTAILQ_REMOVE(&vt100s, &s->vt, list);
}
static void
@@ -1095,6 +1112,7 @@ qemu_text_console_init(Object *obj)
{
QemuTextConsole *c = QEMU_TEXT_CONSOLE(obj);
QTAILQ_INSERT_HEAD(&vt100s, &c->vt, list);
fifo8_create(&c->out_fifo, 16);
c->vt.total_height = DEFAULT_BACKSCROLL;
QEMU_CONSOLE(c)->hw_ops = &text_console_ops;

View File

@@ -752,7 +752,7 @@ void register_displaychangelistener(DisplayChangeListener *dcl)
} else if (QEMU_IS_TEXT_CONSOLE(dcl->con)) {
qemu_text_console_update_size(QEMU_TEXT_CONSOLE(dcl->con));
}
qemu_text_console_update_cursor();
vt100_update_cursor();
}
void update_displaychangelistener(DisplayChangeListener *dcl,
@@ -1457,23 +1457,6 @@ int qemu_console_get_height(QemuConsole *con, int fallback)
}
}
int qemu_invalidate_text_consoles(void)
{
QemuConsole *s;
int count = 0;
QTAILQ_FOREACH(s, &consoles, next) {
if (qemu_console_is_graphic(s) ||
!qemu_console_is_visible(s)) {
continue;
}
count++;
graphic_hw_invalidate(s);
}
return count;
}
void qemu_console_resize(QemuConsole *s, int width, int height)
{
DisplaySurface *surface = qemu_console_surface(s);