LayersMessageUtils.h 36.7 KB
Newer Older
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
4
5
6
7
8
9
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_layers_LayersMessageUtils
#define mozilla_layers_LayersMessageUtils

10
11
12
13
#include <stdint.h>

#include <utility>

14
#include "FrameMetrics.h"
15
#include "VsyncSource.h"
16
17
18
19
#include "base/process_util.h"
#include "chrome/common/ipc_message_utils.h"
#include "gfxTelemetry.h"
#include "ipc/IPCMessageUtils.h"
20
#include "ipc/nsGUIEventIPC.h"
21
#include "mozilla/GfxMessageUtils.h"
22
23
#include "mozilla/MotionPathUtils.h"
#include "mozilla/ServoBindings.h"
24
#include "mozilla/ipc/ByteBufUtils.h"
25
#include "mozilla/layers/APZInputBridge.h"
26
27
28
#include "mozilla/layers/AsyncDragMetrics.h"
#include "mozilla/layers/CompositorOptions.h"
#include "mozilla/layers/CompositorTypes.h"
29
#include "mozilla/layers/FocusTarget.h"
30
#include "mozilla/layers/GeckoContentControllerTypes.h"
31
#include "mozilla/layers/KeyboardMap.h"
32
33
#include "mozilla/layers/LayerAttributes.h"
#include "mozilla/layers/LayersTypes.h"
34
#include "mozilla/layers/MatrixMessage.h"
35
#include "mozilla/layers/RefCountedShmem.h"
36
#include "mozilla/layers/RepaintRequest.h"
37
#include "mozilla/layers/WebRenderMessageUtils.h"
38
#include "nsSize.h"
39
40

#ifdef _MSC_VER
41
#  pragma warning(disable : 4800)
42
43
44
45
#endif

namespace IPC {

46
47
template <>
struct ParamTraits<mozilla::layers::LayersId>
48
    : public PlainOldDataSerializer<mozilla::layers::LayersId> {};
49

50
51
52
template <typename T>
struct ParamTraits<mozilla::layers::BaseTransactionId<T>>
    : public PlainOldDataSerializer<mozilla::layers::BaseTransactionId<T>> {};
53

54
55
56
57
template <>
struct ParamTraits<mozilla::VsyncId>
    : public PlainOldDataSerializer<mozilla::VsyncId> {};

58
template <>
59
60
61
62
63
64
65
66
67
68
69
70
71
struct ParamTraits<mozilla::VsyncEvent> {
  typedef mozilla::VsyncEvent paramType;

  static void Write(Message* msg, const paramType& param) {
    WriteParam(msg, param.mId);
    WriteParam(msg, param.mTime);
  }
  static bool Read(const Message* msg, PickleIterator* iter,
                   paramType* result) {
    return ReadParam(msg, iter, &result->mId) &&
           ReadParam(msg, iter, &result->mTime);
  }
};
72

73
template <>
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
struct ParamTraits<mozilla::layers::MatrixMessage> {
  typedef mozilla::layers::MatrixMessage paramType;

  static void Write(Message* aMsg, const paramType& aParam) {
    WriteParam(aMsg, aParam.mMatrix);
    WriteParam(aMsg, aParam.mTopLevelViewportVisibleRectInBrowserCoords);
    WriteParam(aMsg, aParam.mLayersId);
  }
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
    return ReadParam(aMsg, aIter, &aResult->mMatrix) &&
           ReadParam(aMsg, aIter,
                     &aResult->mTopLevelViewportVisibleRectInBrowserCoords) &&
           ReadParam(aMsg, aIter, &aResult->mLayersId);
  }
};
90

91
92
template <>
struct ParamTraits<mozilla::layers::LayersObserverEpoch>
93
    : public PlainOldDataSerializer<mozilla::layers::LayersObserverEpoch> {};
94

95
96
template <>
struct ParamTraits<mozilla::layers::LayersBackend>
97
98
99
100
    : public ContiguousEnumSerializer<
          mozilla::layers::LayersBackend,
          mozilla::layers::LayersBackend::LAYERS_NONE,
          mozilla::layers::LayersBackend::LAYERS_LAST> {};
101

102
103
template <>
struct ParamTraits<mozilla::layers::TextureType>
104
105
106
    : public ContiguousEnumSerializer<mozilla::layers::TextureType,
                                      mozilla::layers::TextureType::Unknown,
                                      mozilla::layers::TextureType::Last> {};
107

108
109
template <>
struct ParamTraits<mozilla::layers::ScaleMode>
110
111
112
    : public ContiguousEnumSerializerInclusive<
          mozilla::layers::ScaleMode, mozilla::layers::ScaleMode::SCALE_NONE,
          mozilla::layers::kHighestScaleMode> {};
113

114
template <>
115
struct ParamTraits<mozilla::StyleScrollSnapStrictness>
116
    : public ContiguousEnumSerializerInclusive<
117
118
119
          mozilla::StyleScrollSnapStrictness,
          mozilla::StyleScrollSnapStrictness::None,
          mozilla::StyleScrollSnapStrictness::Proximity> {};
120

121
122
template <>
struct ParamTraits<mozilla::layers::TextureFlags>
123
124
    : public BitFlagsEnumSerializer<mozilla::layers::TextureFlags,
                                    mozilla::layers::TextureFlags::ALL_BITS> {};
125
126
127

template <>
struct ParamTraits<mozilla::layers::DiagnosticTypes>
128
129
130
    : public BitFlagsEnumSerializer<
          mozilla::layers::DiagnosticTypes,
          mozilla::layers::DiagnosticTypes::ALL_BITS> {};
131
132
133

template <>
struct ParamTraits<mozilla::layers::ScrollDirection>
134
135
136
137
    : public ContiguousEnumSerializerInclusive<
          mozilla::layers::ScrollDirection,
          mozilla::layers::ScrollDirection::eVertical,
          mozilla::layers::kHighestScrollDirection> {};
