From nobody Tue May 21 10:49:18 2024 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=1578483178; cv=none; d=zohomail.com; s=zohoarc; b=l1T1fpDeUDcBynsKO999X30P+8x707iiJ27YC3b52cdnBmKyb81KG4hLQz3EAbVWV3bI3URR0KlaXRh7sPrz2kO39ro7ScDQ9i9Bh2vwY6R3mXgnCTWP6WggRzW8m1xdO/d91HcmMcwlGRa71ukxovOWjPuZjSelZBXXex7gQc0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578483178; h=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=mE2lnlrRD/lR6rpbLiZ24E0msmA8lV+tPD7M/Fd7f3M=; b=SOXCsEFWIKzw4B/4QETtGhIGRXuxeDdzuBEqYdpCHRO5pB+tHB3EMo+CjH1wHXqcsgdP5sVDs+jOCqFMFNyGk2g/FU3G8NNlO7h2SkkiVjkrZzGwpelkI0RMon9me3OkPOZKwd5FX7ehpDVISKTJTG3SPV9T6XvkZfKvouvHYwI= 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 1578483178561841.4012748634495; Wed, 8 Jan 2020 03:32:58 -0800 (PST) Received: from localhost ([::1]:42306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ip9a4-000593-Hh for importer@patchew.org; Wed, 08 Jan 2020 06:32:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53909) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ip9Xe-0003Pp-3O for qemu-devel@nongnu.org; Wed, 08 Jan 2020 06:30:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ip9Xc-000176-Mb for qemu-devel@nongnu.org; Wed, 08 Jan 2020 06:30:25 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:35726) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ip9Xc-00016A-Ev for qemu-devel@nongnu.org; Wed, 08 Jan 2020 06:30:24 -0500 Received: by mail-wm1-x343.google.com with SMTP id p17so2130611wmb.0 for ; Wed, 08 Jan 2020 03:30:24 -0800 (PST) Received: from localhost.localdomain (93-139-26-156.adsl.net.t-com.hr. [93.139.26.156]) by smtp.gmail.com with ESMTPSA id a14sm4136151wrx.81.2020.01.08.03.30.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jan 2020 03:30:22 -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:mime-version :content-transfer-encoding; bh=mE2lnlrRD/lR6rpbLiZ24E0msmA8lV+tPD7M/Fd7f3M=; b=I9Eg9LCjsT3Kt8rux7TNLu8q5LNnJPKs/F/wYFUJOGoDuVOaqy3DKW3fx162+cu7K4 MIF0jvIJID0jOX5VItlA+KV0Nt+hUVIJv+L+qYX038RNrrN2PLLNLvF8cEjbt/p7wUmN m3UepPBGpN896oxKI655BSoSm9XMPtoYtG+0wd/xFJgc4uIiDnsGtdfE8EHhCA9PPlvx U+KOlz8+t20Gzf7PuZIdPgqbNzQWHbGGswdVuQ0KIuEH0jDlFNIgljoOjNRSPYSqLcmP StAv6ARYMYQzOpaTk9v8266j5gYGdvDvt56BxXitpQ1BLJWghbiB2OHZStFa3BV59qUq JJzA== 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:mime-version :content-transfer-encoding; bh=mE2lnlrRD/lR6rpbLiZ24E0msmA8lV+tPD7M/Fd7f3M=; b=IVC75l5cFRADm3JklFFLlD8H9B0EEt2y0a9HHGBCXoAHJ6LjwFhNBxoHMmp7rBhdQs LCQSRSIBO/kxfQLyrC7M5d7O5lqJ8AIB6Nv354VGYq4kpMHseX4t4JKld9P5QcuPrmGY EfRXZMeWZd4EO3J+ImWzBGZMgaGzbSm9bv17RFyZbjHZnJdjA3GfqavYhO3NjtMWVHNR 5Ta/PpEeoGn0lgbjRzFSQcuiefmX1Tf1FurmIIWjdCJkXV4ASHddUeYOBQr81GrxHKPr TLXbcxQ3Bda1fbpZ47oESkQYGtfYDuMYYAZ+kDiY1yUNp00Jj4O4qUny10mGzSe/uA2n 9FzA== X-Gm-Message-State: APjAAAVYQy1tigeChDWrEdi6XqcpzQj5opznw5Dl7tYTMtl/kBx/B9bZ kS/GoNizpDY6dE/pmrdlZzpL0ShCInpEzQ== X-Google-Smtp-Source: APXvYqxR5eE/rpQpHjVMK9zZACfywR6ZsXQfqO6NwiWlu6kZ7zefuRP32hnbM0X93XHlsx3MI2Ikyw== X-Received: by 2002:a7b:c386:: with SMTP id s6mr3257020wmj.105.1578483023327; Wed, 08 Jan 2020 03:30:23 -0800 (PST) From: pavlica.nikola@gmail.com To: qemu-devel@nongnu.org Subject: [PATCH v4] display/gtk: get proper refreshrate Date: Wed, 8 Jan 2020 12:27:47 +0100 Message-Id: <20200108112747.25249-1-pavlica.nikola@gmail.com> X-Mailer: git-send-email 2.24.1 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::343 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: kraxel@redhat.com, Nikola Pavlica 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: Nikola Pavlica Hi, QEMU mailing list. This is the fourth 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 v4: fixed wrapping and repositioned variable names Signed-off-by: Nikola Pavlica --- include/ui/gtk.h | 2 ++ ui/gtk.c | 10 ++++++++++ 2 files changed, 12 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..eb0efc70ee 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -1966,6 +1966,10 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, Vi= rtualConsole *vc, GSList *group, GtkWidget *view_menu) { bool zoom_to_fit =3D false; + int refresh_rate_millihz; + 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); =20 vc->label =3D qemu_console_get_label(con); vc->s =3D s; @@ -2026,6 +2030,12 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, Vi= rtualConsole *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_mi= llihz; + } + register_displaychangelistener(&vc->gfx.dcl); =20 gd_connect_vc_gfx_signals(vc); --=20 2.24.1