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

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

Issue 2420743003: mojo VR interface simplified (Closed)
Patch Set: Address bajones@ comments and some clean up 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/VRController.cpp
diff --git a/third_party/WebKit/Source/modules/vr/VRController.cpp b/third_party/WebKit/Source/modules/vr/VRController.cpp
index 6ad2e9316cd3b0b2f026c675d95d5da4fa534b2e..9bf199f91db33d53df3679d7fd813c4489f0be8b 100644
--- a/third_party/WebKit/Source/modules/vr/VRController.cpp
+++ b/third_party/WebKit/Source/modules/vr/VRController.cpp
@@ -17,11 +17,9 @@ namespace blink {
VRController::VRController(NavigatorVR* navigatorVR)
: ContextLifecycleObserver(navigatorVR->document()),
- m_navigatorVR(navigatorVR),
- m_binding(this) {
+ m_navigatorVR(navigatorVR) {
navigatorVR->document()->frame()->interfaceProvider()->getInterface(
mojo::GetProxy(&m_service));
- m_service->SetClient(m_binding.CreateInterfacePtrAndBind());
}
VRController::~VRController() {}
@@ -40,64 +38,6 @@ void VRController::getDisplays(ScriptPromiseResolver* resolver) {
WTF::bind(&VRController::onGetDisplays, wrapPersistent(this))));
}
-device::blink::VRPosePtr VRController::getPose(unsigned index) {
- if (!m_service)
- return nullptr;
-
- device::blink::VRPosePtr pose;
- m_service->GetPose(index, &pose);
- return pose;
-}
-
-void VRController::resetPose(unsigned index) {
- if (!m_service)
- return;
-
- m_service->ResetPose(index);
-}
-
-void VRController::requestPresent(ScriptPromiseResolver* resolver,
- unsigned index,
- bool secureOrigin) {
- if (!m_service) {
- DOMException* exception = DOMException::create(
- InvalidStateError, "The service is no longer active.");
- resolver->reject(exception);
- return;
- }
-
- m_service->RequestPresent(
- index, secureOrigin,
- convertToBaseCallback(WTF::bind(&VRController::onPresentComplete,
- wrapPersistent(this),
- wrapPersistent(resolver), index)));
-}
-
-void VRController::exitPresent(unsigned index) {
- if (!m_service)
- return;
-
- m_service->ExitPresent(index);
-}
-
-void VRController::submitFrame(unsigned index, device::blink::VRPosePtr pose) {
- if (!m_service)
- return;
-
- m_service->SubmitFrame(index, std::move(pose));
-}
-
-void VRController::updateLayerBounds(
- unsigned index,
- device::blink::VRLayerBoundsPtr leftBounds,
- device::blink::VRLayerBoundsPtr rightBounds) {
- if (!m_service)
- return;
-
- m_service->UpdateLayerBounds(index, std::move(leftBounds),
- std::move(rightBounds));
-}
-
VRDisplay* VRController::createOrUpdateDisplay(
const device::blink::VRDisplayPtr& display) {
VRDisplay* vrDisplay = getDisplayForIndex(display->index);
@@ -111,11 +51,14 @@ VRDisplay* VRController::createOrUpdateDisplay(
}
VRDisplayVector VRController::updateDisplays(
- mojo::WTFArray<device::blink::VRDisplayPtr> displays) {
+ mojo::WTFArray<device::blink::VRDisplayWithServicePtr> displays) {
VRDisplayVector vrDisplays;
- for (const auto& display : displays.PassStorage()) {
- VRDisplay* vrDisplay = createOrUpdateDisplay(display);
+ for (const auto& displayWithService : displays.PassStorage()) {
+ VRDisplay* vrDisplay =
+ createOrUpdateDisplay(std::move(displayWithService->display));
+ if (displayWithService->service)
+ vrDisplay->setService(std::move(displayWithService->service));
vrDisplays.append(vrDisplay);
}
@@ -135,8 +78,11 @@ VRDisplay* VRController::getDisplayForIndex(unsigned index) {
}
void VRController::onGetDisplays(
- mojo::WTFArray<device::blink::VRDisplayPtr> displays) {
+ mojo::WTFArray<device::blink::VRDisplayWithServicePtr> displays) {
VRDisplayVector outDisplays = updateDisplays(std::move(displays));
+ for (const auto& VRDisplay : outDisplays) {
+ VRDisplay->RegisterDisplayService();
+ }
std::unique_ptr<VRGetDevicesCallback> callback =
m_pendingGetDevicesCallbacks.takeFirst();
@@ -146,68 +92,15 @@ void VRController::onGetDisplays(
callback->onSuccess(outDisplays);
}
-void VRController::onPresentComplete(ScriptPromiseResolver* resolver,
- unsigned index,
- bool success) {
- VRDisplay* vrDisplay = getDisplayForIndex(index);
- if (!vrDisplay) {
- DOMException* exception =
- DOMException::create(InvalidStateError, "VRDisplay not found.");
- resolver->reject(exception);
- return;
- }
-
- if (success) {
- vrDisplay->beginPresent(resolver);
- } else {
- vrDisplay->forceExitPresent();
- DOMException* exception = DOMException::create(
- NotAllowedError, "Presentation request was denied.");
- resolver->reject(exception);
- }
-}
-
-void VRController::OnDisplayChanged(device::blink::VRDisplayPtr display) {
- VRDisplay* vrDisplay = getDisplayForIndex(display->index);
- if (!vrDisplay)
- return;
-
- vrDisplay->update(display);
-}
-
-void VRController::OnExitPresent(unsigned index) {
- VRDisplay* vrDisplay = getDisplayForIndex(index);
- if (vrDisplay)
- vrDisplay->forceExitPresent();
-}
-
-void VRController::OnDisplayConnected(device::blink::VRDisplayPtr display) {
- VRDisplay* vrDisplay = createOrUpdateDisplay(display);
- if (!vrDisplay)
- return;
-
- m_navigatorVR->fireVREvent(VRDisplayEvent::create(
- EventTypeNames::vrdisplayconnect, true, false, vrDisplay, "connect"));
-}
-
-void VRController::OnDisplayDisconnected(unsigned index) {
- VRDisplay* vrDisplay = getDisplayForIndex(index);
- if (!vrDisplay)
- return;
-
- vrDisplay->disconnected();
-
- m_navigatorVR->fireVREvent(
- VRDisplayEvent::create(EventTypeNames::vrdisplaydisconnect, true, false,
- vrDisplay, "disconnect"));
-}
-
void VRController::contextDestroyed() {
// If the document context was destroyed, shut down the client connection
// and never call the mojo service again.
- m_binding.Close();
m_service.reset();
+ // Shutdown all displays' message pipe
+ for (size_t i = 0; i < m_displays.size(); ++i)
+ m_displays[i]->shutdownMessagePipe();
+
// The context is not automatically cleared, so do it manually.
ContextLifecycleObserver::clearContext();
}

Powered by Google App Engine
This is Rietveld 408576698