138

139
template <>
140
struct ParamTraits<mozilla::layers::FrameMetrics::ScrollOffsetUpdateType>
141
142
143
144
    : public ContiguousEnumSerializerInclusive<
          mozilla::layers::FrameMetrics::ScrollOffsetUpdateType,
          mozilla::layers::FrameMetrics::ScrollOffsetUpdateType::eNone,
          mozilla::layers::FrameMetrics::sHighestScrollOffsetUpdateType> {};
145

146
template <>
147
struct ParamTraits<mozilla::layers::RepaintRequest::ScrollOffsetUpdateType>
148
149
150
151
    : public ContiguousEnumSerializerInclusive<
          mozilla::layers::RepaintRequest::ScrollOffsetUpdateType,
          mozilla::layers::RepaintRequest::ScrollOffsetUpdateType::eNone,
          mozilla::layers::RepaintRequest::sHighestScrollOffsetUpdateType> {};
152

153
154
template <>
struct ParamTraits<mozilla::layers::OverscrollBehavior>
155
156
157
158
159
160
161
    : public ContiguousEnumSerializerInclusive<
          mozilla::layers::OverscrollBehavior,
          mozilla::layers::OverscrollBehavior::Auto,
          mozilla::layers::kHighestOverscrollBehavior> {};

template <>
struct ParamTraits<mozilla::layers::LayerHandle> {
162
163
164
165
166
  typedef mozilla::layers::LayerHandle paramType;

  static void Write(Message* msg, const paramType& param) {
    WriteParam(msg, param.mHandle);
  }
167
168
  static bool Read(const Message* msg, PickleIterator* iter,
                   paramType* result) {
169
170
171
172
    return ReadParam(msg, iter, &result->mHandle);
  }
};

173
174
template <>
struct ParamTraits<mozilla::layers::CompositableHandle> {
175
176
177
178
179
  typedef mozilla::layers::CompositableHandle paramType;

  static void Write(Message* msg, const paramType& param) {
    WriteParam(msg, param.mHandle);
  }
180
181
  static bool Read(const Message* msg, PickleIterator* iter,
                   paramType* result) {
182
183
184
185
186
187
    return ReadParam(msg, iter, &result->mHandle);
  }
};

template <>
struct ParamTraits<mozilla::layers::FrameMetrics>
188
    : BitfieldHelper<mozilla::layers::FrameMetrics> {
189
190
  typedef mozilla::layers::FrameMetrics paramType;

191
  static void Write(Message* aMsg, const paramType& aParam) {
192
193
194
195
196
197
198
199
200
    WriteParam(aMsg, aParam.mScrollId);
    WriteParam(aMsg, aParam.mPresShellResolution);
    WriteParam(aMsg, aParam.mCompositionBounds);
    WriteParam(aMsg, aParam.mDisplayPort);
    WriteParam(aMsg, aParam.mCriticalDisplayPort);
    WriteParam(aMsg, aParam.mScrollableRect);
    WriteParam(aMsg, aParam.mCumulativeResolution);
    WriteParam(aMsg, aParam.mDevPixelsPerCSSPixel);
    WriteParam(aMsg, aParam.mScrollOffset);
201
    WriteParam(aMsg, aParam.mBaseScrollOffset);
202
203
204
205
206
207
    WriteParam(aMsg, aParam.mZoom);
    WriteParam(aMsg, aParam.mScrollGeneration);
    WriteParam(aMsg, aParam.mSmoothScrollOffset);
    WriteParam(aMsg, aParam.mRootCompositionSize);
    WriteParam(aMsg, aParam.mDisplayPortMargins);
    WriteParam(aMsg, aParam.mPresShellId);
208
    WriteParam(aMsg, aParam.mLayoutViewport);
209
210
211
    WriteParam(aMsg, aParam.mExtraResolution);
    WriteParam(aMsg, aParam.mPaintRequestTime);
    WriteParam(aMsg, aParam.mScrollUpdateType);
212
213
    WriteParam(aMsg, aParam.mVisualViewportOffset);
    WriteParam(aMsg, aParam.mVisualScrollUpdateType);
214
    WriteParam(aMsg, aParam.mFixedLayerMargins);
215
    WriteParam(aMsg, aParam.mIsRootContent);
216
    WriteParam(aMsg, aParam.mIsRelative);
217
218
219
220
    WriteParam(aMsg, aParam.mDoSmoothScroll);
    WriteParam(aMsg, aParam.mIsScrollInfoLayer);
  }

221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
    return (
        ReadParam(aMsg, aIter, &aResult->mScrollId) &&
        ReadParam(aMsg, aIter, &aResult->mPresShellResolution) &&
        ReadParam(aMsg, aIter, &aResult->mCompositionBounds) &&
        ReadParam(aMsg, aIter, &aResult->mDisplayPort) &&
        ReadParam(aMsg, aIter, &aResult->mCriticalDisplayPort) &&
        ReadParam(aMsg, aIter, &aResult->mScrollableRect) &&
        ReadParam(aMsg, aIter, &aResult->mCumulativeResolution) &&
        ReadParam(aMsg, aIter, &aResult->mDevPixelsPerCSSPixel) &&
        ReadParam(aMsg, aIter, &aResult->mScrollOffset) &&
        ReadParam(aMsg, aIter, &aResult->mBaseScrollOffset) &&
        ReadParam(aMsg, aIter, &aResult->mZoom) &&
        ReadParam(aMsg, aIter, &aResult->mScrollGeneration) &&
        ReadParam(aMsg, aIter, &aResult->mSmoothScrollOffset) &&
        ReadParam(aMsg, aIter, &aResult->mRootCompositionSize) &&
        ReadParam(aMsg, aIter, &aResult->mDisplayPortMargins) &&
        ReadParam(aMsg, aIter, &aResult->mPresShellId) &&
240
        ReadParam(aMsg, aIter, &aResult->mLayoutViewport) &&
241
242
243
        ReadParam(aMsg, aIter, &aResult->mExtraResolution) &&
        ReadParam(aMsg, aIter, &aResult->mPaintRequestTime) &&
        ReadParam(aMsg, aIter, &aResult->mScrollUpdateType) &&
244
245
        ReadParam(aMsg, aIter, &aResult->mVisualViewportOffset) &&
        ReadParam(aMsg, aIter, &aResult->mVisualScrollUpdateType) &&
246
        ReadParam(aMsg, aIter, &aResult->mFixedLayerMargins) &&
247
248
249
250
251
252
253
        ReadBoolForBitfield(aMsg, aIter, aResult,
                            &paramType::SetIsRootContent) &&
        ReadBoolForBitfield(aMsg, aIter, aResult, &paramType::SetIsRelative) &&
        ReadBoolForBitfield(aMsg, aIter, aResult,
                            &paramType::SetDoSmoothScroll) &&
        ReadBoolForBitfield(aMsg, aIter, aResult,
                            &paramType::SetIsScrollInfoLayer));
254
255
256
  }
};

