ui/console-vc: extract vt100_init() and vt100_fini()
Consolidate VT100 initialization and finalization into dedicated functions, continuing the extraction of the VT100 layer from the console/chardev code. vt100_init() gathers the scattered setup (cursor timer, list insertion, FIFO creation, default attributes, and image) that was previously spread across vc_chr_open() and qemu_text_console_class_init(). vt100_fini() pairs with it by handling list removal, FIFO destruction, and cells cleanup, replacing the open-coded QTAILQ_REMOVE in qemu_text_console_finalize(). Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Marc-André Lureau committed
Feb 22, 2026 at 20:04 UTC
d209ed157084037dcd1ee982c7427176df7818f1
1 file changed
+37
-18
ui/console-vc.c
+37
-18
@@ -331,7 +331,7 @@ static void vt100_write(QemuVT100 *vt, const void *buf, size_t len)
331
vt->out_flush(vt);
332
}
333
334
-static int vt100_input(QemuVT100 *vt, const uint8_t *buf, int len);
334
+static size_t vt100_input(QemuVT100 *vt, const uint8_t *buf, size_t len);
335
336
static void vt100_keysym(QemuVT100 *vt, int keysym)
337
{
@@ -1129,12 +1129,19 @@ static void text_console_invalidate(void *opaque)
1129
vt100_refresh(&s->vt);
1130
}
1131
1132
+static void vt100_fini(QemuVT100 *vt)
1133
+{
1134
+ QTAILQ_REMOVE(&vt100s, vt, list);
1135
+ fifo8_destroy(&vt->out_fifo);
1136
+ g_free(vt->cells);
1137
+}
1138
+
1139
static void
1140
qemu_text_console_finalize(Object *obj)
1141
{
1142
QemuTextConsole *s = QEMU_TEXT_CONSOLE(obj);
1143
1137
- QTAILQ_REMOVE(&vt100s, &s->vt, list);
1144
+ vt100_fini(&s->vt);
1145
}
1146
1147
static void
@@ -1142,10 +1149,6 @@ qemu_text_console_class_init(ObjectClass *oc, const void *data)
1149
{
1150
QemuConsoleClass *cc = QEMU_CONSOLE_CLASS(oc);
1151
1145
- if (!cursor_timer) {
1146
- cursor_timer = timer_new_ms(QEMU_CLOCK_REALTIME, cursor_timer_cb, NULL);
1147
- }
1148
-
1152
cc->get_label = qemu_text_console_get_label;
1153
}
1154
@@ -1211,6 +1214,27 @@ static void text_console_out_flush(QemuVT100 *vt)
1214
qemu_text_console_out_flush(console);
1215
}
1216
1217
+static void vt100_init(QemuVT100 *vt,
1218
+ pixman_image_t *image,
1219
+ ChardevVCEncoding encoding,
1220
+ void (*image_update)(QemuVT100 *vt, int x, int y, int w, int h),
1221
+ void (*out_flush)(QemuVT100 *vt))
1222
+{
1223
+ if (!cursor_timer) {
1224
+ cursor_timer = timer_new_ms(QEMU_CLOCK_REALTIME, cursor_timer_cb, NULL);
1225
+ }
1226
+
1227
+ vt->encoding = encoding;
1228
+ QTAILQ_INSERT_HEAD(&vt100s, vt, list);
1229
+ fifo8_create(&vt->out_fifo, 16);
1230
+ vt->total_height = DEFAULT_BACKSCROLL;
1231
+ vt->image_update = image_update;
1232
+ vt->out_flush = out_flush;
1233
+ /* set current text attributes to default */
1234
+ vt->t_attrib = TEXT_ATTRIBUTES_DEFAULT;
1235
+ vt100_set_image(vt, image);
1236
+}
1237
+
1238
static bool vc_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp)
1239
{
1240
ChardevVC *vc = backend->u.vc.data;
@@ -1240,22 +1264,17 @@ static bool vc_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp)
1264
s = QEMU_TEXT_CONSOLE(object_new(TYPE_QEMU_FIXED_TEXT_CONSOLE));
1265
}
1266
1243
- QTAILQ_INSERT_HEAD(&vt100s, &s->vt, list);
1244
- fifo8_create(&s->vt.out_fifo, 16);
1245
- s->vt.total_height = DEFAULT_BACKSCROLL;
1267
dpy_gfx_replace_surface(QEMU_CONSOLE(s), qemu_create_displaysurface(width, height));
1247
- s->vt.image_update = text_console_image_update;
1248
- s->vt.out_flush = text_console_out_flush;
1249
-
1250
- s->chr = chr;
1251
- drv->console = s;
1268
if (vc->has_encoding) {
1253
- drv->encoding = s->vt.encoding = vc->encoding;
1269
+ drv->encoding = vc->encoding;
1270
}
1271
+ vt100_init(&s->vt, QEMU_CONSOLE(s)->surface->image,
1272
+ drv->encoding,
1273
+ text_console_image_update,
1274
+ text_console_out_flush);
1275
1256
- /* set current text attributes to default */
1257
- s->vt.t_attrib = TEXT_ATTRIBUTES_DEFAULT;
1258
- vt100_set_image(&s->vt, QEMU_CONSOLE(s)->surface->image);
1276
+ s->chr = chr;
1277
+ drv->console = s;
1278
1279
if (chr->label) {
1280
char *msg;