| 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 "device/vr/android/cardboard/cardboard_vr_device.h" | 5 #include "device/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 blink::mojom::VRDisplayPtr CardboardVRDevice::GetVRDevice() { | 43 VRDisplayPtr CardboardVRDevice::GetVRDevice() { |
| 44 TRACE_EVENT0("input", "CardboardVRDevice::GetVRDevice"); | 44 TRACE_EVENT0("input", "CardboardVRDevice::GetVRDevice"); |
| 45 blink::mojom::VRDisplayPtr device = blink::mojom::VRDisplay::New(); | 45 VRDisplayPtr device = VRDisplay::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->displayName = | 51 device->displayName = |
| 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->capabilities = blink::mojom::VRDisplayCapabilities::New(); | 61 device->capabilities = VRDisplayCapabilities::New(); |
| 62 device->capabilities->hasOrientation = true; | 62 device->capabilities->hasOrientation = true; |
| 63 device->capabilities->hasPosition = false; | 63 device->capabilities->hasPosition = false; |
| 64 device->capabilities->hasExternalDisplay = false; | 64 device->capabilities->hasExternalDisplay = false; |
| 65 device->capabilities->canPresent = false; | 65 device->capabilities->canPresent = false; |
| 66 | 66 |
| 67 device->leftEye = blink::mojom::VREyeParameters::New(); | 67 device->leftEye = VREyeParameters::New(); |
| 68 device->rightEye = blink::mojom::VREyeParameters::New(); | 68 device->rightEye = VREyeParameters::New(); |
| 69 blink::mojom::VREyeParametersPtr& left_eye = device->leftEye; | 69 VREyeParametersPtr& left_eye = device->leftEye; |
| 70 blink::mojom::VREyeParametersPtr& right_eye = device->rightEye; | 70 VREyeParametersPtr& right_eye = device->rightEye; |
| 71 | 71 |
| 72 left_eye->fieldOfView = blink::mojom::VRFieldOfView::New(); | 72 left_eye->fieldOfView = VRFieldOfView::New(); |
| 73 left_eye->fieldOfView->upDegrees = fov[0]; | 73 left_eye->fieldOfView->upDegrees = fov[0]; |
| 74 left_eye->fieldOfView->downDegrees = fov[1]; | 74 left_eye->fieldOfView->downDegrees = fov[1]; |
| 75 left_eye->fieldOfView->leftDegrees = fov[2]; | 75 left_eye->fieldOfView->leftDegrees = fov[2]; |
| 76 left_eye->fieldOfView->rightDegrees = fov[3]; | 76 left_eye->fieldOfView->rightDegrees = fov[3]; |
| 77 | 77 |
| 78 // Cardboard devices always assume a mirrored FOV, so this is just the left | 78 // Cardboard devices always assume a mirrored FOV, so this is just the left |
| 79 // eye FOV with the left and right degrees swapped. | 79 // eye FOV with the left and right degrees swapped. |
| 80 right_eye->fieldOfView = blink::mojom::VRFieldOfView::New(); | 80 right_eye->fieldOfView = VRFieldOfView::New(); |
| 81 right_eye->fieldOfView->upDegrees = fov[0]; | 81 right_eye->fieldOfView->upDegrees = fov[0]; |
| 82 right_eye->fieldOfView->downDegrees = fov[1]; | 82 right_eye->fieldOfView->downDegrees = fov[1]; |
| 83 right_eye->fieldOfView->leftDegrees = fov[3]; | 83 right_eye->fieldOfView->leftDegrees = fov[3]; |
| 84 right_eye->fieldOfView->rightDegrees = fov[2]; | 84 right_eye->fieldOfView->rightDegrees = fov[2]; |
| 85 | 85 |
| 86 float ipd = Java_CardboardVRDevice_getIpd(env, j_cardboard_device_.obj()); | 86 float ipd = Java_CardboardVRDevice_getIpd(env, j_cardboard_device_.obj()); |
| 87 | 87 |
| 88 left_eye->offset = mojo::Array<float>::New(3); | 88 left_eye->offset = mojo::Array<float>::New(3); |
| 89 left_eye->offset[0] = ipd * -0.5f; | 89 left_eye->offset[0] = ipd * -0.5f; |
| 90 left_eye->offset[1] = 0.0f; | 90 left_eye->offset[1] = 0.0f; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 105 | 105 |
| 106 left_eye->renderWidth = screen_size[0] / 2.0; | 106 left_eye->renderWidth = screen_size[0] / 2.0; |
| 107 left_eye->renderHeight = screen_size[1]; | 107 left_eye->renderHeight = screen_size[1]; |
| 108 | 108 |
| 109 right_eye->renderWidth = screen_size[0] / 2.0; | 109 right_eye->renderWidth = screen_size[0] / 2.0; |
| 110 right_eye->renderHeight = screen_size[1]; | 110 right_eye->renderHeight = screen_size[1]; |
| 111 | 111 |
| 112 return device; | 112 return device; |
| 113 } | 113 } |
| 114 | 114 |
| 115 blink::mojom::VRPosePtr CardboardVRDevice::GetPose() { | 115 VRPosePtr CardboardVRDevice::GetPose() { |
| 116 TRACE_EVENT0("input", "CardboardVRDevice::GetSensorState"); | 116 TRACE_EVENT0("input", "CardboardVRDevice::GetSensorState"); |
| 117 blink::mojom::VRPosePtr pose = blink::mojom::VRPose::New(); | 117 VRPosePtr pose = VRPose::New(); |
| 118 | 118 |
| 119 pose->timestamp = base::Time::Now().ToJsTime(); | 119 pose->timestamp = base::Time::Now().ToJsTime(); |
| 120 | 120 |
| 121 JNIEnv* env = AttachCurrentThread(); | 121 JNIEnv* env = AttachCurrentThread(); |
| 122 Java_CardboardVRDevice_getSensorState(env, j_cardboard_device_.obj(), | 122 Java_CardboardVRDevice_getSensorState(env, j_cardboard_device_.obj(), |
| 123 j_head_matrix_.obj()); | 123 j_head_matrix_.obj()); |
| 124 | 124 |
| 125 std::vector<float> head_matrix; | 125 std::vector<float> head_matrix; |
| 126 base::android::JavaFloatArrayToFloatVector(env, j_head_matrix_.obj(), | 126 base::android::JavaFloatArrayToFloatVector(env, j_head_matrix_.obj(), |
| 127 &head_matrix); | 127 &head_matrix); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 148 | 148 |
| 149 return pose; | 149 return pose; |
| 150 } | 150 } |
| 151 | 151 |
| 152 void CardboardVRDevice::ResetPose() { | 152 void CardboardVRDevice::ResetPose() { |
| 153 Java_CardboardVRDevice_resetSensor(AttachCurrentThread(), | 153 Java_CardboardVRDevice_resetSensor(AttachCurrentThread(), |
| 154 j_cardboard_device_.obj()); | 154 j_cardboard_device_.obj()); |
| 155 } | 155 } |
| 156 | 156 |
| 157 } // namespace device | 157 } // namespace device |
| OLD | NEW |