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>
bb10
Laszlo Agocs 2023-01-04 17:24:59 +01:00
parent b53701d3aa
commit 08b71d8619
2 changed files with 24 additions and 13 deletions

View File

@ -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());

View File

@ -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