Chromium Code Reviews| 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..e125980f9f16526bb081bce3d47e3eaf5dc596f6 100644 |
| --- a/device/vr/android/gvr/gvr_device.cc |
| +++ b/device/vr/android/gvr/gvr_device.cc |
| @@ -29,26 +29,26 @@ GvrDevice::GvrDevice(GvrDeviceProvider* provider, GvrDelegate* delegate) |
| GvrDevice::~GvrDevice() {} |
| -VRDisplayPtr GvrDevice::GetVRDevice() { |
| +mojom::VRDisplayInfoPtr GvrDevice::GetVRDevice() { |
| TRACE_EVENT0("input", "GvrDevice::GetVRDevice"); |
| - VRDisplayPtr device = VRDisplay::New(); |
| + mojom::VRDisplayInfoPtr device = mojom::VRDisplayInfo::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 +127,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 (!IsAccessAllowed(service)) |
| + return nullptr; |
| + |
| + mojom::VRPosePtr pose = mojom::VRPose::New(); |
| pose->timestamp = base::Time::Now().ToJsTime(); |
| @@ -186,39 +189,61 @@ VRPosePtr GvrDevice::GetPose() { |
| return pose; |
| } |
| -void GvrDevice::ResetPose() { |
| +void GvrDevice::ResetPose(VRServiceImpl* service) { |
| + if (!IsAccessAllowed(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 (!IsAccessAllowed(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(); |
| } |
| -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 (!IsAccessAllowed(service)) { |
|
dcheng
2016/11/04 05:12:20
Should this be an early return?
shaobo.yan
2016/11/05 08:11:38
Yes, and sorry for the fault.Updated to delete '!'
|
| + 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 +252,7 @@ void GvrDevice::SetDelegate(GvrDelegate* delegate) { |
| // Notify the clients that this device has changed |
| if (delegate_) { |
| delegate_->SetWebVRSecureOrigin(secure_origin_); |
| - VRDeviceManager::GetInstance()->OnDeviceChanged(GetVRDevice()); |
| + OnDisplayChanged(); |
| } |
| } |