[PATCH 20/60] ui/console-vc: decouple VT100 display updates via function pointer

Marc-André Lureau posted 60 patches 2 weeks, 6 days ago
Maintainers: "Marc-André Lureau" <marcandre.lureau@redhat.com>, John Snow <jsnow@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Mauro Carvalho Chehab <mchehab+huawei@kernel.org>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, Jan Kiszka <jan.kiszka@web.de>, Phil Dennis-Jordan <phil@philjordan.eu>, Richard Henderson <richard.henderson@linaro.org>, Helge Deller <deller@gmx.de>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Gerd Hoffmann <kraxel@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Samuel Tardieu <sam@rfc1149.net>, Igor Mitsyanko <i.mitsyanko@gmail.com>, "Hervé Poussineau" <hpoussin@reactos.org>, Aleksandar Rikalo <arikalo@gmail.com>, Laurent Vivier <laurent@vivier.eu>, Thomas Huth <th.huth+qemu@posteo.eu>, BALATON Zoltan <balaton@eik.bme.hu>, "Michael S. Tsirkin" <mst@redhat.com>, Stefano Garzarella <sgarzare@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, Dmitry Osipenko <dmitry.osipenko@collabora.com>, Dmitry Fleytman <dmitry.fleytman@gmail.com>, Stefano Stabellini <sstabellini@kernel.org>, Anthony PERARD <anthony@xenproject.org>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Alistair Francis <alistair@alistair23.me>, Alex Williamson <alex@shazbot.org>, "Cédric Le Goater" <clg@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Fabiano Rosas <farosas@suse.de>
[PATCH 20/60] ui/console-vc: decouple VT100 display updates via function pointer
Posted by Marc-André Lureau 2 weeks, 6 days ago
Replace direct dpy_gfx_update() calls from the VT100 emulation code
with an indirect call through a new image_update function pointer in
QemuVT100. This decouples the VT100 terminal emulation from the
QEMU display layer, allowing different backends to provide their own
image update implementation.

The QemuVT100 typedef is changed to a forward-declared struct so the
function pointer signature can reference QemuVT100 itself.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 ui/console-vc.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/ui/console-vc.c b/ui/console-vc.c
index 56e2527c7a2..8a18659036f 100644
--- a/ui/console-vc.c
+++ b/ui/console-vc.c
@@ -48,8 +48,11 @@ enum TTYState {
     TTY_STATE_OSC,
 };
 
-typedef struct QemuVT100 {
+typedef struct QemuVT100 QemuVT100;
+
+struct QemuVT100 {
     pixman_image_t *image;
+    void (*image_update)(QemuVT100 *vt, int x, int y, int width, int height);
 
     int width;
     int height;
@@ -66,7 +69,7 @@ typedef struct QemuVT100 {
     int update_y0;
     int update_x1;
     int update_y1;
-} QemuVT100;
+};
 
 typedef struct QemuTextConsole {
     QemuConsole parent;
@@ -224,6 +227,11 @@ static void vt100_show_cursor(QemuVT100 *vt, int show)
     }
 }
 
+static void vt100_image_update(QemuVT100 *vt, int x, int y, int width, int height)
+{
+    vt->image_update(vt, x, y, width, height);
+}
+
 static void console_refresh(QemuTextConsole *s)
 {
     TextCell *c;
@@ -252,7 +260,7 @@ static void console_refresh(QemuTextConsole *s)
         }
     }
     vt100_show_cursor(&s->vt, 1);
-    dpy_gfx_update(QEMU_CONSOLE(s), 0, 0, w, h);
+    vt100_image_update(&s->vt, 0, 0, w, h);
 }
 
 static void console_scroll(QemuTextConsole *s, int ydelta)
@@ -1075,9 +1083,9 @@ static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len)
     }
     vt100_show_cursor(&s->vt, 1);
     if (s->vt.update_x0 < s->vt.update_x1) {
-        dpy_gfx_update(QEMU_CONSOLE(s), s->vt.update_x0, s->vt.update_y0,
-                       s->vt.update_x1 - s->vt.update_x0,
-                       s->vt.update_y1 - s->vt.update_y0);
+        vt100_image_update(&s->vt, s->vt.update_x0, s->vt.update_y0,
+                           s->vt.update_x1 - s->vt.update_x0,
+                           s->vt.update_y1 - s->vt.update_y0);
     }
     return len;
 }
@@ -1175,6 +1183,13 @@ void qemu_text_console_update_size(QemuTextConsole *c)
     dpy_text_resize(QEMU_CONSOLE(c), c->vt.width, c->vt.height);
 }
 
+static void text_console_image_update(QemuVT100 *vt, int x, int y, int width, int height)
+{
+    QemuTextConsole *console = container_of(vt, QemuTextConsole, vt);
+
+    dpy_gfx_update(QEMU_CONSOLE(console), x, y, width, height);
+}
+
 static bool vc_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp)
 {
     ChardevVC *vc = backend->u.vc.data;
@@ -1205,6 +1220,7 @@ static bool vc_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp)
     }
 
     dpy_gfx_replace_surface(QEMU_CONSOLE(s), qemu_create_displaysurface(width, height));
