| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/vr/VRDisplay.h" | 5 #include "modules/vr/VRDisplay.h" |
| 6 | 6 |
| 7 #include "core/dom/DOMException.h" | 7 #include "core/dom/DOMException.h" |
| 8 #include "core/dom/FrameRequestCallback.h" | 8 #include "core/dom/FrameRequestCallback.h" |
| 9 #include "core/dom/Fullscreen.h" | 9 #include "core/dom/Fullscreen.h" |
| 10 #include "core/dom/ScriptedAnimationController.h" | 10 #include "core/dom/ScriptedAnimationController.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 : m_navigatorVR(navigatorVR), | 63 : m_navigatorVR(navigatorVR), |
| 64 m_isConnected(false), | 64 m_isConnected(false), |
| 65 m_isPresenting(false), | 65 m_isPresenting(false), |
| 66 m_canUpdateFramePose(true), | 66 m_canUpdateFramePose(true), |
| 67 m_capabilities(new VRDisplayCapabilities()), | 67 m_capabilities(new VRDisplayCapabilities()), |
| 68 m_eyeParametersLeft(new VREyeParameters()), | 68 m_eyeParametersLeft(new VREyeParameters()), |
| 69 m_eyeParametersRight(new VREyeParameters()), | 69 m_eyeParametersRight(new VREyeParameters()), |
| 70 m_depthNear(0.01), | 70 m_depthNear(0.01), |
| 71 m_depthFar(10000.0), | 71 m_depthFar(10000.0), |
| 72 m_fullscreenCheckTimer(this, &VRDisplay::onFullscreenCheck), | 72 m_fullscreenCheckTimer(this, &VRDisplay::onFullscreenCheck), |
| 73 m_contextGL(nullptr), |
| 73 m_animationCallbackRequested(false), | 74 m_animationCallbackRequested(false), |
| 74 m_inAnimationFrame(false), | 75 m_inAnimationFrame(false), |
| 75 m_display(std::move(display)), | 76 m_display(std::move(display)), |
| 76 m_binding(this, std::move(request)) { | 77 m_binding(this, std::move(request)) { |
| 77 ThreadState::current()->registerPreFinalizer(this); | 78 ThreadState::current()->registerPreFinalizer(this); |
| 78 } | 79 } |
| 79 | 80 |
| 80 VRDisplay::~VRDisplay() {} | 81 VRDisplay::~VRDisplay() {} |
| 81 | 82 |
| 82 VRController* VRDisplay::controller() { | 83 VRController* VRDisplay::controller() { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 108 } | 109 } |
| 109 | 110 |
| 110 void VRDisplay::disconnected() { | 111 void VRDisplay::disconnected() { |
| 111 if (m_isConnected) | 112 if (m_isConnected) |
| 112 m_isConnected = !m_isConnected; | 113 m_isConnected = !m_isConnected; |
| 113 } | 114 } |
| 114 | 115 |
| 115 bool VRDisplay::getFrameData(VRFrameData* frameData) { | 116 bool VRDisplay::getFrameData(VRFrameData* frameData) { |
| 116 updatePose(); | 117 updatePose(); |
| 117 | 118 |
| 119 if (!m_framePose) |
| 120 return false; |
| 121 |
| 118 if (!frameData) | 122 if (!frameData) |
| 119 return false; | 123 return false; |
| 120 | 124 |
| 121 if (m_depthNear == m_depthFar) | 125 if (m_depthNear == m_depthFar) |
| 122 return false; | 126 return false; |
| 123 | 127 |
| 124 return frameData->update(m_framePose, m_eyeParametersLeft, | 128 return frameData->update(m_framePose, m_eyeParametersLeft, |
| 125 m_eyeParametersRight, m_depthNear, m_depthFar); | 129 m_eyeParametersRight, m_depthNear, m_depthFar); |
| 126 } | 130 } |
| 127 | 131 |
| 128 VRPose* VRDisplay::getPose() { | 132 VRPose* VRDisplay::getPose() { |
| 129 updatePose(); | 133 updatePose(); |
| 130 | 134 |
| 131 if (!m_framePose) | 135 if (!m_framePose) |
| 132 return nullptr; | 136 return nullptr; |
| 133 | 137 |
| 134 VRPose* pose = VRPose::create(); | 138 VRPose* pose = VRPose::create(); |
| 135 pose->setPose(m_framePose); | 139 pose->setPose(m_framePose); |
| 136 return pose; | 140 return pose; |
| 137 } | 141 } |
| 138 | 142 |
| 139 void VRDisplay::updatePose() { | 143 void VRDisplay::updatePose() { |
| 144 if (m_displayBlurred) { |
| 145 // WebVR spec says to return a null pose when the display is blurred. |
| 146 m_framePose = nullptr; |
| 147 return; |
| 148 } |
| 140 if (m_canUpdateFramePose) { | 149 if (m_canUpdateFramePose) { |
| 141 if (!m_display) | 150 if (!m_display) |
| 142 return; | 151 return; |
| 143 device::mojom::blink::VRPosePtr pose; | 152 device::mojom::blink::VRPosePtr pose; |
| 144 m_display->GetPose(&pose); | 153 m_display->GetPose(&pose); |
| 145 m_framePose = std::move(pose); | 154 m_framePose = std::move(pose); |
| 146 if (m_isPresenting) | 155 if (m_isPresenting) |
| 147 m_canUpdateFramePose = false; | 156 m_canUpdateFramePose = false; |
| 148 } | 157 } |
| 149 } | 158 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 179 callback->m_useLegacyTimeBase = false; | 188 callback->m_useLegacyTimeBase = false; |
| 180 return ensureScriptedAnimationController(doc).registerCallback(callback); | 189 return ensureScriptedAnimationController(doc).registerCallback(callback); |
| 181 } | 190 } |
| 182 | 191 |
| 183 void VRDisplay::cancelAnimationFrame(int id) { | 192 void VRDisplay::cancelAnimationFrame(int id) { |
| 184 if (!m_scriptedAnimationController) | 193 if (!m_scriptedAnimationController) |
| 185 return; | 194 return; |
| 186 m_scriptedAnimationController->cancelCallback(id); | 195 m_scriptedAnimationController->cancelCallback(id); |
| 187 } | 196 } |
| 188 | 197 |
| 198 void VRDisplay::OnDisplayBlur() { |
| 199 m_displayBlurred = true; |
| 200 m_navigatorVR->fireVrDisplayOnBlur(this); |
| 201 } |
| 202 |
| 203 void VRDisplay::OnDisplayFocus() { |
| 204 m_displayBlurred = false; |
| 205 // Restart our internal doc requestAnimationFrame callback, if it fired while |
| 206 // the display was blurred. |
| 207 // TODO(bajones): Don't use doc->requestAnimationFrame() at all. Animation |
| 208 // frames should be tied to the presenting VR display (e.g. should be serviced |
| 209 // by GVR library callbacks on Android), and not the doc frame rate. |
| 210 if (!m_animationCallbackRequested) { |
| 211 Document* doc = m_navigatorVR->document(); |
| 212 if (!doc) |
| 213 return; |
| 214 doc->requestAnimationFrame(new VRDisplayFrameRequestCallback(this)); |
| 215 } |
| 216 m_navigatorVR->fireVrDisplayOnFocus(this); |
| 217 } |
| 218 |
| 189 void VRDisplay::serviceScriptedAnimations(double monotonicAnimationStartTime) { | 219 void VRDisplay::serviceScriptedAnimations(double monotonicAnimationStartTime) { |
| 190 if (!m_scriptedAnimationController) | 220 if (!m_scriptedAnimationController) |
| 191 return; | 221 return; |
| 192 AutoReset<bool> animating(&m_inAnimationFrame, true); | 222 AutoReset<bool> animating(&m_inAnimationFrame, true); |
| 193 m_animationCallbackRequested = false; | 223 m_animationCallbackRequested = false; |
| 224 |
| 225 // We use an internal rAF callback to run the animation loop at the display |
| 226 // speed, and run the user's callback after our internal callback fires. |
| 227 // However, when the display is blurred, we want to pause the animation loop, |
| 228 // so we don't fire the user's callback until the display is focused. |
| 229 if (m_displayBlurred) |
| 230 return; |
| 194 m_scriptedAnimationController->serviceScriptedAnimations( | 231 m_scriptedAnimationController->serviceScriptedAnimations( |
| 195 monotonicAnimationStartTime); | 232 monotonicAnimationStartTime); |
| 196 } | 233 } |
| 197 | 234 |
| 198 void ReportPresentationResult(PresentationResult result) { | 235 void ReportPresentationResult(PresentationResult result) { |
| 199 // Note that this is called twice for each call to requestPresent - | 236 // Note that this is called twice for each call to requestPresent - |
| 200 // one to declare that requestPresent was called, and one for the | 237 // one to declare that requestPresent was called, and one for the |
| 201 // result. | 238 // result. |
| 202 DEFINE_STATIC_LOCAL( | 239 DEFINE_STATIC_LOCAL( |
| 203 EnumerationHistogram, vrPresentationResultHistogram, | 240 EnumerationHistogram, vrPresentationResultHistogram, |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 visitor->trace(m_capabilities); | 611 visitor->trace(m_capabilities); |
| 575 visitor->trace(m_stageParameters); | 612 visitor->trace(m_stageParameters); |
| 576 visitor->trace(m_eyeParametersLeft); | 613 visitor->trace(m_eyeParametersLeft); |
| 577 visitor->trace(m_eyeParametersRight); | 614 visitor->trace(m_eyeParametersRight); |
| 578 visitor->trace(m_layer); | 615 visitor->trace(m_layer); |
| 579 visitor->trace(m_renderingContext); | 616 visitor->trace(m_renderingContext); |
| 580 visitor->trace(m_scriptedAnimationController); | 617 visitor->trace(m_scriptedAnimationController); |
| 581 } | 618 } |
| 582 | 619 |
| 583 } // namespace blink | 620 } // namespace blink |
| OLD | NEW |