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