| 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..1963d38ddaaff7ae8c5511bf56aecbc81103d201 100644
|
| --- a/device/vr/android/gvr/gvr_device.cc
|
| +++ b/device/vr/android/gvr/gvr_device.cc
|
| @@ -127,9 +127,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 +189,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 +256,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 +267,37 @@ gvr::GvrApi* GvrDevice::GetGvrApi() {
|
| return delegate_->gvr_api();
|
| }
|
|
|
| +void GvrDevice::OnDisplayChanged() {
|
| + VRDisplayPtr vr_device_info = GetVRDevice();
|
| + if (vr_device_info.is_null())
|
| + return;
|
| +
|
| + vr_device_info->index = id();
|
| +
|
| + for (const auto& service : display_services_)
|
| + service.second->OnDisplayChanged(vr_device_info.Clone());
|
| +}
|
| +
|
| +void GvrDevice::OnExitPresent(VRServiceImpl* service) {
|
| + DisplayServiceMap::iterator it = display_services_.find(service);
|
| + if (it != display_services_.end())
|
| + it->second->OnExitPresent();
|
| +}
|
| +
|
| +void GvrDevice::OnDisplayConnected() {
|
| + VRDisplayPtr vr_device_info = GetVRDevice();
|
| + if (vr_device_info.is_null())
|
| + return;
|
| +
|
| + vr_device_info->index = id();
|
| +
|
| + for (const auto& service : display_services_)
|
| + service.second->OnDisplayConnected(vr_device_info.Clone());
|
| +}
|
| +
|
| +void GvrDevice::OnDisplayDisconnected() {
|
| + for (const auto& service : display_services_)
|
| + service.second->OnDisplayDisconnected();
|
| +}
|
| +
|
| } // namespace device
|
|
|