summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2023-01-04 17:24:59 +0100
committerLaszlo Agocs <laszlo.agocs@qt.io>2023-01-09 12:49:15 +0100
commit08b71d8619e2ad3dae8790e498860d3ced2b0851 (patch)
treeaa057936a7ce4d1c27ea2f68358380cf686af446
parentb53701d3aad7ba2e7b1e7d4590748c56826f1004 (diff)
Scale the default 5 ms requestUpdate interval based on the refreshRate
5 ms barely works for 144 Hz screens (when we have 6.94 ms altogether). For 240 Hz (4.16 ms) it is definitely wrong. Instead of picking another fixed value, scale based on the reported refresh rate. (60 -> 5, 144 -> 2, 240 -> 1) Fixes: QTBUG-109679 Change-Id: I75d91d8e351149987f4afd673d6dedbda2fb388a Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Andy Nichols <andy.nichols@qt.io>
-rw-r--r--src/gui/kernel/qplatformwindow.cpp25
-rw-r--r--src/gui/kernel/qwindow.cpp12
2 files changed, 24 insertions, 13 deletions
diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp
index d1bbbe5c39..e2c9fc4141 100644
--- a/src/gui/kernel/qplatformwindow.cpp
+++ b/src/gui/kernel/qplatformwindow.cpp
@@ -727,20 +727,29 @@ QRect QPlatformWindow::initialGeometry(const QWindow *w, const QRect &initialGeo
should be delivered using QPlatformWindow::deliverUpdateRequest()
to not get out of sync with the internal state of QWindow.
- The default implementation posts an UpdateRequest event to the
- window after 5 ms. The additional time is there to give the event
- loop a bit of idle time to gather system events.
+ The default implementation posts an UpdateRequest event to the window after
+ an interval that is at most 5 ms. If the window's associated screen reports
+ a \l{QPlatformScreen::refreshRate()}{refresh rate} higher than 60 Hz, the
+ interval is scaled down to a valid smaller than 5. The additional time is
+ there to give the event loop a bit of idle time to gather system events.
*/
void QPlatformWindow::requestUpdate()
{
Q_D(QPlatformWindow);
- static int updateInterval = []() {
- bool ok = false;
- int customUpdateInterval = qEnvironmentVariableIntValue("QT_QPA_UPDATE_IDLE_TIME", &ok);
- return ok ? customUpdateInterval : 5;
- }();
+ static bool customUpdateIntervalValid = false;
+ static int customUpdateInterval = qEnvironmentVariableIntValue("QT_QPA_UPDATE_IDLE_TIME",
+ &customUpdateIntervalValid);
+ int updateInterval = customUpdateInterval;
+ if (!customUpdateIntervalValid) {
+ updateInterval = 5;
+ if (QPlatformScreen *currentScreen = screen()) {
+ const qreal refreshRate = currentScreen->refreshRate();
+ if (refreshRate > 60.0)
+ updateInterval /= refreshRate / 60.0;
+ }
+ }
Q_ASSERT(!d->updateTimer.isActive());
d->updateTimer.start(updateInterval, Qt::PreciseTimer, window());
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index 313b67ad61..1e368914f3 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -2567,11 +2567,13 @@ bool QWindow::event(QEvent *ev)
/*!
Schedules a QEvent::UpdateRequest event to be delivered to this window.
- The event is delivered in sync with the display vsync on platforms
- where this is possible. Otherwise, the event is delivered after a
- delay of 5 ms. The additional time is there to give the event loop
- a bit of idle time to gather system events, and can be overridden
- using the QT_QPA_UPDATE_IDLE_TIME environment variable.
+ The event is delivered in sync with the display vsync on platforms where
+ this is possible. Otherwise, the event is delivered after a delay of at
+ most 5 ms. If the window's associated screen reports a
+ \l{QScreen::refreshRate()}{refresh rate} higher than 60 Hz, the interval is
+ scaled down to a value smaller than 5. The additional time is there to give
+ the event loop a bit of idle time to gather system events, and can be
+ overridden using the QT_QPA_UPDATE_IDLE_TIME environment variable.
When driving animations, this function should be called once after drawing
has completed. Calling this function multiple times will result in a single