257
258
template <>
struct ParamTraits<mozilla::layers::RepaintRequest>
259
    : BitfieldHelper<mozilla::layers::RepaintRequest> {
260
261
  typedef mozilla::layers::RepaintRequest paramType;

262
  static void Write(Message* aMsg, const paramType& aParam) {
263
264
265
266
267
268
269
270
271
272
    WriteParam(aMsg, aParam.mScrollId);
    WriteParam(aMsg, aParam.mPresShellResolution);
    WriteParam(aMsg, aParam.mCompositionBounds);
    WriteParam(aMsg, aParam.mCumulativeResolution);
    WriteParam(aMsg, aParam.mDevPixelsPerCSSPixel);
    WriteParam(aMsg, aParam.mScrollOffset);
    WriteParam(aMsg, aParam.mZoom);
    WriteParam(aMsg, aParam.mScrollGeneration);
    WriteParam(aMsg, aParam.mDisplayPortMargins);
    WriteParam(aMsg, aParam.mPresShellId);
273
    WriteParam(aMsg, aParam.mLayoutViewport);
274
275
276
277
278
279
280
    WriteParam(aMsg, aParam.mExtraResolution);
    WriteParam(aMsg, aParam.mPaintRequestTime);
    WriteParam(aMsg, aParam.mScrollUpdateType);
    WriteParam(aMsg, aParam.mIsRootContent);
    WriteParam(aMsg, aParam.mIsScrollInfoLayer);
  }

281
282
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
283
284
285
286
287
288
289
290
291
292
    return (ReadParam(aMsg, aIter, &aResult->mScrollId) &&
            ReadParam(aMsg, aIter, &aResult->mPresShellResolution) &&
            ReadParam(aMsg, aIter, &aResult->mCompositionBounds) &&
            ReadParam(aMsg, aIter, &aResult->mCumulativeResolution) &&
            ReadParam(aMsg, aIter, &aResult->mDevPixelsPerCSSPixel) &&
            ReadParam(aMsg, aIter, &aResult->mScrollOffset) &&
            ReadParam(aMsg, aIter, &aResult->mZoom) &&
            ReadParam(aMsg, aIter, &aResult->mScrollGeneration) &&
            ReadParam(aMsg, aIter, &aResult->mDisplayPortMargins) &&
            ReadParam(aMsg, aIter, &aResult->mPresShellId) &&
293
            ReadParam(aMsg, aIter, &aResult->mLayoutViewport) &&
294
295
296
            ReadParam(aMsg, aIter, &aResult->mExtraResolution) &&
            ReadParam(aMsg, aIter, &aResult->mPaintRequestTime) &&
            ReadParam(aMsg, aIter, &aResult->mScrollUpdateType) &&
297
298
299
300
            ReadBoolForBitfield(aMsg, aIter, aResult,
                                &paramType::SetIsRootContent) &&
            ReadBoolForBitfield(aMsg, aIter, aResult,
                                &paramType::SetIsScrollInfoLayer));
301
302
303
  }
};

304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
template <>
struct ParamTraits<nsSize> {
  typedef nsSize paramType;

  static void Write(Message* aMsg, const paramType& aParam) {
    WriteParam(aMsg, aParam.width);
    WriteParam(aMsg, aParam.height);
  }

  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
    return ReadParam(aMsg, aIter, &aResult->width) &&
           ReadParam(aMsg, aIter, &aResult->height);
  }
};

template <>
struct ParamTraits<mozilla::layers::ScrollSnapInfo::ScrollSnapRange> {
  typedef mozilla::layers::ScrollSnapInfo::ScrollSnapRange paramType;

  static void Write(Message* aMsg, const paramType& aParam) {
    WriteParam(aMsg, aParam.mStart);
    WriteParam(aMsg, aParam.mEnd);
  }

  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
    return ReadParam(aMsg, aIter, &aResult->mStart) &&
           ReadParam(aMsg, aIter, &aResult->mEnd);
  }
};

