Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(651)

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell_gl.cc

Issue 2770353002: WebVR: add angular velocity estimate to pose (Closed)
Patch Set: Move angular velocity calculation to helper function Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/android/vr_shell/vr_controller.cc ('k') | device/vr/android/gvr/gvr_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <chrono> 7 #include <chrono>
8 #include <limits> 8 #include <limits>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 19 matching lines...) Expand all
30 #include "ui/gl/android/scoped_java_surface.h" 30 #include "ui/gl/android/scoped_java_surface.h"
31 #include "ui/gl/android/surface_texture.h" 31 #include "ui/gl/android/surface_texture.h"
32 #include "ui/gl/gl_bindings.h" 32 #include "ui/gl/gl_bindings.h"
33 #include "ui/gl/gl_context.h" 33 #include "ui/gl/gl_context.h"
34 #include "ui/gl/gl_surface.h" 34 #include "ui/gl/gl_surface.h"
35 #include "ui/gl/init/gl_factory.h" 35 #include "ui/gl/init/gl_factory.h"
36 36
37 namespace vr_shell { 37 namespace vr_shell {
38 38
39 namespace { 39 namespace {
40 // TODO(mthiesse): If gvr::PlatformInfo().GetPosePredictionTime() is ever
41 // exposed, use that instead (it defaults to 50ms on most platforms).
42 static constexpr int64_t kPredictionTimeWithoutVsyncNanos = 50000000;
43
44 static constexpr float kZNear = 0.1f; 40 static constexpr float kZNear = 0.1f;
45 static constexpr float kZFar = 1000.0f; 41 static constexpr float kZFar = 1000.0f;
46 42
47 static constexpr float kReticleWidth = 0.025f; 43 static constexpr float kReticleWidth = 0.025f;
48 static constexpr float kReticleHeight = 0.025f; 44 static constexpr float kReticleHeight = 0.025f;
49 45
50 static constexpr float kLaserWidth = 0.01f; 46 static constexpr float kLaserWidth = 0.01f;
51 47
52 // Angle (radians) the beam down from the controller axis, for wrist comfort. 48 // Angle (radians) the beam down from the controller axis, for wrist comfort.
53 static constexpr float kErgoAngleOffset = 0.26f; 49 static constexpr float kErgoAngleOffset = 0.26f;
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 // When using async reprojection, we need to know which pose was 797 // When using async reprojection, we need to know which pose was
802 // used in the WebVR app for drawing this frame and supply it when 798 // used in the WebVR app for drawing this frame and supply it when
803 // submitting. Technically we don't need a pose if not reprojecting, 799 // submitting. Technically we don't need a pose if not reprojecting,
804 // but keeping it uninitialized seems likely to cause problems down 800 // but keeping it uninitialized seems likely to cause problems down
805 // the road. Copying it is cheaper than fetching a new one. 801 // the road. Copying it is cheaper than fetching a new one.
806 if (ShouldDrawWebVr()) { 802 if (ShouldDrawWebVr()) {
807 static_assert(!((kPoseRingBufferSize - 1) & kPoseRingBufferSize), 803 static_assert(!((kPoseRingBufferSize - 1) & kPoseRingBufferSize),
808 "kPoseRingBufferSize must be a power of 2"); 804 "kPoseRingBufferSize must be a power of 2");
809 head_pose = webvr_head_pose_[frame_index % kPoseRingBufferSize]; 805 head_pose = webvr_head_pose_[frame_index % kPoseRingBufferSize];
810 } else { 806 } else {
811 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); 807 head_pose = device::GvrDelegate::GetGvrPoseWithNeckModel(gvr_api_.get());
812 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos;
813 head_pose = gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time);
814 }
815
816 gvr::Vec3f position = GetTranslation(head_pose);
817 if (position.x == 0.0f && position.y == 0.0f && position.z == 0.0f) {
818 // This appears to be a 3DOF pose without a neck model. Add one.
819 // The head pose has redundant data. Assume we're only using the
820 // object_from_reference_matrix, we're not updating position_external.
821 // TODO: Not sure what object_from_reference_matrix is. The new api removed
822 // it. For now, removing it seems working fine.
823 gvr_api_->ApplyNeckModel(head_pose, 1.0f);
824 } 808 }
825 809
826 // Update the render position of all UI elements (including desktop). 810 // Update the render position of all UI elements (including desktop).
827 scene_->UpdateTransforms(TimeInMicroseconds()); 811 scene_->UpdateTransforms(TimeInMicroseconds());
828 812
829 { 813 {
830 // TODO(crbug.com/704690): Acquire controller state in a way that's timely 814 // TODO(crbug.com/704690): Acquire controller state in a way that's timely
831 // for both the gamepad API and UI input handling. 815 // for both the gamepad API and UI input handling.
832 TRACE_EVENT0("gpu", "VrShellGl::UpdateController"); 816 TRACE_EVENT0("gpu", "VrShellGl::UpdateController");
833 UpdateController(); 817 UpdateController();
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 void VrShellGl::UpdateScene(std::unique_ptr<base::ListValue> commands) { 1255 void VrShellGl::UpdateScene(std::unique_ptr<base::ListValue> commands) {
1272 scene_->HandleCommands(std::move(commands), TimeInMicroseconds()); 1256 scene_->HandleCommands(std::move(commands), TimeInMicroseconds());
1273 } 1257 }
1274 1258
1275 void VrShellGl::SendVSync(base::TimeDelta time, 1259 void VrShellGl::SendVSync(base::TimeDelta time,
1276 const GetVSyncCallback& callback) { 1260 const GetVSyncCallback& callback) {
1277 uint8_t frame_index = frame_index_++; 1261 uint8_t frame_index = frame_index_++;
1278 1262
1279 TRACE_EVENT1("input", "VrShellGl::SendVSync", "frame", frame_index); 1263 TRACE_EVENT1("input", "VrShellGl::SendVSync", "frame", frame_index);
1280 1264
1281 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); 1265 gvr::Mat4f head_mat;
1282 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; 1266 device::mojom::VRPosePtr pose =
1283 1267 device::GvrDelegate::GetVRPosePtrWithNeckModel(gvr_api_.get(), &head_mat);
1284 gvr::Mat4f head_mat =
1285 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time);
1286 head_mat = gvr_api_->ApplyNeckModel(head_mat, 1.0f);
1287 1268
1288 webvr_head_pose_[frame_index % kPoseRingBufferSize] = head_mat; 1269 webvr_head_pose_[frame_index % kPoseRingBufferSize] = head_mat;
1289 1270
1290 callback.Run(device::GvrDelegate::VRPosePtrFromGvrPose(head_mat), time, 1271 callback.Run(std::move(pose), time, frame_index,
1291 frame_index, device::mojom::VRVSyncProvider::Status::SUCCESS); 1272 device::mojom::VRVSyncProvider::Status::SUCCESS);
1292 } 1273 }
1293 1274
1294 void VrShellGl::CreateVRDisplayInfo( 1275 void VrShellGl::CreateVRDisplayInfo(
1295 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, 1276 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback,
1296 uint32_t device_id) { 1277 uint32_t device_id) {
1297 // This assumes that the initial webvr_surface_size_ was set to the 1278 // This assumes that the initial webvr_surface_size_ was set to the
1298 // appropriate recommended render resolution as the default size during 1279 // appropriate recommended render resolution as the default size during
1299 // InitializeGl. Revisit if the initialization order changes. 1280 // InitializeGl. Revisit if the initialization order changes.
1300 device::mojom::VRDisplayInfoPtr info = 1281 device::mojom::VRDisplayInfoPtr info =
1301 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), 1282 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(),
1302 webvr_surface_size_, device_id); 1283 webvr_surface_size_, device_id);
1303 main_thread_task_runner_->PostTask( 1284 main_thread_task_runner_->PostTask(
1304 FROM_HERE, 1285 FROM_HERE,
1305 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); 1286 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info)));
1306 } 1287 }
1307 1288
1308 } // namespace vr_shell 1289 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_controller.cc ('k') | device/vr/android/gvr/gvr_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698