+    s->vt.image_update = text_console_image_update;
 
     s->chr = chr;
     drv->console = s;

-- 
2.53.0


Re: [PATCH 20/60] ui/console-vc: decouple VT100 display updates via function pointer
Posted by Philippe Mathieu-Daudé 5 days, 15 hours ago
On 17/3/26 09:50, Marc-André Lureau wrote:
> Replace direct dpy_gfx_update() calls from the VT100 emulation code
> with an indirect call through a new image_update function pointer in
> QemuVT100. This decouples the VT100 terminal emulation from the
> QEMU display layer, allowing different backends to provide their own
> image update implementation.
> 
> The QemuVT100 typedef is changed to a forward-declared struct so the
> function pointer signature can reference QemuVT100 itself.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   ui/console-vc.c | 28 ++++++++++++++++++++++------
>   1 file changed, 22 insertions(+), 6 deletions(-)


>   static bool vc_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp)
>   {
>       ChardevVC *vc = backend->u.vc.data;
> @@ -1205,6 +1220,7 @@ static bool vc_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp)
>       }
>   
>       dpy_gfx_replace_surface(QEMU_CONSOLE(s), qemu_create_displaysurface(width, height));
> +    s->vt.image_update = text_console_image_update;

Isn't it better in qemu_text_console_init()?

>   
>       s->chr = chr;
>       drv->console = s;
> 


Re: [PATCH 20/60] ui/console-vc: decouple VT100 display updates via function pointer
Posted by Philippe Mathieu-Daudé 5 days, 11 hours ago
On 1/4/26 11:17, Philippe Mathieu-Daudé wrote:
> On 17/3/26 09:50, Marc-André Lureau wrote:
>> Replace direct dpy_gfx_update() calls from the VT100 emulation code
>> with an indirect call through a new image_update function pointer in
>> QemuVT100. This decouples the VT100 terminal emulation from the
>> QEMU display layer, allowing different backends to provide their own
>> image update implementation.
>>
>> The QemuVT100 typedef is changed to a forward-declared struct so the
>> function pointer signature can reference QemuVT100 itself.
>>
>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> ---
>>   ui/console-vc.c | 28 ++++++++++++++++++++++------
>>   1 file changed, 22 insertions(+), 6 deletions(-)
> 
> 
>>   static bool vc_chr_open(Chardev *chr, ChardevBackend *backend, Error 
>> **errp)
>>   {
>>       ChardevVC *vc = backend->u.vc.data;
>> @@ -1205,6 +1220,7 @@ static bool vc_chr_open(Chardev *chr, 
>> ChardevBackend *backend, Error **errp)
>>       }
>>       dpy_gfx_replace_surface(QEMU_CONSOLE(s), 
>> qemu_create_displaysurface(width, height));
>> +    s->vt.image_update = text_console_image_update;
> 
> Isn't it better in qemu_text_console_init()?

Nevermind, I now see this ends in vt100_init() in patch #30.


Re: [PATCH 20/60] ui/console-vc: decouple VT100 display updates via function pointer
Posted by Philippe Mathieu-Daudé 5 days, 15 hours ago
On 17/3/26 09:50, Marc-André Lureau wrote:
> Replace direct dpy_gfx_update() calls from the VT100 emulation code
> with an indirect call through a new image_update function pointer in
> QemuVT100. This decouples the VT100 terminal emulation from the
> QEMU display layer, allowing different backends to provide their own
> image update implementation.
> 
> The QemuVT100 typedef is changed to a forward-declared struct so the
> function pointer signature can reference QemuVT100 itself.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   ui/console-vc.c | 28 ++++++++++++++++++++++------
>   1 file changed, 22 insertions(+), 6 deletions(-)
> 
> diff --git a/ui/console-vc.c b/ui/console-vc.c
> index 56e2527c7a2..8a18659036f 100644
> --- a/ui/console-vc.c
> +++ b/ui/console-vc.c
> @@ -48,8 +48,11 @@ enum TTYState {
>       TTY_STATE_OSC,
>   };
>   
> -typedef struct QemuVT100 {
> +typedef struct QemuVT100 QemuVT100;

Squash to patch 15 (Introduce QemuVT100 structure)?

> +
> +struct QemuVT100 {
>       pixman_image_t *image;
> +    void (*image_update)(QemuVT100 *vt, int x, int y, int width, int height);
>   
>       int width;
>       int height;
> @@ -66,7 +69,7 @@ typedef struct QemuVT100 {
>       int update_y0;
>       int update_x1;
>       int update_y1;
> -} QemuVT100;
> +};
>   
>   typedef struct QemuTextConsole {
>       QemuConsole parent;
> @@ -224,6 +227,11 @@ static void vt100_show_cursor(QemuVT100 *vt, int show)
>       }
>   }
>   
> +static void vt100_image_update(QemuVT100 *vt, int x, int y, int width, int height)
> +{

assert?

> +    vt->image_update(vt, x, y, width, height);
> +}

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>