Bug 1913305 - Add test. r=mtigley
[gecko.git] / gfx / ipc / GfxMessageUtils.h
blob5ebd5b2c025e8d98c111b8b4a5a778ecae19b891
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"
17 #include "gfxPoint.h"
18 #include "gfxRect.h"
19 #include "gfxTelemetry.h"
20 #include "gfxTypes.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"
29 #include "nsRect.h"
30 #include "nsRegion.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"
38 #include <stdint.h>
40 #ifdef _MSC_VER
41 # pragma warning(disable : 4800)
42 #endif
44 namespace mozilla {
46 typedef gfxImageFormat PixelFormat;
48 } // namespace mozilla
50 namespace IPC {
52 template <>
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))
71 return true;
73 return false;
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)
83 Wr(_11);
84 Wr(_12);
85 Wr(_13);
86 Wr(_14);
87 Wr(_21);
88 Wr(_22);
89 Wr(_23);
90 Wr(_24);
91 Wr(_31);
92 Wr(_32);
93 Wr(_33);
94 Wr(_34);
95 Wr(_41);
96 Wr(_42);
97 Wr(_43);
98 Wr(_44);
99 #undef Wr
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));
107 #undef Rd
111 template <>
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)
117 Wr(_11);
118 Wr(_12);
119 Wr(_13);
120 Wr(_14);
121 Wr(_21);
122 Wr(_22);
123 Wr(_23);
124 Wr(_24);
125 Wr(_31);
126 Wr(_32);
127 Wr(_33);
128 Wr(_34);
129 Wr(_41);
130 Wr(_42);
131 Wr(_43);
132 Wr(_44);
133 Wr(_51);
134 Wr(_52);
135 Wr(_53);
136 Wr(_54);
137 #undef Wr
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) &&
145 Rd(_53) && Rd(_54));
146 #undef Rd
150 template <>
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));
165 template <>
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))
177 return true;
179 return false;
183 template <>
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);
203 return retVal;
207 template <>
208 struct ParamTraits<gfxContentType>
209 : public ContiguousEnumSerializer<gfxContentType, gfxContentType::COLOR,
210 gfxContentType::SENTINEL> {};
212 template <>
213 struct ParamTraits<gfxSurfaceType>
214 : public ContiguousEnumSerializer<gfxSurfaceType, gfxSurfaceType::Image,
215 gfxSurfaceType::Max> {};
217 template <>
218 struct ParamTraits<mozilla::gfx::SamplingFilter>
219 : public ContiguousEnumSerializer<mozilla::gfx::SamplingFilter,
220 mozilla::gfx::SamplingFilter::GOOD,
221 mozilla::gfx::SamplingFilter::SENTINEL> {
224 template <>
225 struct ParamTraits<mozilla::gfx::BackendType>
226 : public ContiguousEnumSerializer<mozilla::gfx::BackendType,
227 mozilla::gfx::BackendType::NONE,
228 mozilla::gfx::BackendType::BACKEND_LAST> {
231 template <>
232 struct ParamTraits<mozilla::gfx::Feature>
233 : public ContiguousEnumSerializer<mozilla::gfx::Feature,
234 mozilla::gfx::Feature::HW_COMPOSITING,
235 mozilla::gfx::Feature::NumValues> {};
237 template <>
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> {};
244 template <>
245 struct ParamTraits<mozilla::gfx::FeatureStatus>
246 : public ContiguousEnumSerializer<mozilla::gfx::FeatureStatus,
247 mozilla::gfx::FeatureStatus::Unused,
248 mozilla::gfx::FeatureStatus::LAST> {};
250 template <>
251 struct ParamTraits<mozilla::gfx::LightType>
252 : public ContiguousEnumSerializer<mozilla::gfx::LightType,
253 mozilla::gfx::LightType::None,
254 mozilla::gfx::LightType::Max> {};
256 template <>
257 struct ParamTraits<mozilla::gfx::ColorSpace>
258 : public ContiguousEnumSerializer<mozilla::gfx::ColorSpace,
259 mozilla::gfx::ColorSpace::SRGB,
260 mozilla::gfx::ColorSpace::Max> {};
262 template <>
263 struct ParamTraits<mozilla::gfx::CompositionOp>
264 : public ContiguousEnumSerializerInclusive<
265 mozilla::gfx::CompositionOp, mozilla::gfx::CompositionOp::OP_OVER,
266 mozilla::gfx::CompositionOp::OP_COUNT> {};
269 template <>
270 struct ParamTraits<mozilla::PixelFormat>
271 : public EnumSerializer<mozilla::PixelFormat,
272 SurfaceFormat::A8R8G8B8_UINT32,
273 SurfaceFormat::UNKNOWN>
277 template <>
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));
294 template <>
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));
311 template <>
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));
325 template <>
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
365 // contain them
366 WriteParam(writer, Rect());
369 static bool Read(MessageReader* reader, paramType* result) {
370 RegionBuilder<Region> builder;
371 Rect rect;
372 while (ReadParam(reader, &rect)) {
373 if (rect.IsEmpty()) {
374 *result = builder.ToRegion();
375 return true;
377 builder.OrWith(rect);
380 return false;
384 template <class Units>
385 struct ParamTraits<mozilla::gfx::IntRegionTyped<Units>>
386 : RegionParamTraits<
387 mozilla::gfx::IntRegionTyped<Units>,
388 mozilla::gfx::IntRectTyped<Units>,
389 typename mozilla::gfx::IntRegionTyped<Units>::RectIterator> {};
391 template <>
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));
406 template <class T>
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));
419 template <class T>
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));
460 template <class T>
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));
490 template <class T>
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));
504 template <class T>
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));
519 template <class T>
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);
539 return retVal;
543 template <class T>
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);
563 return retVal;
567 template <class T>
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);
587 return retVal;
591 template <>
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) {
603 return (
604 ReadParam(reader, &result->top) && ReadParam(reader, &result->right) &&
605 ReadParam(reader, &result->bottom) && ReadParam(reader, &result->left));
609 template <class T>
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) {
621 return (
622 ReadParam(reader, &result->top) && ReadParam(reader, &result->right) &&
623 ReadParam(reader, &result->bottom) && ReadParam(reader, &result->left));
627 template <class T>
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) {
639 return (
640 ReadParam(reader, &result->top) && ReadParam(reader, &result->right) &&
641 ReadParam(reader, &result->bottom) && ReadParam(reader, &result->left));
645 template <>
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);
664 return retVal;
668 template <>
669 struct ParamTraits<nsRegion>
670 : RegionParamTraits<nsRegion, nsRect, nsRegion::RectIterator> {};
672 template <>
673 struct ParamTraits<GeckoProcessType>
674 : public ContiguousEnumSerializer<
675 GeckoProcessType, GeckoProcessType_Default, GeckoProcessType_End> {};
677 template <>
678 struct ParamTraits<mozilla::gfx::SurfaceFormat>
679 : public ContiguousEnumSerializer<mozilla::gfx::SurfaceFormat,
680 mozilla::gfx::SurfaceFormat::B8G8R8A8,
681 mozilla::gfx::SurfaceFormat::UNKNOWN> {};
683 template <>
684 struct ParamTraits<mozilla::gfx::ColorDepth>
685 : public ContiguousEnumSerializerInclusive<
686 mozilla::gfx::ColorDepth, mozilla::gfx::ColorDepth::_First,
687 mozilla::gfx::ColorDepth::_Last> {};
689 template <>
690 struct ParamTraits<mozilla::gfx::TransferFunction>
691 : public ContiguousEnumSerializerInclusive<
692 mozilla::gfx::TransferFunction,
693 mozilla::gfx::TransferFunction::_First,
694 mozilla::gfx::TransferFunction::_Last> {};
696 template <>
697 struct ParamTraits<mozilla::gfx::ColorRange>
698 : public ContiguousEnumSerializerInclusive<
699 mozilla::gfx::ColorRange, mozilla::gfx::ColorRange::_First,
700 mozilla::gfx::ColorRange::_Last> {};
702 template <>
703 struct ParamTraits<mozilla::gfx::YUVColorSpace>
704 : public ContiguousEnumSerializerInclusive<
705 mozilla::gfx::YUVColorSpace, mozilla::gfx::YUVColorSpace::_First,
706 mozilla::gfx::YUVColorSpace::_Last> {};
708 template <>
709 struct ParamTraits<mozilla::gfx::YUVRangedColorSpace>
710 : public ContiguousEnumSerializerInclusive<
711 mozilla::gfx::YUVRangedColorSpace,
712 mozilla::gfx::YUVRangedColorSpace::_First,
713 mozilla::gfx::YUVRangedColorSpace::_Last> {};
715 template <>
716 struct ParamTraits<mozilla::gfx::ColorSpace2>
717 : public ContiguousEnumSerializerInclusive<
718 mozilla::gfx::ColorSpace2, mozilla::gfx::ColorSpace2::_First,
719 mozilla::gfx::ColorSpace2::_Last> {};
721 template <>
722 struct ParamTraits<mozilla::StereoMode>
723 : public ContiguousEnumSerializer<mozilla::StereoMode,
724 mozilla::StereoMode::MONO,
725 mozilla::StereoMode::MAX> {};
727 template <>
728 struct ParamTraits<mozilla::gfx::ChromaSubsampling>
729 : public ContiguousEnumSerializerInclusive<
730 mozilla::gfx::ChromaSubsampling,
731 mozilla::gfx::ChromaSubsampling::_First,
732 mozilla::gfx::ChromaSubsampling::_Last> {};
734 template <>
735 struct ParamTraits<mozilla::gfx::DeviceResetReason>
736 : public ContiguousEnumSerializerInclusive<
737 mozilla::gfx::DeviceResetReason,
738 mozilla::gfx::DeviceResetReason::_First,
739 mozilla::gfx::DeviceResetReason::_Last> {};
741 template <>
742 struct ParamTraits<mozilla::gfx::DeviceResetDetectPlace>
743 : public ContiguousEnumSerializerInclusive<
744 mozilla::gfx::DeviceResetDetectPlace,
745 mozilla::gfx::DeviceResetDetectPlace::_First,
746 mozilla::gfx::DeviceResetDetectPlace::_Last> {};
748 template <>
749 struct ParamTraits<mozilla::gfx::ImplicitlyCopyableFloatArray>
750 : public ParamTraits<nsTArray<float>> {
751 typedef mozilla::gfx::ImplicitlyCopyableFloatArray paramType;
754 template <>
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; }
763 template <>
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; }
772 template <>
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; }
781 template <>
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; }
790 template <>
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);
803 template <>
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)) {
815 return false;
817 return true;
821 template <>
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)) {
831 return false;
833 return true;
837 template <>
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)) {
847 return false;
849 return true;
853 template <>
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)) {
863 return false;
865 return true;
869 template <>
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)) {
883 return false;
885 return true;
889 template <>
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)) {
909 return false;
911 return true;
915 template <>
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)) {
929 return false;
931 return true;
935 template <>
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)) {
945 return false;
947 return true;
951 template <>
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)) {
965 return false;
967 return true;
971 template <>
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)) {
983 return false;
985 return true;
989 template <>
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])) {
1005 return false;
1008 for (int i = 0; i < 4; ++i) {
1009 if (!ReadParam(aReader, &aResult->mValues[i])) {
1010 return false;
1013 return true;
1017 template <>
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)) {
1041 return false;
1043 return true;
1047 template <>
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)) {
1069 return false;
1071 return true;
1075 template <>
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)) {
1097 return false;
1099 return true;
1103 template <>
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)) {
1115 return false;
1117 return true;
1121 template <>
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))) {
1147 return false;
1150 return true;
1154 template <>
1155 struct ParamTraits<mozilla::SideBits>
1156 : public BitFlagsEnumSerializer<mozilla::SideBits,
1157 mozilla::SideBits::eAll> {};
1159 template <>
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);
1172 template <>
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
1184 template <>
1185 struct ParamTraits<FontVisibility>
1186 : public ContiguousEnumSerializer<FontVisibility, FontVisibility::Unknown,
1187 FontVisibility::Count> {};
1189 template <>
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) {
1197 uint32_t v;
1198 if (ReadParam(aReader, &v)) {
1199 aResult->mBlockAndOffset.store(v);
1200 return true;
1202 return false;
1206 template <>
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)) {
1218 return false;
1220 return true;
1224 } // namespace IPC
1226 namespace mozilla {
1227 namespace ipc {
1229 template <>
1230 struct IPDLParamTraits<gfx::PaintFragment> {
1231 typedef mozilla::gfx::PaintFragment paramType;
1232 static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
1233 paramType&& aParam) {
1234 Shmem shmem;
1235 if (aParam.mSize.IsEmpty() ||
1236 !aActor->AllocShmem(aParam.mRecording.mLen, &shmem)) {
1237 WriteParam(aWriter, gfx::IntSize(0, 0));
1238 return;
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)) {
1252 return false;
1254 if (aResult->mSize.IsEmpty()) {
1255 return true;
1257 Shmem shmem;
1258 if (!ReadIPDLParam(aReader, aActor, &shmem) ||
1259 !ReadParam(aReader, &aResult->mDependencies)) {
1260 aActor->DeallocShmem(shmem);
1261 return false;
1264 if (!aResult->mRecording.Allocate(shmem.Size<uint8_t>())) {
1265 aResult->mSize.SizeTo(0, 0);
1266 aActor->DeallocShmem(shmem);
1267 return true;
1270 memcpy(aResult->mRecording.mData, shmem.get<uint8_t>(),
1271 shmem.Size<uint8_t>());
1272 aActor->DeallocShmem(shmem);
1273 return true;
1277 template <>
1278 struct IPDLParamTraits<gfx::FileHandleWrapper*> {
1279 static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
1280 gfx::FileHandleWrapper* aParam) {
1281 if (!aParam) {
1282 WriteIPDLParam(aWriter, aActor, false);
1283 return;
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) {
1293 *aResult = nullptr;
1294 bool notnull = false;
1295 if (!ReadIPDLParam(aReader, aActor, &notnull)) {
1296 return false;
1299 if (!notnull) {
1300 return true;
1303 mozilla::ipc::FileDescriptor desc;
1304 if (!ReadIPDLParam(aReader, aActor, &desc)) {
1305 return false;
1307 auto wrapper =
1308 MakeRefPtr<gfx::FileHandleWrapper>(desc.TakePlatformHandle());
1309 *aResult = std::move(wrapper);
1310 return true;
1314 } // namespace ipc
1315 } // namespace mozilla
1317 #endif /* __GFXMESSAGEUTILS_H__ */