From nobody Sat Feb 7 23:10:58 2026 Delivered-To: importer@patchew.org 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; 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1577814404; cv=none; d=zohomail.com; s=zohoarc; b=MatVcmV3A+W9cS4PoxIPHikBPUuDw/hx224+k+zWPTGjHXAUizZESG3AJK0WSups3y1By9jpkgOiYKeYTVHgSf1fpsI7D9TQwi/Za8IL4KYjz/Q7LpSATHTuIPTlBqdAXUC+45h1I0vLGicjWTIY9SUktHBHhZBHq3YBzvjx8/k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577814404; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=gD4xDTxb2j2tgt4EokXc2JdIide3nx0PuHSHsqB6Z8A=; b=LjVXaqQfPp6A6uPrA9ckw+ZiZX0CfbRP1cju+1ANeyiAWuUh4SNVTs6Bk7a/E8yuyOd5SA8KjTeg/vyBa3lMwJUOBA9+mmD9yqXHyClagkKG70Hu5zXkpsfEAgbPCivjiazKBbqsupx74zQlPh7f5aPGRctz0Ah0tifqorE4Ti0= 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577814404484380.9088038186028; Tue, 31 Dec 2019 09:46:44 -0800 (PST) Received: from localhost ([::1]:45050 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1imLbO-0000XJ-O7 for importer@patchew.org; Tue, 31 Dec 2019 12:46:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37936) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1imLaM-0008UD-PP for qemu-devel@nongnu.org; Tue, 31 Dec 2019 12:45:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1imLaL-0000ir-Ep for qemu-devel@nongnu.org; Tue, 31 Dec 2019 12:45:38 -0500 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:33170) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1imLaL-0000ft-6F for qemu-devel@nongnu.org; Tue, 31 Dec 2019 12:45:37 -0500 Received: by mail-wr1-x42c.google.com with SMTP id b6so35737523wrq.0 for ; Tue, 31 Dec 2019 09:45:36 -0800 (PST) Received: from HP-Laptop (93-139-26-156.adsl.net.t-com.hr. [93.139.26.156]) by smtp.gmail.com with ESMTPSA id s10sm50382551wrw.12.2019.12.31.09.45.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Dec 2019 09:45:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:date:user-agent:mime-version :content-transfer-encoding; bh=gD4xDTxb2j2tgt4EokXc2JdIide3nx0PuHSHsqB6Z8A=; b=rGGkY8YLUuC2n6DhY8fangaHw7oqBiFulhVwL2GRzPYzslvgyAseWD+M1sB3aq+jck JQh4q5RMYdP6MPNI+y2DT+j19BObjkKrcxXUzzqDOqeiyvND88Bm3hEyEb4CLDvvi5Dh 9l+1dW5F6a/IpdExD1XAEOqX5Ts4vFLQ6V+vWaTiNui6qMiFOS0BI2OatE+HUBBDtu+3 eBXrRQtrvK91b8JtIkKerjCMNSGRz5EUhLEXJjifEXTjB/Z9G/qca/iGW4ILl8pYQqgf Cwbe1Hwyeni/KrfcZMJrwkSar1QGioNja0q38X3vgdhqqNiETSkp96x7NS1B25IvU/YL ctCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:user-agent :mime-version:content-transfer-encoding; bh=gD4xDTxb2j2tgt4EokXc2JdIide3nx0PuHSHsqB6Z8A=; b=q5UojYMdVzAVoZx30+4RuGxLeWaE0g9Q3w5Y9sMpIn0YOUuhaQcMrAQwefs7Tyd7ME W4n/RFohIRxyV6bNsnPOSmC8+GzwuUnlO9eZMBmcXXY/hBz4ZF2wkiEJcMyCqV0uUL02 d+ApYRP+yRCG5nxQNKCJMktgB32+5eFVnP/Cz2g3zNXfjNUn02Y+cP1XQL7wwiMQCAMv UzCcGpvHsRd7MJO+5W1hUrAoYwYJuXHOHLYUzZQFBvAuvj2AYLqNBz1k2Q21kV/VvIYN FX1hX+gOimGFXSNi6eWaYyEPcsXNU7sDNfeoYqx0CnHfpWVDeH/cz9OfpivvqPc45V7R yPOg== X-Gm-Message-State: APjAAAXeO6HrzVM8fYbPfUaGOn1R+TZlUIv80VZiQ3wWjo5+9FyAJMcv jJ1+eqlOwuV+xkOxuNSdPiYshba5JTXBTg== X-Google-Smtp-Source: APXvYqwB6PlMuFVeOqyy0YneDvIpZqexOs7e0qt/f7bFAuyrVAOEAXe79RUD3xVw4cRxPlDr3EcWLA== X-Received: by 2002:a5d:4fd0:: with SMTP id h16mr70099669wrw.255.1577814335492; Tue, 31 Dec 2019 09:45:35 -0800 (PST) Message-ID: Subject: [PATCH v3] display/gtk: get proper refreshrate From: Nikola Pavlica To: qemu-devel Date: Tue, 31 Dec 2019 18:45:32 +0100 User-Agent: Evolution 3.34.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42c 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: philmd@redhat.com, kraxel@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Type: text/plain; charset="utf-8" From 2d85b4a0edba0bf3fa3c221dcbde7e82a6a771fa Mon Sep 17 00:00:00 2001 From: Nikola Pavlica Date: Tue, 31 Dec 2019 18:16:28 +0100 Subject: [PATCH v3] display/gtk: get proper refreshrate Hi, QEMU mailing list. This is the third revision of the patch involving the GTK display output getting the proper refresh rate for your particular display output. Because some VMs in QEMU can get GPU virtualization (using technologies such as iGVT-g, as mentioned previously), they could produce a video output that had a higher display refresh rate than of what the GTK display was displaying. (fxp. Playing a video game inside of a Windows VM at 60 Hz, while the output stood locked at 33 Hz because of defaults set in include/ui/console.h) Since QEMU does indeed have internal systems for determining frame times as defined in ui/console.c. The code checks for a variable called update_interval that it later uses for time calculation. This variable, however, isn't defined anywhere in ui/gtk.c and instead ui/console.c just sets it to GUI_REFRESH_INTERVAL_DEFAULT which is 30 update_interval represents the number of milliseconds per display refresh, and by doing some math we get that 1000/30 =3D 33.33... Hz This creates the mentioned problem and what this patch does is that it checks for the display refresh rate reported by GTK itself (we can take this as a safe value) and just converts it back to a number of milliseconds per display refresh. Explinations of each revision: v1: initial patch v2: moved code to a more appropriate place and reduced overhead and memory usage (by not creating a new GdkDisplay) v3: removed magic value and turned it into something more readable and added checks for an error state where GTK was unable to get the refresh rate, in which case we use the already existing default P.S. Big thanks to Phil (philmd@redhat.com) for mentioning these issues and for teaching me on how to work with mailing lists. P.S.S. Happy new years :) Signed-off-by: Nikola Pavlica --- include/ui/gtk.h | 2 ++ ui/gtk.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/ui/gtk.h b/include/ui/gtk.h index d9eedad976..d1b230848a 100644 --- a/include/ui/gtk.h +++ b/include/ui/gtk.h @@ -28,6 +28,8 @@ #include "ui/egl-context.h" #endif =20 +#define MILLISEC_PER_SEC 1000000 + typedef struct GtkDisplayState GtkDisplayState; =20 typedef struct VirtualGfxConsole { diff --git a/ui/gtk.c b/ui/gtk.c index 692ccc7bbb..197d962e3e 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -1967,6 +1967,12 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc, { bool zoom_to_fit =3D false; =20 + int refresh_rate_millihz =3D 0; + + GdkDisplay *dpy =3D gtk_widget_get_display(s->window); + GdkWindow *win =3D gtk_widget_get_window(s->window); + GdkMonitor *monitor =3D gdk_display_get_monitor_at_window(dpy, win); + vc->label =3D qemu_console_get_label(con); vc->s =3D s; vc->gfx.scale_x =3D 1.0; @@ -2026,6 +2032,12 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc, =20 vc->gfx.kbd =3D qkbd_state_init(con); vc->gfx.dcl.con =3D con; + + refresh_rate_millihz =3D gdk_monitor_get_refresh_rate(monitor); + if (refresh_rate_millihz) { + vc->gfx.dcl.update_interval =3D MILLISEC_PER_SEC / refresh_rate_millihz; + } + register_displaychangelistener(&vc->gfx.dcl); =20 gd_connect_vc_gfx_signals(vc); --=20 2.24.0