Bug 1675887 - Respect the time value that's passed to Choreographer.FrameCallback.doFrame. r=kats

This makes the vsync times more consistent.
On a Pixel 2 running Android 11, the callback was called between 1ms and 6ms
after the vsync timestamp in my tests. Having the vsync timestamp slightly in
the past is what the rest of our vsync infrastructure expects.

Differential Revision: https://phabricator.services.mozilla.com/D96279
This commit is contained in:
Markus Stange 2020-11-09 18:32:13 +00:00
parent 7ddc009e5e
commit cb3b5afd46
2 changed files with 13 additions and 4 deletions

View File

@ -298,9 +298,18 @@ class AndroidVsyncSource final : public VsyncSource {
using Base = java::VsyncSource::Natives<JavaVsyncSupport>;
using Base::DisposeNative;
static void NotifyVsync() {
static void NotifyVsync(int64_t aFrameTimeNanos) {
// Convert aFrameTimeNanos to a TimeStamp. The value converts trivially to
// the internal ticks representation of TimeStamp_posix; both use the
// monotonic clock and are in nanoseconds.
TimeStamp nativeTime = TimeStamp::FromSystemTime(aFrameTimeNanos);
// Use the timebase from the frame callback as the vsync time, unless it
// is in the future.
TimeStamp now = TimeStamp::Now();
TimeStamp vsyncTime = nativeTime < now ? nativeTime : now;
Display& display = GetDisplayInstance();
TimeStamp vsyncTime = TimeStamp::Now();
TimeStamp outputTime = vsyncTime + display.GetVsyncRate();
display.NotifyVsync(vsyncTime, outputTime);
}

View File

@ -42,13 +42,13 @@ import org.mozilla.gecko.GeckoAppShell;
}
@WrapForJNI(stubName = "NotifyVsync")
private static native void nativeNotifyVsync();
private static native void nativeNotifyVsync(final long frameTimeNanos);
// Choreographer callback implementation.
public void doFrame(final long frameTimeNanos) {
if (mObservingVsync) {
mChoreographer.postFrameCallback(this);
nativeNotifyVsync();
nativeNotifyVsync(frameTimeNanos);
}
}