Skip to contentSkip to conversation

GL & D-Bus display related fixes

PATCH Superseded [email protected] 3 participants 23 messages Feb 17, 2022 – Mar 7, 2022 1 message not in the archive

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover GL & D-Bus display related fixes

From: Marc-André Lureau <[email protected]>

Hi,

In the thread "[PATCH 0/6] ui/dbus: Share one listener for a console", Akihiko Odaki reported a number of issues with the GL and D-Bus display. His series propose a different design, and reverting some of my previous generic console changes to fix those issues.

However, as I work through the issue so far, they can be solved by reasonable simple fixes while keeping the console changes generic (not specific to the D-Bus display backend). I belive a shared infrastructure is more beneficial long term than having GL-specific code in the DBus code (in particular, the egl-headless & VNC combination could potentially use it)

Thanks a lot Akihiko for reporting the issues proposing a different approach! Please test this alternative series and let me know of any further issues. My understanding is that you are mainly concerned with the Cocoa backend, and I don't have a way to test it, so please check it. If necessary, we may well have to revert my earlier changes and go your way, eventually.

Marc-André Lureau (12):
ui/console: fix crash when using gl context with non-gl listeners ui/console: fix texture leak when calling surface_gl_create_texture()
ui: do not create a surface when resizing a GL scanout ui/console: move check for compatible GL context ui/console: move dcl compatiblity check to a callback ui/console: egl-headless is compatible with non-gl listeners ui/dbus: associate the DBusDisplayConsole listener with the given
console
ui/console: move console compatibility check to dcl_display_console() ui/shader: fix potential leak of shader on error ui/shader: free associated programs
ui/console: add a dpy_gfx_switch callback helper
ui/dbus: fix texture sharing

 include/ui/console.h |  19 ++++---
 ui/dbus.h            |   3 ++
 ui/console-gl.c      |   4 ++
 ui/console.c         | 119 ++++++++++++++++++++++++++-----------------
 ui/dbus-console.c    |  27 +++++-----
 ui/dbus-listener.c   |  11 ----
 ui/dbus.c            |  33 +++++++++++-
 ui/egl-headless.c    |  17 ++++++-
 ui/gtk.c             |  18 ++++++-
 ui/sdl2.c            |   9 +++-
 ui/shader.c          |   9 +++-
 ui/spice-display.c   |   9 +++-
 12 files changed, 192 insertions(+), 86 deletions(-)
Signature · 1 line
2.34.1.428.gdcc0cd074f0c
#1 lore raw

PATCH v2 1/12 ui/console: fix crash when using gl context with non-gl listeners

From: Marc-André Lureau <[email protected]>

The commit 7cc712e98 ("ui: dispatch GL events to all listener") mechanically replaced the dpy_gl calls with a dispatch loop, using the same pre-conditions. However, it didn't take into account that all listeners do not have to implement the GL callbacks.

Add the missing pre-conditions before calling the callbacks.

Fix crash when running a GL-enabled VM with "-device virtio-gpu-gl-pci -display egl-headless -vnc :0".

Fixes 7cc712e98 ("ui: dispatch GL events to all listener")
---
 ui/console.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
ui/console.c +15 -7
index 40eebb6d2cc2..79a01afd1ea7 100644
@@ -1860,7 +1860,9 @@ void dpy_gl_scanout_disable(QemuConsole *con)
         con->scanout.kind = SCANOUT_NONE;
     }
     QLIST_FOREACH(dcl, &s->listeners, next) {
-        dcl->ops->dpy_gl_scanout_disable(dcl);
+        if (dcl->ops->dpy_gl_scanout_disable) {
+            dcl->ops->dpy_gl_scanout_disable(dcl);
+        }
     }
 }
 
@@ -1881,10 +1883,12 @@ void dpy_gl_scanout_texture(QemuConsole *con,
         x, y, width, height
     };
     QLIST_FOREACH(dcl, &s->listeners, next) {
-        dcl->ops->dpy_gl_scanout_texture(dcl, backing_id,
-                                         backing_y_0_top,
-                                         backing_width, backing_height,
-                                         x, y, width, height);
+        if (dcl->ops->dpy_gl_scanout_texture) {
+            dcl->ops->dpy_gl_scanout_texture(dcl, backing_id,
+                                             backing_y_0_top,
+                                             backing_width, backing_height,
+                                             x, y, width, height);
+        }
     }
 }
 
@@ -1897,7 +1901,9 @@ void dpy_gl_scanout_dmabuf(QemuConsole *con,
     con->scanout.kind = SCANOUT_DMABUF;
     con->scanout.dmabuf = dmabuf;
     QLIST_FOREACH(dcl, &s->listeners, next) {
-        dcl->ops->dpy_gl_scanout_dmabuf(dcl, dmabuf);
+        if (dcl->ops->dpy_gl_scanout_dmabuf) {
+            dcl->ops->dpy_gl_scanout_dmabuf(dcl, dmabuf);
+        }
     }
 }
 
@@ -1951,7 +1957,9 @@ void dpy_gl_update(QemuConsole *con,
 
     graphic_hw_gl_block(con, true);
     QLIST_FOREACH(dcl, &s->listeners, next) {
-        dcl->ops->dpy_gl_update(dcl, x, y, w, h);
+        if (dcl->ops->dpy_gl_update) {
+            dcl->ops->dpy_gl_update(dcl, x, y, w, h);
+        }
     }
     graphic_hw_gl_block(con, false);
 }
Signature · 1 line
2.34.1.428.gdcc0cd074f0c
#2 lore raw

PATCH v2 2/12 ui/console: fix texture leak when calling surface_gl_create_texture()

In reply to [email protected]

From: Marc-André Lureau <[email protected]>

Make surface_gl_create_texture() idempotent: if the surface is already bound to a texture, do not create a new one.

This fixes texture leaks when there are multiple DBus listeners, for example.

---
 ui/console-gl.c | 4 ++++
 1 file changed, 4 insertions(+)
