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

Side by Side Diff: device/vr/openvr/openvr_device.cc

Issue 2822983002: Implement displayName and stageParameters of VRDisplay for OpenVRDevice (Closed)
Patch Set: 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2017 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 #define _USE_MATH_DEFINES // for M_PI 5 #define _USE_MATH_DEFINES // for M_PI
6 #include "device/vr/openvr/openvr_device.h" 6 #include "device/vr/openvr/openvr_device.h"
7 #include <math.h> 7 #include <math.h>
8 #include "third_party/openvr/src/headers/openvr.h" 8 #include "third_party/openvr/src/headers/openvr.h"
9 9
10 namespace { 10 namespace {
11 11
12 constexpr float kRadToDeg = static_cast<float>(180 / M_PI); 12 constexpr float kRadToDeg = static_cast<float>(180 / M_PI);
13 constexpr float kDefaultIPD = 0.06f; // Default average IPD 13 constexpr float kDefaultIPD = 0.06f; // Default average IPD
14 14
15 device::mojom::VRFieldOfViewPtr openVRFovToWebVRFov(vr::IVRSystem* vr_system, 15 device::mojom::VRFieldOfViewPtr openVRFovToWebVRFov(vr::IVRSystem* vr_system,
16 vr::Hmd_Eye eye) { 16 vr::Hmd_Eye eye) {
17 device::mojom::VRFieldOfViewPtr out = device::mojom::VRFieldOfView::New(); 17 device::mojom::VRFieldOfViewPtr out = device::mojom::VRFieldOfView::New();
18 float up_tan, down_tan, left_tan, right_tan; 18 float up_tan, down_tan, left_tan, right_tan;
19 vr_system->GetProjectionRaw(eye, &left_tan, &right_tan, &up_tan, &down_tan); 19 vr_system->GetProjectionRaw(eye, &left_tan, &right_tan, &up_tan, &down_tan);
20 out->upDegrees = -(atanf(up_tan) * kRadToDeg); 20 out->upDegrees = -(atanf(up_tan) * kRadToDeg);
21 out->downDegrees = atanf(down_tan) * kRadToDeg; 21 out->downDegrees = atanf(down_tan) * kRadToDeg;
22 out->leftDegrees = -(atanf(left_tan) * kRadToDeg); 22 out->leftDegrees = -(atanf(left_tan) * kRadToDeg);
23 out->rightDegrees = atanf(right_tan) * kRadToDeg; 23 out->rightDegrees = atanf(right_tan) * kRadToDeg;
24 return out; 24 return out;
25 } 25 }
26 26
27 std::string getOpenVRString(vr::IVRSystem* vr_system,
28 vr::TrackedDeviceProperty prop) {
29 std::string out;
30
31 vr::TrackedPropertyError error = vr::TrackedProp_Success;
32 char openvr_string[vr::k_unMaxPropertyStringSize];
33 vr_system->GetStringTrackedDeviceProperty(
34 vr::k_unTrackedDeviceIndex_Hmd, prop, openvr_string,
35 vr::k_unMaxPropertyStringSize, &error);
36
37 if (error == vr::TrackedProp_Success)
38 out = openvr_string;
39
40 return out;
41 }
42
27 } // namespace 43 } // namespace
28 44
29 namespace device { 45 namespace device {
30 46
31 OpenVRDevice::OpenVRDevice() {} 47 OpenVRDevice::OpenVRDevice() {}
32 OpenVRDevice::~OpenVRDevice() {} 48 OpenVRDevice::~OpenVRDevice() {}
33 49
34 void OpenVRDevice::CreateVRDisplayInfo( 50 void OpenVRDevice::CreateVRDisplayInfo(
35 const base::Callback<void(mojom::VRDisplayInfoPtr)>& on_created) { 51 const base::Callback<void(mojom::VRDisplayInfoPtr)>& on_created) {
36 vr::EVRInitError init_error; 52 vr::EVRInitError init_error;
37 auto vr_system = 53 auto vr_system =
38 vr::VR_Init(&init_error, vr::EVRApplicationType::VRApplication_Scene); 54 vr::VR_Init(&init_error, vr::EVRApplicationType::VRApplication_Scene);
39 55
40 if (init_error != vr::VRInitError_None) { 56 if (init_error != vr::VRInitError_None) {
41 LOG(ERROR) << vr::VR_GetVRInitErrorAsEnglishDescription(init_error); 57 LOG(ERROR) << vr::VR_GetVRInitErrorAsEnglishDescription(init_error);
42 on_created.Run(nullptr); 58 on_created.Run(nullptr);
43 return; 59 return;
44 } 60 }
45 61
46 mojom::VRDisplayInfoPtr device = mojom::VRDisplayInfo::New(); 62 mojom::VRDisplayInfoPtr device = mojom::VRDisplayInfo::New();
47 device->index = id(); 63 device->index = id();
64 device->displayName =
65 getOpenVRString(vr_system, vr::Prop_ManufacturerName_String) + " " +
66 getOpenVRString(vr_system, vr::Prop_ModelNumber_String);
48 device->capabilities = mojom::VRDisplayCapabilities::New(); 67 device->capabilities = mojom::VRDisplayCapabilities::New();
49 device->capabilities->hasPosition = true; 68 device->capabilities->hasPosition = true;
50 device->capabilities->hasExternalDisplay = true; 69 device->capabilities->hasExternalDisplay = true;
51 device->capabilities->canPresent = false; 70 device->capabilities->canPresent = false;
52 71
53 device->leftEye = mojom::VREyeParameters::New(); 72 device->leftEye = mojom::VREyeParameters::New();
54 device->rightEye = mojom::VREyeParameters::New(); 73 device->rightEye = mojom::VREyeParameters::New();
55 mojom::VREyeParametersPtr& left_eye = device->leftEye; 74 mojom::VREyeParametersPtr& left_eye = device->leftEye;
56 mojom::VREyeParametersPtr& right_eye = device->rightEye; 75 mojom::VREyeParametersPtr& right_eye = device->rightEye;
57 76
(...skipping 16 matching lines...) Expand all
74 right_eye->offset[1] = 0.0; 93 right_eye->offset[1] = 0.0;
75 right_eye->offset[2] = 0.0; 94 right_eye->offset[2] = 0.0;
76 95
77 uint32_t width, height; 96 uint32_t width, height;
78 vr_system->GetRecommendedRenderTargetSize(&width, &height); 97 vr_system->GetRecommendedRenderTargetSize(&width, &height);
79 left_eye->renderWidth = width; 98 left_eye->renderWidth = width;
80 left_eye->renderHeight = height; 99 left_eye->renderHeight = height;
81 right_eye->renderWidth = left_eye->renderWidth; 100 right_eye->renderWidth = left_eye->renderWidth;
82 right_eye->renderHeight = left_eye->renderHeight; 101 right_eye->renderHeight = left_eye->renderHeight;
83 102
103 device->stageParameters = mojom::VRStageParameters::New();
104 vr::HmdMatrix34_t mat =
105 vr_system->GetSeatedZeroPoseToStandingAbsoluteTrackingPose();
106 device->stageParameters->standingTransform.resize(16);
107 std::vector<float>& transform = device->stageParameters->standingTransform;
108 transform[0] = mat.m[0][0];
109 transform[1] = mat.m[1][0];
110 transform[2] = mat.m[2][0];
111 transform[3] = 0.0f;
112 transform[4] = mat.m[0][1];
113 transform[5] = mat.m[1][1];
114 transform[6] = mat.m[2][1];
115 transform[7] = 0.0f;
116 transform[8] = mat.m[0][2];
117 transform[9] = mat.m[1][2];
118 transform[10] = mat.m[2][2];
119 transform[11] = 0.0f;
120 transform[12] = mat.m[0][3];
121 transform[13] = mat.m[1][3];
122 transform[14] = mat.m[2][3];
123 transform[15] = 1.0f;
billorr 2017/04/17 17:56:08 converting transforms from openvr to mojo/webvr fo
124
125 vr::IVRChaperone* chaperone = vr::VRChaperone();
126 if (chaperone) {
127 chaperone->GetPlayAreaSize(&device->stageParameters->sizeX,
128 &device->stageParameters->sizeZ);
129 } else {
130 device->stageParameters->sizeX = 0.0f;
131 device->stageParameters->sizeZ = 0.0f;
132 }
133
84 render_loop_ = std::make_unique<OpenVRRenderLoop>(vr_system); 134 render_loop_ = std::make_unique<OpenVRRenderLoop>(vr_system);
85 135
86 on_created.Run(std::move(device)); 136 on_created.Run(std::move(device));
87 } 137 }
88 138
89 void OpenVRDevice::RequestPresent(mojom::VRSubmitFrameClientPtr submit_client, 139 void OpenVRDevice::RequestPresent(mojom::VRSubmitFrameClientPtr submit_client,
90 const base::Callback<void(bool)>& callback) { 140 const base::Callback<void(bool)>& callback) {
91 callback.Run(false); 141 callback.Run(false);
92 // We don't support presentation currently. 142 // We don't support presentation currently.
93 } 143 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 base::TimeDelta time = base::TimeDelta::FromSecondsD(2.0); 230 base::TimeDelta time = base::TimeDelta::FromSecondsD(2.0);
181 231
182 device::mojom::VRPosePtr pose = getPose(); 232 device::mojom::VRPosePtr pose = getPose();
183 Sleep(11); // TODO (billorr): Use real vsync timing instead of a sleep (this 233 Sleep(11); // TODO (billorr): Use real vsync timing instead of a sleep (this
184 // sleep just throttles vsyncs so we don't fill message queues). 234 // sleep just throttles vsyncs so we don't fill message queues).
185 callback.Run(std::move(pose), time, frame, 235 callback.Run(std::move(pose), time, frame,
186 device::mojom::VRVSyncProvider::Status::SUCCESS); 236 device::mojom::VRVSyncProvider::Status::SUCCESS);
187 } 237 }
188 238
189 } // namespace device 239 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698