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 c35e7f133671d7e0e39b8124b7fbd0ee82798014..4fd3644cd9809c13b9c6c21a053159d43fcb3d39 100644 |
--- a/third_party/WebKit/Source/modules/vr/VRDisplay.cpp |
+++ b/third_party/WebKit/Source/modules/vr/VRDisplay.cpp |
@@ -47,33 +47,6 @@ VREye stringToVREye(const String& whichEye) { |
return VREyeNone; |
} |
-class VRDisplayFrameRequestCallback : public FrameRequestCallback { |
- public: |
- VRDisplayFrameRequestCallback(VRDisplay* vrDisplay) : m_vrDisplay(vrDisplay) { |
- m_useLegacyTimeBase = true; |
- } |
- ~VRDisplayFrameRequestCallback() override {} |
- void handleEvent(double highResTimeMs) override { |
- Document* doc = m_vrDisplay->document(); |
- if (!doc) |
- return; |
- |
- // Need to divide by 1000 here because serviceScriptedAnimations expects |
- // time to be given in seconds. |
- m_vrDisplay->serviceScriptedAnimations( |
- doc->loader()->timing().pseudoWallTimeToMonotonicTime(highResTimeMs / |
- 1000.0)); |
- } |
- |
- DEFINE_INLINE_VIRTUAL_TRACE() { |
- visitor->trace(m_vrDisplay); |
- |
- FrameRequestCallback::trace(visitor); |
- } |
- |
- Member<VRDisplay> m_vrDisplay; |
-}; |
- |
} // namespace |
VRDisplay::VRDisplay(NavigatorVR* navigatorVR, |
@@ -81,21 +54,13 @@ VRDisplay::VRDisplay(NavigatorVR* navigatorVR, |
device::mojom::blink::VRDisplayClientRequest request) |
: ContextLifecycleObserver(navigatorVR->document()), |
m_navigatorVR(navigatorVR), |
- m_isConnected(false), |
- m_isPresenting(false), |
- m_isValidDeviceForPresenting(true), |
- m_canUpdateFramePose(true), |
m_capabilities(new VRDisplayCapabilities()), |
m_eyeParametersLeft(new VREyeParameters()), |
m_eyeParametersRight(new VREyeParameters()), |
- m_depthNear(0.01), |
- m_depthFar(10000.0), |
m_fullscreenCheckTimer(this, &VRDisplay::onFullscreenCheck), |
- m_contextGL(nullptr), |
- m_animationCallbackRequested(false), |
- m_inAnimationFrame(false), |
m_display(std::move(display)), |
- m_binding(this, std::move(request)) {} |
+ m_displayClientBinding(this, std::move(request)), |
+ m_vsyncProviderClientBinding(this) {} |
VRDisplay::~VRDisplay() {} |
@@ -144,9 +109,7 @@ void VRDisplay::disconnected() { |
} |
bool VRDisplay::getFrameData(VRFrameData* frameData) { |
- updatePose(); |
- |
- if (!m_framePose) |
+ if (!m_framePose || m_displayBlurred) |
return false; |
if (!frameData) |
@@ -160,9 +123,7 @@ bool VRDisplay::getFrameData(VRFrameData* frameData) { |
} |
VRPose* VRDisplay::getPose() { |
- updatePose(); |
- |
- if (!m_framePose) |
+ if (!m_framePose || m_displayBlurred) |
return nullptr; |
VRPose* pose = VRPose::create(); |
@@ -170,23 +131,6 @@ VRPose* VRDisplay::getPose() { |
return pose; |
} |
-void VRDisplay::updatePose() { |
- if (m_displayBlurred) { |
- // WebVR spec says to return a null pose when the display is blurred. |
- m_framePose = nullptr; |
- return; |
- } |
- if (m_canUpdateFramePose) { |
- if (!m_display) |
- return; |
- device::mojom::blink::VRPosePtr pose; |
- m_display->GetPose(&pose); |
- m_framePose = std::move(pose); |
- if (m_isPresenting) |
- m_canUpdateFramePose = false; |
- } |
-} |
- |
void VRDisplay::resetPose() { |
if (!m_display) |
return; |
@@ -209,12 +153,6 @@ int VRDisplay::requestAnimationFrame(FrameRequestCallback* callback) { |
Document* doc = this->document(); |
if (!doc) |
return 0; |
- |
- if (!m_animationCallbackRequested) { |
- doc->requestAnimationFrame(new VRDisplayFrameRequestCallback(this)); |
- m_animationCallbackRequested = true; |
- } |
- |
callback->m_useLegacyTimeBase = false; |
return ensureScriptedAnimationController(doc).registerCallback(callback); |
} |
@@ -227,44 +165,16 @@ void VRDisplay::cancelAnimationFrame(int id) { |
void VRDisplay::OnBlur() { |
m_displayBlurred = true; |
- |
m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( |
EventTypeNames::vrdisplayblur, true, false, this, "")); |
} |
void VRDisplay::OnFocus() { |
m_displayBlurred = false; |
- // Restart our internal doc requestAnimationFrame callback, if it fired while |
- // the display was blurred. |
- // TODO(bajones): Don't use doc->requestAnimationFrame() at all. Animation |
- // frames should be tied to the presenting VR display (e.g. should be serviced |
- // by GVR library callbacks on Android), and not the doc frame rate. |
- if (!m_animationCallbackRequested) { |
- Document* doc = this->document(); |
- if (!doc) |
- return; |
- doc->requestAnimationFrame(new VRDisplayFrameRequestCallback(this)); |
- } |
m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( |
EventTypeNames::vrdisplayfocus, true, false, this, "")); |
} |
-void VRDisplay::serviceScriptedAnimations(double monotonicAnimationStartTime) { |
- if (!m_scriptedAnimationController) |
- return; |
- AutoReset<bool> animating(&m_inAnimationFrame, true); |
- m_animationCallbackRequested = false; |
- |
- // We use an internal rAF callback to run the animation loop at the display |
- // speed, and run the user's callback after our internal callback fires. |
- // However, when the display is blurred, we want to pause the animation loop, |
- // so we don't fire the user's callback until the display is focused. |
- if (m_displayBlurred) |
- return; |
- m_scriptedAnimationController->serviceScriptedAnimations( |
- monotonicAnimationStartTime); |
-} |
- |
void ReportPresentationResult(PresentationResult result) { |
// Note that this is called twice for each call to requestPresent - |
// one to declare that requestPresent was called, and one for the |
@@ -692,6 +602,33 @@ void VRDisplay::OnDeactivate( |
EventTypeNames::vrdisplaydeactivate, true, false, this, reason)); |
} |
+void VRDisplay::OnVRVsyncProviderReady( |
+ const OnVRVsyncProviderReadyCallback& callback) { |
+ if (m_vsyncProviderClientBinding.is_bound()) |
+ m_vsyncProviderClientBinding.Unbind(); |
+ callback.Run(m_vsyncProviderClientBinding.CreateInterfacePtrAndBind()); |
+} |
+ |
+void VRDisplay::OnVSync(device::mojom::blink::VRPosePtr pose, |
+ double timeSeconds, |
+ const OnVSyncCallback& callback) { |
+ callback.Run(); |
+ if (m_displayBlurred) |
+ return; |
+ if (!m_scriptedAnimationController) |
+ return; |
+ Document* doc = this->document(); |
+ if (!doc) |
+ return; |
+ |
+ AutoReset<bool> animating(&m_inAnimationFrame, true); |
+ if (m_canUpdateFramePose) |
bajones
2017/01/10 00:22:17
I think we can safely drop the logic behind m_canU
klausw
2017/01/10 00:35:23
Strictly speaking that may be a spec violation. As
|
+ m_framePose = std::move(pose); |
+ m_canUpdateFramePose = false; |
+ m_scriptedAnimationController->serviceScriptedAnimations( |
+ doc->loader()->timing().referenceMonotonicTime() + timeSeconds); |
bajones
2017/01/10 00:22:17
How confident are we that this will align with the
mthiesse
2017/01/10 00:25:24
I haven't checked, but I can pretty much guarantee
klausw
2017/01/10 00:35:23
This becomes important when switching between wind
|
+} |
+ |
void VRDisplay::onFullscreenCheck(TimerBase*) { |
if (!m_isPresenting) { |
m_fullscreenCheckTimer.stop(); |
@@ -737,7 +674,8 @@ ScriptedAnimationController& VRDisplay::ensureScriptedAnimationController( |
} |
void VRDisplay::dispose() { |
- m_binding.Close(); |
+ m_displayClientBinding.Close(); |
+ m_vsyncProviderClientBinding.Close(); |
} |
ExecutionContext* VRDisplay::getExecutionContext() const { |