Properly schedule repaints with premature presentation timestamps

The last presentation timestamp might be in the future by a couple of
hundred microseconds.

This may break timestamp aligning code because it assumes that the
last presentation timestamp is less or equal to the current time.

In order to properly handle this case, we have to first compute the
next expected presentation timestamp by advancing the last presentation
timestamp by the amount of vblank interval. If that fails, we can safely
resort to aligning timestamps.

BUG: 431509
BUG: 431449
This commit is contained in:
Vlad Zahorodnii 2021-01-14 15:35:43 +02:00
parent 242439b8af
commit b5a1eba277

View file

@ -40,8 +40,11 @@ void RenderLoopPrivate::scheduleRepaint()
const std::chrono::nanoseconds vblankInterval(1'000'000'000'000ull / refreshRate);
// Estimate when the next presentation will occur. Note that this is a prediction.
nextPresentationTimestamp = lastPresentationTimestamp
+ alignTimestamp(currentTime - lastPresentationTimestamp, vblankInterval);
nextPresentationTimestamp = lastPresentationTimestamp + vblankInterval;
if (nextPresentationTimestamp < currentTime) {
nextPresentationTimestamp = lastPresentationTimestamp
+ alignTimestamp(currentTime - lastPresentationTimestamp, vblankInterval);
}
// Estimate when it's a good time to perform the next compositing cycle.
const std::chrono::nanoseconds safetyMargin = std::chrono::milliseconds(3);