From nobody Tue Feb 10 20:47:44 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1686053077; cv=none; d=zohomail.com; s=zohoarc; b=bzaDrRgEeNOgVVthW6JKkJJlyAHaVx4zWLK1x97QKPC+0WeXcZi7DjnPAdJXpqhz7B1hXMh1wOZ0GHhcAIpngbwgXu8yj6iLHTWEhRtqyILcNDg0uCWBqmYwu9r7TikjHLgWBtk58l7oTtM3lXxLHStznnnGbRz9VKFrChSGRxY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686053077; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sqJsNl4Ar54jPG3d2clpVdVLe4x6TN6Wzg67MJF4rOc=; b=db/0Trib++g4L6p8J+hZNaFuaZCSa7yvigpmaY3pr6idqsmVPv62GlgVOkZbv0qYPwtk8wTX71oZJ1ISE7Md9jyMCkzXAZ+u8fP2vhMlOigWkAkLRc+aj9fk1l+6mzFMEF/Xc32r2uvXh+Pl+YAgD/wZacph4lgd4Ak55XwlzVE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1686053077055797.3221890564307; Tue, 6 Jun 2023 05:04:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q6VP7-00087P-1M; Tue, 06 Jun 2023 08:03:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q6VP4-00083W-RS for qemu-devel@nongnu.org; Tue, 06 Jun 2023 08:03:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q6VP2-0007G6-It for qemu-devel@nongnu.org; Tue, 06 Jun 2023 08:03:10 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-295-nIsYckiZNSWBMP3u7lpMpQ-1; Tue, 06 Jun 2023 08:03:04 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 25A93802355; Tue, 6 Jun 2023 11:57:57 +0000 (UTC) Received: from localhost (unknown [10.39.208.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id BBA4E140E958; Tue, 6 Jun 2023 11:57:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686052987; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sqJsNl4Ar54jPG3d2clpVdVLe4x6TN6Wzg67MJF4rOc=; b=Rr8k5rZCRwnAKGAV+27HS+huxE/T1JtDRHftnPllIiIZhQqD5cXdNn/OT1uXvco6xqT1qY dftpYSFW+SXZHkRwd06JsY3YrK284KqqUzkicLve3xR9/pwA38yMZSsN3CCWo/JmPvax7M sVqG9FsNvhpFQJHNOJS4Ife8JEnVwas= X-MC-Unique: nIsYckiZNSWBMP3u7lpMpQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Stefan Weil Subject: [PATCH 09/21] console/win32: allocate shareable display surface Date: Tue, 6 Jun 2023 15:56:46 +0400 Message-Id: <20230606115658.677673-10-marcandre.lureau@redhat.com> In-Reply-To: <20230606115658.677673-1-marcandre.lureau@redhat.com> References: <20230606115658.677673-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1686053079827100011 From: Marc-Andr=C3=A9 Lureau 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. Signed-off-by: Marc-Andr=C3=A9 Lureau --- 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(-) diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h index 65f6c9ea57..91aa0d7ec0 100644 --- a/include/sysemu/os-win32.h +++ b/include/sysemu/os-win32.h @@ -263,6 +263,9 @@ EXCEPTION_DISPOSITION win32_close_exception_handler(struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*); =20 +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 diff --git a/include/ui/console.h b/include/ui/console.h index ae5ec466c1..0fd2692110 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -128,6 +128,10 @@ typedef struct DisplaySurface { GLenum gltype; GLuint texture; #endif +#ifdef WIN32 + HANDLE handle; + uint32_t handle_offset; +#endif } DisplaySurface; =20 typedef struct QemuUIInfo { @@ -314,6 +318,10 @@ DisplaySurface *qemu_create_displaysurface_from(int wi= dth, 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); =20 DisplaySurface *qemu_create_displaysurface(int width, int height); diff --git a/ui/console.c b/ui/console.c index e173731e20..2b53c64ef0 100644 --- a/ui/console.c +++ b/ui/console.c @@ -1513,18 +1513,59 @@ static QemuConsole *new_console(DisplayState *ds, c= onsole_type_t console_type, return s; } =20 +#ifdef WIN32 +void qemu_displaysurface_win32_set_handle(DisplaySurface *surface, + HANDLE h, uint32_t offset) +{ + assert(!surface->handle); + + surface->handle =3D h; + surface->handle_offset =3D offset; +} + +static void +win32_pixman_image_destroy(pixman_image_t *image, void *data) +{ + DisplaySurface *surface =3D data; + + if (!surface->handle) { + return; + } + + assert(surface->handle_offset =3D=3D 0); + + qemu_win32_map_free( + pixman_image_get_data(surface->image), + surface->handle, + &error_warn + ); +} +#endif + DisplaySurface *qemu_create_displaysurface(int width, int height) { - DisplaySurface *surface =3D g_new0(DisplaySurface, 1); + DisplaySurface *surface; + void *bits =3D NULL; +#ifdef WIN32 + HANDLE handle =3D NULL; +#endif =20 - trace_displaysurface_create(surface, width, height); - surface->format =3D PIXMAN_x8r8g8b8; - surface->image =3D pixman_image_create_bits(surface->format, - width, height, - NULL, width * 4); - assert(surface->image !=3D NULL); + trace_displaysurface_create(width, height); + +#ifdef WIN32 + bits =3D qemu_win32_map_alloc(width * height * 4, &handle, &error_abor= t); +#endif + + surface =3D qemu_create_displaysurface_from( + width, height, + PIXMAN_x8r8g8b8, + width * 4, bits + ); surface->flags =3D QEMU_ALLOCATED_FLAG; =20 +#ifdef WIN32 + qemu_displaysurface_win32_set_handle(surface, handle, 0); +#endif return surface; } =20 @@ -1540,6 +1581,10 @@ DisplaySurface *qemu_create_displaysurface_from(int = width, int height, width, height, (void *)data, linesize); assert(surface->image !=3D NULL); +#ifdef WIN32 + pixman_image_set_destroy_function(surface->image, + win32_pixman_image_destroy, surface); +#endif =20 return surface; } diff --git a/ui/qemu-pixman.c b/ui/qemu-pixman.c index 3ab7e2e958..e4f024a85e 100644 --- a/ui/qemu-pixman.c +++ b/ui/qemu-pixman.c @@ -6,6 +6,7 @@ #include "qemu/osdep.h" #include "ui/console.h" #include "standard-headers/drm/drm_fourcc.h" +#include "trace.h" =20 PixelFormat qemu_pixelformat_from_pixman(pixman_format_code_t format) { diff --git a/util/oslib-win32.c b/util/oslib-win32.c index fafbab80b4..429542face 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -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 =3D CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, + size, NULL); + if (*h =3D=3D NULL) { + error_setg_win32(errp, GetLastError(), "Failed to CreateFileMappin= g"); + return NULL; + } + + bits =3D MapViewOfFile(*h, FILE_MAP_ALL_ACCESS, 0, 0, size); + if (bits =3D=3D 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) =3D=3D 0) { + error_setg_win32(errp, GetLastError(), "Failed to UnmapViewOfFile"= ); + } + CloseHandle(h); +} diff --git a/ui/trace-events b/ui/trace-events index 6747361745..712c4b2273 100644 --- a/ui/trace-events +++ b/ui/trace-events @@ -9,7 +9,7 @@ console_putchar_unhandled(int ch) "unhandled escape charact= er '%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=3D%p, = %dx%d" +displaysurface_create(int w, int h) "%dx%d" displaysurface_create_from(void *display_surface, int w, int h, uint32_t f= ormat) "surface=3D%p, %dx%d, format 0x%x" displaysurface_create_pixman(void *display_surface) "surface=3D%p" displaysurface_free(void *display_surface) "surface=3D%p" diff --git a/util/trace-events b/util/trace-events index 3f7e766683..49a4962e18 100644 --- a/util/trace-events +++ b/util/trace-events @@ -52,6 +52,10 @@ qemu_anon_ram_alloc(size_t size, void *ptr) "size %zu pt= r %p" qemu_vfree(void *ptr) "ptr %p" qemu_anon_ram_free(void *ptr, size_t size) "ptr %p size %zu" =20 +# 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, uin= t64_t ebit) "hb %p items %"PRIu64",%"PRIu64" bits %"PRIu64"..%"PRIu64 --=20 2.40.1