Chromium Code Reviews| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 m_displayId(0), | 62 m_displayId(0), |
| 63 m_isConnected(false), | 63 m_isConnected(false), |
| 64 m_isPresenting(false), | 64 m_isPresenting(false), |
| 65 m_canUpdateFramePose(true), | 65 m_canUpdateFramePose(true), |
| 66 m_capabilities(new VRDisplayCapabilities()), | 66 m_capabilities(new VRDisplayCapabilities()), |
| 67 m_eyeParametersLeft(new VREyeParameters()), | 67 m_eyeParametersLeft(new VREyeParameters()), |
| 68 m_eyeParametersRight(new VREyeParameters()), | 68 m_eyeParametersRight(new VREyeParameters()), |
| 69 m_depthNear(0.01), | 69 m_depthNear(0.01), |
| 70 m_depthFar(10000.0), | 70 m_depthFar(10000.0), |
| 71 m_fullscreenCheckTimer(this, &VRDisplay::onFullscreenCheck), | 71 m_fullscreenCheckTimer(this, &VRDisplay::onFullscreenCheck), |
| 72 m_contextGL(nullptr), | |
| 72 m_animationCallbackRequested(false), | 73 m_animationCallbackRequested(false), |
| 73 m_inAnimationFrame(false) {} | 74 m_inAnimationFrame(false) {} |
| 74 | 75 |
| 75 VRDisplay::~VRDisplay() {} | 76 VRDisplay::~VRDisplay() {} |
| 76 | 77 |
| 77 VRController* VRDisplay::controller() { | 78 VRController* VRDisplay::controller() { |
| 78 return m_navigatorVR->controller(); | 79 return m_navigatorVR->controller(); |
| 79 } | 80 } |
| 80 | 81 |
| 81 void VRDisplay::update(const device::blink::VRDisplayPtr& display) { | 82 void VRDisplay::update(const device::blink::VRDisplayPtr& display) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 103 } | 104 } |
| 104 | 105 |
| 105 void VRDisplay::disconnected() { | 106 void VRDisplay::disconnected() { |
| 106 if (m_isConnected) | 107 if (m_isConnected) |
| 107 m_isConnected = !m_isConnected; | 108 m_isConnected = !m_isConnected; |
| 108 } | 109 } |
| 109 | 110 |
| 110 bool VRDisplay::getFrameData(VRFrameData* frameData) { | 111 bool VRDisplay::getFrameData(VRFrameData* frameData) { |
| 111 updatePose(); | 112 updatePose(); |
| 112 | 113 |
| 114 if (!m_framePose) | |
| 115 return false; | |
| 116 | |
| 113 if (!frameData) | 117 if (!frameData) |
| 114 return false; | 118 return false; |
| 115 | 119 |
| 116 if (m_depthNear == m_depthFar) | 120 if (m_depthNear == m_depthFar) |
| 117 return false; | 121 return false; |
| 118 | 122 |
| 119 return frameData->update(m_framePose, m_eyeParametersLeft, | 123 return frameData->update(m_framePose, m_eyeParametersLeft, |
| 120 m_eyeParametersRight, m_depthNear, m_depthFar); | 124 m_eyeParametersRight, m_depthNear, m_depthFar); |
| 121 } | 125 } |
| 122 | 126 |
| 123 VRPose* VRDisplay::getPose() { | 127 VRPose* VRDisplay::getPose() { |
| 124 updatePose(); | 128 updatePose(); |
| 125 | 129 |
| 126 if (!m_framePose) | 130 if (!m_framePose) |
| 127 return nullptr; | 131 return nullptr; |
| 128 | 132 |
| 129 VRPose* pose = VRPose::create(); | 133 VRPose* pose = VRPose::create(); |
| 130 pose->setPose(m_framePose); | 134 pose->setPose(m_framePose); |
| 131 return pose; | 135 return pose; |
| 132 } | 136 } |
| 133 | 137 |
| 134 void VRDisplay::updatePose() { | 138 void VRDisplay::updatePose() { |
| 139 if (m_displayBlurred) { | |
| 140 m_framePose = nullptr; | |
| 141 return; | |
| 142 } | |
| 135 if (m_canUpdateFramePose) { | 143 if (m_canUpdateFramePose) { |
| 136 m_framePose = controller()->getPose(m_displayId); | 144 m_framePose = controller()->getPose(m_displayId); |
| 137 if (m_isPresenting) | 145 if (m_isPresenting) |
| 138 m_canUpdateFramePose = false; | 146 m_canUpdateFramePose = false; |
| 139 } | 147 } |
| 140 } | 148 } |
| 141 | 149 |
| 142 void VRDisplay::resetPose() { | 150 void VRDisplay::resetPose() { |
| 143 controller()->resetPose(m_displayId); | 151 controller()->resetPose(m_displayId); |
| 144 } | 152 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 167 callback->m_useLegacyTimeBase = false; | 175 callback->m_useLegacyTimeBase = false; |
| 168 return ensureScriptedAnimationController(doc).registerCallback(callback); | 176 return ensureScriptedAnimationController(doc).registerCallback(callback); |
| 169 } | 177 } |
| 170 | 178 |
| 171 void VRDisplay::cancelAnimationFrame(int id) { | 179 void VRDisplay::cancelAnimationFrame(int id) { |
| 172 if (!m_scriptedAnimationController) | 180 if (!m_scriptedAnimationController) |
| 173 return; | 181 return; |
| 174 m_scriptedAnimationController->cancelCallback(id); | 182 m_scriptedAnimationController->cancelCallback(id); |
| 175 } | 183 } |
| 176 | 184 |
| 185 void VRDisplay::onDisplayBlur() { | |
| 186 Document* doc = m_navigatorVR->document(); | |
| 187 if (!doc) | |
| 188 return; | |
| 189 m_displayBlurred = true; | |
| 190 doc->suspendScheduledTasks(); | |
|
dcheng
2016/11/04 05:24:46
Why do we want to suspend scheduled tasks? This wi
mthiesse
2016/11/04 17:20:36
I'll remove this in the next patchset. My thinking
| |
| 191 m_scriptedAnimationController->suspend(); | |
| 192 m_navigatorVR->fireVrDisplayOnBlur(this); | |
| 193 } | |
| 194 | |
| 195 void VRDisplay::onDisplayFocus() { | |
| 196 Document* doc = m_navigatorVR->document(); | |
| 197 if (!doc) | |
| 198 return; | |
| 199 m_displayBlurred = false; | |
| 200 m_scriptedAnimationController->resume(); | |
| 201 doc->resumeScheduledTasks(); | |
| 202 m_navigatorVR->fireVrDisplayOnFocus(this); | |
| 203 } | |
| 204 | |
| 177 void VRDisplay::serviceScriptedAnimations(double monotonicAnimationStartTime) { | 205 void VRDisplay::serviceScriptedAnimations(double monotonicAnimationStartTime) { |
| 178 if (!m_scriptedAnimationController) | 206 if (!m_scriptedAnimationController) |
| 179 return; | 207 return; |
| 180 AutoReset<bool> animating(&m_inAnimationFrame, true); | 208 AutoReset<bool> animating(&m_inAnimationFrame, true); |
| 181 m_animationCallbackRequested = false; | 209 m_animationCallbackRequested = false; |
| 182 m_scriptedAnimationController->serviceScriptedAnimations( | 210 m_scriptedAnimationController->serviceScriptedAnimations( |
| 183 monotonicAnimationStartTime); | 211 monotonicAnimationStartTime); |
| 184 } | 212 } |
| 185 | 213 |
| 186 void ReportPresentationResult(PresentationResult result) { | 214 void ReportPresentationResult(PresentationResult result) { |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 499 visitor->trace(m_capabilities); | 527 visitor->trace(m_capabilities); |
| 500 visitor->trace(m_stageParameters); | 528 visitor->trace(m_stageParameters); |
| 501 visitor->trace(m_eyeParametersLeft); | 529 visitor->trace(m_eyeParametersLeft); |
| 502 visitor->trace(m_eyeParametersRight); | 530 visitor->trace(m_eyeParametersRight); |
| 503 visitor->trace(m_layer); | 531 visitor->trace(m_layer); |
| 504 visitor->trace(m_renderingContext); | 532 visitor->trace(m_renderingContext); |
| 505 visitor->trace(m_scriptedAnimationController); | 533 visitor->trace(m_scriptedAnimationController); |
| 506 } | 534 } |
| 507 | 535 |
| 508 } // namespace blink | 536 } // namespace blink |
| OLD | NEW |