Commit a039f3ba authored by Vlad Zahorodnii's avatar Vlad Zahorodnii

[wayland] Send correct current time in the frame callback

Summary:
Currently, each frame callback sent by KWin has the current time in
nanoseconds, but the protocol spec states that we have to send the time
in milliseconds. This is the reason why animations that are driven by
frame callbacks are too fast.

In addition to that, m_timeSinceStart isn't actually "time since start,"
it's rather accumulated duration of all painting cycles. If there is
something to draw and it takes quite a while to compose the scene, maybe
m_timeSinceStart will be close enough to the current time. So, it has
been replaced with QElapsedTimer, this makes the current time correct
and also simplifies code a little bit.

Test Plan: The triangle in weston-subsurfaces no longer spins very fast.

Reviewers: #kwin, romangg

Reviewed By: #kwin, romangg

Subscribers: romangg, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D18656
parent dffd9777
......@@ -101,7 +101,7 @@ Compositor::Compositor(QObject* workspace)
connect(&compositeResetTimer, SIGNAL(timeout()), SLOT(restart()));
connect(options, &Options::configChanged, this, &Compositor::slotConfigChanged);
compositeResetTimer.setSingleShot(true);
nextPaintReference.invalidate(); // Initialize the timer
m_monotonicClock.start();
// 2 sec which should be enough to restart the compositor
static const int compositorLostMessageDelay = 2000;
......@@ -727,7 +727,6 @@ void Compositor::performCompositing()
if (repaints_region.isEmpty() && !windowRepaintsPending()) {
m_scene->idle();
m_timeSinceLastVBlank = fpsInterval - (options->vBlankTime() + 1); // means "start now"
m_timeSinceStart += m_timeSinceLastVBlank;
// Note: It would seem here we should undo suspended unredirect, but when scenes need
// it for some reason, e.g. transformations or translucency, the next pass that does not
// need this anymore and paints normally will also reset the suspended unredirect.
......@@ -769,12 +768,12 @@ void Compositor::performCompositing()
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostLastGuardedFrame);
}
}
m_timeSinceStart += m_timeSinceLastVBlank;
if (waylandServer()) {
const auto currentTime = static_cast<quint32>(m_monotonicClock.elapsed());
for (Toplevel *win : qAsConst(windows)) {
if (auto surface = win->surface()) {
surface->frameRendered(m_timeSinceStart);
surface->frameRendered(currentTime);
}
}
}
......
......@@ -222,18 +222,17 @@ private:
QTimer m_unusedSupportPropertyTimer;
qint64 vBlankInterval, fpsInterval;
int m_xrrRefreshRate;
QElapsedTimer nextPaintReference;
QRegion repaints_region;
QTimer compositeResetTimer; // for compressing composite resets
bool m_finishing; // finish() sets this variable while shutting down
bool m_starting; // start() sets this variable while starting
qint64 m_timeSinceLastVBlank;
qint64 m_timeSinceStart = 0;
Scene *m_scene;
bool m_bufferSwapPending;
bool m_composeAtSwapCompletion;
int m_framesToTestForSafety = 3;
QElapsedTimer m_monotonicClock;
KWIN_SINGLETON_VARIABLE(Compositor, s_compositor)
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment