Commit f3b291bc authored by Vlad Zahorodnii's avatar Vlad Zahorodnii Committed by Merge Service
Browse files

Make TimeLine API ergonomic with presentation timestamps

Currently, if you want to use TimeLine, you need to track the last
presentation timestamp which boils down to carrying some boilerplate
code.

The current situation can be improved by making TimeLine work with
presentation timestamps.

Part-of: <!2473>
parent 6a5173b6
Pipeline #181202 passed with stage
in 31 minutes and 56 seconds
......@@ -48,26 +48,27 @@ void TimeLineTest::testUpdateForward()
timeLine.setEasingCurve(QEasingCurve::Linear);
// 0/1000
timeLine.advance(0ms);
QCOMPARE(timeLine.value(), 0.0);
QVERIFY(!timeLine.done());
// 100/1000
timeLine.update(100ms);
timeLine.advance(100ms);
QCOMPARE(timeLine.value(), 0.1);
QVERIFY(!timeLine.done());
// 400/1000
timeLine.update(300ms);
timeLine.advance(400ms);
QCOMPARE(timeLine.value(), 0.4);
QVERIFY(!timeLine.done());
// 900/1000
timeLine.update(500ms);
timeLine.advance(900ms);
QCOMPARE(timeLine.value(), 0.9);
QVERIFY(!timeLine.done());
// 1000/1000
timeLine.update(3000ms);
timeLine.advance(3000ms);
QCOMPARE(timeLine.value(), 1.0);
QVERIFY(timeLine.done());
}
......@@ -78,26 +79,27 @@ void TimeLineTest::testUpdateBackward()
timeLine.setEasingCurve(QEasingCurve::Linear);
// 0/1000
timeLine.advance(0ms);
QCOMPARE(timeLine.value(), 1.0);
QVERIFY(!timeLine.done());
// 100/1000
timeLine.update(100ms);
timeLine.advance(100ms);
QCOMPARE(timeLine.value(), 0.9);
QVERIFY(!timeLine.done());
// 400/1000
timeLine.update(300ms);
timeLine.advance(400ms);
QCOMPARE(timeLine.value(), 0.6);
QVERIFY(!timeLine.done());
// 900/1000
timeLine.update(500ms);
timeLine.advance(900ms);
QCOMPARE(timeLine.value(), 0.1);
QVERIFY(!timeLine.done());
// 1000/1000
timeLine.update(3000ms);
timeLine.advance(3000ms);
QCOMPARE(timeLine.value(), 0.0);
QVERIFY(timeLine.done());
}
......@@ -105,13 +107,14 @@ void TimeLineTest::testUpdateBackward()
void TimeLineTest::testUpdateFinished()
{
KWin::TimeLine timeLine(1000ms, KWin::TimeLine::Forward);
timeLine.advance(0ms);
timeLine.setEasingCurve(QEasingCurve::Linear);
timeLine.update(1000ms);
timeLine.advance(1000ms);
QCOMPARE(timeLine.value(), 1.0);
QVERIFY(timeLine.done());
timeLine.update(42ms);
timeLine.advance(1042ms);
QCOMPARE(timeLine.value(), 1.0);
QVERIFY(timeLine.done());
}
......@@ -121,10 +124,11 @@ void TimeLineTest::testToggleDirection()
KWin::TimeLine timeLine(1000ms, KWin::TimeLine::Forward);
timeLine.setEasingCurve(QEasingCurve::Linear);
timeLine.advance(0ms);
QCOMPARE(timeLine.value(), 0.0);
QVERIFY(!timeLine.done());
timeLine.update(600ms);
timeLine.advance(600ms);
QCOMPARE(timeLine.value(), 0.6);
QVERIFY(!timeLine.done());
......@@ -132,11 +136,11 @@ void TimeLineTest::testToggleDirection()
QCOMPARE(timeLine.value(), 0.6);
QVERIFY(!timeLine.done());
timeLine.update(200ms);
timeLine.advance(800ms);
QCOMPARE(timeLine.value(), 0.4);
QVERIFY(!timeLine.done());
timeLine.update(3000ms);
timeLine.advance(3000ms);
QCOMPARE(timeLine.value(), 0.0);
QVERIFY(timeLine.done());
}
......@@ -145,8 +149,9 @@ void TimeLineTest::testReset()
{
KWin::TimeLine timeLine(1000ms, KWin::TimeLine::Forward);
timeLine.setEasingCurve(QEasingCurve::Linear);
timeLine.advance(0ms);
timeLine.update(1000ms);
timeLine.advance(1000ms);
QCOMPARE(timeLine.value(), 1.0);
QVERIFY(timeLine.done());
......@@ -181,9 +186,10 @@ void TimeLineTest::testSetElapsed()
KWin::TimeLine timeLine(duration, KWin::TimeLine::Forward);
timeLine.setEasingCurve(QEasingCurve::Linear);
timeLine.advance(0ms);
if (initiallyDone) {
timeLine.update(duration);
timeLine.advance(duration);
QVERIFY(timeLine.done());
}
......@@ -207,8 +213,9 @@ void TimeLineTest::testSetDurationRetargeting()
{
KWin::TimeLine timeLine(1000ms, KWin::TimeLine::Forward);
timeLine.setEasingCurve(QEasingCurve::Linear);
timeLine.advance(0ms);
timeLine.update(500ms);
timeLine.advance(500ms);
QCOMPARE(timeLine.value(), 0.5);
QVERIFY(!timeLine.done());
......@@ -221,8 +228,9 @@ void TimeLineTest::testSetDurationRetargetingSmallDuration()
{
KWin::TimeLine timeLine(1000ms, KWin::TimeLine::Forward);
timeLine.setEasingCurve(QEasingCurve::Linear);
timeLine.advance(0ms);
timeLine.update(999ms);
timeLine.advance(999ms);
QCOMPARE(timeLine.value(), 0.999);
QVERIFY(!timeLine.done());
......@@ -235,15 +243,16 @@ void TimeLineTest::testRunning()
{
KWin::TimeLine timeLine(1000ms, KWin::TimeLine::Forward);
timeLine.setEasingCurve(QEasingCurve::Linear);
timeLine.advance(0ms);
QVERIFY(!timeLine.running());
QVERIFY(!timeLine.done());
timeLine.update(100ms);
timeLine.advance(100ms);
QVERIFY(timeLine.running());
QVERIFY(!timeLine.done());
timeLine.update(900ms);
timeLine.advance(1000ms);
QVERIFY(!timeLine.running());
QVERIFY(timeLine.done());
}
......@@ -333,6 +342,7 @@ void TimeLineTest::testStrictRedirectTargetMode()
KWin::TimeLine timeLine(1000ms, initialDirection);
timeLine.setEasingCurve(QEasingCurve::Linear);
timeLine.setTargetRedirectMode(KWin::TimeLine::RedirectMode::Strict);
timeLine.advance(0ms);
QTEST(timeLine.direction(), "initialDirection");
QTEST(timeLine.value(), "initialValue");
......@@ -340,7 +350,7 @@ void TimeLineTest::testStrictRedirectTargetMode()
QVERIFY(!timeLine.running());
QVERIFY(!timeLine.done());
timeLine.update(1000ms);
timeLine.advance(1000ms);
QTEST(timeLine.value(), "finalValue");
QVERIFY(!timeLine.running());
QVERIFY(timeLine.done());
......@@ -371,6 +381,7 @@ void TimeLineTest::testRelaxedRedirectTargetMode()
KWin::TimeLine timeLine(1000ms, initialDirection);
timeLine.setEasingCurve(QEasingCurve::Linear);
timeLine.setTargetRedirectMode(KWin::TimeLine::RedirectMode::Relaxed);
timeLine.advance(0ms);
QTEST(timeLine.direction(), "initialDirection");
QTEST(timeLine.value(), "initialValue");
......@@ -378,20 +389,21 @@ void TimeLineTest::testRelaxedRedirectTargetMode()
QVERIFY(!timeLine.running());
QVERIFY(!timeLine.done());
timeLine.update(1000ms);
timeLine.advance(1000ms);
QTEST(timeLine.value(), "finalValue");
QVERIFY(!timeLine.running());
QVERIFY(timeLine.done());
QFETCH(KWin::TimeLine::Direction, finalDirection);
timeLine.setDirection(finalDirection);
timeLine.advance(1000ms);
QTEST(timeLine.direction(), "finalDirection");
QTEST(timeLine.value(), "finalValue");
QVERIFY(!timeLine.running());
QVERIFY(!timeLine.done());
timeLine.update(1000ms);
timeLine.advance(2000ms);
QTEST(timeLine.direction(), "finalDirection");
QTEST(timeLine.value(), "initialValue");
QVERIFY(!timeLine.running());
......
......@@ -87,7 +87,6 @@ bool BlendChanges::isActive() const
void BlendChanges::postPaintScreen()
{
if (m_timeline.done()) {
m_lastPresentTime = std::chrono::milliseconds::zero();
m_timeline.reset();
m_state = Off;
......@@ -105,12 +104,7 @@ void BlendChanges::prePaintScreen(ScreenPrePaintData &data, std::chrono::millise
return;
}
if (m_state == Blending) {
std::chrono::milliseconds delta(0);
if (m_lastPresentTime.count()) {
delta = presentTime - m_lastPresentTime;
}
m_lastPresentTime = presentTime;
m_timeline.update(delta);
m_timeline.advance(presentTime);
}
effects->prePaintScreen(data, presentTime);
......
......@@ -41,7 +41,6 @@ public Q_SLOTS:
private:
TimeLine m_timeline;
std::chrono::milliseconds m_lastPresentTime = std::chrono::milliseconds::zero();
enum State {
Off,
ShowingCache,
......
......@@ -84,19 +84,13 @@ void DimInactiveEffect::reconfigure(ReconfigureFlags flags)
void DimInactiveEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime)
{
std::chrono::milliseconds delta(0);
if (m_lastPresentTime.count()) {
delta = presentTime - m_lastPresentTime;
}
m_lastPresentTime = presentTime;
if (m_fullScreenTransition.active) {
m_fullScreenTransition.timeLine.update(delta);
m_fullScreenTransition.timeLine.advance(presentTime);
}
auto transitionIt = m_transitions.begin();
while (transitionIt != m_transitions.end()) {
(*transitionIt).update(delta);
(*transitionIt).advance(presentTime);
++transitionIt;
}
......@@ -148,10 +142,6 @@ void DimInactiveEffect::postPaintScreen()
w->addRepaintFull();
}
if (m_transitions.isEmpty() && !m_fullScreenTransition.active) {
m_lastPresentTime = std::chrono::milliseconds::zero();
}
effects->postPaintScreen();
}
......
......@@ -77,7 +77,6 @@ private:
const EffectWindowGroup *m_activeWindowGroup;
QHash<EffectWindow *, TimeLine> m_transitions;
QHash<EffectWindow *, qreal> m_forceDim;
std::chrono::milliseconds m_lastPresentTime = std::chrono::milliseconds::zero();
struct
{
......
......@@ -70,13 +70,7 @@ void GlideEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::millisec
{
auto animationIt = m_animations.begin();
while (animationIt != m_animations.end()) {
std::chrono::milliseconds delta = std::chrono::milliseconds::zero();
if (animationIt->lastPresentTime.count()) {
delta = presentTime - animationIt->lastPresentTime;
}
animationIt->lastPresentTime = presentTime;
(*animationIt).timeLine.update(delta);
(*animationIt).timeLine.advance(presentTime);
++animationIt;
}
......
......@@ -24,7 +24,6 @@ struct GlideAnimation
EffectWindowDeletedRef deletedRef;
EffectWindowVisibleRef visibleRef;
TimeLine timeLine;
std::chrono::milliseconds lastPresentTime = std::chrono::milliseconds::zero();
};
class GlideEffect : public Effect
......
......@@ -95,25 +95,16 @@ void KscreenEffect::reconfigure(ReconfigureFlags flags)
void KscreenEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime)
{
if (isScreenActive(data.screen)) {
std::chrono::milliseconds delta = std::chrono::milliseconds::zero();
auto &state = !effects->waylandDisplay() ? m_xcbState : m_waylandStates[data.screen];
m_currentScreen = data.screen;
if (state.m_lastPresentTime.count()) {
delta = presentTime - state.m_lastPresentTime;
}
if (state.m_state == StateFadingIn || state.m_state == StateFadingOut) {
state.m_timeLine.update(delta);
state.m_timeLine.advance(presentTime);
if (state.m_timeLine.done()) {
switchState(state);
m_waylandStates.remove(data.screen);
}
}
if (isActive()) {
state.m_lastPresentTime = presentTime;
} else {
state.m_lastPresentTime = std::chrono::milliseconds::zero();
}
}
effects->prePaintScreen(data, presentTime);
......@@ -177,7 +168,6 @@ void KscreenEffect::setState(ScreenState &state, FadeOutState newState)
state.m_state = newState;
state.m_timeLine.reset();
state.m_lastPresentTime = std::chrono::milliseconds::zero();
effects->addRepaintFull();
}
......
......@@ -49,7 +49,6 @@ private:
struct ScreenState
{
TimeLine m_timeLine;
std::chrono::milliseconds m_lastPresentTime = std::chrono::milliseconds::zero();
FadeOutState m_state = StateNormal;
};
......
......@@ -46,13 +46,7 @@ void MagicLampEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::mill
{
auto animationIt = m_animations.begin();
while (animationIt != m_animations.end()) {
std::chrono::milliseconds delta = std::chrono::milliseconds::zero();
if (animationIt->lastPresentTime.count()) {
delta = presentTime - animationIt->lastPresentTime;
}
animationIt->lastPresentTime = presentTime;
(*animationIt).timeLine.update(delta);
(*animationIt).timeLine.advance(presentTime);
++animationIt;
}
......
......@@ -19,7 +19,6 @@ struct MagicLampAnimation
{
EffectWindowVisibleRef visibleRef;
TimeLine timeLine;
std::chrono::milliseconds lastPresentTime = std::chrono::milliseconds::zero();
};
class MagicLampEffect : public DeformEffect
......
......@@ -52,7 +52,6 @@ void ScreenTransformEffect::addScreen(EffectScreen *screen)
}
state.m_timeLine.setDuration(std::chrono::milliseconds(long(animationTime(250))));
state.m_timeLine.setEasingCurve(QEasingCurve::OutCirc);
state.m_lastPresentTime = std::chrono::milliseconds::zero();
state.m_angle = transformAngle(screen->transform(), state.m_oldTransform);
Q_ASSERT(state.m_angle != 0);
effects->addRepaintFull();
......@@ -85,17 +84,12 @@ void ScreenTransformEffect::removeScreen(EffectScreen *screen)
void ScreenTransformEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime)
{
if (isScreenTransforming(data.screen)) {
std::chrono::milliseconds delta = std::chrono::milliseconds::zero();
auto &state = m_states[data.screen];
if (state.m_lastPresentTime.count()) {
delta = presentTime - state.m_lastPresentTime;
}
state.m_lastPresentTime = presentTime;
if (state.isSecondHalf()) {
data.mask |= PAINT_SCREEN_TRANSFORMED;
}
state.m_timeLine.update(delta);
state.m_timeLine.advance(presentTime);
if (state.m_timeLine.done()) {
m_states.remove(data.screen);
}
......
......@@ -48,7 +48,6 @@ private:
TimeLine m_timeLine;
QSharedPointer<GLTexture> m_texture;
std::chrono::milliseconds m_lastPresentTime = std::chrono::milliseconds::zero();
EffectScreen::Transform m_oldTransform;
qreal m_angle = 0;
bool m_captured = false;
......
......@@ -48,13 +48,7 @@ void SheetEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::millisec
{
auto animationIt = m_animations.begin();
while (animationIt != m_animations.end()) {
std::chrono::milliseconds delta = std::chrono::milliseconds::zero();
if (animationIt->lastPresentTime.count()) {
delta = presentTime - animationIt->lastPresentTime;
}
animationIt->lastPresentTime = presentTime;
(*animationIt).timeLine.update(delta);
(*animationIt).timeLine.advance(presentTime);
++animationIt;
}
......
......@@ -57,7 +57,6 @@ private:
EffectWindowVisibleRef visibleRef;
TimeLine timeLine;
int parentY;
std::chrono::milliseconds lastPresentTime = std::chrono::milliseconds::zero();
};
QHash<EffectWindow *, Animation> m_animations;
......
......@@ -123,13 +123,7 @@ void SlidingPopupsEffect::prePaintWindow(EffectWindow *w, WindowPrePaintData &da
return;
}
std::chrono::milliseconds delta = std::chrono::milliseconds::zero();
if (animationIt->lastPresentTime.count()) {
delta = presentTime - animationIt->lastPresentTime;
}
animationIt->lastPresentTime = presentTime;
(*animationIt).timeLine.update(delta);
(*animationIt).timeLine.advance(presentTime);
data.setTransformed();
effects->prePaintWindow(w, data, presentTime);
......
......@@ -86,7 +86,6 @@ private:
EffectWindowVisibleRef visibleRef;
AnimationKind kind;
TimeLine timeLine;
std::chrono::milliseconds lastPresentTime = std::chrono::milliseconds::zero();
};
QHash<EffectWindow *, Animation> m_animations;
......
......@@ -83,14 +83,8 @@ void SnapHelperEffect::reconfigure(ReconfigureFlags flags)
void SnapHelperEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime)
{
std::chrono::milliseconds delta = std::chrono::milliseconds::zero();
if (m_animation.lastPresentTime.count()) {
delta = (presentTime - m_animation.lastPresentTime);
}
m_animation.lastPresentTime = presentTime;
if (m_animation.active) {
m_animation.timeLine.update(delta);
m_animation.timeLine.advance(presentTime);
}
effects->prePaintScreen(data, presentTime);
......@@ -191,7 +185,6 @@ void SnapHelperEffect::postPaintScreen()
if (m_animation.timeLine.done()) {
m_animation.active = false;
m_animation.lastPresentTime = std::chrono::milliseconds::zero();
}
effects->postPaintScreen();
......
......@@ -46,7 +46,6 @@ private:
{
bool active = false;
TimeLine timeLine;
std::chrono::milliseconds lastPresentTime = std::chrono::milliseconds::zero();
};
Animation m_animation;
......
......@@ -54,7 +54,6 @@ AniData::AniData()
, frozenTime(-1)
, waitAtSource(false)
, keepAlive(true)
, lastPresentTime(std::chrono::milliseconds::zero())
{
}
......@@ -72,7 +71,6 @@ AniData::AniData(AnimationEffect::Attribute a, int meta_, const FPx2 &to_,
, waitAtSource(waitAtSource_)
, keepAlive(keepAlive)
, previousWindowPixmapLock(std::move(previousWindowPixmapLock_))
, lastPresentTime(std::chrono::milliseconds::zero())
, shader(shader)
{
}
......
Supports Markdown
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