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/css/StylePropertySet.h" | 7 #include "core/css/StylePropertySet.h" |
| 8 #include "core/dom/DOMException.h" | 8 #include "core/dom/DOMException.h" |
| 9 #include "core/dom/DocumentUserGestureToken.h" | 9 #include "core/dom/DocumentUserGestureToken.h" |
| 10 #include "core/dom/FrameRequestCallback.h" | 10 #include "core/dom/FrameRequestCallback.h" |
| 11 #include "core/dom/Fullscreen.h" | 11 #include "core/dom/Fullscreen.h" |
| 12 #include "core/dom/ScriptedAnimationController.h" | 12 #include "core/dom/ScriptedAnimationController.h" |
| 13 #include "core/frame/UseCounter.h" | 13 #include "core/frame/UseCounter.h" |
| 14 #include "core/inspector/ConsoleMessage.h" | 14 #include "core/inspector/ConsoleMessage.h" |
| 15 #include "core/loader/DocumentLoader.h" | 15 #include "core/loader/DocumentLoader.h" |
| 16 #include "gpu/command_buffer/client/gles2_interface.h" | 16 #include "gpu/command_buffer/client/gles2_interface.h" |
| 17 #include "modules/EventTargetModules.h" | |
| 17 #include "modules/vr/NavigatorVR.h" | 18 #include "modules/vr/NavigatorVR.h" |
| 18 #include "modules/vr/VRController.h" | 19 #include "modules/vr/VRController.h" |
| 19 #include "modules/vr/VRDisplayCapabilities.h" | 20 #include "modules/vr/VRDisplayCapabilities.h" |
| 20 #include "modules/vr/VREyeParameters.h" | 21 #include "modules/vr/VREyeParameters.h" |
| 21 #include "modules/vr/VRFrameData.h" | 22 #include "modules/vr/VRFrameData.h" |
| 22 #include "modules/vr/VRLayer.h" | 23 #include "modules/vr/VRLayer.h" |
| 23 #include "modules/vr/VRPose.h" | 24 #include "modules/vr/VRPose.h" |
| 24 #include "modules/vr/VRStageParameters.h" | 25 #include "modules/vr/VRStageParameters.h" |
| 25 #include "modules/webgl/WebGLRenderingContextBase.h" | 26 #include "modules/webgl/WebGLRenderingContextBase.h" |
| 26 #include "platform/Histogram.h" | 27 #include "platform/Histogram.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 } | 72 } |
| 72 | 73 |
| 73 Member<VRDisplay> m_vrDisplay; | 74 Member<VRDisplay> m_vrDisplay; |
| 74 }; | 75 }; |
| 75 | 76 |
| 76 } // namespace | 77 } // namespace |
| 77 | 78 |
| 78 VRDisplay::VRDisplay(NavigatorVR* navigatorVR, | 79 VRDisplay::VRDisplay(NavigatorVR* navigatorVR, |
| 79 device::mojom::blink::VRDisplayPtr display, | 80 device::mojom::blink::VRDisplayPtr display, |
| 80 device::mojom::blink::VRDisplayClientRequest request) | 81 device::mojom::blink::VRDisplayClientRequest request) |
| 81 : m_navigatorVR(navigatorVR), | 82 : ActiveScriptWrappable(this), |
| 83 ContextLifecycleObserver(navigatorVR->document()), | |
| 84 m_navigatorVR(navigatorVR), | |
| 82 m_isConnected(false), | 85 m_isConnected(false), |
| 83 m_isPresenting(false), | 86 m_isPresenting(false), |
| 84 m_isValidDeviceForPresenting(true), | 87 m_isValidDeviceForPresenting(true), |
| 85 m_canUpdateFramePose(true), | 88 m_canUpdateFramePose(true), |
| 86 m_capabilities(new VRDisplayCapabilities()), | 89 m_capabilities(new VRDisplayCapabilities()), |
| 87 m_eyeParametersLeft(new VREyeParameters()), | 90 m_eyeParametersLeft(new VREyeParameters()), |
| 88 m_eyeParametersRight(new VREyeParameters()), | 91 m_eyeParametersRight(new VREyeParameters()), |
| 89 m_depthNear(0.01), | 92 m_depthNear(0.01), |
| 90 m_depthFar(10000.0), | 93 m_depthFar(10000.0), |
| 91 m_fullscreenCheckTimer(this, &VRDisplay::onFullscreenCheck), | 94 m_fullscreenCheckTimer(this, &VRDisplay::onFullscreenCheck), |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 case VREyeLeft: | 202 case VREyeLeft: |
| 200 return m_eyeParametersLeft; | 203 return m_eyeParametersLeft; |
| 201 case VREyeRight: | 204 case VREyeRight: |
| 202 return m_eyeParametersRight; | 205 return m_eyeParametersRight; |
| 203 default: | 206 default: |
| 204 return nullptr; | 207 return nullptr; |
| 205 } | 208 } |
| 206 } | 209 } |
| 207 | 210 |
| 208 int VRDisplay::requestAnimationFrame(FrameRequestCallback* callback) { | 211 int VRDisplay::requestAnimationFrame(FrameRequestCallback* callback) { |
| 209 Document* doc = m_navigatorVR->document(); | 212 Document* doc = this->document(); |
| 210 if (!doc) | 213 if (!doc) |
| 211 return 0; | 214 return 0; |
| 212 | 215 |
| 213 if (!m_animationCallbackRequested) { | 216 if (!m_animationCallbackRequested) { |
| 214 doc->requestAnimationFrame(new VRDisplayFrameRequestCallback(this)); | 217 doc->requestAnimationFrame(new VRDisplayFrameRequestCallback(this)); |
| 215 m_animationCallbackRequested = true; | 218 m_animationCallbackRequested = true; |
| 216 } | 219 } |
| 217 | 220 |
| 218 callback->m_useLegacyTimeBase = false; | 221 callback->m_useLegacyTimeBase = false; |
| 219 return ensureScriptedAnimationController(doc).registerCallback(callback); | 222 return ensureScriptedAnimationController(doc).registerCallback(callback); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 233 } | 236 } |
| 234 | 237 |
| 235 void VRDisplay::OnFocus() { | 238 void VRDisplay::OnFocus() { |
| 236 m_displayBlurred = false; | 239 m_displayBlurred = false; |
| 237 // Restart our internal doc requestAnimationFrame callback, if it fired while | 240 // Restart our internal doc requestAnimationFrame callback, if it fired while |
| 238 // the display was blurred. | 241 // the display was blurred. |
| 239 // TODO(bajones): Don't use doc->requestAnimationFrame() at all. Animation | 242 // TODO(bajones): Don't use doc->requestAnimationFrame() at all. Animation |
| 240 // frames should be tied to the presenting VR display (e.g. should be serviced | 243 // frames should be tied to the presenting VR display (e.g. should be serviced |
| 241 // by GVR library callbacks on Android), and not the doc frame rate. | 244 // by GVR library callbacks on Android), and not the doc frame rate. |
| 242 if (!m_animationCallbackRequested) { | 245 if (!m_animationCallbackRequested) { |
| 243 Document* doc = m_navigatorVR->document(); | 246 Document* doc = this->document(); |
| 244 if (!doc) | 247 if (!doc) |
| 245 return; | 248 return; |
| 246 doc->requestAnimationFrame(new VRDisplayFrameRequestCallback(this)); | 249 doc->requestAnimationFrame(new VRDisplayFrameRequestCallback(this)); |
| 247 } | 250 } |
| 248 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( | 251 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( |
| 249 EventTypeNames::vrdisplayfocus, true, false, this, "")); | 252 EventTypeNames::vrdisplayfocus, true, false, this, "")); |
| 250 } | 253 } |
| 251 | 254 |
| 252 void VRDisplay::serviceScriptedAnimations(double monotonicAnimationStartTime) { | 255 void VRDisplay::serviceScriptedAnimations(double monotonicAnimationStartTime) { |
| 253 if (!m_scriptedAnimationController) | 256 if (!m_scriptedAnimationController) |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 m_display->ExitPresent(); | 432 m_display->ExitPresent(); |
| 430 | 433 |
| 431 resolver->resolve(); | 434 resolver->resolve(); |
| 432 | 435 |
| 433 forceExitPresent(); | 436 forceExitPresent(); |
| 434 | 437 |
| 435 return promise; | 438 return promise; |
| 436 } | 439 } |
| 437 | 440 |
| 438 void VRDisplay::beginPresent() { | 441 void VRDisplay::beginPresent() { |
| 439 Document* doc = m_navigatorVR->document(); | 442 Document* doc = this->document(); |
| 440 std::unique_ptr<UserGestureIndicator> gestureIndicator; | 443 std::unique_ptr<UserGestureIndicator> gestureIndicator; |
| 441 if (m_capabilities->hasExternalDisplay()) { | 444 if (m_capabilities->hasExternalDisplay()) { |
| 442 forceExitPresent(); | 445 forceExitPresent(); |
| 443 DOMException* exception = DOMException::create( | 446 DOMException* exception = DOMException::create( |
| 444 InvalidStateError, | 447 InvalidStateError, |
| 445 "VR Presentation not implemented for this VRDisplay."); | 448 "VR Presentation not implemented for this VRDisplay."); |
| 446 while (!m_pendingPresentResolvers.isEmpty()) { | 449 while (!m_pendingPresentResolvers.isEmpty()) { |
| 447 ScriptPromiseResolver* resolver = m_pendingPresentResolvers.takeFirst(); | 450 ScriptPromiseResolver* resolver = m_pendingPresentResolvers.takeFirst(); |
| 448 resolver->reject(exception); | 451 resolver->reject(exception); |
| 449 } | 452 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 584 layers.append(m_layer); | 587 layers.append(m_layer); |
| 585 } | 588 } |
| 586 | 589 |
| 587 return layers; | 590 return layers; |
| 588 } | 591 } |
| 589 | 592 |
| 590 void VRDisplay::submitFrame() { | 593 void VRDisplay::submitFrame() { |
| 591 if (!m_display) | 594 if (!m_display) |
| 592 return; | 595 return; |
| 593 | 596 |
| 594 Document* doc = m_navigatorVR->document(); | 597 Document* doc = this->document(); |
| 595 if (!m_isPresenting) { | 598 if (!m_isPresenting) { |
| 596 if (doc) { | 599 if (doc) { |
| 597 doc->addConsoleMessage(ConsoleMessage::create( | 600 doc->addConsoleMessage(ConsoleMessage::create( |
| 598 RenderingMessageSource, WarningMessageLevel, | 601 RenderingMessageSource, WarningMessageLevel, |
| 599 "submitFrame has no effect when the VRDisplay is not presenting.")); | 602 "submitFrame has no effect when the VRDisplay is not presenting.")); |
| 600 } | 603 } |
| 601 return; | 604 return; |
| 602 } | 605 } |
| 603 | 606 |
| 604 if (!m_inAnimationFrame) { | 607 if (!m_inAnimationFrame) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 711 if (m_reenteredFullscreen) { | 714 if (m_reenteredFullscreen) { |
| 712 m_isPresenting = false; | 715 m_isPresenting = false; |
| 713 OnPresentChange(); | 716 OnPresentChange(); |
| 714 m_fullscreenCheckTimer.stop(); | 717 m_fullscreenCheckTimer.stop(); |
| 715 if (m_display) | 718 if (m_display) |
| 716 m_display->ExitPresent(); | 719 m_display->ExitPresent(); |
| 717 return; | 720 return; |
| 718 } | 721 } |
| 719 m_reenteredFullscreen = true; | 722 m_reenteredFullscreen = true; |
| 720 auto canvas = m_layer.source(); | 723 auto canvas = m_layer.source(); |
| 721 Document* doc = m_navigatorVR->document(); | 724 Document* doc = this->document(); |
| 722 std::unique_ptr<UserGestureIndicator> gestureIndicator; | 725 std::unique_ptr<UserGestureIndicator> gestureIndicator; |
| 723 if (doc) { | 726 if (doc) { |
| 724 gestureIndicator = | 727 gestureIndicator = |
| 725 wrapUnique(new UserGestureIndicator(DocumentUserGestureToken::create( | 728 wrapUnique(new UserGestureIndicator(DocumentUserGestureToken::create( |
| 726 doc, UserGestureToken::Status::PossiblyExistingGesture))); | 729 doc, UserGestureToken::Status::PossiblyExistingGesture))); |
| 727 } | 730 } |
| 728 Fullscreen::requestFullscreen(*canvas, Fullscreen::UnprefixedRequest); | 731 Fullscreen::requestFullscreen(*canvas, Fullscreen::UnprefixedRequest); |
| 729 } | 732 } |
| 730 } | 733 } |
| 731 | 734 |
| 732 ScriptedAnimationController& VRDisplay::ensureScriptedAnimationController( | 735 ScriptedAnimationController& VRDisplay::ensureScriptedAnimationController( |
| 733 Document* doc) { | 736 Document* doc) { |
| 734 if (!m_scriptedAnimationController) | 737 if (!m_scriptedAnimationController) |
| 735 m_scriptedAnimationController = ScriptedAnimationController::create(doc); | 738 m_scriptedAnimationController = ScriptedAnimationController::create(doc); |
| 736 | 739 |
| 737 return *m_scriptedAnimationController; | 740 return *m_scriptedAnimationController; |
| 738 } | 741 } |
| 739 | 742 |
| 740 void VRDisplay::dispose() { | 743 void VRDisplay::dispose() { |
| 741 m_binding.Close(); | 744 m_binding.Close(); |
| 742 } | 745 } |
| 743 | 746 |
| 747 ExecutionContext* VRDisplay::getExecutionContext() const { | |
| 748 return ContextLifecycleObserver::getExecutionContext(); | |
| 749 } | |
| 750 | |
| 751 const AtomicString& VRDisplay::interfaceName() const { | |
| 752 return EventTargetNames::VRDisplay; | |
| 753 } | |
| 754 | |
| 755 void VRDisplay::contextDestroyed() { | |
| 756 forceExitPresent(); | |
| 757 ContextLifecycleObserver::clearContext(); | |
|
haraken
2016/12/07 09:01:22
This won't be needed. ContextLifecycleObserver cle
| |
| 758 } | |
| 759 | |
| 760 bool VRDisplay::hasPendingActivity() const { | |
| 761 // Prevent V8 from garbage collecting the wrapper object if there are | |
| 762 // event listeners attached to it. | |
| 763 return hasEventListeners(); | |
|
haraken
2016/12/07 09:01:22
Would you change this to:
return getExecutionCo
| |
| 764 } | |
| 765 | |
| 744 DEFINE_TRACE(VRDisplay) { | 766 DEFINE_TRACE(VRDisplay) { |
| 767 EventTargetWithInlineData::trace(visitor); | |
| 768 ContextLifecycleObserver::trace(visitor); | |
| 745 visitor->trace(m_navigatorVR); | 769 visitor->trace(m_navigatorVR); |
| 746 visitor->trace(m_capabilities); | 770 visitor->trace(m_capabilities); |
| 747 visitor->trace(m_stageParameters); | 771 visitor->trace(m_stageParameters); |
| 748 visitor->trace(m_eyeParametersLeft); | 772 visitor->trace(m_eyeParametersLeft); |
| 749 visitor->trace(m_eyeParametersRight); | 773 visitor->trace(m_eyeParametersRight); |
| 750 visitor->trace(m_layer); | 774 visitor->trace(m_layer); |
| 751 visitor->trace(m_renderingContext); | 775 visitor->trace(m_renderingContext); |
| 752 visitor->trace(m_scriptedAnimationController); | 776 visitor->trace(m_scriptedAnimationController); |
| 753 visitor->trace(m_pendingPresentResolvers); | 777 visitor->trace(m_pendingPresentResolvers); |
| 754 } | 778 } |
| 755 | 779 |
| 756 } // namespace blink | 780 } // namespace blink |
| OLD | NEW |