336
template <>
337
struct ParamTraits<mozilla::layers::ScrollSnapInfo> {
338
339
  typedef mozilla::layers::ScrollSnapInfo paramType;

340
  static void Write(Message* aMsg, const paramType& aParam) {
341
342
    WriteParam(aMsg, aParam.mScrollSnapStrictnessX);
    WriteParam(aMsg, aParam.mScrollSnapStrictnessY);
343
344
    WriteParam(aMsg, aParam.mSnapPositionX);
    WriteParam(aMsg, aParam.mSnapPositionY);
345
346
347
    WriteParam(aMsg, aParam.mXRangeWiderThanSnapport);
    WriteParam(aMsg, aParam.mYRangeWiderThanSnapport);
    WriteParam(aMsg, aParam.mSnapportSize);
348
349
  }

350
351
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
352
353
    return (ReadParam(aMsg, aIter, &aResult->mScrollSnapStrictnessX) &&
            ReadParam(aMsg, aIter, &aResult->mScrollSnapStrictnessY) &&
354
            ReadParam(aMsg, aIter, &aResult->mSnapPositionX) &&
355
356
357
358
            ReadParam(aMsg, aIter, &aResult->mSnapPositionY) &&
            ReadParam(aMsg, aIter, &aResult->mXRangeWiderThanSnapport) &&
            ReadParam(aMsg, aIter, &aResult->mYRangeWiderThanSnapport) &&
            ReadParam(aMsg, aIter, &aResult->mSnapportSize));
359
360
361
  }
};

362
template <>
363
struct ParamTraits<mozilla::layers::OverscrollBehaviorInfo> {
364
365
366
367
368
  // Not using PlainOldDataSerializer so we get enum validation
  // for the members.

  typedef mozilla::layers::OverscrollBehaviorInfo paramType;

369
  static void Write(Message* aMsg, const paramType& aParam) {
370
371
372
373
    WriteParam(aMsg, aParam.mBehaviorX);
    WriteParam(aMsg, aParam.mBehaviorY);
  }

374
375
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
376
377
378
379
380
    return (ReadParam(aMsg, aIter, &aResult->mBehaviorX) &&
            ReadParam(aMsg, aIter, &aResult->mBehaviorY));
  }
};

381
template <>
382
struct ParamTraits<mozilla::layers::LayerClip> {
383
384
  typedef mozilla::layers::LayerClip paramType;

385
  static void Write(Message* aMsg, const paramType& aParam) {
386
387
388
389
    WriteParam(aMsg, aParam.mClipRect);
    WriteParam(aMsg, aParam.mMaskLayerIndex);
  }

390
391
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
392
393
394
395
396
397
398
    return (ReadParam(aMsg, aIter, &aResult->mClipRect) &&
            ReadParam(aMsg, aIter, &aResult->mMaskLayerIndex));
  }
};

template <>
struct ParamTraits<mozilla::layers::ScrollMetadata>
399
    : BitfieldHelper<mozilla::layers::ScrollMetadata> {
400
401
  typedef mozilla::layers::ScrollMetadata paramType;

402
  static void Write(Message* aMsg, const paramType& aParam) {
403
404
405
406
407
408
409
410
411
412
    WriteParam(aMsg, aParam.mMetrics);
    WriteParam(aMsg, aParam.mSnapInfo);
    WriteParam(aMsg, aParam.mScrollParentId);
    WriteParam(aMsg, aParam.mBackgroundColor);
    WriteParam(aMsg, aParam.GetContentDescription());
    WriteParam(aMsg, aParam.mLineScrollAmount);
    WriteParam(aMsg, aParam.mPageScrollAmount);
    WriteParam(aMsg, aParam.mScrollClip);
    WriteParam(aMsg, aParam.mHasScrollgrab);
    WriteParam(aMsg, aParam.mIsLayersIdRoot);
413
    WriteParam(aMsg, aParam.mIsAutoDirRootContentRTL);
414
    WriteParam(aMsg, aParam.mForceDisableApz);
415
    WriteParam(aMsg, aParam.mResolutionUpdated);
416
    WriteParam(aMsg, aParam.mDisregardedDirection);
417
    WriteParam(aMsg, aParam.mOverscrollBehavior);
418
419
  }

420
421
  static bool ReadContentDescription(const Message* aMsg, PickleIterator* aIter,
                                     paramType* aResult) {
422
423
424
425
426
427
428
429
    nsCString str;
    if (!ReadParam(aMsg, aIter, &str)) {
      return false;
    }
    aResult->SetContentDescription(str);
    return true;
  }

430
431
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
432
433
434
435
436
437
438
439
    return (ReadParam(aMsg, aIter, &aResult->mMetrics) &&
            ReadParam(aMsg, aIter, &aResult->mSnapInfo) &&
            ReadParam(aMsg, aIter, &aResult->mScrollParentId) &&
            ReadParam(aMsg, aIter, &aResult->mBackgroundColor) &&
            ReadContentDescription(aMsg, aIter, aResult) &&
            ReadParam(aMsg, aIter, &aResult->mLineScrollAmount) &&
            ReadParam(aMsg, aIter, &aResult->mPageScrollAmount) &&
            ReadParam(aMsg, aIter, &aResult->mScrollClip) &&
440
            ReadBoolForBitfield(aMsg, aIter, aResult,
441
442
443
444
445
446
447
                                &paramType::SetHasScrollgrab) &&
            ReadBoolForBitfield(aMsg, aIter, aResult,
                                &paramType::SetIsLayersIdRoot) &&
            ReadBoolForBitfield(aMsg, aIter, aResult,
                                &paramType::SetIsAutoDirRootContentRTL) &&
            ReadBoolForBitfield(aMsg, aIter, aResult,
                                &paramType::SetForceDisableApz) &&
448
449
            ReadBoolForBitfield(aMsg, aIter, aResult,
                                &paramType::SetResolutionUpdated) &&
450
451
            ReadParam(aMsg, aIter, &aResult->mDisregardedDirection) &&
            ReadParam(aMsg, aIter, &aResult->mOverscrollBehavior));
452
453
454
  }
};

