UI patches
From: Marc-André Lureau <[email protected]>
The following changes since commit 4329d049d5b8d4af71c6b399d64a6d1b98856318:
Merge tag 'pull-tcg-20230626' of https://gitlab.com/rth7680/qemu into staging (2023-06-26 17:40:38 +0200)
are available in the Git repository at:
https://gitlab.com/marcandre.lureau/qemu.git tags/ui-pull-request
for you to fetch changes up to b41858bd0a1361fda7ecb2a08b9b07e21d67f57d:
ui/dbus: use shared D3D11 Texture2D when possible (2023-06-27 12:33:11 +0200)
----------------------------------------------------------------
UI patches
- add dbus multi-touch interface
- add dbus win32 support
- fixes for sdl & gtk display
- fix for win32 stdio chardev
----------------------------------------------------------------
Antonio Caggiano (1):
ui/sdl2: OpenGL window context
Bilal Elmoussaoui (2):
ui/touch: Move event handling to a common helper ui/dbus: Expose a touch device interface
Dongwon Kim (4):
virtio-gpu-udmabuf: create udmabuf for blob even when iov_cnt == 1 ui/gtk: set the area of the scanout texture correctly
virtio-gpu: OUT_OF_MEMORY if failing to create udmabuf ui/gtk: making dmabuf NULL when it's released.
Keqian Zhu via (1):
virtio-gpu: Optimize 2D resource data transfer
Marc-André Lureau (23):
ui: return NULL when getting cursor without a console
egl: no need to lookup EGL functions manually ui/egl: export qemu_egl_get_error_string() ui/egl: fix make_context_current() callback return value ui/dbus: compile without gio/gunixfdlist.h
scripts: add a XML preprocessor script
ui/dbus: win32 support
qtest: add qtest_pid()
tests: make dbus-display-test work on win32 ui/dbus: introduce "Interfaces" properties console/win32: allocate shareable display surface virtio-gpu/win32: allocate shareable 2d resources/images ui/dbus: use shared memory when possible on win32
ui: add egl-headless support on win32
ui/egl: default to GLES on windows
ui: add egl_fb_read_rect()
ui/dbus: add GL support on win32
ui/dbus: add some GL traces
virtio-gpu-virgl: teach it to get the QEMU EGL display ui/egl: query ANGLE d3d device
ui: add optional d3d texture pointer to scanout texture
virtio-gpu-virgl: use D3D11_SHARE_TEXTURE when available ui/dbus: use shared D3D11 Texture2D when possible
Vivek Kasireddy (1):
virtio-gpu: Make non-gl display updates work again when blob=true
Zhang Huasen (1):
chardev/char-win-stdio: Support VT sequences on Windows 11 host
MAINTAINERS | 1 + meson.build | 10 +- qapi/ui.json | 5 +- include/hw/virtio/virtio-gpu.h | 3 + include/sysemu/os-win32.h | 3 + include/ui/console.h | 30 +- include/ui/egl-helpers.h | 11 +- include/ui/gtk.h | 6 +- include/ui/sdl2.h | 3 +- tests/qtest/libqtest.h | 9 + ui/dbus.h | 6 + audio/dbusaudio.c | 43 ++- chardev/char-win-stdio.c | 2 +- hw/display/virtio-gpu-udmabuf.c | 3 +- hw/display/virtio-gpu-virgl.c | 43 ++- hw/display/virtio-gpu.c | 99 ++++-- tests/qtest/dbus-display-test.c | 43 ++- tests/qtest/libqtest.c | 5 + ui/console.c | 137 ++++++++- ui/dbus-chardev.c | 20 +- ui/dbus-console.c | 124 +++++++- ui/dbus-listener.c | 527 +++++++++++++++++++++++++++++--- ui/dbus.c | 4 - ui/egl-context.c | 10 +- ui/egl-headless.c | 25 +- ui/egl-helpers.c | 104 +++++-- ui/gtk-egl.c | 16 +- ui/gtk-gl-area.c | 6 +- ui/gtk.c | 66 +--- ui/qemu-pixman.c | 1 + ui/sdl2-gl.c | 3 +- ui/sdl2.c | 18 +- ui/spice-display.c | 3 +- util/oslib-win32.c | 33 ++ scripts/meson.build | 2 + scripts/xml-preprocess-test.py | 136 +++++++++ scripts/xml-preprocess.py | 293 ++++++++++++++++++ tests/qtest/meson.build | 2 +- ui/dbus-display1.xml | 285 ++++++++++++++++- ui/meson.build | 15 +- ui/trace-events | 9 +- util/trace-events | 4 + 42 files changed, 1953 insertions(+), 215 deletions(-) create mode 100644 scripts/xml-preprocess-test.py create mode 100755 scripts/xml-preprocess.py
Signature · 1 line
2.41.0
[PULL 09/33] virtio-gpu-udmabuf: create udmabuf for blob even when iov_cnt == 1
From: Dongwon Kim <[email protected]>
There were often cases where a scanout blob sometimes has just 1 entry that is linked to many pages in it. So just checking whether iov_cnt is 1 is not enough for screening small, non-scanout blobs. Therefore adding iov_len check as well to make sure it creates an udmabuf only for a scanout blob, which is at least bigger than one page size.
Message-ID: <[email protected]>
--- hw/display/virtio-gpu-udmabuf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/display/virtio-gpu-udmabuf.c +2 -1
@@ -132,7 +132,8 @@ void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res)void *pdata =NULL ; res->dmabuf_fd =-1 ; -if (res->iov_cnt ==1 ) { +if (res->iov_cnt ==1 && + res->iov[0 ].iov_len <4096 ) { pdata = res->iov[0 ].iov_base; }else {virtio_gpu_create_udmabuf (res);
Signature · 1 line
2.41.0
[PULL 15/33] ui/dbus: compile without gio/gunixfdlist.h
In reply to [email protected]From: Marc-André Lureau <[email protected]>
D-Bus on windows doesn't support fd-passing. Let's isolate the fdlist-related code as a first step, before adding Windows support, using another mechanism.
Message-Id: <[email protected]>
--- audio/dbusaudio.c | 7 +++++++ ui/dbus-chardev.c | 6 ++++++ ui/dbus-console.c | 8 ++++++++ ui/dbus-listener.c | 2 ++ 4 files changed, 23 insertions(+)
audio/dbusaudio.c +7 -0
@@ -29,7 +29,10 @@#include "qemu/timer.h" #include "qemu/dbus.h" +#ifdef G_OS_UNIX #include <gio/gunixfdlist.h> +#endif +#include "ui/dbus-display1.h" #define AUDIO_CAP "dbus"
@@ -419,6 +422,7 @@ dbus_audio_fini(void *opaque)g_free (da); } +#ifdef G_OS_UNIX static void listener_out_vanished_cb(GDBusConnection *connection, gboolean remote_peer_vanished,
@@ -591,6 +595,7 @@ dbus_audio_register_in_listener(AudioState *s,return dbus_audio_register_listener (s, invocation, fd_list, arg_listener, false); } +#endif static void dbus_audio_set_server (AudioState *s,GDBusObjectManagerServer *server,bool p2p)
@@ -605,12 +610,14 @@ dbus_audio_set_server(AudioState *s, GDBusObjectManagerServer *server, bool p2p) da->audio =g_dbus_object_skeleton_new (DBUS_DISPLAY1_AUDIO_PATH ); da->iface =qemu_dbus_display1_audio_skeleton_new (); +#ifdef G_OS_UNIX g_object_connect (da->iface,"swapped-signal::handle-register-in-listener" , dbus_audio_register_in_listener, s,"swapped-signal::handle-register-out-listener" , dbus_audio_register_out_listener, s,NULL ); +#endif g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (da->audio),G_DBUS_INTERFACE_SKELETON (da->iface));
ui/dbus-chardev.c +6 -0
@@ -27,7 +27,9 @@#include "qemu/config-file.h" #include "qemu/option.h" +#ifdef G_OS_UNIX #include <gio/gunixfdlist.h> +#endif #include "dbus.h"
@@ -108,6 +110,7 @@ dbus_chardev_init(DBusDisplay *dpy) dbus_display_chardev_foreach, dpy); } +#ifdef G_OS_UNIX static gboolean dbus_chr_register( DBusChardev *dc,
@@ -145,6 +148,7 @@ dbus_chr_register(qemu_dbus_display1_chardev_complete_register (object, invocation,NULL );return DBUS_METHOD_INVOCATION_HANDLED ; } +#endif static gboolean dbus_chr_send_break(
@@ -175,8 +179,10 @@ dbus_chr_open(Chardev *chr, ChardevBackend *backend, dc->iface =qemu_dbus_display1_chardev_skeleton_new ();g_object_set (dc->iface,"name" , backend->u.dbus.data->name,NULL );g_object_connect (dc->iface, +#ifdef G_OS_UNIX"swapped-signal::handle-register" , dbus_chr_register, dc, +#endif"swapped-signal::handle-send-break" , dbus_chr_send_break, dc,NULL );
ui/dbus-console.c +8 -0
@@ -28,7 +28,9 @@#include "ui/kbd-state.h" #include "trace.h" +#ifdef G_OS_UNIX #include <gio/gunixfdlist.h> +#endif #include "dbus.h"
@@ -163,6 +165,7 @@ dbus_display_console_class_init(DBusDisplayConsoleClass *klass) gobject_class->dispose = dbus_display_console_dispose; } +#ifdef G_OS_UNIX static void listener_vanished_cb (DBusDisplayListener *listener) {
@@ -174,6 +177,7 @@ listener_vanished_cb(DBusDisplayListener *listener)g_hash_table_remove (ddc->listeners, name);qkbd_state_lift_all_keys (ddc->kbd); } +#endif static gboolean dbus_console_set_ui_info(DBusDisplayConsole *ddc,
@@ -207,6 +211,7 @@ dbus_console_set_ui_info(DBusDisplayConsole *ddc,return DBUS_METHOD_INVOCATION_HANDLED ; } +#ifdef G_OS_UNIX static gboolean dbus_console_register_listener(DBusDisplayConsole *ddc, GDBusMethodInvocation *invocation,
@@ -282,6 +287,7 @@ dbus_console_register_listener(DBusDisplayConsole *ddc,trace_dbus_registered_listener (sender);return DBUS_METHOD_INVOCATION_HANDLED ; } +#endif static gboolean dbus_kbd_press(DBusDisplayConsole *ddc,
@@ -510,8 +516,10 @@ dbus_display_console_new(DBusDisplay *display, QemuConsole *con)"device-address" , device_addr, NULL);g_object_connect (ddc->iface, +#ifdef G_OS_UNIX"swapped-signal::handle-register-listener" , dbus_console_register_listener, ddc, +#endif"swapped-signal::handle-set-uiinfo" , dbus_console_set_ui_info, ddc,NULL );
ui/dbus-listener.c +2 -0
@@ -25,7 +25,9 @@#include "qemu/error-report.h" #include "sysemu/sysemu.h" #include "dbus.h" +#ifdef G_OS_UNIX #include <gio/gunixfdlist.h> +#endif #ifdef CONFIG_OPENGL #include "ui/shader.h"
Signature · 1 line
2.41.0
[PULL 02/33] egl: no need to lookup EGL functions manually
In reply to [email protected]From: Marc-André Lureau <[email protected]>
libepoxy handles loading the function pointer and dispatching the call, so you don't have to worry about it.
Message-Id: <[email protected]>
--- ui/egl-helpers.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
ui/egl-helpers.c +2 -4
@@ -439,10 +439,8 @@ static EGLDisplay qemu_egl_get_display(EGLNativeDisplayType native,/* In practise any EGL 1.5 implementation would support the EXT extension */ if (epoxy_has_egl_extension (NULL ,"EGL_EXT_platform_base" )) { -PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplayEXT = - (void *)eglGetProcAddress ("eglGetPlatformDisplayEXT" ); -if (getPlatformDisplayEXT && platform !=0 ) { - dpy =getPlatformDisplayEXT (platform, native,NULL ); +if (platform !=0 ) { + dpy =eglGetPlatformDisplayEXT (platform, native,NULL ); } }
Signature · 1 line
2.41.0
[PULL 32/33] virtio-gpu-virgl: use D3D11_SHARE_TEXTURE when available
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Enable D3D texture sharing when possible, and pass it to the texture display callbacks.
Message-Id: <[email protected]>
--- meson.build | 6 ++++++ hw/display/virtio-gpu-virgl.c | 24 +++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-)
meson.build +6 -0
@@ -1072,6 +1072,12 @@ if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu virgl = dependency('virglrenderer', method: 'pkg-config', required: get_option('virglrenderer')) + if virgl.found() + config_host_data.set('HAVE_VIRGL_D3D_INFO_EXT', + cc.has_member('struct virgl_renderer_resource_info_ext', 'd3d_tex2d', + prefix: '#include <virglrenderer.h>', + dependencies: virgl)) + endif endif blkio = not_found if not get_option('blkio').auto() or have_block
hw/display/virtio-gpu-virgl.c +19 -5
@@ -153,8 +153,6 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd) {struct virtio_gpu_set_scanout ss; -struct virgl_renderer_resource_info info; -void *d3d_tex2d =NULL ;int ret;VIRTIO_GPU_FILL_CMD (ss);
@@ -169,10 +167,20 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g, } g->parent_obj.enable =1 ; -memset (&info,0 ,sizeof (info)); -if (ss.resource_id && ss.r.width && ss.r.height) { +struct virgl_renderer_resource_info info; +void *d3d_tex2d =NULL ; + +#ifdef HAVE_VIRGL_D3D_INFO_EXT +struct virgl_renderer_resource_info_ext ext; +memset (&ext,0 ,sizeof (ext)); + ret =virgl_renderer_resource_get_info_ext (ss.resource_id, &ext); + info = ext.base; + d3d_tex2d = ext.d3d_tex2d; +#else +memset (&info,0 ,sizeof (info)); ret =virgl_renderer_resource_get_info (ss.resource_id, &info); +#endif if (ret ==-1 ) { qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal resource specified %d\n",
@@ -617,6 +625,7 @@ void virtio_gpu_virgl_reset(VirtIOGPU *g)int virtio_gpu_virgl_init (VirtIOGPU *g) {int ret; +uint32_t flags =0 ;#if VIRGL_RENDERER_CALLBACKS_VERSION >=4 if (qemu_egl_display) {
@@ -624,8 +633,13 @@ int virtio_gpu_virgl_init(VirtIOGPU *g) virtio_gpu_3d_cbs.get_egl_display = virgl_get_egl_display; }#endif +#ifdef VIRGL_RENDERER_D3D11_SHARE_TEXTURE +if (qemu_egl_angle_d3d) { + flags |=VIRGL_RENDERER_D3D11_SHARE_TEXTURE ; + } +#endif - ret =virgl_renderer_init (g,0 , &virtio_gpu_3d_cbs); + ret =virgl_renderer_init (g, flags, &virtio_gpu_3d_cbs);if (ret !=0 ) {error_report ("virgl could not be initialized: %d" , ret);return ret;
Signature · 1 line
2.41.0
[PULL 27/33] ui/dbus: add GL support on win32
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Enable usage of dbus,gl= on win32. At this point, the scanout texture is read on the DisplaySurface memory, and the client is then updated with the "2D" API (with shared memory if possible).
Message-Id: <[email protected]>
--- ui/dbus-listener.c | 98 ++++++++++++++++++++++++++++++++-------------- ui/dbus.c | 4 -- 2 files changed, 68 insertions(+), 34 deletions(-)
ui/dbus-listener.c +68 -30
@@ -36,6 +36,9 @@#endif #include "trace.h" +static void dbus_gfx_switch (DisplayChangeListener *dcl, +struct DisplaySurface *new_surface); +struct _DBusDisplayListener {GObject parent;
@@ -55,12 +58,28 @@ struct _DBusDisplayListener {#ifdef WIN32 QemuDBusDisplay1ListenerWin32Map *map_proxy;HANDLE peer_process; +#ifdef CONFIG_OPENGL +egl_fb fb; +#endif #endif }; G_DEFINE_TYPE(DBusDisplayListener, dbus_display_listener, G_TYPE_OBJECT) -#if defined(CONFIG_OPENGL ) && defined(CONFIG_GBM ) +static void dbus_gfx_update (DisplayChangeListener *dcl, +int x,int y,int w,int h); + +#ifdef CONFIG_OPENGL +static void dbus_scanout_disable (DisplayChangeListener *dcl) +{ +DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); + + ddl->ds =NULL ; +qemu_dbus_display1_listener_call_disable ( + ddl->proxy,G_DBUS_CALL_FLAGS_NONE ,-1 ,NULL ,NULL ,NULL ); +} + +#ifdef CONFIG_GBM static void dbus_update_gl_cb (GObject *source_object,GAsyncResult *res,gpointer user_data)
@@ -76,29 +95,31 @@ static void dbus_update_gl_cb(GObject *source_object,graphic_hw_gl_block (ddl->dcl.con, false);g_object_unref (ddl); } +#endif -static void dbus_call_update_gl (DBusDisplayListener *ddl, +static void dbus_call_update_gl (DisplayChangeListener *dcl,int x,int y,int w,int h) { -graphic_hw_gl_block (ddl->dcl.con, true); +DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); +glFlush (); +#ifdef CONFIG_GBM +graphic_hw_gl_block (ddl->dcl.con, true);qemu_dbus_display1_listener_call_update_dmabuf (ddl->proxy, x, y, w, h,G_DBUS_CALL_FLAGS_NONE ,DBUS_DEFAULT_TIMEOUT ,NULL , dbus_update_gl_cb,g_object_ref (ddl)); -} - -static void dbus_scanout_disable (DisplayChangeListener *dcl) -{ -DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); +#endif - ddl->ds =NULL ; -qemu_dbus_display1_listener_call_disable ( - ddl->proxy,G_DBUS_CALL_FLAGS_NONE ,-1 ,NULL ,NULL ,NULL ); +#ifdef WIN32 +egl_fb_read_rect (ddl->ds, &ddl->fb, x, y, w, h); +dbus_gfx_update (dcl, x, y, w, h); +#endif } +#ifdef CONFIG_GBM static void dbus_scanout_dmabuf (DisplayChangeListener *dcl,QemuDmaBuf *dmabuf) {
@@ -127,7 +148,8 @@ static void dbus_scanout_dmabuf(DisplayChangeListener *dcl, fd_list, NULL, NULL, NULL); } -#endif /* OPENGL & GBM */ +#endif /* GBM */ +#endif /* OPENGL */ #ifdef WIN32 static bool dbus_scanout_map (DBusDisplayListener *ddl)
@@ -181,7 +203,7 @@ static bool dbus_scanout_map(DBusDisplayListener *ddl) }#endif -#if defined(CONFIG_OPENGL ) && defined(CONFIG_GBM ) +#ifdef CONFIG_OPENGL static void dbus_scanout_texture(DisplayChangeListener *dcl, uint32_t tex_id, bool backing_y_0_top,
@@ -190,6 +212,7 @@ static void dbus_scanout_texture(DisplayChangeListener *dcl, uint32_t x, uint32_t y, uint32_t w, uint32_t h) { +#ifdef CONFIG_GBM QemuDmaBuf dmabuf = { .width = backing_width, .height = backing_height,
@@ -212,8 +235,19 @@ static void dbus_scanout_texture(DisplayChangeListener *dcl,dbus_scanout_dmabuf (dcl, &dmabuf);close (dmabuf.fd); +#endif + +#ifdef WIN32 +DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); + +/* there must be a matching gfx_switch before */ +assert (surface_width (ddl->ds) == w); +assert (surface_height (ddl->ds) == h); +egl_fb_setup_for_tex (&ddl->fb, backing_width, backing_height, tex_id, false); +#endif } +#ifdef CONFIG_GBM static void dbus_cursor_dmabuf (DisplayChangeListener *dcl,QemuDmaBuf *dmabuf,bool have_hot,uint32_t hot_x,uint32_t hot_y)
@@ -260,7 +294,14 @@ static void dbus_cursor_dmabuf(DisplayChangeListener *dcl, NULL); } -static void dbus_cursor_position (DisplayChangeListener *dcl, +static void dbus_release_dmabuf (DisplayChangeListener *dcl, +QemuDmaBuf *dmabuf) +{ +dbus_scanout_disable (dcl); +} +#endif /* GBM */ + +static void dbus_gl_cursor_position (DisplayChangeListener *dcl,uint32_t pos_x,uint32_t pos_y) {DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl);
@@ -270,19 +311,11 @@ static void dbus_cursor_position(DisplayChangeListener *dcl, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL); } -static void dbus_release_dmabuf (DisplayChangeListener *dcl, -QemuDmaBuf *dmabuf) -{ -dbus_scanout_disable (dcl); -} -static void dbus_scanout_update (DisplayChangeListener *dcl,uint32_t x,uint32_t y,uint32_t w,uint32_t h) { -DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); - -dbus_call_update_gl (ddl, x, y, w, h); +dbus_call_update_gl (dcl, x, y, w, h); }static void dbus_gl_refresh (DisplayChangeListener *dcl)
@@ -296,19 +329,19 @@ static void dbus_gl_refresh(DisplayChangeListener *dcl) }if (ddl->gl_updates) { -dbus_call_update_gl (ddl,0 ,0 , +dbus_call_update_gl (dcl,0 ,0 ,surface_width (ddl->ds),surface_height (ddl->ds)); ddl->gl_updates =0 ; } } -#endif /* OPENGL & GBM */ +#endif /* OPENGL */ static void dbus_refresh (DisplayChangeListener *dcl) {graphic_hw_update (dcl->con); } -#if defined(CONFIG_OPENGL ) && defined(CONFIG_GBM ) +#ifdef CONFIG_OPENGL static void dbus_gl_gfx_update (DisplayChangeListener *dcl,int x,int y,int w,int h) {
@@ -382,7 +415,7 @@ static void dbus_gfx_update(DisplayChangeListener *dcl, DBUS_DEFAULT_TIMEOUT, NULL, NULL, NULL); } -#if defined(CONFIG_OPENGL ) && defined(CONFIG_GBM ) +#ifdef CONFIG_OPENGL static void dbus_gl_gfx_switch (DisplayChangeListener *dcl,struct DisplaySurface *new_surface) {
@@ -452,7 +485,7 @@ static void dbus_cursor_define(DisplayChangeListener *dcl, NULL); } -#if defined(CONFIG_OPENGL ) && defined(CONFIG_GBM ) +#ifdef CONFIG_OPENGL const DisplayChangeListenerOps dbus_gl_dcl_ops = { .dpy_name ="dbus-gl" , .dpy_gfx_update = dbus_gl_gfx_update,
@@ -464,10 +497,12 @@ const DisplayChangeListenerOps dbus_gl_dcl_ops = { .dpy_gl_scanout_disable = dbus_scanout_disable, .dpy_gl_scanout_texture = dbus_scanout_texture, +#ifdef CONFIG_GBM .dpy_gl_scanout_dmabuf = dbus_scanout_dmabuf, .dpy_gl_cursor_dmabuf = dbus_cursor_dmabuf, - .dpy_gl_cursor_position = dbus_cursor_position, .dpy_gl_release_dmabuf = dbus_release_dmabuf, +#endif + .dpy_gl_cursor_position = dbus_gl_cursor_position, .dpy_gl_update = dbus_scanout_update, };#endif
@@ -493,6 +528,9 @@ dbus_display_listener_dispose(GObject *object)#ifdef WIN32 g_clear_object (&ddl->map_proxy);g_clear_pointer (&ddl->peer_process, CloseHandle); +#ifdef CONFIG_OPENGL +egl_fb_destroy (&ddl->fb); +#endif #endif G_OBJECT_CLASS (dbus_display_listener_parent_class)->dispose (object);
@@ -504,7 +542,7 @@ dbus_display_listener_constructed(GObject *object)DBusDisplayListener *ddl =DBUS_DISPLAY_LISTENER (object); ddl->dcl.ops = &dbus_dcl_ops; -#if defined(CONFIG_OPENGL ) && defined(CONFIG_GBM ) +#ifdef CONFIG_OPENGL if (display_opengl) { ddl->dcl.ops = &dbus_gl_dcl_ops; }
ui/dbus.c +0 -4
@@ -47,10 +47,8 @@ static DBusDisplay *dbus_display;static QEMUGLContext dbus_create_context (DisplayGLCtx *dgc,QEMUGLParams *params) { -#ifdef CONFIG_GBM eglMakeCurrent (qemu_egl_display,EGL_NO_SURFACE ,EGL_NO_SURFACE , qemu_egl_rn_ctx); -#endif return qemu_egl_create_context (dgc, params); }
@@ -59,9 +57,7 @@ dbus_is_compatible_dcl(DisplayGLCtx *dgc, DisplayChangeListener *dcl) {return -#ifdef CONFIG_GBM dcl->ops == &dbus_gl_dcl_ops || -#endif dcl->ops == &dbus_console_dcl_ops; }
Signature · 1 line
2.41.0
[PULL 10/33] ui/gtk: set the area of the scanout texture correctly
In reply to [email protected]From: Dongwon Kim <[email protected]>
x and y offsets and width and height of the scanout texture is not correctly configured in case guest scanout frame is dmabuf.
Message-ID: <[email protected]>
--- ui/gtk-egl.c | 3 ++- ui/gtk-gl-area.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
ui/gtk-egl.c +2 -1
@@ -257,7 +257,8 @@ void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,gd_egl_scanout_texture (dcl, dmabuf->texture, dmabuf->y0_top, dmabuf->width, dmabuf->height, -0 ,0 , dmabuf->width, dmabuf->height); + dmabuf->x, dmabuf->y, dmabuf->scanout_width, + dmabuf->scanout_height);if (dmabuf->allow_fences) { vc->gfx.guest_fb.dmabuf = dmabuf;
ui/gtk-gl-area.c +2 -1
@@ -299,7 +299,8 @@ void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,gd_gl_area_scanout_texture (dcl, dmabuf->texture, dmabuf->y0_top, dmabuf->width, dmabuf->height, -0 ,0 , dmabuf->width, dmabuf->height); + dmabuf->x, dmabuf->y, dmabuf->scanout_width, + dmabuf->scanout_height);if (dmabuf->allow_fences) { vc->gfx.guest_fb.dmabuf = dmabuf;
Signature · 1 line
2.41.0
Re: [PULL 10/33] ui/gtk: set the area of the scanout texture correctly
Quoted 5 lines · 27.06.2023 16:02, [email protected] wrote:
From: Dongwon Kim <[email protected]>
x and y offsets and width and height of the scanout texture is not correctly configured in case guest scanout frame is dmabuf.
Is this a -stable material too?
Thanks,
/mjt
[PULL 12/33] ui/gtk: making dmabuf NULL when it's released.
In reply to [email protected]From: Dongwon Kim <[email protected]>
Set vc->gfx.guest_fb.dmabuf to NULL to prevent any further access to it after the dmabuf is released.
v2: move declaration of vc inside ifdef
Message-ID: <[email protected]>
--- ui/gtk.c | 5 +++++ 1 file changed, 5 insertions(+)
ui/gtk.c +5 -0
@@ -583,7 +583,12 @@ static void gd_gl_release_dmabuf(DisplayChangeListener *dcl, QemuDmaBuf *dmabuf) {#ifdef CONFIG_GBM +VirtualConsole *vc =container_of (dcl, VirtualConsole, gfx.dcl); +egl_dmabuf_release_texture (dmabuf); +if (vc->gfx.guest_fb.dmabuf == dmabuf) { + vc->gfx.guest_fb.dmabuf =NULL ; + }#endif }
Signature · 1 line
2.41.0
[PULL 04/33] virtio-gpu: Optimize 2D resource data transfer
In reply to [email protected]From: Keqian Zhu via <[email protected]>
The following points sometimes can reduce much data to copy:
1. When width matches, we can transfer data with one call of iov_to_buf().
2. Only the required height need to transfer, not whole image.
Message-Id: <[email protected]>
--- hw/display/virtio-gpu.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
hw/display/virtio-gpu.c +11 -11
@@ -438,11 +438,11 @@ static void virtio_gpu_transfer_to_host_2d(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd) {struct virtio_gpu_simple_resource *res; -int h; +int h, bpp;uint32_t src_offset, dst_offset, stride; -int bpp;pixman_format_code_t format;struct virtio_gpu_transfer_to_host_2d t2d; +void *img_data;VIRTIO_GPU_FILL_CMD (t2d);virtio_gpu_t2d_bswap (&t2d);
@@ -471,23 +471,23 @@ static void virtio_gpu_transfer_to_host_2d(VirtIOGPU *g, format =pixman_image_get_format (res->image); bpp =DIV_ROUND_UP (PIXMAN_FORMAT_BPP (format),8 ); stride =pixman_image_get_stride (res->image); + img_data =pixman_image_get_data (res->image); -if (t2d.offset || t2d.r.x || t2d.r.y || - t2d.r.width !=pixman_image_get_width (res->image)) { -void *img_data =pixman_image_get_data (res->image); +if (t2d.r.x || t2d.r.width !=pixman_image_get_width (res->image)) {for (h =0 ; h < t2d.r.height; h++) { src_offset = t2d.offset + stride * h; dst_offset = (t2d.r.y + h) * stride + (t2d.r.x * bpp);iov_to_buf (res->iov, res->iov_cnt, src_offset, - (uint8_t *)img_data - + dst_offset, t2d.r.width * bpp); + (uint8_t *)img_data + dst_offset, + t2d.r.width * bpp); } }else { -iov_to_buf (res->iov, res->iov_cnt,0 , -pixman_image_get_data (res->image), -pixman_image_get_stride (res->image) - *pixman_image_get_height (res->image)); + src_offset = t2d.offset; + dst_offset = t2d.r.y * stride + t2d.r.x * bpp; +iov_to_buf (res->iov, res->iov_cnt, src_offset, + (uint8_t *)img_data + dst_offset, + stride * t2d.r.height); } }
Signature · 1 line
2.41.0
Re: [PULL 04/33] virtio-gpu: Optimize 2D resource data transfer
Quoted 1 line · On 6/27/23 15:02, [email protected] wrote:
From: Keqian Zhu via <[email protected]>
You need to fix the author for this patch.
r~
Re: [PULL 04/33] virtio-gpu: Optimize 2D resource data transfer
Hi
Quoted 7 lines · Richard Henderson
Quoted 1 line · On 6/27/23 15:02, [email protected] wrote:
From: Keqian Zhu via <[email protected]>
You need to fix the author for this patch.
ok done, do you want me to re-send the whole PR or is that enough?
The following changes since commit 4329d049d5b8d4af71c6b399d64a6d1b98856318:
Merge tag 'pull-tcg-20230626' of https://gitlab.com/rth7680/qemu into
staging (2023-06-26 17:40:38 +0200)
are available in the Git repository at:
https://gitlab.com/marcandre.lureau/qemu.git tags/ui-pull-request
for you to fetch changes up to de1f8ce0abb8c43d1e6a00c31c6d24dfe0505b92:
ui/dbus: use shared D3D11 Texture2D when possible (2023-06-27 17:08:56
+0200)
Quoted 3 lines
r~
Signature · 1 line
Marc-André Lureau
Richard Henderson
AppliedRe: [PULL 04/33] virtio-gpu: Optimize 2D resource data transfer
Quoted 15 lines · Marc-André Lureau
Hi
On Tue, Jun 27, 2023 at 5:04 PM Richard Henderson <[email protected] <mailto:[email protected]>> wrote:
On 6/27/23 15:02, [email protected] <mailto:[email protected]> wrote:
> From: Keqian Zhu via <[email protected] <mailto:[email protected]>>You need to fix the author for this patch.
ok done, do you want me to re-send the whole PR or is that enough?
The following changes since commit
4329d049d5b8d4af71c6b399d64a6d1b98856318:
Quoted 8 lines
Merge tag 'pull-tcg-20230626' of https://gitlab.com/rth7680/qemu
<https://gitlab.com/rth7680/qemu> into staging (2023-06-26 17:40:38 +0200)are available in the Git repository at:
https://gitlab.com/marcandre.lureau/qemu.git <https://gitlab.com/marcandre.lureau/qemu.git> tags/ui-pull-request
for you to fetch changes up to
de1f8ce0abb8c43d1e6a00c31c6d24dfe0505b92:
That was enough, thanks.
Applied. Please update https://wiki.qemu.org/ChangeLog/8.1 as appropriate.
r~
[PULL 14/33] ui/egl: fix make_context_current() callback return value
In reply to [email protected]From: Marc-André Lureau <[email protected]>
eglMakeCurrent() returns 1/EGL_TRUE on success. This is not what the callback expects, where 0 indicates success.
While at it, print the EGL error to ease debugging.
As with virgl_renderer_callbacks, the return value is now checked since version >= 4:
https://gitlab.freedesktop.org/virgl/virglrenderer/-/commit/7f09e6bf0c6ceea6727bd0049781256a28cab0e5
Message-Id: <[email protected]>
--- ui/egl-context.c | 10 ++++++++-- ui/gtk-egl.c | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-)
ui/egl-context.c +8 -2
@@ -1,4 +1,5 @@#include "qemu/osdep.h" +#include "qemu/error-report.h" #include "ui/egl-context.h" QEMUGLContext qemu_egl_create_context(DisplayGLCtx *dgc,
@@ -32,6 +33,11 @@ void qemu_egl_destroy_context(DisplayGLCtx *dgc, QEMUGLContext ctx)int qemu_egl_make_context_current (DisplayGLCtx *dgc,QEMUGLContext ctx) { -return eglMakeCurrent (qemu_egl_display, -EGL_NO_SURFACE ,EGL_NO_SURFACE , ctx); +if (!eglMakeCurrent (qemu_egl_display, +EGL_NO_SURFACE ,EGL_NO_SURFACE , ctx)) { +error_report ("egl: eglMakeCurrent failed: %s" ,qemu_egl_get_error_string ()); +return -1 ; + } + +return 0 ; }
ui/gtk-egl.c +8 -2
@@ -13,6 +13,7 @@#include "qemu/osdep.h" #include "qemu/main-loop.h" +#include "qemu/error-report.h" #include "trace.h"
@@ -369,6 +370,11 @@ int gd_egl_make_current(DisplayGLCtx *dgc, {VirtualConsole *vc =container_of (dgc, VirtualConsole, gfx.dgc); -return eglMakeCurrent (qemu_egl_display, vc->gfx.esurface, - vc->gfx.esurface, ctx); +if (!eglMakeCurrent (qemu_egl_display, vc->gfx.esurface, + vc->gfx.esurface, ctx)) { +error_report ("egl: eglMakeCurrent failed: %s" ,qemu_egl_get_error_string ()); +return -1 ; + } + +return 0 ; }
Signature · 1 line
2.41.0
[PULL 13/33] ui/egl: export qemu_egl_get_error_string()
In reply to [email protected]From: Marc-André Lureau <[email protected]>
It will be used from other units.
Message-Id: <[email protected]>
--- include/ui/egl-helpers.h | 2 ++ ui/egl-helpers.c | 12 +++++------- 2 files changed, 7 insertions(+), 7 deletions(-)
include/ui/egl-helpers.h +2 -0
@@ -67,4 +67,6 @@ bool qemu_egl_has_dmabuf(void);bool egl_init (const char *rendernode,DisplayGLMode mode,Error **errp); +const char *qemu_egl_get_error_string (void ); +#endif /* EGL_HELPERS_H */
ui/egl-helpers.c +5 -7
@@ -28,8 +28,7 @@ DisplayGLMode qemu_egl_mode;/* ------------------------------------------------------------------ */ -#if defined(CONFIG_X11 ) || defined(CONFIG_GBM ) -static const char *egl_get_error_string (void ) +const char *qemu_egl_get_error_string (void ) {EGLint error =eglGetError ();
@@ -68,7 +67,6 @@ static const char *egl_get_error_string(void)return "Unknown EGL error" ; } } -#endif static void egl_fb_delete_texture (egl_fb *fb) {
@@ -480,20 +478,20 @@ static int qemu_egl_init_dpy(EGLNativeDisplayType dpy, qemu_egl_display =qemu_egl_get_display (dpy, platform);if (qemu_egl_display ==EGL_NO_DISPLAY ) { -error_report ("egl: eglGetDisplay failed: %s" ,egl_get_error_string ()); +error_report ("egl: eglGetDisplay failed: %s" ,qemu_egl_get_error_string ());return -1 ; } b =eglInitialize (qemu_egl_display, &major, &minor);if (b ==EGL_FALSE ) { -error_report ("egl: eglInitialize failed: %s" ,egl_get_error_string ()); +error_report ("egl: eglInitialize failed: %s" ,qemu_egl_get_error_string ());return -1 ; } b =eglBindAPI (gles ?EGL_OPENGL_ES_API :EGL_OPENGL_API );if (b ==EGL_FALSE ) {error_report ("egl: eglBindAPI failed (%s mode): %s" , - gles ?"gles" :"core" ,egl_get_error_string ()); + gles ?"gles" :"core" ,qemu_egl_get_error_string ());return -1 ; }
@@ -502,7 +500,7 @@ static int qemu_egl_init_dpy(EGLNativeDisplayType dpy, &qemu_egl_config, 1, &n);if (b ==EGL_FALSE || n !=1 ) {error_report ("egl: eglChooseConfig failed (%s mode): %s" , - gles ?"gles" :"core" ,egl_get_error_string ()); + gles ?"gles" :"core" ,qemu_egl_get_error_string ());return -1 ; }
Signature · 1 line
2.41.0
[PULL 31/33] ui: add optional d3d texture pointer to scanout texture
In reply to [email protected]From: Marc-André Lureau <[email protected]>
The following patch will get the underlying D3D11 Texture2D from the virgl renderer scanout. Pass it along to the texture scanout callbacks as a priliminary step, to simplify review.
Message-Id: <[email protected]>
--- include/ui/console.h | 7 +++++-- include/ui/gtk.h | 6 ++++-- include/ui/sdl2.h | 3 ++- hw/display/virtio-gpu-virgl.c | 4 +++- ui/console.c | 11 +++++++---- ui/dbus-console.c | 3 ++- ui/dbus-listener.c | 5 +++-- ui/egl-headless.c | 5 +++-- ui/gtk-egl.c | 5 +++-- ui/gtk-gl-area.c | 5 +++-- ui/sdl2-gl.c | 3 ++- ui/spice-display.c | 3 ++- 12 files changed, 39 insertions(+), 21 deletions(-)
include/ui/console.h +5 -2
@@ -132,6 +132,7 @@ typedef struct ScanoutTexture {uint32_t y;uint32_t width;uint32_t height; +void *d3d_tex2d; } ScanoutTexture; typedef struct DisplaySurface {
@@ -270,7 +271,8 @@ typedef struct DisplayChangeListenerOps {uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h); + uint32_t w, uint32_t h, + void *d3d_tex2d);/* optional (default to true if has dpy_gl_scanout_dmabuf) */ bool (*dpy_has_dmabuf)(DisplayChangeListener *dcl);/* optional */
@@ -378,7 +380,8 @@ void dpy_gl_scanout_disable(QemuConsole *con);void dpy_gl_scanout_texture (QemuConsole *con,uint32_t backing_id,bool backing_y_0_top,uint32_t backing_width,uint32_t backing_height, -uint32_t x,uint32_t y,uint32_t w,uint32_t h); +uint32_t x,uint32_t y,uint32_t w,uint32_t h, +void *d3d_tex2d);void dpy_gl_scanout_dmabuf (QemuConsole *con,QemuDmaBuf *dmabuf); void dpy_gl_cursor_dmabuf(QemuConsole *con, QemuDmaBuf *dmabuf,
include/ui/gtk.h +4 -2
@@ -175,7 +175,8 @@ void gd_egl_scanout_texture(DisplayChangeListener *dcl,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h); + uint32_t w, uint32_t h, + void *d3d_tex2d);void gd_egl_scanout_dmabuf (DisplayChangeListener *dcl,QemuDmaBuf *dmabuf); void gd_egl_cursor_dmabuf(DisplayChangeListener *dcl,
@@ -211,7 +212,8 @@ void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h); + uint32_t w, uint32_t h, + void *d3d_tex2d);void gd_gl_area_scanout_disable (DisplayChangeListener *dcl);void gd_gl_area_scanout_flush (DisplayChangeListener *dcl,uint32_t x,uint32_t y,uint32_t w,uint32_t h);
include/ui/sdl2.h +2 -1
@@ -90,7 +90,8 @@ void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h); + uint32_t w, uint32_t h, + void *d3d_tex2d);void sdl2_gl_scanout_flush (DisplayChangeListener *dcl,uint32_t x,uint32_t y,uint32_t w,uint32_t h);
hw/display/virtio-gpu-virgl.c +3 -1
@@ -154,6 +154,7 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g, {struct virtio_gpu_set_scanout ss;struct virgl_renderer_resource_info info; +void *d3d_tex2d =NULL ;int ret;VIRTIO_GPU_FILL_CMD (ss);
@@ -186,7 +187,8 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g, g->parent_obj.scanout[ss.scanout_id].con, info.tex_id, info.flags &VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP , info.width, info.height, - ss.r.x, ss.r.y, ss.r.width, ss.r.height); + ss.r.x, ss.r.y, ss.r.width, ss.r.height, + d3d_tex2d); }else {dpy_gfx_replace_surface ( g->parent_obj.scanout[ss.scanout_id].con,NULL );
ui/console.c +7 -4
@@ -1223,7 +1223,8 @@ static void displaychangelistener_display_console(DisplayChangeListener *dcl, con->scanout.texture.x, con->scanout.texture.y, con->scanout.texture.width, - con->scanout.texture.height); + con->scanout.texture.height, + con->scanout.texture.d3d_tex2d); } }
@@ -2115,7 +2116,8 @@ void dpy_gl_scanout_texture(QemuConsole *con,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t width, uint32_t height) + uint32_t width, uint32_t height, + void *d3d_tex2d) { DisplayState *s = con->ds;DisplayChangeListener *dcl;
@@ -2123,7 +2125,7 @@ void dpy_gl_scanout_texture(QemuConsole *con, con->scanout.kind =SCANOUT_TEXTURE ; con->scanout.texture = (ScanoutTexture ) { backing_id, backing_y_0_top, backing_width, backing_height, - x, y, width, height + x, y, width, height, d3d_tex2d, }; QLIST_FOREACH(dcl, &s->listeners, next) {if (con != (dcl->con ? dcl->con : active_console)) {
@@ -2133,7 +2135,8 @@ void dpy_gl_scanout_texture(QemuConsole *con, dcl->ops->dpy_gl_scanout_texture (dcl, backing_id, backing_y_0_top, backing_width, backing_height, - x, y, width, height); + x, y, width, height, + d3d_tex2d); } } }
ui/dbus-console.c +2 -1
@@ -98,7 +98,8 @@ dbus_gl_scanout_texture(DisplayChangeListener *dcl,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h) + uint32_t w, uint32_t h, + void *d3d_tex2d) { DBusDisplayConsole *ddc = container_of(dcl, DBusDisplayConsole, dcl);
ui/dbus-listener.c +3 -2
@@ -212,7 +212,8 @@ static void dbus_scanout_texture(DisplayChangeListener *dcl,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h) + uint32_t w, uint32_t h, + void *d3d_tex2d) {trace_dbus_scanout_texture (tex_id ,backing_y_0_top ,backing_width ,backing_height ,x ,y ,w ,h );
@@ -434,7 +435,7 @@ static void dbus_gl_gfx_switch(DisplayChangeListener *dcl,/* TODO: lazy send dmabuf (there are unnecessary sent otherwise) */ dbus_scanout_texture (&ddl->dcl, ddl->ds->texture, false, - width, height, 0, 0, width, height); + width, height, 0, 0, width, height, NULL); } }#endif
ui/egl-headless.c +3 -2
@@ -61,7 +61,8 @@ static void egl_scanout_texture(DisplayChangeListener *dcl,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h) + uint32_t w, uint32_t h, + void *d3d_tex2d) { egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);
@@ -91,7 +92,7 @@ static void egl_scanout_dmabuf(DisplayChangeListener *dcl,egl_scanout_texture (dcl, dmabuf->texture, false, dmabuf->width, dmabuf->height, -0 ,0 , dmabuf->width, dmabuf->height); +0 ,0 , dmabuf->width, dmabuf->height,NULL ); } static void egl_cursor_dmabuf(DisplayChangeListener *dcl,
ui/gtk-egl.c +3 -2
@@ -224,7 +224,8 @@ void gd_egl_scanout_texture(DisplayChangeListener *dcl, uint32_t backing_id, bool backing_y_0_top, uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h) + uint32_t w, uint32_t h, + void *d3d_tex2d) { VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
@@ -259,7 +260,7 @@ void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,gd_egl_scanout_texture (dcl, dmabuf->texture, dmabuf->y0_top, dmabuf->width, dmabuf->height, dmabuf->x, dmabuf->y, dmabuf->scanout_width, - dmabuf->scanout_height); + dmabuf->scanout_height,NULL );if (dmabuf->allow_fences) { vc->gfx.guest_fb.dmabuf = dmabuf;
ui/gtk-gl-area.c +3 -2
@@ -244,7 +244,8 @@ void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h) + uint32_t w, uint32_t h, + void *d3d_tex2d) { VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
@@ -300,7 +301,7 @@ void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,gd_gl_area_scanout_texture (dcl, dmabuf->texture, dmabuf->y0_top, dmabuf->width, dmabuf->height, dmabuf->x, dmabuf->y, dmabuf->scanout_width, - dmabuf->scanout_height); + dmabuf->scanout_height,NULL );if (dmabuf->allow_fences) { vc->gfx.guest_fb.dmabuf = dmabuf;
ui/sdl2-gl.c +2 -1
@@ -205,7 +205,8 @@ void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h) + uint32_t w, uint32_t h, + void *d3d_tex2d) { struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
ui/spice-display.c +2 -1
@@ -935,7 +935,8 @@ static void qemu_spice_gl_scanout_texture(DisplayChangeListener *dcl,uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, - uint32_t w, uint32_t h) + uint32_t w, uint32_t h, + void *d3d_tex2d) { SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);EGLint stride =0 , fourcc =0 ;
Signature · 1 line
2.41.0
[PULL 03/33] ui/sdl2: OpenGL window context
In reply to [email protected]From: Antonio Caggiano <[email protected]>
When OpenGL is enabled, create only the OpenGL context, ignoring the SDL renderer as it is unused anyway.
Message-Id: <[email protected]>
--- ui/sdl2.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
ui/sdl2.c +11 -7
@@ -113,11 +113,11 @@ void sdl2_window_create(struct sdl2_console *scon)SDL_SetHint (SDL_HINT_RENDER_DRIVER , driver);SDL_SetHint (SDL_HINT_RENDER_BATCHING ,"1" ); - } - scon->real_renderer =SDL_CreateRenderer (scon->real_window,-1 ,0 ); -if (scon->opengl) { scon->winctx =SDL_GL_CreateContext (scon->real_window); + }else { +/* The SDL renderer is only used by sdl2-2D, when OpenGL is disabled */ + scon->real_renderer =SDL_CreateRenderer (scon->real_window,-1 ,0 ); }sdl_update_caption (scon); }
@@ -128,10 +128,14 @@ void sdl2_window_destroy(struct sdl2_console *scon)return ; } -SDL_GL_DeleteContext (scon->winctx); - scon->winctx =NULL ; -SDL_DestroyRenderer (scon->real_renderer); - scon->real_renderer =NULL ; +if (scon->winctx) { +SDL_GL_DeleteContext (scon->winctx); + scon->winctx =NULL ; + } +if (scon->real_renderer) { +SDL_DestroyRenderer (scon->real_renderer); + scon->real_renderer =NULL ; + }SDL_DestroyWindow (scon->real_window); scon->real_window =NULL ; }
Signature · 1 line
2.41.0
[PULL 05/33] chardev/char-win-stdio: Support VT sequences on Windows 11 host
In reply to [email protected]From: Zhang Huasen <[email protected]>
If the monitor or the serial port use STDIO as backend on Windows 11 host, e.g. -nographic options is used, the monitor or the guest Linux do not response to arrow keys.
When Windows creates a console, ENABLE_VIRTUAL_PROCESS_INPUT is disabled by default. Arrow keys cannot be retrieved by ReadFile or ReadConsoleInput functions.
Add ENABLE_VIRTUAL_PROCESS_INPUT to the flag which is passed to SetConsoleMode, when opening stdio console.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1674
Message-Id: <[email protected]>
--- chardev/char-win-stdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
chardev/char-win-stdio.c +1 -1
@@ -190,7 +190,7 @@ static void qemu_chr_open_stdio(Chardev *chr, } } - dwMode |=ENABLE_LINE_INPUT ; + dwMode |=ENABLE_LINE_INPUT |ENABLE_VIRTUAL_TERMINAL_INPUT ;if (is_console) {/* set the terminal in raw mode */
Signature · 1 line
2.41.0
[PULL 30/33] ui/egl: query ANGLE d3d device
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Check if ANGLE is being used with D3D backend.
Message-Id: <[email protected]>
--- include/ui/egl-helpers.h | 1 + ui/egl-helpers.c | 32 +++++++++++++++++++++++++++++++- ui/trace-events | 3 +++ 3 files changed, 35 insertions(+), 1 deletion(-)
include/ui/egl-helpers.h +1 -0
@@ -12,6 +12,7 @@extern EGLDisplay *qemu_egl_display;extern EGLConfig qemu_egl_config;extern DisplayGLMode qemu_egl_mode; +extern bool qemu_egl_angle_d3d; typedef struct egl_fb { int width;
ui/egl-helpers.c +31 -1
@@ -15,16 +15,19 @@* License along with this library; if not, see <http://www.gnu.org/licenses/>. */ #include "qemu/osdep.h" +#include "qemu/drm.h" #include "qemu/error-report.h" #include "ui/console.h" #include "ui/egl-helpers.h" #include "sysemu/sysemu.h" #include "qapi/error.h" +#include "trace.h" EGLDisplay *qemu_egl_display;EGLConfig qemu_egl_config;DisplayGLMode qemu_egl_mode; +bool qemu_egl_angle_d3d;/* ------------------------------------------------------------------ */
@@ -553,7 +556,34 @@ int qemu_egl_init_dpy_win32(EGLNativeDisplayType dpy, DisplayGLMode mode)if (mode ==DISPLAYGL_MODE_ON ) { mode =DISPLAYGL_MODE_ES ; } - return qemu_egl_init_dpy(dpy, 0, mode); + +if (qemu_egl_init_dpy (dpy,0 , mode) <0 ) { +return -1 ; + } + +#ifdef EGL_D3D11_DEVICE_ANGLE +if (epoxy_has_egl_extension (qemu_egl_display,"EGL_EXT_device_query" )) { +EGLDeviceEXT device; +void *d3d11_device; + +if (!eglQueryDisplayAttribEXT (qemu_egl_display, +EGL_DEVICE_EXT , + (EGLAttrib *)&device)) { +return 0 ; + } + +if (!eglQueryDeviceAttribEXT (device, +EGL_D3D11_DEVICE_ANGLE , + (EGLAttrib *)&d3d11_device)) { +return 0 ; + } + +trace_egl_init_d3d11_device (device); + qemu_egl_angle_d3d = device !=NULL ; + } +#endif + + return 0; }#endif
ui/trace-events +3 -0
@@ -162,3 +162,6 @@ dbus_clipboard_register(const char *bus_name) "peer %s" dbus_clipboard_unregister(const char *bus_name) "peer %s" dbus_scanout_texture(uint32_t tex_id, bool backing_y_0_top, uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, uint32_t w, uint32_t h) "tex_id:%u y0top:%d back:%ux%u %u+%u-%ux%u" dbus_gl_gfx_switch(void *p) "surf: %p" + +# egl-helpers.c +egl_init_d3d11_device(void *p) "d3d device: %p"
Signature · 1 line
2.41.0
[PULL 29/33] virtio-gpu-virgl: teach it to get the QEMU EGL display
In reply to [email protected]From: Marc-André Lureau <[email protected]>
virgl offers a few features that require to have access to the underlying EGLDisplay. This is the case for the D3D texture sharing support.
The API callback is merged for virgl 1.0:
https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1113
Message-Id: <[email protected]>
--- hw/display/virtio-gpu-virgl.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
hw/display/virtio-gpu-virgl.c +16 -1
@@ -18,9 +18,17 @@#include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "ui/egl-helpers.h" +#include <virglrenderer.h> -static struct virgl_renderer_callbacks virtio_gpu_3d_cbs; +#if VIRGL_RENDERER_CALLBACKS_VERSION >=4 +static void * +virgl_get_egl_display(G_GNUC_UNUSED void *cookie) +{ +return qemu_egl_display; +} +#endif static void virgl_cmd_create_resource_2d (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd)
@@ -608,6 +616,13 @@ int virtio_gpu_virgl_init(VirtIOGPU *g) {int ret; +#if VIRGL_RENDERER_CALLBACKS_VERSION >=4 +if (qemu_egl_display) { + virtio_gpu_3d_cbs.version =4 ; + virtio_gpu_3d_cbs.get_egl_display = virgl_get_egl_display; + } +#endif + ret =virgl_renderer_init (g,0 , &virtio_gpu_3d_cbs);if (ret !=0 ) {error_report ("virgl could not be initialized: %d" , ret);
Signature · 1 line
2.41.0
[PULL 01/33] ui: return NULL when getting cursor without a console
In reply to [email protected]From: Marc-André Lureau <[email protected]>
VNC may try to get the current cursor even when there are no consoles and crashes. Simple reproducer is qemu with -nodefaults.
Fixes: (again)
https://gitlab.com/qemu-project/qemu/-/issues/1548
Message-Id: <[email protected]>
--- ui/console.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ui/console.c +1 -1
@@ -2306,7 +2306,7 @@ QEMUCursor *qemu_console_get_cursor(QemuConsole *con)if (con ==NULL ) { con = active_console; } -return con->cursor; +return con ? con->cursor :NULL ; }bool qemu_console_is_visible (QemuConsole *con)
Signature · 1 line
2.41.0
[PULL 25/33] ui/egl: default to GLES on windows
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Windows GL drivers are notoriously not very good. Otoh, ANGLE provides rock solid GLES implementation on top of direct3d. We should recommend it and default to ES when using EGL (users can easily override this if necessary)
Message-Id: <[email protected]>
--- ui/egl-helpers.c | 4 ++++ 1 file changed, 4 insertions(+)
ui/egl-helpers.c +4 -0
@@ -535,6 +535,10 @@ int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, DisplayGLMode mode)#ifdef WIN32 int qemu_egl_init_dpy_win32 (EGLNativeDisplayType dpy,DisplayGLMode mode) { +/* prefer GL ES, as that's what ANGLE supports */ +if (mode ==DISPLAYGL_MODE_ON ) { + mode =DISPLAYGL_MODE_ES ; + }return qemu_egl_init_dpy (dpy,0 , mode); }#endif
Signature · 1 line
2.41.0
[PULL 16/33] scripts: add a XML preprocessor script
In reply to [email protected]From: Marc-André Lureau <[email protected]>
gdbus-codegen doesn't support conditions or pre-processing.
Rather than duplicating D-Bus interfaces for win32 adaptation, let's have a preprocess step, so we can have platform-specific interfaces.
The python script is based on
https://github.com/peitaosu/XML-Preprocessor, with bug fixes, some testing and replacing lxml dependency with the built-in xml module.
This preprocessing syntax style is not very common, but is similar to the one provided by WiX (https://wixtoolset.org/docs/v3/overview/preprocessor/)
or wixl, that we adopted in QEMU for packaging the guest agent.
Message-Id: <[email protected]>
--- MAINTAINERS | 1 + scripts/meson.build | 2 + scripts/xml-preprocess-test.py | 136 +++++++++++++++ scripts/xml-preprocess.py | 293 +++++++++++++++++++++++++++++++++ 4 files changed, 432 insertions(+) create mode 100644 scripts/xml-preprocess-test.py create mode 100755 scripts/xml-preprocess.py
MAINTAINERS +1 -0
@@ -3202,6 +3202,7 @@ F: docs/interop/dbus* F: docs/sphinx/dbus* F: docs/sphinx/fakedbusdoc.py F: tests/qtest/dbus* +F: scripts/xml-preprocess* Seccomp M: Daniel P. Berrange <[email protected]>
scripts/meson.build +2 -0
@@ -1,3 +1,5 @@ if stap.found() install_data('qemu-trace-stap', install_dir: get_option('bindir')) endif + +test('xml-preprocess', files('xml-preprocess-test.py'), suite: ['unit'])
scripts/xml-preprocess-test.py new file +136 -0
136 lines not on this page · raw message
scripts/xml-preprocess.py new file +293 -0
293 lines not on this page · raw message
Signature · 1 line
2.41.0
[PULL 22/33] virtio-gpu/win32: allocate shareable 2d resources/images
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Allocate pixman bits for scanouts with qemu_win32_map_alloc() so we can set a shareable handle on the associated display surface.
Note: when bits are provided to pixman_image_create_bits(), you must also give the rowstride (the argument is ignored when bits is NULL)
Message-Id: <[email protected]>
--- include/hw/virtio/virtio-gpu.h | 3 +++ hw/display/virtio-gpu.c | 46 +++++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 3 deletions(-)
include/hw/virtio/virtio-gpu.h +3 -0
@@ -48,6 +48,9 @@ struct virtio_gpu_simple_resource {unsigned int iov_cnt;uint32_t scanout_bitmask;pixman_image_t *image; +#ifdef WIN32 +HANDLE handle; +#endif uint64_t hostmem;uint64_t blob_size;
hw/display/virtio-gpu.c +43 -3
94 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PULL 22/33] virtio-gpu/win32: allocate shareable 2d resources/images
Quoted 56 lines · On 230627 1502, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
Allocate pixman bits for scanouts with
qemu_win32_map_alloc()so we can set a shareable handle on the associated display surface.Note: when bits are provided to
pixman_image_create_bits(), you must also give the rowstride (the argument is ignored when bits is NULL)Signed-off-by Marc-André Lureau <[email protected]>Message-Id: <[email protected]>
--- include/hw/virtio/virtio-gpu.h | 3 +++ hw/display/virtio-gpu.c | 46 +++++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 3 deletions(-)include/hw/virtio/virtio-gpu.h +3
-0@@ -48,6 +48,9 @@ struct virtio_gpu_simple_resource {unsigned int iov_cnt;uint32_t scanout_bitmask;pixman_image_t *image; +#ifdef WIN32 +HANDLE handle; +#endif uint64_t hostmem;uint64_t blob_size;hw/display/virtio-gpu.c +12
-0@@ -258,6 +258,16 @@ static uint32_t calc_image_hostmem(pixman_format_code_t pformat,return height * stride; } +#ifdef WIN32 +static void +win32_pixman_image_destroy (pixman_image_t *image,void *data) +{ +HANDLE handle = data; + +qemu_win32_map_free (pixman_image_get_data (image), handle, &error_warn); +} +#endif +static void virtio_gpu_resource_create_2d (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd) {@@ -304,12 +314,27 @@ static void virtio_gpu_resource_create_2d(VirtIOGPU *g, res->hostmem =calc_image_hostmem (pformat, c2d.width, c2d.height);if (res->hostmem + g->hostmem < g->conf_max_hostmem) { +void *bits =NULL ; +#ifdef WIN32
hw/display/virtio-gpu.c static void virtio_gpu_resource_create_2d(VirtIOGPU *g, · line 327
Quoted 10 lines
hw/display/virtio-gpu.c +6
-1+ bits =qemu_win32_map_alloc (res->hostmem, &res->handle, &error_warn); +if (!bits) { + goto end; + } +#endif res->image =pixman_image_create_bits (pformat, c2d.width, c2d.height, -NULL ,0 ); + bits, res->hostmem / c2d.height);
Hello,
This may lead to FPE when c2d.height is 0.
https://gitlab.com/qemu-project/qemu/-/issues/1744
-Alex
Re: [PULL 22/33] virtio-gpu/win32: allocate shareable 2d resources/images
In reply to [email protected]Quoted 11 lines · On Tue, 27 Jun 2023 at 14:07, <[email protected]> wrote:
From: Marc-André Lureau <[email protected]>
Allocate pixman bits for scanouts with
qemu_win32_map_alloc()so we can set a shareable handle on the associated display surface.Note: when bits are provided to
pixman_image_create_bits(), you must also give the rowstride (the argument is ignored when bits is NULL)Signed-off-by Marc-André Lureau <[email protected]>Message-Id: <[email protected]>
Hi; Coverity notes (CID 1516557) that this introduces a possible division-by-zero (different from the one Alex's fuzzer found):
Quoted 7 lines
hw/display/virtio-gpu.c +3
-0@@ -1252,15 +1281,23 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,g_free (res);return -EINVAL ; } + + res->hostmem =calc_image_hostmem (pformat, res->width, res->height); +#ifdef WIN32
hw/display/virtio-gpu.c static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size, · line 1295
Quoted 10 lines
hw/display/virtio-gpu.c +7
-1+ bits =qemu_win32_map_alloc (res->hostmem, &res->handle, &error_warn); +if (!bits) { +g_free (res); +return -EINVAL ; + } +#endif res->image =pixman_image_create_bits (pformat, res->width, res->height, -NULL ,0 ); + bits, res->hostmem / res->height);
In this function we've just pulled res->height out of the incoming migration stream, and we haven't done any sanity checking on it. So it might be 0, in which case this division will divide by zero and fall over.
thanks
-- PMM
[PULL 24/33] ui: add egl-headless support on win32
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Make GBM optional for EGL code, and enable the build for win32.
Message-Id: <[email protected]>
--- qapi/ui.json | 5 ++--- include/ui/egl-helpers.h | 7 ++++++- ui/egl-headless.c | 20 +++++++++++++------- ui/egl-helpers.c | 38 +++++++++++++++++++++++++++++++------- ui/meson.build | 6 +++--- 5 files changed, 55 insertions(+), 21 deletions(-)
qapi/ui.json +2 -3
@@ -1484,8 +1484,7 @@ { 'name': 'none' }, { 'name': 'gtk', 'if': 'CONFIG_GTK' }, { 'name': 'sdl', 'if': 'CONFIG_SDL' }, - { 'name': 'egl-headless', - 'if': { 'all': ['CONFIG_OPENGL', 'CONFIG_GBM'] } }, + { 'name': 'egl-headless', 'if': 'CONFIG_OPENGL' }, { 'name': 'curses', 'if': 'CONFIG_CURSES' }, { 'name': 'cocoa', 'if': 'CONFIG_COCOA' }, { 'name': 'spice-app', 'if': 'CONFIG_SPICE' },
@@ -1525,7 +1524,7 @@ 'cocoa': { 'type': 'DisplayCocoa', 'if': 'CONFIG_COCOA' }, 'curses': { 'type': 'DisplayCurses', 'if': 'CONFIG_CURSES' }, 'egl-headless': { 'type': 'DisplayEGLHeadless', - 'if': { 'all': ['CONFIG_OPENGL', 'CONFIG_GBM'] } }, + 'if': 'CONFIG_OPENGL' }, 'dbus': { 'type': 'DisplayDBus', 'if': 'CONFIG_DBUS_DISPLAY' }, 'sdl': { 'type': 'DisplaySDL', 'if': 'CONFIG_SDL' } }
include/ui/egl-helpers.h +6 -1
@@ -36,11 +36,12 @@ void egl_texture_blit(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip);void egl_texture_blend (QemuGLShader *gls,egl_fb *dst,egl_fb *src,bool flip,int x,int y,double scale_x,double scale_y); +extern EGLContext qemu_egl_rn_ctx; +#ifdef CONFIG_GBM extern int qemu_egl_rn_fd;extern struct gbm_device *qemu_egl_rn_gbm_dev; -extern EGLContext qemu_egl_rn_ctx;int egl_rendernode_init (const char *rendernode,DisplayGLMode mode); int egl_get_fd_for_texture(uint32_t tex_id, EGLint *stride, EGLint *fourcc,
@@ -62,6 +63,10 @@ int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, DisplayGLMode mode);#endif +#ifdef WIN32 +int qemu_egl_init_dpy_win32 (EGLNativeDisplayType dpy,DisplayGLMode mode); +#endif +EGLContext qemu_egl_init_ctx (void );bool qemu_egl_has_dmabuf (void );
ui/egl-headless.c +13 -7
@@ -79,6 +79,8 @@ static void egl_scanout_texture(DisplayChangeListener *dcl, } } +#ifdef CONFIG_GBM +static void egl_scanout_dmabuf (DisplayChangeListener *dcl,QemuDmaBuf *dmabuf) {
@@ -110,6 +112,14 @@ static void egl_cursor_dmabuf(DisplayChangeListener *dcl, } } +static void egl_release_dmabuf (DisplayChangeListener *dcl, +QemuDmaBuf *dmabuf) +{ +egl_dmabuf_release_texture (dmabuf); +} + +#endif +static void egl_cursor_position (DisplayChangeListener *dcl,uint32_t pos_x,uint32_t pos_y) {
@@ -119,12 +129,6 @@ static void egl_cursor_position(DisplayChangeListener *dcl, edpy->pos_y = pos_y; } -static void egl_release_dmabuf (DisplayChangeListener *dcl, -QemuDmaBuf *dmabuf) -{ -egl_dmabuf_release_texture (dmabuf); -} -static void egl_scanout_flush (DisplayChangeListener *dcl,uint32_t x,uint32_t y,uint32_t w,uint32_t h)
@@ -160,10 +164,12 @@ static const DisplayChangeListenerOps egl_ops = { .dpy_gl_scanout_disable = egl_scanout_disable, .dpy_gl_scanout_texture = egl_scanout_texture, +#ifdef CONFIG_GBM .dpy_gl_scanout_dmabuf = egl_scanout_dmabuf, .dpy_gl_cursor_dmabuf = egl_cursor_dmabuf, - .dpy_gl_cursor_position = egl_cursor_position, .dpy_gl_release_dmabuf = egl_release_dmabuf, +#endif + .dpy_gl_cursor_position = egl_cursor_position, .dpy_gl_update = egl_scanout_flush, };
ui/egl-helpers.c +31 -7
@@ -199,11 +199,12 @@ void egl_texture_blend(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip,/* ---------------------------------------------------------------------- */ +EGLContext qemu_egl_rn_ctx; +#ifdef CONFIG_GBM int qemu_egl_rn_fd;struct gbm_device *qemu_egl_rn_gbm_dev; -EGLContext qemu_egl_rn_ctx;int egl_rendernode_init (const char *rendernode,DisplayGLMode mode) {
@@ -400,7 +401,7 @@ EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win)/* ---------------------------------------------------------------------- */ -#if defined(CONFIG_X11 ) || defined(CONFIG_GBM ) +#if defined(CONFIG_X11 ) || defined(CONFIG_GBM ) || defined(WIN32 )/* * Taken from glamor_egl.h from the Xorg xserver, which is MIT licensed
@@ -508,6 +509,9 @@ static int qemu_egl_init_dpy(EGLNativeDisplayType dpy,return 0 ; } +#endif + +#if defined(CONFIG_X11 ) || defined(CONFIG_GBM )int qemu_egl_init_dpy_x11 (EGLNativeDisplayType dpy,DisplayGLMode mode) {#ifdef EGL_KHR_platform_x11
@@ -525,7 +529,14 @@ int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, DisplayGLMode mode)return qemu_egl_init_dpy (dpy,0 , mode); #endif } +#endif + +#ifdef WIN32 +int qemu_egl_init_dpy_win32 (EGLNativeDisplayType dpy,DisplayGLMode mode) +{ +return qemu_egl_init_dpy (dpy,0 , mode); +}#endif bool qemu_egl_has_dmabuf (void )
@@ -577,15 +588,28 @@ bool egl_init(const char *rendernode, DisplayGLMode mode, Error **errp)return false; } -#ifdef CONFIG_GBM +#ifdef WIN32 +if (qemu_egl_init_dpy_win32 (EGL_DEFAULT_DISPLAY , mode) <0 ) { +error_setg (errp,"egl: init failed" ); +return false; + } + qemu_egl_rn_ctx =qemu_egl_init_ctx (); +if (!qemu_egl_rn_ctx) { +error_setg (errp,"egl: egl_init_ctx failed" ); +return false; + } +#elif defined(CONFIG_GBM )if (egl_rendernode_init (rendernode, mode) <0 ) {error_setg (errp,"egl: render node init failed" );return false; } +#endif + +if (!qemu_egl_rn_ctx) { +error_setg (errp,"egl: not available on this platform" ); +return false; + } + display_opengl =1 ;return true; -#else -error_setg (errp,"egl: not available on this platform" ); -return false; -#endif }
ui/meson.build +3 -3
@@ -65,10 +65,10 @@ if opengl.found() ui_modules += {'opengl' : opengl_ss} endif -if opengl.found() and gbm.found() +if opengl.found() egl_headless_ss = ss.source_set() - egl_headless_ss.add(when: [opengl, gbm, pixman], - if_true: files('egl-headless.c')) + egl_headless_ss.add(when: [opengl, pixman], + if_true: [files('egl-headless.c'), gbm]) ui_modules += {'egl-headless' : egl_headless_ss} endif
Signature · 1 line
2.41.0
[PULL 18/33] qtest: add qtest_pid()
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Used in the following test on win32, to share sockets with the QEMU process.
Message-Id: <[email protected]>
--- tests/qtest/libqtest.h | 9 +++++++++ tests/qtest/libqtest.c | 5 +++++ 2 files changed, 14 insertions(+)
tests/qtest/libqtest.h +9 -0
@@ -985,4 +985,13 @@ void qtest_qom_set_bool(QTestState *s, const char *path, const char *property,* Returns: Value retrieved from property. */ bool qtest_qom_get_bool (QTestState *s,const char *path,const char *property); + +/** +* qtest_pid: +* @s: QTestState instance to operate on. +* +* Returns: the PID of the QEMU process, or <= 0 +*/ +pid_t qtest_pid (QTestState *s); +#endif
tests/qtest/libqtest.c +5 -0
@@ -142,6 +142,11 @@ static int socket_accept(int sock)return ret; } +pid_t qtest_pid (QTestState *s) +{ +return s->qemu_pid; +} +bool qtest_probe_child (QTestState *s) {pid_t pid = s->qemu_pid;
Signature · 1 line
2.41.0
[PULL 23/33] ui/dbus: use shared memory when possible on win32
In reply to [email protected]From: Marc-André Lureau <[email protected]>
When the display surface has an associated HANDLE, we can duplicate it to the client process and let it map the memory to avoid expensive copies.
Introduce two new win32-specific methods ScanoutMap and UpdateMap. The first is used to inform the listener about the a shared map availability, and the second for display updates.
Message-Id: <[email protected]>
--- ui/dbus-listener.c | 165 ++++++++++++++++++++++++++++++++++++++++++- ui/dbus-display1.xml | 48 ++++++++++++- 2 files changed, 208 insertions(+), 5 deletions(-)
ui/dbus-listener.c +163 -2
@@ -48,6 +48,14 @@ struct _DBusDisplayListener {DisplayChangeListener dcl;DisplaySurface *ds;int gl_updates; + +bool ds_mapped; +bool can_share_map; + +#ifdef WIN32 +QemuDBusDisplay1ListenerWin32Map *map_proxy; +HANDLE peer_process; +#endif };G_DEFINE_TYPE (DBusDisplayListener, dbus_display_listener,G_TYPE_OBJECT )
@@ -119,7 +127,61 @@ static void dbus_scanout_dmabuf(DisplayChangeListener *dcl, fd_list, NULL, NULL, NULL); } +#endif /* OPENGL & GBM */ + +#ifdef WIN32 +static bool dbus_scanout_map (DBusDisplayListener *ddl) +{ +g_autoptr (GError) err =NULL ; +BOOL success; +HANDLE target_handle; + +if (ddl->ds_mapped) { +return true; + } + +if (!ddl->can_share_map || !ddl->ds->handle) { +return false; + } + + success =DuplicateHandle ( +GetCurrentProcess (), + ddl->ds->handle, + ddl->peer_process, + &target_handle, +FILE_MAP_READ |SECTION_QUERY , + FALSE,0 ); +if (!success) { + g_autofree char *msg = g_win32_error_message(GetLastError()); +g_debug ("Failed to DuplicateHandle: %s" , msg); + ddl->can_share_map = false; +return false; + } + +if (!qemu_dbus_display1_listener_win32_map_call_scanout_map_sync ( + ddl->map_proxy, +GPOINTER_TO_UINT (target_handle), + ddl->ds->handle_offset, +surface_width (ddl->ds), +surface_height (ddl->ds), +surface_stride (ddl->ds), +surface_format (ddl->ds), +G_DBUS_CALL_FLAGS_NONE , +DBUS_DEFAULT_TIMEOUT , +NULL , + &err)) { +g_debug ("Failed to call ScanoutMap: %s" , err->message); + ddl->can_share_map = false; +return false; + } + + ddl->ds_mapped = true; + +return true; +} +#endif +#if defined(CONFIG_OPENGL ) && defined(CONFIG_GBM ) static void dbus_scanout_texture(DisplayChangeListener *dcl, uint32_t tex_id, bool backing_y_0_top,
@@ -239,7 +301,7 @@ static void dbus_gl_refresh(DisplayChangeListener *dcl) ddl->gl_updates = 0; } } -#endif +#endif /* OPENGL & GBM */ static void dbus_refresh (DisplayChangeListener *dcl) {
@@ -265,10 +327,20 @@ static void dbus_gfx_update(DisplayChangeListener *dcl,size_t stride;assert (ddl->ds); - stride = w *DIV_ROUND_UP (PIXMAN_FORMAT_BPP (surface_format (ddl->ds)),8 );trace_dbus_update (x, y, w, h); +#ifdef WIN32 +if (dbus_scanout_map (ddl)) { +qemu_dbus_display1_listener_win32_map_call_update_map ( + ddl->map_proxy, + x, y, w, h, +G_DBUS_CALL_FLAGS_NONE , +DBUS_DEFAULT_TIMEOUT ,NULL ,NULL ,NULL ); +return ; + } +#endif +if (x ==0 && y ==0 && w ==surface_width (ddl->ds) && h ==surface_height (ddl->ds)) { v_data = g_variant_new_from_data( G_VARIANT_TYPE("ay"),
@@ -290,6 +362,7 @@ static void dbus_gfx_update(DisplayChangeListener *dcl, }/* make a copy, since gvariant only handles linear data */ + stride = w *DIV_ROUND_UP (PIXMAN_FORMAT_BPP (surface_format (ddl->ds)),8 ); img =pixman_image_create_bits (surface_format (ddl->ds), w, h,NULL , stride); pixman_image_composite(PIXMAN_OP_SRC, ddl->ds->image, NULL, img,
@@ -333,6 +406,9 @@ static void dbus_gfx_switch(DisplayChangeListener *dcl,DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); ddl->ds = new_surface; +#ifdef WIN32 + ddl->ds_mapped = false; +#endif if (!ddl->ds) {/* why not call disable instead? */ return ;
@@ -414,6 +490,10 @@ dbus_display_listener_dispose(GObject *object)g_clear_object (&ddl->conn);g_clear_pointer (&ddl->bus_name, g_free);g_clear_object (&ddl->proxy); +#ifdef WIN32 +g_clear_object (&ddl->map_proxy); +g_clear_pointer (&ddl->peer_process, CloseHandle); +#endif G_OBJECT_CLASS (dbus_display_listener_parent_class)->dispose (object); }
@@ -459,6 +539,85 @@ dbus_display_listener_get_console(DBusDisplayListener *ddl)return ddl->console; } +#ifdef WIN32 +static bool +dbus_display_listener_implements (DBusDisplayListener *ddl,const char *iface) +{ +QemuDBusDisplay1Listener *l =QEMU_DBUS_DISPLAY1_LISTENER (ddl->proxy); +bool implements; + + implements =g_strv_contains (qemu_dbus_display1_listener_get_interfaces (l), iface); +if (!implements) { +g_debug ("Display listener does not implement: `%s`" , iface); + } + +return implements; +} +#endif + +static void +dbus_display_listener_setup_shared_map (DBusDisplayListener *ddl) +{ +#ifdef WIN32 +g_autoptr (GError) err =NULL ; +GDBusConnection *conn; +GIOStream *stream; +GSocket *sock; +g_autoptr (GCredentials) creds =NULL ; +DWORD *pid; + +if (!dbus_display_listener_implements (ddl,"org.qemu.Display1.Listener.Win32.Map" )) { +return ; + } + + conn =g_dbus_proxy_get_connection (G_DBUS_PROXY (ddl->proxy)); + stream =g_dbus_connection_get_stream (conn); + +if (!G_IS_UNIX_CONNECTION (stream)) { +return ; + } + + sock =g_socket_connection_get_socket (G_SOCKET_CONNECTION (stream)); + creds =g_socket_get_credentials (sock, &err); + +if (!creds) { +g_debug ("Failed to get peer credentials: %s" , err->message); +return ; + } + + pid =g_credentials_get_native (creds,G_CREDENTIALS_TYPE_WIN32_PID ); + +if (pid ==NULL ) { +g_debug ("Failed to get peer PID" ); +return ; + } + + ddl->peer_process =OpenProcess ( +PROCESS_DUP_HANDLE |PROCESS_QUERY_INFORMATION , + false, *pid); + +if (!ddl->peer_process) { + g_autofree char *msg = g_win32_error_message(GetLastError()); +g_debug ("Failed to OpenProcess: %s" , msg); +return ; + } + + ddl->map_proxy = +qemu_dbus_display1_listener_win32_map_proxy_new_sync (conn, +G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START , +NULL , +"/org/qemu/Display1/Listener" , +NULL , + &err); +if (!ddl->map_proxy) { +g_debug ("Failed to setup win32 map proxy: %s" , err->message); +return ; + } + + ddl->can_share_map = true; +#endif +} +DBusDisplayListener * dbus_display_listener_new(const char *bus_name, GDBusConnection *conn,
@@ -487,6 +646,8 @@ dbus_display_listener_new(const char *bus_name, ddl->conn = conn; ddl->console = console; +dbus_display_listener_setup_shared_map (ddl); + con =qemu_console_lookup_by_index (dbus_display_console_get_index (console));assert (con); ddl->dcl.con = con;
ui/dbus-display1.xml +45 -3
60 lines not on this page · raw message
Signature · 1 line
2.41.0
[PULL 26/33] ui: add egl_fb_read_rect()
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Similar to egl_fb_read(), same limitations, but with extra arguments to read a subset of the framebuffer. Used in following commits.
Message-Id: <[email protected]>
--- include/ui/egl-helpers.h | 1 + ui/egl-helpers.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+)
include/ui/egl-helpers.h +1 -0
@@ -31,6 +31,7 @@ void egl_fb_setup_for_tex(egl_fb *fb, int width, int height,void egl_fb_setup_new_tex (egl_fb *fb,int width,int height);void egl_fb_blit (egl_fb *dst,egl_fb *src,bool flip);void egl_fb_read (DisplaySurface *dst,egl_fb *src); +void egl_fb_read_rect (DisplaySurface *dst,egl_fb *src,int x,int y,int w,int h);void egl_texture_blit (QemuGLShader *gls,egl_fb *dst,egl_fb *src,bool flip); void egl_texture_blend(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip,
ui/egl-helpers.c +14 -0
@@ -169,6 +169,20 @@ void egl_fb_read(DisplaySurface *dst, egl_fb *src) GL_BGRA, GL_UNSIGNED_BYTE, surface_data(dst)); } +void egl_fb_read_rect (DisplaySurface *dst,egl_fb *src,int x,int y,int w,int h) +{ +assert (surface_width (dst) == src->width); +assert (surface_height (dst) == src->height); +assert (surface_format (dst) == PIXMAN_x8r8g8b8); + +glBindFramebuffer (GL_READ_FRAMEBUFFER , src->framebuffer); +glReadBuffer (GL_COLOR_ATTACHMENT0_EXT ); +glPixelStorei (GL_PACK_ROW_LENGTH ,surface_stride (dst) /4 ); +glReadPixels (x, y, w, h, +GL_BGRA ,GL_UNSIGNED_BYTE ,surface_data (dst) + x *4 ); +glPixelStorei (GL_PACK_ROW_LENGTH ,0 ); +} +void egl_texture_blit (QemuGLShader *gls,egl_fb *dst,egl_fb *src,bool flip) {glBindFramebuffer (GL_FRAMEBUFFER_EXT , dst->framebuffer);
Signature · 1 line
2.41.0
[PULL 20/33] ui/dbus: introduce "Interfaces" properties
In reply to [email protected]From: Marc-André Lureau <[email protected]>
This property is similar to ``org.freedesktop.DBus.Interfaces`` property on the bus interface: it's an array of strings listing the extra interfaces and capabilities available, in a convenient way.
Most interfaces are implicit, as they are required. For ``org/qemu/Display1_$id``, we can list the Keyboard And Mouse interfaces. Those could be optional.
Message-Id: <[email protected]>
--- ui/dbus-console.c | 7 +++ ui/dbus-display1.xml | 118 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 123 insertions(+), 2 deletions(-)
ui/dbus-console.c +7 -0
@@ -537,6 +537,12 @@ dbus_display_console_new(DBusDisplay *display, QemuConsole *con)char device_addr[256 ] ="" ;DBusDisplayConsole *ddc;int idx, i; +const char *interfaces[] = { +"org.qemu.Display1.Keyboard" , +"org.qemu.Display1.Mouse" , +"org.qemu.Display1.MultiTouch" , +NULL + };assert (display);assert (con);
@@ -561,6 +567,7 @@ dbus_display_console_new(DBusDisplay *display, QemuConsole *con)"width" ,qemu_console_get_width (con,0 ),"height" ,qemu_console_get_height (con,0 ),"device-address" , device_addr, +"interfaces" , interfaces, NULL); g_object_connect(ddc->iface, "swapped-signal::handle-register-listener",
ui/dbus-display1.xml +116 -2
176 lines not on this page · raw message
Signature · 1 line
2.41.0
[PULL 21/33] console/win32: allocate shareable display surface
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Introduce qemu_win32_map_alloc() and qemu_win32_map_free() to allocate shared memory mapping. The handle can be used to share the mapping with another process.
Teach qemu_create_displaysurface() to allocate shared memory. Following patches will introduce other places for shared memory allocation.
Other patches for -display dbus will share the memory when possible with the client, to avoid expensive memory copy between the processes.
Message-Id: <[email protected]>
--- include/sysemu/os-win32.h | 3 ++ include/ui/console.h | 8 ++++++ ui/console.c | 59 ++++++++++++++++++++++++++++++++++----- ui/qemu-pixman.c | 1 + util/oslib-win32.c | 33 ++++++++++++++++++++++ ui/trace-events | 2 +- util/trace-events | 4 +++ 7 files changed, 102 insertions(+), 8 deletions(-)
include/sysemu/os-win32.h +3 -0
@@ -263,6 +263,9 @@ EXCEPTION_DISPOSITION win32_close_exception_handler(struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*); +void *qemu_win32_map_alloc (size_t size,HANDLE *h,Error **errp); +void qemu_win32_map_free (void *ptr,HANDLE h,Error **errp); + #ifdef __cplusplus }#endif
include/ui/console.h +8 -0
@@ -143,6 +143,10 @@ typedef struct DisplaySurface {GLenum gltype;GLuint texture;#endif +#ifdef WIN32 +HANDLE handle; +uint32_t handle_offset; +#endif } DisplaySurface; typedef struct QemuUIInfo {
@@ -329,6 +333,10 @@ DisplaySurface *qemu_create_displaysurface_from(int width, int height,DisplaySurface *qemu_create_displaysurface_pixman (pixman_image_t *image);DisplaySurface *qemu_create_placeholder_surface (int w,int h,const char *msg); +#ifdef WIN32 +void qemu_displaysurface_win32_set_handle (DisplaySurface *surface, +HANDLE h,uint32_t offset); +#endif PixelFormat qemu_default_pixelformat (int bpp);DisplaySurface *qemu_create_displaysurface (int width,int height);
ui/console.c +52 -7
76 lines not on this page · raw message
ui/qemu-pixman.c +1 -0
@@ -6,6 +6,7 @@#include "qemu/osdep.h" #include "ui/console.h" #include "standard-headers/drm/drm_fourcc.h" +#include "trace.h" PixelFormat qemu_pixelformat_from_pixman (pixman_format_code_t format) {
util/oslib-win32.c +33 -0
@@ -835,3 +835,36 @@ int qemu_msync(void *addr, size_t length, int fd)*/ return qemu_fdatasync (fd); } + +void *qemu_win32_map_alloc (size_t size,HANDLE *h,Error **errp) +{ +void *bits; + +trace_win32_map_alloc (size); + + *h =CreateFileMapping (INVALID_HANDLE_VALUE ,NULL ,PAGE_READWRITE ,0 , + size,NULL ); +if (*h ==NULL ) { +error_setg_win32 (errp,GetLastError (),"Failed to CreateFileMapping" ); +return NULL ; + } + + bits =MapViewOfFile (*h,FILE_MAP_ALL_ACCESS ,0 ,0 , size); +if (bits ==NULL ) { +error_setg_win32 (errp,GetLastError (),"Failed to MapViewOfFile" ); +CloseHandle (*h); +return NULL ; + } + +return bits; +} + +void qemu_win32_map_free (void *ptr,HANDLE h,Error **errp) +{ +trace_win32_map_free (ptr, h); + +if (UnmapViewOfFile (ptr) ==0 ) { +error_setg_win32 (errp,GetLastError (),"Failed to UnmapViewOfFile" ); + } +CloseHandle (h); +}
ui/trace-events +1 -1
@@ -9,7 +9,7 @@ console_putchar_unhandled(int ch) "unhandled escape character '%c'" console_txt_new(int w, int h) "%dx%d" console_select(int nr) "%d" console_refresh(int interval) "interval %d ms" -displaysurface_create(void *display_surface, int w, int h) "surface=%p, %dx%d" +displaysurface_create(int w, int h) "%dx%d" displaysurface_create_from(void *display_surface, int w, int h, uint32_t format) "surface=%p, %dx%d, format 0x%x" displaysurface_create_pixman(void *display_surface) "surface=%p" displaysurface_free(void *display_surface) "surface=%p"
util/trace-events +4 -0
@@ -52,6 +52,10 @@ qemu_anon_ram_alloc(size_t size, void *ptr) "size %zu ptr %p" qemu_vfree(void *ptr) "ptr %p" qemu_anon_ram_free(void *ptr, size_t size) "ptr %p size %zu" +# oslib-win32.c +win32_map_alloc(size_t size) "size:%zd" +win32_map_free(void *ptr, void *h) "ptr:%p handle:%p" + # hbitmap.c hbitmap_iter_skip_words(const void *hb, void *hbi, uint64_t pos, unsigned long cur) "hb %p hbi %p pos %"PRId64" cur 0x%lx" hbitmap_reset(void *hb, uint64_t start, uint64_t count, uint64_t sbit, uint64_t ebit) "hb %p items %"PRIu64",%"PRIu64" bits %"PRIu64"..%"PRIu64
Signature · 1 line
2.41.0
[PULL 07/33] ui/dbus: Expose a touch device interface
In reply to [email protected]From: Bilal Elmoussaoui <[email protected]>
So that clients making use of the DBus backend could send touch events through the new org.qemu.Display1.Touch interface
Message-Id: <[email protected]>
--- ui/dbus-console.c | 59 +++++++++++++++++++++++++++++++++++++++++++- ui/dbus-display1.xml | 45 +++++++++++++++++++++++++++++++-- ui/trace-events | 1 + 3 files changed, 102 insertions(+), 3 deletions(-)
ui/dbus-console.c +58 -1
@@ -32,6 +32,8 @@#include "dbus.h" +static struct touch_slot touch_slots[INPUT_EVENT_SLOTS_MAX ]; +struct _DBusDisplayConsole {GDBusObjectSkeleton parent_instance;DisplayChangeListener dcl;
@@ -44,6 +46,7 @@ struct _DBusDisplayConsole {QKbdState *kbd;QemuDBusDisplay1Mouse *iface_mouse; +QemuDBusDisplay1MultiTouch *iface_touch;gboolean last_set;guint last_x;guint last_y;
@@ -345,6 +348,46 @@ dbus_mouse_rel_motion(DBusDisplayConsole *ddc,return DBUS_METHOD_INVOCATION_HANDLED ; } +static gboolean +dbus_touch_send_event (DBusDisplayConsole *ddc, +GDBusMethodInvocation *invocation, +guint kind,uint64_t num_slot, +double x,double y) +{ +Error *error =NULL ; +int width, height; +trace_dbus_touch_send_event (kind, num_slot, x, y); + +if (kind !=INPUT_MULTI_TOUCH_TYPE_BEGIN && + kind !=INPUT_MULTI_TOUCH_TYPE_UPDATE && + kind !=INPUT_MULTI_TOUCH_TYPE_CANCEL && + kind !=INPUT_MULTI_TOUCH_TYPE_END ) + { +g_dbus_method_invocation_return_error ( + invocation,DBUS_DISPLAY_ERROR , +DBUS_DISPLAY_ERROR_INVALID , +"Invalid touch event kind" ); +return DBUS_METHOD_INVOCATION_HANDLED ; + } + width =qemu_console_get_width (ddc->dcl.con,0 ); + height =qemu_console_get_height (ddc->dcl.con,0 ); + +console_handle_touch_event (ddc->dcl.con, touch_slots, + num_slot, width, height, + x, y, kind, &error); +if (error !=NULL ) { +g_dbus_method_invocation_return_error ( + invocation,DBUS_DISPLAY_ERROR , +DBUS_DISPLAY_ERROR_INVALID , +error_get_pretty (error),NULL ); +error_free (error); + }else { +qemu_dbus_display1_multi_touch_complete_send_event (ddc->iface_touch, + invocation); + } +return DBUS_METHOD_INVOCATION_HANDLED ; +} + static gboolean dbus_mouse_set_pos(DBusDisplayConsole *ddc, GDBusMethodInvocation *invocation,
@@ -440,7 +483,7 @@ dbus_display_console_new(DBusDisplay *display, QemuConsole *con) g_autofree char *label = NULL;char device_addr[256 ] ="" ;DBusDisplayConsole *ddc; -int idx; +int idx, i;assert (display);assert (con);
@@ -495,6 +538,20 @@ dbus_display_console_new(DBusDisplay *display, QemuConsole *con)g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (ddc),G_DBUS_INTERFACE_SKELETON (ddc->iface_mouse)); + ddc->iface_touch =qemu_dbus_display1_multi_touch_skeleton_new (); +g_object_connect (ddc->iface_touch, +"swapped-signal::handle-send-event" , dbus_touch_send_event, ddc, +NULL ); +qemu_dbus_display1_multi_touch_set_max_slots (ddc->iface_touch, +INPUT_EVENT_SLOTS_MAX ); +g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (ddc), +G_DBUS_INTERFACE_SKELETON (ddc->iface_touch)); + +for (i =0 ; i <INPUT_EVENT_SLOTS_MAX ; i++) { +struct touch_slot *slot = &touch_slots[i]; + slot->tracking_id =-1 ; + } +register_displaychangelistener (&ddc->dcl); ddc->mouse_mode_notifier.notify = dbus_mouse_mode_change;qemu_add_mouse_mode_change_notifier (&ddc->mouse_mode_notifier);
ui/dbus-display1.xml +43 -2
57 lines not on this page · raw message
ui/trace-events +1 -0
@@ -154,6 +154,7 @@ dbus_mouse_press(unsigned int button) "button %u" dbus_mouse_release(unsigned int button) "button %u" dbus_mouse_set_pos(unsigned int x, unsigned int y) "x=%u, y=%u" dbus_mouse_rel_motion(int dx, int dy) "dx=%d, dy=%d" +dbus_touch_send_event(unsigned int kind, uint32_t num_slot, uint32_t x, uint32_t y) "kind=%u, num_slot=%u, x=%d, y=%d" dbus_update(int x, int y, int w, int h) "x=%d, y=%d, w=%d, h=%d" dbus_clipboard_grab_failed(void) "" dbus_clipboard_register(const char *bus_name) "peer %s"
Signature · 1 line
2.41.0
[PULL 33/33] ui/dbus: use shared D3D11 Texture2D when possible
In reply to [email protected]From: Marc-André Lureau <[email protected]>
When the client implements "org.qemu.Display1.Listener.Win32.D3d11" and we are running on ANGLE/win32, share the scanout texture with the peer process, and draw with ScanoutTexture2d/UpdateTexture2d methods.
Message-Id: <[email protected]>
--- ui/dbus-listener.c | 299 ++++++++++++++++++++++++++++++++++++++----- ui/dbus-display1.xml | 56 +++++++- 2 files changed, 324 insertions(+), 31 deletions(-)
ui/dbus-listener.c +270 -29
@@ -23,11 +23,16 @@*/ #include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qapi/error.h" #include "sysemu/sysemu.h" #include "dbus.h" #ifdef G_OS_UNIX #include <gio/gunixfdlist.h> #endif +#ifdef WIN32 +#include <d3d11.h> +#include <dxgi1_2.h> +#endif #ifdef CONFIG_OPENGL #include "ui/shader.h"
@@ -39,6 +44,12 @@static void dbus_gfx_switch (DisplayChangeListener *dcl,struct DisplaySurface *new_surface); +enum share_kind { +SHARE_KIND_NONE , +SHARE_KIND_MAPPED , +SHARE_KIND_D3DTEX , +}; +struct _DBusDisplayListener {GObject parent;
@@ -50,6 +61,8 @@ struct _DBusDisplayListener {DisplayChangeListener dcl;DisplaySurface *ds; +enum share_kind ds_share; +int gl_updates;bool ds_mapped;
@@ -57,7 +70,9 @@ struct _DBusDisplayListener {#ifdef WIN32 QemuDBusDisplay1ListenerWin32Map *map_proxy; +QemuDBusDisplay1ListenerWin32D3d11 *d3d11_proxy;HANDLE peer_process; +ID3D11Texture2D *d3d_texture;#ifdef CONFIG_OPENGL egl_fb fb;#endif
@@ -74,28 +89,120 @@ static void dbus_scanout_disable(DisplayChangeListener *dcl) {DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); - ddl->ds =NULL ;qemu_dbus_display1_listener_call_disable ( ddl->proxy,G_DBUS_CALL_FLAGS_NONE ,-1 ,NULL ,NULL ,NULL ); } -#ifdef CONFIG_GBM +#ifdef WIN32 +static bool d3d_texture2d_share (ID3D11Texture2D *d3d_texture, +HANDLE *handle,Error **errp) +{ +IDXGIResource1 *dxgiResource =NULL ; +HRESULT hr; + + hr = d3d_texture->lpVtbl->QueryInterface (d3d_texture, + &IID_IDXGIResource1, + (void **)&dxgiResource); +if (FAILED (hr)) { + goto fail; + } + + hr = dxgiResource->lpVtbl->CreateSharedHandle ( + dxgiResource, +NULL , +DXGI_SHARED_RESOURCE_READ |DXGI_SHARED_RESOURCE_WRITE , +NULL , + handle + ); + + dxgiResource->lpVtbl->Release (dxgiResource); + +if (SUCCEEDED (hr)) { +return true; + } + +fail: +error_setg_win32 (errp,GetLastError (),"failed to create shared handle" ); +return false; +} + +static bool d3d_texture2d_acquire0 (ID3D11Texture2D *d3d_texture,Error **errp) +{ +IDXGIKeyedMutex *dxgiMutex =NULL ; +HRESULT hr; + + hr = d3d_texture->lpVtbl->QueryInterface (d3d_texture, + &IID_IDXGIKeyedMutex, + (void **)&dxgiMutex); +if (FAILED (hr)) { + goto fail; + } + + hr = dxgiMutex->lpVtbl->AcquireSync (dxgiMutex,0 ,INFINITE ); + + dxgiMutex->lpVtbl->Release (dxgiMutex); + +if (SUCCEEDED (hr)) { +return true; + } + +fail: +error_setg_win32 (errp,GetLastError (),"failed to acquire texture mutex" ); +return false; +} + +static bool d3d_texture2d_release0 (ID3D11Texture2D *d3d_texture,Error **errp) +{ +IDXGIKeyedMutex *dxgiMutex =NULL ; +HRESULT hr; + + hr = d3d_texture->lpVtbl->QueryInterface (d3d_texture, + &IID_IDXGIKeyedMutex, + (void **)&dxgiMutex); +if (FAILED (hr)) { + goto fail; + } + + hr = dxgiMutex->lpVtbl->ReleaseSync (dxgiMutex,0 ); + + dxgiMutex->lpVtbl->Release (dxgiMutex); + +if (SUCCEEDED (hr)) { +return true; + } + +fail: +error_setg_win32 (errp,GetLastError (),"failed to release texture mutex" ); +return false; +} +#endif /* WIN32 */ +static void dbus_update_gl_cb (GObject *source_object, -GAsyncResult *res, -gpointer user_data) +GAsyncResult *res, +gpointer user_data) {g_autoptr (GError) err =NULL ;DBusDisplayListener *ddl = user_data; +bool success; + +#ifdef CONFIG_GBM + success =qemu_dbus_display1_listener_call_update_dmabuf_finish ( + ddl->proxy, res, &err); +#endif + +#ifdef WIN32 + success =qemu_dbus_display1_listener_win32_d3d11_call_update_texture2d_finish ( + ddl->d3d11_proxy, res, &err); +d3d_texture2d_acquire0 (ddl->d3d_texture, &error_warn); +#endif -if (!qemu_dbus_display1_listener_call_update_dmabuf_finish (ddl->proxy, - res, &err)) { +if (!success) {error_report ("Failed to call update: %s" , err->message); }graphic_hw_gl_block (ddl->dcl.con, false);g_object_unref (ddl); } -#endif static void dbus_call_update_gl (DisplayChangeListener *dcl,int x,int y,int w,int h)
@@ -116,8 +223,31 @@ static void dbus_call_update_gl(DisplayChangeListener *dcl,#endif #ifdef WIN32 -egl_fb_read_rect (ddl->ds, &ddl->fb, x, y, w, h); -dbus_gfx_update (dcl, x, y, w, h); +switch (ddl->ds_share) { +case SHARE_KIND_MAPPED : +egl_fb_read_rect (ddl->ds, &ddl->fb, x, y, w, h); +dbus_gfx_update (dcl, x, y, w, h); +break ; +case SHARE_KIND_D3DTEX : +Error *err =NULL ; +assert (ddl->d3d_texture); + +graphic_hw_gl_block (ddl->dcl.con, true); +if (!d3d_texture2d_release0 (ddl->d3d_texture, &err)) { +error_report_err (err); +return ; + } +qemu_dbus_display1_listener_win32_d3d11_call_update_texture2d ( + ddl->d3d11_proxy, + x, y, w, h, +G_DBUS_CALL_FLAGS_NONE , +DBUS_DEFAULT_TIMEOUT ,NULL , + dbus_update_gl_cb, +g_object_ref (ddl)); +break ; +default : +g_warn_if_reached (); + }#endif }
@@ -160,7 +290,7 @@ static bool dbus_scanout_map(DBusDisplayListener *ddl)BOOL success;HANDLE target_handle; -if (ddl->ds_mapped) { +if (ddl->ds_share ==SHARE_KIND_MAPPED ) {return true; }
@@ -199,7 +329,69 @@ static bool dbus_scanout_map(DBusDisplayListener *ddl)return false; } - ddl->ds_mapped = true; + ddl->ds_share =SHARE_KIND_MAPPED ; + +return true; +} + +static bool +dbus_scanout_share_d3d_texture ( +DBusDisplayListener *ddl, +ID3D11Texture2D *tex, +bool backing_y_0_top, +uint32_t backing_width, +uint32_t backing_height, +uint32_t x,uint32_t y, +uint32_t w,uint32_t h) +{ +Error *err =NULL ; +BOOL success; +HANDLE share_handle, target_handle; + +if (!d3d_texture2d_release0 (tex, &err)) { +error_report_err (err); +return false; + } + +if (!d3d_texture2d_share (tex, &share_handle, &err)) { +error_report_err (err); +return false; + } + + success =DuplicateHandle ( +GetCurrentProcess (), + share_handle, + ddl->peer_process, + &target_handle, +0 , + FALSE,DUPLICATE_SAME_ACCESS ); +if (!success) { + g_autofree char *msg = g_win32_error_message(GetLastError()); +g_debug ("Failed to DuplicateHandle: %s" , msg); +CloseHandle (share_handle); +return false; + } + +qemu_dbus_display1_listener_win32_d3d11_call_scanout_texture2d ( + ddl->d3d11_proxy, +GPOINTER_TO_INT (target_handle), + backing_width, + backing_height, + backing_y_0_top, + x, y, w, h, +G_DBUS_CALL_FLAGS_NONE , +-1 , +NULL ,NULL ,NULL ); + +CloseHandle (share_handle); + +if (!d3d_texture2d_acquire0 (tex, &err)) { +error_report_err (err); +return false; + } + + ddl->d3d_texture = tex; + ddl->ds_share =SHARE_KIND_D3DTEX ;return true; }
@@ -248,7 +440,14 @@ static void dbus_scanout_texture(DisplayChangeListener *dcl,/* there must be a matching gfx_switch before */ assert (surface_width (ddl->ds) == w);assert (surface_height (ddl->ds) == h); -egl_fb_setup_for_tex (&ddl->fb, backing_width, backing_height, tex_id, false); + +if (d3d_tex2d) { +dbus_scanout_share_d3d_texture (ddl, d3d_tex2d, backing_y_0_top, + backing_width, backing_height, x, y, w, h); + }else { +dbus_scanout_map (ddl); +egl_fb_setup_for_tex (&ddl->fb, backing_width, backing_height, tex_id, false); + }#endif }
@@ -429,6 +628,7 @@ static void dbus_gl_gfx_switch(DisplayChangeListener *dcl,trace_dbus_gl_gfx_switch (new_surface); ddl->ds = new_surface; + ddl->ds_share =SHARE_KIND_NONE ;if (ddl->ds) {int width =surface_width (ddl->ds);int height =surface_height (ddl->ds);
@@ -446,13 +646,7 @@ static void dbus_gfx_switch(DisplayChangeListener *dcl,DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); ddl->ds = new_surface; -#ifdef WIN32 - ddl->ds_mapped = false; -#endif -if (!ddl->ds) { -/* why not call disable instead? */ -return ; - } + ddl->ds_share =SHARE_KIND_NONE ; } static void dbus_mouse_set(DisplayChangeListener *dcl,
@@ -534,6 +728,7 @@ dbus_display_listener_dispose(GObject *object)g_clear_object (&ddl->proxy);#ifdef WIN32 g_clear_object (&ddl->map_proxy); +g_clear_object (&ddl->d3d11_proxy);g_clear_pointer (&ddl->peer_process, CloseHandle);#ifdef CONFIG_OPENGL egl_fb_destroy (&ddl->fb);
@@ -598,12 +793,10 @@ dbus_display_listener_implements(DBusDisplayListener *ddl, const char *iface)return implements; } -#endif -static void -dbus_display_listener_setup_shared_map (DBusDisplayListener *ddl) +static bool +dbus_display_listener_setup_peer_process (DBusDisplayListener *ddl) { -#ifdef WIN32 g_autoptr (GError) err =NULL ;GDBusConnection *conn;GIOStream *stream;
@@ -611,15 +804,15 @@ dbus_display_listener_setup_shared_map(DBusDisplayListener *ddl)g_autoptr (GCredentials) creds =NULL ;DWORD *pid; -if (!dbus_display_listener_implements (ddl,"org.qemu.Display1.Listener.Win32.Map" )) { -return ; +if (ddl->peer_process) { +return true; } conn =g_dbus_proxy_get_connection (G_DBUS_PROXY (ddl->proxy)); stream =g_dbus_connection_get_stream (conn);if (!G_IS_UNIX_CONNECTION (stream)) { -return ; +return false; } sock =g_socket_connection_get_socket (G_SOCKET_CONNECTION (stream));
@@ -627,14 +820,14 @@ dbus_display_listener_setup_shared_map(DBusDisplayListener *ddl)if (!creds) {g_debug ("Failed to get peer credentials: %s" , err->message); -return ; +return false; } pid =g_credentials_get_native (creds,G_CREDENTIALS_TYPE_WIN32_PID );if (pid ==NULL ) {g_debug ("Failed to get peer PID" ); -return ; +return false; } ddl->peer_process = OpenProcess(
@@ -644,11 +837,58 @@ dbus_display_listener_setup_shared_map(DBusDisplayListener *ddl)if (!ddl->peer_process) { g_autofree char *msg = g_win32_error_message(GetLastError());g_debug ("Failed to OpenProcess: %s" , msg); +return false; + } + +return true; +} +#endif + +static void +dbus_display_listener_setup_d3d11 (DBusDisplayListener *ddl) +{ +#ifdef WIN32 +g_autoptr (GError) err =NULL ; + +if (!dbus_display_listener_implements (ddl, +"org.qemu.Display1.Listener.Win32.D3d11" )) { +return ; + } + +if (!dbus_display_listener_setup_peer_process (ddl)) { +return ; + } + + ddl->d3d11_proxy = +qemu_dbus_display1_listener_win32_d3d11_proxy_new_sync (ddl->conn, +G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START , +NULL , +"/org/qemu/Display1/Listener" , +NULL , + &err); +if (!ddl->d3d11_proxy) { +g_debug ("Failed to setup win32 d3d11 proxy: %s" , err->message); +return ; + } +#endif +} + +static void +dbus_display_listener_setup_shared_map (DBusDisplayListener *ddl) +{ +#ifdef WIN32 +g_autoptr (GError) err =NULL ; + +if (!dbus_display_listener_implements (ddl,"org.qemu.Display1.Listener.Win32.Map" )) { +return ; + } + +if (!dbus_display_listener_setup_peer_process (ddl)) {return ; } ddl->map_proxy = - qemu_dbus_display1_listener_win32_map_proxy_new_sync(conn, + qemu_dbus_display1_listener_win32_map_proxy_new_sync(ddl->conn, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL, "/org/qemu/Display1/Listener",
@@ -692,6 +932,7 @@ dbus_display_listener_new(const char *bus_name, ddl->console = console;dbus_display_listener_setup_shared_map (ddl); +dbus_display_listener_setup_d3d11 (ddl); con =qemu_console_lookup_by_index (dbus_display_console_get_index (console));assert (con);
ui/dbus-display1.xml +54 -2
68 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PULL 33/33] ui/dbus: use shared D3D11 Texture2D when possible
Quoted 16 lines · On 6/27/23 15:02, [email protected] wrote:
static void dbus_update_gl_cb(GObject
*source_object,ui/dbus-listener.c +10
-2-GAsyncResult *res, - gpointer user_data) +GAsyncResult *res, + gpointer user_data) {g_autoptr (GError ) err =NULL ;DBusDisplayListener *ddl = user_data; +bool success; + +#ifdef CONFIG_GBM + success =qemu_dbus_display1_listener_call_update_dmabuf_finish ( + ddl->proxy, res, &err); +#endif + +#ifdef WIN32
ui/dbus-listener.c static void dbus_scanout_disable(DisplayChangeListener *dcl) · line 201
Quoted 10 lines
ui/dbus-listener.c +5
-2+ success =qemu_dbus_display1_listener_win32_d3d11_call_update_texture2d_finish ( + ddl->d3d11_proxy, res, &err); +d3d_texture2d_acquire0 (ddl->d3d_texture, &error_warn); +#endif -if (!qemu_dbus_display1_listener_call_update_dmabuf_finish (ddl->proxy, - res, &err)) { +if (!success) {error_report ("Failed to call update: %s" , err->message); }
With neither CONFIG_GBM nor WIN32, success is not set:
../alt/ui/dbus-listener.c:199:10: error: variable 'success' is uninitialized when used here [-Werror,-Wuninitialized]
if (!success) {
^~~~~~~r~
Re: [PULL 33/33] ui/dbus: use shared D3D11 Texture2D when possible
Quoted 29 lines · Richard Henderson
Quoted 23 lines · On 6/27/23 15:02, [email protected] wrote:
static void dbus_update_gl_cb(GObject
*source_object, - GAsyncResult *res, - gpointeruser_data) + GAsyncResult *res, + gpointeruser_data) {
g_autoptr(GError)err = NULL; DBusDisplayListener *ddl =user_data;
+ bool success;ui/dbus-listener.c +12
-2+ +#ifdef CONFIG_GBM + success = qemu_dbus_display1_listener_call_update_dmabuf_finish( + ddl->proxy, res, &err); +#endif + +#ifdef WIN32 + success = qemu_dbus_display1_listener_win32_d3d11_call_update_texture2d_finish( + ddl->d3d11_proxy, res, &err); + d3d_texture2d_acquire0(ddl->d3d_texture, &error_warn); +#endif - if (!qemu_dbus_display1_listener_call_update_dmabuf_finish(ddl->proxy, - res, &err)) { + if (!success) {Quoted 2 lines
error_report("Failed to call update: %s", err->message); }With neither
CONFIG_GBMnor WIN32, success is not set:
Quoted 3 lines
../alt/ui/dbus-listener.c:199:10: error: variable 'success' is uninitialized when used here [-Werror,-Wuninitialized]
if (!success) {
^~~~~~~
Bah. Working around that, the whole function isn't used under these same conditions:
../alt/ui/dbus-listener.c:180:13: error: unused function 'dbus_update_gl_cb' [-Werror,-Wunused-function] static void dbus_update_gl_cb(GObject *source_object, GAsyncResult *res,
^
1 error generated.
Definitely some cleanup to the ifdefs required...
r~
Re: [PULL 33/33] ui/dbus: use shared D3D11 Texture2D when possible
In reply to Richard HendersonQuoted 29 lines · Richard Henderson
Quoted 23 lines · On 6/27/23 15:02, [email protected] wrote:
static void dbus_update_gl_cb(GObject
*source_object, - GAsyncResult *res, - gpointeruser_data) + GAsyncResult *res, + gpointeruser_data) {
g_autoptr(GError)err = NULL; DBusDisplayListener *ddl =user_data;
+ bool success;ui/dbus-listener.c +12
-2+ +#ifdef CONFIG_GBM + success = qemu_dbus_display1_listener_call_update_dmabuf_finish( + ddl->proxy, res, &err); +#endif + +#ifdef WIN32 + success = qemu_dbus_display1_listener_win32_d3d11_call_update_texture2d_finish( + ddl->d3d11_proxy, res, &err); + d3d_texture2d_acquire0(ddl->d3d_texture, &error_warn); +#endif - if (!qemu_dbus_display1_listener_call_update_dmabuf_finish(ddl->proxy, - res, &err)) { + if (!success) {Quoted 2 lines
error_report("Failed to call update: %s", err->message); }With neither
CONFIG_GBMnor WIN32, success is not set:
Quoted 3 lines
../alt/ui/dbus-listener.c:199:10: error: variable 'success' is uninitialized when used here [-Werror,-Wuninitialized]
if (!success) {
^~~~~~~
I'm seeing something similar to this on my builds of git master this morning:
cc -m64 -mcx16 -Ilibcommon.fa.p -Iui -I../ui -I/usr/include/pixman-1 -I/usr/include/libpng16 -I/usr/include/spice-server -I/usr/include/spice-1 -I/usr/include/p11-kit-1 -I/usr/include/SDL2 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/gio-unix-2.0 -I/usr/include/slirp -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/harfbuzz -I/usr/include/atk-1.0 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/vte-2.91 -I/usr/include/cacard -I/usr/include/nss -I/usr/include/nspr -I/usr/include/PCSC -I/usr/include/libusb-1.0 -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O0 -g -fstack-protector-strong -Wundef -Wwrite-strings -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wold-style-declaration -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wimplicit-fallthrough=2 -Wmissing-format-attribute -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-psabi -isystem /home/build/src/qemu/git/qemu/linux-headers -isystem linux-headers -iquote . -iquote /home/build/src/qemu/git/qemu -iquote /home/build/src/qemu/git/qemu/include -iquote /home/build/src/qemu/git/qemu/host/include/x86_64 -iquote /home/build/src/qemu/git/qemu/host/include/generic -iquote /home/build/src/qemu/git/qemu/tcg/i386 -pthread -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-common -fwrapv -fPIE -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -DNCURSES_WIDECHAR=1 -D_REENTRANT -DSTRUCT_IOVEC_DEFINED -MD -MQ libcommon.fa.p/ui_dbus-listener.c.o -MF libcommon.fa.p/ui_dbus-listener.c.o.d -o libcommon.fa.p/ui_dbus-listener.c.o -c ../ui/dbus-listener.c ../ui/dbus-listener.c: In function ‘dbus_call_update_gl’:../ui/dbus-listener.c:210:26: error: unused variable ‘ddl’ [-Werror=unused-variable]
210 | DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
| ^~~
At top level:../ui/dbus-listener.c:180:13: error: ‘dbus_update_gl_cb’ defined but not used [-Werror=unused-function]
180 | static void dbus_update_gl_cb(GObject *source_object,
| ^~~~~~~~~~~~~~~~~
../ui/dbus-listener.c: In function ‘dbus_update_gl_cb’:
../ui/dbus-listener.c:199:9: error: ‘success’ is used uninitialized in this function [-Werror=uninitialized]
199 | if (!success) {
| ^~~~~~~~cc1: all warnings being treated as errors
ninja: build stopped: subcommand failed.
ATB,
Mark.
[PULL 06/33] ui/touch: Move event handling to a common helper
In reply to [email protected]From: Bilal Elmoussaoui <[email protected]>
To share code between the GTK and DBus UI bakcends see the next commit for details
Message-Id: <[email protected]>
--- include/ui/console.h | 15 ++++++++++ ui/console.c | 65 ++++++++++++++++++++++++++++++++++++++++++++ ui/gtk.c | 61 ++++------------------------------------- 3 files changed, 85 insertions(+), 56 deletions(-)
include/ui/console.h +15 -0
@@ -5,6 +5,7 @@#include "qom/object.h" #include "qemu/notify.h" #include "qapi/qapi-types-ui.h" +#include "ui/input.h" #ifdef CONFIG_OPENGL # include <epoxy/gl.h>
@@ -95,6 +96,20 @@ bool kbd_put_qcode_console(QemuConsole *s, int qcode, bool ctrl);void kbd_put_string_console (QemuConsole *s,const char *str,int len);void kbd_put_keysym (int keysym); +/* Touch devices */ +typedef struct touch_slot { +int x; +int y; +int tracking_id; +}touch_slot ; + +void console_handle_touch_event (QemuConsole *con, +struct touch_slot touch_slots[INPUT_EVENT_SLOTS_MAX ], +uint64_t num_slot, +int width,int height, +double x,double y, +InputMultiTouchType type, +Error **errp);/* consoles */ #define TYPE_QEMU_CONSOLE "qemu-console"
ui/console.c +65 -0
71 lines not on this page · raw message
ui/gtk.c +5 -56
87 lines not on this page · raw message
Signature · 1 line
2.41.0
[PULL 17/33] ui/dbus: win32 support
In reply to [email protected]From: Marc-André Lureau <[email protected]>
D-Bus doesn't support fd-passing on Windows (AF_UNIX doesn't have SCM_RIGHTS yet, but there are other means to share objects. I have proposed various solutions upstream, but none seem fitting enough atm).
To make the "-display dbus" work on Windows, implement an alternative D-Bus interface where all the 'h' (FDs) arguments are replaced with 'ay' (WSASocketW data), and sockets are passed to the other end via WSADuplicateSocket().
Message-Id: <[email protected]>
--- meson.build | 4 +-- ui/dbus.h | 6 +++++ audio/dbusaudio.c | 44 +++++++++++++++++++++++++++------ ui/dbus-chardev.c | 22 +++++++++++++---- ui/dbus-console.c | 59 ++++++++++++++++++++++++++++++++++++++------ ui/dbus-display1.xml | 28 +++++++++++++++++++++ ui/meson.build | 9 ++++++- 7 files changed, 149 insertions(+), 23 deletions(-)
meson.build +2 -2
@@ -838,6 +838,8 @@ if gdbus_codegen.found() and get_option('cfi') gdbus_codegen_error = '@0@ uses gdbus-codegen, which does not support control flow integrity' endif +xml_pp = find_program('scripts/xml-preprocess.py') + lttng = not_found if 'ust' in get_option('trace_backends') lttng = dependency('lttng-ust', required: true, version: '>= 2.1',
@@ -1985,8 +1987,6 @@ dbus_display = get_option('dbus_display') \ error_message: '-display dbus requires glib>=2.64') \ .require(gdbus_codegen.found(), error_message: gdbus_codegen_error.format('-display dbus')) \ - .require(targetos != 'windows', - error_message: '-display dbus is not available on Windows') \ .allowed() have_virtfs = get_option('virtfs') \
ui/dbus.h +6 -0
@@ -62,6 +62,12 @@ struct DBusDisplay {Notifier notifier; }; +#ifdef WIN32 +bool +dbus_win32_import_socket (GDBusMethodInvocation *invocation, +GVariant *arg_listener,int *socket); +#endif +#define TYPE_DBUS_DISPLAY "dbus-display"OBJECT_DECLARE_SIMPLE_TYPE (DBusDisplay,DBUS_DISPLAY )
audio/dbusaudio.c +36 -8
121 lines not on this page · raw message
ui/dbus-chardev.c +17 -5
@@ -110,18 +110,24 @@ dbus_chardev_init(DBusDisplay *dpy) dbus_display_chardev_foreach, dpy); } -#ifdef G_OS_UNIX static gboolean dbus_chr_register (DBusChardev *dc,GDBusMethodInvocation *invocation, +#ifdef G_OS_UNIX GUnixFDList *fd_list, +#endifGVariant *arg_stream,QemuDBusDisplay1Chardev *object) {g_autoptr (GError) err =NULL ;int fd; +#ifdef G_OS_WIN32 +if (!dbus_win32_import_socket (invocation, arg_stream, &fd)) { +return DBUS_METHOD_INVOCATION_HANDLED ; + } +#else fd =g_unix_fd_list_get (fd_list,g_variant_get_handle (arg_stream), &err);if (err) { g_dbus_method_invocation_return_error(
@@ -131,13 +137,18 @@ dbus_chr_register( "Couldn't get peer FD: %s", err->message); return DBUS_METHOD_INVOCATION_HANDLED; } +#endif if (qemu_chr_add_client (CHARDEV (dc), fd) <0 ) {g_dbus_method_invocation_return_error (invocation,DBUS_DISPLAY_ERROR ,DBUS_DISPLAY_ERROR_FAILED ,"Couldn't register FD!" ); +#ifdef G_OS_WIN32 +closesocket (fd); +#else close (fd); +#endif return DBUS_METHOD_INVOCATION_HANDLED ; }
@@ -145,10 +156,13 @@ dbus_chr_register("owner" ,g_dbus_method_invocation_get_sender (invocation), NULL); -qemu_dbus_display1_chardev_complete_register (object, invocation,NULL ); +qemu_dbus_display1_chardev_complete_register (object, invocation +#ifndef G_OS_WIN32 + ,NULL +#endif + );return DBUS_METHOD_INVOCATION_HANDLED ; } -#endif static gboolean dbus_chr_send_break(
@@ -179,10 +193,8 @@ dbus_chr_open(Chardev *chr, ChardevBackend *backend, dc->iface =qemu_dbus_display1_chardev_skeleton_new ();g_object_set (dc->iface,"name" , backend->u.dbus.data->name,NULL );g_object_connect (dc->iface, -#ifdef G_OS_UNIX"swapped-signal::handle-register" , dbus_chr_register, dc, -#endif"swapped-signal::handle-send-break" , dbus_chr_send_break, dc,NULL );
ui/dbus-console.c +52 -7
119 lines not on this page · raw message
ui/dbus-display1.xml +28 -0
@@ -57,7 +57,13 @@ :dbus:iface:`org.qemu.Display1.Listener` interface. --> <method name="RegisterListener"> + <?if $(env.TARGETOS) == windows?> + <arg type="ay" name="listener" direction="in"> + <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/> + </arg> + <?else?> <arg type="h" name="listener" direction="in"/> + <?endif?> </method> <!--
@@ -334,6 +340,9 @@ </arg> </method> + <?if $(env.TARGETOS) == windows?> + <!-- Add shared memory/texture support --> + <?else?> <!-- ScanoutDMABUF: @dmabuf: the DMABUF file descriptor.
@@ -372,6 +381,7 @@ <arg type="i" name="width" direction="in"/> <arg type="i" name="height" direction="in"/> </method> + <?endif?> <!-- Disable:
@@ -532,7 +542,13 @@ :dbus:iface:`org.qemu.Display1.AudioOutListener` interface. --> <method name="RegisterOutListener"> + <?if $(env.TARGETOS) == windows?> + <arg type="ay" name="listener" direction="in"> + <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/> + </arg> + <?else?> <arg type="h" name="listener" direction="in"/> + <?endif?> </method> <!--
@@ -547,7 +563,13 @@ :dbus:iface:`org.qemu.Display1.AudioInListener` interface. --> <method name="RegisterInListener"> + <?if $(env.TARGETOS) == windows?> + <arg type="ay" name="listener" direction="in"> + <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/> + </arg> + <?else?> <arg type="h" name="listener" direction="in"/> + <?endif?> </method> </interface>
@@ -760,7 +782,13 @@ The current handler, if any, will be replaced. --> <method name="Register"> + <?if $(env.TARGETOS) == windows?> + <arg type="ay" name="listener" direction="in"> + <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/> + </arg> + <?else?> <arg type="h" name="stream" direction="in"/> + <?endif?> </method> <!--
ui/meson.build +8 -1
@@ -74,9 +74,16 @@ endif if dbus_display dbus_ss = ss.source_set() + env = environment() + env.set('TARGETOS', targetos) + xml = custom_target('dbus-display preprocess', + input: 'dbus-display1.xml', + output: 'dbus-display1.xml', + env: env, + command: [xml_pp, '@INPUT@', '@OUTPUT@']) dbus_display1 = custom_target('dbus-display gdbus-codegen', output: ['dbus-display1.h', 'dbus-display1.c'], - input: files('dbus-display1.xml'), + input: xml, command: [gdbus_codegen, '@INPUT@', '--glib-min-required', '2.64', '--output-directory', meson.current_build_dir(),
Signature · 1 line
2.41.0
Re: [PULL 17/33] ui/dbus: win32 support
Am 27. Juni 2023 13:02:14 UTC schrieb [email protected]:
Quoted 67 lines
From: Marc-André Lureau <[email protected]>
D-Bus doesn't support fd-passing on Windows (
AF_UNIXdoesn't haveSCM_RIGHTSyet, but there are other means to share objects. I have proposed various solutions upstream, but none seem fitting enough atm).To make the "-display dbus" work on Windows, implement an alternative D-Bus interface where all the 'h' (FDs) arguments are replaced with 'ay' (WSASocketW data), and sockets are passed to the other end via
WSADuplicateSocket().Signed-off-by Marc-André Lureau <[email protected]>Message-Id: <[email protected]>
---meson.build | 4 +-- ui/dbus.h | 6 +++++ audio/dbusaudio.c | 44 +++++++++++++++++++++++++++------ ui/dbus-chardev.c | 22 +++++++++++++---- ui/dbus-console.c | 59 ++++++++++++++++++++++++++++++++++++++------ ui/dbus-display1.xml | 28 +++++++++++++++++++++ ui/meson.build | 9 ++++++- 7 files changed, 149 insertions(+), 23 deletions(-)meson.build +0
-0@@ -838,6 +838,8 @@ if gdbus_codegen.found() and get_option('cfi') gdbus_codegen_error = '@0@ uses gdbus-codegen, which does not support control flow integrity'endif
meson.build +2
-0+xml_pp = find_program('scripts/xml-preprocess.py') +lttng =
not_found
if 'ust' inget_option('trace_backends')
lttng = dependency('lttng-ust', required: true, version: '>= 2.1',meson.build +0
-2@@ -1985,8 +1987,6 @@ dbus_display = get_option('dbus_display') \ error_message: '-display dbus requires glib>=2.64') \ .require(gdbus_codegen.found(), error_message: gdbus_codegen_error.format('-display dbus')) \ - .require(targetos != 'windows', - error_message: '-display dbus is not available on Windows') \ .allowed() have_virtfs = get_option('virtfs') \ui/dbus.h +6
-0@@ -62,6 +62,12 @@ struct DBusDisplay {Notifier notifier; }; +#ifdef WIN32 +bool +dbus_win32_import_socket (GDBusMethodInvocation *invocation, +GVariant *arg_listener,int *socket); +#endif +#define TYPE_DBUS_DISPLAY "dbus-display"OBJECT_DECLARE_SIMPLE_TYPE (DBusDisplay,DBUS_DISPLAY )audio/dbusaudio.c +0
-0
audio/dbusaudio.c line 36
Quoted 4 lines
audio/dbusaudio.c +1
-0@@ -33,6 +33,7 @@#include <gio/gunixfdlist.h> #endif +#include "ui/dbus.h"
This patch causes below compile error since pixman.h isn't found. It seems as if the pixman include path is missing. Since pixman.h is found elsewhere in the same build I suspect that the DBUS audio module now needs a pixman dependency -- which sounds a little bit weired.
FAILED: libaudio-dbus.a.p/audio_dbusaudio.c.o
cc -m64 -mcx16 -Ilibaudio-dbus.a.p -I. -I../src -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/gio-unix-2.0 -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O0 -g -fstack-protector-strong -Wundef -Wwrite-strings -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wold-style-declaration -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wimplicit-fallthrough=2 -Wmissing-format-attribute -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-psabi -isystem qemu/src/linux-headers -isystem linux-headers -iquote . -iquote qemu/src -iquote qemu/src/include -iquote qemu/src/host/include/x86_64 -iquote qemu/src/host/include/generic -iquote qemu/src/tcg/i386 -Wno-unused-function -pthread -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-common -fwrapv -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -fPIC -DBUILD_DSO -MD -MQ libaudio-dbus.a.p/audio_dbusaudio.c.o -MF libaudio-dbus.a.p/audio_dbusaudio.c.o.d -o libaudio-dbus.a.p/audio_dbusaudio.c.o -c ../src/audio/dbusaudio.c In file included from qemu/src/include/ui/console.h:4,
from qemu/src/ui/dbus.h:31,
from ../src/audio/dbusaudio.c:36:
qemu/src/include/ui/qemu-pixman.h:12:10: fatal error: pixman.h: No such file or directory
12 | #include <pixman.h>
| ^~~~~~~~~~Best regards,
Bernhard
Quoted 431 lines
audio/dbusaudio.c +0
-1#include "ui/dbus-display1.h" #define AUDIO_CAP "dbus"@@ -422,7 +423,6 @@ dbus_audio_fini(void *opaque)g_free (da); } -#ifdef G_OS_UNIX static void listener_out_vanished_cb(GDBusConnection *connection,
gbooleanremote_peer_vanished,audio/dbusaudio.c +0
-0@@ -448,7 +448,9 @@ listener_in_vanished_cb(GDBusConnection *connection,static gboolean dbus_audio_register_listener(AudioState *s,
GDBusMethodInvocation *invocation,audio/dbusaudio.c +2
-0+#ifdef G_OS_UNIX GUnixFDList *fd_list, +#endif GVariant *arg_listener, bool out){
audio/dbusaudio.c +21
-2@@ -475,6 +477,11 @@ dbus_audio_register_listener(AudioState *s,return DBUS_METHOD_INVOCATION_HANDLED ; } +#ifdef G_OS_WIN32 +if (!dbus_win32_import_socket (invocation, arg_listener, &fd)) { +return DBUS_METHOD_INVOCATION_HANDLED ; + } +#else fd =g_unix_fd_list_get (fd_list,g_variant_get_handle (arg_listener), &err);if (err) { g_dbus_method_invocation_return_error(invocation,@@ -484,6 +491,7 @@ dbus_audio_register_listener(AudioState *s, err->message); return DBUS_METHOD_INVOCATION_HANDLED; } +#endif socket =g_socket_new_from_fd (fd, &err);if (err) {@@ -492,15 +500,28 @@ dbus_audio_register_listener(AudioState *s,DBUS_DISPLAY_ERROR_FAILED ,"Couldn't make a socket: %s" , err->message); +#ifdef G_OS_WIN32 +closesocket (fd); +#else +close (fd); +#endif return DBUS_METHOD_INVOCATION_HANDLED ; } socket_conn =g_socket_connection_factory_create_connection (socket);if (out) {qemu_dbus_display1_audio_complete_register_out_listener ( - da->iface, invocation,NULL ); + da->iface, invocation +#ifdef G_OS_UNIX + ,NULL +#endif + ); }else {qemu_dbus_display1_audio_complete_register_in_listener ( - da->iface, invocation,NULL ); + da->iface, invocation +#ifdef G_OS_UNIX + ,NULL +#endif + ); } listener_conn =@@ -578,24 +599,33 @@ dbus_audio_register_listener(AudioState *s,static gboolean dbus_audio_register_out_listener(AudioState *s,
GDBusMethodInvocation *invocation,audio/dbusaudio.c +2
-0+#ifdef G_OS_UNIX GUnixFDList *fd_list, +#endif GVariant *arg_listener){
return dbus_audio_register_listener(s, invocation,audio/dbusaudio.c +4
-1- fd_list, arg_listener, true); +#ifdef G_OS_UNIX + fd_list, +#endif + arg_listener, true);}
static gboolean dbus_audio_register_in_listener(AudioState *s,
GDBusMethodInvocation *invocation,audio/dbusaudio.c +2
-0+#ifdef G_OS_UNIX GUnixFDList *fd_list, +#endif GVariant *arg_listener){
return dbus_audio_register_listener(s, invocation,audio/dbusaudio.c +2
-2- fd_list, arg_listener, false); -} +#ifdef G_OS_UNIX + fd_list,#endif
audio/dbusaudio.c +2
-0+ arg_listener, false); +}static void
dbus_audio_set_server(AudioState *s, GDBusObjectManagerServer *server, bool p2p)audio/dbusaudio.c +0
-2@@ -610,14 +640,12 @@ dbus_audio_set_server(AudioState *s, GDBusObjectManagerServer *server, bool p2p) da->audio =g_dbus_object_skeleton_new (DBUS_DISPLAY1_AUDIO_PATH ); da->iface =qemu_dbus_display1_audio_skeleton_new (); -#ifdef G_OS_UNIX g_object_connect (da->iface,"swapped-signal::handle-register-in-listener" , dbus_audio_register_in_listener, s,"swapped-signal::handle-register-out-listener" , dbus_audio_register_out_listener, s,NULL ); -#endif g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (da->audio),G_DBUS_INTERFACE_SKELETON (da->iface));ui/dbus-chardev.c +0
-1@@ -110,18 +110,24 @@ dbus_chardev_init(DBusDisplay *dpy) dbus_display_chardev_foreach, dpy); } -#ifdef G_OS_UNIX static gboolean
dbus_chr_register(
DBusChardev *dc,
GDBusMethodInvocation *invocation,ui/dbus-chardev.c +2
-0+#ifdef G_OS_UNIX GUnixFDList *fd_list, +#endif GVariant *arg_stream, QemuDBusDisplay1Chardev *object){ g_autoptr(GError) err = NULL; int fd;ui/dbus-chardev.c +15
-2+#ifdef G_OS_WIN32 +if (!dbus_win32_import_socket (invocation, arg_stream, &fd)) { +return DBUS_METHOD_INVOCATION_HANDLED ; + } +#else fd =g_unix_fd_list_get (fd_list,g_variant_get_handle (arg_stream), &err);if (err) { g_dbus_method_invocation_return_error(@@ -131,13 +137,18 @@ dbus_chr_register( "Couldn't get peer FD: %s", err->message); return DBUS_METHOD_INVOCATION_HANDLED; } +#endif if (qemu_chr_add_client (CHARDEV (dc), fd) <0 ) {g_dbus_method_invocation_return_error (invocation,DBUS_DISPLAY_ERROR ,DBUS_DISPLAY_ERROR_FAILED ,"Couldn't register FD!" ); +#ifdef G_OS_WIN32 +closesocket (fd); +#else close (fd); +#endif return DBUS_METHOD_INVOCATION_HANDLED ; }@@ -145,10 +156,13 @@ dbus_chr_register("owner" ,g_dbus_method_invocation_get_sender (invocation), NULL); -qemu_dbus_display1_chardev_complete_register (object, invocation,NULL ); +qemu_dbus_display1_chardev_complete_register (object, invocation +#ifndef G_OS_WIN32 + ,NULL +#endif + );return DBUS_METHOD_INVOCATION_HANDLED ; } -#endif static gboolean
dbus_chr_send_break(ui/dbus-chardev.c +0
-2@@ -179,10 +193,8 @@ dbus_chr_open(Chardev *chr, ChardevBackend *backend, dc->iface =qemu_dbus_display1_chardev_skeleton_new ();g_object_set (dc->iface,"name" , backend->u.dbus.data->name,NULL );g_object_connect (dc->iface, -#ifdef G_OS_UNIX"swapped-signal::handle-register" , dbus_chr_register, dc, -#endif"swapped-signal::handle-send-break" , dbus_chr_send_break, dc,NULL );ui/dbus-console.c +0
-1@@ -165,7 +165,6 @@ dbus_display_console_class_init(DBusDisplayConsoleClass *klass) gobject_class->dispose = dbus_display_console_dispose; } -#ifdef G_OS_UNIX static void
listener_vanished_cb(DBusDisplayListener *listener){ui/dbus-console.c +0
-1@@ -177,7 +176,6 @@ listener_vanished_cb(DBusDisplayListener *listener)g_hash_table_remove (ddc->listeners, name);qkbd_state_lift_all_keys (ddc->kbd); } -#endif static gboolean
dbus_console_set_ui_info(DBusDisplayConsole *ddc,ui/dbus-console.c +35
-1@@ -211,11 +209,47 @@ dbus_console_set_ui_info(DBusDisplayConsole *ddc,return DBUS_METHOD_INVOCATION_HANDLED ; } -#ifdef G_OS_UNIX +#ifdef G_OS_WIN32 +bool +dbus_win32_import_socket (GDBusMethodInvocation *invocation, +GVariant *arg_listener,int *socket) +{ +gsize n; +WSAPROTOCOL_INFOW *info = (void *)g_variant_get_fixed_array (arg_listener, &n,1 ); + +if (!info || n !=sizeof (*info)) { +g_dbus_method_invocation_return_error ( + invocation, +DBUS_DISPLAY_ERROR , +DBUS_DISPLAY_ERROR_FAILED , +"Failed to get socket infos" ); +return false; + } + + *socket =WSASocketW (FROM_PROTOCOL_INFO , +FROM_PROTOCOL_INFO , +FROM_PROTOCOL_INFO , + info,0 ,0 ); +if (*socket ==INVALID_SOCKET ) { + g_autofree gchar *emsg = g_win32_error_message(WSAGetLastError()); +g_dbus_method_invocation_return_error ( + invocation, +DBUS_DISPLAY_ERROR , +DBUS_DISPLAY_ERROR_FAILED , +"Couldn't create socket: %s" , emsg); +return false; + } + +return true; +} +#endif +static gboolean dbus_console_register_listener(DBusDisplayConsole *ddc,
GDBusMethodInvocation *invocation,ui/dbus-console.c +2
-0+#ifdef G_OS_UNIX GUnixFDList *fd_list, +#endif GVariant *arg_listener){ const char *sender = g_dbus_method_invocation_get_sender(invocation);ui/dbus-console.c +15
-2@@ -237,6 +271,11 @@ dbus_console_register_listener(DBusDisplayConsole *ddc,return DBUS_METHOD_INVOCATION_HANDLED ; } +#ifdef G_OS_WIN32 +if (!dbus_win32_import_socket (invocation, arg_listener, &fd)) { +return DBUS_METHOD_INVOCATION_HANDLED ; + } +#else fd =g_unix_fd_list_get (fd_list,g_variant_get_handle (arg_listener), &err);if (err) { g_dbus_method_invocation_return_error(@@ -246,6 +285,7 @@ dbus_console_register_listener(DBusDisplayConsole *ddc, "Couldn't get peer fd: %s", err->message); return DBUS_METHOD_INVOCATION_HANDLED; } +#endif socket =g_socket_new_from_fd (fd, &err);if (err) {@@ -254,13 +294,21 @@ dbus_console_register_listener(DBusDisplayConsole *ddc,DBUS_DISPLAY_ERROR ,DBUS_DISPLAY_ERROR_FAILED , "Couldn't make a socket: %s", err->message); +#ifdef G_OS_WIN32 +closesocket (fd); +#else close (fd); +#endif return DBUS_METHOD_INVOCATION_HANDLED ; } socket_conn =g_socket_connection_factory_create_connection (socket);qemu_dbus_display1_console_complete_register_listener ( - ddc->iface, invocation,NULL ); + ddc->iface, invocation +#ifdef G_OS_UNIX + ,NULL +#endif + ); listener_conn = g_dbus_connection_new_sync( G_IO_STREAM(socket_conn),@@ -287,7 +335,6 @@ dbus_console_register_listener(DBusDisplayConsole *ddc,trace_dbus_registered_listener (sender);return DBUS_METHOD_INVOCATION_HANDLED ; } -#endif static gboolean
dbus_kbd_press(DBusDisplayConsole *ddc,ui/dbus-console.c +0
-2@@ -516,10 +563,8 @@ dbus_display_console_new(DBusDisplay *display, QemuConsole *con)"device-address" , device_addr, NULL);g_object_connect (ddc->iface, -#ifdef G_OS_UNIX"swapped-signal::handle-register-listener" , dbus_console_register_listener, ddc, -#endif"swapped-signal::handle-set-uiinfo" , dbus_console_set_ui_info, ddc,NULL );ui/dbus-display1.xml +28
-0@@ -57,7 +57,13 @@ :dbus:iface:`org.qemu.Display1.Listener` interface. --> <method name="RegisterListener"> + <?if $(env.TARGETOS) == windows?> + <arg type="ay" name="listener" direction="in"> + <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/> + </arg> + <?else?> <arg type="h" name="listener" direction="in"/> + <?endif?> </method> <!--@@ -334,6 +340,9 @@ </arg> </method> + <?if $(env.TARGETOS) == windows?> + <!-- Add shared memory/texture support --> + <?else?> <!-- ScanoutDMABUF: @dmabuf: the DMABUF file descriptor.@@ -372,6 +381,7 @@ <arg type="i" name="width" direction="in"/> <arg type="i" name="height" direction="in"/> </method> + <?endif?> <!-- Disable:@@ -532,7 +542,13 @@ :dbus:iface:`org.qemu.Display1.AudioOutListener` interface. --> <method name="RegisterOutListener"> + <?if $(env.TARGETOS) == windows?> + <arg type="ay" name="listener" direction="in"> + <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/> + </arg> + <?else?> <arg type="h" name="listener" direction="in"/> + <?endif?> </method> <!--@@ -547,7 +563,13 @@ :dbus:iface:`org.qemu.Display1.AudioInListener` interface. --> <method name="RegisterInListener"> + <?if $(env.TARGETOS) == windows?> + <arg type="ay" name="listener" direction="in"> + <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/> + </arg> + <?else?> <arg type="h" name="listener" direction="in"/> + <?endif?> </method> </interface>@@ -760,7 +782,13 @@ The current handler, if any, will be replaced. --> <method name="Register"> + <?if $(env.TARGETOS) == windows?> + <arg type="ay" name="listener" direction="in"> + <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/> + </arg> + <?else?> <arg type="h" name="stream" direction="in"/> + <?endif?> </method> <!--ui/meson.build +0
-0@@ -74,9 +74,16 @@ endifif
dbus_display
dbus_ss=ss.source_set()ui/meson.build +8
-1+ env = environment() + env.set('TARGETOS', targetos) + xml = custom_target('dbus-display preprocess', + input: 'dbus-display1.xml', + output: 'dbus-display1.xml', + env: env, + command: [xml_pp, '@INPUT@', '@OUTPUT@']) dbus_display1 = custom_target('dbus-display gdbus-codegen', output: ['dbus-display1.h', 'dbus-display1.c'], - input: files('dbus-display1.xml'), + input: xml, command: [gdbus_codegen, '@INPUT@', '--glib-min-required', '2.64', '--output-directory', meson.current_build_dir(),
Re: [PULL 17/33] ui/dbus: win32 support
Hi
Quoted 104 lines · Bernhard Beschow
Am 27. Juni 2023 13:02:14 UTC schrieb [email protected]:
Quoted 28 lines
From: Marc-André Lureau <[email protected]>
D-Bus doesn't support fd-passing on Windows (
AF_UNIXdoesn't haveSCM_RIGHTSyet, but there are other means to share objects. I have proposed various solutions upstream, but none seem fitting enough atm).To make the "-display dbus" work on Windows, implement an alternative D-Bus interface where all the 'h' (FDs) arguments are replaced with 'ay' (WSASocketW data), and sockets are passed to the other end via
WSADuplicateSocket().Signed-off-by Marc-André Lureau <[email protected]>Message-Id: <[email protected]>
---meson.build | 4 +-- ui/dbus.h | 6 +++++ audio/dbusaudio.c | 44 +++++++++++++++++++++++++++------ ui/dbus-chardev.c | 22 +++++++++++++---- ui/dbus-console.c | 59 ++++++++++++++++++++++++++++++++++++++------ ui/dbus-display1.xml | 28 +++++++++++++++++++++ ui/meson.build | 9 ++++++- 7 files changed, 149 insertions(+), 23 deletions(-)meson.build +0
-0meson.build if gdbus_codegen.found() and get_option('cfi') · line 838
Quoted 1 line
meson.build +0
-0@@ -838,6 +838,8 @@ if gdbus_codegen.found() and get_option('cfi') gdbus_codegen_error = '@0@ uses gdbus-codegen, which does not supportcontrol flow integrity'
Quoted 38 lines
endif
meson.build +2
-0+xml_pp = find_program('scripts/xml-preprocess.py') +lttng =
not_found
if 'ust' inget_option('trace_backends')
lttng = dependency('lttng-ust', required: true, version: '>= 2.1',meson.build +0
-2@@ -1985,8 +1987,6 @@ dbus_display = get_option('dbus_display') \ error_message: '-display dbus requires glib>=2.64') \ .require(gdbus_codegen.found(), error_message: gdbus_codegen_error.format('-display dbus')) \ - .require(targetos != 'windows', - error_message: '-display dbus is not available on Windows') \ .allowed() have_virtfs = get_option('virtfs') \ui/dbus.h +6
-0@@ -62,6 +62,12 @@ struct DBusDisplay {Notifier notifier; }; +#ifdef WIN32 +bool +dbus_win32_import_socket (GDBusMethodInvocation *invocation, +GVariant *arg_listener,int *socket); +#endif +#define TYPE_DBUS_DISPLAY "dbus-display"OBJECT_DECLARE_SIMPLE_TYPE (DBusDisplay,DBUS_DISPLAY )audio/dbusaudio.c +0
-0audio/dbusaudio.c line 36
Quoted 4 lines
audio/dbusaudio.c +1
-0@@ -33,6 +33,7 @@#include <gio/gunixfdlist.h> #endif +#include "ui/dbus.h" This patch causes below compile error since
pixman.hisn't found. It seems as if the pixman include path is missing. Sincepixman.his found elsewhere in the same build I suspect that the DBUS audio module now needs a pixman dependency -- which sounds a little bit weired.FAILED:
libaudio-dbus.a.p/audio_dbusaudio.c.o
cc -m64 -mcx16 -Ilibaudio-dbus.a.p -I. -I../src -Iqapi -Itrace -Iui(quoted diff) +0
-10-Iui/shader -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/gio-unix-2.0 -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O0 -g -fstack-protector-strong -Wundef -Wwrite-strings -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wold-style-declaration -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wimplicit-fallthrough=2 -Wmissing-format-attribute -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-psabi -isystemqemu/src/linux-headers -isystem linux-headers -iquote . -iquote qemu/src -iquote qemu/src/include -iquote qemu/src/host/include/x86_64 -iquote qemu/src/host/include/generic -iquote qemu/src/tcg/i386
(quoted diff) +0
-5-Wno-unused-function -pthread -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-common -fwrapv -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -fPIC -DBUILD_DSO -MD -MQ libaudio-dbus.a.p/audio_dbusaudio.c.o -MFlibaudio-dbus.a.p/audio_dbusaudio.c.o.d -o
libaudio-dbus.a.p/audio_dbusaudio.c.o-c../src/audio/dbusaudio.cIn file included fromqemu/src/include/ui/console.h:4,
Quoted 8 lines
from qemu/src/ui/dbus.h:31,
from ../src/audio/dbusaudio.c:36:
qemu/src/include/ui/qemu-pixman.h:12:10: fatal error: pixman.h: No such
file or directory
12 | #include <pixman.h>
| ^~~~~~~~~~This is reported here:
https://gitlab.com/qemu-project/qemu/-/issues/1739
I am going to send the patch.
Re: [PULL 17/33] ui/dbus: win32 support
Quoted 128 lines · Marc-André Lureau
Hi
On Thu, Jun 29, 2023 at 7:55 PM Bernhard Beschow <[email protected] <mailto:[email protected]>> wrote:
Am 27. Juni 2023 13:02:14 UTC schrieb [email protected] <mailto:[email protected]>: >From: Marc-André Lureau <[email protected] <mailto:[email protected]>> > >D-Bus doesn't support fd-passing on Windows (AF_UNIX doesn't have >SCM_RIGHTS yet, but there are other means to share objects. I have >proposed various solutions upstream, but none seem fitting enough atm). > >To make the "-display dbus" work on Windows, implement an alternative >D-Bus interface where all the 'h' (FDs) arguments are replaced with >'ay' (WSASocketW data), and sockets are passed to the other end via >WSADuplicateSocket(). > >Signed-off-by: Marc-André Lureau <[email protected] <mailto:[email protected]>> >Message-Id: <[email protected] <mailto:[email protected]>> >--- > meson.build | 4 +-- > ui/dbus.h | 6 +++++ > audio/dbusaudio.c | 44 +++++++++++++++++++++++++++------ > ui/dbus-chardev.c | 22 +++++++++++++---- > ui/dbus-console.c | 59 ++++++++++++++++++++++++++++++++++++++------ > ui/dbus-display1.xml | 28 +++++++++++++++++++++ > ui/meson.build | 9 ++++++- > 7 files changed, 149 insertions(+), 23 deletions(-) > >diff --git a/meson.build b/meson.build >index b409788832..9a1ce43471 100644 >--- a/meson.build >+++ b/meson.build >@@ -838,6 +838,8 @@ if gdbus_codegen.found() and get_option('cfi') > gdbus_codegen_error = '@0@ uses gdbus-codegen, which does not support control flow integrity' > endif > >+xml_pp = find_program('scripts/xml-preprocess.py') >+ > lttng = not_found > if 'ust' in get_option('trace_backends') > lttng = dependency('lttng-ust', required: true, version: '>= 2.1', >@@ -1985,8 +1987,6 @@ dbus_display = get_option('dbus_display') \ > error_message: '-display dbus requires glib>=2.64') \ > .require(gdbus_codegen.found(), > error_message: gdbus_codegen_error.format('-display dbus')) \ >- .require(targetos != 'windows', >- error_message: '-display dbus is not available on Windows') \ > .allowed() > > have_virtfs = get_option('virtfs') \ >diff --git a/ui/dbus.h b/ui/dbus.h >index 9c149e7b41..1e8c24a48e 100644 >--- a/ui/dbus.h >+++ b/ui/dbus.h >@@ -62,6 +62,12 @@ struct DBusDisplay { > Notifier notifier; > }; > >+#ifdef WIN32 >+bool >+dbus_win32_import_socket(GDBusMethodInvocation *invocation, >+ GVariant *arg_listener, int *socket); >+#endif >+ > #define TYPE_DBUS_DISPLAY "dbus-display" > OBJECT_DECLARE_SIMPLE_TYPE(DBusDisplay, DBUS_DISPLAY) > >diff --git a/audio/dbusaudio.c b/audio/dbusaudio.c >index de59467d9e..7a11fbfb42 100644 >--- a/audio/dbusaudio.c >+++ b/audio/dbusaudio.c >@@ -33,6 +33,7 @@ > #include <gio/gunixfdlist.h> > #endif > >+#include "ui/dbus.h" This patch causes below compile error since pixman.h isn't found. It seems as if the pixman include path is missing. Since pixman.h is found elsewhere in the same build I suspect that the DBUS audio module now needs a pixman dependency -- which sounds a little bit weired. FAILED: libaudio-dbus.a.p/audio_dbusaudio.c.o cc -m64 -mcx16 -Ilibaudio-dbus.a.p -I. -I../src -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/gio-unix-2.0 -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O0 -g -fstack-protector-strong -Wundef -Wwrite-strings -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wold-style-declaration -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wimplicit-fallthrough=2 -Wmissing-format-attribute -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-psabi -isystem qemu/src/linux-headers -isystem linux-headers -iquote . -iquote qemu/src -iquote qemu/src/include -iquote qemu/src/host/include/x86_64 -iquote qemu/src/host/include/generic -iquote qemu/src/tcg/i386 -Wno-unused-function -pthread -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-common -fwrapv -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -fPIC -DBUILD_DSO -MD -MQ libaudio-dbus.a.p/audio_dbusaudio.c.o -MF libaudio-dbus.a.p/audio_dbusaudio.c.o.d -o libaudio-dbus.a.p/audio_dbusaudio.c.o -c ../src/audio/dbusaudio.c In file included from qemu/src/include/ui/console.h:4, from qemu/src/ui/dbus.h:31, from ../src/audio/dbusaudio.c:36: qemu/src/include/ui/qemu-pixman.h:12:10: fatal error: pixman.h: No such file or directory 12 | #include <pixman.h> | ^~~~~~~~~~
Quoted 4 lines
This is reported here:
https://gitlab.com/qemu-project/qemu/-/issues/1739 <https://gitlab.com/qemu-project/qemu/-/issues/1739>I am going to send the patch.
I just send a patch fixing this error, see:
https://lore.kernel.org/qemu-devel/[email protected]/
[PULL 08/33] virtio-gpu: Make non-gl display updates work again when blob=true
In reply to [email protected]From: Vivek Kasireddy <[email protected]>
In the case where the console does not have gl capability, and if blob is set to true, make sure that the display updates still work. Commit e86a93f55463 accidentally broke this by misplacing the return statement (in resource_flush) causing the updates to be silently ignored.
Message-ID: <[email protected]>
--- hw/display/virtio-gpu.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)
hw/display/virtio-gpu.c +22 -5
@@ -498,6 +498,8 @@ static void virtio_gpu_resource_flush(VirtIOGPU *g,struct virtio_gpu_resource_flush rf;struct virtio_gpu_scanout *scanout;pixman_region16_t flush_region; +bool within_bounds = false; +bool update_submitted = false;int i;VIRTIO_GPU_FILL_CMD (rf);
@@ -518,13 +520,28 @@ static void virtio_gpu_resource_flush(VirtIOGPU *g, rf.r.x < scanout->x + scanout->width && rf.r.x + rf.r.width >= scanout->x && rf.r.y < scanout->y + scanout->height && - rf.r.y + rf.r.height >= scanout->y && - console_has_gl(scanout->con)) { -dpy_gl_update (scanout->con,0 ,0 , scanout->width, - scanout->height); + rf.r.y + rf.r.height >= scanout->y) { + within_bounds = true; + +if (console_has_gl (scanout->con)) { +dpy_gl_update (scanout->con,0 ,0 , scanout->width, + scanout->height); + update_submitted = true; + } } } -return ; + +if (update_submitted) { +return ; + } +if (!within_bounds) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: flush bounds outside scanouts" +" bounds for flush %d: %d %d %d %d\n" , + __func__, rf.resource_id, rf.r.x, rf.r.y, + rf.r.width, rf.r.height); + cmd->error =VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER ; +return ; + } } if (!res->blob &&
Signature · 1 line
2.41.0
[PULL 11/33] virtio-gpu: OUT_OF_MEMORY if failing to create udmabuf
In reply to [email protected]From: Dongwon Kim <[email protected]>
Respond with VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY if it fails to create an udmabuf for the blob resource.
v2: consolidated return statments and removed an unnecessary style change
Message-ID: <[email protected]>
--- hw/display/virtio-gpu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/display/virtio-gpu.c +3 -1
@@ -651,8 +651,10 @@ static void virtio_gpu_do_set_scanout(VirtIOGPU *g,if (console_has_gl (scanout->con)) {if (!virtio_gpu_update_dmabuf (g, scanout_id, res, fb, r)) {virtio_gpu_update_scanout (g, scanout_id, res, r); -return ; + }else { + *error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; } +return ; } data = res->blob;
Signature · 1 line
2.41.0
[PULL 19/33] tests: make dbus-display-test work on win32
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Message-Id: <[email protected]>
--- tests/qtest/dbus-display-test.c | 43 ++++++++++++++++++++++++++++++--- tests/qtest/meson.build | 2 +- 2 files changed, 41 insertions(+), 4 deletions(-)
tests/qtest/dbus-display-test.c +40 -3
@@ -1,4 +1,5 @@#include "qemu/osdep.h" +#include "qemu/sockets.h" #include "qemu/dbus.h" #include "qemu/sockets.h" #include <gio/gio.h>
@@ -14,7 +15,11 @@ test_dbus_p2p_from_fd(int fd)g_autoptr (GSocketConnection) socketc =NULL ;GDBusConnection *conn; +#ifdef WIN32 + socket =g_socket_new_from_fd (_get_osfhandle (fd), &err); +#else socket =g_socket_new_from_fd (fd, &err); +#endif g_assert_no_error (err); socketc =g_socket_connection_factory_create_connection (socket);
@@ -126,7 +131,10 @@ test_dbus_console_registered(GObject *source_object, qemu_dbus_display1_console_call_register_listener_finish( QEMU_DBUS_DISPLAY1_CONSOLE(source_object), -NULL , res, &err); +#ifndef WIN32 +NULL , +#endif + res, &err);g_assert_no_error (err); test->listener_conn =g_thread_join (test->thread);
@@ -145,17 +153,25 @@ test_dbus_display_console(void)g_autoptr (GError) err =NULL ;g_autoptr (GDBusConnection) conn =NULL ;g_autoptr (QemuDBusDisplay1ConsoleProxy) console =NULL ; -g_autoptr (GUnixFDList) fd_list =NULL ;g_autoptr (GMainLoop) loop =NULL ;QTestState *qts =NULL ; -int pair[2 ], idx; +int pair[2 ];TestDBusConsoleRegister test; +#ifdef WIN32 +WSAPROTOCOL_INFOW info; +g_autoptr (GVariant) listener =NULL ; +#else +g_autoptr (GUnixFDList) fd_list =NULL ; +int idx; +#endif test_setup (&qts, &conn); g_assert_cmpint(qemu_socketpair(AF_UNIX, SOCK_STREAM, 0, pair), ==, 0); +#ifndef WIN32 fd_list =g_unix_fd_list_new (); idx =g_unix_fd_list_append (fd_list, pair[1 ],NULL ); +#endif console = QEMU_DBUS_DISPLAY1_CONSOLE_PROXY( qemu_dbus_display1_console_proxy_new_sync(
@@ -171,12 +187,33 @@ test_dbus_display_console(void) test.thread =g_thread_new (NULL , test_dbus_p2p_server_setup_thread,GINT_TO_POINTER (pair[0 ])); +#ifdef WIN32 +if (WSADuplicateSocketW (_get_osfhandle (pair[1 ]), +GetProcessId ((HANDLE )qtest_pid (qts)), + &info) ==SOCKET_ERROR ) + { + g_autofree char *emsg = g_win32_error_message(WSAGetLastError()); +g_error ("WSADuplicateSocket failed: %s" , emsg); + } +close (pair[1 ]); + listener =g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE , + &info, +sizeof (info), +1 ); +#endif + qemu_dbus_display1_console_call_register_listener( QEMU_DBUS_DISPLAY1_CONSOLE(console), +#ifdef WIN32 + listener, +#elseg_variant_new_handle (idx), +#endifG_DBUS_CALL_FLAGS_NONE ,-1 , +#ifndef WIN32 fd_list, +#endifNULL , test_dbus_console_registered, &test);
tests/qtest/meson.build +1 -1
@@ -104,7 +104,7 @@ qtests_i386 = \ 'numa-test' ] -if dbus_display and targetos != 'windows' +if dbus_display qtests_i386 += ['dbus-display-test'] endif
Signature · 1 line
2.41.0
[PULL 28/33] ui/dbus: add some GL traces
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Message-Id: <[email protected]>
--- ui/dbus-listener.c | 6 ++++++ ui/trace-events | 3 +++ 2 files changed, 9 insertions(+)
ui/dbus-listener.c +6 -0
@@ -102,6 +102,8 @@ static void dbus_call_update_gl(DisplayChangeListener *dcl, {DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); +trace_dbus_update_gl (x, y, w, h); +glFlush ();#ifdef CONFIG_GBM graphic_hw_gl_block (ddl->dcl.con, true);
@@ -212,6 +214,8 @@ static void dbus_scanout_texture(DisplayChangeListener *dcl, uint32_t x, uint32_t y, uint32_t w, uint32_t h) { +trace_dbus_scanout_texture (tex_id ,backing_y_0_top , +backing_width ,backing_height ,x ,y ,w ,h );#ifdef CONFIG_GBM QemuDmaBuf dmabuf = { .width = backing_width,
@@ -421,6 +425,8 @@ static void dbus_gl_gfx_switch(DisplayChangeListener *dcl, {DBusDisplayListener *ddl =container_of (dcl, DBusDisplayListener, dcl); +trace_dbus_gl_gfx_switch (new_surface); + ddl->ds = new_surface;if (ddl->ds) {int width =surface_width (ddl->ds);
ui/trace-events +3 -0
@@ -156,6 +156,9 @@ dbus_mouse_set_pos(unsigned int x, unsigned int y) "x=%u, y=%u" dbus_mouse_rel_motion(int dx, int dy) "dx=%d, dy=%d" dbus_touch_send_event(unsigned int kind, uint32_t num_slot, uint32_t x, uint32_t y) "kind=%u, num_slot=%u, x=%d, y=%d" dbus_update(int x, int y, int w, int h) "x=%d, y=%d, w=%d, h=%d" +dbus_update_gl(int x, int y, int w, int h) "x=%d, y=%d, w=%d, h=%d" dbus_clipboard_grab_failed(void) "" dbus_clipboard_register(const char *bus_name) "peer %s" dbus_clipboard_unregister(const char *bus_name) "peer %s" +dbus_scanout_texture(uint32_t tex_id, bool backing_y_0_top, uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, uint32_t w, uint32_t h) "tex_id:%u y0top:%d back:%ux%u %u+%u-%ux%u" +dbus_gl_gfx_switch(void *p) "surf: %p"
Signature · 1 line
2.41.0