OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/browser/vr/android/cardboard/cardboard_vr_device.h" | 5 #include "content/browser/vr/android/cardboard/cardboard_vr_device.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 | 9 |
10 #include "base/android/context_utils.h" | 10 #include "base/android/context_utils.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 j_cardboard_device_.Reset(Java_CardboardVRDevice_create( | 33 j_cardboard_device_.Reset(Java_CardboardVRDevice_create( |
34 env, base::android::GetApplicationContext())); | 34 env, base::android::GetApplicationContext())); |
35 j_head_matrix_.Reset(env, env->NewFloatArray(16)); | 35 j_head_matrix_.Reset(env, env->NewFloatArray(16)); |
36 } | 36 } |
37 | 37 |
38 CardboardVRDevice::~CardboardVRDevice() { | 38 CardboardVRDevice::~CardboardVRDevice() { |
39 Java_CardboardVRDevice_stopTracking(AttachCurrentThread(), | 39 Java_CardboardVRDevice_stopTracking(AttachCurrentThread(), |
40 j_cardboard_device_.obj()); | 40 j_cardboard_device_.obj()); |
41 } | 41 } |
42 | 42 |
43 mojom::VRDeviceInfoPtr CardboardVRDevice::GetVRDevice() { | 43 blink::mojom::VRDeviceInfoPtr CardboardVRDevice::GetVRDevice() { |
44 TRACE_EVENT0("input", "CardboardVRDevice::GetVRDevice"); | 44 TRACE_EVENT0("input", "CardboardVRDevice::GetVRDevice"); |
45 mojom::VRDeviceInfoPtr device = mojom::VRDeviceInfo::New(); | 45 blink::mojom::VRDeviceInfoPtr device = blink::mojom::VRDeviceInfo::New(); |
46 | 46 |
47 JNIEnv* env = AttachCurrentThread(); | 47 JNIEnv* env = AttachCurrentThread(); |
48 | 48 |
49 ScopedJavaLocalRef<jstring> j_device_name = | 49 ScopedJavaLocalRef<jstring> j_device_name = |
50 Java_CardboardVRDevice_getDeviceName(env, j_cardboard_device_.obj()); | 50 Java_CardboardVRDevice_getDeviceName(env, j_cardboard_device_.obj()); |
51 device->deviceName = | 51 device->deviceName = |
52 base::android::ConvertJavaStringToUTF8(env, j_device_name.obj()); | 52 base::android::ConvertJavaStringToUTF8(env, j_device_name.obj()); |
53 | 53 |
54 ScopedJavaLocalRef<jfloatArray> j_fov(env, env->NewFloatArray(4)); | 54 ScopedJavaLocalRef<jfloatArray> j_fov(env, env->NewFloatArray(4)); |
55 Java_CardboardVRDevice_getFieldOfView(env, j_cardboard_device_.obj(), | 55 Java_CardboardVRDevice_getFieldOfView(env, j_cardboard_device_.obj(), |
56 j_fov.obj()); | 56 j_fov.obj()); |
57 | 57 |
58 std::vector<float> fov; | 58 std::vector<float> fov; |
59 base::android::JavaFloatArrayToFloatVector(env, j_fov.obj(), &fov); | 59 base::android::JavaFloatArrayToFloatVector(env, j_fov.obj(), &fov); |
60 | 60 |
61 device->hmdInfo = mojom::VRHMDInfo::New(); | 61 device->hmdInfo = blink::mojom::VRHMDInfo::New(); |
62 mojom::VRHMDInfoPtr& hmdInfo = device->hmdInfo; | 62 blink::mojom::VRHMDInfoPtr& hmdInfo = device->hmdInfo; |
63 | 63 |
64 hmdInfo->leftEye = mojom::VREyeParameters::New(); | 64 hmdInfo->leftEye = blink::mojom::VREyeParameters::New(); |
65 hmdInfo->rightEye = mojom::VREyeParameters::New(); | 65 hmdInfo->rightEye = blink::mojom::VREyeParameters::New(); |
66 mojom::VREyeParametersPtr& left_eye = hmdInfo->leftEye; | 66 blink::mojom::VREyeParametersPtr& left_eye = hmdInfo->leftEye; |
67 mojom::VREyeParametersPtr& right_eye = hmdInfo->rightEye; | 67 blink::mojom::VREyeParametersPtr& right_eye = hmdInfo->rightEye; |
68 | 68 |
69 left_eye->recommendedFieldOfView = mojom::VRFieldOfView::New(); | 69 left_eye->recommendedFieldOfView = blink::mojom::VRFieldOfView::New(); |
70 left_eye->recommendedFieldOfView->upDegrees = fov[0]; | 70 left_eye->recommendedFieldOfView->upDegrees = fov[0]; |
71 left_eye->recommendedFieldOfView->downDegrees = fov[1]; | 71 left_eye->recommendedFieldOfView->downDegrees = fov[1]; |
72 left_eye->recommendedFieldOfView->leftDegrees = fov[2]; | 72 left_eye->recommendedFieldOfView->leftDegrees = fov[2]; |
73 left_eye->recommendedFieldOfView->rightDegrees = fov[3]; | 73 left_eye->recommendedFieldOfView->rightDegrees = fov[3]; |
74 | 74 |
75 // Cardboard devices always assume a mirrored FOV, so this is just the left | 75 // Cardboard devices always assume a mirrored FOV, so this is just the left |
76 // eye FOV with the left and right degrees swapped. | 76 // eye FOV with the left and right degrees swapped. |
77 right_eye->recommendedFieldOfView = mojom::VRFieldOfView::New(); | 77 right_eye->recommendedFieldOfView = blink::mojom::VRFieldOfView::New(); |
78 right_eye->recommendedFieldOfView->upDegrees = fov[0]; | 78 right_eye->recommendedFieldOfView->upDegrees = fov[0]; |
79 right_eye->recommendedFieldOfView->downDegrees = fov[1]; | 79 right_eye->recommendedFieldOfView->downDegrees = fov[1]; |
80 right_eye->recommendedFieldOfView->leftDegrees = fov[3]; | 80 right_eye->recommendedFieldOfView->leftDegrees = fov[3]; |
81 right_eye->recommendedFieldOfView->rightDegrees = fov[2]; | 81 right_eye->recommendedFieldOfView->rightDegrees = fov[2]; |
82 | 82 |
83 // Cardboard does not support configurable FOV. | 83 // Cardboard does not support configurable FOV. |
84 left_eye->maximumFieldOfView = left_eye->recommendedFieldOfView.Clone(); | 84 left_eye->maximumFieldOfView = left_eye->recommendedFieldOfView.Clone(); |
85 right_eye->maximumFieldOfView = right_eye->recommendedFieldOfView.Clone(); | 85 right_eye->maximumFieldOfView = right_eye->recommendedFieldOfView.Clone(); |
86 left_eye->minimumFieldOfView = left_eye->recommendedFieldOfView.Clone(); | 86 left_eye->minimumFieldOfView = left_eye->recommendedFieldOfView.Clone(); |
87 right_eye->minimumFieldOfView = right_eye->recommendedFieldOfView.Clone(); | 87 right_eye->minimumFieldOfView = right_eye->recommendedFieldOfView.Clone(); |
88 | 88 |
89 float ipd = Java_CardboardVRDevice_getIpd(env, j_cardboard_device_.obj()); | 89 float ipd = Java_CardboardVRDevice_getIpd(env, j_cardboard_device_.obj()); |
90 | 90 |
91 left_eye->eyeTranslation = mojom::VRVector3::New(); | 91 left_eye->eyeTranslation = blink::mojom::VRVector3::New(); |
92 left_eye->eyeTranslation->x = ipd * -0.5f; | 92 left_eye->eyeTranslation->x = ipd * -0.5f; |
93 left_eye->eyeTranslation->y = 0.0f; | 93 left_eye->eyeTranslation->y = 0.0f; |
94 left_eye->eyeTranslation->z = 0.0f; | 94 left_eye->eyeTranslation->z = 0.0f; |
95 | 95 |
96 right_eye->eyeTranslation = mojom::VRVector3::New(); | 96 right_eye->eyeTranslation = blink::mojom::VRVector3::New(); |
97 right_eye->eyeTranslation->x = ipd * 0.5f; | 97 right_eye->eyeTranslation->x = ipd * 0.5f; |
98 right_eye->eyeTranslation->y = 0.0f; | 98 right_eye->eyeTranslation->y = 0.0f; |
99 right_eye->eyeTranslation->z = 0.0f; | 99 right_eye->eyeTranslation->z = 0.0f; |
100 | 100 |
101 ScopedJavaLocalRef<jintArray> j_screen_size(env, env->NewIntArray(2)); | 101 ScopedJavaLocalRef<jintArray> j_screen_size(env, env->NewIntArray(2)); |
102 Java_CardboardVRDevice_getScreenSize(env, j_cardboard_device_.obj(), | 102 Java_CardboardVRDevice_getScreenSize(env, j_cardboard_device_.obj(), |
103 j_screen_size.obj()); | 103 j_screen_size.obj()); |
104 | 104 |
105 std::vector<int> screen_size; | 105 std::vector<int> screen_size; |
106 base::android::JavaIntArrayToIntVector(env, j_screen_size.obj(), | 106 base::android::JavaIntArrayToIntVector(env, j_screen_size.obj(), |
107 &screen_size); | 107 &screen_size); |
108 | 108 |
109 left_eye->renderRect = mojom::VRRect::New(); | 109 left_eye->renderRect = blink::mojom::VRRect::New(); |
110 left_eye->renderRect->x = 0; | 110 left_eye->renderRect->x = 0; |
111 left_eye->renderRect->y = 0; | 111 left_eye->renderRect->y = 0; |
112 left_eye->renderRect->width = screen_size[0] / 2.0; | 112 left_eye->renderRect->width = screen_size[0] / 2.0; |
113 left_eye->renderRect->height = screen_size[1]; | 113 left_eye->renderRect->height = screen_size[1]; |
114 | 114 |
115 right_eye->renderRect = mojom::VRRect::New(); | 115 right_eye->renderRect = blink::mojom::VRRect::New(); |
116 right_eye->renderRect->x = screen_size[0] / 2.0; | 116 right_eye->renderRect->x = screen_size[0] / 2.0; |
117 right_eye->renderRect->y = 0; | 117 right_eye->renderRect->y = 0; |
118 right_eye->renderRect->width = screen_size[0] / 2.0; | 118 right_eye->renderRect->width = screen_size[0] / 2.0; |
119 right_eye->renderRect->height = screen_size[1]; | 119 right_eye->renderRect->height = screen_size[1]; |
120 | 120 |
121 return device; | 121 return device; |
122 } | 122 } |
123 | 123 |
124 mojom::VRSensorStatePtr CardboardVRDevice::GetSensorState() { | 124 blink::mojom::VRSensorStatePtr CardboardVRDevice::GetSensorState() { |
125 TRACE_EVENT0("input", "CardboardVRDevice::GetSensorState"); | 125 TRACE_EVENT0("input", "CardboardVRDevice::GetSensorState"); |
126 mojom::VRSensorStatePtr state = mojom::VRSensorState::New(); | 126 blink::mojom::VRSensorStatePtr state = blink::mojom::VRSensorState::New(); |
127 | 127 |
128 state->timestamp = base::Time::Now().ToJsTime(); | 128 state->timestamp = base::Time::Now().ToJsTime(); |
129 state->frameIndex = frame_index_++; | 129 state->frameIndex = frame_index_++; |
130 | 130 |
131 JNIEnv* env = AttachCurrentThread(); | 131 JNIEnv* env = AttachCurrentThread(); |
132 Java_CardboardVRDevice_getSensorState(env, j_cardboard_device_.obj(), | 132 Java_CardboardVRDevice_getSensorState(env, j_cardboard_device_.obj(), |
133 j_head_matrix_.obj()); | 133 j_head_matrix_.obj()); |
134 | 134 |
135 std::vector<float> head_matrix; | 135 std::vector<float> head_matrix; |
136 base::android::JavaFloatArrayToFloatVector(env, j_head_matrix_.obj(), | 136 base::android::JavaFloatArrayToFloatVector(env, j_head_matrix_.obj(), |
137 &head_matrix); | 137 &head_matrix); |
138 | 138 |
139 gfx::Transform transform( | 139 gfx::Transform transform( |
140 head_matrix[0], head_matrix[1], head_matrix[2], head_matrix[3], | 140 head_matrix[0], head_matrix[1], head_matrix[2], head_matrix[3], |
141 head_matrix[4], head_matrix[5], head_matrix[6], head_matrix[7], | 141 head_matrix[4], head_matrix[5], head_matrix[6], head_matrix[7], |
142 head_matrix[8], head_matrix[9], head_matrix[10], head_matrix[11], | 142 head_matrix[8], head_matrix[9], head_matrix[10], head_matrix[11], |
143 head_matrix[12], head_matrix[13], head_matrix[14], head_matrix[15]); | 143 head_matrix[12], head_matrix[13], head_matrix[14], head_matrix[15]); |
144 | 144 |
145 gfx::DecomposedTransform decomposed_transform; | 145 gfx::DecomposedTransform decomposed_transform; |
146 gfx::DecomposeTransform(&decomposed_transform, transform); | 146 gfx::DecomposeTransform(&decomposed_transform, transform); |
147 | 147 |
148 state->orientation = mojom::VRVector4::New(); | 148 state->orientation = blink::mojom::VRVector4::New(); |
149 state->orientation->x = decomposed_transform.quaternion[0]; | 149 state->orientation->x = decomposed_transform.quaternion[0]; |
150 state->orientation->y = decomposed_transform.quaternion[1]; | 150 state->orientation->y = decomposed_transform.quaternion[1]; |
151 state->orientation->z = decomposed_transform.quaternion[2]; | 151 state->orientation->z = decomposed_transform.quaternion[2]; |
152 state->orientation->w = decomposed_transform.quaternion[3]; | 152 state->orientation->w = decomposed_transform.quaternion[3]; |
153 | 153 |
154 state->position = mojom::VRVector3::New(); | 154 state->position = blink::mojom::VRVector3::New(); |
155 state->position->x = decomposed_transform.translate[0]; | 155 state->position->x = decomposed_transform.translate[0]; |
156 state->position->y = decomposed_transform.translate[1]; | 156 state->position->y = decomposed_transform.translate[1]; |
157 state->position->z = decomposed_transform.translate[2]; | 157 state->position->z = decomposed_transform.translate[2]; |
158 | 158 |
159 return state; | 159 return state; |
160 } | 160 } |
161 | 161 |
162 void CardboardVRDevice::ResetSensor() { | 162 void CardboardVRDevice::ResetSensor() { |
163 Java_CardboardVRDevice_resetSensor(AttachCurrentThread(), | 163 Java_CardboardVRDevice_resetSensor(AttachCurrentThread(), |
164 j_cardboard_device_.obj()); | 164 j_cardboard_device_.obj()); |
165 } | 165 } |
166 | 166 |
167 } // namespace content | 167 } // namespace content |
OLD | NEW |