mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 14:57:20 +00:00
[client] x11: improve presentation sync calibration
This commit is contained in:
parent
162b1b93db
commit
ad256e0b00
@ -90,19 +90,18 @@ static void x11DoPresent(void)
|
|||||||
x11.presentSerial++,
|
x11.presentSerial++,
|
||||||
x11.presentRegion, // valid
|
x11.presentRegion, // valid
|
||||||
x11.presentRegion, // update
|
x11.presentRegion, // update
|
||||||
0, // x_off,
|
0, // x_off,
|
||||||
0, // y_off,
|
0, // y_off,
|
||||||
0, // target_crtc
|
None, // target_crtc
|
||||||
None, // wait_fence
|
None, // wait_fence
|
||||||
None, // idle_fence
|
None, // idle_fence
|
||||||
0, // options
|
PresentOptionNone, // options
|
||||||
0, // target_msc,
|
0, // target_msc,
|
||||||
0, // divisor,
|
0, // divisor,
|
||||||
0, // remainder,
|
0, // remainder,
|
||||||
NULL, // notifies
|
NULL, // notifies
|
||||||
0 // nnotifies
|
0 // nnotifies
|
||||||
);
|
);
|
||||||
XFlush(x11.display);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void x11Setup(void)
|
static void x11Setup(void)
|
||||||
@ -708,7 +707,7 @@ static int x11EventThread(void * unused)
|
|||||||
|
|
||||||
case Expose:
|
case Expose:
|
||||||
{
|
{
|
||||||
app_invalidateWindow(true);
|
app_invalidateWindow(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1133,10 +1132,28 @@ static bool x11WaitFrame(void)
|
|||||||
/* wait until we are woken up by the present event */
|
/* wait until we are woken up by the present event */
|
||||||
lgWaitEvent(x11.frameEvent, TIMEOUT_INFINITE);
|
lgWaitEvent(x11.frameEvent, TIMEOUT_INFINITE);
|
||||||
|
|
||||||
|
#define WARMUP_TIME 3000000 //2s
|
||||||
#define CALIBRATION_COUNT 400
|
#define CALIBRATION_COUNT 400
|
||||||
const uint64_t ust = atomic_load(&x11.presentUst);
|
const uint64_t ust = atomic_load(&x11.presentUst);
|
||||||
const uint64_t msc = atomic_load(&x11.presentMsc);
|
const uint64_t msc = atomic_load(&x11.presentMsc);
|
||||||
|
|
||||||
|
static bool warmup = true;
|
||||||
|
if (warmup)
|
||||||
|
{
|
||||||
|
static uint64_t expire = 0;
|
||||||
|
if (!expire)
|
||||||
|
{
|
||||||
|
DEBUG_INFO("Warming up...");
|
||||||
|
expire = ust + WARMUP_TIME;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ust < expire)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
warmup = false;
|
||||||
|
DEBUG_INFO("Warmup done, doing calibration...");
|
||||||
|
}
|
||||||
|
|
||||||
/* calibrate a delay to push our presentation time forward as far as
|
/* calibrate a delay to push our presentation time forward as far as
|
||||||
* possible without skipping frames */
|
* possible without skipping frames */
|
||||||
static int calibrate = 0;
|
static int calibrate = 0;
|
||||||
@ -1192,7 +1209,16 @@ static bool x11WaitFrame(void)
|
|||||||
|
|
||||||
/* if we have finished, print out the delay */
|
/* if we have finished, print out the delay */
|
||||||
if (++calibrate == CALIBRATION_COUNT)
|
if (++calibrate == CALIBRATION_COUNT)
|
||||||
DEBUG_INFO("Calibration done, delay = %lu us", delay);
|
{
|
||||||
|
/* delays shorter then 1ms are unmaintainable */
|
||||||
|
if (delay < 1000)
|
||||||
|
{
|
||||||
|
delay = 0;
|
||||||
|
DEBUG_INFO("Calibration done, no delay required");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
DEBUG_INFO("Calibration done, delay = %lu us", delay);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1200,9 +1226,28 @@ static bool x11WaitFrame(void)
|
|||||||
lastts = ust;
|
lastts = ust;
|
||||||
lastmsc = msc;
|
lastmsc = msc;
|
||||||
|
|
||||||
/* minor adjustments if we are still seeing odd skips */
|
/* adjustments if we are still seeing odd skips */
|
||||||
if (deltamsc > 1 && delay - 10 < delay)
|
if (delay > 0 && deltamsc > 1)
|
||||||
delay -= 10;
|
{
|
||||||
|
/* only adjust if the last skip was less then 1s ago */
|
||||||
|
static uint64_t lastSkip = 0;
|
||||||
|
const bool adjust = ust - lastSkip < 1000000UL;
|
||||||
|
lastSkip = ust;
|
||||||
|
|
||||||
|
if (adjust)
|
||||||
|
{
|
||||||
|
if (delay - 500 < delay)
|
||||||
|
{
|
||||||
|
delay -= 500;
|
||||||
|
DEBUG_INFO("Excessing skipping detected, reduced calibration delay to %lu us", delay);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
delay = 0;
|
||||||
|
DEBUG_WARN("Excessive skipping detected, calibration delay disabled");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (delay)
|
if (delay)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user