Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 | 22 |
| 23 static const uint64_t kPredictionTimeWithoutVsyncNanos = 50000000; | 23 static const uint64_t kPredictionTimeWithoutVsyncNanos = 50000000; |
| 24 | 24 |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 GvrDevice::GvrDevice(GvrDeviceProvider* provider, GvrDelegate* delegate) | 27 GvrDevice::GvrDevice(GvrDeviceProvider* provider, GvrDelegate* delegate) |
| 28 : VRDevice(provider), delegate_(delegate), gvr_provider_(provider) {} | 28 : VRDevice(provider), delegate_(delegate), gvr_provider_(provider) {} |
| 29 | 29 |
| 30 GvrDevice::~GvrDevice() {} | 30 GvrDevice::~GvrDevice() {} |
| 31 | 31 |
| 32 VRDisplayPtr GvrDevice::GetVRDevice() { | 32 mojom::VRDisplayPtr GvrDevice::GetVRDevice() { |
| 33 TRACE_EVENT0("input", "GvrDevice::GetVRDevice"); | 33 TRACE_EVENT0("input", "GvrDevice::GetVRDevice"); |
| 34 | 34 |
| 35 VRDisplayPtr device = VRDisplay::New(); | 35 mojom::VRDisplayPtr device = mojom::VRDisplay::New(); |
| 36 | 36 |
| 37 device->index = id(); | 37 device->capabilities = mojom::VRDisplayCapabilities::New(); |
| 38 | |
| 39 device->capabilities = VRDisplayCapabilities::New(); | |
| 40 device->capabilities->hasOrientation = true; | 38 device->capabilities->hasOrientation = true; |
| 41 device->capabilities->hasPosition = false; | 39 device->capabilities->hasPosition = false; |
| 42 device->capabilities->hasExternalDisplay = false; | 40 device->capabilities->hasExternalDisplay = false; |
| 43 device->capabilities->canPresent = true; | 41 device->capabilities->canPresent = true; |
| 44 | 42 |
| 45 device->leftEye = VREyeParameters::New(); | 43 device->leftEye = mojom::VREyeParameters::New(); |
| 46 device->rightEye = VREyeParameters::New(); | 44 device->rightEye = mojom::VREyeParameters::New(); |
| 47 VREyeParametersPtr& left_eye = device->leftEye; | 45 mojom::VREyeParametersPtr& left_eye = device->leftEye; |
| 48 VREyeParametersPtr& right_eye = device->rightEye; | 46 mojom::VREyeParametersPtr& right_eye = device->rightEye; |
| 49 | 47 |
| 50 left_eye->fieldOfView = VRFieldOfView::New(); | 48 left_eye->fieldOfView = mojom::VRFieldOfView::New(); |
| 51 right_eye->fieldOfView = VRFieldOfView::New(); | 49 right_eye->fieldOfView = mojom::VRFieldOfView::New(); |
| 52 | 50 |
| 53 left_eye->offset = mojo::Array<float>::New(3); | 51 left_eye->offset = mojo::Array<float>::New(3); |
| 54 right_eye->offset = mojo::Array<float>::New(3); | 52 right_eye->offset = mojo::Array<float>::New(3); |
| 55 | 53 |
| 56 // TODO(bajones): GVR has a bug that causes it to return bad render target | 54 // TODO(bajones): GVR has a bug that causes it to return bad render target |
| 57 // sizes when the phone is in portait mode. Send arbitrary, | 55 // sizes when the phone is in portait mode. Send arbitrary, |
| 58 // not-horrifically-wrong values instead. | 56 // not-horrifically-wrong values instead. |
| 59 // gvr::Sizei render_target_size = gvr_api->GetRecommendedRenderTargetSize(); | 57 // gvr::Sizei render_target_size = gvr_api->GetRecommendedRenderTargetSize(); |
| 60 left_eye->renderWidth = 1024; // render_target_size.width / 2; | 58 left_eye->renderWidth = 1024; // render_target_size.width / 2; |
| 61 left_eye->renderHeight = 1024; // render_target_size.height; | 59 left_eye->renderHeight = 1024; // render_target_size.height; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 left_eye->offset[2] = -left_eye_mat.m[2][3]; | 118 left_eye->offset[2] = -left_eye_mat.m[2][3]; |
| 121 | 119 |
| 122 gvr::Mat4f right_eye_mat = gvr_api->GetEyeFromHeadMatrix(GVR_RIGHT_EYE); | 120 gvr::Mat4f right_eye_mat = gvr_api->GetEyeFromHeadMatrix(GVR_RIGHT_EYE); |
| 123 right_eye->offset[0] = -right_eye_mat.m[0][3]; | 121 right_eye->offset[0] = -right_eye_mat.m[0][3]; |
| 124 right_eye->offset[1] = -right_eye_mat.m[1][3]; | 122 right_eye->offset[1] = -right_eye_mat.m[1][3]; |
| 125 right_eye->offset[2] = -right_eye_mat.m[2][3]; | 123 right_eye->offset[2] = -right_eye_mat.m[2][3]; |
| 126 | 124 |
| 127 return device; | 125 return device; |
| 128 } | 126 } |
| 129 | 127 |
| 130 VRPosePtr GvrDevice::GetPose() { | 128 mojom::VRPosePtr GvrDevice::GetPose(VRServiceImpl* service) { |
| 131 TRACE_EVENT0("input", "GvrDevice::GetSensorState"); | 129 TRACE_EVENT0("input", "GvrDevice::GetSensorState"); |
| 132 | 130 |
| 133 VRPosePtr pose = VRPose::New(); | 131 if (CheckAccessAllowed(service)) |
| 132 return nullptr; | |
| 133 | |
| 134 mojom::VRPosePtr pose = mojom::VRPose::New(); | |
| 134 | 135 |
| 135 pose->timestamp = base::Time::Now().ToJsTime(); | 136 pose->timestamp = base::Time::Now().ToJsTime(); |
| 136 | 137 |
| 137 // Increment pose frame counter always, even if it's a faked pose. | 138 // Increment pose frame counter always, even if it's a faked pose. |
| 138 pose->poseIndex = ++pose_index_; | 139 pose->poseIndex = ++pose_index_; |
| 139 | 140 |
| 140 pose->orientation = mojo::Array<float>::New(4); | 141 pose->orientation = mojo::Array<float>::New(4); |
| 141 | 142 |
| 142 gvr::GvrApi* gvr_api = GetGvrApi(); | 143 gvr::GvrApi* gvr_api = GetGvrApi(); |
| 143 if (!gvr_api) { | 144 if (!gvr_api) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 pose->position[2] = decomposed_transform.translate[2]; | 180 pose->position[2] = decomposed_transform.translate[2]; |
| 180 } | 181 } |
| 181 | 182 |
| 182 // Save the underlying GVR pose for use by rendering. It can't use a | 183 // Save the underlying GVR pose for use by rendering. It can't use a |
| 183 // VRPosePtr since that's a different data type. | 184 // VRPosePtr since that's a different data type. |
| 184 delegate_->SetGvrPoseForWebVr(head_mat, pose_index_); | 185 delegate_->SetGvrPoseForWebVr(head_mat, pose_index_); |
| 185 | 186 |
| 186 return pose; | 187 return pose; |
| 187 } | 188 } |
| 188 | 189 |
| 189 void GvrDevice::ResetPose() { | 190 void GvrDevice::ResetPose(VRServiceImpl* service) { |
| 191 if (CheckAccessAllowed(service)) | |
| 192 return; | |
| 193 | |
| 190 gvr::GvrApi* gvr_api = GetGvrApi(); | 194 gvr::GvrApi* gvr_api = GetGvrApi(); |
| 191 if (gvr_api) | 195 if (gvr_api) |
| 192 gvr_api->ResetTracking(); | 196 gvr_api->ResetTracking(); |
| 193 } | 197 } |
| 194 | 198 |
| 195 bool GvrDevice::RequestPresent(bool secure_origin) { | 199 bool GvrDevice::RequestPresent(VRServiceImpl* service, bool secure_origin) { |
| 200 if (presenting_service_ != nullptr) | |
| 201 if (presenting_service_ != service) | |
| 202 return false; | |
|
bajones
2016/10/25 22:21:37
Any reason why CheckAccessAllowed isn't used here?
| |
| 203 | |
| 204 // One service could present on several devices at the same time | |
| 205 // and different service could present on different devices the same time | |
| 206 if (presenting_service_ == nullptr) | |
| 207 presenting_service_ = service; | |
| 208 | |
| 196 secure_origin_ = secure_origin; | 209 secure_origin_ = secure_origin; |
| 197 if (delegate_) | 210 if (delegate_) |
| 198 delegate_->SetWebVRSecureOrigin(secure_origin_); | 211 delegate_->SetWebVRSecureOrigin(secure_origin_); |
| 199 return gvr_provider_->RequestPresent(); | 212 |
| 213 if (!gvr_provider_->RequestPresent()) { | |
|
bajones
2016/10/25 22:21:37
This change is unnecessary.
| |
| 214 return false; | |
| 215 } | |
| 216 return true; | |
| 200 } | 217 } |
| 201 | 218 |
| 202 void GvrDevice::ExitPresent() { | 219 void GvrDevice::ExitPresent(VRServiceImpl* service) { |
| 220 if (IsPresentingService(service)) | |
| 221 presenting_service_ = nullptr; | |
| 222 | |
| 203 gvr_provider_->ExitPresent(); | 223 gvr_provider_->ExitPresent(); |
| 224 OnExitPresent(service); | |
| 204 } | 225 } |
| 205 | 226 |
| 206 void GvrDevice::SubmitFrame(VRPosePtr pose) { | 227 void GvrDevice::SubmitFrame(VRServiceImpl* service, mojom::VRPosePtr pose) { |
| 207 if (delegate_) | 228 if (IsPresentingService(service)) { |
| 208 delegate_->SubmitWebVRFrame(); | 229 if (delegate_) |
| 230 delegate_->SubmitWebVRFrame(); | |
| 231 } | |
| 209 } | 232 } |
| 210 | 233 |
| 211 void GvrDevice::UpdateLayerBounds(VRLayerBoundsPtr leftBounds, | 234 void GvrDevice::UpdateLayerBounds(VRServiceImpl* service, |
| 212 VRLayerBoundsPtr rightBounds) { | 235 mojom::VRLayerBoundsPtr leftBounds, |
| 213 if (!delegate_) | 236 mojom::VRLayerBoundsPtr rightBounds) { |
| 214 return; | 237 if (CheckAccessAllowed(service)) { |
| 238 if (!delegate_) | |
| 239 return; | |
| 215 | 240 |
| 216 delegate_->UpdateWebVRTextureBounds(0, // Left eye | 241 delegate_->UpdateWebVRTextureBounds(0, // Left eye |
| 217 leftBounds->left, leftBounds->top, | 242 leftBounds->left, leftBounds->top, |
| 218 leftBounds->width, leftBounds->height); | 243 leftBounds->width, leftBounds->height); |
| 219 delegate_->UpdateWebVRTextureBounds(1, // Right eye | 244 delegate_->UpdateWebVRTextureBounds(1, // Right eye |
| 220 rightBounds->left, rightBounds->top, | 245 rightBounds->left, rightBounds->top, |
| 221 rightBounds->width, rightBounds->height); | 246 rightBounds->width, |
| 247 rightBounds->height); | |
| 248 } | |
| 222 } | 249 } |
| 223 | 250 |
| 224 void GvrDevice::SetDelegate(GvrDelegate* delegate) { | 251 void GvrDevice::SetDelegate(GvrDelegate* delegate) { |
| 225 delegate_ = delegate; | 252 delegate_ = delegate; |
| 226 | 253 |
| 227 // Notify the clients that this device has changed | 254 // Notify the clients that this device has changed |
| 228 if (delegate_) { | 255 if (delegate_) { |
| 229 delegate_->SetWebVRSecureOrigin(secure_origin_); | 256 delegate_->SetWebVRSecureOrigin(secure_origin_); |
| 230 VRDeviceManager::GetInstance()->OnDeviceChanged(GetVRDevice()); | 257 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.
| |
| 231 } | 258 } |
| 232 } | 259 } |
| 233 | 260 |
| 234 gvr::GvrApi* GvrDevice::GetGvrApi() { | 261 gvr::GvrApi* GvrDevice::GetGvrApi() { |
| 235 if (!delegate_) | 262 if (!delegate_) |
| 236 return nullptr; | 263 return nullptr; |
| 237 | 264 |
| 238 return delegate_->gvr_api(); | 265 return delegate_->gvr_api(); |
| 239 } | 266 } |
| 240 | 267 |
| 268 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
| |
| 269 mojom::VRDisplayPtr vr_device_info = GetVRDevice(); | |
| 270 if (vr_device_info.is_null()) | |
| 271 return; | |
| 272 | |
| 273 for (const auto& client : display_clients_) | |
| 274 client.second->OnDisplayChanged(vr_device_info.Clone()); | |
| 275 } | |
| 276 | |
| 277 void GvrDevice::OnExitPresent(VRServiceImpl* service) { | |
| 278 DisplayClientMap::iterator it = display_clients_.find(service); | |
| 279 if (it != display_clients_.end()) | |
| 280 it->second->OnExitPresent(); | |
| 281 } | |
| 282 | |
| 283 void GvrDevice::OnDisplayConnected() { | |
| 284 mojom::VRDisplayPtr vr_device_info = GetVRDevice(); | |
| 285 if (vr_device_info.is_null()) | |
| 286 return; | |
| 287 | |
| 288 for (const auto& client : display_clients_) | |
| 289 client.second->OnDisplayConnected(vr_device_info.Clone()); | |
| 290 } | |
| 291 | |
| 292 void GvrDevice::OnDisplayDisconnected() { | |
| 293 for (const auto& client : display_clients_) | |
| 294 client.second->OnDisplayDisconnected(); | |
| 295 } | |
| 296 | |
| 241 } // namespace device | 297 } // namespace device |
| OLD | NEW |