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 17 matching lines...) Expand all Loading... | |
| 28 #include "ui/gl/android/scoped_java_surface.h" | 28 #include "ui/gl/android/scoped_java_surface.h" |
| 29 #include "ui/gl/android/surface_texture.h" | 29 #include "ui/gl/android/surface_texture.h" |
| 30 #include "ui/gl/gl_bindings.h" | 30 #include "ui/gl/gl_bindings.h" |
| 31 #include "ui/gl/gl_context.h" | 31 #include "ui/gl/gl_context.h" |
| 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 | |
| 39 // exposed, use that instead (it defaults to 50ms on most platforms). | |
| 40 static constexpr int64_t kPredictionTimeWithoutVsyncNanos = 50000000; | |
| 41 | |
| 42 static constexpr float kZNear = 0.1f; | 38 static constexpr float kZNear = 0.1f; |
| 43 static constexpr float kZFar = 1000.0f; | 39 static constexpr float kZFar = 1000.0f; |
| 44 | 40 |
| 45 static constexpr float kReticleWidth = 0.025f; | 41 static constexpr float kReticleWidth = 0.025f; |
| 46 static constexpr float kReticleHeight = 0.025f; | 42 static constexpr float kReticleHeight = 0.025f; |
| 47 | 43 |
| 48 static constexpr float kLaserWidth = 0.01f; | 44 static constexpr float kLaserWidth = 0.01f; |
| 49 | 45 |
| 50 // Angle (radians) the beam down from the controller axis, for wrist comfort. | 46 // Angle (radians) the beam down from the controller axis, for wrist comfort. |
| 51 static constexpr float kErgoAngleOffset = 0.26f; | 47 static constexpr float kErgoAngleOffset = 0.26f; |
| (...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 800 // used in the WebVR app for drawing this frame and supply it when | 796 // used in the WebVR app for drawing this frame and supply it when |
| 801 // submitting. Technically we don't need a pose if not reprojecting, | 797 // submitting. Technically we don't need a pose if not reprojecting, |
| 802 // but keeping it uninitialized seems likely to cause problems down | 798 // but keeping it uninitialized seems likely to cause problems down |
| 803 // the road. Copying it is cheaper than fetching a new one. | 799 // the road. Copying it is cheaper than fetching a new one. |
| 804 if (ShouldDrawWebVr()) { | 800 if (ShouldDrawWebVr()) { |
| 805 static_assert(!((kPoseRingBufferSize - 1) & kPoseRingBufferSize), | 801 static_assert(!((kPoseRingBufferSize - 1) & kPoseRingBufferSize), |
| 806 "kPoseRingBufferSize must be a power of 2"); | 802 "kPoseRingBufferSize must be a power of 2"); |
| 807 head_pose = webvr_head_pose_[frame_index % kPoseRingBufferSize]; | 803 head_pose = webvr_head_pose_[frame_index % kPoseRingBufferSize]; |
| 808 } else { | 804 } else { |
| 809 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); | 805 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); |
| 810 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; | 806 target_time.monotonic_system_time_nanos += |
| 807 VrShell::kPredictionTimeWithoutVsyncNanos; | |
| 811 head_pose = gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); | 808 head_pose = gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); |
| 812 } | 809 } |
| 813 | 810 |
| 814 gvr::Vec3f position = GetTranslation(head_pose); | 811 gvr::Vec3f position = GetTranslation(head_pose); |
| 815 if (position.x == 0.0f && position.y == 0.0f && position.z == 0.0f) { | 812 if (position.x == 0.0f && position.y == 0.0f && position.z == 0.0f) { |
| 816 // This appears to be a 3DOF pose without a neck model. Add one. | 813 // This appears to be a 3DOF pose without a neck model. Add one. |
| 817 // The head pose has redundant data. Assume we're only using the | 814 // The head pose has redundant data. Assume we're only using the |
| 818 // object_from_reference_matrix, we're not updating position_external. | 815 // object_from_reference_matrix, we're not updating position_external. |
| 819 // TODO: Not sure what object_from_reference_matrix is. The new api removed | 816 // TODO: Not sure what object_from_reference_matrix is. The new api removed |
| 820 // it. For now, removing it seems working fine. | 817 // it. For now, removing it seems working fine. |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1257 scene_->HandleCommands(std::move(commands), TimeInMicroseconds()); | 1254 scene_->HandleCommands(std::move(commands), TimeInMicroseconds()); |
| 1258 } | 1255 } |
| 1259 | 1256 |
| 1260 void VrShellGl::SendVSync(base::TimeDelta time, | 1257 void VrShellGl::SendVSync(base::TimeDelta time, |
| 1261 const GetVSyncCallback& callback) { | 1258 const GetVSyncCallback& callback) { |
| 1262 uint8_t frame_index = frame_index_++; | 1259 uint8_t frame_index = frame_index_++; |
| 1263 | 1260 |
| 1264 TRACE_EVENT1("input", "VrShellGl::SendVSync", "frame", frame_index); | 1261 TRACE_EVENT1("input", "VrShellGl::SendVSync", "frame", frame_index); |
| 1265 | 1262 |
| 1266 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); | 1263 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); |
| 1267 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; | 1264 target_time.monotonic_system_time_nanos += |
| 1265 VrShell::kPredictionTimeWithoutVsyncNanos; | |
|
mthiesse
2017/04/05 18:43:18
Instead of moving this constant to the header, and
mthiesse
2017/04/05 18:57:00
Actually, don't worry about this for your CL. I'll
klausw
2017/04/05 22:38:22
Done, now there's just one place that applies the
| |
| 1268 | 1266 |
| 1269 gvr::Mat4f head_mat = | 1267 gvr::Mat4f head_mat = |
| 1270 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); | 1268 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); |
| 1271 head_mat = gvr_api_->ApplyNeckModel(head_mat, 1.0f); | 1269 head_mat = gvr_api_->ApplyNeckModel(head_mat, 1.0f); |
| 1272 | 1270 |
| 1271 target_time.monotonic_system_time_nanos += | |
| 1272 VrShell::kAngularVelocityEpsilonNanos; | |
| 1273 gvr::Mat4f head_mat_2 = | |
| 1274 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); | |
| 1275 | |
| 1273 webvr_head_pose_[frame_index % kPoseRingBufferSize] = head_mat; | 1276 webvr_head_pose_[frame_index % kPoseRingBufferSize] = head_mat; |
| 1274 | 1277 |
| 1275 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, frame_index, | 1278 callback.Run(VrShell::VRPosePtrFromGvrPose( |
| 1279 head_mat, head_mat_2, VrShell::kAngularVelocityEpsilonNanos), | |
| 1280 time, frame_index, | |
| 1276 device::mojom::VRVSyncProvider::Status::SUCCESS); | 1281 device::mojom::VRVSyncProvider::Status::SUCCESS); |
| 1277 } | 1282 } |
| 1278 | 1283 |
| 1279 void VrShellGl::ResetPose() { | 1284 void VrShellGl::ResetPose() { |
| 1280 // Should never call RecenterTracking when using with Daydream viewers. On | 1285 // Should never call RecenterTracking when using with Daydream viewers. On |
| 1281 // those devices recentering should only be done via the controller. | 1286 // those devices recentering should only be done via the controller. |
| 1282 if (gvr_api_ && gvr_api_->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD) | 1287 if (gvr_api_ && gvr_api_->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD) |
| 1283 gvr_api_->RecenterTracking(); | 1288 gvr_api_->RecenterTracking(); |
| 1284 } | 1289 } |
| 1285 | 1290 |
| 1286 void VrShellGl::CreateVRDisplayInfo( | 1291 void VrShellGl::CreateVRDisplayInfo( |
| 1287 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, | 1292 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, |
| 1288 uint32_t device_id) { | 1293 uint32_t device_id) { |
| 1289 // This assumes that the initial webvr_surface_size_ was set to the | 1294 // This assumes that the initial webvr_surface_size_ was set to the |
| 1290 // appropriate recommended render resolution as the default size during | 1295 // appropriate recommended render resolution as the default size during |
| 1291 // InitializeGl. Revisit if the initialization order changes. | 1296 // InitializeGl. Revisit if the initialization order changes. |
| 1292 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( | 1297 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( |
| 1293 gvr_api_.get(), webvr_surface_size_, device_id); | 1298 gvr_api_.get(), webvr_surface_size_, device_id); |
| 1294 main_thread_task_runner_->PostTask( | 1299 main_thread_task_runner_->PostTask( |
| 1295 FROM_HERE, | 1300 FROM_HERE, |
| 1296 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); | 1301 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); |
| 1297 } | 1302 } |
| 1298 | 1303 |
| 1299 } // namespace vr_shell | 1304 } // namespace vr_shell |
| OLD | NEW |