diff options
Diffstat (limited to 'ui')
| -rw-r--r-- | ui/console.c | 80 | ||||
| -rw-r--r-- | ui/dbus-listener.c | 12 | ||||
| -rw-r--r-- | ui/qemu-pixman.c | 68 |
3 files changed, 93 insertions, 67 deletions
diff --git a/ui/console.c b/ui/console.c index 3a2aaba3c7..5165f17125 100644 --- a/ui/console.c +++ b/ui/console.c @@ -453,61 +453,26 @@ qemu_graphic_console_init(Object *obj) { } -#ifdef WIN32 -void qemu_displaysurface_win32_set_handle(DisplaySurface *surface, - HANDLE h, uint32_t offset) +void qemu_displaysurface_set_share_handle(DisplaySurface *surface, + qemu_pixman_shareable handle, + uint32_t offset) { - assert(!surface->handle); + assert(surface->share_handle == SHAREABLE_NONE); - surface->handle = h; - surface->handle_offset = offset; -} -#else -void qemu_displaysurface_set_shmfd(DisplaySurface *surface, - int shmfd, uint32_t offset) -{ - assert(surface->shmfd == -1); + surface->share_handle = handle; + surface->share_handle_offset = offset; - surface->shmfd = shmfd; - surface->shmfd_offset = offset; } -#endif DisplaySurface *qemu_create_displaysurface(int width, int height) { - DisplaySurface *surface; - void *bits = NULL; -#ifdef WIN32 - HANDLE handle = NULL; -#else - int shmfd = -1; -#endif - trace_displaysurface_create(width, height); -#ifdef WIN32 - bits = qemu_win32_map_alloc(width * height * 4, &handle, &error_abort); -#else - bits = qemu_memfd_alloc("displaysurface", width * height * 4, 0, &shmfd, &error_abort); -#endif - - surface = qemu_create_displaysurface_from( + return qemu_create_displaysurface_from( width, height, PIXMAN_x8r8g8b8, - width * 4, bits + width * 4, NULL ); - surface->flags = QEMU_ALLOCATED_FLAG; - -#ifdef WIN32 - qemu_displaysurface_win32_set_handle(surface, handle, 0); - void *data = handle; -#else - qemu_displaysurface_set_shmfd(surface, shmfd, 0); - void *data = GINT_TO_POINTER(shmfd); -#endif - pixman_image_set_destroy_function(surface->image, qemu_pixman_shared_image_destroy, data); - - return surface; } DisplaySurface *qemu_create_displaysurface_from(int width, int height, @@ -517,14 +482,25 @@ DisplaySurface *qemu_create_displaysurface_from(int width, int height, DisplaySurface *surface = g_new0(DisplaySurface, 1); trace_displaysurface_create_from(surface, width, height, format); -#ifndef WIN32 - surface->shmfd = -1; -#endif - surface->image = pixman_image_create_bits(format, - width, height, - (void *)data, linesize); - assert(surface->image != NULL); + surface->share_handle = SHAREABLE_NONE; + if (data) { + surface->image = pixman_image_create_bits(format, + width, height, + (void *)data, linesize); + } else { + qemu_pixman_image_new_shareable(&surface->image, + &surface->share_handle, + "displaysurface", + format, + width, + height, + linesize, + &error_abort); + surface->flags = QEMU_ALLOCATED_FLAG; + } + + assert(surface->image != NULL); return surface; } @@ -533,9 +509,7 @@ DisplaySurface *qemu_create_displaysurface_pixman(pixman_image_t *image) DisplaySurface *surface = g_new0(DisplaySurface, 1); trace_displaysurface_create_pixman(surface); -#ifndef WIN32 - surface->shmfd = -1; -#endif + surface->share_handle = SHAREABLE_NONE; surface->image = pixman_image_ref(image); return surface; diff --git a/ui/dbus-listener.c b/ui/dbus-listener.c index ec47946282..99738e769b 100644 --- a/ui/dbus-listener.c +++ b/ui/dbus-listener.c @@ -336,13 +336,13 @@ static bool dbus_scanout_map(DBusDisplayListener *ddl) return true; } - if (!ddl->can_share_map || !ddl->ds->handle) { + if (!ddl->can_share_map || !ddl->ds->share_handle) { return false; } success = DuplicateHandle( GetCurrentProcess(), - ddl->ds->handle, + ddl->ds->share_handle, ddl->peer_process, &target_handle, FILE_MAP_READ | SECTION_QUERY, @@ -359,7 +359,7 @@ static bool dbus_scanout_map(DBusDisplayListener *ddl) if (!qemu_dbus_display1_listener_win32_map_call_scanout_map_sync( ddl->map_proxy, GPOINTER_TO_UINT(target_handle), - ddl->ds->handle_offset, + ddl->ds->share_handle_offset, surface_width(ddl->ds), surface_height(ddl->ds), surface_stride(ddl->ds), @@ -453,13 +453,13 @@ static bool dbus_scanout_map(DBusDisplayListener *ddl) return true; } - if (!ddl->can_share_map || ddl->ds->shmfd == -1) { + if (!ddl->can_share_map || ddl->ds->share_handle == SHAREABLE_NONE) { return false; } ddl_discard_display_messages(ddl); fd_list = g_unix_fd_list_new(); - if (g_unix_fd_list_append(fd_list, ddl->ds->shmfd, &err) != 0) { + if (g_unix_fd_list_append(fd_list, ddl->ds->share_handle, &err) != 0) { g_debug("Failed to setup scanout map fdlist: %s", err->message); ddl->can_share_map = false; return false; @@ -468,7 +468,7 @@ static bool dbus_scanout_map(DBusDisplayListener *ddl) if (!qemu_dbus_display1_listener_unix_map_call_scanout_map_sync( ddl->map_proxy, g_variant_new_handle(0), - ddl->ds->shmfd_offset, + ddl->ds->share_handle_offset, surface_width(ddl->ds), surface_height(ddl->ds), surface_stride(ddl->ds), diff --git a/ui/qemu-pixman.c b/ui/qemu-pixman.c index 46a91e7f7a..6ef4376f4e 100644 --- a/ui/qemu-pixman.c +++ b/ui/qemu-pixman.c @@ -270,19 +270,71 @@ void qemu_pixman_glyph_render(pixman_image_t *glyph, } #endif /* CONFIG_PIXMAN */ -void -qemu_pixman_shared_image_destroy(pixman_image_t *image, void *data) +static void * +qemu_pixman_shareable_alloc(const char *name, size_t size, + qemu_pixman_shareable *handle, + Error **errp) { - void *ptr = pixman_image_get_data(image); - #ifdef WIN32 - HANDLE handle = data; + return qemu_win32_map_alloc(size, handle, errp); +#else + return qemu_memfd_alloc(name, size, 0, handle, errp); +#endif +} +static void +qemu_pixman_shareable_free(qemu_pixman_shareable handle, + void *ptr, size_t size) +{ +#ifdef WIN32 qemu_win32_map_free(ptr, handle, &error_warn); #else - int shmfd = GPOINTER_TO_INT(data); + qemu_memfd_free(ptr, size, handle); +#endif +} + +static void +qemu_pixman_shared_image_destroy(pixman_image_t *image, void *data) +{ + qemu_pixman_shareable handle = PTR_TO_SHAREABLE(data); + void *ptr = pixman_image_get_data(image); size_t size = pixman_image_get_height(image) * pixman_image_get_stride(image); - qemu_memfd_free(ptr, size, shmfd); -#endif + qemu_pixman_shareable_free(handle, ptr, size); +} + +bool +qemu_pixman_image_new_shareable(pixman_image_t **image, + qemu_pixman_shareable *handle, + const char *name, + pixman_format_code_t format, + int width, + int height, + int rowstride_bytes, + Error **errp) +{ + ERRP_GUARD(); + size_t size = height * rowstride_bytes; + void *bits = NULL; + + g_return_val_if_fail(image != NULL, false); + g_return_val_if_fail(handle != NULL, false); + + bits = qemu_pixman_shareable_alloc(name, size, handle, errp); + if (!bits) { + return false; + } + + *image = pixman_image_create_bits(format, width, height, bits, rowstride_bytes); + if (!*image) { + error_setg(errp, "Failed to allocate image"); + qemu_pixman_shareable_free(*handle, bits, size); + return false; + } + + pixman_image_set_destroy_function(*image, + qemu_pixman_shared_image_destroy, + SHAREABLE_TO_PTR(*handle)); + + return true; } |