| 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 eb5950d44d394193f96dc9d3ae47e35d98459849..d09411fb5e3af74ba688a138dec66829ad6938df 100644
|
| --- a/third_party/WebKit/Source/modules/vr/VRDisplay.cpp
|
| +++ b/third_party/WebKit/Source/modules/vr/VRDisplay.cpp
|
| @@ -35,9 +35,11 @@ VREye stringToVREye(const String& whichEye) {
|
|
|
| } // namespace
|
|
|
| +unsigned VRDisplay::nextId = 1;
|
| +
|
| VRDisplay::VRDisplay(NavigatorVR* navigatorVR)
|
| : m_navigatorVR(navigatorVR),
|
| - m_displayId(0),
|
| + m_displayId(nextId),
|
| m_isConnected(false),
|
| m_isPresenting(false),
|
| m_canUpdateFramePose(true),
|
| @@ -46,7 +48,11 @@ VRDisplay::VRDisplay(NavigatorVR* navigatorVR)
|
| m_eyeParametersRight(new VREyeParameters()),
|
| m_depthNear(0.01),
|
| m_depthFar(10000.0),
|
| - m_fullscreenCheckTimer(this, &VRDisplay::onFullscreenCheck) {}
|
| + m_fullscreenCheckTimer(this, &VRDisplay::onFullscreenCheck),
|
| + m_binding(this) {
|
| + if (nextId != MAX)
|
| + ++nextId;
|
| +}
|
|
|
| VRDisplay::~VRDisplay() {}
|
|
|
| @@ -55,7 +61,6 @@ VRController* VRDisplay::controller() {
|
| }
|
|
|
| void VRDisplay::update(const device::blink::VRDisplayPtr& display) {
|
| - m_displayId = display->index;
|
| m_displayName = display->displayName;
|
| m_isConnected = true;
|
|
|
| @@ -109,14 +114,21 @@ VRPose* VRDisplay::getPose() {
|
|
|
| void VRDisplay::updatePose() {
|
| if (m_canUpdateFramePose) {
|
| - m_framePose = controller()->getPose(m_displayId);
|
| + if (!m_client)
|
| + return;
|
| + device::blink::VRPosePtr pose;
|
| + m_client->GetPose(&pose);
|
| + m_framePose = std::move(pose);
|
| if (m_isPresenting)
|
| m_canUpdateFramePose = false;
|
| }
|
| }
|
|
|
| void VRDisplay::resetPose() {
|
| - controller()->resetPose(m_displayId);
|
| + if (!m_client)
|
| + return;
|
| +
|
| + m_client->ResetPose();
|
| }
|
|
|
| VREyeParameters* VRDisplay::getEyeParameters(const String& whichEye) {
|
| @@ -239,7 +251,16 @@ ScriptPromise VRDisplay::requestPresent(ScriptState* scriptState,
|
|
|
| if (firstPresent) {
|
| bool secureContext = scriptState->getExecutionContext()->isSecureContext();
|
| - controller()->requestPresent(resolver, m_displayId, secureContext);
|
| + if (!m_client) {
|
| + DOMException* exception = DOMException::create(
|
| + InvalidStateError, "The service is no longer active.");
|
| + resolver->reject(exception);
|
| + return promise;
|
| + }
|
| + m_client->RequestPresent(
|
| + secureContext, convertToBaseCallback(WTF::bind(
|
| + &VRDisplay::onPresentComplete, wrapPersistent(this),
|
| + wrapPersistent(resolver))));
|
| } else {
|
| updateLayerBounds();
|
| resolver->resolve();
|
| @@ -248,6 +269,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();
|
| @@ -260,7 +293,13 @@ ScriptPromise VRDisplay::exitPresent(ScriptState* scriptState) {
|
| return promise;
|
| }
|
|
|
| - controller()->exitPresent(m_displayId);
|
| + if (!m_client) {
|
| + DOMException* exception =
|
| + DOMException::create(InvalidStateError, "VRService is not available.");
|
| + resolver->reject(exception);
|
| + return promise;
|
| + }
|
| + m_client->ExitPresent();
|
|
|
| resolver->resolve();
|
|
|
| @@ -340,8 +379,10 @@ void VRDisplay::updateLayerBounds() {
|
| rightBounds->height = 1.0f;
|
| }
|
|
|
| - controller()->updateLayerBounds(m_displayId, std::move(leftBounds),
|
| - std::move(rightBounds));
|
| + if (!m_client)
|
| + return;
|
| +
|
| + m_client->UpdateLayerBounds(std::move(leftBounds), std::move(rightBounds));
|
| }
|
|
|
| HeapVector<VRLayer> VRDisplay::getLayers() {
|
| @@ -388,10 +429,45 @@ void VRDisplay::submitFrame() {
|
| m_renderingContext->restoreColorMask();
|
| m_renderingContext->restoreClearColor();
|
|
|
| - controller()->submitFrame(m_displayId, m_framePose.Clone());
|
| + if (!m_client)
|
| + return;
|
| +
|
| + m_client->SubmitFrame(m_framePose.Clone());
|
| m_canUpdateFramePose = true;
|
| }
|
|
|
| +void VRDisplay::RegisterDeviceClient(device::blink::VRDeviceClientPtr client) {
|
| + if (!client) {
|
| + m_client = std::move(client);
|
| + }
|
| +}
|
| +
|
| +void VRDisplay::UpdateDisplayInfo(device::blink::VRDisplayPtr display) {
|
| + if (!display.is_null()) {
|
| + update(display);
|
| + }
|
| +}
|
| +
|
| +void VRDisplay::OnDisplayChanged(device::blink::VRDisplayPtr display) {
|
| + update(display);
|
| +}
|
| +
|
| +void VRDisplay::OnExitPresent() {
|
| + forceExitPresent();
|
| +}
|
| +
|
| +void VRDisplay::OnDisplayConnected(device::blink::VRDisplayPtr display) {
|
| + update(display);
|
| +
|
| + 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
|
| @@ -402,10 +478,20 @@ void VRDisplay::onFullscreenCheck(TimerBase*) {
|
| m_isPresenting = false;
|
| m_navigatorVR->fireVRDisplayPresentChange(this);
|
| m_fullscreenCheckTimer.stop();
|
| - controller()->exitPresent(m_displayId);
|
| + if (!m_client)
|
| + return;
|
| + m_client->ExitPresent();
|
| }
|
| }
|
|
|
| +device::blink::VRDisplayClientPtr VRDisplay::BindClient() {
|
| + return std::move(m_binding.CreateInterfacePtrAndBind());
|
| +}
|
| +
|
| +void VRDisplay::shutdownMessagePipe() {
|
| + m_binding.Close();
|
| +}
|
| +
|
| DEFINE_TRACE(VRDisplay) {
|
| visitor->trace(m_navigatorVR);
|
| visitor->trace(m_capabilities);
|
|
|