Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/VRMessageUtils.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_gfx_vr_VRMessageUtils_h
8
#define mozilla_gfx_vr_VRMessageUtils_h
9
10
#include "ipc/IPCMessageUtils.h"
11
#include "mozilla/ArrayUtils.h"
12
#include "mozilla/GfxMessageUtils.h"
13
#include "VRManager.h"
14
15
#include "gfxVR.h"
16
17
namespace IPC {
18
19
template<>
20
struct ParamTraits<mozilla::gfx::VRDeviceType> :
21
  public ContiguousEnumSerializer<mozilla::gfx::VRDeviceType,
22
                                  mozilla::gfx::VRDeviceType(0),
23
                                  mozilla::gfx::VRDeviceType(mozilla::gfx::VRDeviceType::NumVRDeviceTypes)> {};
24
25
template<>
26
struct ParamTraits<mozilla::gfx::VRDisplayCapabilityFlags> :
27
  public BitFlagsEnumSerializer<mozilla::gfx::VRDisplayCapabilityFlags,
28
                                mozilla::gfx::VRDisplayCapabilityFlags::Cap_All> {};
29
30
template <>
31
struct ParamTraits<mozilla::gfx::VRDisplayState>
32
{
33
  typedef mozilla::gfx::VRDisplayState paramType;
34
35
  static void Write(Message* aMsg, const paramType& aParam)
36
0
  {
37
0
    // TODO - VRDisplayState is asserted to be a POD type
38
0
    //        A simple memcpy may be sufficient here, or
39
0
    //        this code can be refactored out if we use
40
0
    //        shmem between the VR and content process.
41
0
    nsCString displayName;
42
0
    displayName.Assign(aParam.mDisplayName);
43
0
    WriteParam(aMsg, displayName);
44
0
    WriteParam(aMsg, aParam.mCapabilityFlags);
45
0
    WriteParam(aMsg, aParam.mEyeResolution.width);
46
0
    WriteParam(aMsg, aParam.mEyeResolution.height);
47
0
    WriteParam(aMsg, aParam.mSuppressFrames);
48
0
    WriteParam(aMsg, aParam.mIsConnected);
49
0
    WriteParam(aMsg, aParam.mIsMounted);
50
0
    WriteParam(aMsg, aParam.mStageSize.width);
51
0
    WriteParam(aMsg, aParam.mStageSize.height);
52
0
    WriteParam(aMsg, aParam.mLastSubmittedFrameId);
53
0
    WriteParam(aMsg, aParam.mPresentingGeneration);
54
0
    for (int i = 0; i < 16; i++) {
55
0
      // TODO - Should probably memcpy the whole array or
56
0
      // convert Maxtrix4x4 to a POD type and use it
57
0
      // instead
58
0
      WriteParam(aMsg, aParam.mSittingToStandingTransform[i]);
59
0
    }
60
0
    for (int i = 0; i < mozilla::gfx::VRDisplayState::NumEyes; i++) {
61
0
      WriteParam(aMsg, aParam.mEyeFOV[i]);
62
0
      WriteParam(aMsg, aParam.mEyeTranslation[i].x);
63
0
      WriteParam(aMsg, aParam.mEyeTranslation[i].y);
64
0
      WriteParam(aMsg, aParam.mEyeTranslation[i].z);
65
0
    }
66
0
  }
67
68
  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
69
0
  {
70
0
    nsCString displayName;
71
0
    if (!ReadParam(aMsg, aIter, &(displayName)) ||
72
0
        !ReadParam(aMsg, aIter, &(aResult->mCapabilityFlags)) ||
73
0
        !ReadParam(aMsg, aIter, &(aResult->mEyeResolution.width)) ||
74
0
        !ReadParam(aMsg, aIter, &(aResult->mEyeResolution.height)) ||
75
0
        !ReadParam(aMsg, aIter, &(aResult->mSuppressFrames)) ||
76
0
        !ReadParam(aMsg, aIter, &(aResult->mIsConnected)) ||
77
0
        !ReadParam(aMsg, aIter, &(aResult->mIsMounted)) ||
78
0
        !ReadParam(aMsg, aIter, &(aResult->mStageSize.width)) ||
79
0
        !ReadParam(aMsg, aIter, &(aResult->mStageSize.height)) ||
80
0
        !ReadParam(aMsg, aIter, &(aResult->mLastSubmittedFrameId)) ||
81
0
        !ReadParam(aMsg, aIter, &(aResult->mPresentingGeneration))) {
82
0
      return false;
83
0
    }
84
0
    for (int i = 0; i < 16; i++) {
85
0
      if (!ReadParam(aMsg, aIter, &(aResult->mSittingToStandingTransform[i]))) {
86
0
        return false;
87
0
      }
88
0
    }
89
0
    strncpy(aResult->mDisplayName, displayName.BeginReading(), mozilla::gfx::kVRDisplayNameMaxLen);
90
0
    for (int i = 0; i < mozilla::gfx::VRDisplayState::NumEyes; i++) {
91
0
      if (!ReadParam(aMsg, aIter, &(aResult->mEyeFOV[i])) ||
92
0
          !ReadParam(aMsg, aIter, &(aResult->mEyeTranslation[i].x)) ||
93
0
          !ReadParam(aMsg, aIter, &(aResult->mEyeTranslation[i].y)) ||
94
0
          !ReadParam(aMsg, aIter, &(aResult->mEyeTranslation[i].z))) {
95
0
        return false;
96
0
      }
97
0
    }
98
0
    return true;
99
0
  }
100
};
101
102
template <>
103
struct ParamTraits<mozilla::gfx::VRDisplayInfo>
104
{
105
  typedef mozilla::gfx::VRDisplayInfo paramType;
106
107
  static void Write(Message* aMsg, const paramType& aParam)
108
0
  {
109
0
    WriteParam(aMsg, aParam.mType);
110
0
    WriteParam(aMsg, aParam.mDisplayID);
111
0
    WriteParam(aMsg, aParam.mPresentingGroups);
112
0
    WriteParam(aMsg, aParam.mGroupMask);
113
0
    WriteParam(aMsg, aParam.mFrameId);
114
0
    WriteParam(aMsg, aParam.mDisplayState);
115
0
    for (size_t i = 0; i < mozilla::ArrayLength(aParam.mLastSensorState); i++) {
116
0
      WriteParam(aMsg, aParam.mLastSensorState[i]);
117
0
    }
118
0
    for (size_t i = 0; i < mozilla::ArrayLength(aParam.mControllerState); i++) {
119
0
      WriteParam(aMsg, aParam.mControllerState[i]);
120
0
    }
121
0
  }
122
123
  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
124
0
  {
125
0
    if (!ReadParam(aMsg, aIter, &(aResult->mType)) ||
126
0
        !ReadParam(aMsg, aIter, &(aResult->mDisplayID)) ||
127
0
        !ReadParam(aMsg, aIter, &(aResult->mPresentingGroups)) ||
128
0
        !ReadParam(aMsg, aIter, &(aResult->mGroupMask)) ||
129
0
        !ReadParam(aMsg, aIter, &(aResult->mFrameId)) ||
130
0
        !ReadParam(aMsg, aIter, &(aResult->mDisplayState))) {
131
0
      return false;
132
0
    }
133
0
    for (size_t i = 0; i < mozilla::ArrayLength(aResult->mLastSensorState); i++) {
134
0
      if (!ReadParam(aMsg, aIter, &(aResult->mLastSensorState[i]))) {
135
0
        return false;
136
0
      }
137
0
    }
138
0
    for (size_t i = 0; i < mozilla::ArrayLength(aResult->mControllerState); i++) {
139
0
      if (!ReadParam(aMsg, aIter, &(aResult->mControllerState[i]))) {
140
0
        return false;
141
0
      }
142
0
    }
143
0
    return true;
144
0
  }
145
};
146
147
148
template <>
149
struct ParamTraits<mozilla::gfx::VRPose>
150
{
151
  typedef mozilla::gfx::VRPose paramType;
152
153
  static void Write(Message* aMsg, const paramType& aParam)
154
0
  {
155
0
    WriteParam(aMsg, aParam.orientation[0]);
156
0
    WriteParam(aMsg, aParam.orientation[1]);
157
0
    WriteParam(aMsg, aParam.orientation[2]);
158
0
    WriteParam(aMsg, aParam.orientation[3]);
159
0
    WriteParam(aMsg, aParam.position[0]);
160
0
    WriteParam(aMsg, aParam.position[1]);
161
0
    WriteParam(aMsg, aParam.position[2]);
162
0
    WriteParam(aMsg, aParam.angularVelocity[0]);
163
0
    WriteParam(aMsg, aParam.angularVelocity[1]);
164
0
    WriteParam(aMsg, aParam.angularVelocity[2]);
165
0
    WriteParam(aMsg, aParam.angularAcceleration[0]);
166
0
    WriteParam(aMsg, aParam.angularAcceleration[1]);
167
0
    WriteParam(aMsg, aParam.angularAcceleration[2]);
168
0
    WriteParam(aMsg, aParam.linearVelocity[0]);
169
0
    WriteParam(aMsg, aParam.linearVelocity[1]);
170
0
    WriteParam(aMsg, aParam.linearVelocity[2]);
171
0
    WriteParam(aMsg, aParam.linearAcceleration[0]);
172
0
    WriteParam(aMsg, aParam.linearAcceleration[1]);
173
0
    WriteParam(aMsg, aParam.linearAcceleration[2]);
174
0
  }
175
176
  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
177
0
  {
178
0
    if (!ReadParam(aMsg, aIter, &(aResult->orientation[0])) ||
179
0
        !ReadParam(aMsg, aIter, &(aResult->orientation[1])) ||
180
0
        !ReadParam(aMsg, aIter, &(aResult->orientation[2])) ||
181
0
        !ReadParam(aMsg, aIter, &(aResult->orientation[3])) ||
182
0
        !ReadParam(aMsg, aIter, &(aResult->position[0])) ||
183
0
        !ReadParam(aMsg, aIter, &(aResult->position[1])) ||
184
0
        !ReadParam(aMsg, aIter, &(aResult->position[2])) ||
185
0
        !ReadParam(aMsg, aIter, &(aResult->angularVelocity[0])) ||
186
0
        !ReadParam(aMsg, aIter, &(aResult->angularVelocity[1])) ||
187
0
        !ReadParam(aMsg, aIter, &(aResult->angularVelocity[2])) ||
188
0
        !ReadParam(aMsg, aIter, &(aResult->angularAcceleration[0])) ||
189
0
        !ReadParam(aMsg, aIter, &(aResult->angularAcceleration[1])) ||
190
0
        !ReadParam(aMsg, aIter, &(aResult->angularAcceleration[2])) ||
191
0
        !ReadParam(aMsg, aIter, &(aResult->linearVelocity[0])) ||
192
0
        !ReadParam(aMsg, aIter, &(aResult->linearVelocity[1])) ||
193
0
        !ReadParam(aMsg, aIter, &(aResult->linearVelocity[2])) ||
194
0
        !ReadParam(aMsg, aIter, &(aResult->linearAcceleration[0])) ||
195
0
        !ReadParam(aMsg, aIter, &(aResult->linearAcceleration[1])) ||
196
0
        !ReadParam(aMsg, aIter, &(aResult->linearAcceleration[2]))) {
197
0
      return false;
198
0
    }
199
0
    return true;
200
0
  }
201
};
202
203
template <>
204
struct ParamTraits<mozilla::gfx::VRHMDSensorState>
205
{
206
  typedef mozilla::gfx::VRHMDSensorState paramType;
207
208
  static void Write(Message* aMsg, const paramType& aParam)
209
0
  {
210
0
    WriteParam(aMsg, aParam.timestamp);
211
0
    WriteParam(aMsg, aParam.inputFrameID);
212
0
    WriteParam(aMsg, aParam.flags);
213
0
    WriteParam(aMsg, aParam.pose);
214
0
    for (size_t i = 0; i < mozilla::ArrayLength(aParam.leftViewMatrix); i++) {
215
0
      WriteParam(aMsg, aParam.leftViewMatrix[i]);
216
0
    }
217
0
    for (size_t i = 0; i < mozilla::ArrayLength(aParam.rightViewMatrix); i++) {
218
0
      WriteParam(aMsg, aParam.rightViewMatrix[i]);
219
0
    }
220
0
  }
221
222
  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
223
0
  {
224
0
    if (!ReadParam(aMsg, aIter, &(aResult->timestamp)) ||
225
0
        !ReadParam(aMsg, aIter, &(aResult->inputFrameID)) ||
226
0
        !ReadParam(aMsg, aIter, &(aResult->flags)) ||
227
0
        !ReadParam(aMsg, aIter, &(aResult->pose))) {
228
0
      return false;
229
0
    }
230
0
    for (size_t i = 0; i < mozilla::ArrayLength(aResult->leftViewMatrix); i++) {
231
0
      if (!ReadParam(aMsg, aIter, &(aResult->leftViewMatrix[i]))) {
232
0
        return false;
233
0
      }
234
0
    }
235
0
    for (size_t i = 0; i < mozilla::ArrayLength(aResult->rightViewMatrix); i++) {
236
0
      if (!ReadParam(aMsg, aIter, &(aResult->rightViewMatrix[i]))) {
237
0
        return false;
238
0
      }
239
0
    }
240
0
    return true;
241
0
  }
242
};
243
244
template <>
245
struct ParamTraits<mozilla::gfx::VRFieldOfView>
246
{
247
  typedef mozilla::gfx::VRFieldOfView paramType;
248
249
  static void Write(Message* aMsg, const paramType& aParam)
250
0
  {
251
0
    WriteParam(aMsg, aParam.upDegrees);
252
0
    WriteParam(aMsg, aParam.rightDegrees);
253
0
    WriteParam(aMsg, aParam.downDegrees);
254
0
    WriteParam(aMsg, aParam.leftDegrees);
255
0
  }
256
257
  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
258
0
  {
259
0
    if (!ReadParam(aMsg, aIter, &(aResult->upDegrees)) ||
260
0
        !ReadParam(aMsg, aIter, &(aResult->rightDegrees)) ||
261
0
        !ReadParam(aMsg, aIter, &(aResult->downDegrees)) ||
262
0
        !ReadParam(aMsg, aIter, &(aResult->leftDegrees))) {
263
0
      return false;
264
0
    }
265
0
266
0
    return true;
267
0
  }
268
};
269
270
271
template <>
272
struct ParamTraits<mozilla::gfx::VRControllerState>
273
{
274
  typedef mozilla::gfx::VRControllerState paramType;
275
276
  static void Write(Message* aMsg, const paramType& aParam)
277
0
  {
278
0
    nsCString controllerName;
279
0
    controllerName.Assign(aParam.controllerName); // FINDME!! HACK! - Bounds checking?
280
0
    WriteParam(aMsg, controllerName);
281
0
    WriteParam(aMsg, aParam.hand);
282
0
    WriteParam(aMsg, aParam.numButtons);
283
0
    WriteParam(aMsg, aParam.numAxes);
284
0
    WriteParam(aMsg, aParam.numHaptics);
285
0
    WriteParam(aMsg, aParam.buttonPressed);
286
0
    WriteParam(aMsg, aParam.buttonTouched);
287
0
    WriteParam(aMsg, aParam.flags);
288
0
    WriteParam(aMsg, aParam.pose);
289
0
    WriteParam(aMsg, aParam.isPositionValid);
290
0
    WriteParam(aMsg, aParam.isOrientationValid);
291
0
    for (size_t i = 0; i < mozilla::ArrayLength(aParam.axisValue); i++) {
292
0
      WriteParam(aMsg, aParam.axisValue[i]);
293
0
    }
294
0
    for (size_t i = 0; i < mozilla::ArrayLength(aParam.triggerValue); i++) {
295
0
      WriteParam(aMsg, aParam.triggerValue[i]);
296
0
    }
297
0
  }
298
299
  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
300
0
  {
301
0
    nsCString controllerName;
302
0
    if (!ReadParam(aMsg, aIter, &(controllerName)) ||
303
0
        !ReadParam(aMsg, aIter, &(aResult->hand)) ||
304
0
        !ReadParam(aMsg, aIter, &(aResult->numButtons)) ||
305
0
        !ReadParam(aMsg, aIter, &(aResult->numAxes)) ||
306
0
        !ReadParam(aMsg, aIter, &(aResult->numHaptics)) ||
307
0
        !ReadParam(aMsg, aIter, &(aResult->buttonPressed)) ||
308
0
        !ReadParam(aMsg, aIter, &(aResult->buttonTouched)) ||
309
0
        !ReadParam(aMsg, aIter, &(aResult->flags)) ||
310
0
        !ReadParam(aMsg, aIter, &(aResult->pose)) ||
311
0
        !ReadParam(aMsg, aIter, &(aResult->isPositionValid)) ||
312
0
        !ReadParam(aMsg, aIter, &(aResult->isOrientationValid))) {
313
0
      return false;
314
0
    }
315
0
    for (size_t i = 0; i < mozilla::ArrayLength(aResult->axisValue); i++) {
316
0
      if (!ReadParam(aMsg, aIter, &(aResult->axisValue[i]))) {
317
0
        return false;
318
0
      }
319
0
    }
320
0
    for (size_t i = 0; i < mozilla::ArrayLength(aResult->triggerValue); i++) {
321
0
      if (!ReadParam(aMsg, aIter, &(aResult->triggerValue[i]))) {
322
0
        return false;
323
0
      }
324
0
    }
325
0
    strncpy(aResult->controllerName, controllerName.BeginReading(), mozilla::gfx::kVRControllerNameMaxLen); // FINDME! TODO! HACK!  Safe? Better way?
326
0
327
0
    return true;
328
0
  }
329
};
330
331
template <>
332
struct ParamTraits<mozilla::gfx::VRControllerInfo>
333
{
334
  typedef mozilla::gfx::VRControllerInfo paramType;
335
336
  static void Write(Message* aMsg, const paramType& aParam)
337
0
  {
338
0
    WriteParam(aMsg, aParam.mType);
339
0
    WriteParam(aMsg, aParam.mControllerID);
340
0
    WriteParam(aMsg, aParam.mMappingType);
341
0
    WriteParam(aMsg, aParam.mControllerState);
342
0
  }
343
344
  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
345
0
  {
346
0
    if (!ReadParam(aMsg, aIter, &(aResult->mType)) ||
347
0
        !ReadParam(aMsg, aIter, &(aResult->mControllerID)) ||
348
0
        !ReadParam(aMsg, aIter, &(aResult->mMappingType)) ||
349
0
        !ReadParam(aMsg, aIter, &(aResult->mControllerState))) {
350
0
      return false;
351
0
    }
352
0
353
0
    return true;
354
0
  }
355
};
356
357
template <>
358
struct ParamTraits<mozilla::gfx::VRSubmitFrameResultInfo>
359
{
360
  typedef mozilla::gfx::VRSubmitFrameResultInfo paramType;
361
362
  static void Write(Message* aMsg, const paramType& aParam)
363
0
  {
364
0
    WriteParam(aMsg, aParam.mBase64Image);
365
0
    WriteParam(aMsg, aParam.mFormat);
366
0
    WriteParam(aMsg, aParam.mWidth);
367
0
    WriteParam(aMsg, aParam.mHeight);
368
0
    WriteParam(aMsg, aParam.mFrameNum);
369
0
  }
370
371
  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
372
0
  {
373
0
    if (!ReadParam(aMsg, aIter, &(aResult->mBase64Image)) ||
374
0
        !ReadParam(aMsg, aIter, &(aResult->mFormat)) ||
375
0
        !ReadParam(aMsg, aIter, &(aResult->mWidth)) ||
376
0
        !ReadParam(aMsg, aIter, &(aResult->mHeight)) ||
377
0
        !ReadParam(aMsg, aIter, &(aResult->mFrameNum))) {
378
0
      return false;
379
0
    }
380
0
381
0
    return true;
382
0
  }
383
};
384
385
} // namespace IPC
386
387
#endif // mozilla_gfx_vr_VRMessageUtils_h