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