Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set sw=2 ts=8 et tw=80 : */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef __GFXMESSAGEUTILS_H__
8 : #define __GFXMESSAGEUTILS_H__
9 :
10 : #include "FilterSupport.h"
11 : #include "FrameMetrics.h"
12 : #include "ImageTypes.h"
13 : #include "RegionBuilder.h"
14 : #include "base/process_util.h"
15 : #include "chrome/common/ipc_message_utils.h"
16 : #include "gfxFeature.h"
17 : #include "gfxFallback.h"
18 : #include "gfxPoint.h"
19 : #include "gfxRect.h"
20 : #include "gfxTelemetry.h"
21 : #include "gfxTypes.h"
22 : #include "ipc/IPCMessageUtils.h"
23 : #include "mozilla/gfx/Matrix.h"
24 : #include "nsRect.h"
25 : #include "nsRegion.h"
26 : #include "mozilla/Array.h"
27 :
28 : #include <stdint.h>
29 :
30 : #ifdef _MSC_VER
31 : #pragma warning( disable : 4800 )
32 : #endif
33 :
34 : namespace mozilla {
35 :
36 : typedef gfxImageFormat PixelFormat;
37 :
38 : } // namespace mozilla
39 :
40 : namespace IPC {
41 :
42 : template<>
43 : struct ParamTraits<mozilla::gfx::Matrix>
44 : {
45 : typedef mozilla::gfx::Matrix paramType;
46 :
47 0 : static void Write(Message* aMsg, const paramType& aParam)
48 : {
49 0 : WriteParam(aMsg, aParam._11);
50 0 : WriteParam(aMsg, aParam._12);
51 0 : WriteParam(aMsg, aParam._21);
52 0 : WriteParam(aMsg, aParam._22);
53 0 : WriteParam(aMsg, aParam._31);
54 0 : WriteParam(aMsg, aParam._32);
55 0 : }
56 :
57 0 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
58 : {
59 0 : if (ReadParam(aMsg, aIter, &aResult->_11) &&
60 0 : ReadParam(aMsg, aIter, &aResult->_12) &&
61 0 : ReadParam(aMsg, aIter, &aResult->_21) &&
62 0 : ReadParam(aMsg, aIter, &aResult->_22) &&
63 0 : ReadParam(aMsg, aIter, &aResult->_31) &&
64 0 : ReadParam(aMsg, aIter, &aResult->_32))
65 0 : return true;
66 :
67 0 : return false;
68 : }
69 :
70 : static void Log(const paramType& aParam, std::wstring* aLog)
71 : {
72 : aLog->append(StringPrintf(L"[[%g %g] [%g %g] [%g %g]]", aParam._11, aParam._12, aParam._21, aParam._22,
73 : aParam._31, aParam._32));
74 : }
75 : };
76 :
77 : template<>
78 : struct ParamTraits<mozilla::gfx::Matrix4x4>
79 : {
80 : typedef mozilla::gfx::Matrix4x4 paramType;
81 :
82 0 : static void Write(Message* msg, const paramType& param)
83 : {
84 : #define Wr(_f) WriteParam(msg, param. _f)
85 0 : Wr(_11); Wr(_12); Wr(_13); Wr(_14);
86 0 : Wr(_21); Wr(_22); Wr(_23); Wr(_24);
87 0 : Wr(_31); Wr(_32); Wr(_33); Wr(_34);
88 0 : Wr(_41); Wr(_42); Wr(_43); Wr(_44);
89 : #undef Wr
90 0 : }
91 :
92 0 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
93 : {
94 : #define Rd(_f) ReadParam(msg, iter, &result-> _f)
95 0 : return (Rd(_11) && Rd(_12) && Rd(_13) && Rd(_14) &&
96 0 : Rd(_21) && Rd(_22) && Rd(_23) && Rd(_24) &&
97 0 : Rd(_31) && Rd(_32) && Rd(_33) && Rd(_34) &&
98 0 : Rd(_41) && Rd(_42) && Rd(_43) && Rd(_44));
99 : #undef Rd
100 : }
101 : };
102 :
103 : template<>
104 : struct ParamTraits<mozilla::gfx::Matrix5x4>
105 : {
106 : typedef mozilla::gfx::Matrix5x4 paramType;
107 :
108 : static void Write(Message* msg, const paramType& param)
109 : {
110 : #define Wr(_f) WriteParam(msg, param. _f)
111 : Wr(_11); Wr(_12); Wr(_13); Wr(_14);
112 : Wr(_21); Wr(_22); Wr(_23); Wr(_24);
113 : Wr(_31); Wr(_32); Wr(_33); Wr(_34);
114 : Wr(_41); Wr(_42); Wr(_43); Wr(_44);
115 : Wr(_51); Wr(_52); Wr(_53); Wr(_54);
116 : #undef Wr
117 : }
118 :
119 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
120 : {
121 : #define Rd(_f) ReadParam(msg, iter, &result-> _f)
122 : return (Rd(_11) && Rd(_12) && Rd(_13) && Rd(_14) &&
123 : Rd(_21) && Rd(_22) && Rd(_23) && Rd(_24) &&
124 : Rd(_31) && Rd(_32) && Rd(_33) && Rd(_34) &&
125 : Rd(_41) && Rd(_42) && Rd(_43) && Rd(_44) &&
126 : Rd(_51) && Rd(_52) && Rd(_53) && Rd(_54));
127 : #undef Rd
128 : }
129 : };
130 :
131 : template<>
132 : struct ParamTraits<gfxPoint>
133 : {
134 : typedef gfxPoint paramType;
135 :
136 : static void Write(Message* aMsg, const paramType& aParam)
137 : {
138 : WriteParam(aMsg, aParam.x);
139 : WriteParam(aMsg, aParam.y);
140 : }
141 :
142 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
143 : {
144 : return (ReadParam(aMsg, aIter, &aResult->x) &&
145 : ReadParam(aMsg, aIter, &aResult->y));
146 : }
147 : };
148 :
149 : template<>
150 : struct ParamTraits<gfxSize>
151 : {
152 : typedef gfxSize paramType;
153 :
154 : static void Write(Message* aMsg, const paramType& aParam)
155 : {
156 : WriteParam(aMsg, aParam.width);
157 : WriteParam(aMsg, aParam.height);
158 : }
159 :
160 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
161 : {
162 : if (ReadParam(aMsg, aIter, &aResult->width) &&
163 : ReadParam(aMsg, aIter, &aResult->height))
164 : return true;
165 :
166 : return false;
167 : }
168 : };
169 :
170 : template<>
171 : struct ParamTraits<gfxRect>
172 : {
173 : typedef gfxRect paramType;
174 :
175 : static void Write(Message* aMsg, const paramType& aParam)
176 : {
177 : WriteParam(aMsg, aParam.x);
178 : WriteParam(aMsg, aParam.y);
179 : WriteParam(aMsg, aParam.width);
180 : WriteParam(aMsg, aParam.height);
181 : }
182 :
183 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
184 : {
185 : return ReadParam(aMsg, aIter, &aResult->x) &&
186 : ReadParam(aMsg, aIter, &aResult->y) &&
187 : ReadParam(aMsg, aIter, &aResult->width) &&
188 : ReadParam(aMsg, aIter, &aResult->height);
189 : }
190 : };
191 :
192 : template <>
193 : struct ParamTraits<gfxContentType>
194 : : public ContiguousEnumSerializer<
195 : gfxContentType,
196 : gfxContentType::COLOR,
197 : gfxContentType::SENTINEL>
198 : {};
199 :
200 : template <>
201 : struct ParamTraits<gfxSurfaceType>
202 : : public ContiguousEnumSerializer<
203 : gfxSurfaceType,
204 : gfxSurfaceType::Image,
205 : gfxSurfaceType::Max>
206 : {};
207 :
208 : template <>
209 : struct ParamTraits<mozilla::gfx::SamplingFilter>
210 : : public ContiguousEnumSerializer<
211 : mozilla::gfx::SamplingFilter,
212 : mozilla::gfx::SamplingFilter::GOOD,
213 : mozilla::gfx::SamplingFilter::SENTINEL>
214 : {};
215 :
216 : template <>
217 : struct ParamTraits<mozilla::gfx::BackendType>
218 : : public ContiguousEnumSerializer<
219 : mozilla::gfx::BackendType,
220 : mozilla::gfx::BackendType::NONE,
221 : mozilla::gfx::BackendType::BACKEND_LAST>
222 : {};
223 :
224 : template <>
225 : struct ParamTraits<mozilla::gfx::Feature>
226 : : public ContiguousEnumSerializer<
227 : mozilla::gfx::Feature,
228 : mozilla::gfx::Feature::HW_COMPOSITING,
229 : mozilla::gfx::Feature::NumValues>
230 : {};
231 :
232 : template <>
233 : struct ParamTraits<mozilla::gfx::Fallback>
234 : : public ContiguousEnumSerializer<
235 : mozilla::gfx::Fallback,
236 : mozilla::gfx::Fallback::NO_CONSTANT_BUFFER_OFFSETTING,
237 : mozilla::gfx::Fallback::NumValues>
238 : {};
239 :
240 : template <>
241 : struct ParamTraits<mozilla::gfx::FeatureStatus>
242 : : public ContiguousEnumSerializer<
243 : mozilla::gfx::FeatureStatus,
244 : mozilla::gfx::FeatureStatus::Unused,
245 : mozilla::gfx::FeatureStatus::LAST>
246 : {};
247 :
248 : template <>
249 : struct ParamTraits<mozilla::gfx::AttributeName>
250 : : public ContiguousEnumSerializer<
251 : mozilla::gfx::AttributeName,
252 : mozilla::gfx::eBlendBlendmode,
253 : mozilla::gfx::eLastAttributeName>
254 : {};
255 :
256 : template <>
257 : struct ParamTraits<mozilla::gfx::AttributeType>
258 : : public ContiguousEnumSerializer<
259 : mozilla::gfx::AttributeType,
260 : mozilla::gfx::AttributeType::eBool,
261 : mozilla::gfx::AttributeType::Max>
262 : {};
263 :
264 : template <>
265 : struct ParamTraits<mozilla::gfx::PrimitiveType>
266 : : public ContiguousEnumSerializer<
267 : mozilla::gfx::PrimitiveType,
268 : mozilla::gfx::PrimitiveType::Empty,
269 : mozilla::gfx::PrimitiveType::Max>
270 : {};
271 :
272 : template <>
273 : struct ParamTraits<mozilla::gfx::ColorSpace>
274 : : public ContiguousEnumSerializer<
275 : mozilla::gfx::ColorSpace,
276 : mozilla::gfx::ColorSpace::SRGB,
277 : mozilla::gfx::ColorSpace::Max>
278 : {};
279 :
280 : /*
281 : template <>
282 : struct ParamTraits<mozilla::PixelFormat>
283 : : public EnumSerializer<mozilla::PixelFormat,
284 : SurfaceFormat::A8R8G8B8_UINT32,
285 : SurfaceFormat::UNKNOWN>
286 : {};
287 : */
288 :
289 : template<>
290 : struct ParamTraits<mozilla::gfx::Color>
291 : {
292 : typedef mozilla::gfx::Color paramType;
293 :
294 31 : static void Write(Message* msg, const paramType& param)
295 : {
296 31 : WriteParam(msg, param.r);
297 31 : WriteParam(msg, param.g);
298 31 : WriteParam(msg, param.b);
299 31 : WriteParam(msg, param.a);
300 31 : }
301 :
302 31 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
303 : {
304 62 : return (ReadParam(msg, iter, &result->r) &&
305 62 : ReadParam(msg, iter, &result->g) &&
306 93 : ReadParam(msg, iter, &result->b) &&
307 62 : ReadParam(msg, iter, &result->a));
308 : }
309 : };
310 :
311 : template<>
312 : struct ParamTraits<nsPoint>
313 : {
314 : typedef nsPoint paramType;
315 :
316 27 : static void Write(Message* msg, const paramType& param)
317 : {
318 27 : WriteParam(msg, param.x);
319 27 : WriteParam(msg, param.y);
320 27 : }
321 :
322 27 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
323 : {
324 54 : return (ReadParam(msg, iter, &result->x) &&
325 54 : ReadParam(msg, iter, &result->y));
326 : }
327 : };
328 :
329 : template<>
330 : struct ParamTraits<nsIntPoint>
331 : {
332 : typedef nsIntPoint paramType;
333 :
334 33 : static void Write(Message* msg, const paramType& param)
335 : {
336 33 : WriteParam(msg, param.x);
337 33 : WriteParam(msg, param.y);
338 33 : }
339 :
340 33 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
341 : {
342 66 : return (ReadParam(msg, iter, &result->x) &&
343 66 : ReadParam(msg, iter, &result->y));
344 : }
345 : };
346 :
347 : template<typename T>
348 : struct ParamTraits<mozilla::gfx::IntSizeTyped<T> >
349 : {
350 : typedef mozilla::gfx::IntSizeTyped<T> paramType;
351 :
352 55 : static void Write(Message* msg, const paramType& param)
353 : {
354 55 : WriteParam(msg, param.width);
355 55 : WriteParam(msg, param.height);
356 55 : }
357 :
358 55 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
359 : {
360 110 : return (ReadParam(msg, iter, &result->width) &&
361 110 : ReadParam(msg, iter, &result->height));
362 : }
363 : };
364 :
365 : template<typename Region, typename Rect, typename Iter>
366 : struct RegionParamTraits
367 : {
368 : typedef Region paramType;
369 :
370 983 : static void Write(Message* msg, const paramType& param)
371 : {
372 :
373 1318 : for (auto iter = param.RectIter(); !iter.Done(); iter.Next()) {
374 335 : const Rect& r = iter.Get();
375 335 : MOZ_RELEASE_ASSERT(!r.IsEmpty(), "GFX: rect is empty.");
376 335 : WriteParam(msg, r);
377 : }
378 : // empty rects are sentinel values because nsRegions will never
379 : // contain them
380 983 : WriteParam(msg, Rect());
381 983 : }
382 :
383 983 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
384 : {
385 1966 : RegionBuilder<Region> builder;
386 983 : Rect rect;
387 1653 : while (ReadParam(msg, iter, &rect)) {
388 1318 : if (rect.IsEmpty()) {
389 983 : *result = builder.ToRegion();
390 983 : return true;
391 : }
392 335 : builder.OrWith(rect);
393 : }
394 :
395 0 : return false;
396 : }
397 : };
398 :
399 : template<class Units>
400 : struct ParamTraits<mozilla::gfx::IntRegionTyped<Units>>
401 : : RegionParamTraits<mozilla::gfx::IntRegionTyped<Units>,
402 : mozilla::gfx::IntRectTyped<Units>,
403 : typename mozilla::gfx::IntRegionTyped<Units>::RectIterator>
404 : {};
405 :
406 : template<>
407 : struct ParamTraits<mozilla::gfx::IntSize>
408 : {
409 : typedef mozilla::gfx::IntSize paramType;
410 :
411 11 : static void Write(Message* msg, const paramType& param)
412 : {
413 11 : WriteParam(msg, param.width);
414 11 : WriteParam(msg, param.height);
415 11 : }
416 :
417 11 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
418 : {
419 22 : return (ReadParam(msg, iter, &result->width) &&
420 22 : ReadParam(msg, iter, &result->height));
421 : }
422 : };
423 :
424 : template<class T>
425 : struct ParamTraits< mozilla::gfx::CoordTyped<T> >
426 : {
427 : typedef mozilla::gfx::CoordTyped<T> paramType;
428 :
429 0 : static void Write(Message* msg, const paramType& param)
430 : {
431 0 : WriteParam(msg, param.value);
432 0 : }
433 :
434 0 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
435 : {
436 0 : return (ReadParam(msg, iter, &result->value));
437 : }
438 : };
439 :
440 : template<class T>
441 : struct ParamTraits< mozilla::gfx::IntCoordTyped<T> >
442 : {
443 : typedef mozilla::gfx::IntCoordTyped<T> paramType;
444 :
445 : static void Write(Message* msg, const paramType& param)
446 : {
447 : WriteParam(msg, param.value);
448 : }
449 :
450 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
451 : {
452 : return (ReadParam(msg, iter, &result->value));
453 : }
454 : };
455 :
456 : template<class T, class U>
457 : struct ParamTraits< mozilla::gfx::ScaleFactor<T, U> >
458 : {
459 : typedef mozilla::gfx::ScaleFactor<T, U> paramType;
460 :
461 33 : static void Write(Message* msg, const paramType& param)
462 : {
463 33 : WriteParam(msg, param.scale);
464 33 : }
465 :
466 33 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
467 : {
468 33 : return (ReadParam(msg, iter, &result->scale));
469 : }
470 : };
471 :
472 : template<class T, class U>
473 : struct ParamTraits< mozilla::gfx::ScaleFactors2D<T, U> >
474 : {
475 : typedef mozilla::gfx::ScaleFactors2D<T, U> paramType;
476 :
477 81 : static void Write(Message* msg, const paramType& param)
478 : {
479 81 : WriteParam(msg, param.xScale);
480 81 : WriteParam(msg, param.yScale);
481 81 : }
482 :
483 81 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
484 : {
485 162 : return (ReadParam(msg, iter, &result->xScale) &&
486 162 : ReadParam(msg, iter, &result->yScale));
487 : }
488 : };
489 :
490 : template<class T>
491 : struct ParamTraits< mozilla::gfx::PointTyped<T> >
492 : {
493 : typedef mozilla::gfx::PointTyped<T> paramType;
494 :
495 54 : static void Write(Message* msg, const paramType& param)
496 : {
497 54 : WriteParam(msg, param.x);
498 54 : WriteParam(msg, param.y);
499 54 : }
500 :
501 54 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
502 : {
503 108 : return (ReadParam(msg, iter, &result->x) &&
504 108 : ReadParam(msg, iter, &result->y));
505 : }
506 : };
507 :
508 : template<class F, class T>
509 : struct ParamTraits< mozilla::gfx::Point3DTyped<F, T> >
510 : {
511 : typedef mozilla::gfx::Point3DTyped<F, T> paramType;
512 :
513 0 : static void Write(Message* msg, const paramType& param)
514 : {
515 0 : WriteParam(msg, param.x);
516 0 : WriteParam(msg, param.y);
517 0 : WriteParam(msg, param.z);
518 0 : }
519 :
520 0 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
521 : {
522 0 : return (ReadParam(msg, iter, &result->x) &&
523 0 : ReadParam(msg, iter, &result->y) &&
524 0 : ReadParam(msg, iter, &result->z));
525 : }
526 : };
527 :
528 : template<class T>
529 : struct ParamTraits< mozilla::gfx::IntPointTyped<T> >
530 : {
531 : typedef mozilla::gfx::IntPointTyped<T> paramType;
532 :
533 14 : static void Write(Message* msg, const paramType& param)
534 : {
535 14 : WriteParam(msg, param.x);
536 14 : WriteParam(msg, param.y);
537 14 : }
538 :
539 12 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
540 : {
541 24 : return (ReadParam(msg, iter, &result->x) &&
542 24 : ReadParam(msg, iter, &result->y));
543 : }
544 : };
545 :
546 : template<class T>
547 : struct ParamTraits< mozilla::gfx::SizeTyped<T> >
548 : {
549 : typedef mozilla::gfx::SizeTyped<T> paramType;
550 :
551 31 : static void Write(Message* msg, const paramType& param)
552 : {
553 31 : WriteParam(msg, param.width);
554 31 : WriteParam(msg, param.height);
555 31 : }
556 :
557 30 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
558 : {
559 60 : return (ReadParam(msg, iter, &result->width) &&
560 60 : ReadParam(msg, iter, &result->height));
561 : }
562 : };
563 :
564 : template<class T>
565 : struct ParamTraits< mozilla::gfx::RectTyped<T> >
566 : {
567 : typedef mozilla::gfx::RectTyped<T> paramType;
568 :
569 139 : static void Write(Message* msg, const paramType& param)
570 : {
571 139 : WriteParam(msg, param.x);
572 139 : WriteParam(msg, param.y);
573 139 : WriteParam(msg, param.width);
574 139 : WriteParam(msg, param.height);
575 139 : }
576 :
577 138 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
578 : {
579 276 : return (ReadParam(msg, iter, &result->x) &&
580 276 : ReadParam(msg, iter, &result->y) &&
581 414 : ReadParam(msg, iter, &result->width) &&
582 276 : ReadParam(msg, iter, &result->height));
583 : }
584 : };
585 :
586 : template<class T>
587 : struct ParamTraits< mozilla::gfx::IntRectTyped<T> >
588 : {
589 : typedef mozilla::gfx::IntRectTyped<T> paramType;
590 :
591 1559 : static void Write(Message* msg, const paramType& param)
592 : {
593 1559 : WriteParam(msg, param.x);
594 1559 : WriteParam(msg, param.y);
595 1559 : WriteParam(msg, param.width);
596 1559 : WriteParam(msg, param.height);
597 1559 : }
598 :
599 1559 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
600 : {
601 3118 : return (ReadParam(msg, iter, &result->x) &&
602 3118 : ReadParam(msg, iter, &result->y) &&
603 4677 : ReadParam(msg, iter, &result->width) &&
604 3118 : ReadParam(msg, iter, &result->height));
605 : }
606 : };
607 :
608 : template<>
609 : struct ParamTraits<mozilla::gfx::Margin>
610 : {
611 : typedef mozilla::gfx::Margin paramType;
612 :
613 : static void Write(Message* msg, const paramType& param)
614 : {
615 : WriteParam(msg, param.top);
616 : WriteParam(msg, param.right);
617 : WriteParam(msg, param.bottom);
618 : WriteParam(msg, param.left);
619 : }
620 :
621 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
622 : {
623 : return (ReadParam(msg, iter, &result->top) &&
624 : ReadParam(msg, iter, &result->right) &&
625 : ReadParam(msg, iter, &result->bottom) &&
626 : ReadParam(msg, iter, &result->left));
627 : }
628 : };
629 :
630 : template<class T>
631 : struct ParamTraits< mozilla::gfx::MarginTyped<T> >
632 : {
633 : typedef mozilla::gfx::MarginTyped<T> paramType;
634 :
635 27 : static void Write(Message* msg, const paramType& param)
636 : {
637 27 : WriteParam(msg, param.top);
638 27 : WriteParam(msg, param.right);
639 27 : WriteParam(msg, param.bottom);
640 27 : WriteParam(msg, param.left);
641 27 : }
642 :
643 27 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
644 : {
645 54 : return (ReadParam(msg, iter, &result->top) &&
646 54 : ReadParam(msg, iter, &result->right) &&
647 81 : ReadParam(msg, iter, &result->bottom) &&
648 54 : ReadParam(msg, iter, &result->left));
649 : }
650 : };
651 :
652 : template<>
653 : struct ParamTraits<nsRect>
654 : {
655 : typedef nsRect paramType;
656 :
657 0 : static void Write(Message* msg, const paramType& param)
658 : {
659 0 : WriteParam(msg, param.x);
660 0 : WriteParam(msg, param.y);
661 0 : WriteParam(msg, param.width);
662 0 : WriteParam(msg, param.height);
663 0 : }
664 :
665 0 : static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
666 : {
667 0 : return (ReadParam(msg, iter, &result->x) &&
668 0 : ReadParam(msg, iter, &result->y) &&
669 0 : ReadParam(msg, iter, &result->width) &&
670 0 : ReadParam(msg, iter, &result->height));
671 : }
672 : };
673 :
674 : template<>
675 : struct ParamTraits<nsRegion>
676 : : RegionParamTraits<nsRegion, nsRect, nsRegion::RectIterator>
677 : {};
678 :
679 : template<>
680 : struct ParamTraits<GeckoProcessType>
681 : : public ContiguousEnumSerializer<
682 : GeckoProcessType,
683 : GeckoProcessType_Default,
684 : GeckoProcessType_End>
685 : {};
686 :
687 : template <>
688 : struct ParamTraits<mozilla::gfx::SurfaceFormat>
689 : : public ContiguousEnumSerializer<
690 : mozilla::gfx::SurfaceFormat,
691 : mozilla::gfx::SurfaceFormat::B8G8R8A8,
692 : mozilla::gfx::SurfaceFormat::UNKNOWN>
693 : {};
694 :
695 : template <>
696 : struct ParamTraits<mozilla::StereoMode>
697 : : public ContiguousEnumSerializer<
698 : mozilla::StereoMode,
699 : mozilla::StereoMode::MONO,
700 : mozilla::StereoMode::MAX>
701 : {};
702 :
703 : template <>
704 : struct ParamTraits<mozilla::YUVColorSpace>
705 : : public ContiguousEnumSerializer<
706 : mozilla::YUVColorSpace,
707 : mozilla::YUVColorSpace::BT601,
708 : mozilla::YUVColorSpace::UNKNOWN>
709 : {};
710 :
711 : template <>
712 : struct ParamTraits<mozilla::gfx::AttributeMap>
713 : {
714 : typedef mozilla::gfx::AttributeMap paramType;
715 :
716 : static void Write(Message* aMsg, const paramType& aParam)
717 : {
718 : WriteParam(aMsg, aParam.Count());
719 : for (auto iter = aParam.ConstIter(); !iter.Done(); iter.Next()) {
720 : mozilla::gfx::AttributeName name =
721 : mozilla::gfx::AttributeName(iter.Key());
722 : mozilla::gfx::AttributeType type =
723 : mozilla::gfx::AttributeMap::GetType(iter.UserData());
724 :
725 : WriteParam(aMsg, type);
726 : WriteParam(aMsg, name);
727 :
728 : switch (type) {
729 :
730 : #define CASE_TYPE(typeName) \
731 : case mozilla::gfx::AttributeType::e##typeName: \
732 : WriteParam(aMsg, aParam.Get##typeName(name)); \
733 : break;
734 :
735 : CASE_TYPE(Bool)
736 : CASE_TYPE(Uint)
737 : CASE_TYPE(Float)
738 : CASE_TYPE(Size)
739 : CASE_TYPE(IntSize)
740 : CASE_TYPE(IntPoint)
741 : CASE_TYPE(Matrix)
742 : CASE_TYPE(Matrix5x4)
743 : CASE_TYPE(Point3D)
744 : CASE_TYPE(Color)
745 : CASE_TYPE(AttributeMap)
746 : CASE_TYPE(Floats)
747 :
748 : #undef CASE_TYPE
749 :
750 : default:
751 : MOZ_CRASH("GFX: unhandled attribute type");
752 : }
753 : }
754 : }
755 :
756 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
757 : {
758 : uint32_t count;
759 : if (!ReadParam(aMsg, aIter, &count)) {
760 : return false;
761 : }
762 : for (uint32_t i = 0; i < count; i++) {
763 : mozilla::gfx::AttributeType type;
764 : if (!ReadParam(aMsg, aIter, &type)) {
765 : return false;
766 : }
767 : mozilla::gfx::AttributeName name;
768 : if (!ReadParam(aMsg, aIter, &name)) {
769 : return false;
770 : }
771 : switch (type) {
772 :
773 : #define HANDLE_TYPE(type, typeName) \
774 : case mozilla::gfx::AttributeType::e##typeName: \
775 : { \
776 : type value; \
777 : if (!ReadParam(aMsg, aIter, &value)) { \
778 : return false; \
779 : } \
780 : aResult->Set(name, value); \
781 : break; \
782 : }
783 :
784 : HANDLE_TYPE(bool, Bool)
785 : HANDLE_TYPE(uint32_t, Uint)
786 : HANDLE_TYPE(float, Float)
787 : HANDLE_TYPE(mozilla::gfx::Size, Size)
788 : HANDLE_TYPE(mozilla::gfx::IntSize, IntSize)
789 : HANDLE_TYPE(mozilla::gfx::IntPoint, IntPoint)
790 : HANDLE_TYPE(mozilla::gfx::Matrix, Matrix)
791 : HANDLE_TYPE(mozilla::gfx::Matrix5x4, Matrix5x4)
792 : HANDLE_TYPE(mozilla::gfx::Point3D, Point3D)
793 : HANDLE_TYPE(mozilla::gfx::Color, Color)
794 : HANDLE_TYPE(mozilla::gfx::AttributeMap, AttributeMap)
795 :
796 : #undef HANDLE_TYPE
797 :
798 : case mozilla::gfx::AttributeType::eFloats:
799 : {
800 : nsTArray<float> value;
801 : if (!ReadParam(aMsg, aIter, &value)) {
802 : return false;
803 : }
804 : aResult->Set(name, &value[0], value.Length());
805 : break;
806 : }
807 : default:
808 : MOZ_CRASH("GFX: unhandled attribute type");
809 : }
810 : }
811 : return true;
812 : }
813 : };
814 :
815 : template <>
816 : struct ParamTraits<mozilla::gfx::FilterPrimitiveDescription>
817 : {
818 : typedef mozilla::gfx::FilterPrimitiveDescription paramType;
819 :
820 : static void Write(Message* aMsg, const paramType& aParam)
821 : {
822 : WriteParam(aMsg, aParam.Type());
823 : WriteParam(aMsg, aParam.PrimitiveSubregion());
824 : WriteParam(aMsg, aParam.FilterSpaceBounds());
825 : WriteParam(aMsg, aParam.IsTainted());
826 : WriteParam(aMsg, aParam.OutputColorSpace());
827 : WriteParam(aMsg, aParam.NumberOfInputs());
828 : for (size_t i = 0; i < aParam.NumberOfInputs(); i++) {
829 : WriteParam(aMsg, aParam.InputPrimitiveIndex(i));
830 : WriteParam(aMsg, aParam.InputColorSpace(i));
831 : }
832 : WriteParam(aMsg, aParam.Attributes());
833 : }
834 :
835 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
836 : {
837 : mozilla::gfx::PrimitiveType type;
838 : mozilla::gfx::IntRect primitiveSubregion;
839 : mozilla::gfx::IntRect filterSpaceBounds;
840 : bool isTainted = false;
841 : mozilla::gfx::ColorSpace outputColorSpace;
842 : size_t numberOfInputs = 0;
843 : if (!ReadParam(aMsg, aIter, &type) ||
844 : !ReadParam(aMsg, aIter, &primitiveSubregion) ||
845 : !ReadParam(aMsg, aIter, &filterSpaceBounds) ||
846 : !ReadParam(aMsg, aIter, &isTainted) ||
847 : !ReadParam(aMsg, aIter, &outputColorSpace) ||
848 : !ReadParam(aMsg, aIter, &numberOfInputs)) {
849 : return false;
850 : }
851 :
852 : aResult->SetType(type);
853 : aResult->SetPrimitiveSubregion(primitiveSubregion);
854 : aResult->SetFilterSpaceBounds(filterSpaceBounds);
855 : aResult->SetIsTainted(isTainted);
856 : aResult->SetOutputColorSpace(outputColorSpace);
857 :
858 : for (size_t i = 0; i < numberOfInputs; i++) {
859 : int32_t inputPrimitiveIndex = 0;
860 : mozilla::gfx::ColorSpace inputColorSpace;
861 : if (!ReadParam(aMsg, aIter, &inputPrimitiveIndex) ||
862 : !ReadParam(aMsg, aIter, &inputColorSpace)) {
863 : return false;
864 : }
865 : aResult->SetInputPrimitive(i, inputPrimitiveIndex);
866 : aResult->SetInputColorSpace(i, inputColorSpace);
867 : }
868 :
869 : return ReadParam(aMsg, aIter, &aResult->Attributes());
870 : }
871 : };
872 :
873 : template <>
874 : struct ParamTraits<mozilla::gfx::FilterDescription>
875 : {
876 : typedef mozilla::gfx::FilterDescription paramType;
877 :
878 : static void Write(Message* aMsg, const paramType& aParam)
879 : {
880 : WriteParam(aMsg, aParam.mPrimitives);
881 : }
882 :
883 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
884 : {
885 : return (ReadParam(aMsg, aIter, &aResult->mPrimitives));
886 : }
887 : };
888 :
889 : template <>
890 : struct ParamTraits<mozilla::gfx::Glyph>
891 : {
892 : typedef mozilla::gfx::Glyph paramType;
893 0 : static void Write(Message* aMsg, const paramType& aParam) {
894 0 : WriteParam(aMsg, aParam.mIndex);
895 0 : WriteParam(aMsg, aParam.mPosition);
896 0 : }
897 :
898 0 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) {
899 0 : return (ReadParam(aMsg, aIter, &aResult->mIndex) &&
900 0 : ReadParam(aMsg, aIter, &aResult->mPosition)
901 0 : );
902 : }
903 : };
904 :
905 : template<typename T, size_t Length>
906 : struct ParamTraits<mozilla::Array<T, Length>>
907 : {
908 : typedef mozilla::Array<T, Length> paramType;
909 0 : static void Write(Message* aMsg, const paramType& aParam) {
910 0 : for (size_t i = 0; i < Length; i++) {
911 0 : WriteParam(aMsg, aParam[i]);
912 : }
913 0 : }
914 :
915 0 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) {
916 0 : for (size_t i = 0; i < Length; i++) {
917 0 : if (!ReadParam<T>(aMsg, aIter, &aResult->operator[](i))) {
918 0 : return false;
919 : }
920 : }
921 0 : return true;
922 : }
923 : };
924 :
925 :
926 : } /* namespace IPC */
927 :
928 : #endif /* __GFXMESSAGEUTILS_H__ */
|