aboutsummaryrefslogtreecommitdiff
path: root/hw/display
diff options
context:
space:
mode:
Diffstat (limited to 'hw/display')
-rw-r--r--hw/display/vhost-user-gpu.c32
-rw-r--r--hw/display/virtio-gpu-udmabuf.c27
2 files changed, 29 insertions, 30 deletions
diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c
index 709c8a02a1..e4b398d26c 100644
--- a/hw/display/vhost-user-gpu.c
+++ b/hw/display/vhost-user-gpu.c
@@ -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) {
@@ -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: {
diff --git a/hw/display/virtio-gpu-udmabuf.c b/hw/display/virtio-gpu-udmabuf.c
index d51184d658..c02ec6d37d 100644
--- a/hw/display/virtio-gpu-udmabuf.c
+++ b/hw/display/virtio-gpu-udmabuf.c
@@ -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);
}
@@ -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);
@@ -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) {
@@ -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);