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/. */
7 #ifndef __GFXMESSAGEUTILS_H__
8 #define __GFXMESSAGEUTILS_H__
10 #include "FilterSupport.h"
11 #include "ImageTypes.h"
12 #include "RegionBuilder.h"
13 #include "chrome/common/ipc_message_utils.h"
14 #include "gfxFeature.h"
15 #include "gfxFontUtils.h"
16 #include "gfxFallback.h"
19 #include "gfxTelemetry.h"
21 #include "ipc/EnumSerializer.h"
22 #include "ipc/IPCMessageUtilsSpecializations.h"
23 #include "mozilla/gfx/CrossProcessPaint.h"
24 #include "mozilla/gfx/FileHandleWrapper.h"
25 #include "mozilla/gfx/Matrix.h"
26 #include "mozilla/gfx/ScaleFactor.h"
27 #include "mozilla/gfx/ScaleFactors2D.h"
28 #include "SharedFontList.h"
31 #include "mozilla/Array.h"
32 #include "mozilla/ipc/FileDescriptor.h"
33 #include "mozilla/ipc/IPDLParamTraits.h"
34 #include "mozilla/ipc/ProtocolMessageUtils.h"
35 #include "mozilla/ipc/ProtocolUtils.h"
36 #include "mozilla/ipc/ShmemMessageUtils.h"
41 # pragma warning(disable : 4800)
46 typedef gfxImageFormat PixelFormat
;
48 } // namespace mozilla
53 struct ParamTraits
<mozilla::gfx::Matrix
> {
54 typedef mozilla::gfx::Matrix paramType
;
56 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
57 WriteParam(aWriter
, aParam
._11
);
58 WriteParam(aWriter
, aParam
._12
);
59 WriteParam(aWriter
, aParam
._21
);
60 WriteParam(aWriter
, aParam
._22
);
61 WriteParam(aWriter
, aParam
._31
);
62 WriteParam(aWriter
, aParam
._32
);
65 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
66 if (ReadParam(aReader
, &aResult
->_11
) &&
67 ReadParam(aReader
, &aResult
->_12
) &&
68 ReadParam(aReader
, &aResult
->_21
) &&
69 ReadParam(aReader
, &aResult
->_22
) &&
70 ReadParam(aReader
, &aResult
->_31
) && ReadParam(aReader
, &aResult
->_32
))
77 template <class SourceUnits
, class TargetUnits
, class T
>
78 struct ParamTraits
<mozilla::gfx::Matrix4x4Typed
<SourceUnits
, TargetUnits
, T
>> {
79 typedef mozilla::gfx::Matrix4x4Typed
<SourceUnits
, TargetUnits
, T
> paramType
;
81 static void Write(MessageWriter
* writer
, const paramType
& param
) {
82 #define Wr(_f) WriteParam(writer, param._f)
102 static bool Read(MessageReader
* reader
, paramType
* result
) {
103 #define Rd(_f) ReadParam(reader, &result->_f)
104 return (Rd(_11
) && Rd(_12
) && Rd(_13
) && Rd(_14
) && Rd(_21
) && Rd(_22
) &&
105 Rd(_23
) && Rd(_24
) && Rd(_31
) && Rd(_32
) && Rd(_33
) && Rd(_34
) &&
106 Rd(_41
) && Rd(_42
) && Rd(_43
) && Rd(_44
));
112 struct ParamTraits
<mozilla::gfx::Matrix5x4
> {
113 typedef mozilla::gfx::Matrix5x4 paramType
;
115 static void Write(MessageWriter
* writer
, const paramType
& param
) {
116 #define Wr(_f) WriteParam(writer, param._f)
140 static bool Read(MessageReader
* reader
, paramType
* result
) {
141 #define Rd(_f) ReadParam(reader, &result->_f)
142 return (Rd(_11
) && Rd(_12
) && Rd(_13
) && Rd(_14
) && Rd(_21
) && Rd(_22
) &&
143 Rd(_23
) && Rd(_24
) && Rd(_31
) && Rd(_32
) && Rd(_33
) && Rd(_34
) &&
144 Rd(_41
) && Rd(_42
) && Rd(_43
) && Rd(_44
) && Rd(_51
) && Rd(_52
) &&
151 struct ParamTraits
<gfxPoint
> {
152 typedef gfxPoint paramType
;
154 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
155 WriteParam(aWriter
, aParam
.x
.value
);
156 WriteParam(aWriter
, aParam
.y
.value
);
159 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
160 return (ReadParam(aReader
, &aResult
->x
.value
) &&
161 ReadParam(aReader
, &aResult
->y
.value
));
166 struct ParamTraits
<gfxSize
> {
167 typedef gfxSize paramType
;
169 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
170 WriteParam(aWriter
, aParam
.width
);
171 WriteParam(aWriter
, aParam
.height
);
174 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
175 if (ReadParam(aReader
, &aResult
->width
) &&
176 ReadParam(aReader
, &aResult
->height
))
184 struct ParamTraits
<gfxRect
> {
185 typedef gfxRect paramType
;
187 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
188 WriteParam(aWriter
, aParam
.X());
189 WriteParam(aWriter
, aParam
.Y());
190 WriteParam(aWriter
, aParam
.Width());
191 WriteParam(aWriter
, aParam
.Height());
194 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
195 auto x
= aResult
->X();
196 auto y
= aResult
->Y();
197 auto w
= aResult
->Width();
198 auto h
= aResult
->Height();
200 bool retVal
= (ReadParam(aReader
, &x
) && ReadParam(aReader
, &y
) &&
201 ReadParam(aReader
, &w
) && ReadParam(aReader
, &h
));
202 aResult
->SetRect(x
, y
, w
, h
);
208 struct ParamTraits
<gfxContentType
>
209 : public ContiguousEnumSerializer
<gfxContentType
, gfxContentType::COLOR
,
210 gfxContentType::SENTINEL
> {};
213 struct ParamTraits
<gfxSurfaceType
>
214 : public ContiguousEnumSerializer
<gfxSurfaceType
, gfxSurfaceType::Image
,
215 gfxSurfaceType::Max
> {};
218 struct ParamTraits
<mozilla::gfx::SamplingFilter
>
219 : public ContiguousEnumSerializer
<mozilla::gfx::SamplingFilter
,
220 mozilla::gfx::SamplingFilter::GOOD
,
221 mozilla::gfx::SamplingFilter::SENTINEL
> {
225 struct ParamTraits
<mozilla::gfx::BackendType
>
226 : public ContiguousEnumSerializer
<mozilla::gfx::BackendType
,
227 mozilla::gfx::BackendType::NONE
,
228 mozilla::gfx::BackendType::BACKEND_LAST
> {
232 struct ParamTraits
<mozilla::gfx::Feature
>
233 : public ContiguousEnumSerializer
<mozilla::gfx::Feature
,
234 mozilla::gfx::Feature::HW_COMPOSITING
,
235 mozilla::gfx::Feature::NumValues
> {};
238 struct ParamTraits
<mozilla::gfx::Fallback
>
239 : public ContiguousEnumSerializer
<
240 mozilla::gfx::Fallback
,
241 mozilla::gfx::Fallback::NO_CONSTANT_BUFFER_OFFSETTING
,
242 mozilla::gfx::Fallback::NumValues
> {};
245 struct ParamTraits
<mozilla::gfx::FeatureStatus
>
246 : public ContiguousEnumSerializer
<mozilla::gfx::FeatureStatus
,
247 mozilla::gfx::FeatureStatus::Unused
,
248 mozilla::gfx::FeatureStatus::LAST
> {};
251 struct ParamTraits
<mozilla::gfx::LightType
>
252 : public ContiguousEnumSerializer
<mozilla::gfx::LightType
,
253 mozilla::gfx::LightType::None
,
254 mozilla::gfx::LightType::Max
> {};
257 struct ParamTraits
<mozilla::gfx::ColorSpace
>
258 : public ContiguousEnumSerializer
<mozilla::gfx::ColorSpace
,
259 mozilla::gfx::ColorSpace::SRGB
,
260 mozilla::gfx::ColorSpace::Max
> {};
263 struct ParamTraits
<mozilla::gfx::CompositionOp
>
264 : public ContiguousEnumSerializerInclusive
<
265 mozilla::gfx::CompositionOp
, mozilla::gfx::CompositionOp::OP_OVER
,
266 mozilla::gfx::CompositionOp::OP_COUNT
> {};
270 struct ParamTraits<mozilla::PixelFormat>
271 : public EnumSerializer<mozilla::PixelFormat,
272 SurfaceFormat::A8R8G8B8_UINT32,
273 SurfaceFormat::UNKNOWN>
278 struct ParamTraits
<mozilla::gfx::sRGBColor
> {
279 typedef mozilla::gfx::sRGBColor paramType
;
281 static void Write(MessageWriter
* writer
, const paramType
& param
) {
282 WriteParam(writer
, param
.r
);
283 WriteParam(writer
, param
.g
);
284 WriteParam(writer
, param
.b
);
285 WriteParam(writer
, param
.a
);
288 static bool Read(MessageReader
* reader
, paramType
* result
) {
289 return (ReadParam(reader
, &result
->r
) && ReadParam(reader
, &result
->g
) &&
290 ReadParam(reader
, &result
->b
) && ReadParam(reader
, &result
->a
));
295 struct ParamTraits
<mozilla::gfx::DeviceColor
> {
296 typedef mozilla::gfx::DeviceColor paramType
;
298 static void Write(MessageWriter
* writer
, const paramType
& param
) {
299 WriteParam(writer
, param
.r
);
300 WriteParam(writer
, param
.g
);
301 WriteParam(writer
, param
.b
);
302 WriteParam(writer
, param
.a
);
305 static bool Read(MessageReader
* reader
, paramType
* result
) {
306 return (ReadParam(reader
, &result
->r
) && ReadParam(reader
, &result
->g
) &&
307 ReadParam(reader
, &result
->b
) && ReadParam(reader
, &result
->a
));
312 struct ParamTraits
<nsPoint
> {
313 typedef nsPoint paramType
;
315 static void Write(MessageWriter
* writer
, const paramType
& param
) {
316 WriteParam(writer
, param
.x
);
317 WriteParam(writer
, param
.y
);
320 static bool Read(MessageReader
* reader
, paramType
* result
) {
321 return (ReadParam(reader
, &result
->x
) && ReadParam(reader
, &result
->y
));
326 struct ParamTraits
<nsIntPoint
> {
327 typedef nsIntPoint paramType
;
329 static void Write(MessageWriter
* writer
, const paramType
& param
) {
330 WriteParam(writer
, param
.x
);
331 WriteParam(writer
, param
.y
);
334 static bool Read(MessageReader
* reader
, paramType
* result
) {
335 return (ReadParam(reader
, &result
->x
) && ReadParam(reader
, &result
->y
));
339 template <typename T
>
340 struct ParamTraits
<mozilla::gfx::IntSizeTyped
<T
>> {
341 typedef mozilla::gfx::IntSizeTyped
<T
> paramType
;
343 static void Write(MessageWriter
* writer
, const paramType
& param
) {
344 WriteParam(writer
, param
.width
);
345 WriteParam(writer
, param
.height
);
348 static bool Read(MessageReader
* reader
, paramType
* result
) {
349 return (ReadParam(reader
, &result
->width
) &&
350 ReadParam(reader
, &result
->height
));
354 template <typename Region
, typename Rect
, typename Iter
>
355 struct RegionParamTraits
{
356 typedef Region paramType
;
358 static void Write(MessageWriter
* writer
, const paramType
& param
) {
359 for (auto iter
= param
.RectIter(); !iter
.Done(); iter
.Next()) {
360 const Rect
& r
= iter
.Get();
361 MOZ_RELEASE_ASSERT(!r
.IsEmpty(), "GFX: rect is empty.");
362 WriteParam(writer
, r
);
364 // empty rects are sentinel values because nsRegions will never
366 WriteParam(writer
, Rect());
369 static bool Read(MessageReader
* reader
, paramType
* result
) {
370 RegionBuilder
<Region
> builder
;
372 while (ReadParam(reader
, &rect
)) {
373 if (rect
.IsEmpty()) {
374 *result
= builder
.ToRegion();
377 builder
.OrWith(rect
);
384 template <class Units
>
385 struct ParamTraits
<mozilla::gfx::IntRegionTyped
<Units
>>
387 mozilla::gfx::IntRegionTyped
<Units
>,
388 mozilla::gfx::IntRectTyped
<Units
>,
389 typename
mozilla::gfx::IntRegionTyped
<Units
>::RectIterator
> {};
392 struct ParamTraits
<mozilla::gfx::IntSize
> {
393 typedef mozilla::gfx::IntSize paramType
;
395 static void Write(MessageWriter
* writer
, const paramType
& param
) {
396 WriteParam(writer
, param
.width
);
397 WriteParam(writer
, param
.height
);
400 static bool Read(MessageReader
* reader
, paramType
* result
) {
401 return (ReadParam(reader
, &result
->width
) &&
402 ReadParam(reader
, &result
->height
));
407 struct ParamTraits
<mozilla::gfx::CoordTyped
<T
>> {
408 typedef mozilla::gfx::CoordTyped
<T
> paramType
;
410 static void Write(MessageWriter
* writer
, const paramType
& param
) {
411 WriteParam(writer
, param
.value
);
414 static bool Read(MessageReader
* reader
, paramType
* result
) {
415 return (ReadParam(reader
, &result
->value
));
420 struct ParamTraits
<mozilla::gfx::IntCoordTyped
<T
>> {
421 typedef mozilla::gfx::IntCoordTyped
<T
> paramType
;
423 static void Write(MessageWriter
* writer
, const paramType
& param
) {
424 WriteParam(writer
, param
.value
);
427 static bool Read(MessageReader
* reader
, paramType
* result
) {
428 return (ReadParam(reader
, &result
->value
));
432 template <class T
, class U
>
433 struct ParamTraits
<mozilla::gfx::ScaleFactor
<T
, U
>> {
434 typedef mozilla::gfx::ScaleFactor
<T
, U
> paramType
;
436 static void Write(MessageWriter
* writer
, const paramType
& param
) {
437 WriteParam(writer
, param
.scale
);
440 static bool Read(MessageReader
* reader
, paramType
* result
) {
441 return (ReadParam(reader
, &result
->scale
));
445 template <class T
, class U
>
446 struct ParamTraits
<mozilla::gfx::ScaleFactors2D
<T
, U
>> {
447 typedef mozilla::gfx::ScaleFactors2D
<T
, U
> paramType
;
449 static void Write(MessageWriter
* writer
, const paramType
& param
) {
450 WriteParam(writer
, param
.xScale
);
451 WriteParam(writer
, param
.yScale
);
454 static bool Read(MessageReader
* reader
, paramType
* result
) {
455 return (ReadParam(reader
, &result
->xScale
) &&
456 ReadParam(reader
, &result
->yScale
));
461 struct ParamTraits
<mozilla::gfx::PointTyped
<T
>> {
462 typedef mozilla::gfx::PointTyped
<T
> paramType
;
464 static void Write(MessageWriter
* writer
, const paramType
& param
) {
465 WriteParam(writer
, param
.x
);
466 WriteParam(writer
, param
.y
);
469 static bool Read(MessageReader
* reader
, paramType
* result
) {
470 return (ReadParam(reader
, &result
->x
) && ReadParam(reader
, &result
->y
));
474 template <class F
, class T
>
475 struct ParamTraits
<mozilla::gfx::Point3DTyped
<F
, T
>> {
476 typedef mozilla::gfx::Point3DTyped
<F
, T
> paramType
;
478 static void Write(MessageWriter
* writer
, const paramType
& param
) {
479 WriteParam(writer
, param
.x
);
480 WriteParam(writer
, param
.y
);
481 WriteParam(writer
, param
.z
);
484 static bool Read(MessageReader
* reader
, paramType
* result
) {
485 return (ReadParam(reader
, &result
->x
) && ReadParam(reader
, &result
->y
) &&
486 ReadParam(reader
, &result
->z
));
491 struct ParamTraits
<mozilla::gfx::IntPointTyped
<T
>> {
492 typedef mozilla::gfx::IntPointTyped
<T
> paramType
;
494 static void Write(MessageWriter
* writer
, const paramType
& param
) {
495 WriteParam(writer
, param
.x
);
496 WriteParam(writer
, param
.y
);
499 static bool Read(MessageReader
* reader
, paramType
* result
) {
500 return (ReadParam(reader
, &result
->x
) && ReadParam(reader
, &result
->y
));
505 struct ParamTraits
<mozilla::gfx::SizeTyped
<T
>> {
506 typedef mozilla::gfx::SizeTyped
<T
> paramType
;
508 static void Write(MessageWriter
* writer
, const paramType
& param
) {
509 WriteParam(writer
, param
.width
);
510 WriteParam(writer
, param
.height
);
513 static bool Read(MessageReader
* reader
, paramType
* result
) {
514 return (ReadParam(reader
, &result
->width
) &&
515 ReadParam(reader
, &result
->height
));
520 struct ParamTraits
<mozilla::gfx::RectTyped
<T
>> {
521 typedef mozilla::gfx::RectTyped
<T
> paramType
;
523 static void Write(MessageWriter
* writer
, const paramType
& param
) {
524 WriteParam(writer
, param
.X());
525 WriteParam(writer
, param
.Y());
526 WriteParam(writer
, param
.Width());
527 WriteParam(writer
, param
.Height());
530 static bool Read(MessageReader
* reader
, paramType
* result
) {
531 auto x
= result
->X();
532 auto y
= result
->Y();
533 auto w
= result
->Width();
534 auto h
= result
->Height();
536 bool retVal
= (ReadParam(reader
, &x
) && ReadParam(reader
, &y
) &&
537 ReadParam(reader
, &w
) && ReadParam(reader
, &h
));
538 result
->SetRect(x
, y
, w
, h
);
544 struct ParamTraits
<mozilla::gfx::RectAbsoluteTyped
<T
>> {
545 typedef mozilla::gfx::RectAbsoluteTyped
<T
> paramType
;
547 static void Write(MessageWriter
* writer
, const paramType
& param
) {
548 WriteParam(writer
, param
.Left());
549 WriteParam(writer
, param
.Top());
550 WriteParam(writer
, param
.Right());
551 WriteParam(writer
, param
.Bottom());
554 static bool Read(MessageReader
* reader
, paramType
* result
) {
555 auto l
= result
->Left();
556 auto t
= result
->Top();
557 auto r
= result
->Right();
558 auto b
= result
->Bottom();
560 bool retVal
= (ReadParam(reader
, &l
) && ReadParam(reader
, &t
) &&
561 ReadParam(reader
, &r
) && ReadParam(reader
, &b
));
562 result
->SetBox(l
, t
, r
, b
);
568 struct ParamTraits
<mozilla::gfx::IntRectTyped
<T
>> {
569 typedef mozilla::gfx::IntRectTyped
<T
> paramType
;
571 static void Write(MessageWriter
* writer
, const paramType
& param
) {
572 WriteParam(writer
, param
.X());
573 WriteParam(writer
, param
.Y());
574 WriteParam(writer
, param
.Width());
575 WriteParam(writer
, param
.Height());
578 static bool Read(MessageReader
* reader
, paramType
* result
) {
579 auto x
= result
->X();
580 auto y
= result
->Y();
581 auto w
= result
->Width();
582 auto h
= result
->Height();
584 bool retVal
= (ReadParam(reader
, &x
) && ReadParam(reader
, &y
) &&
585 ReadParam(reader
, &w
) && ReadParam(reader
, &h
));
586 result
->SetRect(x
, y
, w
, h
);
592 struct ParamTraits
<mozilla::gfx::Margin
> {
593 typedef mozilla::gfx::Margin paramType
;
595 static void Write(MessageWriter
* writer
, const paramType
& param
) {
596 WriteParam(writer
, param
.top
);
597 WriteParam(writer
, param
.right
);
598 WriteParam(writer
, param
.bottom
);
599 WriteParam(writer
, param
.left
);
602 static bool Read(MessageReader
* reader
, paramType
* result
) {
604 ReadParam(reader
, &result
->top
) && ReadParam(reader
, &result
->right
) &&
605 ReadParam(reader
, &result
->bottom
) && ReadParam(reader
, &result
->left
));
610 struct ParamTraits
<mozilla::gfx::MarginTyped
<T
>> {
611 typedef mozilla::gfx::MarginTyped
<T
> paramType
;
613 static void Write(MessageWriter
* writer
, const paramType
& param
) {
614 WriteParam(writer
, param
.top
);
615 WriteParam(writer
, param
.right
);
616 WriteParam(writer
, param
.bottom
);
617 WriteParam(writer
, param
.left
);
620 static bool Read(MessageReader
* reader
, paramType
* result
) {
622 ReadParam(reader
, &result
->top
) && ReadParam(reader
, &result
->right
) &&
623 ReadParam(reader
, &result
->bottom
) && ReadParam(reader
, &result
->left
));
628 struct ParamTraits
<mozilla::gfx::IntMarginTyped
<T
>> {
629 typedef mozilla::gfx::IntMarginTyped
<T
> paramType
;
631 static void Write(MessageWriter
* writer
, const paramType
& param
) {
632 WriteParam(writer
, param
.top
);
633 WriteParam(writer
, param
.right
);
634 WriteParam(writer
, param
.bottom
);
635 WriteParam(writer
, param
.left
);
638 static bool Read(MessageReader
* reader
, paramType
* result
) {
640 ReadParam(reader
, &result
->top
) && ReadParam(reader
, &result
->right
) &&
641 ReadParam(reader
, &result
->bottom
) && ReadParam(reader
, &result
->left
));
646 struct ParamTraits
<nsRect
> {
647 typedef nsRect paramType
;
649 static void Write(MessageWriter
* writer
, const paramType
& param
) {
650 WriteParam(writer
, param
.X());
651 WriteParam(writer
, param
.Y());
652 WriteParam(writer
, param
.Width());
653 WriteParam(writer
, param
.Height());
656 static bool Read(MessageReader
* reader
, paramType
* result
) {
657 auto x
= result
->X();
658 auto y
= result
->Y();
659 auto w
= result
->Width();
660 auto h
= result
->Height();
661 bool retVal
= (ReadParam(reader
, &x
) && ReadParam(reader
, &y
) &&
662 ReadParam(reader
, &w
) && ReadParam(reader
, &h
));
663 result
->SetRect(x
, y
, w
, h
);
669 struct ParamTraits
<nsRegion
>
670 : RegionParamTraits
<nsRegion
, nsRect
, nsRegion::RectIterator
> {};
673 struct ParamTraits
<GeckoProcessType
>
674 : public ContiguousEnumSerializer
<
675 GeckoProcessType
, GeckoProcessType_Default
, GeckoProcessType_End
> {};
678 struct ParamTraits
<mozilla::gfx::SurfaceFormat
>
679 : public ContiguousEnumSerializer
<mozilla::gfx::SurfaceFormat
,
680 mozilla::gfx::SurfaceFormat::B8G8R8A8
,
681 mozilla::gfx::SurfaceFormat::UNKNOWN
> {};
684 struct ParamTraits
<mozilla::gfx::ColorDepth
>
685 : public ContiguousEnumSerializerInclusive
<
686 mozilla::gfx::ColorDepth
, mozilla::gfx::ColorDepth::_First
,
687 mozilla::gfx::ColorDepth::_Last
> {};
690 struct ParamTraits
<mozilla::gfx::TransferFunction
>
691 : public ContiguousEnumSerializerInclusive
<
692 mozilla::gfx::TransferFunction
,
693 mozilla::gfx::TransferFunction::_First
,
694 mozilla::gfx::TransferFunction::_Last
> {};
697 struct ParamTraits
<mozilla::gfx::ColorRange
>
698 : public ContiguousEnumSerializerInclusive
<
699 mozilla::gfx::ColorRange
, mozilla::gfx::ColorRange::_First
,
700 mozilla::gfx::ColorRange::_Last
> {};
703 struct ParamTraits
<mozilla::gfx::YUVColorSpace
>
704 : public ContiguousEnumSerializerInclusive
<
705 mozilla::gfx::YUVColorSpace
, mozilla::gfx::YUVColorSpace::_First
,
706 mozilla::gfx::YUVColorSpace::_Last
> {};
709 struct ParamTraits
<mozilla::gfx::YUVRangedColorSpace
>
710 : public ContiguousEnumSerializerInclusive
<
711 mozilla::gfx::YUVRangedColorSpace
,
712 mozilla::gfx::YUVRangedColorSpace::_First
,
713 mozilla::gfx::YUVRangedColorSpace::_Last
> {};
716 struct ParamTraits
<mozilla::gfx::ColorSpace2
>
717 : public ContiguousEnumSerializerInclusive
<
718 mozilla::gfx::ColorSpace2
, mozilla::gfx::ColorSpace2::_First
,
719 mozilla::gfx::ColorSpace2::_Last
> {};
722 struct ParamTraits
<mozilla::StereoMode
>
723 : public ContiguousEnumSerializer
<mozilla::StereoMode
,
724 mozilla::StereoMode::MONO
,
725 mozilla::StereoMode::MAX
> {};
728 struct ParamTraits
<mozilla::gfx::ChromaSubsampling
>
729 : public ContiguousEnumSerializerInclusive
<
730 mozilla::gfx::ChromaSubsampling
,
731 mozilla::gfx::ChromaSubsampling::_First
,
732 mozilla::gfx::ChromaSubsampling::_Last
> {};
735 struct ParamTraits
<mozilla::gfx::DeviceResetReason
>
736 : public ContiguousEnumSerializerInclusive
<
737 mozilla::gfx::DeviceResetReason
,
738 mozilla::gfx::DeviceResetReason::_First
,
739 mozilla::gfx::DeviceResetReason::_Last
> {};
742 struct ParamTraits
<mozilla::gfx::DeviceResetDetectPlace
>
743 : public ContiguousEnumSerializerInclusive
<
744 mozilla::gfx::DeviceResetDetectPlace
,
745 mozilla::gfx::DeviceResetDetectPlace::_First
,
746 mozilla::gfx::DeviceResetDetectPlace::_Last
> {};
749 struct ParamTraits
<mozilla::gfx::ImplicitlyCopyableFloatArray
>
750 : public ParamTraits
<nsTArray
<float>> {
751 typedef mozilla::gfx::ImplicitlyCopyableFloatArray paramType
;
755 struct ParamTraits
<mozilla::gfx::EmptyAttributes
> {
756 typedef mozilla::gfx::EmptyAttributes paramType
;
758 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {}
760 static bool Read(MessageReader
* aReader
, paramType
* aResult
) { return true; }
764 struct ParamTraits
<mozilla::gfx::MergeAttributes
> {
765 typedef mozilla::gfx::MergeAttributes paramType
;
767 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {}
769 static bool Read(MessageReader
* aReader
, paramType
* aResult
) { return true; }
773 struct ParamTraits
<mozilla::gfx::ToAlphaAttributes
> {
774 typedef mozilla::gfx::ToAlphaAttributes paramType
;
776 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {}
778 static bool Read(MessageReader
* aReader
, paramType
* aResult
) { return true; }
782 struct ParamTraits
<mozilla::gfx::TileAttributes
> {
783 typedef mozilla::gfx::TileAttributes paramType
;
785 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {}
787 static bool Read(MessageReader
* aReader
, paramType
* aResult
) { return true; }
791 struct ParamTraits
<mozilla::gfx::BlendAttributes
> {
792 typedef mozilla::gfx::BlendAttributes paramType
;
794 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
795 WriteParam(aWriter
, aParam
.mBlendMode
);
798 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
799 return ReadParam(aReader
, &aResult
->mBlendMode
);
804 struct ParamTraits
<mozilla::gfx::MorphologyAttributes
> {
805 typedef mozilla::gfx::MorphologyAttributes paramType
;
807 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
808 WriteParam(aWriter
, aParam
.mOperator
);
809 WriteParam(aWriter
, aParam
.mRadii
);
812 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
813 if (!ReadParam(aReader
, &aResult
->mOperator
) ||
814 !ReadParam(aReader
, &aResult
->mRadii
)) {
822 struct ParamTraits
<mozilla::gfx::FloodAttributes
> {
823 typedef mozilla::gfx::FloodAttributes paramType
;
825 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
826 WriteParam(aWriter
, aParam
.mColor
);
829 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
830 if (!ReadParam(aReader
, &aResult
->mColor
)) {
838 struct ParamTraits
<mozilla::gfx::OpacityAttributes
> {
839 typedef mozilla::gfx::OpacityAttributes paramType
;
841 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
842 WriteParam(aWriter
, aParam
.mOpacity
);
845 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
846 if (!ReadParam(aReader
, &aResult
->mOpacity
)) {
854 struct ParamTraits
<mozilla::gfx::OffsetAttributes
> {
855 typedef mozilla::gfx::OffsetAttributes paramType
;
857 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
858 WriteParam(aWriter
, aParam
.mValue
);
861 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
862 if (!ReadParam(aReader
, &aResult
->mValue
)) {
870 struct ParamTraits
<mozilla::gfx::DisplacementMapAttributes
> {
871 typedef mozilla::gfx::DisplacementMapAttributes paramType
;
873 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
874 WriteParam(aWriter
, aParam
.mScale
);
875 WriteParam(aWriter
, aParam
.mXChannel
);
876 WriteParam(aWriter
, aParam
.mYChannel
);
879 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
880 if (!ReadParam(aReader
, &aResult
->mScale
) ||
881 !ReadParam(aReader
, &aResult
->mXChannel
) ||
882 !ReadParam(aReader
, &aResult
->mYChannel
)) {
890 struct ParamTraits
<mozilla::gfx::TurbulenceAttributes
> {
891 typedef mozilla::gfx::TurbulenceAttributes paramType
;
893 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
894 WriteParam(aWriter
, aParam
.mOffset
);
895 WriteParam(aWriter
, aParam
.mBaseFrequency
);
896 WriteParam(aWriter
, aParam
.mSeed
);
897 WriteParam(aWriter
, aParam
.mOctaves
);
898 WriteParam(aWriter
, aParam
.mStitchable
);
899 WriteParam(aWriter
, aParam
.mType
);
902 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
903 if (!ReadParam(aReader
, &aResult
->mOffset
) ||
904 !ReadParam(aReader
, &aResult
->mBaseFrequency
) ||
905 !ReadParam(aReader
, &aResult
->mSeed
) ||
906 !ReadParam(aReader
, &aResult
->mOctaves
) ||
907 !ReadParam(aReader
, &aResult
->mStitchable
) ||
908 !ReadParam(aReader
, &aResult
->mType
)) {
916 struct ParamTraits
<mozilla::gfx::ImageAttributes
> {
917 typedef mozilla::gfx::ImageAttributes paramType
;
919 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
920 WriteParam(aWriter
, aParam
.mFilter
);
921 WriteParam(aWriter
, aParam
.mInputIndex
);
922 WriteParam(aWriter
, aParam
.mTransform
);
925 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
926 if (!ReadParam(aReader
, &aResult
->mFilter
) ||
927 !ReadParam(aReader
, &aResult
->mInputIndex
) ||
928 !ReadParam(aReader
, &aResult
->mTransform
)) {
936 struct ParamTraits
<mozilla::gfx::GaussianBlurAttributes
> {
937 typedef mozilla::gfx::GaussianBlurAttributes paramType
;
939 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
940 WriteParam(aWriter
, aParam
.mStdDeviation
);
943 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
944 if (!ReadParam(aReader
, &aResult
->mStdDeviation
)) {
952 struct ParamTraits
<mozilla::gfx::DropShadowAttributes
> {
953 typedef mozilla::gfx::DropShadowAttributes paramType
;
955 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
956 WriteParam(aWriter
, aParam
.mStdDeviation
);
957 WriteParam(aWriter
, aParam
.mOffset
);
958 WriteParam(aWriter
, aParam
.mColor
);
961 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
962 if (!ReadParam(aReader
, &aResult
->mStdDeviation
) ||
963 !ReadParam(aReader
, &aResult
->mOffset
) ||
964 !ReadParam(aReader
, &aResult
->mColor
)) {
972 struct ParamTraits
<mozilla::gfx::ColorMatrixAttributes
> {
973 typedef mozilla::gfx::ColorMatrixAttributes paramType
;
975 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
976 WriteParam(aWriter
, aParam
.mType
);
977 WriteParam(aWriter
, aParam
.mValues
);
980 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
981 if (!ReadParam(aReader
, &aResult
->mType
) ||
982 !ReadParam(aReader
, &aResult
->mValues
)) {
990 struct ParamTraits
<mozilla::gfx::ComponentTransferAttributes
> {
991 typedef mozilla::gfx::ComponentTransferAttributes paramType
;
993 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
994 for (int i
= 0; i
< 4; ++i
) {
995 WriteParam(aWriter
, aParam
.mTypes
[i
]);
997 for (int i
= 0; i
< 4; ++i
) {
998 WriteParam(aWriter
, aParam
.mValues
[i
]);
1002 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
1003 for (int i
= 0; i
< 4; ++i
) {
1004 if (!ReadParam(aReader
, &aResult
->mTypes
[i
])) {
1008 for (int i
= 0; i
< 4; ++i
) {
1009 if (!ReadParam(aReader
, &aResult
->mValues
[i
])) {
1018 struct ParamTraits
<mozilla::gfx::ConvolveMatrixAttributes
> {
1019 typedef mozilla::gfx::ConvolveMatrixAttributes paramType
;
1021 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
1022 WriteParam(aWriter
, aParam
.mKernelSize
);
1023 WriteParam(aWriter
, aParam
.mKernelMatrix
);
1024 WriteParam(aWriter
, aParam
.mDivisor
);
1025 WriteParam(aWriter
, aParam
.mBias
);
1026 WriteParam(aWriter
, aParam
.mTarget
);
1027 WriteParam(aWriter
, aParam
.mEdgeMode
);
1028 WriteParam(aWriter
, aParam
.mKernelUnitLength
);
1029 WriteParam(aWriter
, aParam
.mPreserveAlpha
);
1032 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
1033 if (!ReadParam(aReader
, &aResult
->mKernelSize
) ||
1034 !ReadParam(aReader
, &aResult
->mKernelMatrix
) ||
1035 !ReadParam(aReader
, &aResult
->mDivisor
) ||
1036 !ReadParam(aReader
, &aResult
->mBias
) ||
1037 !ReadParam(aReader
, &aResult
->mTarget
) ||
1038 !ReadParam(aReader
, &aResult
->mEdgeMode
) ||
1039 !ReadParam(aReader
, &aResult
->mKernelUnitLength
) ||
1040 !ReadParam(aReader
, &aResult
->mPreserveAlpha
)) {
1048 struct ParamTraits
<mozilla::gfx::DiffuseLightingAttributes
> {
1049 typedef mozilla::gfx::DiffuseLightingAttributes paramType
;
1051 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
1052 WriteParam(aWriter
, aParam
.mLightType
);
1053 WriteParam(aWriter
, aParam
.mLightValues
);
1054 WriteParam(aWriter
, aParam
.mSurfaceScale
);
1055 WriteParam(aWriter
, aParam
.mKernelUnitLength
);
1056 WriteParam(aWriter
, aParam
.mColor
);
1057 WriteParam(aWriter
, aParam
.mLightingConstant
);
1058 WriteParam(aWriter
, aParam
.mSpecularExponent
);
1061 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
1062 if (!ReadParam(aReader
, &aResult
->mLightType
) ||
1063 !ReadParam(aReader
, &aResult
->mLightValues
) ||
1064 !ReadParam(aReader
, &aResult
->mSurfaceScale
) ||
1065 !ReadParam(aReader
, &aResult
->mKernelUnitLength
) ||
1066 !ReadParam(aReader
, &aResult
->mColor
) ||
1067 !ReadParam(aReader
, &aResult
->mLightingConstant
) ||
1068 !ReadParam(aReader
, &aResult
->mSpecularExponent
)) {
1076 struct ParamTraits
<mozilla::gfx::SpecularLightingAttributes
> {
1077 typedef mozilla::gfx::SpecularLightingAttributes paramType
;
1079 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
1080 WriteParam(aWriter
, aParam
.mLightType
);
1081 WriteParam(aWriter
, aParam
.mLightValues
);
1082 WriteParam(aWriter
, aParam
.mSurfaceScale
);
1083 WriteParam(aWriter
, aParam
.mKernelUnitLength
);
1084 WriteParam(aWriter
, aParam
.mColor
);
1085 WriteParam(aWriter
, aParam
.mLightingConstant
);
1086 WriteParam(aWriter
, aParam
.mSpecularExponent
);
1089 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
1090 if (!ReadParam(aReader
, &aResult
->mLightType
) ||
1091 !ReadParam(aReader
, &aResult
->mLightValues
) ||
1092 !ReadParam(aReader
, &aResult
->mSurfaceScale
) ||
1093 !ReadParam(aReader
, &aResult
->mKernelUnitLength
) ||
1094 !ReadParam(aReader
, &aResult
->mColor
) ||
1095 !ReadParam(aReader
, &aResult
->mLightingConstant
) ||
1096 !ReadParam(aReader
, &aResult
->mSpecularExponent
)) {
1104 struct ParamTraits
<mozilla::gfx::CompositeAttributes
> {
1105 typedef mozilla::gfx::CompositeAttributes paramType
;
1107 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
1108 WriteParam(aWriter
, aParam
.mOperator
);
1109 WriteParam(aWriter
, aParam
.mCoefficients
);
1112 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
1113 if (!ReadParam(aReader
, &aResult
->mOperator
) ||
1114 !ReadParam(aReader
, &aResult
->mCoefficients
)) {
1122 struct ParamTraits
<mozilla::gfx::Glyph
> {
1123 typedef mozilla::gfx::Glyph paramType
;
1124 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
1125 WriteParam(aWriter
, aParam
.mIndex
);
1126 WriteParam(aWriter
, aParam
.mPosition
);
1129 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
1130 return (ReadParam(aReader
, &aResult
->mIndex
) &&
1131 ReadParam(aReader
, &aResult
->mPosition
));
1135 template <typename T
, size_t Length
>
1136 struct ParamTraits
<mozilla::Array
<T
, Length
>> {
1137 typedef mozilla::Array
<T
, Length
> paramType
;
1138 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
1139 for (size_t i
= 0; i
< Length
; i
++) {
1140 WriteParam(aWriter
, aParam
[i
]);
1144 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
1145 for (size_t i
= 0; i
< Length
; i
++) {
1146 if (!ReadParam
<T
>(aReader
, &aResult
->operator[](i
))) {
1155 struct ParamTraits
<mozilla::SideBits
>
1156 : public BitFlagsEnumSerializer
<mozilla::SideBits
,
1157 mozilla::SideBits::eAll
> {};
1160 struct ParamTraits
<gfxSparseBitSet
> {
1161 typedef gfxSparseBitSet paramType
;
1162 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
1163 WriteParam(aWriter
, aParam
.mBlockIndex
);
1164 WriteParam(aWriter
, aParam
.mBlocks
);
1166 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
1167 return ReadParam(aReader
, &aResult
->mBlockIndex
) &&
1168 ReadParam(aReader
, &aResult
->mBlocks
);
1173 struct ParamTraits
<gfxSparseBitSet::Block
> {
1174 typedef gfxSparseBitSet::Block paramType
;
1175 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
1176 aWriter
->WriteBytes(&aParam
, sizeof(aParam
));
1178 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
1179 return aReader
->ReadBytesInto(aResult
, sizeof(*aResult
));
1183 // The actual FontVisibility enum is defined in gfxTypes.h
1185 struct ParamTraits
<FontVisibility
>
1186 : public ContiguousEnumSerializer
<FontVisibility
, FontVisibility::Unknown
,
1187 FontVisibility::Count
> {};
1190 struct ParamTraits
<mozilla::fontlist::Pointer
> {
1191 typedef mozilla::fontlist::Pointer paramType
;
1192 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
1193 uint32_t v
= aParam
.mBlockAndOffset
;
1194 WriteParam(aWriter
, v
);
1196 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
1198 if (ReadParam(aReader
, &v
)) {
1199 aResult
->mBlockAndOffset
.store(v
);
1207 struct ParamTraits
<mozilla::gfx::FenceInfo
> {
1208 typedef mozilla::gfx::FenceInfo paramType
;
1210 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
1211 WriteParam(aWriter
, aParam
.mFenceHandle
);
1212 WriteParam(aWriter
, aParam
.mFenceValue
);
1215 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
1216 if (!ReadParam(aReader
, &aResult
->mFenceHandle
) ||
1217 !ReadParam(aReader
, &aResult
->mFenceValue
)) {
1230 struct IPDLParamTraits
<gfx::PaintFragment
> {
1231 typedef mozilla::gfx::PaintFragment paramType
;
1232 static void Write(IPC::MessageWriter
* aWriter
, IProtocol
* aActor
,
1233 paramType
&& aParam
) {
1235 if (aParam
.mSize
.IsEmpty() ||
1236 !aActor
->AllocShmem(aParam
.mRecording
.mLen
, &shmem
)) {
1237 WriteParam(aWriter
, gfx::IntSize(0, 0));
1241 memcpy(shmem
.get
<uint8_t>(), aParam
.mRecording
.mData
,
1242 aParam
.mRecording
.mLen
);
1244 WriteParam(aWriter
, aParam
.mSize
);
1245 WriteIPDLParam(aWriter
, aActor
, std::move(shmem
));
1246 WriteParam(aWriter
, aParam
.mDependencies
);
1249 static bool Read(IPC::MessageReader
* aReader
, IProtocol
* aActor
,
1250 paramType
* aResult
) {
1251 if (!ReadParam(aReader
, &aResult
->mSize
)) {
1254 if (aResult
->mSize
.IsEmpty()) {
1258 if (!ReadIPDLParam(aReader
, aActor
, &shmem
) ||
1259 !ReadParam(aReader
, &aResult
->mDependencies
)) {
1260 aActor
->DeallocShmem(shmem
);
1264 if (!aResult
->mRecording
.Allocate(shmem
.Size
<uint8_t>())) {
1265 aResult
->mSize
.SizeTo(0, 0);
1266 aActor
->DeallocShmem(shmem
);
1270 memcpy(aResult
->mRecording
.mData
, shmem
.get
<uint8_t>(),
1271 shmem
.Size
<uint8_t>());
1272 aActor
->DeallocShmem(shmem
);
1278 struct IPDLParamTraits
<gfx::FileHandleWrapper
*> {
1279 static void Write(IPC::MessageWriter
* aWriter
, IProtocol
* aActor
,
1280 gfx::FileHandleWrapper
* aParam
) {
1282 WriteIPDLParam(aWriter
, aActor
, false);
1285 WriteIPDLParam(aWriter
, aActor
, true);
1287 mozilla::ipc::FileDescriptor
desc(aParam
->GetHandle());
1288 WriteIPDLParam(aWriter
, aActor
, desc
);
1291 static bool Read(IPC::MessageReader
* aReader
, IProtocol
* aActor
,
1292 RefPtr
<gfx::FileHandleWrapper
>* aResult
) {
1294 bool notnull
= false;
1295 if (!ReadIPDLParam(aReader
, aActor
, ¬null
)) {
1303 mozilla::ipc::FileDescriptor desc
;
1304 if (!ReadIPDLParam(aReader
, aActor
, &desc
)) {
1308 MakeRefPtr
<gfx::FileHandleWrapper
>(desc
.TakePlatformHandle());
1309 *aResult
= std::move(wrapper
);
1315 } // namespace mozilla
1317 #endif /* __GFXMESSAGEUTILS_H__ */