455
456
template <>
struct ParamTraits<mozilla::layers::TextureFactoryIdentifier> {
457
458
  typedef mozilla::layers::TextureFactoryIdentifier paramType;

459
  static void Write(Message* aMsg, const paramType& aParam) {
460
461
462
    WriteParam(aMsg, aParam.mParentBackend);
    WriteParam(aMsg, aParam.mParentProcessType);
    WriteParam(aMsg, aParam.mMaxTextureSize);
463
    WriteParam(aMsg, aParam.mSupportsTextureDirectMapping);
464
    WriteParam(aMsg, aParam.mCompositorUseANGLE);
465
    WriteParam(aMsg, aParam.mCompositorUseDComp);
466
    WriteParam(aMsg, aParam.mUseCompositorWnd);
467
468
469
    WriteParam(aMsg, aParam.mSupportsTextureBlitting);
    WriteParam(aMsg, aParam.mSupportsPartialUploads);
    WriteParam(aMsg, aParam.mSupportsComponentAlpha);
470
    WriteParam(aMsg, aParam.mUsingAdvancedLayers);
471
472
473
    WriteParam(aMsg, aParam.mSyncHandle);
  }

474
475
476
477
478
479
480
481
482
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
    bool result =
        ReadParam(aMsg, aIter, &aResult->mParentBackend) &&
        ReadParam(aMsg, aIter, &aResult->mParentProcessType) &&
        ReadParam(aMsg, aIter, &aResult->mMaxTextureSize) &&
        ReadParam(aMsg, aIter, &aResult->mSupportsTextureDirectMapping) &&
        ReadParam(aMsg, aIter, &aResult->mCompositorUseANGLE) &&
        ReadParam(aMsg, aIter, &aResult->mCompositorUseDComp) &&
483
        ReadParam(aMsg, aIter, &aResult->mUseCompositorWnd) &&
484
485
486
487
488
        ReadParam(aMsg, aIter, &aResult->mSupportsTextureBlitting) &&
        ReadParam(aMsg, aIter, &aResult->mSupportsPartialUploads) &&
        ReadParam(aMsg, aIter, &aResult->mSupportsComponentAlpha) &&
        ReadParam(aMsg, aIter, &aResult->mUsingAdvancedLayers) &&
        ReadParam(aMsg, aIter, &aResult->mSyncHandle);
489
490
491
492
    return result;
  }
};

493
494
template <>
struct ParamTraits<mozilla::layers::TextureInfo> {
495
496
  typedef mozilla::layers::TextureInfo paramType;

497
  static void Write(Message* aMsg, const paramType& aParam) {
498
499
500
501
    WriteParam(aMsg, aParam.mCompositableType);
    WriteParam(aMsg, aParam.mTextureFlags);
  }

502
503
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
504
505
506
507
508
509
510
    return ReadParam(aMsg, aIter, &aResult->mCompositableType) &&
           ReadParam(aMsg, aIter, &aResult->mTextureFlags);
  }
};

template <>
struct ParamTraits<mozilla::layers::CompositableType>
511
512
513
514
    : public ContiguousEnumSerializer<
          mozilla::layers::CompositableType,
          mozilla::layers::CompositableType::UNKNOWN,
          mozilla::layers::CompositableType::COUNT> {};
515
516

template <>
517
struct ParamTraits<mozilla::layers::ScrollableLayerGuid> {
518
519
  typedef mozilla::layers::ScrollableLayerGuid paramType;

520
  static void Write(Message* aMsg, const paramType& aParam) {
521
522
523
524
525
    WriteParam(aMsg, aParam.mLayersId);
    WriteParam(aMsg, aParam.mPresShellId);
    WriteParam(aMsg, aParam.mScrollId);
  }

526
527
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
528
529
530
531
532
533
    return (ReadParam(aMsg, aIter, &aResult->mLayersId) &&
            ReadParam(aMsg, aIter, &aResult->mPresShellId) &&
            ReadParam(aMsg, aIter, &aResult->mScrollId));
  }
};

534
535
536
537
538
539
540
541
542
543
544
545
546
template <>
struct ParamTraits<nsEventStatus>
    : public ContiguousEnumSerializer<nsEventStatus, nsEventStatus_eIgnore,
                                      nsEventStatus_eSentinel> {};

template <>
struct ParamTraits<mozilla::layers::APZEventResult> {
  typedef mozilla::layers::APZEventResult paramType;

  static void Write(Message* aMsg, const paramType& aParam) {
    WriteParam(aMsg, aParam.mStatus);
    WriteParam(aMsg, aParam.mTargetGuid);
    WriteParam(aMsg, aParam.mInputBlockId);
547
    WriteParam(aMsg, aParam.mHitRegionWithApzAwareListeners);
548
    WriteParam(aMsg, aParam.mTargetIsRoot);
549
550
551
552
553
554
  }

  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
    return (ReadParam(aMsg, aIter, &aResult->mStatus) &&
            ReadParam(aMsg, aIter, &aResult->mTargetGuid) &&
555
            ReadParam(aMsg, aIter, &aResult->mInputBlockId) &&
556
557
            ReadParam(aMsg, aIter, &aResult->mHitRegionWithApzAwareListeners) &&
            ReadParam(aMsg, aIter, &aResult->mTargetIsRoot));
558
559
560
  }
};

561
template <>
562
struct ParamTraits<mozilla::layers::ZoomConstraints> {
563
564
  typedef mozilla::layers::ZoomConstraints paramType;

565
  static void Write(Message* aMsg, const paramType& aParam) {
566
567
568
569
570
571
    WriteParam(aMsg, aParam.mAllowZoom);
    WriteParam(aMsg, aParam.mAllowDoubleTapZoom);
    WriteParam(aMsg, aParam.mMinZoom);
    WriteParam(aMsg, aParam.mMaxZoom);
  }

572
573
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
574
575
576
577
578
579
580
581
    return (ReadParam(aMsg, aIter, &aResult->mAllowZoom) &&
            ReadParam(aMsg, aIter, &aResult->mAllowDoubleTapZoom) &&
            ReadParam(aMsg, aIter, &aResult->mMinZoom) &&
            ReadParam(aMsg, aIter, &aResult->mMaxZoom));
  }
};

