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 "chrome/browser/android/vr_shell/vr_shell_gl.h" | 5 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 #include "ui/gl/gl_surface.h" | 32 #include "ui/gl/gl_surface.h" |
| 33 #include "ui/gl/init/gl_factory.h" | 33 #include "ui/gl/init/gl_factory.h" |
| 34 | 34 |
| 35 namespace vr_shell { | 35 namespace vr_shell { |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 // TODO(mthiesse): If gvr::PlatformInfo().GetPosePredictionTime() is ever | 38 // TODO(mthiesse): If gvr::PlatformInfo().GetPosePredictionTime() is ever |
| 39 // exposed, use that instead (it defaults to 50ms on most platforms). | 39 // exposed, use that instead (it defaults to 50ms on most platforms). |
| 40 static constexpr int64_t kPredictionTimeWithoutVsyncNanos = 50000000; | 40 static constexpr int64_t kPredictionTimeWithoutVsyncNanos = 50000000; |
| 41 | 41 |
| 42 // Time offset used for calculating angular velocity from a pair | |
|
cjgrant
2017/03/24 21:15:40
nit: Most editors can be used to auto-format comme
klausw
2017/03/24 22:13:29
I was using auto format, but Emacs for some reason
| |
| 43 // of predicted poses. The precise value shouldn't matter as long as | |
| 44 // it's nonzero and much less than a frame. | |
| 45 static constexpr int64_t kAngularVelocityEpsilonNanos = 1000000; | |
| 46 | |
| 42 static constexpr float kZNear = 0.1f; | 47 static constexpr float kZNear = 0.1f; |
| 43 static constexpr float kZFar = 1000.0f; | 48 static constexpr float kZFar = 1000.0f; |
| 44 | 49 |
| 45 static constexpr float kReticleWidth = 0.025f; | 50 static constexpr float kReticleWidth = 0.025f; |
| 46 static constexpr float kReticleHeight = 0.025f; | 51 static constexpr float kReticleHeight = 0.025f; |
| 47 | 52 |
| 48 static constexpr float kLaserWidth = 0.01f; | 53 static constexpr float kLaserWidth = 0.01f; |
| 49 | 54 |
| 50 // Angle (radians) the beam down from the controller axis, for wrist comfort. | 55 // Angle (radians) the beam down from the controller axis, for wrist comfort. |
| 51 static constexpr float kErgoAngleOffset = 0.26f; | 56 static constexpr float kErgoAngleOffset = 0.26f; |
| (...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1263 | 1268 |
| 1264 TRACE_EVENT1("input", "VrShellGl::SendVSync", "frame", frame_index); | 1269 TRACE_EVENT1("input", "VrShellGl::SendVSync", "frame", frame_index); |
| 1265 | 1270 |
| 1266 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); | 1271 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); |
| 1267 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; | 1272 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; |
| 1268 | 1273 |
| 1269 gvr::Mat4f head_mat = | 1274 gvr::Mat4f head_mat = |
| 1270 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); | 1275 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); |
| 1271 head_mat = gvr_api_->ApplyNeckModel(head_mat, 1.0f); | 1276 head_mat = gvr_api_->ApplyNeckModel(head_mat, 1.0f); |
| 1272 | 1277 |
| 1278 target_time.monotonic_system_time_nanos += kAngularVelocityEpsilonNanos; | |
| 1279 gvr::Mat4f head_mat_2 = | |
| 1280 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); | |
| 1281 | |
| 1273 webvr_head_pose_[frame_index % kPoseRingBufferSize] = head_mat; | 1282 webvr_head_pose_[frame_index % kPoseRingBufferSize] = head_mat; |
| 1274 | 1283 |
| 1275 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, frame_index, | 1284 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat, head_mat_2, |
| 1285 kAngularVelocityEpsilonNanos), | |
| 1286 time, frame_index, | |
| 1276 device::mojom::VRVSyncProvider::Status::SUCCESS); | 1287 device::mojom::VRVSyncProvider::Status::SUCCESS); |
| 1277 } | 1288 } |
| 1278 | 1289 |
| 1279 void VrShellGl::ResetPose() { | 1290 void VrShellGl::ResetPose() { |
| 1280 // Should never call RecenterTracking when using with Daydream viewers. On | 1291 // Should never call RecenterTracking when using with Daydream viewers. On |
| 1281 // those devices recentering should only be done via the controller. | 1292 // those devices recentering should only be done via the controller. |
| 1282 if (gvr_api_ && gvr_api_->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD) | 1293 if (gvr_api_ && gvr_api_->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD) |
| 1283 gvr_api_->RecenterTracking(); | 1294 gvr_api_->RecenterTracking(); |
| 1284 } | 1295 } |
| 1285 | 1296 |
| 1286 void VrShellGl::CreateVRDisplayInfo( | 1297 void VrShellGl::CreateVRDisplayInfo( |
| 1287 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, | 1298 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, |
| 1288 uint32_t device_id) { | 1299 uint32_t device_id) { |
| 1289 // This assumes that the initial webvr_surface_size_ was set to the | 1300 // This assumes that the initial webvr_surface_size_ was set to the |
| 1290 // appropriate recommended render resolution as the default size during | 1301 // appropriate recommended render resolution as the default size during |
| 1291 // InitializeGl. Revisit if the initialization order changes. | 1302 // InitializeGl. Revisit if the initialization order changes. |
| 1292 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( | 1303 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( |
| 1293 gvr_api_.get(), webvr_surface_size_, device_id); | 1304 gvr_api_.get(), webvr_surface_size_, device_id); |
| 1294 main_thread_task_runner_->PostTask( | 1305 main_thread_task_runner_->PostTask( |
| 1295 FROM_HERE, | 1306 FROM_HERE, |
| 1296 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); | 1307 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); |
| 1297 } | 1308 } |
| 1298 | 1309 |
| 1299 } // namespace vr_shell | 1310 } // namespace vr_shell |
| OLD | NEW |