[PATCH v2 20/67] ui/console-vc: move cursor blinking logic into VT100 layer

Marc-André Lureau posted 67 patches 17 hours ago
Maintainers: John Snow <jsnow@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Mauro Carvalho Chehab <mchehab+huawei@kernel.org>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, 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>, "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 v2 20/67] ui/console-vc: move cursor blinking logic into VT100 layer
Posted by Marc-André Lureau 17 hours ago
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>
---
 include/ui/console.h  |  1 -
 ui/console-priv.h     |  2 +-
 ui/console-vc-stubs.c |  2 +-
 ui/console-vc.c       | 28 +++++++++++++++++++++++-----
 ui/console.c          | 19 +------------------
 5 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index 395a723e318..5b5bba46ec2 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -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
diff --git a/ui/console-priv.h b/ui/console-priv.h
index 2c2cfd99570..8bcdb79d914 100644
--- a/ui/console-priv.h
+++ b/ui/console-priv.h
@@ -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
diff --git a/ui/console-vc-stubs.c b/ui/console-vc-stubs.c
index 8a7f19c1f44..d911a82f263 100644
--- a/ui/console-vc-stubs.c
+++ b/ui/console-vc-stubs.c
@@ -14,7 +14,7 @@ void qemu_text_console_update_size(QemuTextConsole *c)
 {
 }
 
-void qemu_text_console_update_cursor(void)
+void vt100_update_cursor(void)
 {
 }
 
diff --git a/ui/console-vc.c b/ui/console-vc.c
index d46dcb6a678..6694c5082f8 100644
--- a/ui/console-vc.c
+++ b/ui/console-vc.c
@@ -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 "ui/cp437.h"
 
@@ -69,8 +70,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;
 
@@ -1103,20 +1109,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)
@@ -1132,6 +1146,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
@@ -1156,6 +1173,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;
diff --git a/ui/console.c b/ui/console.c
index 24e4761e1f9..8af1dee0e22 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -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);

-- 
2.53.0