Chromium Code Reviews| Index: third_party/WebKit/Source/modules/vr/VRDisplay.cpp |
| diff --git a/third_party/WebKit/Source/modules/vr/VRDisplay.cpp b/third_party/WebKit/Source/modules/vr/VRDisplay.cpp |
| index 4fa6fa737b48b1bcd283427ec31cc2e29c010de0..9e7cf6bb540a00d4fe9b2143f4f3ee3886e2cd62 100644 |
| --- a/third_party/WebKit/Source/modules/vr/VRDisplay.cpp |
| +++ b/third_party/WebKit/Source/modules/vr/VRDisplay.cpp |
| @@ -151,6 +151,14 @@ VREyeParameters* VRDisplay::getEyeParameters(const String& whichEye) { |
| } |
| } |
| +void VRDisplay::doGetVSync() { |
| + if (!m_displayBlurred && !m_pendingVsync) { |
| + m_pendingVsync = true; |
| + m_vrVSyncProvider->GetVSync(convertToBaseCallback( |
| + WTF::bind(&VRDisplay::OnVSync, wrapWeakPersistent(this)))); |
| + } |
| +} |
| + |
| int VRDisplay::requestAnimationFrame(FrameRequestCallback* callback) { |
| Document* doc = this->document(); |
| if (!doc) |
| @@ -159,9 +167,15 @@ int VRDisplay::requestAnimationFrame(FrameRequestCallback* callback) { |
| if (!m_vrVSyncProvider.is_bound()) { |
| ConnectVSyncProvider(); |
| } else if (!m_displayBlurred && !m_pendingVsync) { |
| - m_pendingVsync = true; |
| - m_vrVSyncProvider->GetVSync(convertToBaseCallback( |
| - WTF::bind(&VRDisplay::OnVSync, wrapWeakPersistent(this)))); |
| + // Schedule a task to fetch a new VSync after the current |
| + // execution context finishes. If we call GetVSync inline here, we |
| + // can end up with the next VSync already being ready and |
| + // scheduled when we exit, and then we'll process several frames |
| + // in a row without ever yielding back to the main event loop, |
| + // causing extreme input delay. See crbug.com/701444. |
| + Platform::current()->currentThread()->getWebTaskRunner()->postTask( |
|
mthiesse
2017/03/15 15:17:35
Two comments:
1. This shouldn't be necessary, this
klausw
2017/03/15 15:42:39
Yes, this was unexpected. It's not just starving I
klausw
2017/03/15 15:50:59
To clarify, I think that executing the next GetVSy
klausw
2017/03/15 17:39:25
The deferred serviceScriptedAnimations works, goin
|
| + BLINK_FROM_HERE, |
| + WTF::bind(&VRDisplay::doGetVSync, wrapWeakPersistent(this))); |
| } |
| callback->m_useLegacyTimeBase = false; |
| return ensureScriptedAnimationController(doc).registerCallback(callback); |
| @@ -715,6 +729,8 @@ void VRDisplay::OnVSync(device::mojom::blink::VRPosePtr pose, |
| m_framePose = std::move(pose); |
| m_vrFrameId = frameId; |
| m_pendingRaf = false; |
| + TRACE_EVENT1("gpu", "VRDisplay::OnVSync", "frame", frameId); |
| + |
| m_scriptedAnimationController->serviceScriptedAnimations( |
| m_timebase + timeDelta.InSecondsF()); |
| } |