| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 right_eye->offset[2] = -right_eye_mat.m[2][3]; | 143 right_eye->offset[2] = -right_eye_mat.m[2][3]; |
| 144 | 144 |
| 145 if (delegate_) { | 145 if (delegate_) { |
| 146 delegate_->SetWebVRRenderSurfaceSize(2 * left_eye->renderWidth, | 146 delegate_->SetWebVRRenderSurfaceSize(2 * left_eye->renderWidth, |
| 147 left_eye->renderHeight); | 147 left_eye->renderHeight); |
| 148 } | 148 } |
| 149 | 149 |
| 150 return device; | 150 return device; |
| 151 } | 151 } |
| 152 | 152 |
| 153 mojom::VRPosePtr GvrDevice::GetPose() { | |
| 154 TRACE_EVENT0("input", "GvrDevice::GetSensorState"); | |
| 155 | |
| 156 mojom::VRPosePtr pose = mojom::VRPose::New(); | |
| 157 | |
| 158 pose->timestamp = base::Time::Now().ToJsTime(); | |
| 159 | |
| 160 // Increment pose frame counter always, even if it's a faked pose. | |
| 161 pose->poseIndex = ++pose_index_; | |
| 162 | |
| 163 pose->orientation.emplace(4); | |
| 164 | |
| 165 gvr::GvrApi* gvr_api = GetGvrApi(); | |
| 166 if (!gvr_api) { | |
| 167 // If we don't have a GvrApi instance return a static forward orientation. | |
| 168 pose->orientation.value()[0] = 0.0; | |
| 169 pose->orientation.value()[1] = 0.0; | |
| 170 pose->orientation.value()[2] = 0.0; | |
| 171 pose->orientation.value()[3] = 1.0; | |
| 172 | |
| 173 return pose; | |
| 174 } | |
| 175 | |
| 176 if (!delegate_) | |
| 177 return nullptr; | |
| 178 | |
| 179 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); | |
| 180 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; | |
| 181 | |
| 182 gvr::Mat4f head_mat = | |
| 183 gvr_api->GetHeadSpaceFromStartSpaceRotation(target_time); | |
| 184 head_mat = gvr_api->ApplyNeckModel(head_mat, 1.0f); | |
| 185 | |
| 186 gfx::Transform inv_transform( | |
| 187 head_mat.m[0][0], head_mat.m[0][1], head_mat.m[0][2], head_mat.m[0][3], | |
| 188 head_mat.m[1][0], head_mat.m[1][1], head_mat.m[1][2], head_mat.m[1][3], | |
| 189 head_mat.m[2][0], head_mat.m[2][1], head_mat.m[2][2], head_mat.m[2][3], | |
| 190 head_mat.m[3][0], head_mat.m[3][1], head_mat.m[3][2], head_mat.m[3][3]); | |
| 191 | |
| 192 gfx::Transform transform; | |
| 193 if (inv_transform.GetInverse(&transform)) { | |
| 194 gfx::DecomposedTransform decomposed_transform; | |
| 195 gfx::DecomposeTransform(&decomposed_transform, transform); | |
| 196 | |
| 197 pose->orientation.value()[0] = decomposed_transform.quaternion[0]; | |
| 198 pose->orientation.value()[1] = decomposed_transform.quaternion[1]; | |
| 199 pose->orientation.value()[2] = decomposed_transform.quaternion[2]; | |
| 200 pose->orientation.value()[3] = decomposed_transform.quaternion[3]; | |
| 201 | |
| 202 pose->position.emplace(3); | |
| 203 pose->position.value()[0] = decomposed_transform.translate[0]; | |
| 204 pose->position.value()[1] = decomposed_transform.translate[1]; | |
| 205 pose->position.value()[2] = decomposed_transform.translate[2]; | |
| 206 } | |
| 207 | |
| 208 // Save the underlying GVR pose for use by rendering. It can't use a | |
| 209 // VRPosePtr since that's a different data type. | |
| 210 delegate_->SetGvrPoseForWebVr(head_mat, pose_index_); | |
| 211 | |
| 212 return pose; | |
| 213 } | |
| 214 | |
| 215 void GvrDevice::ResetPose() { | 153 void GvrDevice::ResetPose() { |
| 216 gvr::GvrApi* gvr_api = GetGvrApi(); | 154 gvr::GvrApi* gvr_api = GetGvrApi(); |
| 217 | 155 |
| 218 // Should never call RecenterTracking when using with Daydream viewers. On | 156 // Should never call RecenterTracking when using with Daydream viewers. On |
| 219 // those devices recentering should only be done via the controller. | 157 // those devices recentering should only be done via the controller. |
| 220 if (gvr_api && gvr_api->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD) | 158 if (gvr_api && gvr_api->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD) |
| 221 gvr_api->RecenterTracking(); | 159 gvr_api->RecenterTracking(); |
| 222 } | 160 } |
| 223 | 161 |
| 224 void GvrDevice::RequestPresent(const base::Callback<void(bool)>& callback) { | 162 void GvrDevice::RequestPresent(const base::Callback<void(bool)>& callback) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 254 | 192 |
| 255 gvr::Rectf right_gvr_bounds; | 193 gvr::Rectf right_gvr_bounds; |
| 256 right_gvr_bounds.left = right_bounds->left; | 194 right_gvr_bounds.left = right_bounds->left; |
| 257 right_gvr_bounds.top = 1.0f - right_bounds->top; | 195 right_gvr_bounds.top = 1.0f - right_bounds->top; |
| 258 right_gvr_bounds.right = right_bounds->left + right_bounds->width; | 196 right_gvr_bounds.right = right_bounds->left + right_bounds->width; |
| 259 right_gvr_bounds.bottom = 1.0f - (right_bounds->top + right_bounds->height); | 197 right_gvr_bounds.bottom = 1.0f - (right_bounds->top + right_bounds->height); |
| 260 | 198 |
| 261 delegate_->UpdateWebVRTextureBounds(left_gvr_bounds, right_gvr_bounds); | 199 delegate_->UpdateWebVRTextureBounds(left_gvr_bounds, right_gvr_bounds); |
| 262 } | 200 } |
| 263 | 201 |
| 202 void GvrDevice::GetVRVSyncProvider(mojom::VRVSyncProviderRequest request) { |
| 203 if (delegate_) |
| 204 delegate_->OnVRVsyncProviderRequest(std::move(request)); |
| 205 } |
| 206 |
| 264 void GvrDevice::SetDelegate(GvrDelegate* delegate) { | 207 void GvrDevice::SetDelegate(GvrDelegate* delegate) { |
| 265 delegate_ = delegate; | 208 delegate_ = delegate; |
| 266 | 209 |
| 267 // Notify the clients that this device has changed | 210 // Notify the clients that this device has changed |
| 268 if (delegate_) { | 211 if (delegate_) { |
| 269 delegate_->SetWebVRSecureOrigin(secure_origin_); | 212 delegate_->SetWebVRSecureOrigin(secure_origin_); |
| 270 OnChanged(); | 213 OnChanged(); |
| 271 } | 214 } |
| 272 } | 215 } |
| 273 | 216 |
| 274 gvr::GvrApi* GvrDevice::GetGvrApi() { | 217 gvr::GvrApi* GvrDevice::GetGvrApi() { |
| 275 if (!delegate_) | 218 if (!delegate_) |
| 276 return nullptr; | 219 return nullptr; |
| 277 | 220 |
| 278 return delegate_->gvr_api(); | 221 return delegate_->gvr_api(); |
| 279 } | 222 } |
| 280 | 223 |
| 281 } // namespace device | 224 } // namespace device |
| OLD | NEW |