| 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..0a7c745bccb97f49c4f4e7b84c101dfb1faaa588 100644
|
| --- a/third_party/WebKit/Source/modules/vr/VRDisplay.cpp
|
| +++ b/third_party/WebKit/Source/modules/vr/VRDisplay.cpp
|
| @@ -57,9 +57,10 @@ class VRDisplayFrameRequestCallback : public FrameRequestCallback {
|
|
|
| } // namespace
|
|
|
| -VRDisplay::VRDisplay(NavigatorVR* navigatorVR)
|
| +VRDisplay::VRDisplay(NavigatorVR* navigatorVR,
|
| + device::mojom::blink::VRDisplayPtr display,
|
| + device::mojom::blink::VRDisplayClientRequest request)
|
| : m_navigatorVR(navigatorVR),
|
| - m_displayId(0),
|
| m_isConnected(false),
|
| m_isPresenting(false),
|
| m_canUpdateFramePose(true),
|
| @@ -70,7 +71,11 @@ VRDisplay::VRDisplay(NavigatorVR* navigatorVR)
|
| m_depthFar(10000.0),
|
| m_fullscreenCheckTimer(this, &VRDisplay::onFullscreenCheck),
|
| m_animationCallbackRequested(false),
|
| - m_inAnimationFrame(false) {}
|
| + m_inAnimationFrame(false),
|
| + m_display(std::move(display)),
|
| + m_binding(this, std::move(request)) {
|
| + ThreadState::current()->registerPreFinalizer(this);
|
| +}
|
|
|
| VRDisplay::~VRDisplay() {}
|
|
|
| @@ -78,7 +83,7 @@ VRController* VRDisplay::controller() {
|
| return m_navigatorVR->controller();
|
| }
|
|
|
| -void VRDisplay::update(const device::blink::VRDisplayPtr& display) {
|
| +void VRDisplay::update(const device::mojom::blink::VRDisplayInfoPtr& display) {
|
| m_displayId = display->index;
|
| m_displayName = display->displayName;
|
| m_isConnected = true;
|
| @@ -133,14 +138,21 @@ VRPose* VRDisplay::getPose() {
|
|
|
| void VRDisplay::updatePose() {
|
| if (m_canUpdateFramePose) {
|
| - m_framePose = controller()->getPose(m_displayId);
|
| + 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() {
|
| - controller()->resetPose(m_displayId);
|
| + if (!m_display)
|
| + return;
|
| +
|
| + m_display->ResetPose();
|
| }
|
|
|
| VREyeParameters* VRDisplay::getEyeParameters(const String& whichEye) {
|
| @@ -299,7 +311,16 @@ ScriptPromise VRDisplay::requestPresent(ScriptState* scriptState,
|
|
|
| if (firstPresent) {
|
| bool secureContext = scriptState->getExecutionContext()->isSecureContext();
|
| - controller()->requestPresent(resolver, m_displayId, secureContext);
|
| + if (!m_display) {
|
| + DOMException* exception = DOMException::create(
|
| + InvalidStateError, "The service is no longer active.");
|
| + resolver->reject(exception);
|
| + return promise;
|
| + }
|
| + m_display->RequestPresent(
|
| + secureContext, convertToBaseCallback(WTF::bind(
|
| + &VRDisplay::onPresentComplete, wrapPersistent(this),
|
| + wrapPersistent(resolver))));
|
| } else {
|
| updateLayerBounds();
|
| resolver->resolve();
|
| @@ -309,6 +330,18 @@ ScriptPromise VRDisplay::requestPresent(ScriptState* scriptState,
|
| return promise;
|
| }
|
|
|
| +void VRDisplay::onPresentComplete(ScriptPromiseResolver* resolver,
|
| + bool success) {
|
| + if (success) {
|
| + this->beginPresent(resolver);
|
| + } else {
|
| + this->forceExitPresent();
|
| + DOMException* exception = DOMException::create(
|
| + NotAllowedError, "Presentation request was denied.");
|
| + resolver->reject(exception);
|
| + }
|
| +}
|
| +
|
| ScriptPromise VRDisplay::exitPresent(ScriptState* scriptState) {
|
| ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
|
| ScriptPromise promise = resolver->promise();
|
| @@ -321,7 +354,13 @@ ScriptPromise VRDisplay::exitPresent(ScriptState* scriptState) {
|
| return promise;
|
| }
|
|
|
| - controller()->exitPresent(m_displayId);
|
| + if (!m_display) {
|
| + DOMException* exception =
|
| + DOMException::create(InvalidStateError, "VRService is not available.");
|
| + resolver->reject(exception);
|
| + return promise;
|
| + }
|
| + m_display->ExitPresent();
|
|
|
| resolver->resolve();
|
|
|
| @@ -368,11 +407,14 @@ void VRDisplay::forceExitPresent() {
|
| }
|
|
|
| void VRDisplay::updateLayerBounds() {
|
| + if (!m_display)
|
| + return;
|
| +
|
| // Set up the texture bounds for the provided layer
|
| - device::blink::VRLayerBoundsPtr leftBounds =
|
| - device::blink::VRLayerBounds::New();
|
| - device::blink::VRLayerBoundsPtr rightBounds =
|
| - device::blink::VRLayerBounds::New();
|
| + device::mojom::blink::VRLayerBoundsPtr leftBounds =
|
| + device::mojom::blink::VRLayerBounds::New();
|
| + device::mojom::blink::VRLayerBoundsPtr rightBounds =
|
| + device::mojom::blink::VRLayerBounds::New();
|
|
|
| if (m_layer.leftBounds().size() == 4) {
|
| leftBounds->left = m_layer.leftBounds()[0];
|
| @@ -400,8 +442,7 @@ void VRDisplay::updateLayerBounds() {
|
| rightBounds->height = 1.0f;
|
| }
|
|
|
| - controller()->updateLayerBounds(m_displayId, std::move(leftBounds),
|
| - std::move(rightBounds));
|
| + m_display->UpdateLayerBounds(std::move(leftBounds), std::move(rightBounds));
|
| }
|
|
|
| HeapVector<VRLayer> VRDisplay::getLayers() {
|
| @@ -415,6 +456,9 @@ HeapVector<VRLayer> VRDisplay::getLayers() {
|
| }
|
|
|
| void VRDisplay::submitFrame() {
|
| + if (!m_display)
|
| + return;
|
| +
|
| Document* doc = m_navigatorVR->document();
|
| if (!m_isPresenting) {
|
| if (doc) {
|
| @@ -468,10 +512,29 @@ void VRDisplay::submitFrame() {
|
| m_renderingContext->restoreColorMask();
|
| m_renderingContext->restoreClearColor();
|
|
|
| - controller()->submitFrame(m_displayId, m_framePose.Clone());
|
| + m_display->SubmitFrame(m_framePose.Clone());
|
| m_canUpdateFramePose = true;
|
| }
|
|
|
| +void VRDisplay::OnDisplayChanged(
|
| + device::mojom::blink::VRDisplayInfoPtr display) {
|
| + update(display);
|
| +}
|
| +
|
| +void VRDisplay::OnExitPresent() {
|
| + forceExitPresent();
|
| +}
|
| +
|
| +void VRDisplay::onDisplayConnected() {
|
| + m_navigatorVR->fireVREvent(VRDisplayEvent::create(
|
| + EventTypeNames::vrdisplayconnect, true, false, this, "connect"));
|
| +}
|
| +
|
| +void VRDisplay::onDisplayDisconnected() {
|
| + m_navigatorVR->fireVREvent(VRDisplayEvent::create(
|
| + EventTypeNames::vrdisplaydisconnect, true, false, this, "disconnect"));
|
| +}
|
| +
|
| void VRDisplay::onFullscreenCheck(TimerBase*) {
|
| // TODO: This is a temporary measure to track if fullscreen mode has been
|
| // exited by the UA. If so we need to end VR presentation. Soon we won't
|
| @@ -482,7 +545,9 @@ void VRDisplay::onFullscreenCheck(TimerBase*) {
|
| m_isPresenting = false;
|
| m_navigatorVR->fireVRDisplayPresentChange(this);
|
| m_fullscreenCheckTimer.stop();
|
| - controller()->exitPresent(m_displayId);
|
| + if (!m_display)
|
| + return;
|
| + m_display->ExitPresent();
|
| }
|
| }
|
|
|
| @@ -494,6 +559,10 @@ ScriptedAnimationController& VRDisplay::ensureScriptedAnimationController(
|
| return *m_scriptedAnimationController;
|
| }
|
|
|
| +void VRDisplay::dispose() {
|
| + m_binding.Close();
|
| +}
|
| +
|
| DEFINE_TRACE(VRDisplay) {
|
| visitor->trace(m_navigatorVR);
|
| visitor->trace(m_capabilities);
|
|
|