From nobody Tue Nov 26 08:40:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1708735836; cv=none; d=zohomail.com; s=zohoarc; b=fGr77DSo5GMxiUZi3OGhX+CMT5MM71nVmP0Ks2xbjqwiC0zFbfT2030ltGwTUqaUYMdXU31xU/ACFzGvVmtqmex52OLLGuJd4TWrbnwuPCVjTxmM8vmNh8wHBTUA/3lHckMcwXZw4dSUdGuBFm4Y7K1yqm30OevMgIN8d9fht4Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708735836; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ylu3c6iLbz3q2o+ct3FoEaLR9X06nod5uaTCkzgO2iM=; b=KyixgclS3M14QAuqdetxzkaShCWPoe6n+MGbjBcM7feKx8Ot6mo6GmIdLvMTNpKpt8AMLlwsjgjcYrBTWuTGPNgQ6WWLUbfuesisqtlXY4Z4Bc2kFpfsMlgfLeUc9awbaF9SmY9DSJER9qLwfRjL9QpAfU5psbeLuN/NxEHu4fA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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 1708735836498630.3573219171017; Fri, 23 Feb 2024 16:50:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdgEX-0002Kh-Ax; Fri, 23 Feb 2024 19:49:41 -0500 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 1rdgEU-0002KJ-J6 for qemu-devel@nongnu.org; Fri, 23 Feb 2024 19:49:38 -0500 Received: from mgamail.intel.com ([198.175.65.12]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rdgER-0004F2-Jg for qemu-devel@nongnu.org; Fri, 23 Feb 2024 19:49:38 -0500 Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2024 16:49:32 -0800 Received: from ssingh-linux.fm.intel.com ([10.105.129.123]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2024 16:49:32 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708735776; x=1740271776; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=OF4AC9jXPv2xf6+wu6q+Bxa6uMXjEtKT2Zu/YAfY5Ls=; b=ipNVYRYwJs93wNZTY/wS0wiZYkFlatbRNZj297JUGObVnJqHxPhOLMgp EOueRefsQSYiRAEdBtRWTgs1T85Ah+6+xTtKttiYaT+cJ0ea+lXESxCrz jBiYNObGuSH4Osia1/4NY4X5AnxOvNcdcMo80UUcnlsvnTSxUKwXt2wOd jexouHAFoG9/G7LkZYjPNNMUFgOERMhBgtv0ZxWCMnqxrHGhPnFST7iYt QGe5D1ateWTAa2FiKGoSNzmyj8LWNWIDCP+hZRL0xoz/fsh8+lskb4BGo idD7rdSnKAR1BCqqMil8eUHUcVIhfgOGx2NQD+c8QHpva9A4hXtJ2lM68 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10993"; a="14508841" X-IronPort-AV: E=Sophos;i="6.06,180,1705392000"; d="scan'208";a="14508841" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,180,1705392000"; d="scan'208";a="10767124" From: Satyeshwar Singh To: qemu-devel@nongnu.org Cc: satyeshwar.singh@intel.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Vivek Kasireddy , Dongwon Kim Subject: [PATCH] virtio-gpu: Fix HW cursor visibility Date: Fri, 23 Feb 2024 17:51:23 -0800 Message-Id: <20240224015123.1575580-1-satyeshwar.singh@intel.com> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=198.175.65.12; envelope-from=satyeshwar.singh@intel.com; helo=mgamail.intel.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.066, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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 @intel.com) X-ZM-MESSAGEID: 1708735839090100003 When show-cursor is on, most of the time Windows VM draws the cursor by itself and hands it over to Qemu as a separate resource. However, sometimes, Windows OS gives control of the cursor to applications like Notepad. In such cases a software cursor which is part of the overall framebuffer is drawn by the application. Windows intimates the indirect display driver (IDD) about this change through a flag and IDD is in turn responsible for communicating with the hypervisor (Qemu) to hide the HW cursor. This show/hide cursor can happen any time dynamically. Unfortunately, it seems like Qemu doesn't expect this change to happen dynamically. The code in virtio-gpu.c was written such that update_cursor would first call dpy_cursor_define if the cursor shape has changed and this is not a simple move operation (which indeed is the case when moving to a SW cursor) and then call dpy_mouse_set. dpy_cursor_define calls toolkits like GTK but in addition to creating the cursor content, it also calls gdk_window_set_cursor thereby setting the cursor. It is therefore, the right function to either show or hide the cursor but there was no code present to hide the cursor. Changing the cursor visibility in dpy_mouse_set has two issues. First, dpy_cursor_define already decided to display the cursor so showing the cursor in the previous call only to hide it in dpy_mouse_set doesn't sound right. Second, dpy_mouse_set skips the rest of the code if we are in absolute mode so adding this code there wouldn't work in that mode. Qemu makes the decision of whether to show or hide the cursor by observing the cursor->resource_id flag in virtio-gpu.c as is evident from the lines dpy_mouse_set(s->con, cursor->pos.x, cursor->pos.y, cursor->resource_id ? 1 : 0); The last parameter is considered the "visible" parameter in gdk code. Therefore, in this patch we continue with the same model. Instead of changing the function prototype and changing a dozen plus files, we are adding the visible field in QEMUCursor data structure and passing it from virtio-gpu to the GTK code where we check if the cursor is visible or not. If not, we simply call gdk_window_set_cursor with NULL parameter, thereby hiding the cursor. Once Windows VM switches back to the HW cursor, then IDD would again provide a new resource_id to Qemu and we can start displaying it once more. Signed-off-by: Satyeshwar Singh Cc: Marc-Andr=C3=A9 Lureau Cc: Vivek Kasireddy Cc: Dongwon Kim --- hw/display/virtio-gpu.c | 1 + include/ui/console.h | 1 + ui/gtk.c | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 1c1ee230b3..1ae9be605b 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -98,6 +98,7 @@ static void update_cursor(VirtIOGPU *g, struct virtio_gpu= _update_cursor *cursor) =20 s->current_cursor->hot_x =3D cursor->hot_x; s->current_cursor->hot_y =3D cursor->hot_y; + s->current_cursor->visible =3D cursor->resource_id ? 1 : 0; =20 if (cursor->resource_id > 0) { vgc->update_cursor_data(g, s, cursor->resource_id); diff --git a/include/ui/console.h b/include/ui/console.h index a4a49ffc64..47c39ed405 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -161,6 +161,7 @@ typedef struct QEMUCursor { uint16_t width, height; int hot_x, hot_y; int refcount; + int visible; uint32_t data[]; } QEMUCursor; =20 diff --git a/ui/gtk.c b/ui/gtk.c index 810d7fc796..12a76de570 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -478,6 +478,11 @@ static void gd_cursor_define(DisplayChangeListener *dc= l, return; } =20 + if(!c->visible) { + gdk_window_set_cursor(gtk_widget_get_window(vc->gfx.drawing_area),= NULL); + return; + } + pixbuf =3D gdk_pixbuf_new_from_data((guchar *)(c->data), GDK_COLORSPACE_RGB, true, 8, c->width, c->height, c->width * 4, --=20 2.33.1