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

Unified Diff: device/vr/android/gvr/gvr_device.cc

Issue 2420743003: mojo VR interface simplified (Closed)
Patch Set: update binding process and update some unittest 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: device/vr/android/gvr/gvr_device.cc
diff --git a/device/vr/android/gvr/gvr_device.cc b/device/vr/android/gvr/gvr_device.cc
index 9238409817038e7f9ada4174f54f00923ae0bab6..5aed5f3c32931899eaab0c244a69684eba5ceb5f 100644
--- a/device/vr/android/gvr/gvr_device.cc
+++ b/device/vr/android/gvr/gvr_device.cc
@@ -34,8 +34,6 @@ VRDisplayPtr GvrDevice::GetVRDevice() {
VRDisplayPtr device = VRDisplay::New();
- device->index = id();
-
device->capabilities = VRDisplayCapabilities::New();
device->capabilities->hasOrientation = true;
device->capabilities->hasPosition = false;
@@ -127,9 +125,12 @@ VRDisplayPtr GvrDevice::GetVRDevice() {
return device;
}
-VRPosePtr GvrDevice::GetPose() {
+VRPosePtr GvrDevice::GetPose(VRServiceImpl* service) {
TRACE_EVENT0("input", "GvrDevice::GetSensorState");
+ if (CheckAccessAllowed(service))
+ return nullptr;
+
VRPosePtr pose = VRPose::New();
pose->timestamp = base::Time::Now().ToJsTime();
@@ -186,39 +187,65 @@ VRPosePtr GvrDevice::GetPose() {
return pose;
}
-void GvrDevice::ResetPose() {
+void GvrDevice::ResetPose(VRServiceImpl* service) {
+ if (CheckAccessAllowed(service))
+ return;
+
gvr::GvrApi* gvr_api = GetGvrApi();
if (gvr_api)
gvr_api->ResetTracking();
}
-bool GvrDevice::RequestPresent(bool secure_origin) {
+bool GvrDevice::RequestPresent(VRServiceImpl* service, bool secure_origin) {
+ if (presenting_service_ != nullptr)
+ if (presenting_service_ != service)
+ return false;
+
+ // One service could present on several devices at the same time
+ // and different service could present on different devices the same time
+ if (presenting_service_ == nullptr)
+ presenting_service_ = service;
+
secure_origin_ = secure_origin;
if (delegate_)
delegate_->SetWebVRSecureOrigin(secure_origin_);
- return gvr_provider_->RequestPresent();
+
+ if (!gvr_provider_->RequestPresent()) {
+ return false;
+ }
+ return true;
}
-void GvrDevice::ExitPresent() {
+void GvrDevice::ExitPresent(VRServiceImpl* service) {
+ if (IsPresentingService(service))
+ presenting_service_ = nullptr;
+
gvr_provider_->ExitPresent();
+ OnExitPresent(service);
}
-void GvrDevice::SubmitFrame(VRPosePtr pose) {
- if (delegate_)
- delegate_->SubmitWebVRFrame();
+void GvrDevice::SubmitFrame(VRServiceImpl* service, VRPosePtr pose) {
+ if (IsPresentingService(service)) {
+ if (delegate_)
+ delegate_->SubmitWebVRFrame();
+ }
}
-void GvrDevice::UpdateLayerBounds(VRLayerBoundsPtr leftBounds,
+void GvrDevice::UpdateLayerBounds(VRServiceImpl* service,
+ VRLayerBoundsPtr leftBounds,
VRLayerBoundsPtr rightBounds) {
- if (!delegate_)
- return;
-
- delegate_->UpdateWebVRTextureBounds(0, // Left eye
- leftBounds->left, leftBounds->top,
- leftBounds->width, leftBounds->height);
- delegate_->UpdateWebVRTextureBounds(1, // Right eye
- rightBounds->left, rightBounds->top,
- rightBounds->width, rightBounds->height);
+ if (CheckAccessAllowed(service)) {
+ if (!delegate_)
+ return;
+
+ delegate_->UpdateWebVRTextureBounds(0, // Left eye
+ leftBounds->left, leftBounds->top,
+ leftBounds->width, leftBounds->height);
+ delegate_->UpdateWebVRTextureBounds(1, // Right eye
+ rightBounds->left, rightBounds->top,
+ rightBounds->width,
+ rightBounds->height);
+ }
}
void GvrDevice::SetDelegate(GvrDelegate* delegate) {
@@ -227,7 +254,7 @@ void GvrDevice::SetDelegate(GvrDelegate* delegate) {
// Notify the clients that this device has changed
if (delegate_) {
delegate_->SetWebVRSecureOrigin(secure_origin_);
- VRDeviceManager::GetInstance()->OnDeviceChanged(GetVRDevice());
+ this->OnDisplayChanged();
}
}
@@ -238,4 +265,33 @@ gvr::GvrApi* GvrDevice::GetGvrApi() {
return delegate_->gvr_api();
}
+void GvrDevice::OnDisplayChanged() {
+ VRDisplayPtr vr_device_info = GetVRDevice();
+ if (vr_device_info.is_null())
+ return;
+
+ for (const auto& client : display_clients_)
+ client.second->OnDisplayChanged(vr_device_info.Clone());
+}
+
+void GvrDevice::OnExitPresent(VRServiceImpl* service) {
+ DisplayClientMap::iterator it = display_clients_.find(service);
+ if (it != display_clients_.end())
+ it->second->OnExitPresent();
+}
+
+void GvrDevice::OnDisplayConnected() {
+ VRDisplayPtr vr_device_info = GetVRDevice();
+ if (vr_device_info.is_null())
+ return;
+
+ for (const auto& client : display_clients_)
+ client.second->OnDisplayConnected(vr_device_info.Clone());
+}
+
+void GvrDevice::OnDisplayDisconnected() {
+ for (const auto& client : display_clients_)
+ client.second->OnDisplayDisconnected();
+}
+
} // namespace device

Powered by Google App Engine
This is Rietveld 408576698