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

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

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: 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..dba8cffbf7e180c6f0d6a7df8f0c50f0efcee284 100644
--- a/device/vr/android/gvr/gvr_device.cc
+++ b/device/vr/android/gvr/gvr_device.cc
@@ -29,26 +29,24 @@ GvrDevice::GvrDevice(GvrDeviceProvider* provider, GvrDelegate* delegate)
GvrDevice::~GvrDevice() {}
-VRDisplayPtr GvrDevice::GetVRDevice() {
+mojom::VRDisplayPtr GvrDevice::GetVRDevice() {
TRACE_EVENT0("input", "GvrDevice::GetVRDevice");
- VRDisplayPtr device = VRDisplay::New();
+ mojom::VRDisplayPtr device = mojom::VRDisplay::New();
- device->index = id();
-
- device->capabilities = VRDisplayCapabilities::New();
+ device->capabilities = mojom::VRDisplayCapabilities::New();
device->capabilities->hasOrientation = true;
device->capabilities->hasPosition = false;
device->capabilities->hasExternalDisplay = false;
device->capabilities->canPresent = true;
- device->leftEye = VREyeParameters::New();
- device->rightEye = VREyeParameters::New();
- VREyeParametersPtr& left_eye = device->leftEye;
- VREyeParametersPtr& right_eye = device->rightEye;
+ device->leftEye = mojom::VREyeParameters::New();
+ device->rightEye = mojom::VREyeParameters::New();
+ mojom::VREyeParametersPtr& left_eye = device->leftEye;
+ mojom::VREyeParametersPtr& right_eye = device->rightEye;
- left_eye->fieldOfView = VRFieldOfView::New();
- right_eye->fieldOfView = VRFieldOfView::New();
+ left_eye->fieldOfView = mojom::VRFieldOfView::New();
+ right_eye->fieldOfView = mojom::VRFieldOfView::New();
left_eye->offset = mojo::Array<float>::New(3);
right_eye->offset = mojo::Array<float>::New(3);
@@ -127,10 +125,13 @@ VRDisplayPtr GvrDevice::GetVRDevice() {
return device;
}
-VRPosePtr GvrDevice::GetPose() {
+mojom::VRPosePtr GvrDevice::GetPose(VRServiceImpl* service) {
TRACE_EVENT0("input", "GvrDevice::GetSensorState");
- VRPosePtr pose = VRPose::New();
+ if (CheckAccessAllowed(service))
+ return nullptr;
+
+ mojom::VRPosePtr pose = mojom::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;
bajones 2016/10/25 22:21:37 Any reason why CheckAccessAllowed isn't used here?
+
+ // 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()) {
bajones 2016/10/25 22:21:37 This change is unnecessary.
+ 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, mojom::VRPosePtr pose) {
+ if (IsPresentingService(service)) {
+ if (delegate_)
+ delegate_->SubmitWebVRFrame();
+ }
}
-void GvrDevice::UpdateLayerBounds(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);
+void GvrDevice::UpdateLayerBounds(VRServiceImpl* service,
+ mojom::VRLayerBoundsPtr leftBounds,
+ mojom::VRLayerBoundsPtr rightBounds) {
+ 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();
bajones 2016/10/25 22:21:38 just OnDisplayChanged(), please.
shaobo.yan 2016/10/26 01:19:22 Sorry about these three fault.
}
}
@@ -238,4 +265,33 @@ gvr::GvrApi* GvrDevice::GetGvrApi() {
return delegate_->gvr_api();
}
+void GvrDevice::OnDisplayChanged() {
bajones 2016/10/25 22:21:38 There's nothing GvrDevice specific about any of th
shaobo.yan 2016/10/26 01:19:22 Sure and if any kind of devices need different beh
+ mojom::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() {
+ mojom::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