Skip to content

Commit

Permalink
Merge tag 'ui-pull-request' of https://gitlab.com/marcandre.lureau/qemu
Browse files Browse the repository at this point in the history
… into staging

UI: small fixes and improvements

# -----BEGIN PGP SIGNATURE-----
#
# iQJQBAABCAA6FiEEh6m9kz+HxgbSdvYt2ujhCXWWnOUFAmZDZEAcHG1hcmNhbmRy
# ZS5sdXJlYXVAcmVkaGF0LmNvbQAKCRDa6OEJdZac5UxvD/9HWbB8JdbV8lNCLePT
# a6RUWSqLyP/cV0FCw9URYgAjAYROO966dZopCH7+Sz6goC8tk3IFUoqL0LbtZQjK
# zMNueGRbwJj0iGMxFG4wuWBpBF6Dzc4sh90TF3XWSE8PMpWsDY+sP3VRu4sP1qu7
# OmCGTuSwNUugxazPLxvbTpLMnco9b+asAGlAU6WqpcURmia7XN7dBLGzfQ9vMxuc
# L5od+pPGfcxuj3ETMG+5OQlIZH1lmX3465LajkUDVxffNfznqMVDYyo4sKNW5KOY
# u420AoACeVsANWce1Aw2ekj1ETsvqxj23RClNIgdpDbMsGk9eM6eS+6vRctcM6z4
# wMH6GAKKI3AWj7Q6qY4096bcdNmYD/GOs9dgswqYjf+JLzEVcI1dHQ36K124nKH0
# t+9t3UUx1NBMwAp+EEN94W1ClwOZ0zvapS8zNaf76KIi9Eb4vrIyOlzdTM7SU4kC
# CQ4Tu9MBB5WIqzhsVtIH36zDBasgAU8DCtpelDY1AJiODGiQbfZi4yo8eEiQMS1s
# onixsXa7zyCCpmxwkYmvF54RbZFlPXxmdvu0jYxKddbEuTGX/Y3qvDAWv1kz6iJS
# iGmYtokfkv86XBCTGTAb3QEmFfOWcLnPc59Gg0TF3zyzY3q05nU/qjuIlgYedR/o
# TnnNYbyqXumojRCd69Dyy3THEg==
# =SW9v
# -----END PGP SIGNATURE-----
# gpg: Signature made Tue 14 May 2024 03:16:48 PM CEST
# gpg:                using RSA key 87A9BD933F87C606D276F62DDAE8E10975969CE5
# gpg:                issuer "marcandre.lureau@redhat.com"
# gpg: Good signature from "Marc-André Lureau <marcandre.lureau@redhat.com>" [full]
# gpg:                 aka "Marc-André Lureau <marcandre.lureau@gmail.com>" [full]

