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 1480df6785b9b4e392e0ccdfd209e937ac9dddc1..2eab7ee317878a31a835725a794684c32a328672 100644 |
| --- a/third_party/WebKit/Source/modules/vr/VRDisplay.cpp |
| +++ b/third_party/WebKit/Source/modules/vr/VRDisplay.cpp |
| @@ -69,6 +69,7 @@ VRDisplay::VRDisplay(NavigatorVR* navigatorVR) |
| m_depthNear(0.01), |
| m_depthFar(10000.0), |
| m_fullscreenCheckTimer(this, &VRDisplay::onFullscreenCheck), |
| + m_contextGL(nullptr), |
| m_animationCallbackRequested(false), |
| m_inAnimationFrame(false) {} |
| @@ -110,6 +111,9 @@ void VRDisplay::disconnected() { |
| bool VRDisplay::getFrameData(VRFrameData* frameData) { |
| updatePose(); |
| + if (!m_framePose) |
| + return false; |
| + |
| if (!frameData) |
| return false; |
| @@ -132,6 +136,10 @@ VRPose* VRDisplay::getPose() { |
| } |
| void VRDisplay::updatePose() { |
| + if (m_displayBlurred) { |
| + m_framePose = nullptr; |
|
dcheng
2016/11/08 23:05:45
Out of curiosity, why don't we just clear this in
mthiesse
2016/11/10 22:14:10
I clear it in updatePose simply for code clarity.
|
| + return; |
| + } |
| if (m_canUpdateFramePose) { |
| m_framePose = controller()->getPose(m_displayId); |
| if (m_isPresenting) |
| @@ -174,11 +182,34 @@ void VRDisplay::cancelAnimationFrame(int id) { |
| m_scriptedAnimationController->cancelCallback(id); |
| } |
| +void VRDisplay::onDisplayBlur() { |
| + m_displayBlurred = true; |
| + m_navigatorVR->fireVrDisplayOnBlur(this); |
| +} |
| + |
| +void VRDisplay::onDisplayFocus() { |
| + 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 = m_navigatorVR->document(); |
| + if (!doc) |
| + return; |
| + doc->requestAnimationFrame(new VRDisplayFrameRequestCallback(this)); |
| + } |
| + m_navigatorVR->fireVrDisplayOnFocus(this); |
| +} |
| + |
| void VRDisplay::serviceScriptedAnimations(double monotonicAnimationStartTime) { |
| if (!m_scriptedAnimationController) |
| return; |
| AutoReset<bool> animating(&m_inAnimationFrame, true); |
| m_animationCallbackRequested = false; |
| + if (m_displayBlurred) |
| + return; |
| m_scriptedAnimationController->serviceScriptedAnimations( |
| monotonicAnimationStartTime); |
| } |