OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "modules/vr/VRTypeConverters.h" |
| 6 |
| 7 #include <string.h> |
| 8 #include <algorithm> |
| 9 |
| 10 using blink::mojom::VRVector3Ptr; |
| 11 using blink::mojom::VRVector4Ptr; |
| 12 using blink::mojom::VRRectPtr; |
| 13 using blink::mojom::VRFieldOfViewPtr; |
| 14 using blink::mojom::VREyeParametersPtr; |
| 15 using blink::mojom::VRHMDInfoPtr; |
| 16 using blink::mojom::VRDeviceInfoPtr; |
| 17 using blink::mojom::VRSensorStatePtr; |
| 18 |
| 19 namespace mojo { |
| 20 |
| 21 // static |
| 22 blink::WebVRVector3 TypeConverter<blink::WebVRVector3, VRVector3Ptr>::Convert( |
| 23 const VRVector3Ptr& input) |
| 24 { |
| 25 blink::WebVRVector3 output; |
| 26 output.x = input->x; |
| 27 output.y = input->y; |
| 28 output.z = input->z; |
| 29 return output; |
| 30 } |
| 31 |
| 32 // static |
| 33 blink::WebVRVector4 TypeConverter<blink::WebVRVector4, VRVector4Ptr>::Convert( |
| 34 const VRVector4Ptr& input) |
| 35 { |
| 36 blink::WebVRVector4 output; |
| 37 output.x = input->x; |
| 38 output.y = input->y; |
| 39 output.z = input->z; |
| 40 output.w = input->w; |
| 41 return output; |
| 42 } |
| 43 |
| 44 // static |
| 45 blink::WebVRRect TypeConverter<blink::WebVRRect, VRRectPtr>::Convert( |
| 46 const VRRectPtr& input) |
| 47 { |
| 48 blink::WebVRRect output; |
| 49 output.x = input->x; |
| 50 output.y = input->y; |
| 51 output.width = input->width; |
| 52 output.height = input->height; |
| 53 return output; |
| 54 } |
| 55 |
| 56 // static |
| 57 blink::WebVRFieldOfView |
| 58 TypeConverter<blink::WebVRFieldOfView, VRFieldOfViewPtr>::Convert( |
| 59 const VRFieldOfViewPtr& input) |
| 60 { |
| 61 blink::WebVRFieldOfView output; |
| 62 output.upDegrees = input->upDegrees; |
| 63 output.downDegrees = input->downDegrees; |
| 64 output.leftDegrees = input->leftDegrees; |
| 65 output.rightDegrees = input->rightDegrees; |
| 66 return output; |
| 67 } |
| 68 |
| 69 // static |
| 70 blink::WebVREyeParameters |
| 71 TypeConverter<blink::WebVREyeParameters, VREyeParametersPtr>::Convert( |
| 72 const VREyeParametersPtr& input) |
| 73 { |
| 74 blink::WebVREyeParameters output; |
| 75 output.minimumFieldOfView = input->minimumFieldOfView.To<blink::WebVRFieldOf
View>(); |
| 76 output.maximumFieldOfView = input->maximumFieldOfView.To<blink::WebVRFieldOf
View>(); |
| 77 output.recommendedFieldOfView = input->recommendedFieldOfView.To<blink::WebV
RFieldOfView>(); |
| 78 output.eyeTranslation = input->eyeTranslation.To<blink::WebVRVector3>(); |
| 79 output.renderRect = input->renderRect.To<blink::WebVRRect>(); |
| 80 return output; |
| 81 } |
| 82 |
| 83 // static |
| 84 blink::WebVRHMDInfo TypeConverter<blink::WebVRHMDInfo, VRHMDInfoPtr>::Convert( |
| 85 const VRHMDInfoPtr& input) |
| 86 { |
| 87 blink::WebVRHMDInfo output; |
| 88 output.leftEye = input->leftEye.To<blink::WebVREyeParameters>(); |
| 89 output.rightEye = input->rightEye.To<blink::WebVREyeParameters>(); |
| 90 return output; |
| 91 } |
| 92 |
| 93 // static |
| 94 blink::WebVRDevice TypeConverter<blink::WebVRDevice, VRDeviceInfoPtr>::Convert( |
| 95 const VRDeviceInfoPtr& input) |
| 96 { |
| 97 blink::WebVRDevice output; |
| 98 memset(&output, 0, sizeof(blink::WebVRDevice)); |
| 99 |
| 100 output.index = input->index; |
| 101 output.flags = blink::WebVRDeviceTypePosition; |
| 102 output.deviceName = blink::WebString::fromUTF8(input->deviceName.data(), |
| 103 input->deviceName.size()); |
| 104 |
| 105 if (!input->hmdInfo.is_null()) { |
| 106 output.flags |= blink::WebVRDeviceTypeHMD; |
| 107 output.hmdInfo = input->hmdInfo.To<blink::WebVRHMDInfo>(); |
| 108 } |
| 109 |
| 110 return output; |
| 111 } |
| 112 |
| 113 // static |
| 114 blink::WebHMDSensorState |
| 115 TypeConverter<blink::WebHMDSensorState, VRSensorStatePtr>::Convert( |
| 116 const VRSensorStatePtr& input) |
| 117 { |
| 118 blink::WebHMDSensorState output; |
| 119 output.timestamp = input->timestamp; |
| 120 output.frameIndex = input->frameIndex; |
| 121 output.flags = 0; |
| 122 |
| 123 if (!input->orientation.is_null()) { |
| 124 output.flags |= blink::WebVRSensorStateOrientation; |
| 125 output.orientation = input->orientation.To<blink::WebVRVector4>(); |
| 126 } |
| 127 if (!input->position.is_null()) { |
| 128 output.flags |= blink::WebVRSensorStatePosition; |
| 129 output.position = input->position.To<blink::WebVRVector3>(); |
| 130 } |
| 131 if (!input->angularVelocity.is_null()) { |
| 132 output.flags |= blink::WebVRSensorStateAngularVelocity; |
| 133 output.angularVelocity = input->angularVelocity.To<blink::WebVRVector3>(
); |
| 134 } |
| 135 if (!input->linearVelocity.is_null()) { |
| 136 output.flags |= blink::WebVRSensorStateLinearVelocity; |
| 137 output.linearVelocity = input->linearVelocity.To<blink::WebVRVector3>(); |
| 138 } |
| 139 if (!input->angularAcceleration.is_null()) { |
| 140 output.flags |= blink::WebVRSensorStateAngularAcceleration; |
| 141 output.angularAcceleration = input->angularAcceleration.To<blink::WebVRV
ector3>(); |
| 142 } |
| 143 if (!input->linearAcceleration.is_null()) { |
| 144 output.flags |= blink::WebVRSensorStateLinearAcceleration; |
| 145 output.linearAcceleration = input->linearAcceleration.To<blink::WebVRVec
tor3>(); |
| 146 } |
| 147 |
| 148 return output; |
| 149 } |
| 150 |
| 151 } // namespace mojo |
OLD | NEW |