* tag 'ui-pull-request' of https://gitlab.com/marcandre.lureau/qemu:
  ui/sdl2: Allow host to power down screen
  ui/gtk: Fix mouse/motion event scaling issue with GTK display backend
  ui/gtk: Add gd_motion_event trace event
  ui/console: move QemuDmaBuf struct def to dmabuf.c
  ui/console: Use qemu_dmabuf_new() and free() helpers instead
  ui/console: Use qemu_dmabuf_set_..() helpers instead
  ui/console: Use qemu_dmabuf_get_..() helpers instead
  ui/console: new dmabuf.h and dmabuf.c for QemuDmaBuf struct and helpers
  ui/gtk: Check if fence_fd is equal to or greater than 0
  ui/gtk: Draw guest frame at refresh cycle
  Allow UNIX socket option for VNC websocket

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed May 15, 2024
2 parents 3d48b6b + 2e701e6 commit 265aad5
Show file tree
Hide file tree
Showing 22 changed files with 547 additions and 203 deletions.
32 changes: 18 additions & 14 deletions hw/display/vhost-user-gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUserGpuMsg *msg)
case VHOST_USER_GPU_DMABUF_SCANOUT: {
VhostUserGpuDMABUFScanout *m = &msg->payload.dmabuf_scanout;
int fd = qemu_chr_fe_get_msgfd(&g->vhost_chr);
uint64_t modifier = 0;
QemuDmaBuf *dmabuf;

if (m->scanout_id >= g->parent_obj.conf.max_outputs) {
Expand All @@ -261,30 +262,33 @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUserGpuMsg *msg)

g->parent_obj.enable = 1;
con = g->parent_obj.scanout[m->scanout_id].con;
dmabuf = &g->dmabuf[m->scanout_id];
if (dmabuf->fd >= 0) {
close(dmabuf->fd);
dmabuf->fd = -1;
dmabuf = g->dmabuf[m->scanout_id];

if (dmabuf) {
qemu_dmabuf_close(dmabuf);
dpy_gl_release_dmabuf(con, dmabuf);
g_clear_pointer(&dmabuf, qemu_dmabuf_free);
}
dpy_gl_release_dmabuf(con, dmabuf);

if (fd == -1) {
dpy_gl_scanout_disable(con);
g->dmabuf[m->scanout_id] = NULL;
break;
}
*dmabuf = (QemuDmaBuf) {
.fd = fd,
.width = m->fd_width,
.height = m->fd_height,
.stride = m->fd_stride,
.fourcc = m->fd_drm_fourcc,
.y0_top = m->fd_flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP,
};

if (msg->request == VHOST_USER_GPU_DMABUF_SCANOUT2) {
VhostUserGpuDMABUFScanout2 *m2 = &msg->payload.dmabuf_scanout2;
dmabuf->modifier = m2->modifier;
modifier = m2->modifier;
}

dmabuf = qemu_dmabuf_new(m->fd_width, m->fd_height,
m->fd_stride, 0, 0, 0, 0,
m->fd_drm_fourcc, modifier,
fd, false, m->fd_flags &
VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP);

dpy_gl_scanout_dmabuf(con, dmabuf);
g->dmabuf[m->scanout_id] = dmabuf;
break;
}
case VHOST_USER_GPU_DMABUF_UPDATE: {
Expand Down
27 changes: 11 additions & 16 deletions hw/display/virtio-gpu-udmabuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ static void virtio_gpu_free_dmabuf(VirtIOGPU *g, VGPUDMABuf *dmabuf)
struct virtio_gpu_scanout *scanout;

scanout = &g->parent_obj.scanout[dmabuf->scanout_id];
dpy_gl_release_dmabuf(scanout->con, &dmabuf->buf);
dpy_gl_release_dmabuf(scanout->con, dmabuf->buf);
g_clear_pointer(&dmabuf->buf, qemu_dmabuf_free);
QTAILQ_REMOVE(&g->dmabuf.bufs, dmabuf, next);
g_free(dmabuf);
}
Expand All @@ -181,17 +182,10 @@ static VGPUDMABuf
}

dmabuf = g_new0(VGPUDMABuf, 1);
dmabuf->buf.width = r->width;
dmabuf->buf.height = r->height;
dmabuf->buf.stride = fb->stride;
dmabuf->buf.x = r->x;
dmabuf->buf.y = r->y;
dmabuf->buf.backing_width = fb->width;
dmabuf->buf.backing_height = fb->height;
dmabuf->buf.fourcc = qemu_pixman_to_drm_format(fb->format);
dmabuf->buf.fd = res->dmabuf_fd;
dmabuf->buf.allow_fences = true;
dmabuf->buf.draw_submitted = false;
dmabuf->buf = qemu_dmabuf_new(r->width, r->height, fb->stride,
r->x, r->y, fb->width, fb->height,
qemu_pixman_to_drm_format(fb->format),
0, res->dmabuf_fd, true, false);
dmabuf->scanout_id = scanout_id;
QTAILQ_INSERT_HEAD(&g->dmabuf.bufs, dmabuf, next);