template <>
582
struct ParamTraits<mozilla::layers::EventRegions> {
583
584
  typedef mozilla::layers::EventRegions paramType;

585
  static void Write(Message* aMsg, const paramType& aParam) {
586
587
588
589
590
    WriteParam(aMsg, aParam.mHitRegion);
    WriteParam(aMsg, aParam.mDispatchToContentHitRegion);
    WriteParam(aMsg, aParam.mNoActionRegion);
    WriteParam(aMsg, aParam.mHorizontalPanRegion);
    WriteParam(aMsg, aParam.mVerticalPanRegion);
591
    WriteParam(aMsg, aParam.mDTCRequiresTargetConfirmation);
592
593
  }

594
595
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
596
597
598
599
    return (ReadParam(aMsg, aIter, &aResult->mHitRegion) &&
            ReadParam(aMsg, aIter, &aResult->mDispatchToContentHitRegion) &&
            ReadParam(aMsg, aIter, &aResult->mNoActionRegion) &&
            ReadParam(aMsg, aIter, &aResult->mHorizontalPanRegion) &&
600
601
            ReadParam(aMsg, aIter, &aResult->mVerticalPanRegion) &&
            ReadParam(aMsg, aIter, &aResult->mDTCRequiresTargetConfirmation));
602
603
604
  }
};

605
template <>
606
struct ParamTraits<mozilla::layers::FocusTarget::ScrollTargets> {
607
608
  typedef mozilla::layers::FocusTarget::ScrollTargets paramType;

609
  static void Write(Message* aMsg, const paramType& aParam) {
610
611
612
613
    WriteParam(aMsg, aParam.mHorizontal);
    WriteParam(aMsg, aParam.mVertical);
  }

614
615
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
616
    return ReadParam(aMsg, aIter, &aResult->mHorizontal) &&
617
           ReadParam(aMsg, aIter, &aResult->mVertical);
618
619
620
  }
};

621
622
template <>
struct ParamTraits<mozilla::layers::FocusTarget::NoFocusTarget>
623
624
    : public EmptyStructSerializer<
          mozilla::layers::FocusTarget::NoFocusTarget> {};
625

626
template <>
627
struct ParamTraits<mozilla::layers::FocusTarget> {
628
629
  typedef mozilla::layers::FocusTarget paramType;

630
  static void Write(Message* aMsg, const paramType& aParam) {
631
    WriteParam(aMsg, aParam.mSequenceNumber);
632
    WriteParam(aMsg, aParam.mFocusHasKeyEventListeners);
633
    WriteParam(aMsg, aParam.mData);
634
635
  }

636
637
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
638
639
    if (!ReadParam(aMsg, aIter, &aResult->mSequenceNumber) ||
        !ReadParam(aMsg, aIter, &aResult->mFocusHasKeyEventListeners) ||
640
        !ReadParam(aMsg, aIter, &aResult->mData)) {
641
642
643
644
645
646
      return false;
    }
    return true;
  }
};

647
template <>
648
649
650
651
652
653
654
655
struct ParamTraits<
    mozilla::layers::KeyboardScrollAction::KeyboardScrollActionType>
    : public ContiguousEnumSerializerInclusive<
          mozilla::layers::KeyboardScrollAction::KeyboardScrollActionType,
          mozilla::layers::KeyboardScrollAction::KeyboardScrollActionType::
              eScrollCharacter,
          mozilla::layers::KeyboardScrollAction::
              sHighestKeyboardScrollActionType> {};
656
657

template <>
658
struct ParamTraits<mozilla::layers::KeyboardScrollAction> {
659
660
  typedef mozilla::layers::KeyboardScrollAction paramType;

661
  static void Write(Message* aMsg, const paramType& aParam) {
662
663
664
665
    WriteParam(aMsg, aParam.mType);
    WriteParam(aMsg, aParam.mForward);
  }

666
667
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
668
669
670
671
672
    return ReadParam(aMsg, aIter, &aResult->mType) &&
           ReadParam(aMsg, aIter, &aResult->mForward);
  }
};

673
template <>
674
struct ParamTraits<mozilla::layers::KeyboardShortcut> {
675
676
  typedef mozilla::layers::KeyboardShortcut paramType;

677
  static void Write(Message* aMsg, const paramType& aParam) {
678
679
680
681
682
683
684
685
686
    WriteParam(aMsg, aParam.mAction);
    WriteParam(aMsg, aParam.mKeyCode);
    WriteParam(aMsg, aParam.mCharCode);
    WriteParam(aMsg, aParam.mModifiers);
    WriteParam(aMsg, aParam.mModifiersMask);
    WriteParam(aMsg, aParam.mEventType);
    WriteParam(aMsg, aParam.mDispatchToContent);
  }

687
688
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
689
690
691
692
693
694
695
696
697
698
    return ReadParam(aMsg, aIter, &aResult->mAction) &&
           ReadParam(aMsg, aIter, &aResult->mKeyCode) &&
           ReadParam(aMsg, aIter, &aResult->mCharCode) &&
           ReadParam(aMsg, aIter, &aResult->mModifiers) &&
           ReadParam(aMsg, aIter, &aResult->mModifiersMask) &&
           ReadParam(aMsg, aIter, &aResult->mEventType) &&
           ReadParam(aMsg, aIter, &aResult->mDispatchToContent);
  }
};

