Commit a782190e authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

VR: Fix rounding error in VSync computation.

Also fixes the timebase being off by a factor of 1000, though this
didn't actually cause issues...

Bug: 745866
Change-Id: Ia29646ce935bf66b45a5f6aee10bf7715a3fea17
Reviewed-on: https://chromium-review.googlesource.com/575700
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarChristopher Grant <cjgrant@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487648}
parent 3ebd3007
......@@ -117,7 +117,7 @@ void VrShellDelegate::UpdateVSyncInterval(JNIEnv* env,
jlong timebase_nanos,
jlong interval_micros) {
vsync_timebase_ = base::TimeTicks() +
base::TimeDelta::FromMilliseconds(timebase_nanos / 1000);
base::TimeDelta::FromMicroseconds(timebase_nanos / 1000);
vsync_interval_ = base::TimeDelta::FromMicroseconds(interval_micros);
if (gvr_delegate_) {
gvr_delegate_->UpdateVSyncInterval(vsync_timebase_, vsync_interval_);
......
......@@ -1067,18 +1067,20 @@ void VrShellGl::OnVSync() {
return;
base::TimeTicks now = base::TimeTicks::Now();
base::TimeTicks target;
target = now + vsync_interval_;
int64_t intervals = (target - vsync_timebase_) / vsync_interval_;
base::TimeTicks target = now + vsync_interval_;
double intervalsF =
(target - vsync_timebase_).InSecondsF() / vsync_interval_.InSecondsF();
uint64_t intervals = std::llround(intervalsF);
target = vsync_timebase_ + intervals * vsync_interval_;
task_runner_->PostDelayedTask(FROM_HERE, vsync_task_.callback(),
target - now);
base::TimeDelta current = target - vsync_interval_ - base::TimeTicks();
base::TimeDelta current_time = target - vsync_interval_ - base::TimeTicks();
if (!callback_.is_null()) {
SendVSync(current, base::ResetAndReturn(&callback_));
SendVSync(current_time, base::ResetAndReturn(&callback_));
} else {
pending_vsync_ = true;
pending_time_ = current;
pending_time_ = current_time;
}
if (!ShouldDrawWebVr()) {
DrawFrame(-1);
......
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