Expand All @@ -206,6 +200,7 @@ int virtio_gpu_update_dmabuf(VirtIOGPU *g,
{
struct virtio_gpu_scanout *scanout = &g->parent_obj.scanout[scanout_id];
VGPUDMABuf *new_primary, *old_primary = NULL;
uint32_t width, height;

new_primary = virtio_gpu_create_dmabuf(g, scanout_id, res, fb, r);
if (!new_primary) {
Expand All @@ -216,11 +211,11 @@ int virtio_gpu_update_dmabuf(VirtIOGPU *g,
old_primary = g->dmabuf.primary[scanout_id];
}

width = qemu_dmabuf_get_width(new_primary->buf);
height = qemu_dmabuf_get_height(new_primary->buf);
g->dmabuf.primary[scanout_id] = new_primary;
qemu_console_resize(scanout->con,
new_primary->buf.width,
new_primary->buf.height);
dpy_gl_scanout_dmabuf(scanout->con, &new_primary->buf);
qemu_console_resize(scanout->con, width, height);
dpy_gl_scanout_dmabuf(scanout->con, new_primary->buf);

if (old_primary) {
virtio_gpu_free_dmabuf(g, old_primary);
Expand Down
32 changes: 17 additions & 15 deletions hw/vfio/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,11 @@ static VFIODMABuf *vfio_display_get_dmabuf(VFIOPCIDevice *vdev,

dmabuf = g_new0(VFIODMABuf, 1);
dmabuf->dmabuf_id = plane.dmabuf_id;
dmabuf->buf.width = plane.width;
dmabuf->buf.height = plane.height;
dmabuf->buf.backing_width = plane.width;
dmabuf->buf.backing_height = plane.height;
dmabuf->buf.stride = plane.stride;
dmabuf->buf.fourcc = plane.drm_format;
dmabuf->buf.modifier = plane.drm_format_mod;
dmabuf->buf.fd = fd;
dmabuf->buf = qemu_dmabuf_new(plane.width, plane.height,
plane.stride, 0, 0, plane.width,
plane.height, plane.drm_format,
plane.drm_format_mod, fd, false, false);

if (plane_type == DRM_PLANE_TYPE_CURSOR) {
vfio_display_update_cursor(dmabuf, &plane);
}
Expand All @@ -260,8 +257,10 @@ static VFIODMABuf *vfio_display_get_dmabuf(VFIOPCIDevice *vdev,
static void vfio_display_free_one_dmabuf(VFIODisplay *dpy, VFIODMABuf *dmabuf)
{
QTAILQ_REMOVE(&dpy->dmabuf.bufs, dmabuf, next);
dpy_gl_release_dmabuf(dpy->con, &dmabuf->buf);
close(dmabuf->buf.fd);

qemu_dmabuf_close(dmabuf->buf);
dpy_gl_release_dmabuf(dpy->con, dmabuf->buf);
g_clear_pointer(&dmabuf->buf, qemu_dmabuf_free);
g_free(dmabuf);
}

Expand All @@ -286,6 +285,7 @@ static void vfio_display_dmabuf_update(void *opaque)
VFIOPCIDevice *vdev = opaque;
VFIODisplay *dpy = vdev->dpy;
VFIODMABuf *primary, *cursor;
uint32_t width, height;
bool free_bufs = false, new_cursor = false;

primary = vfio_display_get_dmabuf(vdev, DRM_PLANE_TYPE_PRIMARY);
Expand All @@ -296,11 +296,13 @@ static void vfio_display_dmabuf_update(void *opaque)
return;
}

width = qemu_dmabuf_get_width(primary->buf);
height = qemu_dmabuf_get_height(primary->buf);

if (dpy->dmabuf.primary != primary) {
dpy->dmabuf.primary = primary;
qemu_console_resize(dpy->con,
primary->buf.width, primary->buf.height);
dpy_gl_scanout_dmabuf(dpy->con, &primary->buf);
qemu_console_resize(dpy->con, width, height);
dpy_gl_scanout_dmabuf(dpy->con, primary->buf);
free_bufs = true;
}

Expand All @@ -314,7 +316,7 @@ static void vfio_display_dmabuf_update(void *opaque)
if (cursor && (new_cursor || cursor->hot_updates)) {
bool have_hot = (cursor->hot_x != 0xffffffff &&
cursor->hot_y != 0xffffffff);
dpy_gl_cursor_dmabuf(dpy->con, &cursor->buf, have_hot,
dpy_gl_cursor_dmabuf(dpy->con, cursor->buf, have_hot,
cursor->hot_x, cursor->hot_y);
cursor->hot_updates = 0;
} else if (!cursor && new_cursor) {
Expand All @@ -328,7 +330,7 @@ static void vfio_display_dmabuf_update(void *opaque)
cursor->pos_updates = 0;
}

dpy_gl_update(dpy->con, 0, 0, primary->buf.width, primary->buf.height);
dpy_gl_update(dpy->con, 0, 0, width, height);

if (free_bufs) {
vfio_display_free_dmabufs(vdev);
Expand Down
2 changes: 1 addition & 1 deletion include/hw/vfio/vfio-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ typedef struct VFIOGroup {
} VFIOGroup;

typedef struct VFIODMABuf {
QemuDmaBuf buf;
QemuDmaBuf *buf;
uint32_t pos_x, pos_y, pos_updates;
uint32_t hot_x, hot_y, hot_updates;
int dmabuf_id;
Expand Down
4 changes: 2 additions & 2 deletions include/hw/virtio/virtio-gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ struct VirtIOGPUBaseClass {
DEFINE_PROP_UINT32("yres", _state, _conf.yres, 800)

typedef struct VGPUDMABuf {
QemuDmaBuf buf;
QemuDmaBuf *buf;
uint32_t scanout_id;
QTAILQ_ENTRY(VGPUDMABuf) next;
} VGPUDMABuf;
Expand Down Expand Up @@ -238,7 +238,7 @@ struct VhostUserGPU {
VhostUserBackend *vhost;
int vhost_gpu_fd; /* closed by the chardev */
CharBackend vhost_chr;
QemuDmaBuf dmabuf[VIRTIO_GPU_MAX_SCANOUTS];
QemuDmaBuf *dmabuf[VIRTIO_GPU_MAX_SCANOUTS];
bool backend_blocked;
};

Expand Down
20 changes: 1 addition & 19 deletions include/ui/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "qapi/qapi-types-ui.h"
#include "ui/input.h"
#include "ui/surface.h"
#include "ui/dmabuf.h"

#define TYPE_QEMU_CONSOLE "qemu-console"
OBJECT_DECLARE_TYPE(QemuConsole, QemuConsoleClass, QEMU_CONSOLE)
Expand Down Expand Up @@ -185,25 +186,6 @@ struct QEMUGLParams {
int minor_ver;
};

typedef struct QemuDmaBuf {
int fd;
uint32_t width;
uint32_t height;
uint32_t stride;
uint32_t fourcc;
uint64_t modifier;
uint32_t texture;
uint32_t x;
uint32_t y;
uint32_t backing_width;
uint32_t backing_height;
bool y0_top;
void *sync;
int fence_fd;
bool allow_fences;
bool draw_submitted;
} QemuDmaBuf;

enum display_scanout {
SCANOUT_NONE,
SCANOUT_SURFACE,
Expand Down
49 changes: 49 additions & 0 deletions include/ui/dmabuf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* QemuDmaBuf struct and helpers used for accessing its data
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/

#ifndef DMABUF_H
#define DMABUF_H

typedef struct QemuDmaBuf QemuDmaBuf;

QemuDmaBuf *qemu_dmabuf_new(uint32_t width, uint32_t height,
uint32_t stride, uint32_t x,
uint32_t y, uint32_t backing_width,
uint32_t backing_height, uint32_t fourcc,
uint64_t modifier, int dmabuf_fd,
bool allow_fences, bool y0_top);
void qemu_dmabuf_free(QemuDmaBuf *dmabuf);

G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuDmaBuf, qemu_dmabuf_free);

int qemu_dmabuf_get_fd(QemuDmaBuf *dmabuf);
int qemu_dmabuf_dup_fd(QemuDmaBuf *dmabuf);
void qemu_dmabuf_close(QemuDmaBuf *dmabuf);
uint32_t qemu_dmabuf_get_width(QemuDmaBuf *dmabuf);
uint32_t qemu_dmabuf_get_height(QemuDmaBuf *dmabuf);
uint32_t qemu_dmabuf_get_stride(QemuDmaBuf *dmabuf);
uint32_t qemu_dmabuf_get_fourcc(QemuDmaBuf *dmabuf);
uint64_t qemu_dmabuf_get_modifier(QemuDmaBuf *dmabuf);
uint32_t qemu_dmabuf_get_texture(QemuDmaBuf *dmabuf);
uint32_t qemu_dmabuf_get_x(QemuDmaBuf *dmabuf);
uint32_t qemu_dmabuf_get_y(QemuDmaBuf *dmabuf);
uint32_t qemu_dmabuf_get_backing_width(QemuDmaBuf *dmabuf);
uint32_t qemu_dmabuf_get_backing_height(QemuDmaBuf *dmabuf);
bool qemu_dmabuf_get_y0_top(QemuDmaBuf *dmabuf);
void *qemu_dmabuf_get_sync(QemuDmaBuf *dmabuf);
int32_t qemu_dmabuf_get_fence_fd(QemuDmaBuf *dmabuf);
bool qemu_dmabuf_get_allow_fences(QemuDmaBuf *dmabuf);
bool qemu_dmabuf_get_draw_submitted(QemuDmaBuf *dmabuf);
void qemu_dmabuf_set_texture(QemuDmaBuf *dmabuf, uint32_t texture);
void qemu_dmabuf_set_fence_fd(QemuDmaBuf *dmabuf, int32_t fence_fd);
void qemu_dmabuf_set_sync(QemuDmaBuf *dmabuf, void *sync);
void qemu_dmabuf_set_draw_submitted(QemuDmaBuf *dmabuf, bool draw_submitted);
void qemu_dmabuf_set_fd(QemuDmaBuf *dmabuf, int32_t fd);

#endif
4 changes: 4 additions & 0 deletions qemu-options.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2516,6 +2516,10 @@ SRST
host. It is possible to control the websocket listen address
independently, using the syntax ``websocket``\ =host:port.

Websocket could be allowed over UNIX domain socket, using the syntax
``websocket``\ =unix:path, where path is the location of a unix socket
to listen for connections on.

If no TLS credentials are provided, the websocket connection
runs in unencrypted mode. If TLS credentials are provided, the
websocket connection requires encrypted client connections.
Expand Down
4 changes: 2 additions & 2 deletions ui/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ int qemu_console_get_width(QemuConsole *con, int fallback)
}
switch (con->scanout.kind) {
case SCANOUT_DMABUF:
return con->scanout.dmabuf->width;
return qemu_dmabuf_get_width(con->scanout.dmabuf);
case SCANOUT_TEXTURE:
return con->scanout.texture.width;
case SCANOUT_SURFACE:
Expand All @@ -1476,7 +1476,7 @@ int qemu_console_get_height(QemuConsole *con, int fallback)
}
switch (con->scanout.kind) {
case SCANOUT_DMABUF:
return con->scanout.dmabuf->height;
return qemu_dmabuf_get_height(con->scanout.dmabuf);
case SCANOUT_TEXTURE:
return con->scanout.texture.height;
case SCANOUT_SURFACE:
Expand Down
9 changes: 6 additions & 3 deletions ui/dbus-console.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,14 @@ static void
dbus_gl_scanout_dmabuf(DisplayChangeListener *dcl,
QemuDmaBuf *dmabuf)
{
uint32_t width, height;

DBusDisplayConsole *ddc = container_of(dcl, DBusDisplayConsole, dcl);

dbus_display_console_set_size(ddc,
dmabuf->width,
dmabuf->height);
width = qemu_dmabuf_get_width(dmabuf);
height = qemu_dmabuf_get_height(dmabuf);

dbus_display_console_set_size(ddc, width, height);
}

static void
Expand Down

0 comments on commit 265aad5

Please sign in to comment.