Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Unified Diff: third_party/WebKit/Source/modules/vr/VRDisplay.cpp

Issue 2420743003: mojo VR interface simplified (Closed)
Patch Set: address leon@ comments about name Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 b7c149764abad85e4d1c99449b0fc3429db8e67b..3fc7c91eb406025d55b5439b6643a92a997e950e 100644
--- a/third_party/WebKit/Source/modules/vr/VRDisplay.cpp
+++ b/third_party/WebKit/Source/modules/vr/VRDisplay.cpp
@@ -36,9 +36,11 @@ VREye stringToVREye(const String& whichEye) {
} // namespace
+unsigned VRDisplay::nextId = 1;
+
VRDisplay::VRDisplay(NavigatorVR* navigatorVR)
: m_navigatorVR(navigatorVR),
- m_displayId(0),
+ m_displayId(nextId),
bajones 2016/10/25 22:21:38 I know that there's been discussion about the fact
shaobo.yan 2016/10/26 01:19:22 Shall I take the chance to see if the gamepad part
m_isConnected(false),
m_isPresenting(false),
m_canUpdateFramePose(true),
@@ -47,7 +49,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,8 +61,7 @@ VRController* VRDisplay::controller() {
return m_navigatorVR->controller();
}
-void VRDisplay::update(const device::blink::VRDisplayPtr& display) {
- m_displayId = display->index;
+void VRDisplay::update(const device::mojom::blink::VRDisplayPtr& display) {
m_displayName = display->displayName;
m_isConnected = true;
@@ -110,14 +115,21 @@ VRPose* VRDisplay::getPose() {
void VRDisplay::updatePose() {
if (m_canUpdateFramePose) {
- m_framePose = controller()->getPose(m_displayId);
+ if (!m_device)
+ return;
+ device::mojom::blink::VRPosePtr pose;
+ m_device->GetPose(&pose);
+ m_framePose = std::move(pose);
if (m_isPresenting)
m_canUpdateFramePose = false;
}
}
void VRDisplay::resetPose() {
- controller()->resetPose(m_displayId);
+ if (!m_device)
+ return;
+
+ m_device->ResetPose();
}
VREyeParameters* VRDisplay::getEyeParameters(const String& whichEye) {
@@ -260,7 +272,16 @@ ScriptPromise VRDisplay::requestPresent(ScriptState* scriptState,
if (firstPresent) {
bool secureContext = scriptState->getExecutionContext()->isSecureContext();
- controller()->requestPresent(resolver, m_displayId, secureContext);
+ if (!m_device) {
+ DOMException* exception = DOMException::create(
+ InvalidStateError, "The service is no longer active.");
+ resolver->reject(exception);
+ return promise;
+ }
+ m_device->RequestPresent(
+ secureContext, convertToBaseCallback(WTF::bind(
+ &VRDisplay::onPresentComplete, wrapPersistent(this),
+ wrapPersistent(resolver))));
} else {
updateLayerBounds();
resolver->resolve();
@@ -270,6 +291,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();
@@ -282,7 +315,13 @@ ScriptPromise VRDisplay::exitPresent(ScriptState* scriptState) {
return promise;
}
- controller()->exitPresent(m_displayId);
+ if (!m_device) {
+ DOMException* exception =
+ DOMException::create(InvalidStateError, "VRService is not available.");
+ resolver->reject(exception);
+ return promise;
+ }
+ m_device->ExitPresent();
resolver->resolve();
@@ -330,10 +369,10 @@ void VRDisplay::forceExitPresent() {
void VRDisplay::updateLayerBounds() {
// 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];
@@ -361,8 +400,10 @@ void VRDisplay::updateLayerBounds() {
rightBounds->height = 1.0f;
}
- controller()->updateLayerBounds(m_displayId, std::move(leftBounds),
- std::move(rightBounds));
+ if (!m_device)
+ return;
+
+ m_device->UpdateLayerBounds(std::move(leftBounds), std::move(rightBounds));
}
HeapVector<VRLayer> VRDisplay::getLayers() {
@@ -409,10 +450,45 @@ void VRDisplay::submitFrame() {
m_renderingContext->restoreColorMask();
m_renderingContext->restoreClearColor();
- controller()->submitFrame(m_displayId, m_framePose.Clone());
+ if (!m_device)
+ return;
+
+ m_device->SubmitFrame(m_framePose.Clone());
m_canUpdateFramePose = true;
}
+void VRDisplay::RegisterDevice(device::mojom::blink::VRDevicePtr client) {
+ if (!client) {
+ m_device = std::move(client);
+ }
+}
+
+void VRDisplay::UpdateDisplayInfo(device::mojom::blink::VRDisplayPtr display) {
+ if (!display.is_null()) {
+ update(display);
+ }
+}
+
+void VRDisplay::OnDisplayChanged(device::mojom::blink::VRDisplayPtr display) {
+ update(display);
+}
+
+void VRDisplay::OnExitPresent() {
+ forceExitPresent();
+}
+
+void VRDisplay::OnDisplayConnected(device::mojom::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
@@ -423,10 +499,20 @@ void VRDisplay::onFullscreenCheck(TimerBase*) {
m_isPresenting = false;
m_navigatorVR->fireVRDisplayPresentChange(this);
m_fullscreenCheckTimer.stop();
- controller()->exitPresent(m_displayId);
+ if (!m_device)
+ return;
+ m_device->ExitPresent();
}
}
+device::mojom::blink::VRDisplayClientPtr VRDisplay::BindClient() {
+ return m_binding.CreateInterfacePtrAndBind();
+}
+
+void VRDisplay::shutdownMessagePipe() {
+ m_binding.Close();
+}
+
DEFINE_TRACE(VRDisplay) {
visitor->trace(m_navigatorVR);
visitor->trace(m_capabilities);

Powered by Google App Engine
This is Rietveld 408576698