[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 10/21] virtio-gpu/win32: allocate shareable 2d resources/images
From: |
marcandre . lureau |
Subject: |
[PATCH 10/21] virtio-gpu/win32: allocate shareable 2d resources/images |
Date: |
Tue, 6 Jun 2023 15:56:47 +0400 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
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 <marcandre.lureau@redhat.com>
---
include/hw/virtio/virtio-gpu.h | 3 +++
hw/display/virtio-gpu.c | 46 +++++++++++++++++++++++++++++++---
2 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index 2e28507efe..7a5f8056ea 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -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;
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 66cddd94d9..2871563c40 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -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
+ 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);
+#ifdef WIN32
+ if (res->image) {
+ pixman_image_set_destroy_function(res->image,
win32_pixman_image_destroy, res->handle);
+ }
+#endif
}
+#ifdef WIN32
+end:
+#endif
if (!res->image) {
qemu_log_mask(LOG_GUEST_ERROR,
"%s: resource creation failed %d %d %d\n",
@@ -666,6 +691,9 @@ static void virtio_gpu_do_set_scanout(VirtIOGPU *g,
*error = VIRTIO_GPU_RESP_ERR_UNSPEC;
return;
}
+#ifdef WIN32
+ qemu_displaysurface_win32_set_handle(scanout->ds, res->handle,
fb->offset);
+#endif
pixman_image_unref(rect);
dpy_gfx_replace_surface(g->parent_obj.scanout[scanout_id].con,
@@ -1209,6 +1237,7 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque,
size_t size,
struct virtio_gpu_simple_resource *res;
struct virtio_gpu_scanout *scanout;
uint32_t resource_id, pformat;
+ void *bits = NULL;
int i;
g->hostmem = 0;
@@ -1233,15 +1262,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
+ 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);
if (!res->image) {
g_free(res);
return -EINVAL;
}
- res->hostmem = calc_image_hostmem(pformat, res->width, res->height);
res->addrs = g_new(uint64_t, res->iov_cnt);
res->iov = g_new(struct iovec, res->iov_cnt);
@@ -1302,6 +1339,9 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque,
size_t size,
if (!scanout->ds) {
return -EINVAL;
}
+#ifdef WIN32
+ qemu_displaysurface_win32_set_handle(scanout->ds, res->handle, 0);
+#endif
dpy_gfx_replace_surface(scanout->con, scanout->ds);
dpy_gfx_update_full(scanout->con);
--
2.40.1
- [PATCH 01/21] ui/egl: export qemu_egl_get_error_string(), (continued)
- [PATCH 01/21] ui/egl: export qemu_egl_get_error_string(), marcandre . lureau, 2023/06/06
- [PATCH 02/21] ui/egl: fix make_context_current() callback return value, marcandre . lureau, 2023/06/06
- [PATCH 03/21] ui/dbus: compile without gio/gunixfdlist.h, marcandre . lureau, 2023/06/06
- [PATCH 04/21] scripts: add a XML preprocessor script, marcandre . lureau, 2023/06/06
- [PATCH 05/21] ui/dbus: win32 support, marcandre . lureau, 2023/06/06
- [PATCH 06/21] qtest: add qtest_pid(), marcandre . lureau, 2023/06/06
- [PATCH 07/21] tests: make dbus-display-test work on win32, marcandre . lureau, 2023/06/06
- [PATCH 08/21] ui/dbus: introduce "Interfaces" properties, marcandre . lureau, 2023/06/06
- [PATCH 10/21] virtio-gpu/win32: allocate shareable 2d resources/images,
marcandre . lureau <=
- [PATCH 11/21] ui/dbus: use shared memory when possible on win32, marcandre . lureau, 2023/06/06
- [PATCH 12/21] ui: add egl-headless support on win32, marcandre . lureau, 2023/06/06
- [PATCH 13/21] ui/egl: default to GLES on windows, marcandre . lureau, 2023/06/06
- [PATCH 14/21] ui: add egl_fb_read_rect(), marcandre . lureau, 2023/06/06
- [PATCH 15/21] ui/dbus: add GL support on win32, marcandre . lureau, 2023/06/06
- [PATCH 16/21] ui/dbus: add some GL traces, marcandre . lureau, 2023/06/06
- [PATCH 18/21] ui/egl: query ANGLE d3d device, marcandre . lureau, 2023/06/06
- [PATCH 17/21] virtio-gpu-virgl: teach it to get the QEMU EGL display, marcandre . lureau, 2023/06/06
- [PATCH 19/21] ui: add optional d3d texture pointer to scanout texture, marcandre . lureau, 2023/06/06
- [PATCH 20/21] virtio-gpu-virgl: use D3D11_SHARE_TEXTURE when available, marcandre . lureau, 2023/06/06