| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/vr/android/gvr/gvr_device.h" | 5 #include "device/vr/android/gvr/gvr_device.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 left_eye->offset[2] = -left_eye_mat.m[2][3]; | 120 left_eye->offset[2] = -left_eye_mat.m[2][3]; |
| 121 | 121 |
| 122 gvr::Mat4f right_eye_mat = gvr_api->GetEyeFromHeadMatrix(GVR_RIGHT_EYE); | 122 gvr::Mat4f right_eye_mat = gvr_api->GetEyeFromHeadMatrix(GVR_RIGHT_EYE); |
| 123 right_eye->offset[0] = -right_eye_mat.m[0][3]; | 123 right_eye->offset[0] = -right_eye_mat.m[0][3]; |
| 124 right_eye->offset[1] = -right_eye_mat.m[1][3]; | 124 right_eye->offset[1] = -right_eye_mat.m[1][3]; |
| 125 right_eye->offset[2] = -right_eye_mat.m[2][3]; | 125 right_eye->offset[2] = -right_eye_mat.m[2][3]; |
| 126 | 126 |
| 127 return device; | 127 return device; |
| 128 } | 128 } |
| 129 | 129 |
| 130 VRPosePtr GvrDevice::GetPose() { | 130 VRPosePtr GvrDevice::GetPose(VRServiceImpl* service) { |
| 131 TRACE_EVENT0("input", "GvrDevice::GetSensorState"); | 131 TRACE_EVENT0("input", "GvrDevice::GetSensorState"); |
| 132 | 132 |
| 133 if (CheckAccessAllowed(service)) |
| 134 return nullptr; |
| 135 |
| 133 VRPosePtr pose = VRPose::New(); | 136 VRPosePtr pose = VRPose::New(); |
| 134 | 137 |
| 135 pose->timestamp = base::Time::Now().ToJsTime(); | 138 pose->timestamp = base::Time::Now().ToJsTime(); |
| 136 | 139 |
| 137 // Increment pose frame counter always, even if it's a faked pose. | 140 // Increment pose frame counter always, even if it's a faked pose. |
| 138 pose->poseIndex = ++pose_index_; | 141 pose->poseIndex = ++pose_index_; |
| 139 | 142 |
| 140 pose->orientation = mojo::Array<float>::New(4); | 143 pose->orientation = mojo::Array<float>::New(4); |
| 141 | 144 |
| 142 gvr::GvrApi* gvr_api = GetGvrApi(); | 145 gvr::GvrApi* gvr_api = GetGvrApi(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 pose->position[2] = decomposed_transform.translate[2]; | 182 pose->position[2] = decomposed_transform.translate[2]; |
| 180 } | 183 } |
| 181 | 184 |
| 182 // Save the underlying GVR pose for use by rendering. It can't use a | 185 // Save the underlying GVR pose for use by rendering. It can't use a |
| 183 // VRPosePtr since that's a different data type. | 186 // VRPosePtr since that's a different data type. |
| 184 delegate_->SetGvrPoseForWebVr(head_mat, pose_index_); | 187 delegate_->SetGvrPoseForWebVr(head_mat, pose_index_); |
| 185 | 188 |
| 186 return pose; | 189 return pose; |
| 187 } | 190 } |
| 188 | 191 |
| 189 void GvrDevice::ResetPose() { | 192 void GvrDevice::ResetPose(VRServiceImpl* service) { |
| 193 if (CheckAccessAllowed(service)) |
| 194 return; |
| 195 |
| 190 gvr::GvrApi* gvr_api = GetGvrApi(); | 196 gvr::GvrApi* gvr_api = GetGvrApi(); |
| 191 if (gvr_api) | 197 if (gvr_api) |
| 192 gvr_api->ResetTracking(); | 198 gvr_api->ResetTracking(); |
| 193 } | 199 } |
| 194 | 200 |
| 195 bool GvrDevice::RequestPresent(bool secure_origin) { | 201 bool GvrDevice::RequestPresent(VRServiceImpl* service, bool secure_origin) { |
| 202 if (presenting_service_ != nullptr) |
| 203 if (presenting_service_ != service) |
| 204 return false; |
| 205 |
| 206 // One service could present on several devices at the same time |
| 207 // and different service could present on different devices the same time |
| 208 if (presenting_service_ == nullptr) |
| 209 presenting_service_ = service; |
| 210 |
| 196 secure_origin_ = secure_origin; | 211 secure_origin_ = secure_origin; |
| 197 if (delegate_) | 212 if (delegate_) |
| 198 delegate_->SetWebVRSecureOrigin(secure_origin_); | 213 delegate_->SetWebVRSecureOrigin(secure_origin_); |
| 199 return gvr_provider_->RequestPresent(); | 214 |
| 215 if (!gvr_provider_->RequestPresent()) { |
| 216 return false; |
| 217 } |
| 218 return true; |
| 200 } | 219 } |
| 201 | 220 |
| 202 void GvrDevice::ExitPresent() { | 221 void GvrDevice::ExitPresent(VRServiceImpl* service) { |
| 222 if (IsPresentingService(service)) |
| 223 presenting_service_ = nullptr; |
| 224 |
| 203 gvr_provider_->ExitPresent(); | 225 gvr_provider_->ExitPresent(); |
| 226 OnExitPresent(service); |
| 204 } | 227 } |
| 205 | 228 |
| 206 void GvrDevice::SubmitFrame(VRPosePtr pose) { | 229 void GvrDevice::SubmitFrame(VRServiceImpl* service, VRPosePtr pose) { |
| 207 if (delegate_) | 230 if (IsPresentingService(service)) { |
| 208 delegate_->SubmitWebVRFrame(); | 231 if (delegate_) |
| 232 delegate_->SubmitWebVRFrame(); |
| 233 } |
| 209 } | 234 } |
| 210 | 235 |
| 211 void GvrDevice::UpdateLayerBounds(VRLayerBoundsPtr leftBounds, | 236 void GvrDevice::UpdateLayerBounds(VRServiceImpl* service, |
| 237 VRLayerBoundsPtr leftBounds, |
| 212 VRLayerBoundsPtr rightBounds) { | 238 VRLayerBoundsPtr rightBounds) { |
| 213 if (!delegate_) | 239 if (CheckAccessAllowed(service)) { |
| 214 return; | 240 if (!delegate_) |
| 241 return; |
| 215 | 242 |
| 216 delegate_->UpdateWebVRTextureBounds(0, // Left eye | 243 delegate_->UpdateWebVRTextureBounds(0, // Left eye |
| 217 leftBounds->left, leftBounds->top, | 244 leftBounds->left, leftBounds->top, |
| 218 leftBounds->width, leftBounds->height); | 245 leftBounds->width, leftBounds->height); |
| 219 delegate_->UpdateWebVRTextureBounds(1, // Right eye | 246 delegate_->UpdateWebVRTextureBounds(1, // Right eye |
| 220 rightBounds->left, rightBounds->top, | 247 rightBounds->left, rightBounds->top, |
| 221 rightBounds->width, rightBounds->height); | 248 rightBounds->width, |
| 249 rightBounds->height); |
| 250 } |
| 222 } | 251 } |
| 223 | 252 |
| 224 void GvrDevice::SetDelegate(GvrDelegate* delegate) { | 253 void GvrDevice::SetDelegate(GvrDelegate* delegate) { |
| 225 delegate_ = delegate; | 254 delegate_ = delegate; |
| 226 | 255 |
| 227 // Notify the clients that this device has changed | 256 // Notify the clients that this device has changed |
| 228 if (delegate_) { | 257 if (delegate_) { |
| 229 delegate_->SetWebVRSecureOrigin(secure_origin_); | 258 delegate_->SetWebVRSecureOrigin(secure_origin_); |
| 230 VRDeviceManager::GetInstance()->OnDeviceChanged(GetVRDevice()); | 259 this->OnDisplayChanged(); |
| 231 } | 260 } |
| 232 } | 261 } |
| 233 | 262 |
| 234 gvr::GvrApi* GvrDevice::GetGvrApi() { | 263 gvr::GvrApi* GvrDevice::GetGvrApi() { |
| 235 if (!delegate_) | 264 if (!delegate_) |
| 236 return nullptr; | 265 return nullptr; |
| 237 | 266 |
| 238 return delegate_->gvr_api(); | 267 return delegate_->gvr_api(); |
| 239 } | 268 } |
| 240 | 269 |
| 270 void GvrDevice::OnDisplayChanged() { |
| 271 VRDisplayPtr vr_device_info = GetVRDevice(); |
| 272 if (vr_device_info.is_null()) |
| 273 return; |
| 274 |
| 275 vr_device_info->index = id(); |
| 276 |
| 277 for (const auto& service : display_services_) |
| 278 service.second->OnDisplayChanged(vr_device_info.Clone()); |
| 279 } |
| 280 |
| 281 void GvrDevice::OnExitPresent(VRServiceImpl* service) { |
| 282 DisplayServiceMap::iterator it = display_services_.find(service); |
| 283 if (it != display_services_.end()) |
| 284 it->second->OnExitPresent(); |
| 285 } |
| 286 |
| 287 void GvrDevice::OnDisplayConnected() { |
| 288 VRDisplayPtr vr_device_info = GetVRDevice(); |
| 289 if (vr_device_info.is_null()) |
| 290 return; |
| 291 |
| 292 vr_device_info->index = id(); |
| 293 |
| 294 for (const auto& service : display_services_) |
| 295 service.second->OnDisplayConnected(vr_device_info.Clone()); |
| 296 } |
| 297 |
| 298 void GvrDevice::OnDisplayDisconnected() { |
| 299 for (const auto& service : display_services_) |
| 300 service.second->OnDisplayDisconnected(); |
| 301 } |
| 302 |
| 241 } // namespace device | 303 } // namespace device |
| OLD | NEW |