michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=8 et tw=80 : */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef __GFXMESSAGEUTILS_H__ michael@0: #define __GFXMESSAGEUTILS_H__ michael@0: michael@0: #include "base/process_util.h" michael@0: #include "chrome/common/ipc_message_utils.h" michael@0: #include "ipc/IPCMessageUtils.h" michael@0: michael@0: #include michael@0: michael@0: #include "gfx3DMatrix.h" michael@0: #include "gfxColor.h" michael@0: #include "mozilla/gfx/Matrix.h" michael@0: #include "GraphicsFilter.h" michael@0: #include "gfxPoint.h" michael@0: #include "gfxRect.h" michael@0: #include "nsRect.h" michael@0: #include "nsRegion.h" michael@0: #include "gfxTypes.h" michael@0: #include "mozilla/layers/LayersTypes.h" michael@0: #include "mozilla/layers/CompositorTypes.h" michael@0: #include "FrameMetrics.h" michael@0: #include "FilterSupport.h" michael@0: #include "mozilla/layers/GeckoContentController.h" michael@0: michael@0: #ifdef _MSC_VER michael@0: #pragma warning( disable : 4800 ) michael@0: #endif michael@0: michael@0: namespace mozilla { michael@0: michael@0: typedef gfxImageFormat PixelFormat; michael@0: #if defined(MOZ_HAVE_CXX11_STRONG_ENUMS) michael@0: typedef ::GraphicsFilter GraphicsFilterType; michael@0: #else michael@0: // If we don't have support for enum classes, then we need to use the actual michael@0: // enum type here instead of the simulated enum class. michael@0: typedef GraphicsFilter::Enum GraphicsFilterType; michael@0: #endif michael@0: michael@0: } // namespace mozilla michael@0: michael@0: namespace IPC { michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::gfx::Matrix paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam._11); michael@0: WriteParam(aMsg, aParam._12); michael@0: WriteParam(aMsg, aParam._21); michael@0: WriteParam(aMsg, aParam._22); michael@0: WriteParam(aMsg, aParam._31); michael@0: WriteParam(aMsg, aParam._32); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: if (ReadParam(aMsg, aIter, &aResult->_11) && michael@0: ReadParam(aMsg, aIter, &aResult->_12) && michael@0: ReadParam(aMsg, aIter, &aResult->_21) && michael@0: ReadParam(aMsg, aIter, &aResult->_22) && michael@0: ReadParam(aMsg, aIter, &aResult->_31) && michael@0: ReadParam(aMsg, aIter, &aResult->_32)) michael@0: return true; michael@0: michael@0: return false; michael@0: } michael@0: michael@0: static void Log(const paramType& aParam, std::wstring* aLog) michael@0: { michael@0: aLog->append(StringPrintf(L"[[%g %g] [%g %g] [%g %g]]", aParam._11, aParam._12, aParam._21, aParam._22, michael@0: aParam._31, aParam._32)); michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::gfx::Matrix4x4 paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: #define Wr(_f) WriteParam(msg, param. _f) michael@0: Wr(_11); Wr(_12); Wr(_13); Wr(_14); michael@0: Wr(_21); Wr(_22); Wr(_23); Wr(_24); michael@0: Wr(_31); Wr(_32); Wr(_33); Wr(_34); michael@0: Wr(_41); Wr(_42); Wr(_43); Wr(_44); michael@0: #undef Wr michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: #define Rd(_f) ReadParam(msg, iter, &result-> _f) michael@0: return (Rd(_11) && Rd(_12) && Rd(_13) && Rd(_14) && michael@0: Rd(_21) && Rd(_22) && Rd(_23) && Rd(_24) && michael@0: Rd(_31) && Rd(_32) && Rd(_33) && Rd(_34) && michael@0: Rd(_41) && Rd(_42) && Rd(_43) && Rd(_44)); michael@0: #undef Rd michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::gfx::Matrix5x4 paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: #define Wr(_f) WriteParam(msg, param. _f) michael@0: Wr(_11); Wr(_12); Wr(_13); Wr(_14); michael@0: Wr(_21); Wr(_22); Wr(_23); Wr(_24); michael@0: Wr(_31); Wr(_32); Wr(_33); Wr(_34); michael@0: Wr(_41); Wr(_42); Wr(_43); Wr(_44); michael@0: Wr(_51); Wr(_52); Wr(_53); Wr(_54); michael@0: #undef Wr michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: #define Rd(_f) ReadParam(msg, iter, &result-> _f) michael@0: return (Rd(_11) && Rd(_12) && Rd(_13) && Rd(_14) && michael@0: Rd(_21) && Rd(_22) && Rd(_23) && Rd(_24) && michael@0: Rd(_31) && Rd(_32) && Rd(_33) && Rd(_34) && michael@0: Rd(_41) && Rd(_42) && Rd(_43) && Rd(_44) && michael@0: Rd(_51) && Rd(_52) && Rd(_53) && Rd(_54)); michael@0: #undef Rd michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef gfxPoint paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.x); michael@0: WriteParam(aMsg, aParam.y); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: return (ReadParam(aMsg, aIter, &aResult->x) && michael@0: ReadParam(aMsg, aIter, &aResult->y)); michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef gfxPoint3D paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.x); michael@0: WriteParam(aMsg, aParam.y); michael@0: WriteParam(aMsg, aParam.z); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: return (ReadParam(aMsg, aIter, &aResult->x) && michael@0: ReadParam(aMsg, aIter, &aResult->y) && michael@0: ReadParam(aMsg, aIter, &aResult->z)); michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef gfxSize paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.width); michael@0: WriteParam(aMsg, aParam.height); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: if (ReadParam(aMsg, aIter, &aResult->width) && michael@0: ReadParam(aMsg, aIter, &aResult->height)) michael@0: return true; michael@0: michael@0: return false; michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef gfxRect paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.x); michael@0: WriteParam(aMsg, aParam.y); michael@0: WriteParam(aMsg, aParam.width); michael@0: WriteParam(aMsg, aParam.height); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: return ReadParam(aMsg, aIter, &aResult->x) && michael@0: ReadParam(aMsg, aIter, &aResult->y) && michael@0: ReadParam(aMsg, aIter, &aResult->width) && michael@0: ReadParam(aMsg, aIter, &aResult->height); michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef gfx3DMatrix paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: #define Wr(_f) WriteParam(msg, param. _f) michael@0: Wr(_11); Wr(_12); Wr(_13); Wr(_14); michael@0: Wr(_21); Wr(_22); Wr(_23); Wr(_24); michael@0: Wr(_31); Wr(_32); Wr(_33); Wr(_34); michael@0: Wr(_41); Wr(_42); Wr(_43); Wr(_44); michael@0: #undef Wr michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: #define Rd(_f) ReadParam(msg, iter, &result-> _f) michael@0: return (Rd(_11) && Rd(_12) && Rd(_13) && Rd(_14) && michael@0: Rd(_21) && Rd(_22) && Rd(_23) && Rd(_24) && michael@0: Rd(_31) && Rd(_32) && Rd(_33) && Rd(_34) && michael@0: Rd(_41) && Rd(_42) && Rd(_43) && Rd(_44)); michael@0: #undef Rd michael@0: } michael@0: }; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: : public ContiguousTypedEnumSerializer< michael@0: gfxContentType, michael@0: gfxContentType::COLOR, michael@0: gfxContentType::SENTINEL> michael@0: {}; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: : public ContiguousTypedEnumSerializer< michael@0: gfxSurfaceType, michael@0: gfxSurfaceType::Image, michael@0: gfxSurfaceType::Max> michael@0: {}; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: : public ContiguousEnumSerializer< michael@0: mozilla::GraphicsFilterType, michael@0: GraphicsFilter::FILTER_FAST, michael@0: GraphicsFilter::FILTER_SENTINEL> michael@0: {}; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: : public ContiguousTypedEnumSerializer< michael@0: mozilla::layers::LayersBackend, michael@0: mozilla::layers::LayersBackend::LAYERS_NONE, michael@0: mozilla::layers::LayersBackend::LAYERS_LAST> michael@0: {}; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: : public ContiguousTypedEnumSerializer< michael@0: mozilla::layers::ScaleMode, michael@0: mozilla::layers::ScaleMode::SCALE_NONE, michael@0: mozilla::layers::ScaleMode::SENTINEL> michael@0: {}; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: : public ContiguousTypedEnumSerializer< michael@0: gfxImageFormat, michael@0: gfxImageFormat::ARGB32, michael@0: gfxImageFormat::Unknown> michael@0: {}; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: : public ContiguousEnumSerializer< michael@0: mozilla::gfx::AttributeName, michael@0: mozilla::gfx::eBlendBlendmode, michael@0: mozilla::gfx::eLastAttributeName> michael@0: {}; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: : public ContiguousTypedEnumSerializer< michael@0: mozilla::gfx::AttributeType, michael@0: mozilla::gfx::AttributeType::eBool, michael@0: mozilla::gfx::AttributeType::Max> michael@0: {}; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: : public ContiguousTypedEnumSerializer< michael@0: mozilla::gfx::PrimitiveType, michael@0: mozilla::gfx::PrimitiveType::Empty, michael@0: mozilla::gfx::PrimitiveType::Max> michael@0: {}; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: : public ContiguousTypedEnumSerializer< michael@0: mozilla::gfx::ColorSpace, michael@0: mozilla::gfx::ColorSpace::SRGB, michael@0: mozilla::gfx::ColorSpace::Max> michael@0: {}; michael@0: michael@0: /* michael@0: template <> michael@0: struct ParamTraits michael@0: : public EnumSerializer michael@0: {}; michael@0: */ michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef gfxRGBA paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: WriteParam(msg, param.r); michael@0: WriteParam(msg, param.g); michael@0: WriteParam(msg, param.b); michael@0: WriteParam(msg, param.a); michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: return (ReadParam(msg, iter, &result->r) && michael@0: ReadParam(msg, iter, &result->g) && michael@0: ReadParam(msg, iter, &result->b) && michael@0: ReadParam(msg, iter, &result->a)); michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::gfx::Color paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: WriteParam(msg, param.r); michael@0: WriteParam(msg, param.g); michael@0: WriteParam(msg, param.b); michael@0: WriteParam(msg, param.a); michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: return (ReadParam(msg, iter, &result->r) && michael@0: ReadParam(msg, iter, &result->g) && michael@0: ReadParam(msg, iter, &result->b) && michael@0: ReadParam(msg, iter, &result->a)); michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef nsPoint paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: WriteParam(msg, param.x); michael@0: WriteParam(msg, param.y); michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: return (ReadParam(msg, iter, &result->x) && michael@0: ReadParam(msg, iter, &result->y)); michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef nsIntPoint paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: WriteParam(msg, param.x); michael@0: WriteParam(msg, param.y); michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: return (ReadParam(msg, iter, &result->x) && michael@0: ReadParam(msg, iter, &result->y)); michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::gfx::IntSize paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: WriteParam(msg, param.width); michael@0: WriteParam(msg, param.height); michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: return (ReadParam(msg, iter, &result->width) && michael@0: ReadParam(msg, iter, &result->height)); michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef nsIntRect paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: WriteParam(msg, param.x); michael@0: WriteParam(msg, param.y); michael@0: WriteParam(msg, param.width); michael@0: WriteParam(msg, param.height); michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: return (ReadParam(msg, iter, &result->x) && michael@0: ReadParam(msg, iter, &result->y) && michael@0: ReadParam(msg, iter, &result->width) && michael@0: ReadParam(msg, iter, &result->height)); michael@0: } michael@0: }; michael@0: michael@0: template michael@0: struct RegionParamTraits michael@0: { michael@0: typedef Region paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: Iter it(param); michael@0: while (const Rect* r = it.Next()) michael@0: WriteParam(msg, *r); michael@0: // empty rects are sentinel values because nsRegions will never michael@0: // contain them michael@0: WriteParam(msg, Rect()); michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: Rect rect; michael@0: while (ReadParam(msg, iter, &rect)) { michael@0: if (rect.IsEmpty()) michael@0: return true; michael@0: result->Or(*result, rect); michael@0: } michael@0: return false; michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: : RegionParamTraits michael@0: {}; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef nsIntSize paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: WriteParam(msg, param.width); michael@0: WriteParam(msg, param.height); michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: return (ReadParam(msg, iter, &result->width) && michael@0: ReadParam(msg, iter, &result->height)); michael@0: } michael@0: }; michael@0: michael@0: template michael@0: struct ParamTraits< mozilla::gfx::ScaleFactor > michael@0: { michael@0: typedef mozilla::gfx::ScaleFactor paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: WriteParam(msg, param.scale); michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: return (ReadParam(msg, iter, &result->scale)); michael@0: } michael@0: }; michael@0: michael@0: template michael@0: struct ParamTraits< mozilla::gfx::PointTyped > michael@0: { michael@0: typedef mozilla::gfx::PointTyped paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: WriteParam(msg, param.x); michael@0: WriteParam(msg, param.y); michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: return (ReadParam(msg, iter, &result->x) && michael@0: ReadParam(msg, iter, &result->y)); michael@0: } michael@0: }; michael@0: michael@0: template michael@0: struct ParamTraits< mozilla::gfx::Point3DTyped > michael@0: { michael@0: typedef mozilla::gfx::Point3DTyped paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: WriteParam(msg, param.x); michael@0: WriteParam(msg, param.y); michael@0: WriteParam(msg, param.z); michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: return (ReadParam(msg, iter, &result->x) && michael@0: ReadParam(msg, iter, &result->y) && michael@0: ReadParam(msg, iter, &result->z)); michael@0: } michael@0: }; michael@0: michael@0: template michael@0: struct ParamTraits< mozilla::gfx::IntPointTyped > michael@0: { michael@0: typedef mozilla::gfx::IntPointTyped paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: WriteParam(msg, param.x); michael@0: WriteParam(msg, param.y); michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: return (ReadParam(msg, iter, &result->x) && michael@0: ReadParam(msg, iter, &result->y)); michael@0: } michael@0: }; michael@0: michael@0: template michael@0: struct ParamTraits< mozilla::gfx::SizeTyped > michael@0: { michael@0: typedef mozilla::gfx::SizeTyped paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: WriteParam(msg, param.width); michael@0: WriteParam(msg, param.height); michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: return (ReadParam(msg, iter, &result->width) && michael@0: ReadParam(msg, iter, &result->height)); michael@0: } michael@0: }; michael@0: michael@0: template michael@0: struct ParamTraits< mozilla::gfx::RectTyped > michael@0: { michael@0: typedef mozilla::gfx::RectTyped paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: WriteParam(msg, param.x); michael@0: WriteParam(msg, param.y); michael@0: WriteParam(msg, param.width); michael@0: WriteParam(msg, param.height); michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: return (ReadParam(msg, iter, &result->x) && michael@0: ReadParam(msg, iter, &result->y) && michael@0: ReadParam(msg, iter, &result->width) && michael@0: ReadParam(msg, iter, &result->height)); michael@0: } michael@0: }; michael@0: michael@0: template michael@0: struct ParamTraits< mozilla::gfx::IntRectTyped > michael@0: { michael@0: typedef mozilla::gfx::IntRectTyped paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: WriteParam(msg, param.x); michael@0: WriteParam(msg, param.y); michael@0: WriteParam(msg, param.width); michael@0: WriteParam(msg, param.height); michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: return (ReadParam(msg, iter, &result->x) && michael@0: ReadParam(msg, iter, &result->y) && michael@0: ReadParam(msg, iter, &result->width) && michael@0: ReadParam(msg, iter, &result->height)); michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::gfx::Margin paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: WriteParam(msg, param.top); michael@0: WriteParam(msg, param.right); michael@0: WriteParam(msg, param.bottom); michael@0: WriteParam(msg, param.left); michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: return (ReadParam(msg, iter, &result->top) && michael@0: ReadParam(msg, iter, &result->right) && michael@0: ReadParam(msg, iter, &result->bottom) && michael@0: ReadParam(msg, iter, &result->left)); michael@0: } michael@0: }; michael@0: michael@0: template michael@0: struct ParamTraits< mozilla::gfx::MarginTyped > michael@0: { michael@0: typedef mozilla::gfx::MarginTyped paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: WriteParam(msg, param.top); michael@0: WriteParam(msg, param.right); michael@0: WriteParam(msg, param.bottom); michael@0: WriteParam(msg, param.left); michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: return (ReadParam(msg, iter, &result->top) && michael@0: ReadParam(msg, iter, &result->right) && michael@0: ReadParam(msg, iter, &result->bottom) && michael@0: ReadParam(msg, iter, &result->left)); michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef nsRect paramType; michael@0: michael@0: static void Write(Message* msg, const paramType& param) michael@0: { michael@0: WriteParam(msg, param.x); michael@0: WriteParam(msg, param.y); michael@0: WriteParam(msg, param.width); michael@0: WriteParam(msg, param.height); michael@0: } michael@0: michael@0: static bool Read(const Message* msg, void** iter, paramType* result) michael@0: { michael@0: return (ReadParam(msg, iter, &result->x) && michael@0: ReadParam(msg, iter, &result->y) && michael@0: ReadParam(msg, iter, &result->width) && michael@0: ReadParam(msg, iter, &result->height)); michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: : RegionParamTraits michael@0: {}; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::layers::FrameMetrics paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.mScrollableRect); michael@0: WriteParam(aMsg, aParam.mViewport); michael@0: WriteParam(aMsg, aParam.mScrollOffset); michael@0: WriteParam(aMsg, aParam.mDisplayPort); michael@0: WriteParam(aMsg, aParam.mDisplayPortMargins); michael@0: WriteParam(aMsg, aParam.mUseDisplayPortMargins); michael@0: WriteParam(aMsg, aParam.mCriticalDisplayPort); michael@0: WriteParam(aMsg, aParam.mCompositionBounds); michael@0: WriteParam(aMsg, aParam.mRootCompositionSize); michael@0: WriteParam(aMsg, aParam.mScrollId); michael@0: WriteParam(aMsg, aParam.mResolution); michael@0: WriteParam(aMsg, aParam.mCumulativeResolution); michael@0: WriteParam(aMsg, aParam.mZoom); michael@0: WriteParam(aMsg, aParam.mDevPixelsPerCSSPixel); michael@0: WriteParam(aMsg, aParam.mMayHaveTouchListeners); michael@0: WriteParam(aMsg, aParam.mPresShellId); michael@0: WriteParam(aMsg, aParam.mIsRoot); michael@0: WriteParam(aMsg, aParam.mHasScrollgrab); michael@0: WriteParam(aMsg, aParam.mUpdateScrollOffset); michael@0: WriteParam(aMsg, aParam.mScrollGeneration); michael@0: WriteParam(aMsg, aParam.mContentDescription); michael@0: WriteParam(aMsg, aParam.mTransformScale); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: return (ReadParam(aMsg, aIter, &aResult->mScrollableRect) && michael@0: ReadParam(aMsg, aIter, &aResult->mViewport) && michael@0: ReadParam(aMsg, aIter, &aResult->mScrollOffset) && michael@0: ReadParam(aMsg, aIter, &aResult->mDisplayPort) && michael@0: ReadParam(aMsg, aIter, &aResult->mDisplayPortMargins) && michael@0: ReadParam(aMsg, aIter, &aResult->mUseDisplayPortMargins) && michael@0: ReadParam(aMsg, aIter, &aResult->mCriticalDisplayPort) && michael@0: ReadParam(aMsg, aIter, &aResult->mCompositionBounds) && michael@0: ReadParam(aMsg, aIter, &aResult->mRootCompositionSize) && michael@0: ReadParam(aMsg, aIter, &aResult->mScrollId) && michael@0: ReadParam(aMsg, aIter, &aResult->mResolution) && michael@0: ReadParam(aMsg, aIter, &aResult->mCumulativeResolution) && michael@0: ReadParam(aMsg, aIter, &aResult->mZoom) && michael@0: ReadParam(aMsg, aIter, &aResult->mDevPixelsPerCSSPixel) && michael@0: ReadParam(aMsg, aIter, &aResult->mMayHaveTouchListeners) && michael@0: ReadParam(aMsg, aIter, &aResult->mPresShellId) && michael@0: ReadParam(aMsg, aIter, &aResult->mIsRoot) && michael@0: ReadParam(aMsg, aIter, &aResult->mHasScrollgrab) && michael@0: ReadParam(aMsg, aIter, &aResult->mUpdateScrollOffset) && michael@0: ReadParam(aMsg, aIter, &aResult->mScrollGeneration) && michael@0: ReadParam(aMsg, aIter, &aResult->mContentDescription) && michael@0: ReadParam(aMsg, aIter, &aResult->mTransformScale)); michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::layers::TextureFactoryIdentifier paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.mParentBackend); michael@0: WriteParam(aMsg, aParam.mMaxTextureSize); michael@0: WriteParam(aMsg, aParam.mSupportsTextureBlitting); michael@0: WriteParam(aMsg, aParam.mSupportsPartialUploads); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: return ReadParam(aMsg, aIter, &aResult->mParentBackend) && michael@0: ReadParam(aMsg, aIter, &aResult->mMaxTextureSize) && michael@0: ReadParam(aMsg, aIter, &aResult->mSupportsTextureBlitting) && michael@0: ReadParam(aMsg, aIter, &aResult->mSupportsPartialUploads); michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::layers::TextureInfo paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.mCompositableType); michael@0: WriteParam(aMsg, aParam.mDeprecatedTextureHostFlags); michael@0: WriteParam(aMsg, aParam.mTextureFlags); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: return ReadParam(aMsg, aIter, &aResult->mCompositableType) && michael@0: ReadParam(aMsg, aIter, &aResult->mDeprecatedTextureHostFlags) && michael@0: ReadParam(aMsg, aIter, &aResult->mTextureFlags); michael@0: } michael@0: }; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: : public ContiguousEnumSerializer< michael@0: mozilla::layers::CompositableType, michael@0: mozilla::layers::BUFFER_UNKNOWN, michael@0: mozilla::layers::BUFFER_COUNT> michael@0: {}; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: : public ContiguousTypedEnumSerializer< michael@0: mozilla::gfx::SurfaceFormat, michael@0: mozilla::gfx::SurfaceFormat::B8G8R8A8, michael@0: mozilla::gfx::SurfaceFormat::UNKNOWN> michael@0: {}; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::layers::ScrollableLayerGuid paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.mLayersId); michael@0: WriteParam(aMsg, aParam.mPresShellId); michael@0: WriteParam(aMsg, aParam.mScrollId); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: return (ReadParam(aMsg, aIter, &aResult->mLayersId) && michael@0: ReadParam(aMsg, aIter, &aResult->mPresShellId) && michael@0: ReadParam(aMsg, aIter, &aResult->mScrollId)); michael@0: } michael@0: }; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::layers::ZoomConstraints paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.mAllowZoom); michael@0: WriteParam(aMsg, aParam.mAllowDoubleTapZoom); michael@0: WriteParam(aMsg, aParam.mMinZoom); michael@0: WriteParam(aMsg, aParam.mMaxZoom); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: return (ReadParam(aMsg, aIter, &aResult->mAllowZoom) && michael@0: ReadParam(aMsg, aIter, &aResult->mAllowDoubleTapZoom) && michael@0: ReadParam(aMsg, aIter, &aResult->mMinZoom) && michael@0: ReadParam(aMsg, aIter, &aResult->mMaxZoom)); michael@0: } michael@0: }; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::layers::EventRegions paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.mHitRegion); michael@0: WriteParam(aMsg, aParam.mDispatchToContentHitRegion); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: return (ReadParam(aMsg, aIter, &aResult->mHitRegion) && michael@0: ReadParam(aMsg, aIter, &aResult->mDispatchToContentHitRegion)); michael@0: } michael@0: }; michael@0: michael@0: struct MessageAndAttributeMap michael@0: { michael@0: Message* msg; michael@0: const mozilla::gfx::AttributeMap& map; michael@0: }; michael@0: michael@0: static bool michael@0: WriteAttribute(mozilla::gfx::AttributeName aName, michael@0: mozilla::gfx::AttributeType aType, michael@0: void* aUserData) michael@0: { michael@0: MessageAndAttributeMap* msgAndMap = michael@0: static_cast(aUserData); michael@0: michael@0: WriteParam(msgAndMap->msg, aType); michael@0: WriteParam(msgAndMap->msg, aName); michael@0: michael@0: switch (aType) { michael@0: michael@0: #define HANDLE_TYPE(typeName) \ michael@0: case mozilla::gfx::AttributeType::e##typeName: \ michael@0: WriteParam(msgAndMap->msg, msgAndMap->map.Get##typeName(aName)); \ michael@0: break; michael@0: michael@0: HANDLE_TYPE(Bool) michael@0: HANDLE_TYPE(Uint) michael@0: HANDLE_TYPE(Float) michael@0: HANDLE_TYPE(Size) michael@0: HANDLE_TYPE(IntSize) michael@0: HANDLE_TYPE(IntPoint) michael@0: HANDLE_TYPE(Matrix) michael@0: HANDLE_TYPE(Matrix5x4) michael@0: HANDLE_TYPE(Point3D) michael@0: HANDLE_TYPE(Color) michael@0: HANDLE_TYPE(AttributeMap) michael@0: HANDLE_TYPE(Floats) michael@0: michael@0: #undef HANDLE_TYPE michael@0: michael@0: default: michael@0: MOZ_CRASH("unhandled attribute type"); michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::gfx::AttributeMap paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.Count()); michael@0: MessageAndAttributeMap msgAndMap = { aMsg, aParam }; michael@0: aParam.EnumerateRead(WriteAttribute, &msgAndMap); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: uint32_t count; michael@0: if (!ReadParam(aMsg, aIter, &count)) { michael@0: return false; michael@0: } michael@0: for (uint32_t i = 0; i < count; i++) { michael@0: mozilla::gfx::AttributeType type; michael@0: if (!ReadParam(aMsg, aIter, &type)) { michael@0: return false; michael@0: } michael@0: mozilla::gfx::AttributeName name; michael@0: if (!ReadParam(aMsg, aIter, &name)) { michael@0: return false; michael@0: } michael@0: switch (type) { michael@0: michael@0: #define HANDLE_TYPE(type, typeName) \ michael@0: case mozilla::gfx::AttributeType::e##typeName: \ michael@0: { \ michael@0: type value; \ michael@0: if (!ReadParam(aMsg, aIter, &value)) { \ michael@0: return false; \ michael@0: } \ michael@0: aResult->Set(name, value); \ michael@0: } michael@0: michael@0: HANDLE_TYPE(bool, Bool) michael@0: HANDLE_TYPE(uint32_t, Uint) michael@0: HANDLE_TYPE(float, Float) michael@0: HANDLE_TYPE(mozilla::gfx::Size, Size) michael@0: HANDLE_TYPE(mozilla::gfx::IntSize, IntSize) michael@0: HANDLE_TYPE(mozilla::gfx::IntPoint, IntPoint) michael@0: HANDLE_TYPE(mozilla::gfx::Matrix, Matrix) michael@0: HANDLE_TYPE(mozilla::gfx::Matrix5x4, Matrix5x4) michael@0: HANDLE_TYPE(mozilla::gfx::Point3D, Point3D) michael@0: HANDLE_TYPE(mozilla::gfx::Color, Color) michael@0: HANDLE_TYPE(mozilla::gfx::AttributeMap, AttributeMap) michael@0: michael@0: #undef HANDLE_TYPE michael@0: michael@0: case mozilla::gfx::AttributeType::eFloats: michael@0: { michael@0: nsTArray value; michael@0: if (!ReadParam(aMsg, aIter, &value)) { michael@0: return false; michael@0: } michael@0: aResult->Set(name, &value[0], value.Length()); michael@0: break; michael@0: } michael@0: default: michael@0: MOZ_CRASH("unhandled attribute type"); michael@0: } michael@0: } michael@0: return true; michael@0: } michael@0: }; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::gfx::FilterPrimitiveDescription paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.Type()); michael@0: WriteParam(aMsg, aParam.PrimitiveSubregion()); michael@0: WriteParam(aMsg, aParam.IsTainted()); michael@0: WriteParam(aMsg, aParam.OutputColorSpace()); michael@0: WriteParam(aMsg, aParam.NumberOfInputs()); michael@0: for (size_t i = 0; i < aParam.NumberOfInputs(); i++) { michael@0: WriteParam(aMsg, aParam.InputPrimitiveIndex(i)); michael@0: WriteParam(aMsg, aParam.InputColorSpace(i)); michael@0: } michael@0: WriteParam(aMsg, aParam.Attributes()); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: mozilla::gfx::PrimitiveType type; michael@0: mozilla::gfx::IntRect primitiveSubregion; michael@0: bool isTainted = false; michael@0: mozilla::gfx::ColorSpace outputColorSpace; michael@0: size_t numberOfInputs = 0; michael@0: if (!ReadParam(aMsg, aIter, &type) || michael@0: !ReadParam(aMsg, aIter, &primitiveSubregion) || michael@0: !ReadParam(aMsg, aIter, &isTainted) || michael@0: !ReadParam(aMsg, aIter, &outputColorSpace) || michael@0: !ReadParam(aMsg, aIter, &numberOfInputs)) { michael@0: return false; michael@0: } michael@0: michael@0: aResult->SetType(type); michael@0: aResult->SetPrimitiveSubregion(primitiveSubregion); michael@0: aResult->SetIsTainted(isTainted); michael@0: aResult->SetOutputColorSpace(outputColorSpace); michael@0: michael@0: for (size_t i = 0; i < numberOfInputs; i++) { michael@0: int32_t inputPrimitiveIndex = 0; michael@0: mozilla::gfx::ColorSpace inputColorSpace; michael@0: if (!ReadParam(aMsg, aIter, &inputPrimitiveIndex) || michael@0: !ReadParam(aMsg, aIter, &inputColorSpace)) { michael@0: return false; michael@0: } michael@0: aResult->SetInputPrimitive(i, inputPrimitiveIndex); michael@0: aResult->SetInputColorSpace(i, inputColorSpace); michael@0: } michael@0: michael@0: return ReadParam(aMsg, aIter, &aResult->Attributes()); michael@0: } michael@0: }; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::gfx::FilterDescription paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.mFilterSpaceBounds); michael@0: WriteParam(aMsg, aParam.mPrimitives); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: return (ReadParam(aMsg, aIter, &aResult->mFilterSpaceBounds) && michael@0: ReadParam(aMsg, aIter, &aResult->mPrimitives)); michael@0: } michael@0: }; michael@0: michael@0: typedef mozilla::layers::GeckoContentController::APZStateChange APZStateChange; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: : public ContiguousTypedEnumSerializer< michael@0: APZStateChange, michael@0: APZStateChange::TransformBegin, michael@0: APZStateChange::APZStateChangeSentinel> michael@0: {}; michael@0: michael@0: } /* namespace IPC */ michael@0: michael@0: #endif /* __GFXMESSAGEUTILS_H__ */