699
template <>
700
struct ParamTraits<mozilla::layers::KeyboardMap> {
701
702
  typedef mozilla::layers::KeyboardMap paramType;

703
  static void Write(Message* aMsg, const paramType& aParam) {
704
705
706
    WriteParam(aMsg, aParam.Shortcuts());
  }

707
708
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
709
710
711
712
    nsTArray<mozilla::layers::KeyboardShortcut> shortcuts;
    if (!ReadParam(aMsg, aIter, &shortcuts)) {
      return false;
    }
713
    *aResult = mozilla::layers::KeyboardMap(std::move(shortcuts));
714
715
716
717
    return true;
  }
};

718
template <>
719
720
721
722
723
struct ParamTraits<mozilla::layers::GeckoContentController_TapType>
    : public ContiguousEnumSerializerInclusive<
          mozilla::layers::GeckoContentController_TapType,
          mozilla::layers::GeckoContentController_TapType::eSingleTap,
          mozilla::layers::kHighestGeckoContentController_TapType> {};
724
725

template <>
726
struct ParamTraits<mozilla::layers::GeckoContentController_APZStateChange>
727
    : public ContiguousEnumSerializerInclusive<
728
729
730
731
          mozilla::layers::GeckoContentController_APZStateChange,
          mozilla::layers::GeckoContentController_APZStateChange::
              eTransformBegin,
          mozilla::layers::kHighestGeckoContentController_APZStateChange> {};
732

733
template <>
734
struct ParamTraits<mozilla::layers::EventRegionsOverride>
735
736
737
738
739
740
    : public BitFlagsEnumSerializer<
          mozilla::layers::EventRegionsOverride,
          mozilla::layers::EventRegionsOverride::ALL_BITS> {};

template <>
struct ParamTraits<mozilla::layers::AsyncDragMetrics> {
741
742
  typedef mozilla::layers::AsyncDragMetrics paramType;

743
  static void Write(Message* aMsg, const paramType& aParam) {
744
745
746
747
748
749
750
    WriteParam(aMsg, aParam.mViewId);
    WriteParam(aMsg, aParam.mPresShellId);
    WriteParam(aMsg, aParam.mDragStartSequenceNumber);
    WriteParam(aMsg, aParam.mScrollbarDragOffset);
    WriteParam(aMsg, aParam.mDirection);
  }

751
752
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
753
754
755
756
757
758
759
760
761
    return (ReadParam(aMsg, aIter, &aResult->mViewId) &&
            ReadParam(aMsg, aIter, &aResult->mPresShellId) &&
            ReadParam(aMsg, aIter, &aResult->mDragStartSequenceNumber) &&
            ReadParam(aMsg, aIter, &aResult->mScrollbarDragOffset) &&
            ReadParam(aMsg, aIter, &aResult->mDirection));
  }
};

template <>
762
struct ParamTraits<mozilla::layers::CompositorOptions> {
763
764
765
766
767
  typedef mozilla::layers::CompositorOptions paramType;

  static void Write(Message* aMsg, const paramType& aParam) {
    WriteParam(aMsg, aParam.mUseAPZ);
    WriteParam(aMsg, aParam.mUseWebRender);
768
    WriteParam(aMsg, aParam.mUseAdvancedLayers);
769
    WriteParam(aMsg, aParam.mInitiallyPaused);
770
771
  }

772
773
774
775
776
777
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
    return ReadParam(aMsg, aIter, &aResult->mUseAPZ) &&
           ReadParam(aMsg, aIter, &aResult->mUseWebRender) &&
           ReadParam(aMsg, aIter, &aResult->mUseAdvancedLayers) &&
           ReadParam(aMsg, aIter, &aResult->mInitiallyPaused);
778
779
780
  }
};

781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
template <>
struct ParamTraits<mozilla::layers::ScrollbarLayerType>
    : public ContiguousEnumSerializerInclusive<
          mozilla::layers::ScrollbarLayerType,
          mozilla::layers::ScrollbarLayerType::None,
          mozilla::layers::kHighestScrollbarLayerType> {};

template <>
struct ParamTraits<mozilla::layers::ScrollbarData> {
  typedef mozilla::layers::ScrollbarData paramType;

  static void Write(Message* aMsg, const paramType& aParam) {
    WriteParam(aMsg, aParam.mDirection);
    WriteParam(aMsg, aParam.mScrollbarLayerType);
    WriteParam(aMsg, aParam.mThumbRatio);
    WriteParam(aMsg, aParam.mThumbStart);
    WriteParam(aMsg, aParam.mThumbLength);
    WriteParam(aMsg, aParam.mThumbIsAsyncDraggable);
    WriteParam(aMsg, aParam.mScrollTrackStart);
    WriteParam(aMsg, aParam.mScrollTrackLength);
    WriteParam(aMsg, aParam.mTargetViewId);
  }

  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
    return ReadParam(aMsg, aIter, &aResult->mDirection) &&
           ReadParam(aMsg, aIter, &aResult->mScrollbarLayerType) &&
           ReadParam(aMsg, aIter, &aResult->mThumbRatio) &&
           ReadParam(aMsg, aIter, &aResult->mThumbStart) &&
           ReadParam(aMsg, aIter, &aResult->mThumbLength) &&
           ReadParam(aMsg, aIter, &aResult->mThumbIsAsyncDraggable) &&
           ReadParam(aMsg, aIter, &aResult->mScrollTrackStart) &&
           ReadParam(aMsg, aIter, &aResult->mScrollTrackLength) &&
           ReadParam(aMsg, aIter, &aResult->mTargetViewId);
  }
};

818
template <>
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
struct ParamTraits<mozilla::layers::SimpleLayerAttributes::FixedPositionData>
    : public PlainOldDataSerializer<
          mozilla::layers::SimpleLayerAttributes::FixedPositionData> {};

template <>
struct ParamTraits<mozilla::layers::SimpleLayerAttributes::StickyPositionData>
    : public PlainOldDataSerializer<
          mozilla::layers::SimpleLayerAttributes::StickyPositionData> {};

