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 | |
22 TypeConverter<blink::WebVRVector3, VRVector3Ptr>::Convert( | |
23 const VRVector3Ptr& input) { | |
24 blink::WebVRVector3 output; | |
25 output.x = input->x; | |
26 output.y = input->y; | |
27 output.z = input->z; | |
28 return output; | |
29 } | |
30 | |
31 // static | |
32 blink::WebVRVector4 | |
33 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 | |
45 TypeConverter<blink::WebVRRect, VRRectPtr>::Convert( | |
46 const VRRectPtr& input) { | |
47 blink::WebVRRect output; | |
48 output.x = input->x; | |
49 output.y = input->y; | |
50 output.width = input->width; | |
51 output.height = input->height; | |
52 return output; | |
53 } | |
54 | |
55 // static | |
56 blink::WebVRFieldOfView | |
57 TypeConverter<blink::WebVRFieldOfView, VRFieldOfViewPtr>::Convert( | |
58 const VRFieldOfViewPtr& input) { | |
59 blink::WebVRFieldOfView output; | |
60 output.upDegrees = input->upDegrees; | |
61 output.downDegrees = input->downDegrees; | |
62 output.leftDegrees = input->leftDegrees; | |
63 output.rightDegrees = input->rightDegrees; | |
64 return output; | |
65 } | |
66 | |
67 // static | |
68 blink::WebVREyeParameters | |
69 TypeConverter<blink::WebVREyeParameters, VREyeParametersPtr>::Convert( | |
70 const VREyeParametersPtr& input) { | |
71 blink::WebVREyeParameters output; | |
72 output.minimumFieldOfView = | |
73 input->minimumFieldOfView.To<blink::WebVRFieldOfView>(); | |
74 output.maximumFieldOfView = | |
75 input->maximumFieldOfView.To<blink::WebVRFieldOfView>(); | |
76 output.recommendedFieldOfView = | |
77 input->recommendedFieldOfView.To<blink::WebVRFieldOfView>(); | |
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 | |
85 TypeConverter<blink::WebVRHMDInfo, VRHMDInfoPtr>::Convert( | |
86 const VRHMDInfoPtr& input) { | |
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 | |
95 TypeConverter<blink::WebVRDevice, VRDeviceInfoPtr>::Convert( | |
96 const VRDeviceInfoPtr& input) { | |
97 blink::WebVRDevice output; | |
98 memset(&output, 0, sizeof(blink::WebVRDevice)); | |
99 | |
100 output.index = input->index; | |
101 output.flags = blink::WebVRDeviceTypePosition; | |
102 | |
103 memcpy(output.deviceName, input->deviceName.data(), | |
Tom Sepez
2015/06/01 18:26:28
blink::WebVRDevice::deviceName is of type unsigned
| |
104 std::min(blink::WebVRDevice::deviceNameLengthCap-1, | |
105 input->deviceName.size())); | |
106 | |
107 if (!input->hmdInfo.is_null()) { | |
108 output.flags |= blink::WebVRDeviceTypeHMD; | |
109 output.hmdInfo = input->hmdInfo.To<blink::WebVRHMDInfo>(); | |
110 } | |
111 | |
112 return output; | |
113 } | |
114 | |
115 // static | |
116 blink::WebHMDSensorState | |
117 TypeConverter<blink::WebHMDSensorState, VRSensorStatePtr>::Convert( | |
118 const VRSensorStatePtr& input) { | |
119 blink::WebHMDSensorState output; | |
120 output.timestamp = input->timestamp; | |
121 output.frameIndex = input->frameIndex; | |
122 output.flags = 0; | |
123 | |
124 if (!input->orientation.is_null()) { | |
125 output.flags |= blink::WebVRSensorStateOrientation; | |
126 output.orientation = input->orientation.To<blink::WebVRVector4>(); | |
127 } | |
128 if (!input->position.is_null()) { | |
129 output.flags |= blink::WebVRSensorStatePosition; | |
130 output.position = input->position.To<blink::WebVRVector3>(); | |
131 } | |
132 if (!input->angularVelocity.is_null()) { | |
133 output.flags |= blink::WebVRSensorStateAngularVelocity; | |
134 output.angularVelocity = input->angularVelocity.To<blink::WebVRVector3>(); | |
135 } | |
136 if (!input->linearVelocity.is_null()) { | |
137 output.flags |= blink::WebVRSensorStateLinearVelocity; | |
138 output.linearVelocity = input->linearVelocity.To<blink::WebVRVector3>(); | |
139 } | |
140 if (!input->angularAcceleration.is_null()) { | |
141 output.flags |= blink::WebVRSensorStateAngularAcceleration; | |
142 output.angularAcceleration = | |
143 input->angularAcceleration.To<blink::WebVRVector3>(); | |
144 } | |
145 if (!input->linearAcceleration.is_null()) { | |
146 output.flags |= blink::WebVRSensorStateLinearAcceleration; | |
147 output.linearAcceleration = | |
148 input->linearAcceleration.To<blink::WebVRVector3>(); | |
149 } | |
150 | |
151 return output; | |
152 } | |
153 | |
154 } // namespace mojo | |
OLD | NEW |