@samitouri / QOSamiQemu / commits / 4da64afc29

ui/console-vc: refactor text_console_resize() into vt100_set_image()

Decouple the resize logic from QemuTextConsole by operating on QemuVT100 and taking a pixman_image_t directly, instead of reaching into the console's scanout surface. The callers now pass the image explicitly, which makes the VT100 layer independent of the console object hierarchy. 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 19:23 UTC 4da64afc29f2672f6a6d6f5786be8c03067bbfa9
1 file changed +19 -21
ui/console-vc.c
+19 -21
@@ -11,6 +11,7 @@
11 #include "qemu/queue.h"
12 #include "ui/console.h"
13
14 +#include "pixman.h"
15 #include "trace.h"
16 #include "console-priv.h"
17
@@ -394,44 +395,41 @@ static void text_console_update(void *opaque, console_ch_t *chardata)
395 }
396 }
397
397 -static void text_console_resize(QemuTextConsole *t)
398 +static void vt100_set_image(QemuVT100 *vt, pixman_image_t *image)
399 {
399 - QemuConsole *s = QEMU_CONSOLE(t);
400 TextCell *cells, *c, *c1;
401 int w1, x, y, last_width, w, h;
402
403 - assert(s->scanout.kind == SCANOUT_SURFACE);
404 -
405 - t->vt.image = s->surface->image;
406 - w = pixman_image_get_width(t->vt.image) / FONT_WIDTH;
407 - h = pixman_image_get_height(t->vt.image) / FONT_HEIGHT;
408 - if (w == t->vt.width && h == t->vt.height) {
403 + vt->image = image;
404 + w = pixman_image_get_width(image) / FONT_WIDTH;
405 + h = pixman_image_get_height(image) / FONT_HEIGHT;
406 + if (w == vt->width && h == vt->height) {
407 return;
408 }
409
412 - last_width = t->vt.width;
413 - t->vt.width = w;
414 - t->vt.height = h;
410 + last_width = vt->width;
411 + vt->width = w;
412 + vt->height = h;
413
416 - w1 = MIN(t->vt.width, last_width);
414 + w1 = MIN(vt->width, last_width);
415
418 - cells = g_new(TextCell, t->vt.width * t->vt.total_height + 1);
419 - for (y = 0; y < t->vt.total_height; y++) {
420 - c = &cells[y * t->vt.width];
416 + cells = g_new(TextCell, vt->width * vt->total_height + 1);
417 + for (y = 0; y < vt->total_height; y++) {
418 + c = &cells[y * vt->width];
419 if (w1 > 0) {
422 - c1 = &t->vt.cells[y * last_width];
420 + c1 = &vt->cells[y * last_width];
421 for (x = 0; x < w1; x++) {
422 *c++ = *c1++;
423 }
424 }
427 - for (x = w1; x < t->vt.width; x++) {
425 + for (x = w1; x < vt->width; x++) {
426 c->ch = ' ';
427 c->t_attrib = TEXT_ATTRIBUTES_DEFAULT;
428 c++;
429 }
430 }
433 - g_free(t->vt.cells);
434 - t->vt.cells = cells;
431 + g_free(vt->cells);
432 + vt->cells = cells;
433 }
434
435 static void vc_put_lf(VCChardev *vc)
@@ -1076,7 +1074,7 @@ static void text_console_invalidate(void *opaque)
1074 QemuTextConsole *s = QEMU_TEXT_CONSOLE(opaque);
1075
1076 if (!QEMU_IS_FIXED_TEXT_CONSOLE(s)) {
1079 - text_console_resize(QEMU_TEXT_CONSOLE(s));
1077 + vt100_set_image(&s->vt, QEMU_CONSOLE(s)->surface->image);
1078 }
1079 vt100_refresh(&s->vt);
1080 }
@@ -1196,7 +1194,7 @@ static bool vc_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp)
1194
1195 /* set current text attributes to default */
1196 drv->t_attrib = TEXT_ATTRIBUTES_DEFAULT;
1199 - text_console_resize(s);
1197 + vt100_set_image(&s->vt, QEMU_CONSOLE(s)->surface->image);
1198
1199 if (chr->label) {
1200 char *msg;