template <>
struct ParamTraits<mozilla::layers::SimpleLayerAttributes> {
  typedef mozilla::layers::SimpleLayerAttributes paramType;

  static void Write(Message* aMsg, const paramType& aParam) {
    WriteParam(aMsg, aParam.mTransform);
    WriteParam(aMsg, aParam.mTransformIsPerspective);
    WriteParam(aMsg, aParam.mScrolledClip);
    WriteParam(aMsg, aParam.mPostXScale);
    WriteParam(aMsg, aParam.mPostYScale);
    WriteParam(aMsg, aParam.mContentFlags);
    WriteParam(aMsg, aParam.mOpacity);
    WriteParam(aMsg, aParam.mIsFixedPosition);
    WriteParam(aMsg, aParam.mIsAsyncZoomContainerForViewId);
    WriteParam(aMsg, aParam.mScrollbarData);
    WriteParam(aMsg, aParam.mMixBlendMode);
    WriteParam(aMsg, aParam.mForceIsolatedGroup);
    WriteParam(aMsg, aParam.mFixedPositionData);
    WriteParam(aMsg, aParam.mStickyPositionData);
  }

  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
    return ReadParam(aMsg, aIter, &aResult->mTransform) &&
           ReadParam(aMsg, aIter, &aResult->mTransformIsPerspective) &&
           ReadParam(aMsg, aIter, &aResult->mScrolledClip) &&
           ReadParam(aMsg, aIter, &aResult->mPostXScale) &&
           ReadParam(aMsg, aIter, &aResult->mPostYScale) &&
           ReadParam(aMsg, aIter, &aResult->mContentFlags) &&
           ReadParam(aMsg, aIter, &aResult->mOpacity) &&
           ReadParam(aMsg, aIter, &aResult->mIsFixedPosition) &&
           ReadParam(aMsg, aIter, &aResult->mIsAsyncZoomContainerForViewId) &&
           ReadParam(aMsg, aIter, &aResult->mScrollbarData) &&
           ReadParam(aMsg, aIter, &aResult->mMixBlendMode) &&
           ReadParam(aMsg, aIter, &aResult->mForceIsolatedGroup) &&
           ReadParam(aMsg, aIter, &aResult->mFixedPositionData) &&
           ReadParam(aMsg, aIter, &aResult->mStickyPositionData);
  }
};
867

868
869
template <>
struct ParamTraits<mozilla::layers::ScrollUpdateInfo>
870
    : public PlainOldDataSerializer<mozilla::layers::ScrollUpdateInfo> {};
871

872
873
874
875
876
877
878
879
template <>
struct ParamTraits<mozilla::layers::CompositionPayloadType>
    : public ContiguousEnumSerializerInclusive<
          mozilla::layers::CompositionPayloadType,
          mozilla::layers::CompositionPayloadType::eKeyPress,
          mozilla::layers::kHighestCompositionPayloadType> {};

template <>
880
struct ParamTraits<mozilla::layers::CompositionPayload> {
881
882
883
884
885
886
887
  typedef mozilla::layers::CompositionPayload paramType;

  static void Write(Message* aMsg, const paramType& aParam) {
    WriteParam(aMsg, aParam.mType);
    WriteParam(aMsg, aParam.mTimeStamp);
  }

888
889
  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
890
891
892
893
    return ReadParam(aMsg, aIter, &aResult->mType) &&
           ReadParam(aMsg, aIter, &aResult->mTimeStamp);
  }
};
894

895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
template <>
struct ParamTraits<mozilla::RayReferenceData> {
  typedef mozilla::RayReferenceData paramType;

  static void Write(Message* aMsg, const paramType& aParam) {
    WriteParam(aMsg, aParam.mInitialPosition);
    WriteParam(aMsg, aParam.mContainingBlockRect);
  }

  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
    return (ReadParam(aMsg, aIter, &aResult->mInitialPosition) &&
            ReadParam(aMsg, aIter, &aResult->mContainingBlockRect));
  }
};

#define IMPL_PARAMTRAITS_BY_SERDE(type_)                                    \
  template <>                                                               \
  struct ParamTraits<mozilla::type_> {                                      \
    typedef mozilla::type_ paramType;                                       \
    static void Write(Message* aMsg, const paramType& aParam) {             \
916
      mozilla::ipc::ByteBuf v;                                              \
917
918
      mozilla::DebugOnly<bool> rv = Servo_##type_##_Serialize(&aParam, &v); \
      MOZ_ASSERT(rv, "Serialize ##type_## failed");                         \
919
      WriteParam(aMsg, std::move(v));                                       \
920
921
922
923
924
925
926
927
    }                                                                       \
    static bool Read(const Message* aMsg, PickleIterator* aIter,            \
                     paramType* aResult) {                                  \
      mozilla::ipc::ByteBuf in;                                             \
      bool rv = ReadParam(aMsg, aIter, &in);                                \
      if (!rv) {                                                            \
        return false;                                                       \
      }                                                                     \
928
      return in.mData && Servo_##type_##_Deserialize(&in, aResult);         \
929
930
931
932
    }                                                                       \
  };

IMPL_PARAMTRAITS_BY_SERDE(LengthPercentage)
933
IMPL_PARAMTRAITS_BY_SERDE(StyleOffsetPath)
934
935
IMPL_PARAMTRAITS_BY_SERDE(StyleOffsetRotate)
IMPL_PARAMTRAITS_BY_SERDE(StylePositionOrAuto)
936
937
938
IMPL_PARAMTRAITS_BY_SERDE(StyleRotate)
IMPL_PARAMTRAITS_BY_SERDE(StyleScale)
IMPL_PARAMTRAITS_BY_SERDE(StyleTranslate)
939
IMPL_PARAMTRAITS_BY_SERDE(StyleTransform)
940

941
942
943
} /* namespace IPC */

#endif /* mozilla_layers_LayersMessageUtils */