/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef __GFXMESSAGEUTILS_H__ #define __GFXMESSAGEUTILS_H__ #include "FilterSupport.h" #include "ImageTypes.h" #include "RegionBuilder.h" #include "chrome/common/ipc_message_utils.h" #include "gfxFeature.h" #include "gfxFallback.h" #include "gfxPoint.h" #include "gfxRect.h" #include "gfxTelemetry.h" #include "gfxTypes.h" #include "ipc/EnumSerializer.h" #include "ipc/IPCMessageUtilsSpecializations.h" #include "mozilla/gfx/CrossProcessPaint.h" #include "mozilla/gfx/Matrix.h" #include "mozilla/gfx/ScaleFactor.h" #include "mozilla/gfx/ScaleFactors2D.h" #include "nsRect.h" #include "nsRegion.h" #include "mozilla/Array.h" #include "mozilla/ipc/IPDLParamTraits.h" #include "mozilla/ipc/ProtocolUtils.h" #include "mozilla/ipc/ShmemMessageUtils.h" #include #ifdef _MSC_VER # pragma warning(disable : 4800) #endif namespace mozilla { typedef gfxImageFormat PixelFormat; } // namespace mozilla namespace IPC { template <> struct ParamTraits { typedef mozilla::gfx::Matrix paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam._11); WriteParam(aMsg, aParam._12); WriteParam(aMsg, aParam._21); WriteParam(aMsg, aParam._22); WriteParam(aMsg, aParam._31); WriteParam(aMsg, aParam._32); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (ReadParam(aMsg, aIter, &aResult->_11) && ReadParam(aMsg, aIter, &aResult->_12) && ReadParam(aMsg, aIter, &aResult->_21) && ReadParam(aMsg, aIter, &aResult->_22) && ReadParam(aMsg, aIter, &aResult->_31) && ReadParam(aMsg, aIter, &aResult->_32)) return true; return false; } static void Log(const paramType& aParam, std::wstring* aLog) { aLog->append(StringPrintf(L"[[%g %g] [%g %g] [%g %g]]", aParam._11, aParam._12, aParam._21, aParam._22, aParam._31, aParam._32)); } }; template <> struct ParamTraits { typedef mozilla::gfx::Matrix4x4 paramType; static void Write(Message* msg, const paramType& param) { #define Wr(_f) WriteParam(msg, param._f) Wr(_11); Wr(_12); Wr(_13); Wr(_14); Wr(_21); Wr(_22); Wr(_23); Wr(_24); Wr(_31); Wr(_32); Wr(_33); Wr(_34); Wr(_41); Wr(_42); Wr(_43); Wr(_44); #undef Wr } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { #define Rd(_f) ReadParam(msg, iter, &result->_f) return (Rd(_11) && Rd(_12) && Rd(_13) && Rd(_14) && Rd(_21) && Rd(_22) && Rd(_23) && Rd(_24) && Rd(_31) && Rd(_32) && Rd(_33) && Rd(_34) && Rd(_41) && Rd(_42) && Rd(_43) && Rd(_44)); #undef Rd } }; template <> struct ParamTraits { typedef mozilla::gfx::Matrix5x4 paramType; static void Write(Message* msg, const paramType& param) { #define Wr(_f) WriteParam(msg, param._f) Wr(_11); Wr(_12); Wr(_13); Wr(_14); Wr(_21); Wr(_22); Wr(_23); Wr(_24); Wr(_31); Wr(_32); Wr(_33); Wr(_34); Wr(_41); Wr(_42); Wr(_43); Wr(_44); Wr(_51); Wr(_52); Wr(_53); Wr(_54); #undef Wr } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { #define Rd(_f) ReadParam(msg, iter, &result->_f) return (Rd(_11) && Rd(_12) && Rd(_13) && Rd(_14) && Rd(_21) && Rd(_22) && Rd(_23) && Rd(_24) && Rd(_31) && Rd(_32) && Rd(_33) && Rd(_34) && Rd(_41) && Rd(_42) && Rd(_43) && Rd(_44) && Rd(_51) && Rd(_52) && Rd(_53) && Rd(_54)); #undef Rd } }; template <> struct ParamTraits { typedef gfxPoint paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.x); WriteParam(aMsg, aParam.y); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { return (ReadParam(aMsg, aIter, &aResult->x) && ReadParam(aMsg, aIter, &aResult->y)); } }; template <> struct ParamTraits { typedef gfxSize paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.width); WriteParam(aMsg, aParam.height); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (ReadParam(aMsg, aIter, &aResult->width) && ReadParam(aMsg, aIter, &aResult->height)) return true; return false; } }; template <> struct ParamTraits { typedef gfxRect paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.X()); WriteParam(aMsg, aParam.Y()); WriteParam(aMsg, aParam.Width()); WriteParam(aMsg, aParam.Height()); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { auto x = aResult->X(); auto y = aResult->Y(); auto w = aResult->Width(); auto h = aResult->Height(); bool retVal = (ReadParam(aMsg, aIter, &x) && ReadParam(aMsg, aIter, &y) && ReadParam(aMsg, aIter, &w) && ReadParam(aMsg, aIter, &h)); aResult->SetRect(x, y, w, h); return retVal; } }; template <> struct ParamTraits : public ContiguousEnumSerializer {}; template <> struct ParamTraits : public ContiguousEnumSerializer {}; template <> struct ParamTraits : public ContiguousEnumSerializer { }; template <> struct ParamTraits : public ContiguousEnumSerializer { }; template <> struct ParamTraits : public ContiguousEnumSerializer {}; template <> struct ParamTraits : public ContiguousEnumSerializer< mozilla::gfx::Fallback, mozilla::gfx::Fallback::NO_CONSTANT_BUFFER_OFFSETTING, mozilla::gfx::Fallback::NumValues> {}; template <> struct ParamTraits : public ContiguousEnumSerializer {}; template <> struct ParamTraits : public ContiguousEnumSerializer {}; template <> struct ParamTraits : public ContiguousEnumSerializer {}; template <> struct ParamTraits : public ContiguousEnumSerializerInclusive< mozilla::gfx::CompositionOp, mozilla::gfx::CompositionOp::OP_OVER, mozilla::gfx::CompositionOp::OP_COUNT> {}; /* template <> struct ParamTraits : public EnumSerializer {}; */ template <> struct ParamTraits { typedef mozilla::gfx::sRGBColor paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.r); WriteParam(msg, param.g); WriteParam(msg, param.b); WriteParam(msg, param.a); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { return ( ReadParam(msg, iter, &result->r) && ReadParam(msg, iter, &result->g) && ReadParam(msg, iter, &result->b) && ReadParam(msg, iter, &result->a)); } }; template <> struct ParamTraits { typedef mozilla::gfx::DeviceColor paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.r); WriteParam(msg, param.g); WriteParam(msg, param.b); WriteParam(msg, param.a); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { return ( ReadParam(msg, iter, &result->r) && ReadParam(msg, iter, &result->g) && ReadParam(msg, iter, &result->b) && ReadParam(msg, iter, &result->a)); } }; template <> struct ParamTraits { typedef nsPoint paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.x); WriteParam(msg, param.y); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { return (ReadParam(msg, iter, &result->x) && ReadParam(msg, iter, &result->y)); } }; template <> struct ParamTraits { typedef nsIntPoint paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.x); WriteParam(msg, param.y); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { return (ReadParam(msg, iter, &result->x) && ReadParam(msg, iter, &result->y)); } }; template struct ParamTraits> { typedef mozilla::gfx::IntSizeTyped paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.width); WriteParam(msg, param.height); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { return (ReadParam(msg, iter, &result->width) && ReadParam(msg, iter, &result->height)); } }; template struct RegionParamTraits { typedef Region paramType; static void Write(Message* msg, const paramType& param) { for (auto iter = param.RectIter(); !iter.Done(); iter.Next()) { const Rect& r = iter.Get(); MOZ_RELEASE_ASSERT(!r.IsEmpty(), "GFX: rect is empty."); WriteParam(msg, r); } // empty rects are sentinel values because nsRegions will never // contain them WriteParam(msg, Rect()); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { RegionBuilder builder; Rect rect; while (ReadParam(msg, iter, &rect)) { if (rect.IsEmpty()) { *result = builder.ToRegion(); return true; } builder.OrWith(rect); } return false; } }; template struct ParamTraits> : RegionParamTraits< mozilla::gfx::IntRegionTyped, mozilla::gfx::IntRectTyped, typename mozilla::gfx::IntRegionTyped::RectIterator> {}; template <> struct ParamTraits { typedef mozilla::gfx::IntSize paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.width); WriteParam(msg, param.height); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { return (ReadParam(msg, iter, &result->width) && ReadParam(msg, iter, &result->height)); } }; template struct ParamTraits> { typedef mozilla::gfx::CoordTyped paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.value); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { return (ReadParam(msg, iter, &result->value)); } }; template struct ParamTraits> { typedef mozilla::gfx::IntCoordTyped paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.value); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { return (ReadParam(msg, iter, &result->value)); } }; template struct ParamTraits> { typedef mozilla::gfx::ScaleFactor paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.scale); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { return (ReadParam(msg, iter, &result->scale)); } }; template struct ParamTraits> { typedef mozilla::gfx::ScaleFactors2D paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.xScale); WriteParam(msg, param.yScale); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { return (ReadParam(msg, iter, &result->xScale) && ReadParam(msg, iter, &result->yScale)); } }; template struct ParamTraits> { typedef mozilla::gfx::PointTyped paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.x); WriteParam(msg, param.y); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { return (ReadParam(msg, iter, &result->x) && ReadParam(msg, iter, &result->y)); } }; template struct ParamTraits> { typedef mozilla::gfx::Point3DTyped paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.x); WriteParam(msg, param.y); WriteParam(msg, param.z); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { return (ReadParam(msg, iter, &result->x) && ReadParam(msg, iter, &result->y) && ReadParam(msg, iter, &result->z)); } }; template struct ParamTraits> { typedef mozilla::gfx::IntPointTyped paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.x); WriteParam(msg, param.y); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { return (ReadParam(msg, iter, &result->x) && ReadParam(msg, iter, &result->y)); } }; template struct ParamTraits> { typedef mozilla::gfx::SizeTyped paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.width); WriteParam(msg, param.height); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { return (ReadParam(msg, iter, &result->width) && ReadParam(msg, iter, &result->height)); } }; template struct ParamTraits> { typedef mozilla::gfx::RectTyped paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.X()); WriteParam(msg, param.Y()); WriteParam(msg, param.Width()); WriteParam(msg, param.Height()); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { auto x = result->X(); auto y = result->Y(); auto w = result->Width(); auto h = result->Height(); bool retVal = (ReadParam(msg, iter, &x) && ReadParam(msg, iter, &y) && ReadParam(msg, iter, &w) && ReadParam(msg, iter, &h)); result->SetRect(x, y, w, h); return retVal; } }; template struct ParamTraits> { typedef mozilla::gfx::RectAbsoluteTyped paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.Left()); WriteParam(msg, param.Top()); WriteParam(msg, param.Right()); WriteParam(msg, param.Bottom()); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { auto l = result->Left(); auto t = result->Top(); auto r = result->Right(); auto b = result->Bottom(); bool retVal = (ReadParam(msg, iter, &l) && ReadParam(msg, iter, &t) && ReadParam(msg, iter, &r) && ReadParam(msg, iter, &b)); result->SetBox(l, t, r, b); return retVal; } }; template struct ParamTraits> { typedef mozilla::gfx::IntRectTyped paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.X()); WriteParam(msg, param.Y()); WriteParam(msg, param.Width()); WriteParam(msg, param.Height()); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { auto x = result->X(); auto y = result->Y(); auto w = result->Width(); auto h = result->Height(); bool retVal = (ReadParam(msg, iter, &x) && ReadParam(msg, iter, &y) && ReadParam(msg, iter, &w) && ReadParam(msg, iter, &h)); result->SetRect(x, y, w, h); return retVal; } }; template <> struct ParamTraits { typedef mozilla::gfx::Margin paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.top); WriteParam(msg, param.right); WriteParam(msg, param.bottom); WriteParam(msg, param.left); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { return (ReadParam(msg, iter, &result->top) && ReadParam(msg, iter, &result->right) && ReadParam(msg, iter, &result->bottom) && ReadParam(msg, iter, &result->left)); } }; template struct ParamTraits> { typedef mozilla::gfx::MarginTyped paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.top); WriteParam(msg, param.right); WriteParam(msg, param.bottom); WriteParam(msg, param.left); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { return (ReadParam(msg, iter, &result->top) && ReadParam(msg, iter, &result->right) && ReadParam(msg, iter, &result->bottom) && ReadParam(msg, iter, &result->left)); } }; template struct ParamTraits> { typedef mozilla::gfx::IntMarginTyped paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.top); WriteParam(msg, param.right); WriteParam(msg, param.bottom); WriteParam(msg, param.left); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { return (ReadParam(msg, iter, &result->top) && ReadParam(msg, iter, &result->right) && ReadParam(msg, iter, &result->bottom) && ReadParam(msg, iter, &result->left)); } }; template <> struct ParamTraits { typedef nsRect paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.X()); WriteParam(msg, param.Y()); WriteParam(msg, param.Width()); WriteParam(msg, param.Height()); } static bool Read(const Message* msg, PickleIterator* iter, paramType* result) { auto x = result->X(); auto y = result->Y(); auto w = result->Width(); auto h = result->Height(); bool retVal = (ReadParam(msg, iter, &x) && ReadParam(msg, iter, &y) && ReadParam(msg, iter, &w) && ReadParam(msg, iter, &h)); result->SetRect(x, y, w, h); return retVal; } }; template <> struct ParamTraits : RegionParamTraits {}; template <> struct ParamTraits : public ContiguousEnumSerializer< GeckoProcessType, GeckoProcessType_Default, GeckoProcessType_End> {}; template <> struct ParamTraits : public ContiguousEnumSerializer {}; template <> struct ParamTraits : public ContiguousEnumSerializer {}; template <> struct ParamTraits : public ContiguousEnumSerializer {}; template <> struct ParamTraits : public ContiguousEnumSerializer< mozilla::gfx::YUVColorSpace, mozilla::gfx::YUVColorSpace::BT601, mozilla::gfx::YUVColorSpace::_NUM_COLORSPACE> {}; template <> struct ParamTraits : public ContiguousEnumSerializer {}; template <> struct ParamTraits : public ParamTraits> { typedef mozilla::gfx::ImplicitlyCopyableFloatArray paramType; }; template <> struct ParamTraits { typedef mozilla::gfx::EmptyAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) {} static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { return true; } }; template <> struct ParamTraits { typedef mozilla::gfx::MergeAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) {} static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { return true; } }; template <> struct ParamTraits { typedef mozilla::gfx::ToAlphaAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) {} static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { return true; } }; template <> struct ParamTraits { typedef mozilla::gfx::TileAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) {} static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { return true; } }; template <> struct ParamTraits { typedef mozilla::gfx::BlendAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mBlendMode); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { return ReadParam(aMsg, aIter, &aResult->mBlendMode); } }; template <> struct ParamTraits { typedef mozilla::gfx::MorphologyAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mOperator); WriteParam(aMsg, aParam.mRadii); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (!ReadParam(aMsg, aIter, &aResult->mOperator) || !ReadParam(aMsg, aIter, &aResult->mRadii)) { return false; } return true; } }; template <> struct ParamTraits { typedef mozilla::gfx::FloodAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mColor); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (!ReadParam(aMsg, aIter, &aResult->mColor)) { return false; } return true; } }; template <> struct ParamTraits { typedef mozilla::gfx::OpacityAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mOpacity); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (!ReadParam(aMsg, aIter, &aResult->mOpacity)) { return false; } return true; } }; template <> struct ParamTraits { typedef mozilla::gfx::OffsetAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mValue); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (!ReadParam(aMsg, aIter, &aResult->mValue)) { return false; } return true; } }; template <> struct ParamTraits { typedef mozilla::gfx::DisplacementMapAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mScale); WriteParam(aMsg, aParam.mXChannel); WriteParam(aMsg, aParam.mYChannel); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (!ReadParam(aMsg, aIter, &aResult->mScale) || !ReadParam(aMsg, aIter, &aResult->mXChannel) || !ReadParam(aMsg, aIter, &aResult->mYChannel)) { return false; } return true; } }; template <> struct ParamTraits { typedef mozilla::gfx::TurbulenceAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mOffset); WriteParam(aMsg, aParam.mBaseFrequency); WriteParam(aMsg, aParam.mSeed); WriteParam(aMsg, aParam.mOctaves); WriteParam(aMsg, aParam.mStitchable); WriteParam(aMsg, aParam.mType); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (!ReadParam(aMsg, aIter, &aResult->mOffset) || !ReadParam(aMsg, aIter, &aResult->mBaseFrequency) || !ReadParam(aMsg, aIter, &aResult->mSeed) || !ReadParam(aMsg, aIter, &aResult->mOctaves) || !ReadParam(aMsg, aIter, &aResult->mStitchable) || !ReadParam(aMsg, aIter, &aResult->mType)) { return false; } return true; } }; template <> struct ParamTraits { typedef mozilla::gfx::ImageAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mFilter); WriteParam(aMsg, aParam.mInputIndex); WriteParam(aMsg, aParam.mTransform); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (!ReadParam(aMsg, aIter, &aResult->mFilter) || !ReadParam(aMsg, aIter, &aResult->mInputIndex) || !ReadParam(aMsg, aIter, &aResult->mTransform)) { return false; } return true; } }; template <> struct ParamTraits { typedef mozilla::gfx::GaussianBlurAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mStdDeviation); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (!ReadParam(aMsg, aIter, &aResult->mStdDeviation)) { return false; } return true; } }; template <> struct ParamTraits { typedef mozilla::gfx::DropShadowAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mStdDeviation); WriteParam(aMsg, aParam.mOffset); WriteParam(aMsg, aParam.mColor); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (!ReadParam(aMsg, aIter, &aResult->mStdDeviation) || !ReadParam(aMsg, aIter, &aResult->mOffset) || !ReadParam(aMsg, aIter, &aResult->mColor)) { return false; } return true; } }; template <> struct ParamTraits { typedef mozilla::gfx::ColorMatrixAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mType); WriteParam(aMsg, aParam.mValues); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (!ReadParam(aMsg, aIter, &aResult->mType) || !ReadParam(aMsg, aIter, &aResult->mValues)) { return false; } return true; } }; template <> struct ParamTraits { typedef mozilla::gfx::ComponentTransferAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) { for (int i = 0; i < 4; ++i) { WriteParam(aMsg, aParam.mTypes[i]); } for (int i = 0; i < 4; ++i) { WriteParam(aMsg, aParam.mValues[i]); } } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { for (int i = 0; i < 4; ++i) { if (!ReadParam(aMsg, aIter, &aResult->mTypes[i])) { return false; } } for (int i = 0; i < 4; ++i) { if (!ReadParam(aMsg, aIter, &aResult->mValues[i])) { return false; } } return true; } }; template <> struct ParamTraits { typedef mozilla::gfx::ConvolveMatrixAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mKernelSize); WriteParam(aMsg, aParam.mKernelMatrix); WriteParam(aMsg, aParam.mDivisor); WriteParam(aMsg, aParam.mBias); WriteParam(aMsg, aParam.mTarget); WriteParam(aMsg, aParam.mEdgeMode); WriteParam(aMsg, aParam.mKernelUnitLength); WriteParam(aMsg, aParam.mPreserveAlpha); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (!ReadParam(aMsg, aIter, &aResult->mKernelSize) || !ReadParam(aMsg, aIter, &aResult->mKernelMatrix) || !ReadParam(aMsg, aIter, &aResult->mDivisor) || !ReadParam(aMsg, aIter, &aResult->mBias) || !ReadParam(aMsg, aIter, &aResult->mTarget) || !ReadParam(aMsg, aIter, &aResult->mEdgeMode) || !ReadParam(aMsg, aIter, &aResult->mKernelUnitLength) || !ReadParam(aMsg, aIter, &aResult->mPreserveAlpha)) { return false; } return true; } }; template <> struct ParamTraits { typedef mozilla::gfx::DiffuseLightingAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mLightType); WriteParam(aMsg, aParam.mLightValues); WriteParam(aMsg, aParam.mSurfaceScale); WriteParam(aMsg, aParam.mKernelUnitLength); WriteParam(aMsg, aParam.mColor); WriteParam(aMsg, aParam.mLightingConstant); WriteParam(aMsg, aParam.mSpecularExponent); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (!ReadParam(aMsg, aIter, &aResult->mLightType) || !ReadParam(aMsg, aIter, &aResult->mLightValues) || !ReadParam(aMsg, aIter, &aResult->mSurfaceScale) || !ReadParam(aMsg, aIter, &aResult->mKernelUnitLength) || !ReadParam(aMsg, aIter, &aResult->mColor) || !ReadParam(aMsg, aIter, &aResult->mLightingConstant) || !ReadParam(aMsg, aIter, &aResult->mSpecularExponent)) { return false; } return true; } }; template <> struct ParamTraits { typedef mozilla::gfx::SpecularLightingAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mLightType); WriteParam(aMsg, aParam.mLightValues); WriteParam(aMsg, aParam.mSurfaceScale); WriteParam(aMsg, aParam.mKernelUnitLength); WriteParam(aMsg, aParam.mColor); WriteParam(aMsg, aParam.mLightingConstant); WriteParam(aMsg, aParam.mSpecularExponent); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (!ReadParam(aMsg, aIter, &aResult->mLightType) || !ReadParam(aMsg, aIter, &aResult->mLightValues) || !ReadParam(aMsg, aIter, &aResult->mSurfaceScale) || !ReadParam(aMsg, aIter, &aResult->mKernelUnitLength) || !ReadParam(aMsg, aIter, &aResult->mColor) || !ReadParam(aMsg, aIter, &aResult->mLightingConstant) || !ReadParam(aMsg, aIter, &aResult->mSpecularExponent)) { return false; } return true; } }; template <> struct ParamTraits { typedef mozilla::gfx::CompositeAttributes paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mOperator); WriteParam(aMsg, aParam.mCoefficients); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (!ReadParam(aMsg, aIter, &aResult->mOperator) || !ReadParam(aMsg, aIter, &aResult->mCoefficients)) { return false; } return true; } }; template <> struct ParamTraits { typedef mozilla::gfx::Glyph paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mIndex); WriteParam(aMsg, aParam.mPosition); } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { return (ReadParam(aMsg, aIter, &aResult->mIndex) && ReadParam(aMsg, aIter, &aResult->mPosition)); } }; template struct ParamTraits> { typedef mozilla::Array paramType; static void Write(Message* aMsg, const paramType& aParam) { for (size_t i = 0; i < Length; i++) { WriteParam(aMsg, aParam[i]); } } static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { for (size_t i = 0; i < Length; i++) { if (!ReadParam(aMsg, aIter, &aResult->operator[](i))) { return false; } } return true; } }; template <> struct ParamTraits : public BitFlagsEnumSerializer {}; } /* namespace IPC */ namespace mozilla { namespace ipc { template <> struct IPDLParamTraits { typedef mozilla::gfx::PaintFragment paramType; static void Write(IPC::Message* aMsg, IProtocol* aActor, paramType&& aParam) { Shmem shmem; if (aParam.mSize.IsEmpty() || !aActor->AllocShmem(aParam.mRecording.mLen, SharedMemory::TYPE_BASIC, &shmem)) { WriteParam(aMsg, gfx::IntSize(0, 0)); return; } memcpy(shmem.get(), aParam.mRecording.mData, aParam.mRecording.mLen); WriteParam(aMsg, aParam.mSize); WriteIPDLParam(aMsg, aActor, std::move(shmem)); WriteParam(aMsg, aParam.mDependencies); } static bool Read(const IPC::Message* aMsg, PickleIterator* aIter, IProtocol* aActor, paramType* aResult) { if (!ReadParam(aMsg, aIter, &aResult->mSize)) { return false; } if (aResult->mSize.IsEmpty()) { return true; } Shmem shmem; if (!ReadIPDLParam(aMsg, aIter, aActor, &shmem) || !ReadParam(aMsg, aIter, &aResult->mDependencies)) { aActor->DeallocShmem(shmem); return false; } if (!aResult->mRecording.Allocate(shmem.Size())) { aResult->mSize.SizeTo(0, 0); aActor->DeallocShmem(shmem); return true; } memcpy(aResult->mRecording.mData, shmem.get(), shmem.Size()); aActor->DeallocShmem(shmem); return true; } }; } // namespace ipc } // namespace mozilla #endif /* __GFXMESSAGEUTILS_H__ */