ui/console-gl.c +4 -0
index 7c9894a51d99..8e3c9a3c8c01 100644
@@ -49,6 +49,10 @@ void surface_gl_create_texture(QemuGLShader *gls,
     assert(gls);
     assert(QEMU_IS_ALIGNED(surface_stride(surface), surface_bytes_per_pixel(surface)));
 
+    if (surface->texture) {
+        return;
+    }
+
     switch (surface->format) {
     case PIXMAN_BE_b8g8r8x8:
     case PIXMAN_BE_b8g8r8a8:
Signature · 1 line
2.34.1.428.gdcc0cd074f0c
#3 lore raw

PATCH v2 3/12 ui: do not create a surface when resizing a GL scanout

In reply to [email protected]

From: Marc-André Lureau <[email protected]>

qemu_console_resize() will create a blank surface and replace the current scanout with it if called while the current scanout is GL (texture or dmabuf).

This is not only very costly, but also can produce glitches on the display/listener side.

Instead, compare the current console size with the fitting console functions, which also works when the scanout is GL.

Note: there might be still an unnecessary surface creation on calling qemu_console_resize() when the size is actually changing, but display backends currently rely on DisplaySurface details during dpy_gfx_switch() to handle various resize aspects. We would need more refactoring to handle resize without DisplaySurface, this is left for a future improvement.

---
 ui/console.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
ui/console.c +3 -4
index 79a01afd1ea7..365a2c14b809 100644
@@ -2400,13 +2400,12 @@ static void vc_chr_open(Chardev *chr,
 
 void qemu_console_resize(QemuConsole *s, int width, int height)
 {
-    DisplaySurface *surface = qemu_console_surface(s);
+    DisplaySurface *surface;
 
     assert(s->console_type == GRAPHIC_CONSOLE);
 
-    if (surface && (surface->flags & QEMU_ALLOCATED_FLAG) &&
-        pixman_image_get_width(surface->image) == width &&
-        pixman_image_get_height(surface->image) == height) {
+    if (qemu_console_get_width(s, -1) == width &&
+        qemu_console_get_height(s, -1) == height) {
         return;
     }
 
Signature · 1 line
2.34.1.428.gdcc0cd074f0c
#4 lore raw

PATCH v2 4/12 ui/console: move check for compatible GL context

In reply to [email protected]

From: Marc-André Lureau <[email protected]>

Move GL context compatibility check in dpy_compatible_with(), and use recommended error reporting.

---
 ui/console.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)
ui/console.c +6 -15
index 365a2c14b809..57e431d9e609 100644
@@ -1482,6 +1482,12 @@ static bool dpy_compatible_with(QemuConsole *con,
 
     flags = con->hw_ops->get_flags ? con->hw_ops->get_flags(con->hw) : 0;
 
+    if (console_has_gl(con) && con->gl->ops->compatible_dcl != dcl->ops) {
+        error_setg(errp, "Display %s is incompatible with the GL context",
+                   dcl->ops->dpy_name);
+        return false;
+    }
+
     if (flags & GRAPHIC_FLAGS_GL &&
         !console_has_gl(con)) {
         error_setg(errp, "The console requires a GL context.");
@@ -1509,27 +1515,12 @@ void qemu_console_set_display_gl_ctx(QemuConsole *con, DisplayGLCtx *gl)
     con->gl = gl;
 }
 
-static bool dpy_gl_compatible_with(QemuConsole *con, DisplayChangeListener *dcl)
-{
-    if (!con->gl) {
-        return true;
-    }
-
-    return con->gl->ops->compatible_dcl == dcl->ops;
-}
-
 void register_displaychangelistener(DisplayChangeListener *dcl)
 {
     QemuConsole *con;
 
     assert(!dcl->ds);
 
-    if (dcl->con && !dpy_gl_compatible_with(dcl->con, dcl)) {
-        error_report("Display %s is incompatible with the GL context",
-                     dcl->ops->dpy_name);
-        exit(1);
-    }
-
     if (dcl->con) {
         dpy_compatible_with(dcl->con, dcl, &error_fatal);
     }
Signature · 1 line
2.34.1.428.gdcc0cd074f0c
#5 lore raw

PATCH v2 5/12 ui/console: move dcl compatiblity check to a callback

In reply to [email protected]

From: Marc-André Lureau <[email protected]>

As expected from the "compatible_dcl" comment, a simple comparison of ops isn't enough. The following patch will fix a regression introduced by this limited check by extending the compatibility callback for egl-headless.

For now, this patch simply replaces the the "compatible_dcl" ops pointer with a "dpy_gl_ctx_is_compatible_ctx" callback.

---
 include/ui/console.h |  9 ++-------
 ui/console.c         |  3 ++-
 ui/dbus.c            |  9 ++++++++-
 ui/egl-headless.c    |  9 ++++++++-
 ui/gtk.c             | 18 ++++++++++++++++--
 ui/sdl2.c            |  9 ++++++++-
 ui/spice-display.c   |  9 ++++++++-
 7 files changed, 52 insertions(+), 14 deletions(-)
include/ui/console.h +2 -7
index f590819880b5..18a10c0b7db0 100644
@@ -282,13 +282,8 @@ struct DisplayChangeListener {
 };
 
 typedef struct DisplayGLCtxOps {
-    /*
-     * We only check if the GLCtx is compatible with a DCL via ops. A natural
-     * evolution of this would be a callback to check some runtime requirements
-     * and allow various DCL kinds.
-     */
-    const DisplayChangeListenerOps *compatible_dcl;
-
+    bool (*dpy_gl_ctx_is_compatible_dcl)(DisplayGLCtx *dgc,
+                                         DisplayChangeListener *dcl);
     QEMUGLContext (*dpy_gl_ctx_create)(DisplayGLCtx *dgc,
                                        QEMUGLParams *params);
     void (*dpy_gl_ctx_destroy)(DisplayGLCtx *dgc,
ui/console.c +2 -1
index 57e431d9e609..c9318552871b 100644
@@ -1482,7 +1482,8 @@ static bool dpy_compatible_with(QemuConsole *con,
 
     flags = con->hw_ops->get_flags ? con->hw_ops->get_flags(con->hw) : 0;
 
-    if (console_has_gl(con) && con->gl->ops->compatible_dcl != dcl->ops) {
+    if (console_has_gl(con) &&
+        !con->gl->ops->dpy_gl_ctx_is_compatible_dcl(con->gl, dcl)) {
         error_setg(errp, "Display %s is incompatible with the GL context",
                    dcl->ops->dpy_name);
         return false;
ui/dbus.c +8 -1
index 0074424c1fed..f00a44421cf7 100644
@@ -48,8 +48,15 @@ static QEMUGLContext dbus_create_context(DisplayGLCtx *dgc,
     return qemu_egl_create_context(dgc, params);
 }
 
+static bool
+dbus_is_compatible_dcl(DisplayGLCtx *dgc,
+                       DisplayChangeListener *dcl)
+{
+    return dcl->ops == &dbus_gl_dcl_ops;
+}
+
 static const DisplayGLCtxOps dbus_gl_ops = {
-    .compatible_dcl          = &dbus_gl_dcl_ops,
+    .dpy_gl_ctx_is_compatible_dcl = dbus_is_compatible_dcl,
     .dpy_gl_ctx_create       = dbus_create_context,
     .dpy_gl_ctx_destroy      = qemu_egl_destroy_context,
     .dpy_gl_ctx_make_current = qemu_egl_make_context_current,
ui/egl-headless.c +8 -1
index 94082a9da951..9aff115280bc 100644
@@ -166,8 +166,15 @@ static const DisplayChangeListenerOps egl_ops = {
     .dpy_gl_update           = egl_scanout_flush,
 };
 
+static bool
+egl_is_compatible_dcl(DisplayGLCtx *dgc,
+                      DisplayChangeListener *dcl)
+{
+    return dcl->ops == &egl_ops;
+}
+
 static const DisplayGLCtxOps eglctx_ops = {
-    .compatible_dcl          = &egl_ops,
+    .dpy_gl_ctx_is_compatible_dcl = egl_is_compatible_dcl,
     .dpy_gl_ctx_create       = egl_create_context,
     .dpy_gl_ctx_destroy      = qemu_egl_destroy_context,
     .dpy_gl_ctx_make_current = qemu_egl_make_context_current,
ui/gtk.c +16 -2
index a8567b9ddc8f..1b24a67d7964 100644
@@ -614,8 +614,15 @@ static const DisplayChangeListenerOps dcl_gl_area_ops = {
     .dpy_has_dmabuf          = gd_has_dmabuf,
 };
 
+static bool
+gd_gl_area_is_compatible_dcl(DisplayGLCtx *dgc,
+                             DisplayChangeListener *dcl)
+{
+    return dcl->ops == &dcl_gl_area_ops;
+}
+
 static const DisplayGLCtxOps gl_area_ctx_ops = {
-    .compatible_dcl          = &dcl_gl_area_ops,
+    .dpy_gl_ctx_is_compatible_dcl = gd_gl_area_is_compatible_dcl,
     .dpy_gl_ctx_create       = gd_gl_area_create_context,
     .dpy_gl_ctx_destroy      = gd_gl_area_destroy_context,
     .dpy_gl_ctx_make_current = gd_gl_area_make_current,
@@ -641,8 +648,15 @@ static const DisplayChangeListenerOps dcl_egl_ops = {
     .dpy_has_dmabuf          = gd_has_dmabuf,
 };
 
+static bool
+gd_egl_is_compatible_dcl(DisplayGLCtx *dgc,
+                         DisplayChangeListener *dcl)
+{
+    return dcl->ops == &dcl_egl_ops;
+}
+
 static const DisplayGLCtxOps egl_ctx_ops = {
-    .compatible_dcl          = &dcl_egl_ops,
+    .dpy_gl_ctx_is_compatible_dcl = gd_egl_is_compatible_dcl,
     .dpy_gl_ctx_create       = gd_egl_create_context,
     .dpy_gl_ctx_destroy      = qemu_egl_destroy_context,
     .dpy_gl_ctx_make_current = gd_egl_make_current,
ui/sdl2.c +8 -1
index 46a252d7d9d7..d3741f9b754d 100644
@@ -788,8 +788,15 @@ static const DisplayChangeListenerOps dcl_gl_ops = {
     .dpy_gl_update           = sdl2_gl_scanout_flush,
 };
 
+static bool
+sdl2_gl_is_compatible_dcl(DisplayGLCtx *dgc,
+                          DisplayChangeListener *dcl)
+{
+    return dcl->ops == &dcl_gl_ops;
+}
+
 static const DisplayGLCtxOps gl_ctx_ops = {
-    .compatible_dcl          = &dcl_gl_ops,
+    .dpy_gl_ctx_is_compatible_dcl = sdl2_gl_is_compatible_dcl,
     .dpy_gl_ctx_create       = sdl2_gl_create_context,
     .dpy_gl_ctx_destroy      = sdl2_gl_destroy_context,
     .dpy_gl_ctx_make_current = sdl2_gl_make_context_current,
ui/spice-display.c +8 -1
index a3078adf91ec..494168e7fe75 100644
@@ -1125,8 +1125,15 @@ static const DisplayChangeListenerOps display_listener_gl_ops = {
     .dpy_gl_update           = qemu_spice_gl_update,
 };
 
+static bool
+qemu_spice_is_compatible_dcl(DisplayGLCtx *dgc,
+                             DisplayChangeListener *dcl)
+{
+    return dcl->ops == &display_listener_gl_ops;
+}
+
 static const DisplayGLCtxOps gl_ctx_ops = {
-    .compatible_dcl          = &display_listener_gl_ops,
+    .dpy_gl_ctx_is_compatible_dcl = qemu_spice_is_compatible_dcl,
     .dpy_gl_ctx_create       = qemu_spice_gl_create_context,
     .dpy_gl_ctx_destroy      = qemu_egl_destroy_context,
     .dpy_gl_ctx_make_current = qemu_egl_make_context_current,
Signature · 1 line
2.34.1.428.gdcc0cd074f0c
#6 lore raw

PATCH v2 6/12 ui/console: egl-headless is compatible with non-gl listeners

In reply to [email protected]

From: Marc-André Lureau <[email protected]>

Fix a regression introduced by commit 5e79d516e ("ui: split the GL context in a different object").

---
 ui/egl-headless.c | 8 ++++++++
 1 file changed, 8 insertions(+)
ui/egl-headless.c +8 -0
index 9aff115280bc..7a30fd977765 100644
@@ -170,6 +170,14 @@ static bool
 egl_is_compatible_dcl(DisplayGLCtx *dgc,
                       DisplayChangeListener *dcl)
 {
+    if (!dcl->ops->dpy_gl_update) {
+        /*
+         * egl-headless is compatible with all 2d listeners, as it blits the GL
+         * updates on the 2d console surface.
+         */
+        return true;
+    }
+
     return dcl->ops == &egl_ops;
 }
 
Signature · 1 line
2.34.1.428.gdcc0cd074f0c
#7 lore raw

PATCH v2 7/12 ui/dbus: associate the DBusDisplayConsole listener with the given console

In reply to [email protected]

From: Marc-André Lureau <[email protected]>

DBusDisplayConsole is specific to a given QemuConsole.

Fixes commit 142ca628 ("ui: add a D-Bus display backend")
---
 ui/dbus.h         |  3 +++
 ui/dbus-console.c | 27 +++++++++++++--------------
 ui/dbus.c         |  2 +-
 3 files changed, 17 insertions(+), 15 deletions(-)
ui/dbus.h +3 -0
index 64c77cab4441..5f5c1f759c9b 100644
@@ -79,6 +79,9 @@ dbus_display_console_new(DBusDisplay *display, QemuConsole *con);
 int
 dbus_display_console_get_index(DBusDisplayConsole *ddc);
 
+
+extern const DisplayChangeListenerOps dbus_console_dcl_ops;
+
 #define DBUS_DISPLAY_TYPE_LISTENER dbus_display_listener_get_type()
 G_DECLARE_FINAL_TYPE(DBusDisplayListener,
                      dbus_display_listener,
ui/dbus-console.c +13 -14
index e062f721d761..898a4ac8a5ba 100644
@@ -36,7 +36,6 @@ struct _DBusDisplayConsole {
     DisplayChangeListener dcl;
 
     DBusDisplay *display;
-    QemuConsole *con;
     GHashTable *listeners;
     QemuDBusDisplay1Console *iface;
 
@@ -118,7 +117,7 @@ dbus_gl_scanout_update(DisplayChangeListener *dcl,
 {
 }
 
-static const DisplayChangeListenerOps dbus_console_dcl_ops = {
+const DisplayChangeListenerOps dbus_console_dcl_ops = {
     .dpy_name                = "dbus-console",
     .dpy_gfx_switch          = dbus_gfx_switch,
     .dpy_gfx_update          = dbus_gfx_update,
@@ -191,7 +190,7 @@ dbus_console_set_ui_info(DBusDisplayConsole *ddc,
         .height = arg_height,
     };
 
-    if (!dpy_ui_info_supported(ddc->con)) {
+    if (!dpy_ui_info_supported(ddc->dcl.con)) {
         g_dbus_method_invocation_return_error(invocation,
                                               DBUS_DISPLAY_ERROR,
                                               DBUS_DISPLAY_ERROR_UNSUPPORTED,
@@ -199,7 +198,7 @@ dbus_console_set_ui_info(DBusDisplayConsole *ddc,
         return DBUS_METHOD_INVOCATION_HANDLED;
     }
 
-    dpy_set_ui_info(ddc->con, &info, false);
+    dpy_set_ui_info(ddc->dcl.con, &info, false);
     qemu_dbus_display1_console_complete_set_uiinfo(ddc->iface, invocation);
     return DBUS_METHOD_INVOCATION_HANDLED;
 }
@@ -335,8 +334,8 @@ dbus_mouse_rel_motion(DBusDisplayConsole *ddc,
         return DBUS_METHOD_INVOCATION_HANDLED;
     }
 
-    qemu_input_queue_rel(ddc->con, INPUT_AXIS_X, dx);
-    qemu_input_queue_rel(ddc->con, INPUT_AXIS_Y, dy);
+    qemu_input_queue_rel(ddc->dcl.con, INPUT_AXIS_X, dx);
+    qemu_input_queue_rel(ddc->dcl.con, INPUT_AXIS_Y, dy);
     qemu_input_event_sync();
 
     qemu_dbus_display1_mouse_complete_rel_motion(ddc->iface_mouse,
@@ -362,8 +361,8 @@ dbus_mouse_set_pos(DBusDisplayConsole *ddc,
         return DBUS_METHOD_INVOCATION_HANDLED;
     }
 
-    width = qemu_console_get_width(ddc->con, 0);
-    height = qemu_console_get_height(ddc->con, 0);
+    width = qemu_console_get_width(ddc->dcl.con, 0);
+    height = qemu_console_get_height(ddc->dcl.con, 0);
     if (x >= width || y >= height) {
         g_dbus_method_invocation_return_error(
             invocation, DBUS_DISPLAY_ERROR,
@@ -371,8 +370,8 @@ dbus_mouse_set_pos(DBusDisplayConsole *ddc,
             "Invalid mouse position");
         return DBUS_METHOD_INVOCATION_HANDLED;
     }
-    qemu_input_queue_abs(ddc->con, INPUT_AXIS_X, x, 0, width);
-    qemu_input_queue_abs(ddc->con, INPUT_AXIS_Y, y, 0, height);
+    qemu_input_queue_abs(ddc->dcl.con, INPUT_AXIS_X, x, 0, width);
+    qemu_input_queue_abs(ddc->dcl.con, INPUT_AXIS_Y, y, 0, height);
     qemu_input_event_sync();
 
     qemu_dbus_display1_mouse_complete_set_abs_position(ddc->iface_mouse,
@@ -388,7 +387,7 @@ dbus_mouse_press(DBusDisplayConsole *ddc,
 {
     trace_dbus_mouse_press(button);
 
-    qemu_input_queue_btn(ddc->con, button, true);
+    qemu_input_queue_btn(ddc->dcl.con, button, true);
     qemu_input_event_sync();
 
     qemu_dbus_display1_mouse_complete_press(ddc->iface_mouse, invocation);
@@ -403,7 +402,7 @@ dbus_mouse_release(DBusDisplayConsole *ddc,
 {
     trace_dbus_mouse_release(button);
 
-    qemu_input_queue_btn(ddc->con, button, false);
+    qemu_input_queue_btn(ddc->dcl.con, button, false);
     qemu_input_event_sync();
 
     qemu_dbus_display1_mouse_complete_release(ddc->iface_mouse, invocation);
@@ -424,7 +423,7 @@ dbus_mouse_mode_change(Notifier *notify, void *data)
 
 int dbus_display_console_get_index(DBusDisplayConsole *ddc)
 {
-    return qemu_console_get_index(ddc->con);
+    return qemu_console_get_index(ddc->dcl.con);
 }
 
 DBusDisplayConsole *
@@ -446,7 +445,7 @@ dbus_display_console_new(DBusDisplay *display, QemuConsole *con)
                         "g-object-path", path,
                         NULL);
     ddc->display = display;
-    ddc->con = con;
+    ddc->dcl.con = con;
     /* handle errors, and skip non graphics? */
     qemu_console_fill_device_address(
         con, device_addr, sizeof(device_addr), NULL);
ui/dbus.c +1 -1
index f00a44421cf7..22c82d2f323a 100644
@@ -52,7 +52,7 @@ static bool
 dbus_is_compatible_dcl(DisplayGLCtx *dgc,
                        DisplayChangeListener *dcl)
 {
-    return dcl->ops == &dbus_gl_dcl_ops;
+    return dcl->ops == &dbus_gl_dcl_ops || dcl->ops == &dbus_console_dcl_ops;
 }
 
 static const DisplayGLCtxOps dbus_gl_ops = {
Signature · 1 line
2.34.1.428.gdcc0cd074f0c
#8 lore raw

PATCH v2 8/12 ui/console: move console compatibility check to dcl_display_console()

In reply to [email protected]

From: Marc-André Lureau <[email protected]>

The current checks are done at registration time only. However, if a DCL has no specific console specified, it may be switched dynamically with console_select() later on.

Let's move the checks when displaychangelistener_display_console() is called, which includes registration time and remains fatal if the specified console is incompatible.

Note: we may want to display the compatibility error to the DCL, this is left for a future improvement.

---
 ui/console.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
ui/console.c +9 -10
index c9318552871b..d3ecbb215736 100644
@@ -148,6 +148,8 @@ static DisplayState *get_alloc_displaystate(void);
 static void text_console_update_cursor_timer(void);
 static void text_console_update_cursor(void *opaque);
 static bool displaychangelistener_has_dmabuf(DisplayChangeListener *dcl);
+static bool console_compatible_with(QemuConsole *con,
+                                    DisplayChangeListener *dcl, Error **errp);
 
 static void gui_update(void *opaque)
 {
@@ -1057,13 +1059,14 @@ static void console_putchar(QemuConsole *s, int ch)
 }
 
 static void displaychangelistener_display_console(DisplayChangeListener *dcl,
-                                                  QemuConsole *con)
+                                                  QemuConsole *con,
+                                                  Error **errp)
 {
     static const char nodev[] =
         "This VM has no graphic display device.";
     static DisplaySurface *dummy;
 
-    if (!con) {
+    if (!con || !console_compatible_with(con, dcl, errp)) {
         if (!dcl->ops->dpy_gfx_switch) {
             return;
         }
@@ -1114,7 +1117,7 @@ void console_select(unsigned int index)
                 if (dcl->con != NULL) {
                     continue;
                 }
-                displaychangelistener_display_console(dcl, s);
+                displaychangelistener_display_console(dcl, s, NULL);
             }
         }
         if (ds->have_text) {
@@ -1475,8 +1478,8 @@ static bool displaychangelistener_has_dmabuf(DisplayChangeListener *dcl)
     return false;
 }
 
-static bool dpy_compatible_with(QemuConsole *con,
-                                DisplayChangeListener *dcl, Error **errp)
+static bool console_compatible_with(QemuConsole *con,
+                                    DisplayChangeListener *dcl, Error **errp)
 {
     int flags;
 
@@ -1522,10 +1525,6 @@ void register_displaychangelistener(DisplayChangeListener *dcl)
 
     assert(!dcl->ds);
 
-    if (dcl->con) {
-        dpy_compatible_with(dcl->con, dcl, &error_fatal);
-    }
-
     trace_displaychangelistener_register(dcl, dcl->ops->dpy_name);
     dcl->ds = get_alloc_displaystate();
     QLIST_INSERT_HEAD(&dcl->ds->listeners, dcl, next);
@@ -1536,7 +1535,7 @@ void register_displaychangelistener(DisplayChangeListener *dcl)
     } else {
         con = active_console;
     }
-    displaychangelistener_display_console(dcl, con);
+    displaychangelistener_display_console(dcl, con, dcl->con ? &error_fatal : NULL);
     text_console_update_cursor(NULL);
 }
 
Signature · 1 line
2.34.1.428.gdcc0cd074f0c
#9 lore raw

PATCH v2 9/12 ui/shader: fix potential leak of shader on error

In reply to [email protected]

From: Marc-André Lureau <[email protected]>

Value of 0 for program and shaders are silently ignored and indicate error.

---
 ui/shader.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
ui/shader.c +4 -2
index e8b8d321b7c7..4c80fc831f68 100644
@@ -130,15 +130,17 @@ static GLuint qemu_gl_create_link_program(GLuint vert, GLuint frag)
 static GLuint qemu_gl_create_compile_link_program(const GLchar *vert_src,
                                                   const GLchar *frag_src)
 {
-    GLuint vert_shader, frag_shader, program;
+    GLuint vert_shader, frag_shader, program = 0;
 
     vert_shader = qemu_gl_create_compile_shader(GL_VERTEX_SHADER, vert_src);
     frag_shader = qemu_gl_create_compile_shader(GL_FRAGMENT_SHADER, frag_src);
     if (!vert_shader || !frag_shader) {
-        return 0;
+        goto end;
     }
 
     program = qemu_gl_create_link_program(vert_shader, frag_shader);
+
+end:
     glDeleteShader(vert_shader);
     glDeleteShader(frag_shader);
 
Signature · 1 line
2.34.1.428.gdcc0cd074f0c
#10 lore raw

PATCH v2 10/12 ui/shader: free associated programs

In reply to [email protected]

From: Marc-André Lureau <[email protected]>

---
 ui/shader.c | 3 +++
 1 file changed, 3 insertions(+)
ui/shader.c +3 -0
index 4c80fc831f68..ab448c41d4c6 100644
@@ -172,5 +172,8 @@ void qemu_gl_fini_shader(QemuGLShader *gls)
     if (!gls) {
         return;
     }
+    glDeleteProgram(gls->texture_blit_prog);
+    glDeleteProgram(gls->texture_blit_flip_prog);
+    glDeleteProgram(gls->texture_blit_vao);
     g_free(gls);
 }
Signature · 1 line
2.34.1.428.gdcc0cd074f0c
#11 lore raw

PATCH v2 11/12 ui/console: add a dpy_gfx_switch callback helper

In reply to [email protected]

From: Marc-André Lureau <[email protected]>

Slight code improvement.

---
 ui/console.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
ui/console.c +13 -10
index d3ecbb215736..102fcf0a5068 100644
@@ -1058,6 +1058,15 @@ static void console_putchar(QemuConsole *s, int ch)
     }
 }
 
+static void displaychangelistener_gfx_switch(DisplayChangeListener *dcl,
+                                             struct DisplaySurface *new_surface)
+{
+    if (dcl->ops->dpy_gfx_switch) {
+        dcl->ops->dpy_gfx_switch(dcl, new_surface);
+    }
+}
+
+
 static void displaychangelistener_display_console(DisplayChangeListener *dcl,
                                                   QemuConsole *con,
                                                   Error **errp)
@@ -1067,13 +1076,10 @@ static void displaychangelistener_display_console(DisplayChangeListener *dcl,
     static DisplaySurface *dummy;
 
     if (!con || !console_compatible_with(con, dcl, errp)) {
-        if (!dcl->ops->dpy_gfx_switch) {
-            return;
-        }
         if (!dummy) {
             dummy = qemu_create_placeholder_surface(640, 480, nodev);
         }
-        dcl->ops->dpy_gfx_switch(dcl, dummy);
+        displaychangelistener_gfx_switch(dcl, dummy);
         return;
     }
 
@@ -1091,9 +1097,8 @@ static void displaychangelistener_display_console(DisplayChangeListener *dcl,
                                          con->scanout.texture.y,
                                          con->scanout.texture.width,
                                          con->scanout.texture.height);
-    } else if (con->scanout.kind == SCANOUT_SURFACE &&
-               dcl->ops->dpy_gfx_switch) {
-        dcl->ops->dpy_gfx_switch(dcl, con->surface);
+    } else if (con->scanout.kind == SCANOUT_SURFACE) {
+        displaychangelistener_gfx_switch(dcl, con->surface);
     }
 
     dcl->ops->dpy_gfx_update(dcl, 0, 0,
@@ -1677,9 +1682,7 @@ void dpy_gfx_replace_surface(QemuConsole *con,
         if (con != (dcl->con ? dcl->con : active_console)) {
             continue;
         }
-        if (dcl->ops->dpy_gfx_switch) {
-            dcl->ops->dpy_gfx_switch(dcl, surface);
-        }
+        displaychangelistener_gfx_switch(dcl, surface);
     }
     qemu_free_displaysurface(old_surface);
 }
Signature · 1 line
2.34.1.428.gdcc0cd074f0c
#12 lore raw

PATCH v2 12/12 ui/dbus: fix texture sharing

In reply to [email protected]

From: Marc-André Lureau <[email protected]>

The DBus listener naively create, update and destroy textures without taking into account other listeners. The texture were shared, but texture update was unnecessarily duplicated.

Teach DisplayGLCtx to do optionally shared texture handling. This is only implemented for DBus display at this point, however the same infrastructure could potentially be used for egl-headless & VNC listeners for example, or other future combinations.

---
 include/ui/console.h | 10 ++++++++++
 ui/console.c         | 26 ++++++++++++++++++++++++++
 ui/dbus-listener.c   | 11 -----------
 ui/dbus.c            | 24 ++++++++++++++++++++++++
 4 files changed, 60 insertions(+), 11 deletions(-)
include/ui/console.h +10 -0
index 18a10c0b7db0..0f84861933e1 100644
@@ -290,10 +290,20 @@ typedef struct DisplayGLCtxOps {
                                QEMUGLContext ctx);
     int (*dpy_gl_ctx_make_current)(DisplayGLCtx *dgc,
                                    QEMUGLContext ctx);
+    void (*dpy_gl_ctx_create_texture)(DisplayGLCtx *dgc,
+                                      DisplaySurface *surface);
+    void (*dpy_gl_ctx_destroy_texture)(DisplayGLCtx *dgc,
+                                      DisplaySurface *surface);
+    void (*dpy_gl_ctx_update_texture)(DisplayGLCtx *dgc,
+                                      DisplaySurface *surface,
+                                      int x, int y, int w, int h);
 } DisplayGLCtxOps;
 
 struct DisplayGLCtx {
     const DisplayGLCtxOps *ops;
+#ifdef CONFIG_OPENGL
+    QemuGLShader *gls; /* optional shared shader */
+#endif
 };
 
 DisplayState *init_displaystate(void);
ui/console.c +26 -0
index 102fcf0a5068..b9188559fb12 100644
@@ -1066,6 +1066,27 @@ static void displaychangelistener_gfx_switch(DisplayChangeListener *dcl,
     }
 }
 
+static void dpy_gfx_create_texture(QemuConsole *con, DisplaySurface *surface)
+{
+    if (con->gl && con->gl->ops->dpy_gl_ctx_create_texture) {
+        con->gl->ops->dpy_gl_ctx_create_texture(con->gl, surface);
+    }
+}
+
+static void dpy_gfx_destroy_texture(QemuConsole *con, DisplaySurface *surface)
+{
+    if (con->gl && con->gl->ops->dpy_gl_ctx_destroy_texture) {
+        con->gl->ops->dpy_gl_ctx_destroy_texture(con->gl, surface);
+    }
+}
+
+static void dpy_gfx_update_texture(QemuConsole *con, DisplaySurface *surface,
+                                   int x, int y, int w, int h)
+{
+    if (con->gl && con->gl->ops->dpy_gl_ctx_update_texture) {
+        con->gl->ops->dpy_gl_ctx_update_texture(con->gl, surface, x, y, w, h);
+    }
+}
 
 static void displaychangelistener_display_console(DisplayChangeListener *dcl,
                                                   QemuConsole *con,
@@ -1078,6 +1099,7 @@ static void displaychangelistener_display_console(DisplayChangeListener *dcl,
     if (!con || !console_compatible_with(con, dcl, errp)) {
         if (!dummy) {
             dummy = qemu_create_placeholder_surface(640, 480, nodev);
+            dpy_gfx_create_texture(con, dummy);
         }
         displaychangelistener_gfx_switch(dcl, dummy);
         return;
@@ -1098,6 +1120,7 @@ static void displaychangelistener_display_console(DisplayChangeListener *dcl,
                                          con->scanout.texture.width,
                                          con->scanout.texture.height);
     } else if (con->scanout.kind == SCANOUT_SURFACE) {
+        dpy_gfx_create_texture(con, con->surface);
         displaychangelistener_gfx_switch(dcl, con->surface);
     }
 
@@ -1634,6 +1657,7 @@ void dpy_gfx_update(QemuConsole *con, int x, int y, int w, int h)
     if (!qemu_console_is_visible(con)) {
         return;
     }
+    dpy_gfx_update_texture(con, con->surface, x, y, w, h);
     QLIST_FOREACH(dcl, &s->listeners, next) {
         if (con != (dcl->con ? dcl->con : active_console)) {
             continue;
@@ -1678,12 +1702,14 @@ void dpy_gfx_replace_surface(QemuConsole *con,
 
     con->scanout.kind = SCANOUT_SURFACE;
     con->surface = surface;
+    dpy_gfx_create_texture(con, surface);
     QLIST_FOREACH(dcl, &s->listeners, next) {
         if (con != (dcl->con ? dcl->con : active_console)) {
             continue;
         }
         displaychangelistener_gfx_switch(dcl, surface);
     }
+    dpy_gfx_destroy_texture(con, old_surface);
     qemu_free_displaysurface(old_surface);
 }
 
ui/dbus-listener.c +0 -11
index 81c119b13a2c..a287edd2fc15 100644
@@ -42,7 +42,6 @@ struct _DBusDisplayListener {
 
     DisplayChangeListener dcl;
     DisplaySurface *ds;
-    QemuGLShader *gls;
     int gl_updates;
 };
 
@@ -240,10 +239,6 @@ static void dbus_gl_gfx_update(DisplayChangeListener *dcl,
 {
     DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
 
-    if (ddl->ds) {
-        surface_gl_update_texture(ddl->gls, ddl->ds, x, y, w, h);
-    }
-
     ddl->gl_updates++;
 }
 
@@ -285,15 +280,11 @@ static void dbus_gl_gfx_switch(DisplayChangeListener *dcl,
 {
     DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
 
-    if (ddl->ds) {
-        surface_gl_destroy_texture(ddl->gls, ddl->ds);
-    }
     ddl->ds = new_surface;
     if (ddl->ds) {
         int width = surface_width(ddl->ds);
         int height = surface_height(ddl->ds);
 
-        surface_gl_create_texture(ddl->gls, ddl->ds);
         /* TODO: lazy send dmabuf (there are unnecessary sent otherwise) */
         dbus_scanout_texture(&ddl->dcl, ddl->ds->texture, false,
                              width, height, 0, 0, width, height);
@@ -403,7 +394,6 @@ dbus_display_listener_dispose(GObject *object)
     g_clear_object(&ddl->conn);
     g_clear_pointer(&ddl->bus_name, g_free);
     g_clear_object(&ddl->proxy);
-    g_clear_pointer(&ddl->gls, qemu_gl_fini_shader);
 
     G_OBJECT_CLASS(dbus_display_listener_parent_class)->dispose(object);
 }
@@ -414,7 +404,6 @@ dbus_display_listener_constructed(GObject *object)
     DBusDisplayListener *ddl = DBUS_DISPLAY_LISTENER(object);
 
     if (display_opengl) {
-        ddl->gls = qemu_gl_init_shader();
         ddl->dcl.ops = &dbus_gl_dcl_ops;
     } else {
         ddl->dcl.ops = &dbus_dcl_ops;
ui/dbus.c +24 -0
index 22c82d2f323a..8e2e4c9cad28 100644
@@ -55,11 +55,33 @@ dbus_is_compatible_dcl(DisplayGLCtx *dgc,
     return dcl->ops == &dbus_gl_dcl_ops || dcl->ops == &dbus_console_dcl_ops;
 }
 
+static void
+dbus_create_texture(DisplayGLCtx *ctx, DisplaySurface *surface)
+{
+    surface_gl_create_texture(ctx->gls, surface);
+}
+
+static void
+dbus_destroy_texture(DisplayGLCtx *ctx, DisplaySurface *surface)
+{
+    surface_gl_destroy_texture(ctx->gls, surface);
+}
+
+static void
+dbus_update_texture(DisplayGLCtx *ctx, DisplaySurface *surface,
+                    int x, int y, int w, int h)
+{
+    surface_gl_update_texture(ctx->gls, surface, x, y, w, h);
+}
+
 static const DisplayGLCtxOps dbus_gl_ops = {
     .dpy_gl_ctx_is_compatible_dcl = dbus_is_compatible_dcl,
     .dpy_gl_ctx_create       = dbus_create_context,
     .dpy_gl_ctx_destroy      = qemu_egl_destroy_context,
     .dpy_gl_ctx_make_current = qemu_egl_make_context_current,
+    .dpy_gl_ctx_create_texture = dbus_create_texture,
+    .dpy_gl_ctx_destroy_texture = dbus_destroy_texture,
+    .dpy_gl_ctx_update_texture = dbus_update_texture,
 };
 
 static NotifierList dbus_display_notifiers =
@@ -90,6 +112,7 @@ dbus_display_init(Object *o)
     g_autoptr(GDBusObjectSkeleton) vm = NULL;
 
     dd->glctx.ops = &dbus_gl_ops;
+    dd->glctx.gls = qemu_gl_init_shader();
     dd->iface = qemu_dbus_display1_vm_skeleton_new();
     dd->consoles = g_ptr_array_new_with_free_func(g_object_unref);
 
@@ -126,6 +149,7 @@ dbus_display_finalize(Object *o)
     g_clear_object(&dd->iface);
     g_free(dd->dbus_addr);
     g_free(dd->audiodev);
+    g_clear_pointer(&dd->glctx.gls, qemu_gl_fini_shader);
     dbus_display = NULL;
 }
 
Signature · 1 line
2.34.1.428.gdcc0cd074f0c

A message that is not in the archive (sent off-list or not yet received): CAMVc7JWYPZv9yWg0OQfoHQrwaZkb++crxePYQWKTD+af--NLGA@mail.gmail.com

#14 lore raw

PATCH v2 12/12 ui/dbus: fix texture sharing

I mistakenly dropped CC (again). My apologies.

---------- Forwarded message ---------
From: Akihiko Odaki <[email protected]>
Date: Thu, Feb 17, 2022 at 9:38 PM
Subject: Re: [PATCH v2 12/12] ui/dbus: fix texture sharing
To: Marc-André Lureau <[email protected]>

Quoted 11 lines · On Thu, Feb 17, 2022 at 9:02 PM <[email protected]> wrote:

From: Marc-André Lureau <[email protected]>

The DBus listener naively create, update and destroy textures without taking into account other listeners. The texture were shared, but texture update was unnecessarily duplicated.

Teach DisplayGLCtx to do optionally shared texture handling. This is only implemented for DBus display at this point, however the same infrastructure could potentially be used for egl-headless & VNC listeners for example, or other future combinations.

egl-headless only needs one DisplayChangeListener per console since its output is propagated by ui/console. The vnc protocol is for remote access and therefore cannot have OpenGL textures. The functionality is unique to dbus.

Quoted 218 lines
---
 include/ui/console.h | 10 ++++++++++
 ui/console.c         | 26 ++++++++++++++++++++++++++
 ui/dbus-listener.c   | 11 -----------
 ui/dbus.c            | 24 ++++++++++++++++++++++++
 4 files changed, 60 insertions(+), 11 deletions(-)
include/ui/console.h +10 -0
index 18a10c0b7db0..0f84861933e1 100644
@@ -290,10 +290,20 @@ typedef struct DisplayGLCtxOps {
                                QEMUGLContext ctx);
     int (*dpy_gl_ctx_make_current)(DisplayGLCtx *dgc,
                                    QEMUGLContext ctx);
+    void (*dpy_gl_ctx_create_texture)(DisplayGLCtx *dgc,
+                                      DisplaySurface *surface);
+    void (*dpy_gl_ctx_destroy_texture)(DisplayGLCtx *dgc,
+                                      DisplaySurface *surface);
+    void (*dpy_gl_ctx_update_texture)(DisplayGLCtx *dgc,
+                                      DisplaySurface *surface,
+                                      int x, int y, int w, int h);
 } DisplayGLCtxOps;
 
 struct DisplayGLCtx {
     const DisplayGLCtxOps *ops;
+#ifdef CONFIG_OPENGL
+    QemuGLShader *gls; /* optional shared shader */
+#endif
 };
 
 DisplayState *init_displaystate(void);
ui/console.c +26 -0
index 102fcf0a5068..b9188559fb12 100644
@@ -1066,6 +1066,27 @@ static void displaychangelistener_gfx_switch(DisplayChangeListener *dcl,
     }
 }
 
+static void dpy_gfx_create_texture(QemuConsole *con, DisplaySurface *surface)
+{
+    if (con->gl && con->gl->ops->dpy_gl_ctx_create_texture) {
+        con->gl->ops->dpy_gl_ctx_create_texture(con->gl, surface);
+    }
+}
+
+static void dpy_gfx_destroy_texture(QemuConsole *con, DisplaySurface *surface)
+{
+    if (con->gl && con->gl->ops->dpy_gl_ctx_destroy_texture) {
+        con->gl->ops->dpy_gl_ctx_destroy_texture(con->gl, surface);
+    }
+}
+
+static void dpy_gfx_update_texture(QemuConsole *con, DisplaySurface *surface,
+                                   int x, int y, int w, int h)
+{
+    if (con->gl && con->gl->ops->dpy_gl_ctx_update_texture) {
+        con->gl->ops->dpy_gl_ctx_update_texture(con->gl, surface, x, y, w, h);
+    }
+}
 
 static void displaychangelistener_display_console(DisplayChangeListener *dcl,
                                                   QemuConsole *con,
@@ -1078,6 +1099,7 @@ static void displaychangelistener_display_console(DisplayChangeListener *dcl,
     if (!con || !console_compatible_with(con, dcl, errp)) {
         if (!dummy) {
             dummy = qemu_create_placeholder_surface(640, 480, nodev);
+            dpy_gfx_create_texture(con, dummy);
         }
         displaychangelistener_gfx_switch(dcl, dummy);
         return;
@@ -1098,6 +1120,7 @@ static void displaychangelistener_display_console(DisplayChangeListener *dcl,
                                          con->scanout.texture.width,
                                          con->scanout.texture.height);
     } else if (con->scanout.kind == SCANOUT_SURFACE) {
+        dpy_gfx_create_texture(con, con->surface);
         displaychangelistener_gfx_switch(dcl, con->surface);
     }
 
@@ -1634,6 +1657,7 @@ void dpy_gfx_update(QemuConsole *con, int x, int y, int w, int h)
     if (!qemu_console_is_visible(con)) {
         return;
     }
+    dpy_gfx_update_texture(con, con->surface, x, y, w, h);
     QLIST_FOREACH(dcl, &s->listeners, next) {
         if (con != (dcl->con ? dcl->con : active_console)) {
             continue;
@@ -1678,12 +1702,14 @@ void dpy_gfx_replace_surface(QemuConsole *con,
 
     con->scanout.kind = SCANOUT_SURFACE;
     con->surface = surface;
+    dpy_gfx_create_texture(con, surface);
     QLIST_FOREACH(dcl, &s->listeners, next) {
         if (con != (dcl->con ? dcl->con : active_console)) {
             continue;
         }
         displaychangelistener_gfx_switch(dcl, surface);
     }
+    dpy_gfx_destroy_texture(con, old_surface);
     qemu_free_displaysurface(old_surface);
 }
 
ui/dbus-listener.c +0 -11
index 81c119b13a2c..a287edd2fc15 100644
@@ -42,7 +42,6 @@ struct _DBusDisplayListener {
 
     DisplayChangeListener dcl;
     DisplaySurface *ds;
-    QemuGLShader *gls;
     int gl_updates;
 };
 
@@ -240,10 +239,6 @@ static void dbus_gl_gfx_update(DisplayChangeListener *dcl,
 {
     DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
 
-    if (ddl->ds) {
-        surface_gl_update_texture(ddl->gls, ddl->ds, x, y, w, h);
-    }
-
     ddl->gl_updates++;
 }
 
@@ -285,15 +280,11 @@ static void dbus_gl_gfx_switch(DisplayChangeListener *dcl,
 {
     DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
 
-    if (ddl->ds) {
-        surface_gl_destroy_texture(ddl->gls, ddl->ds);
-    }
     ddl->ds = new_surface;
     if (ddl->ds) {
         int width = surface_width(ddl->ds);
         int height = surface_height(ddl->ds);
 
-        surface_gl_create_texture(ddl->gls, ddl->ds);
         /* TODO: lazy send dmabuf (there are unnecessary sent otherwise) */
         dbus_scanout_texture(&ddl->dcl, ddl->ds->texture, false,
                              width, height, 0, 0, width, height);
@@ -403,7 +394,6 @@ dbus_display_listener_dispose(GObject *object)
     g_clear_object(&ddl->conn);
     g_clear_pointer(&ddl->bus_name, g_free);
     g_clear_object(&ddl->proxy);
-    g_clear_pointer(&ddl->gls, qemu_gl_fini_shader);
 
     G_OBJECT_CLASS(dbus_display_listener_parent_class)->dispose(object);
 }
@@ -414,7 +404,6 @@ dbus_display_listener_constructed(GObject *object)
     DBusDisplayListener *ddl = DBUS_DISPLAY_LISTENER(object);
 
     if (display_opengl) {
-        ddl->gls = qemu_gl_init_shader();
         ddl->dcl.ops = &dbus_gl_dcl_ops;
     } else {
         ddl->dcl.ops = &dbus_dcl_ops;
ui/dbus.c +24 -1
index 22c82d2f323a..8e2e4c9cad28 100644
@@ -55,11 +55,33 @@ dbus_is_compatible_dcl(DisplayGLCtx *dgc,
     return dcl->ops == &dbus_gl_dcl_ops || dcl->ops == &dbus_console_dcl_ops;
 }
 
+static void
+dbus_create_texture(DisplayGLCtx *ctx, DisplaySurface *surface)
+{
+    surface_gl_create_texture(ctx->gls, surface);
+}
+
+static void
+dbus_destroy_texture(DisplayGLCtx *ctx, DisplaySurface *surface)
+{
+    surface_gl_destroy_texture(ctx->gls, surface);
+}
+
+static void
+dbus_update_texture(DisplayGLCtx *ctx, DisplaySurface *surface,
+                    int x, int y, int w, int h)
+{
+    surface_gl_update_texture(ctx->gls, surface, x, y, w, h);
+}
+
 static const DisplayGLCtxOps dbus_gl_ops = {
     .dpy_gl_ctx_is_compatible_dcl = dbus_is_compatible_dcl,
     .dpy_gl_ctx_create       = dbus_create_context,
     .dpy_gl_ctx_destroy      = qemu_egl_destroy_context,
     .dpy_gl_ctx_make_current = qemu_egl_make_context_current,
+    .dpy_gl_ctx_create_texture = dbus_create_texture,
+    .dpy_gl_ctx_destroy_texture = dbus_destroy_texture,
+    .dpy_gl_ctx_update_texture = dbus_update_texture,
 };
 
 static NotifierList dbus_display_notifiers =
@@ -90,6 +112,7 @@ dbus_display_init(Object *o)
     g_autoptr(GDBusObjectSkeleton) vm = NULL;
 
     dd->glctx.ops = &dbus_gl_ops;
+    dd->glctx.gls = qemu_gl_init_shader();
     dd->iface = qemu_dbus_display1_vm_skeleton_new();
     dd->consoles = g_ptr_array_new_with_free_func(g_object_unref);
 
@@ -126,6 +149,7 @@ dbus_display_finalize(Object *o)
     g_clear_object(&dd->iface);
     g_free(dd->dbus_addr);
     g_free(dd->audiodev);
+    g_clear_pointer(&dd->glctx.gls, qemu_gl_fini_shader);
     dbus_display = NULL;
 }
 
--

2.34.1.428.gdcc0cd074f0c

#15 lore raw
In reply to [email protected]
Quoted 51 lines · On Thu, Feb 17, 2022 at 8:58 PM <[email protected]> wrote:

From: Marc-André Lureau <[email protected]>

Hi,

In the thread "[PATCH 0/6] ui/dbus: Share one listener for a console", Akihiko Odaki reported a number of issues with the GL and D-Bus display. His series propose a different design, and reverting some of my previous generic console changes to fix those issues.

However, as I work through the issue so far, they can be solved by reasonable simple fixes while keeping the console changes generic (not specific to the D-Bus display backend). I belive a shared infrastructure is more beneficial long term than having GL-specific code in the DBus code (in particular, the egl-headless & VNC combination could potentially use it)

Thanks a lot Akihiko for reporting the issues proposing a different approach! Please test this alternative series and let me know of any further issues. My understanding is that you are mainly concerned with the Cocoa backend, and I don't have a way to test it, so please check it. If necessary, we may well have to revert my earlier changes and go your way, eventually.

Marc-André Lureau (12):
ui/console: fix crash when using gl context with non-gl listeners ui/console: fix texture leak when calling surface_gl_create_texture()
ui: do not create a surface when resizing a GL scanout ui/console: move check for compatible GL context ui/console: move dcl compatiblity check to a callback ui/console: egl-headless is compatible with non-gl listeners ui/dbus: associate the DBusDisplayConsole listener with the given
console
ui/console: move console compatibility check to dcl_display_console() ui/shader: fix potential leak of shader on error ui/shader: free associated programs
ui/console: add a dpy_gfx_switch callback helper
ui/dbus: fix texture sharing

 include/ui/console.h |  19 ++++---
 ui/dbus.h            |   3 ++
 ui/console-gl.c      |   4 ++
 ui/console.c         | 119 ++++++++++++++++++++++++++-----------------
 ui/dbus-console.c    |  27 +++++-----
 ui/dbus-listener.c   |  11 ----
 ui/dbus.c            |  33 +++++++++++-
 ui/egl-headless.c    |  17 ++++++-
 ui/gtk.c             |  18 ++++++-
 ui/sdl2.c            |   9 +++-
 ui/shader.c          |   9 +++-
 ui/spice-display.c   |   9 +++-
 12 files changed, 192 insertions(+), 86 deletions(-)
Quoted 4 lines

--
2.34.1.428.gdcc0cd074f0c

You missed only one thing:

Quoted 3 lines

- that console_select and register_displaychangelistener may not call dpy_gfx_switch and call dpy_gl_scanout_texture instead. It is incompatible with non-OpenGL displays

displaychangelistener_display_console always has to call dpy_gfx_switch for non-OpenGL displays, but it still doesn't.

Anything else should be addressed with this patch series. (And it also has nice fixes for shader leaks.)

cocoa doesn't have OpenGL output and egl-headless, the cause of many pains addressed here, does not work on macOS so you need little attention. I have an out-of-tree OpenGL support for cocoa but it is out-of-tree anyway and I can fix it anytime.

Regards,
Akihiko Odaki

#16 lore raw

Hi

Quoted 67 lines · Akihiko Odaki
Quoted 6 lines · On Thu, Feb 17, 2022 at 8:58 PM <[email protected]> wrote:

From: Marc-André Lureau <[email protected]>

Hi,

In the thread "[PATCH 0/6] ui/dbus: Share one listener for a console",

Akihiko

Quoted 1 line

Odaki reported a number of issues with the GL and D-Bus display. His

series

Quoted 1 line

propose a different design, and reverting some of my previous generic

console

Quoted 3 lines

changes to fix those issues.

However, as I work through the issue so far, they can be solved by

reasonable

Quoted 1 line

simple fixes while keeping the console changes generic (not specific to

the

Quoted 1 line

D-Bus display backend). I belive a shared infrastructure is more

beneficial long

Quoted 4 lines

term than having GL-specific code in the DBus code (in particular, the egl-headless & VNC combination could potentially use it)

Thanks a lot Akihiko for reporting the issues proposing a different

approach!

Quoted 1 line

Please test this alternative series and let me know of any further

issues. My

Quoted 1 line

understanding is that you are mainly concerned with the Cocoa backend,

and I

Quoted 1 line

don't have a way to test it, so please check it. If necessary, we may

well have

Quoted 31 lines

to revert my earlier changes and go your way, eventually.

Marc-André Lureau (12):
ui/console: fix crash when using gl context with non-gl listeners ui/console: fix texture leak when calling surface_gl_create_texture()
ui: do not create a surface when resizing a GL scanout ui/console: move check for compatible GL context ui/console: move dcl compatiblity check to a callback ui/console: egl-headless is compatible with non-gl listeners ui/dbus: associate the DBusDisplayConsole listener with the given
console
ui/console: move console compatibility check to dcl_display_console() ui/shader: fix potential leak of shader on error ui/shader: free associated programs
ui/console: add a dpy_gfx_switch callback helper
ui/dbus: fix texture sharing

 include/ui/console.h |  19 ++++---
 ui/dbus.h            |   3 ++
 ui/console-gl.c      |   4 ++
 ui/console.c         | 119 ++++++++++++++++++++++++++-----------------
 ui/dbus-console.c    |  27 +++++-----
 ui/dbus-listener.c   |  11 ----
 ui/dbus.c            |  33 +++++++++++-
 ui/egl-headless.c    |  17 ++++++-
 ui/gtk.c             |  18 ++++++-
 ui/sdl2.c            |   9 +++-
 ui/shader.c          |   9 +++-
 ui/spice-display.c   |   9 +++-
 12 files changed, 192 insertions(+), 86 deletions(-)
Quoted 4 lines

--
2.34.1.428.gdcc0cd074f0c

Quoted 8 lines

You missed only one thing:

Quoted 3 lines

- that console_select and register_displaychangelistener may not call dpy_gfx_switch and call dpy_gl_scanout_texture instead. It is incompatible with non-OpenGL displays

displaychangelistener_display_console always has to call dpy_gfx_switch for non-OpenGL displays, but it still doesn't.

Ok, would that be what you have in mind?

--- a/ui/console.c
+++ b/ui/console.c
@@ -1122,6 +1122,10 @@ static void displaychangelistener_display_console(DisplayChangeListener *dcl,

     } else if (con->scanout.kind == SCANOUT_SURFACE) {
         dpy_gfx_create_texture(con, con->surface);
         displaychangelistener_gfx_switch(dcl, con->surface);
+    } else {
+        /* use the fallback surface, egl-headless keeps it updated */
+        assert(con->surface);
+        displaychangelistener_gfx_switch(dcl, con->surface);
     }

I wish such egl-headless specific code would be there, but we would need more refactoring.

I think I would rather have a backend split for GL context, like "-object egl-context". egl-headless-specific copy code would be handled by common/util code for anything that wants a pixman surface (VNC, screen capture, non-GL display etc).

This split would allow sharing the context code, and introduce other system specific GL initialization, such as WGL etc. Right now, I doubt the EGL code works on anything but Linux.

Quoted 3 lines

Anything else should be addressed with this patch series. (And it also has nice fixes for shader leaks.)

thanks

Quoted 6 lines

cocoa doesn't have OpenGL output and egl-headless, the cause of many pains addressed here, does not work on macOS so you need little attention. I have an out-of-tree OpenGL support for cocoa but it is out-of-tree anyway and I can fix it anytime.

Great!

btw, I suppose you checked your DBus changes against the WIP "qemu-display" project. What was your experience? I don't think many people have tried it yet. Do you think this could be made to work on macOS? at least the non-dmabuf support should work, as long as Gtk4 has good macOS support. I don't know if dmabuf or similar exist there, any idea?

Signature · 1 line
Marc-André Lureau
#17 lore raw
Quoted 76 lines · Marc-André Lureau

Hi

Quoted 58 lines · Akihiko Odaki
Quoted 51 lines · On Thu, Feb 17, 2022 at 8:58 PM <[email protected]> wrote:

From: Marc-André Lureau <[email protected]>

Hi,

In the thread "[PATCH 0/6] ui/dbus: Share one listener for a console", Akihiko Odaki reported a number of issues with the GL and D-Bus display. His series propose a different design, and reverting some of my previous generic console changes to fix those issues.

However, as I work through the issue so far, they can be solved by reasonable simple fixes while keeping the console changes generic (not specific to the D-Bus display backend). I belive a shared infrastructure is more beneficial long term than having GL-specific code in the DBus code (in particular, the egl-headless & VNC combination could potentially use it)

Thanks a lot Akihiko for reporting the issues proposing a different approach! Please test this alternative series and let me know of any further issues. My understanding is that you are mainly concerned with the Cocoa backend, and I don't have a way to test it, so please check it. If necessary, we may well have to revert my earlier changes and go your way, eventually.

Marc-André Lureau (12):
ui/console: fix crash when using gl context with non-gl listeners ui/console: fix texture leak when calling surface_gl_create_texture()
ui: do not create a surface when resizing a GL scanout ui/console: move check for compatible GL context ui/console: move dcl compatiblity check to a callback ui/console: egl-headless is compatible with non-gl listeners ui/dbus: associate the DBusDisplayConsole listener with the given
console
ui/console: move console compatibility check to dcl_display_console() ui/shader: fix potential leak of shader on error ui/shader: free associated programs
ui/console: add a dpy_gfx_switch callback helper
ui/dbus: fix texture sharing

 include/ui/console.h |  19 ++++---
 ui/dbus.h            |   3 ++
 ui/console-gl.c      |   4 ++
 ui/console.c         | 119 ++++++++++++++++++++++++++-----------------
 ui/dbus-console.c    |  27 +++++-----
 ui/dbus-listener.c   |  11 ----
 ui/dbus.c            |  33 +++++++++++-
 ui/egl-headless.c    |  17 ++++++-
 ui/gtk.c             |  18 ++++++-
 ui/sdl2.c            |   9 +++-
 ui/shader.c          |   9 +++-
 ui/spice-display.c   |   9 +++-
 12 files changed, 192 insertions(+), 86 deletions(-)
Quoted 4 lines

--
2.34.1.428.gdcc0cd074f0c

Quoted 7 lines

You missed only one thing:

Quoted 3 lines

- that console_select and register_displaychangelistener may not call dpy_gfx_switch and call dpy_gl_scanout_texture instead. It is incompatible with non-OpenGL displays

displaychangelistener_display_console always has to call dpy_gfx_switch for non-OpenGL displays, but it still doesn't.

Ok, would that be what you have in mind?

--- a/ui/console.c
+++ b/ui/console.c

Review static void displaychangelistener_display_console(DisplayChangeListener *dcl, · line 1129

Quoted 8 lines
(quoted diff) +4 -0
@@ -1122,6 +1122,10 @@ static void displaychangelistener_display_console(DisplayChangeListener *dcl,
     } else if (con->scanout.kind == SCANOUT_SURFACE) {
         dpy_gfx_create_texture(con, con->surface);
         displaychangelistener_gfx_switch(dcl, con->surface);
+    } else {
+        /* use the fallback surface, egl-headless keeps it updated */
+        assert(con->surface);
+        displaychangelistener_gfx_switch(dcl, con->surface);
     }

It should call displaychangelistener_gfx_switch even when e.g. con->scanout.kind == SCANOUT_TEXTURE. egl-headless renders the content to the last DisplaySurface it received while con->scanout.kind == SCANOUT_TEXTURE.

Quoted 6 lines

I wish such egl-headless specific code would be there, but we would need more refactoring.

I think I would rather have a backend split for GL context, like "-object egl-context". egl-headless-specific copy code would be handled by common/util code for anything that wants a pixman surface (VNC, screen capture, non-GL display etc).

This split would allow sharing the context code, and introduce other system specific GL initialization, such as WGL etc. Right now, I doubt the EGL code works on anything but Linux.

Sharing the context code is unlikely to happen. Usually the toolkit (GTK, SDL, or Cocoa in my fork) knows what graphics accelerator should be used and how the context should be created for a particular window. The context sharing can be achieved only for headless displays, namely dbus, egl-headless and spice. Few people would want to use them in combination.

Quoted 16 lines
Quoted 4 lines

Anything else should be addressed with this patch series. (And it also has nice fixes for shader leaks.)

thanks

Quoted 6 lines

cocoa doesn't have OpenGL output and egl-headless, the cause of many pains addressed here, does not work on macOS so you need little attention. I have an out-of-tree OpenGL support for cocoa but it is out-of-tree anyway and I can fix it anytime.

Quoted 3 lines

Great!

btw, I suppose you checked your DBus changes against the WIP "qemu-display" project. What was your experience? I don't think many people have tried it yet. Do you think this could be made to work on macOS? at least the non-dmabuf support should work, as long as Gtk4 has good macOS support. I don't know if dmabuf or similar exist there, any idea?

I tested it on Fedora. I think it would probably work on macOS but maybe require some tweaks. IOSurface is a counterpart of DMA-BUF in macOS but its situation is bad; it must be delivered via macOS's own IPC mechanisms (Mach port and XPC), but they are for server-client model and not for P2P. fileport mechanism allows to convert Mach port to file descriptor, but it is not documented. (In reality, I think all of the major browsers, Chromium, Firefox and Safari use fileport for this purpose. Apple should really document it if they use it for their app.) It is also possible to share IOSurface with a global number, but it can be brute-forced and is insecure.

Regards,
Akihiko Odaki

Quoted 4 lines

--
Marc-André Lureau

#18 lore raw

Hi

Quoted 102 lines · Akihiko Odaki
Quoted 4 lines · Marc-André Lureau

Hi

On Thu, Feb 17, 2022 at 5:09 PM Akihiko Odaki <[email protected]>

Quoted 8 lines · wrote:
Quoted 8 lines · On Thu, Feb 17, 2022 at 8:58 PM <[email protected]> wrote:
Quoted 6 lines

From: Marc-André Lureau <[email protected]>

Hi,

In the thread "[PATCH 0/6] ui/dbus: Share one listener for a

console", Akihiko

Quoted 1 line
Quoted 1 line
Quoted 1 line

Odaki reported a number of issues with the GL and D-Bus display. His

series

Quoted 1 line
Quoted 1 line
Quoted 1 line

propose a different design, and reverting some of my previous generic

console

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

changes to fix those issues.

However, as I work through the issue so far, they can be solved by

reasonable

Quoted 1 line
Quoted 1 line
Quoted 1 line

simple fixes while keeping the console changes generic (not specific

to the

Quoted 1 line
Quoted 1 line
Quoted 1 line

D-Bus display backend). I belive a shared infrastructure is more

beneficial long

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

term than having GL-specific code in the DBus code (in particular, the egl-headless & VNC combination could potentially use it)

Thanks a lot Akihiko for reporting the issues proposing a different

approach!

Quoted 1 line
Quoted 1 line
Quoted 1 line

Please test this alternative series and let me know of any further

issues. My

Quoted 1 line
Quoted 1 line
Quoted 1 line

understanding is that you are mainly concerned with the Cocoa

backend, and I

Quoted 1 line
Quoted 1 line
Quoted 1 line

don't have a way to test it, so please check it. If necessary, we may

well have

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

to revert my earlier changes and go your way, eventually.

Marc-André Lureau (12):
ui/console: fix crash when using gl context with non-gl listeners ui/console: fix texture leak when calling

surface_gl_create_texture()

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

ui: do not create a surface when resizing a GL scanout ui/console: move check for compatible GL context ui/console: move dcl compatiblity check to a callback ui/console: egl-headless is compatible with non-gl listeners ui/dbus: associate the DBusDisplayConsole listener with the given
console
ui/console: move console compatibility check to

dcl_display_console()

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

ui/shader: fix potential leak of shader on error ui/shader: free associated programs ui/console: add a dpy_gfx_switch callback helper ui/dbus: fix texture sharing

 include/ui/console.h |  19 ++++---
 ui/dbus.h            |   3 ++
 ui/console-gl.c      |   4 ++
 ui/console.c         | 119

++++++++++++++++++++++++++-----------------

Review static void

Quoted 29 lines
Quoted 15 lines
Quoted 10 lines
 ui/dbus-console.c    |  27 +++++-----
 ui/dbus-listener.c   |  11 ----
 ui/dbus.c            |  33 +++++++++++-
 ui/egl-headless.c    |  17 ++++++-
 ui/gtk.c             |  18 ++++++-
 ui/sdl2.c            |   9 +++-
 ui/shader.c          |   9 +++-
 ui/spice-display.c   |   9 +++-
 12 files changed, 192 insertions(+), 86 deletions(-)
Quoted 4 lines

--
2.34.1.428.gdcc0cd074f0c

Quoted 7 lines

You missed only one thing:

Quoted 3 lines

- that console_select and register_displaychangelistener may not call dpy_gfx_switch and call dpy_gl_scanout_texture instead. It is incompatible with non-OpenGL displays

displaychangelistener_display_console always has to call dpy_gfx_switch for non-OpenGL displays, but it still doesn't.

Ok, would that be what you have in mind?

--- a/ui/console.c
+++ b/ui/console.c

(quoted diff) +0 -0
@@ -1122,6 +1122,10 @@ static void

displaychangelistener_display_console(DisplayChangeListener *dcl,

Review static void · line 1129

Quoted 8 lines
(quoted diff) +4 -0
     } else if (con->scanout.kind == SCANOUT_SURFACE) {
         dpy_gfx_create_texture(con, con->surface);
         displaychangelistener_gfx_switch(dcl, con->surface);
+    } else {
+        /* use the fallback surface, egl-headless keeps it updated */
+        assert(con->surface);
+        displaychangelistener_gfx_switch(dcl, con->surface);
     }
Quoted 5 lines

It should call displaychangelistener_gfx_switch even when e.g. con->scanout.kind == SCANOUT_TEXTURE. egl-headless renders the content to the last DisplaySurface it received while con->scanout.kind == SCANOUT_TEXTURE.

I see, egl-headless is really not a "listener".

Quoted 13 lines
Quoted 2 lines

I wish such egl-headless specific code would be there, but we would need

more refactoring.

Quoted 2 lines

I think I would rather have a backend split for GL context, like

"-object egl-context". egl-headless-specific copy code would be handled by common/util code for anything that wants a pixman surface (VNC, screen capture, non-GL display etc).

Quoted 2 lines

This split would allow sharing the context code, and introduce other

system specific GL initialization, such as WGL etc. Right now, I doubt the EGL code works on anything but Linux.

Quoted 7 lines

Sharing the context code is unlikely to happen. Usually the toolkit (GTK, SDL, or Cocoa in my fork) knows what graphics accelerator should be used and how the context should be created for a particular window. The context sharing can be achieved only for headless displays, namely dbus, egl-headless and spice. Few people would want to use them in combination.

Ok for toolkits, they usually have their own context. But ideally, qemu should be "headless". And the GL contexts should be working on other systems than EGL Linux.

Any of the spice, vnc, dbus display etc may legitimately be fixed to work with WGL etc. Doing this repeatedly on the various display backends would be bad design.

Although my idea is that display servers (spice, vnc, rdp, etc) & various UI (gtk, cocoa, sdl, etc) should be outside of qemu. The display would use IPC, based on DBus if it fits the job, or something else if necessary. Obviously, there is still a lot of work to do to improve surface & texture sharing and portability, but that should be possible...

Quoted 25 lines
Quoted 17 lines
Quoted 5 lines

Anything else should be addressed with this patch series. (And it also has nice fixes for shader leaks.)

thanks

Quoted 6 lines

cocoa doesn't have OpenGL output and egl-headless, the cause of many pains addressed here, does not work on macOS so you need little attention. I have an out-of-tree OpenGL support for cocoa but it is out-of-tree anyway and I can fix it anytime.

Quoted 3 lines

Great!

btw, I suppose you checked your DBus changes against the WIP

"qemu-display" project. What was your experience? I don't think many people have tried it yet. Do you think this could be made to work on macOS? at least the non-dmabuf support should work, as long as Gtk4 has good macOS support. I don't know if dmabuf or similar exist there, any idea?

Quoted 12 lines

I tested it on Fedora. I think it would probably work on macOS but maybe require some tweaks. IOSurface is a counterpart of DMA-BUF in macOS but its situation is bad; it must be delivered via macOS's own IPC mechanisms (Mach port and XPC), but they are for server-client model and not for P2P. fileport mechanism allows to convert Mach port to file descriptor, but it is not documented. (In reality, I think all of the major browsers, Chromium, Firefox and Safari use fileport for this purpose. Apple should really document it if they use it for their app.) It is also possible to share IOSurface with a global number, but it can be brute-forced and is insecure.

Thanks, the Gtk developers might have some clue. They have been working on improving macOS support, and it can use opengl now (
https://blogs.gnome.org/chergert/2020/12/15/gtk-4-got-a-new-macos-backend-now-with-opengl/
).

Quoted 8 lines

Regards,
Akihiko Odaki

Quoted 4 lines

--
Marc-André Lureau

Signature · 1 line
Marc-André Lureau
#19 lore raw
Quoted 116 lines · Marc-André Lureau

Hi

Quoted 76 lines · Akihiko Odaki
Quoted 73 lines · Marc-André Lureau

Hi

Quoted 58 lines · Akihiko Odaki
Quoted 51 lines · On Thu, Feb 17, 2022 at 8:58 PM <[email protected]> wrote:

From: Marc-André Lureau <[email protected]>

Hi,

In the thread "[PATCH 0/6] ui/dbus: Share one listener for a console", Akihiko Odaki reported a number of issues with the GL and D-Bus display. His series propose a different design, and reverting some of my previous generic console changes to fix those issues.

However, as I work through the issue so far, they can be solved by reasonable simple fixes while keeping the console changes generic (not specific to the D-Bus display backend). I belive a shared infrastructure is more beneficial long term than having GL-specific code in the DBus code (in particular, the egl-headless & VNC combination could potentially use it)

Thanks a lot Akihiko for reporting the issues proposing a different approach! Please test this alternative series and let me know of any further issues. My understanding is that you are mainly concerned with the Cocoa backend, and I don't have a way to test it, so please check it. If necessary, we may well have to revert my earlier changes and go your way, eventually.

Marc-André Lureau (12):
ui/console: fix crash when using gl context with non-gl listeners ui/console: fix texture leak when calling surface_gl_create_texture()
ui: do not create a surface when resizing a GL scanout ui/console: move check for compatible GL context ui/console: move dcl compatiblity check to a callback ui/console: egl-headless is compatible with non-gl listeners ui/dbus: associate the DBusDisplayConsole listener with the given
console
ui/console: move console compatibility check to dcl_display_console() ui/shader: fix potential leak of shader on error ui/shader: free associated programs
ui/console: add a dpy_gfx_switch callback helper
ui/dbus: fix texture sharing

 include/ui/console.h |  19 ++++---
 ui/dbus.h            |   3 ++
 ui/console-gl.c      |   4 ++
 ui/console.c         | 119 ++++++++++++++++++++++++++-----------------
 ui/dbus-console.c    |  27 +++++-----
 ui/dbus-listener.c   |  11 ----
 ui/dbus.c            |  33 +++++++++++-
 ui/egl-headless.c    |  17 ++++++-
 ui/gtk.c             |  18 ++++++-
 ui/sdl2.c            |   9 +++-
 ui/shader.c          |   9 +++-
 ui/spice-display.c   |   9 +++-
 12 files changed, 192 insertions(+), 86 deletions(-)
Quoted 4 lines

--
2.34.1.428.gdcc0cd074f0c

Quoted 7 lines

You missed only one thing:

Quoted 3 lines

- that console_select and register_displaychangelistener may not call dpy_gfx_switch and call dpy_gl_scanout_texture instead. It is incompatible with non-OpenGL displays

displaychangelistener_display_console always has to call dpy_gfx_switch for non-OpenGL displays, but it still doesn't.

Ok, would that be what you have in mind?

Quoted 16 lines

Review static void displaychangelistener_display_console(DisplayChangeListener *dcl, · line 1129

Quoted 11 lines

--- a/ui/console.c
+++ b/ui/console.c

(quoted diff) +4 -0
@@ -1122,6 +1122,10 @@ static void displaychangelistener_display_console(DisplayChangeListener *dcl,
     } else if (con->scanout.kind == SCANOUT_SURFACE) {
         dpy_gfx_create_texture(con, con->surface);
         displaychangelistener_gfx_switch(dcl, con->surface);
+    } else {
+        /* use the fallback surface, egl-headless keeps it updated */
+        assert(con->surface);
+        displaychangelistener_gfx_switch(dcl, con->surface);
     }

It should call displaychangelistener_gfx_switch even when e.g. con->scanout.kind == SCANOUT_TEXTURE. egl-headless renders the content to the last DisplaySurface it received while con->scanout.kind == SCANOUT_TEXTURE.

I see, egl-headless is really not a "listener".

Quoted 6 lines
Quoted 6 lines

I wish such egl-headless specific code would be there, but we would need more refactoring.

I think I would rather have a backend split for GL context, like "-object egl-context". egl-headless-specific copy code would be handled by common/util code for anything that wants a pixman surface (VNC, screen capture, non-GL display etc).

Quoted 8 lines
Quoted 1 line

This split would allow sharing the context code, and introduce other system specific GL initialization, such as WGL etc. Right now, I doubt the EGL code works on anything but Linux.

Sharing the context code is unlikely to happen. Usually the toolkit (GTK, SDL, or Cocoa in my fork) knows what graphics accelerator should be used and how the context should be created for a particular window. The context sharing can be achieved only for headless displays, namely dbus, egl-headless and spice. Few people would want to use them in combination.

Quoted 3 lines

Ok for toolkits, they usually have their own context. But ideally, qemu should be "headless". And the GL contexts should be working on other systems than EGL Linux.

Any of the spice, vnc, dbus display etc may legitimately be fixed to work with WGL etc. Doing this repeatedly on the various display backends would be bad design.

We already have ui/egl-context.c to share the code for EGL. We can have ui/headless-context.c or something which creates a context for headless but the implementation can be anything proper there. It doesn't require modifying ui/console.c or adding something like "-object egl-context".

Quoted 2 lines

Although my idea is that display servers (spice, vnc, rdp, etc) & various UI (gtk, cocoa, sdl, etc) should be outside of qemu. The display would use IPC, based on DBus if it fits the job, or something else if necessary. Obviously, there is still a lot of work to do to improve surface & texture sharing and portability, but that should be possible...

Maybe we can rework the present UIs of QEMU to make them compatible with both in-process communication and D-Bus inter-process communication. If the user has a requirement incompatible with IPC (e.g. OpenGL on macOS), the user can opt for in-process communication. D-Bus would be used otherwise. (Of course that would require substantial effort.)

Quoted 35 lines
Quoted 23 lines
Quoted 19 lines
Quoted 7 lines

Anything else should be addressed with this patch series. (And it also has nice fixes for shader leaks.)

thanks

Quoted 6 lines

cocoa doesn't have OpenGL output and egl-headless, the cause of many pains addressed here, does not work on macOS so you need little attention. I have an out-of-tree OpenGL support for cocoa but it is out-of-tree anyway and I can fix it anytime.

Quoted 3 lines

Great!

btw, I suppose you checked your DBus changes against the WIP "qemu-display" project. What was your experience? I don't think many people have tried it yet. Do you think this could be made to work on macOS? at least the non-dmabuf support should work, as long as Gtk4 has good macOS support. I don't know if dmabuf or similar exist there, any idea?

Quoted 11 lines

I tested it on Fedora. I think it would probably work on macOS but maybe require some tweaks. IOSurface is a counterpart of DMA-BUF in macOS but its situation is bad; it must be delivered via macOS's own IPC mechanisms (Mach port and XPC), but they are for server-client model and not for P2P. fileport mechanism allows to convert Mach port to file descriptor, but it is not documented. (In reality, I think all of the major browsers, Chromium, Firefox and Safari use fileport for this purpose. Apple should really document it if they use it for their app.) It is also possible to share IOSurface with a global number, but it can be brute-forced and is insecure.

Quoted 1 line

Thanks, the Gtk developers might have some clue. They have been working on improving macOS support, and it can use opengl now (https://blogs.gnome.org/chergert/2020/12/15/gtk-4-got-a-new-macos-backend-now-with-opengl/).

They don't need IPC for passing textures so that is a different story.

Quoted 14 lines
Quoted 9 lines

Regards,
Akihiko Odaki

Quoted 4 lines

--
Marc-André Lureau

--
Marc-André Lureau

#20 lore raw

Hi

Quoted 147 lines · Akihiko Odaki
Quoted 4 lines · Marc-André Lureau

Hi

On Thu, Feb 17, 2022 at 8:39 PM Akihiko Odaki <[email protected]>

Quoted 7 lines · wrote:
Quoted 7 lines
Quoted 4 lines · Marc-André Lureau

Hi

On Thu, Feb 17, 2022 at 5:09 PM Akihiko Odaki <

Quoted 8 lines · [email protected]> wrote:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · On Thu, Feb 17, 2022 at 8:58 PM <[email protected]> wrote:
Quoted 6 lines

From: Marc-André Lureau <[email protected]>

Hi,

In the thread "[PATCH 0/6] ui/dbus: Share one listener for a

console", Akihiko

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Odaki reported a number of issues with the GL and D-Bus display.

His series

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

propose a different design, and reverting some of my previous

generic console

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

changes to fix those issues.

However, as I work through the issue so far, they can be solved by

reasonable

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

simple fixes while keeping the console changes generic (not

specific to the

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

D-Bus display backend). I belive a shared infrastructure is more

beneficial long

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

term than having GL-specific code in the DBus code (in particular,

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

egl-headless & VNC combination could potentially use it)

Thanks a lot Akihiko for reporting the issues proposing a

different approach!

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Please test this alternative series and let me know of any further

issues. My

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

understanding is that you are mainly concerned with the Cocoa

backend, and I

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

don't have a way to test it, so please check it. If necessary, we

may well have

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

to revert my earlier changes and go your way, eventually.

Marc-André Lureau (12):
ui/console: fix crash when using gl context with non-gl listeners ui/console: fix texture leak when calling

surface_gl_create_texture()

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

ui: do not create a surface when resizing a GL scanout ui/console: move check for compatible GL context ui/console: move dcl compatiblity check to a callback ui/console: egl-headless is compatible with non-gl listeners ui/dbus: associate the DBusDisplayConsole listener with the given
console
ui/console: move console compatibility check to

dcl_display_console()

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

ui/shader: fix potential leak of shader on error ui/shader: free associated programs ui/console: add a dpy_gfx_switch callback helper ui/dbus: fix texture sharing

 include/ui/console.h |  19 ++++---
 ui/dbus.h            |   3 ++
 ui/console-gl.c      |   4 ++
 ui/console.c         | 119

++++++++++++++++++++++++++-----------------

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
 ui/dbus-console.c    |  27 +++++-----
 ui/dbus-listener.c   |  11 ----
 ui/dbus.c            |  33 +++++++++++-
 ui/egl-headless.c    |  17 ++++++-
 ui/gtk.c             |  18 ++++++-
 ui/sdl2.c            |   9 +++-
 ui/shader.c          |   9 +++-
 ui/spice-display.c   |   9 +++-
 12 files changed, 192 insertions(+), 86 deletions(-)
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

--
2.34.1.428.gdcc0cd074f0c

You missed only one thing:

Quoted 1 line

- that console_select and register_displaychangelistener may not

call

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

dpy_gfx_switch and call dpy_gl_scanout_texture instead. It is incompatible with non-OpenGL displays

displaychangelistener_display_console always has to call dpy_gfx_switch for non-OpenGL displays, but it still doesn't.

Quoted 5 lines
Quoted 5 lines

Review static void

Quoted 5 lines

Ok, would that be what you have in mind?

--- a/ui/console.c
+++ b/ui/console.c

(quoted diff) +0 -0
@@ -1122,6 +1122,10 @@ static void

displaychangelistener_display_console(DisplayChangeListener *dcl,

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
(quoted diff) +4 -0
     } else if (con->scanout.kind == SCANOUT_SURFACE) {
         dpy_gfx_create_texture(con, con->surface);
         displaychangelistener_gfx_switch(dcl, con->surface);
+    } else {
+        /* use the fallback surface, egl-headless keeps it updated */
+        assert(con->surface);
+        displaychangelistener_gfx_switch(dcl, con->surface);
     }
Quoted 11 lines
Quoted 4 lines

It should call displaychangelistener_gfx_switch even when e.g. con->scanout.kind == SCANOUT_TEXTURE. egl-headless renders the content to the last DisplaySurface it received while con->scanout.kind == SCANOUT_TEXTURE.

I see, egl-headless is really not a "listener".

Quoted 3 lines
Quoted 3 lines

I wish such egl-headless specific code would be there, but we would

need more refactoring.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

I think I would rather have a backend split for GL context, like

"-object egl-context". egl-headless-specific copy code would be handled by common/util code for anything that wants a pixman surface (VNC, screen capture, non-GL display etc).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

This split would allow sharing the context code, and introduce other

system specific GL initialization, such as WGL etc. Right now, I doubt the EGL code works on anything but Linux.

Quoted 10 lines
Quoted 7 lines

Sharing the context code is unlikely to happen. Usually the toolkit (GTK, SDL, or Cocoa in my fork) knows what graphics accelerator should be used and how the context should be created for a particular window. The context sharing can be achieved only for headless displays, namely dbus, egl-headless and spice. Few people would want to use them in combination.

Ok for toolkits, they usually have their own context. But ideally, qemu

should be "headless". And the GL contexts should be working on other systems than EGL Linux.

Quoted 2 lines

Any of the spice, vnc, dbus display etc may legitimately be fixed to

Quoted 9 lines

work with WGL etc. Doing this repeatedly on the various display backends would be bad design.

We already have ui/egl-context.c to share the code for EGL. We can have ui/headless-context.c or something which creates a context for headless but the implementation can be anything proper there. It doesn't require modifying ui/console.c or adding something like "-object egl-context".

Agree, as long as you have only a single context provider per system. But that's not my experience with GL in the past. Maybe this is true today.

Quoted 7 lines
Quoted 2 lines

Although my idea is that display servers (spice, vnc, rdp, etc) &

various UI (gtk, cocoa, sdl, etc) should be outside of qemu. The display would use IPC, based on DBus if it fits the job, or something else if necessary. Obviously, there is still a lot of work to do to improve surface & texture sharing and portability, but that should be possible...

Quoted 7 lines

Maybe we can rework the present UIs of QEMU to make them compatible with both in-process communication and D-Bus inter-process communication. If the user has a requirement incompatible with IPC (e.g. OpenGL on macOS), the user can opt for in-process communication. D-Bus would be used otherwise. (Of course that would require substantial effort.)

That should be possible, as long the IPC is very close to the inner qemu API, we could have an IPC-based display code turned into a shared library instead and run in process. Although I think that would limit the kind of UI you can expect (it would be a bare display, like qemu-display today, not something that would bring you a full user-friendly UI, virt-manager/Boxes kind)

Quoted 40 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Anything else should be addressed with this patch series. (And it

also

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 1 line

has nice fixes for shader leaks.)

thanks

Quoted 6 lines

cocoa doesn't have OpenGL output and egl-headless, the cause of many pains addressed here, does not work on macOS so you need little attention. I have an out-of-tree OpenGL support for cocoa but it is out-of-tree anyway and I can fix it anytime.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Great!

btw, I suppose you checked your DBus changes against the WIP

"qemu-display" project. What was your experience? I don't think many people have tried it yet. Do you think this could be made to work on macOS? at least the non-dmabuf support should work, as long as Gtk4 has good macOS support. I don't know if dmabuf or similar exist there, any idea?

Quoted 13 lines
Quoted 12 lines

I tested it on Fedora. I think it would probably work on macOS but maybe require some tweaks. IOSurface is a counterpart of DMA-BUF in macOS but its situation is bad; it must be delivered via macOS's own IPC mechanisms (Mach port and XPC), but they are for server-client model and not for P2P. fileport mechanism allows to convert Mach port to file descriptor, but it is not documented. (In reality, I think all of the major browsers, Chromium, Firefox and Safari use fileport for this purpose. Apple should really document it if they use it for their app.) It is also possible to share IOSurface with a global number, but it can be brute-forced and is insecure.

Quoted 7 lines
Quoted 1 line

Thanks, the Gtk developers might have some clue. They have been working

on improving macOS support, and it can use opengl now (
https://blogs.gnome.org/chergert/2020/12/15/gtk-4-got-a-new-macos-backend-now-with-opengl/
).

They don't need IPC for passing textures so that is a different story.

Yes but they have web-engine and video decoding concerns (beside qemu/dmabuf gtk display they should be aware of). I'll try to reach Christian about it.

thanks

Quoted 15 lines
Quoted 14 lines
Quoted 9 lines

Regards,
Akihiko Odaki

Quoted 4 lines

--
Marc-André Lureau

--
Marc-André Lureau

Signature · 1 line
Marc-André Lureau
#21 lore raw
Quoted 127 lines · Marc-André Lureau

Hi

Quoted 123 lines · Akihiko Odaki
Quoted 119 lines · Marc-André Lureau

Hi

Quoted 76 lines · Akihiko Odaki
Quoted 73 lines · Marc-André Lureau

Hi

Quoted 58 lines · Akihiko Odaki
Quoted 51 lines · On Thu, Feb 17, 2022 at 8:58 PM <[email protected]> wrote:

From: Marc-André Lureau <[email protected]>

Hi,

In the thread "[PATCH 0/6] ui/dbus: Share one listener for a console", Akihiko Odaki reported a number of issues with the GL and D-Bus display. His series propose a different design, and reverting some of my previous generic console changes to fix those issues.

However, as I work through the issue so far, they can be solved by reasonable simple fixes while keeping the console changes generic (not specific to the D-Bus display backend). I belive a shared infrastructure is more beneficial long term than having GL-specific code in the DBus code (in particular, the egl-headless & VNC combination could potentially use it)

Thanks a lot Akihiko for reporting the issues proposing a different approach! Please test this alternative series and let me know of any further issues. My understanding is that you are mainly concerned with the Cocoa backend, and I don't have a way to test it, so please check it. If necessary, we may well have to revert my earlier changes and go your way, eventually.

Marc-André Lureau (12):
ui/console: fix crash when using gl context with non-gl listeners ui/console: fix texture leak when calling surface_gl_create_texture()
ui: do not create a surface when resizing a GL scanout ui/console: move check for compatible GL context ui/console: move dcl compatiblity check to a callback ui/console: egl-headless is compatible with non-gl listeners ui/dbus: associate the DBusDisplayConsole listener with the given
console
ui/console: move console compatibility check to dcl_display_console() ui/shader: fix potential leak of shader on error ui/shader: free associated programs
ui/console: add a dpy_gfx_switch callback helper
ui/dbus: fix texture sharing

 include/ui/console.h |  19 ++++---
 ui/dbus.h            |   3 ++
 ui/console-gl.c      |   4 ++
 ui/console.c         | 119 ++++++++++++++++++++++++++-----------------
 ui/dbus-console.c    |  27 +++++-----
 ui/dbus-listener.c   |  11 ----
 ui/dbus.c            |  33 +++++++++++-
 ui/egl-headless.c    |  17 ++++++-
 ui/gtk.c             |  18 ++++++-
 ui/sdl2.c            |   9 +++-
 ui/shader.c          |   9 +++-
 ui/spice-display.c   |   9 +++-
 12 files changed, 192 insertions(+), 86 deletions(-)
Quoted 4 lines

--
2.34.1.428.gdcc0cd074f0c

Quoted 7 lines

You missed only one thing:

Quoted 3 lines

- that console_select and register_displaychangelistener may not call dpy_gfx_switch and call dpy_gl_scanout_texture instead. It is incompatible with non-OpenGL displays

displaychangelistener_display_console always has to call dpy_gfx_switch for non-OpenGL displays, but it still doesn't.

Ok, would that be what you have in mind?

Quoted 16 lines

Review static void displaychangelistener_display_console(DisplayChangeListener *dcl, · line 1129

Quoted 11 lines

--- a/ui/console.c
+++ b/ui/console.c

(quoted diff) +4 -0
@@ -1122,6 +1122,10 @@ static void displaychangelistener_display_console(DisplayChangeListener *dcl,
     } else if (con->scanout.kind == SCANOUT_SURFACE) {
         dpy_gfx_create_texture(con, con->surface);
         displaychangelistener_gfx_switch(dcl, con->surface);
+    } else {
+        /* use the fallback surface, egl-headless keeps it updated */
+        assert(con->surface);
+        displaychangelistener_gfx_switch(dcl, con->surface);
     }

It should call displaychangelistener_gfx_switch even when e.g. con->scanout.kind == SCANOUT_TEXTURE. egl-headless renders the content to the last DisplaySurface it received while con->scanout.kind == SCANOUT_TEXTURE.

I see, egl-headless is really not a "listener".

Quoted 6 lines
Quoted 6 lines

I wish such egl-headless specific code would be there, but we would need more refactoring.

I think I would rather have a backend split for GL context, like "-object egl-context". egl-headless-specific copy code would be handled by common/util code for anything that wants a pixman surface (VNC, screen capture, non-GL display etc).

Quoted 8 lines
Quoted 1 line

This split would allow sharing the context code, and introduce other system specific GL initialization, such as WGL etc. Right now, I doubt the EGL code works on anything but Linux.

Sharing the context code is unlikely to happen. Usually the toolkit (GTK, SDL, or Cocoa in my fork) knows what graphics accelerator should be used and how the context should be created for a particular window. The context sharing can be achieved only for headless displays, namely dbus, egl-headless and spice. Few people would want to use them in combination.

Ok for toolkits, they usually have their own context. But ideally, qemu should be "headless". And the GL contexts should be working on other systems than EGL Linux.

Any of the spice, vnc, dbus display etc may legitimately be fixed to work with WGL etc. Doing this repeatedly on the various display backends would be bad design.

Quoted 8 lines
Quoted 5 lines

We already have ui/egl-context.c to share the code for EGL. We can have ui/headless-context.c or something which creates a context for headless but the implementation can be anything proper there. It doesn't require modifying ui/console.c or adding something like "-object egl-context".

Agree, as long as you have only a single context provider per system. But that's not my experience with GL in the past. Maybe this is true today.

It doesn't matter even if a system has multiple context providers. ui/headless-context.c may just choose the context provider according to the flag a user provided.

Quoted 13 lines
Quoted 11 lines
Quoted 4 lines

Although my idea is that display servers (spice, vnc, rdp, etc) & various UI (gtk, cocoa, sdl, etc) should be outside of qemu. The display would use IPC, based on DBus if it fits the job, or something else if necessary. Obviously, there is still a lot of work to do to improve surface & texture sharing and portability, but that should be possible...

Maybe we can rework the present UIs of QEMU to make them compatible with both in-process communication and D-Bus inter-process communication. If the user has a requirement incompatible with IPC (e.g. OpenGL on macOS), the user can opt for in-process communication. D-Bus would be used otherwise. (Of course that would require substantial effort.)

Quoted 1 line

That should be possible, as long the IPC is very close to the inner qemu API, we could have an IPC-based display code turned into a shared library instead and run in process.

That is exactly what I'm thinking of.

Quoted 1 line

Although I think that would limit the kind of UI you can expect (it would be a bare display, like qemu-display today, not something that would bring you a full user-friendly UI, virt-manager/Boxes kind)

I don't think QEMU has to provide anything fancier than the current UIs. Users can combine QEMU and the external UI implementation like virt-manager, which allows the UI to evolve in a separate way. The UIs in QEMU would remain as references.

Quoted 67 lines
Quoted 38 lines
Quoted 38 lines
Quoted 37 lines
Quoted 22 lines
Quoted 10 lines

Anything else should be addressed with this patch series. (And it also has nice fixes for shader leaks.)

thanks

Quoted 6 lines

cocoa doesn't have OpenGL output and egl-headless, the cause of many pains addressed here, does not work on macOS so you need little attention. I have an out-of-tree OpenGL support for cocoa but it is out-of-tree anyway and I can fix it anytime.

Quoted 3 lines

Great!

btw, I suppose you checked your DBus changes against the WIP "qemu-display" project. What was your experience? I don't think many people have tried it yet. Do you think this could be made to work on macOS? at least the non-dmabuf support should work, as long as Gtk4 has good macOS support. I don't know if dmabuf or similar exist there, any idea?

I tested it on Fedora. I think it would probably work on macOS but maybe require some tweaks. IOSurface is a counterpart of DMA-BUF in macOS but its situation is bad; it must be delivered via macOS's own IPC mechanisms (Mach port and XPC), but they are for server-client model and not for P2P. fileport mechanism allows to convert Mach port to file descriptor, but it is not documented. (In reality, I think all of the major browsers, Chromium, Firefox and Safari use fileport for this purpose. Apple should really document it if they use it for their app.) It is also possible to share IOSurface with a global number, but it can be brute-forced and is insecure.

Quoted 3 lines
Quoted 1 line

Thanks, the Gtk developers might have some clue. They have been working on improving macOS support, and it can use opengl now (https://blogs.gnome.org/chergert/2020/12/15/gtk-4-got-a-new-macos-backend-now-with-opengl/).

They don't need IPC for passing textures so that is a different story.

Yes but they have web-engine and video decoding concerns (beside qemu/dmabuf gtk display they should be aware of). I'll try to reach Christian about it.

thanks

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Regards,
Akihiko Odaki

Quoted 2 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

--
Marc-André Lureau

--
Marc-André Lureau

--
Marc-André Lureau

#22 lore raw
In reply to Marc-André Lureau

Hi

Quoted 27 lines · Marc-André Lureau
Quoted 23 lines · Akihiko Odaki
Quoted 1 line
Quoted 1 line
Quoted 1 line

btw, I suppose you checked your DBus changes against the WIP

"qemu-display" project. What was your experience? I don't think many people have tried it yet. Do you think this could be made to work on macOS? at least the non-dmabuf support should work, as long as Gtk4 has good macOS support. I don't know if dmabuf or similar exist there, any idea?

Quoted 13 lines
Quoted 12 lines

I tested it on Fedora. I think it would probably work on macOS but maybe require some tweaks. IOSurface is a counterpart of DMA-BUF in macOS but its situation is bad; it must be delivered via macOS's own IPC mechanisms (Mach port and XPC), but they are for server-client model and not for P2P. fileport mechanism allows to convert Mach port to file descriptor, but it is not documented. (In reality, I think all of the major browsers, Chromium, Firefox and Safari use fileport for this purpose. Apple should really document it if they use it for their app.) It is also possible to share IOSurface with a global number, but it can be brute-forced and is insecure.

Quoted 1 line

Thanks, the Gtk developers might have some clue. They have been working

on improving macOS support, and it can use opengl now (
https://blogs.gnome.org/chergert/2020/12/15/gtk-4-got-a-new-macos-backend-now-with-opengl/
).

Quoted 8 lines
Quoted 2 lines

They don't need IPC for passing textures so that is a different story.

Yes but they have web-engine and video decoding concerns (beside qemu/dmabuf gtk display they should be aware of). I'll try to reach Christian about it.

fwiw, here is Christian Hergert comment about texture sharing & gtk on macos:

"There is, and we are using it in GTK 4 as of 4.6 to render from OpenGL to a surface we can attach to CALayers or OpenGL textures. It has allowed us to do a bunch of tricks to ensure we have opaque surfaces since NSWindow doesn't have anything like set_opaque_region() from Wayland.

It's called IOSurface and the browsers use this to pass rendererings between processes."

Signature · 1 line
Marc-André Lureau
#23 lore raw
In reply to Akihiko Odaki
Quoted 11 lines · Akihiko Odaki
Quoted 11 lines
Quoted 7 lines

You missed only one thing:

Quoted 3 lines

- that console_select and register_displaychangelistener may not call dpy_gfx_switch and call dpy_gl_scanout_texture instead. It is incompatible with non-OpenGL displays

displaychangelistener_display_console always has to call dpy_gfx_switch for non-OpenGL displays, but it still doesn't.

Ok, would that be what you have in mind?

Quoted 16 lines

Review static void displaychangelistener_display_console(DisplayChangeListener *dcl, · line 1129

Quoted 11 lines

--- a/ui/console.c
+++ b/ui/console.c

(quoted diff) +4 -0
@@ -1122,6 +1122,10 @@ static void displaychangelistener_display_console(DisplayChangeListener *dcl,
      } else if (con->scanout.kind == SCANOUT_SURFACE) {
          dpy_gfx_create_texture(con, con->surface);
          displaychangelistener_gfx_switch(dcl, con->surface);
+    } else {
+        /* use the fallback surface, egl-headless keeps it updated */
+        assert(con->surface);
+        displaychangelistener_gfx_switch(dcl, con->surface);
      }

It should call displaychangelistener_gfx_switch even when e.g. con->scanout.kind == SCANOUT_TEXTURE. egl-headless renders the content to the last DisplaySurface it received while con->scanout.kind == SCANOUT_TEXTURE.

Hi,

Let me remind that the release date is approaching but the regression which breaks switching the console for vnc with egl-headless is still not fixed. (vnc has the feature to switch consoles with Ctrl+Alt+[1-9] if it is not bound to a particular console.)

Please fix this or, if not possible, revert the changes related to dbus.

My patch series is available for fixing the problem. The design it adopted is somewhat controversial and it cannot be applied to the current master branch. Please tell me if it is necessary to rebase this.
https://patchew.org/QEMU/[email protected]/

Regards,
Akihiko Odaki