From nobody Sat May 11 18:16:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1613821190; cv=none; d=zohomail.com; s=zohoarc; b=HRXj6XhUCu+W57wEiM/5nRbXztMROEnaQ5ic8MmHXolk2/H45IOsy52xTXlpKIIt7E1cMKRoOfOysAklTikkGR3SNFluJyB9L4kehXl2NjmVT4a2RTMNRph1fAVjKNmBFLUrHHbMDCHfCfqgXoyxfkcWPRIRMwn7CYkc0cOHAnE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613821190; h=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; bh=SwgMkpNKM1+VEZ2jCT/Y+i+eShsgjra0a21NxLZIL+M=; b=aDkqkSQPMpnSfXDSlyRZn8Kg7GkJVRRnH0nevjytzGO2PUCXBjnIfhQOPB2KjxMWhT2opcPNjnhSE7Tais1je9Gms+FJpiL+7cVOOLmnbiisEgqq56U1XPRUYm7bPsMSMlpT2HBrnqlpuf1wHEhT8Q/nvDA6sjLuZVpcVfeVFnc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613821190347513.8600861570407; Sat, 20 Feb 2021 03:39:50 -0800 (PST) Received: from localhost ([::1]:39934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lDQc0-0007Dx-P4 for importer@patchew.org; Sat, 20 Feb 2021 06:39:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49638) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lDQaa-0006jU-Ow for qemu-devel@nongnu.org; Sat, 20 Feb 2021 06:38:20 -0500 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]:34819) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lDQaY-0002pK-MS for qemu-devel@nongnu.org; Sat, 20 Feb 2021 06:38:20 -0500 Received: by mail-pj1-x102b.google.com with SMTP id e9so5790646pjj.0 for ; Sat, 20 Feb 2021 03:38:17 -0800 (PST) Received: from localhost.localdomain ([2400:4050:c360:8200:d8f0:71c1:3d6a:4f53]) by smtp.gmail.com with ESMTPSA id dw23sm11331247pjb.3.2021.02.20.03.38.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 Feb 2021 03:38:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SwgMkpNKM1+VEZ2jCT/Y+i+eShsgjra0a21NxLZIL+M=; b=S+lSJcQ8OF2s+31vbnA+3A6nWM4d7whH98snhqHmXWqXhLd9NUPGpIsDn3pSsMsgyT h/+8T9V04Q1kByG73JPRYvCbQ0+rgwandqKme+9YO2M4rn7eZYF6m56g/KbIYNGWjojt G2QRJ55cDFM1Xae1n2wBJ81rYu+Rdr5+EJOI8O7D4dNDYNRcRBIqN/3Y+1k6tCouP85J hQeH4donOm65Kp5mvJtN1+GEFSO85RytI1k7saPq5oJ5B1jKUwoWCWQuYtMTItqe93yA OcuybJVVowSG/MItI1fOn3QB11RjxIQKzElO+hr/JvnDAf/uqir+mC6sqKHiUm02Q5M2 Es8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SwgMkpNKM1+VEZ2jCT/Y+i+eShsgjra0a21NxLZIL+M=; b=cLe8Jh4kFukD30JDhEuiMma1I75fBUz+2LDS3fPXuyHCnRX5pGZV2oj+IMhwfHmi53 SSFeH6k2iRcDRYKdT9wzarxhfwXUPQa6w2J7FsO11T9Dl54NafWN5CfzaXKMUImUcDOl eS6w264B31emSD3hRey+9cqWS630fDRGUdO9cPuNMhO9YcMGYb95nIqWKI2euFHVrXRg bFB6yfInAGAi4g8UQbin5NDxhn/dnZe0qDD/BZeshfm9LaUaU7mPV/nieLUwENx5cQ4z LMq/MGN03lRUB771MTESqUVLHqRtJXLhRDaRJoHzlKE1jY867JIIJqqcNDIFggmhrJ/i 7FEw== X-Gm-Message-State: AOAM530JSRxthpg2nOaqve6SgefhJoFjem3Gj9eil19HFestHvOWtPoO 8AIKs4pdWfS0jmJAf956iSFLVr1IuFwHvg== X-Google-Smtp-Source: ABdhPJwG3WZfyJtFjKX+NwF9ZPF/XJAZreHs1p7TwaMhRpveP5jx2nvPlChAWDtlI/jp7XsO0gNuoQ== X-Received: by 2002:a17:90a:c84:: with SMTP id v4mr14015528pja.228.1613821096194; Sat, 20 Feb 2021 03:38:16 -0800 (PST) From: Akihiko Odaki To: Subject: [PATCH v2] ui/console: Pass placeholder surface to displays Date: Sat, 20 Feb 2021 20:38:10 +0900 Message-Id: <20210220113810.78371-1-akihiko.odaki@gmail.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20210219144848.wy7wmel4lixaqkyb@sirius.home.kraxel.org> References: <20210219144848.wy7wmel4lixaqkyb@sirius.home.kraxel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::102b; envelope-from=akihiko.odaki@gmail.com; helo=mail-pj1-x102b.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , qemu-devel@nongnu.org, Akihiko Odaki , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" ui/console used to accept NULL as graphic console surface, but its semantics was inconsistent among displays: - cocoa and gtk-egl perform NULL dereference. - egl-headless, spice and spice-egl do nothing. - gtk releases underlying resources. - sdl2-2d and sdl2-gl destroys the window. - vnc shows a message, "Display output is not active." Fortunately, only virtio-gpu and virtio-gpu-3d assign NULL so we can study them to figure out the desired behavior. They assign NULL *except* for the primary display when the device is realized, reset, or its scanout is disabled. This effectively destroys windows for the (uninitialized) secondary displays. To implement the consistent behavior of display device realization/reset, this change embeds it to the operation switching the surface. When NULL was given as a new surface when switching, ui/console will instead passes a placeholder down to each display listeners. sdl calls is_placeholder when switching surfaces, and destroys the window if the given surface was a placeholder. The other displays simply shows the placeholder when the console is inactive. Signed-off-by: Akihiko Odaki --- include/ui/console.h | 6 ++++++ ui/console.c | 46 ++++++++++++++++++++++++++++++-------------- ui/gtk.c | 4 ---- ui/sdl2-2d.c | 7 ++----- ui/sdl2-gl.c | 4 ++-- ui/spice-display.c | 6 +++--- ui/vnc.c | 10 ---------- 7 files changed, 45 insertions(+), 38 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index d30e972d0b5..e0ac3850858 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -106,6 +106,7 @@ struct QemuConsoleClass { }; =20 #define QEMU_ALLOCATED_FLAG 0x01 +#define QEMU_PLACEHOLDER_FLAG 0x02 =20 typedef struct DisplaySurface { pixman_format_code_t format; @@ -281,6 +282,11 @@ static inline int is_buffer_shared(DisplaySurface *sur= face) return !(surface->flags & QEMU_ALLOCATED_FLAG); } =20 +static inline int is_placeholder(DisplaySurface *surface) +{ + return surface->flags & QEMU_PLACEHOLDER_FLAG; +} + void register_displaychangelistener(DisplayChangeListener *dcl); void update_displaychangelistener(DisplayChangeListener *dcl, uint64_t interval); diff --git a/ui/console.c b/ui/console.c index c5d11bc7017..b786c36d5b1 100644 --- a/ui/console.c +++ b/ui/console.c @@ -1088,6 +1088,30 @@ static void console_putchar(QemuConsole *s, int ch) } } =20 +static void dpy_gfx_switch(DisplayChangeListener *dcl, DisplaySurface *sur= face) +{ + static DisplaySurface *placeholder; + static const char placeholder_msg[] =3D "Display output is not active.= "; + DisplaySurface *broadcast; + + if (!dcl->ops->dpy_gfx_switch) { + return; + } + + if (surface) { + broadcast =3D surface; + } else { + if (!placeholder) { + placeholder =3D qemu_create_message_surface(640, 480, placehol= der_msg); + placeholder->flags |=3D QEMU_PLACEHOLDER_FLAG; + } + + broadcast =3D placeholder; + } + + dcl->ops->dpy_gfx_switch(dcl, broadcast); +} + void console_select(unsigned int index) { DisplayChangeListener *dcl; @@ -1104,9 +1128,7 @@ void console_select(unsigned int index) if (dcl->con !=3D NULL) { continue; } - if (dcl->ops->dpy_gfx_switch) { - dcl->ops->dpy_gfx_switch(dcl, s->surface); - } + dpy_gfx_switch(dcl, s->surface); } if (s->surface) { dpy_gfx_update(s, 0, 0, surface_width(s->surface), @@ -1545,15 +1567,13 @@ void register_displaychangelistener(DisplayChangeLi= stener *dcl) } else { con =3D active_console; } - if (dcl->ops->dpy_gfx_switch) { - if (con) { - dcl->ops->dpy_gfx_switch(dcl, con->surface); - } else { - if (!dummy) { - dummy =3D qemu_create_message_surface(640, 480, nodev); - } - dcl->ops->dpy_gfx_switch(dcl, dummy); + if (con) { + dpy_gfx_switch(dcl, con->surface); + } else { + if (!dummy) { + dummy =3D qemu_create_message_surface(640, 480, nodev); } + dpy_gfx_switch(dcl, dummy); } text_console_update_cursor(NULL); } @@ -1685,9 +1705,7 @@ void dpy_gfx_replace_surface(QemuConsole *con, if (con !=3D (dcl->con ? dcl->con : active_console)) { continue; } - if (dcl->ops->dpy_gfx_switch) { - dcl->ops->dpy_gfx_switch(dcl, surface); - } + dpy_gfx_switch(dcl, surface); } qemu_free_displaysurface(old_surface); } diff --git a/ui/gtk.c b/ui/gtk.c index 79dc2401203..a4a5f981e2a 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -567,10 +567,6 @@ static void gd_switch(DisplayChangeListener *dcl, } vc->gfx.ds =3D surface; =20 - if (!surface) { - return; - } - if (surface->format =3D=3D PIXMAN_x8r8g8b8) { /* * PIXMAN_x8r8g8b8 =3D=3D CAIRO_FORMAT_RGB24 diff --git a/ui/sdl2-2d.c b/ui/sdl2-2d.c index a2ea85127d5..ddd2e05734e 100644 --- a/ui/sdl2-2d.c +++ b/ui/sdl2-2d.c @@ -32,14 +32,11 @@ void sdl2_2d_update(DisplayChangeListener *dcl, int x, int y, int w, int h) { struct sdl2_console *scon =3D container_of(dcl, struct sdl2_console, d= cl); - DisplaySurface *surf =3D qemu_console_surface(dcl->con); + DisplaySurface *surf =3D scon->surface; SDL_Rect rect; size_t surface_data_offset; assert(!scon->opengl); =20 - if (!surf) { - return; - } if (!scon->texture) { return; } @@ -75,7 +72,7 @@ void sdl2_2d_switch(DisplayChangeListener *dcl, scon->texture =3D NULL; } =20 - if (!new_surface) { + if (is_placeholder(new_surface)) { sdl2_window_destroy(scon); return; } diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c index fd594d74611..a68697714f0 100644 --- a/ui/sdl2-gl.c +++ b/ui/sdl2-gl.c @@ -86,7 +86,7 @@ void sdl2_gl_switch(DisplayChangeListener *dcl, =20 scon->surface =3D new_surface; =20 - if (!new_surface) { + if (is_placeholder(new_surface)) { qemu_gl_fini_shader(scon->gls); scon->gls =3D NULL; sdl2_window_destroy(scon); @@ -112,7 +112,7 @@ void sdl2_gl_refresh(DisplayChangeListener *dcl) assert(scon->opengl); =20 graphic_hw_update(dcl->con); - if (scon->updates && scon->surface) { + if (scon->updates && scon->real_window) { scon->updates =3D 0; sdl2_gl_render_surface(scon); } diff --git a/ui/spice-display.c b/ui/spice-display.c index 6f32b66a6e7..222c7c20a2a 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -388,7 +388,7 @@ void qemu_spice_display_switch(SimpleSpiceDisplay *ssd, SimpleSpiceUpdate *update; bool need_destroy; =20 - if (surface && ssd->surface && + if (ssd->surface && surface_width(surface) =3D=3D pixman_image_get_width(ssd->surface)= && surface_height(surface) =3D=3D pixman_image_get_height(ssd->surfac= e) && surface_format(surface) =3D=3D pixman_image_get_format(ssd->surfac= e)) { @@ -410,8 +410,8 @@ void qemu_spice_display_switch(SimpleSpiceDisplay *ssd, =20 /* full mode switch */ trace_qemu_spice_display_surface(ssd->qxl.id, - surface ? surface_width(surface) : 0, - surface ? surface_height(surface) : 0, + surface_width(surface), + surface_height(surface), false); =20 memset(&ssd->dirty, 0, sizeof(ssd->dirty)); diff --git a/ui/vnc.c b/ui/vnc.c index 16bb3be770b..310abc93781 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -790,20 +790,10 @@ static bool vnc_check_pageflip(DisplaySurface *s1, static void vnc_dpy_switch(DisplayChangeListener *dcl, DisplaySurface *surface) { - static const char placeholder_msg[] =3D - "Display output is not active."; - static DisplaySurface *placeholder; VncDisplay *vd =3D container_of(dcl, VncDisplay, dcl); bool pageflip =3D vnc_check_pageflip(vd->ds, surface); VncState *vs; =20 - if (surface =3D=3D NULL) { - if (placeholder =3D=3D NULL) { - placeholder =3D qemu_create_message_surface(640, 480, placehol= der_msg); - } - surface =3D placeholder; - } - vnc_abort_display_jobs(vd); vd->ds =3D surface; =20 --=20 2.24.3 (Apple Git-128)