GfxMessageUtils.h (40639B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef __GFXMESSAGEUTILS_H__ 8 #define __GFXMESSAGEUTILS_H__ 9 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/ProtocolMessageUtils.h" 34 #include "mozilla/ipc/ProtocolUtils.h" 35 #include "mozilla/ipc/ShmemMessageUtils.h" 36 37 #include <stdint.h> 38 39 #ifdef _MSC_VER 40 # pragma warning(disable : 4800) 41 #endif 42 43 namespace mozilla { 44 45 typedef gfxImageFormat PixelFormat; 46 47 } // namespace mozilla 48 49 namespace IPC { 50 51 template <> 52 struct ParamTraits<mozilla::gfx::Matrix> { 53 typedef mozilla::gfx::Matrix paramType; 54 55 static void Write(MessageWriter* aWriter, const paramType& aParam) { 56 WriteParam(aWriter, aParam._11); 57 WriteParam(aWriter, aParam._12); 58 WriteParam(aWriter, aParam._21); 59 WriteParam(aWriter, aParam._22); 60 WriteParam(aWriter, aParam._31); 61 WriteParam(aWriter, aParam._32); 62 } 63 64 static bool Read(MessageReader* aReader, paramType* aResult) { 65 if (ReadParam(aReader, &aResult->_11) && 66 ReadParam(aReader, &aResult->_12) && 67 ReadParam(aReader, &aResult->_21) && 68 ReadParam(aReader, &aResult->_22) && 69 ReadParam(aReader, &aResult->_31) && ReadParam(aReader, &aResult->_32)) 70 return true; 71 72 return false; 73 } 74 }; 75 76 template <class SourceUnits, class TargetUnits, class T> 77 struct ParamTraits<mozilla::gfx::Matrix4x4Typed<SourceUnits, TargetUnits, T>> { 78 typedef mozilla::gfx::Matrix4x4Typed<SourceUnits, TargetUnits, T> paramType; 79 80 static void Write(MessageWriter* writer, const paramType& param) { 81 #define Wr(_f) WriteParam(writer, param._f) 82 Wr(_11); 83 Wr(_12); 84 Wr(_13); 85 Wr(_14); 86 Wr(_21); 87 Wr(_22); 88 Wr(_23); 89 Wr(_24); 90 Wr(_31); 91 Wr(_32); 92 Wr(_33); 93 Wr(_34); 94 Wr(_41); 95 Wr(_42); 96 Wr(_43); 97 Wr(_44); 98 #undef Wr 99 } 100 101 static bool Read(MessageReader* reader, paramType* result) { 102 #define Rd(_f) ReadParam(reader, &result->_f) 103 return (Rd(_11) && Rd(_12) && Rd(_13) && Rd(_14) && Rd(_21) && Rd(_22) && 104 Rd(_23) && Rd(_24) && Rd(_31) && Rd(_32) && Rd(_33) && Rd(_34) && 105 Rd(_41) && Rd(_42) && Rd(_43) && Rd(_44)); 106 #undef Rd 107 } 108 }; 109 110 template <> 111 struct ParamTraits<mozilla::gfx::Matrix5x4> { 112 typedef mozilla::gfx::Matrix5x4 paramType; 113 114 static void Write(MessageWriter* writer, const paramType& param) { 115 #define Wr(_f) WriteParam(writer, param._f) 116 Wr(_11); 117 Wr(_12); 118 Wr(_13); 119 Wr(_14); 120 Wr(_21); 121 Wr(_22); 122 Wr(_23); 123 Wr(_24); 124 Wr(_31); 125 Wr(_32); 126 Wr(_33); 127 Wr(_34); 128 Wr(_41); 129 Wr(_42); 130 Wr(_43); 131 Wr(_44); 132 Wr(_51); 133 Wr(_52); 134 Wr(_53); 135 Wr(_54); 136 #undef Wr 137 } 138 139 static bool Read(MessageReader* reader, paramType* result) { 140 #define Rd(_f) ReadParam(reader, &result->_f) 141 return (Rd(_11) && Rd(_12) && Rd(_13) && Rd(_14) && Rd(_21) && Rd(_22) && 142 Rd(_23) && Rd(_24) && Rd(_31) && Rd(_32) && Rd(_33) && Rd(_34) && 143 Rd(_41) && Rd(_42) && Rd(_43) && Rd(_44) && Rd(_51) && Rd(_52) && 144 Rd(_53) && Rd(_54)); 145 #undef Rd 146 } 147 }; 148 149 template <> 150 struct ParamTraits<gfxPoint> { 151 typedef gfxPoint paramType; 152 153 static void Write(MessageWriter* aWriter, const paramType& aParam) { 154 WriteParam(aWriter, aParam.x.value); 155 WriteParam(aWriter, aParam.y.value); 156 } 157 158 static bool Read(MessageReader* aReader, paramType* aResult) { 159 return (ReadParam(aReader, &aResult->x.value) && 160 ReadParam(aReader, &aResult->y.value)); 161 } 162 }; 163 164 template <> 165 struct ParamTraits<gfxSize> { 166 typedef gfxSize paramType; 167 168 static void Write(MessageWriter* aWriter, const paramType& aParam) { 169 WriteParam(aWriter, aParam.width); 170 WriteParam(aWriter, aParam.height); 171 } 172 173 static bool Read(MessageReader* aReader, paramType* aResult) { 174 if (ReadParam(aReader, &aResult->width) && 175 ReadParam(aReader, &aResult->height)) 176 return true; 177 178 return false; 179 } 180 }; 181 182 template <> 183 struct ParamTraits<gfxRect> { 184 typedef gfxRect paramType; 185 186 static void Write(MessageWriter* aWriter, const paramType& aParam) { 187 WriteParam(aWriter, aParam.X()); 188 WriteParam(aWriter, aParam.Y()); 189 WriteParam(aWriter, aParam.Width()); 190 WriteParam(aWriter, aParam.Height()); 191 } 192 193 static bool Read(MessageReader* aReader, paramType* aResult) { 194 auto x = aResult->X(); 195 auto y = aResult->Y(); 196 auto w = aResult->Width(); 197 auto h = aResult->Height(); 198 199 bool retVal = (ReadParam(aReader, &x) && ReadParam(aReader, &y) && 200 ReadParam(aReader, &w) && ReadParam(aReader, &h)); 201 aResult->SetRect(x, y, w, h); 202 return retVal; 203 } 204 }; 205 206 template <> 207 struct ParamTraits<gfxContentType> 208 : public ContiguousEnumSerializer<gfxContentType, gfxContentType::COLOR, 209 gfxContentType::SENTINEL> {}; 210 211 template <> 212 struct ParamTraits<gfxSurfaceType> 213 : public ContiguousEnumSerializer<gfxSurfaceType, gfxSurfaceType::Image, 214 gfxSurfaceType::Max> {}; 215 216 template <> 217 struct ParamTraits<mozilla::gfx::SamplingFilter> 218 : public ContiguousEnumSerializer<mozilla::gfx::SamplingFilter, 219 mozilla::gfx::SamplingFilter::GOOD, 220 mozilla::gfx::SamplingFilter::SENTINEL> { 221 }; 222 223 template <> 224 struct ParamTraits<mozilla::gfx::BackendType> 225 : public ContiguousEnumSerializer<mozilla::gfx::BackendType, 226 mozilla::gfx::BackendType::NONE, 227 mozilla::gfx::BackendType::BACKEND_LAST> { 228 }; 229 230 template <> 231 struct ParamTraits<mozilla::gfx::Feature> 232 : public ContiguousEnumSerializer<mozilla::gfx::Feature, 233 mozilla::gfx::Feature::HW_COMPOSITING, 234 mozilla::gfx::Feature::NumValues> {}; 235 236 template <> 237 struct ParamTraits<mozilla::gfx::Fallback> 238 : public ContiguousEnumSerializer< 239 mozilla::gfx::Fallback, 240 mozilla::gfx::Fallback::NO_CONSTANT_BUFFER_OFFSETTING, 241 mozilla::gfx::Fallback::NumValues> {}; 242 243 template <> 244 struct ParamTraits<mozilla::gfx::FeatureStatus> 245 : public ContiguousEnumSerializer<mozilla::gfx::FeatureStatus, 246 mozilla::gfx::FeatureStatus::Unused, 247 mozilla::gfx::FeatureStatus::LAST> {}; 248 249 template <> 250 struct ParamTraits<mozilla::gfx::LightType> 251 : public ContiguousEnumSerializer<mozilla::gfx::LightType, 252 mozilla::gfx::LightType::None, 253 mozilla::gfx::LightType::Max> {}; 254 255 template <> 256 struct ParamTraits<mozilla::gfx::ColorSpace> 257 : public ContiguousEnumSerializer<mozilla::gfx::ColorSpace, 258 mozilla::gfx::ColorSpace::SRGB, 259 mozilla::gfx::ColorSpace::Max> {}; 260 261 template <> 262 struct ParamTraits<mozilla::gfx::CompositionOp> 263 : public ContiguousEnumSerializerInclusive< 264 mozilla::gfx::CompositionOp, mozilla::gfx::CompositionOp::OP_OVER, 265 mozilla::gfx::CompositionOp::OP_COUNT> {}; 266 267 /* 268 template <> 269 struct ParamTraits<mozilla::PixelFormat> 270 : public EnumSerializer<mozilla::PixelFormat, 271 SurfaceFormat::A8R8G8B8_UINT32, 272 SurfaceFormat::UNKNOWN> 273 {}; 274 */ 275 276 template <> 277 struct ParamTraits<mozilla::gfx::sRGBColor> { 278 typedef mozilla::gfx::sRGBColor paramType; 279 280 static void Write(MessageWriter* writer, const paramType& param) { 281 WriteParam(writer, param.r); 282 WriteParam(writer, param.g); 283 WriteParam(writer, param.b); 284 WriteParam(writer, param.a); 285 } 286 287 static bool Read(MessageReader* reader, paramType* result) { 288 return (ReadParam(reader, &result->r) && ReadParam(reader, &result->g) && 289 ReadParam(reader, &result->b) && ReadParam(reader, &result->a)); 290 } 291 }; 292 293 template <> 294 struct ParamTraits<mozilla::gfx::DeviceColor> { 295 typedef mozilla::gfx::DeviceColor paramType; 296 297 static void Write(MessageWriter* writer, const paramType& param) { 298 WriteParam(writer, param.r); 299 WriteParam(writer, param.g); 300 WriteParam(writer, param.b); 301 WriteParam(writer, param.a); 302 } 303 304 static bool Read(MessageReader* reader, paramType* result) { 305 return (ReadParam(reader, &result->r) && ReadParam(reader, &result->g) && 306 ReadParam(reader, &result->b) && ReadParam(reader, &result->a)); 307 } 308 }; 309 310 template <> 311 struct ParamTraits<nsPoint> { 312 typedef nsPoint paramType; 313 314 static void Write(MessageWriter* writer, const paramType& param) { 315 WriteParam(writer, param.x); 316 WriteParam(writer, param.y); 317 } 318 319 static bool Read(MessageReader* reader, paramType* result) { 320 return (ReadParam(reader, &result->x) && ReadParam(reader, &result->y)); 321 } 322 }; 323 324 template <> 325 struct ParamTraits<nsIntPoint> { 326 typedef nsIntPoint paramType; 327 328 static void Write(MessageWriter* writer, const paramType& param) { 329 WriteParam(writer, param.x); 330 WriteParam(writer, param.y); 331 } 332 333 static bool Read(MessageReader* reader, paramType* result) { 334 return (ReadParam(reader, &result->x) && ReadParam(reader, &result->y)); 335 } 336 }; 337 338 template <typename T> 339 struct ParamTraits<mozilla::gfx::IntSizeTyped<T>> { 340 typedef mozilla::gfx::IntSizeTyped<T> paramType; 341 342 static void Write(MessageWriter* writer, const paramType& param) { 343 WriteParam(writer, param.width); 344 WriteParam(writer, param.height); 345 } 346 347 static bool Read(MessageReader* reader, paramType* result) { 348 return (ReadParam(reader, &result->width) && 349 ReadParam(reader, &result->height)); 350 } 351 }; 352 353 template <typename Region, typename Rect, typename Iter> 354 struct RegionParamTraits { 355 typedef Region paramType; 356 357 static void Write(MessageWriter* writer, const paramType& param) { 358 for (auto iter = param.RectIter(); !iter.Done(); iter.Next()) { 359 const Rect& r = iter.Get(); 360 MOZ_RELEASE_ASSERT(!r.IsEmpty(), "GFX: rect is empty."); 361 WriteParam(writer, r); 362 } 363 // empty rects are sentinel values because nsRegions will never 364 // contain them 365 WriteParam(writer, Rect()); 366 } 367 368 static bool Read(MessageReader* reader, paramType* result) { 369 RegionBuilder<Region> builder; 370 Rect rect; 371 while (ReadParam(reader, &rect)) { 372 if (rect.IsEmpty()) { 373 *result = builder.ToRegion(); 374 return true; 375 } 376 builder.OrWith(rect); 377 } 378 379 return false; 380 } 381 }; 382 383 template <class Units> 384 struct ParamTraits<mozilla::gfx::IntRegionTyped<Units>> 385 : RegionParamTraits< 386 mozilla::gfx::IntRegionTyped<Units>, 387 mozilla::gfx::IntRectTyped<Units>, 388 typename mozilla::gfx::IntRegionTyped<Units>::RectIterator> {}; 389 390 template <> 391 struct ParamTraits<mozilla::gfx::IntSize> { 392 typedef mozilla::gfx::IntSize paramType; 393 394 static void Write(MessageWriter* writer, const paramType& param) { 395 WriteParam(writer, param.width); 396 WriteParam(writer, param.height); 397 } 398 399 static bool Read(MessageReader* reader, paramType* result) { 400 return (ReadParam(reader, &result->width) && 401 ReadParam(reader, &result->height)); 402 } 403 }; 404 405 template <class T> 406 struct ParamTraits<mozilla::gfx::CoordTyped<T>> { 407 typedef mozilla::gfx::CoordTyped<T> paramType; 408 409 static void Write(MessageWriter* writer, const paramType& param) { 410 WriteParam(writer, param.value); 411 } 412 413 static bool Read(MessageReader* reader, paramType* result) { 414 return (ReadParam(reader, &result->value)); 415 } 416 }; 417 418 template <class T> 419 struct ParamTraits<mozilla::gfx::IntCoordTyped<T>> { 420 typedef mozilla::gfx::IntCoordTyped<T> paramType; 421 422 static void Write(MessageWriter* writer, const paramType& param) { 423 WriteParam(writer, param.value); 424 } 425 426 static bool Read(MessageReader* reader, paramType* result) { 427 return (ReadParam(reader, &result->value)); 428 } 429 }; 430 431 template <class T, class U> 432 struct ParamTraits<mozilla::gfx::ScaleFactor<T, U>> { 433 typedef mozilla::gfx::ScaleFactor<T, U> paramType; 434 435 static void Write(MessageWriter* writer, const paramType& param) { 436 WriteParam(writer, param.scale); 437 } 438 439 static bool Read(MessageReader* reader, paramType* result) { 440 return (ReadParam(reader, &result->scale)); 441 } 442 }; 443 444 template <class T, class U> 445 struct ParamTraits<mozilla::gfx::ScaleFactors2D<T, U>> { 446 typedef mozilla::gfx::ScaleFactors2D<T, U> paramType; 447 448 static void Write(MessageWriter* writer, const paramType& param) { 449 WriteParam(writer, param.xScale); 450 WriteParam(writer, param.yScale); 451 } 452 453 static bool Read(MessageReader* reader, paramType* result) { 454 return (ReadParam(reader, &result->xScale) && 455 ReadParam(reader, &result->yScale)); 456 } 457 }; 458 459 template <class T> 460 struct ParamTraits<mozilla::gfx::PointTyped<T>> { 461 typedef mozilla::gfx::PointTyped<T> paramType; 462 463 static void Write(MessageWriter* writer, const paramType& param) { 464 WriteParam(writer, param.x); 465 WriteParam(writer, param.y); 466 } 467 468 static bool Read(MessageReader* reader, paramType* result) { 469 return (ReadParam(reader, &result->x) && ReadParam(reader, &result->y)); 470 } 471 }; 472 473 template <class F, class T> 474 struct ParamTraits<mozilla::gfx::Point3DTyped<F, T>> { 475 typedef mozilla::gfx::Point3DTyped<F, T> paramType; 476 477 static void Write(MessageWriter* writer, const paramType& param) { 478 WriteParam(writer, param.x); 479 WriteParam(writer, param.y); 480 WriteParam(writer, param.z); 481 } 482 483 static bool Read(MessageReader* reader, paramType* result) { 484 return (ReadParam(reader, &result->x) && ReadParam(reader, &result->y) && 485 ReadParam(reader, &result->z)); 486 } 487 }; 488 489 template <class T> 490 struct ParamTraits<mozilla::gfx::IntPointTyped<T>> { 491 typedef mozilla::gfx::IntPointTyped<T> paramType; 492 493 static void Write(MessageWriter* writer, const paramType& param) { 494 WriteParam(writer, param.x); 495 WriteParam(writer, param.y); 496 } 497 498 static bool Read(MessageReader* reader, paramType* result) { 499 return (ReadParam(reader, &result->x) && ReadParam(reader, &result->y)); 500 } 501 }; 502 503 template <class T> 504 struct ParamTraits<mozilla::gfx::SizeTyped<T>> { 505 typedef mozilla::gfx::SizeTyped<T> paramType; 506 507 static void Write(MessageWriter* writer, const paramType& param) { 508 WriteParam(writer, param.width); 509 WriteParam(writer, param.height); 510 } 511 512 static bool Read(MessageReader* reader, paramType* result) { 513 return (ReadParam(reader, &result->width) && 514 ReadParam(reader, &result->height)); 515 } 516 }; 517 518 template <class T> 519 struct ParamTraits<mozilla::gfx::RectTyped<T>> { 520 typedef mozilla::gfx::RectTyped<T> paramType; 521 522 static void Write(MessageWriter* writer, const paramType& param) { 523 WriteParam(writer, param.X()); 524 WriteParam(writer, param.Y()); 525 WriteParam(writer, param.Width()); 526 WriteParam(writer, param.Height()); 527 } 528 529 static bool Read(MessageReader* reader, paramType* result) { 530 auto x = result->X(); 531 auto y = result->Y(); 532 auto w = result->Width(); 533 auto h = result->Height(); 534 535 bool retVal = (ReadParam(reader, &x) && ReadParam(reader, &y) && 536 ReadParam(reader, &w) && ReadParam(reader, &h)); 537 result->SetRect(x, y, w, h); 538 return retVal; 539 } 540 }; 541 542 template <class T> 543 struct ParamTraits<mozilla::gfx::RectAbsoluteTyped<T>> { 544 typedef mozilla::gfx::RectAbsoluteTyped<T> paramType; 545 546 static void Write(MessageWriter* writer, const paramType& param) { 547 WriteParam(writer, param.Left()); 548 WriteParam(writer, param.Top()); 549 WriteParam(writer, param.Right()); 550 WriteParam(writer, param.Bottom()); 551 } 552 553 static bool Read(MessageReader* reader, paramType* result) { 554 auto l = result->Left(); 555 auto t = result->Top(); 556 auto r = result->Right(); 557 auto b = result->Bottom(); 558 559 bool retVal = (ReadParam(reader, &l) && ReadParam(reader, &t) && 560 ReadParam(reader, &r) && ReadParam(reader, &b)); 561 result->SetBox(l, t, r, b); 562 return retVal; 563 } 564 }; 565 566 template <class T> 567 struct ParamTraits<mozilla::gfx::IntRectTyped<T>> { 568 typedef mozilla::gfx::IntRectTyped<T> paramType; 569 570 static void Write(MessageWriter* writer, const paramType& param) { 571 WriteParam(writer, param.X()); 572 WriteParam(writer, param.Y()); 573 WriteParam(writer, param.Width()); 574 WriteParam(writer, param.Height()); 575 } 576 577 static bool Read(MessageReader* reader, paramType* result) { 578 auto x = result->X(); 579 auto y = result->Y(); 580 auto w = result->Width(); 581 auto h = result->Height(); 582 583 bool retVal = (ReadParam(reader, &x) && ReadParam(reader, &y) && 584 ReadParam(reader, &w) && ReadParam(reader, &h)); 585 result->SetRect(x, y, w, h); 586 return retVal; 587 } 588 }; 589 590 template <> 591 struct ParamTraits<mozilla::gfx::RectCornerRadii> { 592 typedef mozilla::gfx::RectCornerRadii paramType; 593 594 static void Write(MessageWriter* writer, const paramType& param) { 595 for (const auto& i : param.radii) { 596 WriteParam(writer, i); 597 } 598 } 599 600 static bool Read(MessageReader* reader, paramType* result) { 601 for (auto& i : result->radii) { 602 if (!ReadParam(reader, &i)) { 603 return false; 604 } 605 } 606 return true; 607 } 608 }; 609 610 template <> 611 struct ParamTraits<mozilla::gfx::RoundedRect> { 612 typedef mozilla::gfx::RoundedRect paramType; 613 614 static void Write(MessageWriter* writer, const paramType& param) { 615 WriteParam(writer, param.rect); 616 WriteParam(writer, param.corners); 617 } 618 619 static bool Read(MessageReader* reader, paramType* result) { 620 return ReadParam(reader, &result->rect) && 621 ReadParam(reader, &result->corners); 622 } 623 }; 624 625 template <> 626 struct ParamTraits<mozilla::gfx::Margin> { 627 typedef mozilla::gfx::Margin paramType; 628 629 static void Write(MessageWriter* writer, const paramType& param) { 630 WriteParam(writer, param.top); 631 WriteParam(writer, param.right); 632 WriteParam(writer, param.bottom); 633 WriteParam(writer, param.left); 634 } 635 636 static bool Read(MessageReader* reader, paramType* result) { 637 return ( 638 ReadParam(reader, &result->top) && ReadParam(reader, &result->right) && 639 ReadParam(reader, &result->bottom) && ReadParam(reader, &result->left)); 640 } 641 }; 642 643 template <class T> 644 struct ParamTraits<mozilla::gfx::MarginTyped<T>> { 645 typedef mozilla::gfx::MarginTyped<T> paramType; 646 647 static void Write(MessageWriter* writer, const paramType& param) { 648 WriteParam(writer, param.top); 649 WriteParam(writer, param.right); 650 WriteParam(writer, param.bottom); 651 WriteParam(writer, param.left); 652 } 653 654 static bool Read(MessageReader* reader, paramType* result) { 655 return ( 656 ReadParam(reader, &result->top) && ReadParam(reader, &result->right) && 657 ReadParam(reader, &result->bottom) && ReadParam(reader, &result->left)); 658 } 659 }; 660 661 template <class T> 662 struct ParamTraits<mozilla::gfx::IntMarginTyped<T>> { 663 typedef mozilla::gfx::IntMarginTyped<T> paramType; 664 665 static void Write(MessageWriter* writer, const paramType& param) { 666 WriteParam(writer, param.top); 667 WriteParam(writer, param.right); 668 WriteParam(writer, param.bottom); 669 WriteParam(writer, param.left); 670 } 671 672 static bool Read(MessageReader* reader, paramType* result) { 673 return ( 674 ReadParam(reader, &result->top) && ReadParam(reader, &result->right) && 675 ReadParam(reader, &result->bottom) && ReadParam(reader, &result->left)); 676 } 677 }; 678 679 template <> 680 struct ParamTraits<nsRect> { 681 typedef nsRect paramType; 682 683 static void Write(MessageWriter* writer, const paramType& param) { 684 WriteParam(writer, param.X()); 685 WriteParam(writer, param.Y()); 686 WriteParam(writer, param.Width()); 687 WriteParam(writer, param.Height()); 688 } 689 690 static bool Read(MessageReader* reader, paramType* result) { 691 auto x = result->X(); 692 auto y = result->Y(); 693 auto w = result->Width(); 694 auto h = result->Height(); 695 bool retVal = (ReadParam(reader, &x) && ReadParam(reader, &y) && 696 ReadParam(reader, &w) && ReadParam(reader, &h)); 697 result->SetRect(x, y, w, h); 698 return retVal; 699 } 700 }; 701 702 template <> 703 struct ParamTraits<nsRegion> 704 : RegionParamTraits<nsRegion, nsRect, nsRegion::RectIterator> {}; 705 706 template <> 707 struct ParamTraits<GeckoProcessType> 708 : public ContiguousEnumSerializer< 709 GeckoProcessType, GeckoProcessType_Default, GeckoProcessType_End> {}; 710 711 template <> 712 struct ParamTraits<mozilla::gfx::SurfaceFormat> 713 : public ContiguousEnumSerializer<mozilla::gfx::SurfaceFormat, 714 mozilla::gfx::SurfaceFormat::B8G8R8A8, 715 mozilla::gfx::SurfaceFormat::UNKNOWN> {}; 716 717 template <> 718 struct ParamTraits<mozilla::gfx::ColorDepth> 719 : public ContiguousEnumSerializerInclusive< 720 mozilla::gfx::ColorDepth, mozilla::gfx::ColorDepth::_First, 721 mozilla::gfx::ColorDepth::_Last> {}; 722 723 template <> 724 struct ParamTraits<mozilla::gfx::TransferFunction> 725 : public ContiguousEnumSerializerInclusive< 726 mozilla::gfx::TransferFunction, 727 mozilla::gfx::TransferFunction::_First, 728 mozilla::gfx::TransferFunction::_Last> {}; 729 730 template <> 731 struct ParamTraits<mozilla::gfx::ColorRange> 732 : public ContiguousEnumSerializerInclusive< 733 mozilla::gfx::ColorRange, mozilla::gfx::ColorRange::_First, 734 mozilla::gfx::ColorRange::_Last> {}; 735 736 template <> 737 struct ParamTraits<mozilla::gfx::YUVColorSpace> 738 : public ContiguousEnumSerializerInclusive< 739 mozilla::gfx::YUVColorSpace, mozilla::gfx::YUVColorSpace::_First, 740 mozilla::gfx::YUVColorSpace::_Last> {}; 741 742 template <> 743 struct ParamTraits<mozilla::gfx::YUVRangedColorSpace> 744 : public ContiguousEnumSerializerInclusive< 745 mozilla::gfx::YUVRangedColorSpace, 746 mozilla::gfx::YUVRangedColorSpace::_First, 747 mozilla::gfx::YUVRangedColorSpace::_Last> {}; 748 749 template <> 750 struct ParamTraits<mozilla::gfx::ColorSpace2> 751 : public ContiguousEnumSerializerInclusive< 752 mozilla::gfx::ColorSpace2, mozilla::gfx::ColorSpace2::_First, 753 mozilla::gfx::ColorSpace2::_Last> {}; 754 755 template <> 756 struct ParamTraits<mozilla::StereoMode> 757 : public ContiguousEnumSerializer<mozilla::StereoMode, 758 mozilla::StereoMode::MONO, 759 mozilla::StereoMode::MAX> {}; 760 761 template <> 762 struct ParamTraits<mozilla::gfx::ChromaSubsampling> 763 : public ContiguousEnumSerializerInclusive< 764 mozilla::gfx::ChromaSubsampling, 765 mozilla::gfx::ChromaSubsampling::_First, 766 mozilla::gfx::ChromaSubsampling::_Last> {}; 767 768 template <> 769 struct ParamTraits<mozilla::gfx::DeviceResetReason> 770 : public ContiguousEnumSerializerInclusive< 771 mozilla::gfx::DeviceResetReason, 772 mozilla::gfx::DeviceResetReason::_First, 773 mozilla::gfx::DeviceResetReason::_Last> {}; 774 775 template <> 776 struct ParamTraits<mozilla::gfx::DeviceResetDetectPlace> 777 : public ContiguousEnumSerializerInclusive< 778 mozilla::gfx::DeviceResetDetectPlace, 779 mozilla::gfx::DeviceResetDetectPlace::_First, 780 mozilla::gfx::DeviceResetDetectPlace::_Last> {}; 781 782 template <> 783 struct ParamTraits<mozilla::gfx::ImplicitlyCopyableFloatArray> 784 : public ParamTraits<nsTArray<float>> { 785 typedef mozilla::gfx::ImplicitlyCopyableFloatArray paramType; 786 }; 787 788 template <> 789 struct ParamTraits<mozilla::gfx::EmptyAttributes> { 790 typedef mozilla::gfx::EmptyAttributes paramType; 791 792 static void Write(MessageWriter* aWriter, const paramType& aParam) {} 793 794 static bool Read(MessageReader* aReader, paramType* aResult) { return true; } 795 }; 796 797 template <> 798 struct ParamTraits<mozilla::gfx::MergeAttributes> { 799 typedef mozilla::gfx::MergeAttributes paramType; 800 801 static void Write(MessageWriter* aWriter, const paramType& aParam) {} 802 803 static bool Read(MessageReader* aReader, paramType* aResult) { return true; } 804 }; 805 806 template <> 807 struct ParamTraits<mozilla::gfx::ToAlphaAttributes> { 808 typedef mozilla::gfx::ToAlphaAttributes paramType; 809 810 static void Write(MessageWriter* aWriter, const paramType& aParam) {} 811 812 static bool Read(MessageReader* aReader, paramType* aResult) { return true; } 813 }; 814 815 template <> 816 struct ParamTraits<mozilla::gfx::TileAttributes> { 817 typedef mozilla::gfx::TileAttributes paramType; 818 819 static void Write(MessageWriter* aWriter, const paramType& aParam) {} 820 821 static bool Read(MessageReader* aReader, paramType* aResult) { return true; } 822 }; 823 824 template <> 825 struct ParamTraits<mozilla::gfx::BlendAttributes> { 826 typedef mozilla::gfx::BlendAttributes paramType; 827 828 static void Write(MessageWriter* aWriter, const paramType& aParam) { 829 WriteParam(aWriter, aParam.mBlendMode); 830 } 831 832 static bool Read(MessageReader* aReader, paramType* aResult) { 833 return ReadParam(aReader, &aResult->mBlendMode); 834 } 835 }; 836 837 template <> 838 struct ParamTraits<mozilla::gfx::MorphologyAttributes> { 839 typedef mozilla::gfx::MorphologyAttributes paramType; 840 841 static void Write(MessageWriter* aWriter, const paramType& aParam) { 842 WriteParam(aWriter, aParam.mOperator); 843 WriteParam(aWriter, aParam.mRadii); 844 } 845 846 static bool Read(MessageReader* aReader, paramType* aResult) { 847 if (!ReadParam(aReader, &aResult->mOperator) || 848 !ReadParam(aReader, &aResult->mRadii)) { 849 return false; 850 } 851 return true; 852 } 853 }; 854 855 template <> 856 struct ParamTraits<mozilla::gfx::FloodAttributes> { 857 typedef mozilla::gfx::FloodAttributes paramType; 858 859 static void Write(MessageWriter* aWriter, const paramType& aParam) { 860 WriteParam(aWriter, aParam.mColor); 861 } 862 863 static bool Read(MessageReader* aReader, paramType* aResult) { 864 if (!ReadParam(aReader, &aResult->mColor)) { 865 return false; 866 } 867 return true; 868 } 869 }; 870 871 template <> 872 struct ParamTraits<mozilla::gfx::OpacityAttributes> { 873 typedef mozilla::gfx::OpacityAttributes paramType; 874 875 static void Write(MessageWriter* aWriter, const paramType& aParam) { 876 WriteParam(aWriter, aParam.mOpacity); 877 } 878 879 static bool Read(MessageReader* aReader, paramType* aResult) { 880 if (!ReadParam(aReader, &aResult->mOpacity)) { 881 return false; 882 } 883 return true; 884 } 885 }; 886 887 template <> 888 struct ParamTraits<mozilla::gfx::OffsetAttributes> { 889 typedef mozilla::gfx::OffsetAttributes paramType; 890 891 static void Write(MessageWriter* aWriter, const paramType& aParam) { 892 WriteParam(aWriter, aParam.mValue); 893 } 894 895 static bool Read(MessageReader* aReader, paramType* aResult) { 896 if (!ReadParam(aReader, &aResult->mValue)) { 897 return false; 898 } 899 return true; 900 } 901 }; 902 903 template <> 904 struct ParamTraits<mozilla::gfx::DisplacementMapAttributes> { 905 typedef mozilla::gfx::DisplacementMapAttributes paramType; 906 907 static void Write(MessageWriter* aWriter, const paramType& aParam) { 908 WriteParam(aWriter, aParam.mScale); 909 WriteParam(aWriter, aParam.mXChannel); 910 WriteParam(aWriter, aParam.mYChannel); 911 } 912 913 static bool Read(MessageReader* aReader, paramType* aResult) { 914 if (!ReadParam(aReader, &aResult->mScale) || 915 !ReadParam(aReader, &aResult->mXChannel) || 916 !ReadParam(aReader, &aResult->mYChannel)) { 917 return false; 918 } 919 return true; 920 } 921 }; 922 923 template <> 924 struct ParamTraits<mozilla::gfx::TurbulenceAttributes> { 925 typedef mozilla::gfx::TurbulenceAttributes paramType; 926 927 static void Write(MessageWriter* aWriter, const paramType& aParam) { 928 WriteParam(aWriter, aParam.mOffset); 929 WriteParam(aWriter, aParam.mBaseFrequency); 930 WriteParam(aWriter, aParam.mSeed); 931 WriteParam(aWriter, aParam.mOctaves); 932 WriteParam(aWriter, aParam.mStitchable); 933 WriteParam(aWriter, aParam.mType); 934 } 935 936 static bool Read(MessageReader* aReader, paramType* aResult) { 937 if (!ReadParam(aReader, &aResult->mOffset) || 938 !ReadParam(aReader, &aResult->mBaseFrequency) || 939 !ReadParam(aReader, &aResult->mSeed) || 940 !ReadParam(aReader, &aResult->mOctaves) || 941 !ReadParam(aReader, &aResult->mStitchable) || 942 !ReadParam(aReader, &aResult->mType)) { 943 return false; 944 } 945 return true; 946 } 947 }; 948 949 template <> 950 struct ParamTraits<mozilla::gfx::ImageAttributes> { 951 typedef mozilla::gfx::ImageAttributes paramType; 952 953 static void Write(MessageWriter* aWriter, const paramType& aParam) { 954 WriteParam(aWriter, aParam.mFilter); 955 WriteParam(aWriter, aParam.mInputIndex); 956 WriteParam(aWriter, aParam.mTransform); 957 } 958 959 static bool Read(MessageReader* aReader, paramType* aResult) { 960 if (!ReadParam(aReader, &aResult->mFilter) || 961 !ReadParam(aReader, &aResult->mInputIndex) || 962 !ReadParam(aReader, &aResult->mTransform)) { 963 return false; 964 } 965 return true; 966 } 967 }; 968 969 template <> 970 struct ParamTraits<mozilla::gfx::GaussianBlurAttributes> { 971 typedef mozilla::gfx::GaussianBlurAttributes paramType; 972 973 static void Write(MessageWriter* aWriter, const paramType& aParam) { 974 WriteParam(aWriter, aParam.mStdDeviation); 975 } 976 977 static bool Read(MessageReader* aReader, paramType* aResult) { 978 if (!ReadParam(aReader, &aResult->mStdDeviation)) { 979 return false; 980 } 981 return true; 982 } 983 }; 984 985 template <> 986 struct ParamTraits<mozilla::gfx::DropShadowAttributes> { 987 typedef mozilla::gfx::DropShadowAttributes paramType; 988 989 static void Write(MessageWriter* aWriter, const paramType& aParam) { 990 WriteParam(aWriter, aParam.mStdDeviation); 991 WriteParam(aWriter, aParam.mOffset); 992 WriteParam(aWriter, aParam.mColor); 993 } 994 995 static bool Read(MessageReader* aReader, paramType* aResult) { 996 if (!ReadParam(aReader, &aResult->mStdDeviation) || 997 !ReadParam(aReader, &aResult->mOffset) || 998 !ReadParam(aReader, &aResult->mColor)) { 999 return false; 1000 } 1001 return true; 1002 } 1003 }; 1004 1005 template <> 1006 struct ParamTraits<mozilla::gfx::ColorMatrixAttributes> { 1007 typedef mozilla::gfx::ColorMatrixAttributes paramType; 1008 1009 static void Write(MessageWriter* aWriter, const paramType& aParam) { 1010 WriteParam(aWriter, aParam.mType); 1011 WriteParam(aWriter, aParam.mValues); 1012 } 1013 1014 static bool Read(MessageReader* aReader, paramType* aResult) { 1015 if (!ReadParam(aReader, &aResult->mType) || 1016 !ReadParam(aReader, &aResult->mValues)) { 1017 return false; 1018 } 1019 return true; 1020 } 1021 }; 1022 1023 template <> 1024 struct ParamTraits<mozilla::gfx::ComponentTransferAttributes> { 1025 typedef mozilla::gfx::ComponentTransferAttributes paramType; 1026 1027 static void Write(MessageWriter* aWriter, const paramType& aParam) { 1028 for (int i = 0; i < 4; ++i) { 1029 WriteParam(aWriter, aParam.mTypes[i]); 1030 } 1031 for (int i = 0; i < 4; ++i) { 1032 WriteParam(aWriter, aParam.mValues[i]); 1033 } 1034 } 1035 1036 static bool Read(MessageReader* aReader, paramType* aResult) { 1037 for (int i = 0; i < 4; ++i) { 1038 if (!ReadParam(aReader, &aResult->mTypes[i])) { 1039 return false; 1040 } 1041 } 1042 for (int i = 0; i < 4; ++i) { 1043 if (!ReadParam(aReader, &aResult->mValues[i])) { 1044 return false; 1045 } 1046 } 1047 return true; 1048 } 1049 }; 1050 1051 template <> 1052 struct ParamTraits<mozilla::gfx::ConvolveMatrixAttributes> { 1053 typedef mozilla::gfx::ConvolveMatrixAttributes paramType; 1054 1055 static void Write(MessageWriter* aWriter, const paramType& aParam) { 1056 WriteParam(aWriter, aParam.mKernelSize); 1057 WriteParam(aWriter, aParam.mKernelMatrix); 1058 WriteParam(aWriter, aParam.mDivisor); 1059 WriteParam(aWriter, aParam.mBias); 1060 WriteParam(aWriter, aParam.mTarget); 1061 WriteParam(aWriter, aParam.mEdgeMode); 1062 WriteParam(aWriter, aParam.mKernelUnitLength); 1063 WriteParam(aWriter, aParam.mPreserveAlpha); 1064 } 1065 1066 static bool Read(MessageReader* aReader, paramType* aResult) { 1067 if (!ReadParam(aReader, &aResult->mKernelSize) || 1068 !ReadParam(aReader, &aResult->mKernelMatrix) || 1069 !ReadParam(aReader, &aResult->mDivisor) || 1070 !ReadParam(aReader, &aResult->mBias) || 1071 !ReadParam(aReader, &aResult->mTarget) || 1072 !ReadParam(aReader, &aResult->mEdgeMode) || 1073 !ReadParam(aReader, &aResult->mKernelUnitLength) || 1074 !ReadParam(aReader, &aResult->mPreserveAlpha)) { 1075 return false; 1076 } 1077 return true; 1078 } 1079 }; 1080 1081 template <> 1082 struct ParamTraits<mozilla::gfx::DiffuseLightingAttributes> { 1083 typedef mozilla::gfx::DiffuseLightingAttributes paramType; 1084 1085 static void Write(MessageWriter* aWriter, const paramType& aParam) { 1086 WriteParam(aWriter, aParam.mLightType); 1087 WriteParam(aWriter, aParam.mLightValues); 1088 WriteParam(aWriter, aParam.mSurfaceScale); 1089 WriteParam(aWriter, aParam.mKernelUnitLength); 1090 WriteParam(aWriter, aParam.mColor); 1091 WriteParam(aWriter, aParam.mLightingConstant); 1092 WriteParam(aWriter, aParam.mSpecularExponent); 1093 } 1094 1095 static bool Read(MessageReader* aReader, paramType* aResult) { 1096 if (!ReadParam(aReader, &aResult->mLightType) || 1097 !ReadParam(aReader, &aResult->mLightValues) || 1098 !ReadParam(aReader, &aResult->mSurfaceScale) || 1099 !ReadParam(aReader, &aResult->mKernelUnitLength) || 1100 !ReadParam(aReader, &aResult->mColor) || 1101 !ReadParam(aReader, &aResult->mLightingConstant) || 1102 !ReadParam(aReader, &aResult->mSpecularExponent)) { 1103 return false; 1104 } 1105 return true; 1106 } 1107 }; 1108 1109 template <> 1110 struct ParamTraits<mozilla::gfx::SpecularLightingAttributes> { 1111 typedef mozilla::gfx::SpecularLightingAttributes paramType; 1112 1113 static void Write(MessageWriter* aWriter, const paramType& aParam) { 1114 WriteParam(aWriter, aParam.mLightType); 1115 WriteParam(aWriter, aParam.mLightValues); 1116 WriteParam(aWriter, aParam.mSurfaceScale); 1117 WriteParam(aWriter, aParam.mKernelUnitLength); 1118 WriteParam(aWriter, aParam.mColor); 1119 WriteParam(aWriter, aParam.mLightingConstant); 1120 WriteParam(aWriter, aParam.mSpecularExponent); 1121 } 1122 1123 static bool Read(MessageReader* aReader, paramType* aResult) { 1124 if (!ReadParam(aReader, &aResult->mLightType) || 1125 !ReadParam(aReader, &aResult->mLightValues) || 1126 !ReadParam(aReader, &aResult->mSurfaceScale) || 1127 !ReadParam(aReader, &aResult->mKernelUnitLength) || 1128 !ReadParam(aReader, &aResult->mColor) || 1129 !ReadParam(aReader, &aResult->mLightingConstant) || 1130 !ReadParam(aReader, &aResult->mSpecularExponent)) { 1131 return false; 1132 } 1133 return true; 1134 } 1135 }; 1136 1137 template <> 1138 struct ParamTraits<mozilla::gfx::CompositeAttributes> { 1139 typedef mozilla::gfx::CompositeAttributes paramType; 1140 1141 static void Write(MessageWriter* aWriter, const paramType& aParam) { 1142 WriteParam(aWriter, aParam.mOperator); 1143 WriteParam(aWriter, aParam.mCoefficients); 1144 } 1145 1146 static bool Read(MessageReader* aReader, paramType* aResult) { 1147 if (!ReadParam(aReader, &aResult->mOperator) || 1148 !ReadParam(aReader, &aResult->mCoefficients)) { 1149 return false; 1150 } 1151 return true; 1152 } 1153 }; 1154 1155 template <> 1156 struct ParamTraits<mozilla::gfx::Glyph> { 1157 typedef mozilla::gfx::Glyph paramType; 1158 static void Write(MessageWriter* aWriter, const paramType& aParam) { 1159 WriteParam(aWriter, aParam.mIndex); 1160 WriteParam(aWriter, aParam.mPosition); 1161 } 1162 1163 static bool Read(MessageReader* aReader, paramType* aResult) { 1164 return (ReadParam(aReader, &aResult->mIndex) && 1165 ReadParam(aReader, &aResult->mPosition)); 1166 } 1167 }; 1168 1169 template <typename T, size_t Length> 1170 struct ParamTraits<mozilla::Array<T, Length>> { 1171 typedef mozilla::Array<T, Length> paramType; 1172 static void Write(MessageWriter* aWriter, const paramType& aParam) { 1173 for (size_t i = 0; i < Length; i++) { 1174 WriteParam(aWriter, aParam[i]); 1175 } 1176 } 1177 1178 static bool Read(MessageReader* aReader, paramType* aResult) { 1179 for (size_t i = 0; i < Length; i++) { 1180 if (!ReadParam<T>(aReader, &aResult->operator[](i))) { 1181 return false; 1182 } 1183 } 1184 return true; 1185 } 1186 }; 1187 1188 template <> 1189 struct ParamTraits<mozilla::SideBits> 1190 : public BitFlagsEnumSerializer<mozilla::SideBits, 1191 mozilla::SideBits::eAll> {}; 1192 1193 template <> 1194 struct ParamTraits<gfxSparseBitSet> { 1195 typedef gfxSparseBitSet paramType; 1196 static void Write(MessageWriter* aWriter, const paramType& aParam) { 1197 WriteParam(aWriter, aParam.mBlockIndex); 1198 WriteParam(aWriter, aParam.mBlocks); 1199 } 1200 static bool Read(MessageReader* aReader, paramType* aResult) { 1201 return ReadParam(aReader, &aResult->mBlockIndex) && 1202 ReadParam(aReader, &aResult->mBlocks); 1203 } 1204 }; 1205 1206 template <> 1207 struct ParamTraits<gfxSparseBitSet::BlockIndex> { 1208 typedef gfxSparseBitSet::BlockIndex paramType; 1209 static void Write(MessageWriter* aWriter, const paramType& aParam) { 1210 WriteParam(aWriter, aParam.mIndex); 1211 } 1212 static bool Read(MessageReader* aReader, paramType* aResult) { 1213 return ReadParam(aReader, &aResult->mIndex); 1214 } 1215 }; 1216 1217 template <> 1218 struct ParamTraits<gfxSparseBitSet::Block> { 1219 typedef gfxSparseBitSet::Block paramType; 1220 static void Write(MessageWriter* aWriter, const paramType& aParam) { 1221 aWriter->WriteBytes(&aParam, sizeof(aParam)); 1222 } 1223 static bool Read(MessageReader* aReader, paramType* aResult) { 1224 return aReader->ReadBytesInto(aResult, sizeof(*aResult)); 1225 } 1226 }; 1227 1228 // The actual FontVisibility enum is defined in gfxTypes.h 1229 template <> 1230 struct ParamTraits<FontVisibility> 1231 : public ContiguousEnumSerializer<FontVisibility, FontVisibility::Unknown, 1232 FontVisibility::Count> {}; 1233 1234 template <> 1235 struct ParamTraits<mozilla::fontlist::Pointer> { 1236 typedef mozilla::fontlist::Pointer paramType; 1237 static void Write(MessageWriter* aWriter, const paramType& aParam) { 1238 uint32_t v = aParam.mBlockAndOffset; 1239 WriteParam(aWriter, v); 1240 } 1241 static bool Read(MessageReader* aReader, paramType* aResult) { 1242 uint32_t v; 1243 if (ReadParam(aReader, &v)) { 1244 aResult->mBlockAndOffset.store(v); 1245 return true; 1246 } 1247 return false; 1248 } 1249 }; 1250 1251 template <> 1252 struct ParamTraits<mozilla::gfx::PaintFragment> { 1253 typedef mozilla::gfx::PaintFragment paramType; 1254 static void Write(IPC::MessageWriter* aWriter, paramType&& aParam) { 1255 if (!aWriter->GetActor()) { 1256 aWriter->FatalError("Need an actor"); 1257 return; 1258 } 1259 1260 mozilla::ipc::Shmem shmem; 1261 if (aParam.mSize.IsEmpty() || 1262 !aWriter->GetActor()->AllocShmem(aParam.mRecording.mLen, &shmem)) { 1263 WriteParam(aWriter, mozilla::gfx::IntSize(0, 0)); 1264 return; 1265 } 1266 1267 memcpy(shmem.get<uint8_t>(), aParam.mRecording.mData, 1268 aParam.mRecording.mLen); 1269 1270 WriteParam(aWriter, aParam.mSize); 1271 WriteParam(aWriter, std::move(shmem)); 1272 WriteParam(aWriter, aParam.mDependencies); 1273 } 1274 1275 static bool Read(IPC::MessageReader* aReader, paramType* aResult) { 1276 if (!aReader->GetActor()) { 1277 return false; 1278 } 1279 if (!ReadParam(aReader, &aResult->mSize)) { 1280 return false; 1281 } 1282 if (aResult->mSize.IsEmpty()) { 1283 return true; 1284 } 1285 mozilla::ipc::Shmem shmem; 1286 if (!ReadParam(aReader, &shmem) || 1287 !ReadParam(aReader, &aResult->mDependencies)) { 1288 aReader->GetActor()->DeallocShmem(shmem); 1289 return false; 1290 } 1291 1292 if (!aResult->mRecording.Allocate(shmem.Size<uint8_t>())) { 1293 aResult->mSize.SizeTo(0, 0); 1294 aReader->GetActor()->DeallocShmem(shmem); 1295 return true; 1296 } 1297 1298 memcpy(aResult->mRecording.mData, shmem.get<uint8_t>(), 1299 shmem.Size<uint8_t>()); 1300 aReader->GetActor()->DeallocShmem(shmem); 1301 return true; 1302 } 1303 }; 1304 1305 template <> 1306 struct ParamTraits<mozilla::gfx::FileHandleWrapper*> { 1307 static void Write(MessageWriter* aWriter, 1308 mozilla::gfx::FileHandleWrapper* aParam) { 1309 if (!aParam) { 1310 WriteParam(aWriter, false); 1311 return; 1312 } 1313 WriteParam(aWriter, true); 1314 1315 mozilla::ipc::FileDescriptor desc(aParam->GetHandle()); 1316 WriteParam(aWriter, desc); 1317 } 1318 1319 static bool Read(MessageReader* aReader, 1320 RefPtr<mozilla::gfx::FileHandleWrapper>* aResult) { 1321 *aResult = nullptr; 1322 bool notnull = false; 1323 if (!ReadParam(aReader, ¬null)) { 1324 return false; 1325 } 1326 1327 if (!notnull) { 1328 return true; 1329 } 1330 1331 mozilla::ipc::FileDescriptor desc; 1332 if (!ReadParam(aReader, &desc)) { 1333 return false; 1334 } 1335 auto wrapper = mozilla::MakeRefPtr<mozilla::gfx::FileHandleWrapper>( 1336 desc.TakePlatformHandle()); 1337 *aResult = std::move(wrapper); 1338 return true; 1339 } 1340 }; 1341 1342 } // namespace IPC 1343 1344 #endif /* __GFXMESSAGEUTILS_H__ */