/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set sw=2 ts=8 et 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 "base/process_util.h" #include "chrome/common/ipc_message_utils.h" #include "ipc/IPCMessageUtils.h" #include #include "gfx3DMatrix.h" #include "gfxColor.h" #include "mozilla/gfx/Matrix.h" #include "GraphicsFilter.h" #include "gfxPoint.h" #include "gfxRect.h" #include "nsRect.h" #include "nsRegion.h" #include "gfxTypes.h" #include "mozilla/layers/LayersTypes.h" #include "mozilla/layers/CompositorTypes.h" #include "FrameMetrics.h" #ifdef _MSC_VER #pragma warning( disable : 4800 ) #endif namespace mozilla { typedef gfxImageFormat PixelFormat; #if defined(MOZ_HAVE_CXX11_STRONG_ENUMS) typedef ::GraphicsFilter GraphicsFilterType; #else // If we don't have support for enum classes, then we need to use the actual // enum type here instead of the simulated enum class. typedef GraphicsFilter::Enum GraphicsFilterType; #endif } // 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, void** 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 gfxPoint paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.x); WriteParam(aMsg, aParam.y); } static bool Read(const Message* aMsg, void** aIter, paramType* aResult) { return (ReadParam(aMsg, aIter, &aResult->x) && ReadParam(aMsg, aIter, &aResult->y)); } }; template<> struct ParamTraits { typedef gfxPoint3D paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.x); WriteParam(aMsg, aParam.y); WriteParam(aMsg, aParam.z); } static bool Read(const Message* aMsg, void** aIter, paramType* aResult) { return (ReadParam(aMsg, aIter, &aResult->x) && ReadParam(aMsg, aIter, &aResult->y) && ReadParam(aMsg, aIter, &aResult->z)); } }; 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, void** 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, void** aIter, paramType* aResult) { return ReadParam(aMsg, aIter, &aResult->x) && ReadParam(aMsg, aIter, &aResult->y) && ReadParam(aMsg, aIter, &aResult->width) && ReadParam(aMsg, aIter, &aResult->height); } }; template<> struct ParamTraits { typedef gfx3DMatrix 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, void** 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 : public TypedEnumSerializer {}; template <> struct ParamTraits : public TypedEnumSerializer {}; template <> struct ParamTraits : public EnumSerializer {}; template <> struct ParamTraits : public EnumSerializer {}; template <> struct ParamTraits : public EnumSerializer {}; template <> struct ParamTraits : public TypedEnumSerializer {}; /* template <> struct ParamTraits : public EnumSerializer {}; */ template<> struct ParamTraits { typedef gfxRGBA 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, void** 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, void** 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, void** iter, paramType* result) { return (ReadParam(msg, iter, &result->x) && ReadParam(msg, iter, &result->y)); } }; 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, void** iter, paramType* result) { return (ReadParam(msg, iter, &result->width) && ReadParam(msg, iter, &result->height)); } }; template<> struct ParamTraits { typedef nsIntRect 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, void** iter, paramType* result) { return (ReadParam(msg, iter, &result->x) && ReadParam(msg, iter, &result->y) && ReadParam(msg, iter, &result->width) && ReadParam(msg, iter, &result->height)); } }; template struct RegionParamTraits { typedef Region paramType; static void Write(Message* msg, const paramType& param) { Iter it(param); while (const Rect* r = it.Next()) WriteParam(msg, *r); // empty rects are sentinel values because nsRegions will never // contain them WriteParam(msg, Rect()); } static bool Read(const Message* msg, void** iter, paramType* result) { Rect rect; while (ReadParam(msg, iter, &rect)) { if (rect.IsEmpty()) return true; result->Or(*result, rect); } return false; } }; template<> struct ParamTraits : RegionParamTraits {}; template<> struct ParamTraits { typedef nsIntSize paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.width); WriteParam(msg, param.height); } static bool Read(const Message* msg, void** iter, paramType* result) { return (ReadParam(msg, iter, &result->width) && ReadParam(msg, iter, &result->height)); } }; template struct ParamTraits< mozilla::gfx::ScaleFactor > { typedef mozilla::gfx::ScaleFactor paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.scale); } static bool Read(const Message* msg, void** iter, paramType* result) { return (ReadParam(msg, iter, &result->scale)); } }; template struct ParamTraits< mozilla::gfx::PointTyped > { 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, void** iter, paramType* result) { return (ReadParam(msg, iter, &result->x) && ReadParam(msg, iter, &result->y)); } }; template struct ParamTraits< mozilla::gfx::IntPointTyped > { 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, void** iter, paramType* result) { return (ReadParam(msg, iter, &result->x) && ReadParam(msg, iter, &result->y)); } }; template<> struct ParamTraits { typedef mozilla::gfx::Size paramType; static void Write(Message* msg, const paramType& param) { WriteParam(msg, param.width); WriteParam(msg, param.height); } static bool Read(const Message* msg, void** iter, paramType* result) { return (ReadParam(msg, iter, &result->width) && ReadParam(msg, iter, &result->height)); } }; template struct ParamTraits< mozilla::gfx::RectTyped > { 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, void** iter, paramType* result) { return (ReadParam(msg, iter, &result->x) && ReadParam(msg, iter, &result->y) && ReadParam(msg, iter, &result->width) && ReadParam(msg, iter, &result->height)); } }; template struct ParamTraits< mozilla::gfx::IntRectTyped > { 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, void** iter, paramType* result) { return (ReadParam(msg, iter, &result->x) && ReadParam(msg, iter, &result->y) && ReadParam(msg, iter, &result->width) && ReadParam(msg, iter, &result->height)); } }; 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, void** 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< mozilla::gfx::MarginTyped > { 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, void** 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, void** iter, paramType* result) { return (ReadParam(msg, iter, &result->x) && ReadParam(msg, iter, &result->y) && ReadParam(msg, iter, &result->width) && ReadParam(msg, iter, &result->height)); } }; template<> struct ParamTraits : RegionParamTraits {}; template <> struct ParamTraits { typedef mozilla::layers::FrameMetrics paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mScrollableRect); WriteParam(aMsg, aParam.mViewport); WriteParam(aMsg, aParam.mScrollOffset); WriteParam(aMsg, aParam.mDisplayPort); WriteParam(aMsg, aParam.mCriticalDisplayPort); WriteParam(aMsg, aParam.mCompositionBounds); WriteParam(aMsg, aParam.mScrollId); WriteParam(aMsg, aParam.mResolution); WriteParam(aMsg, aParam.mCumulativeResolution); WriteParam(aMsg, aParam.mZoom); WriteParam(aMsg, aParam.mDevPixelsPerCSSPixel); WriteParam(aMsg, aParam.mMayHaveTouchListeners); WriteParam(aMsg, aParam.mPresShellId); WriteParam(aMsg, aParam.mIsRoot); WriteParam(aMsg, aParam.mHasScrollgrab); WriteParam(aMsg, aParam.mUpdateScrollOffset); WriteParam(aMsg, aParam.mDisableScrollingX); WriteParam(aMsg, aParam.mDisableScrollingY); } static bool Read(const Message* aMsg, void** aIter, paramType* aResult) { return (ReadParam(aMsg, aIter, &aResult->mScrollableRect) && ReadParam(aMsg, aIter, &aResult->mViewport) && ReadParam(aMsg, aIter, &aResult->mScrollOffset) && ReadParam(aMsg, aIter, &aResult->mDisplayPort) && ReadParam(aMsg, aIter, &aResult->mCriticalDisplayPort) && ReadParam(aMsg, aIter, &aResult->mCompositionBounds) && ReadParam(aMsg, aIter, &aResult->mScrollId) && ReadParam(aMsg, aIter, &aResult->mResolution) && ReadParam(aMsg, aIter, &aResult->mCumulativeResolution) && ReadParam(aMsg, aIter, &aResult->mZoom) && ReadParam(aMsg, aIter, &aResult->mDevPixelsPerCSSPixel) && ReadParam(aMsg, aIter, &aResult->mMayHaveTouchListeners) && ReadParam(aMsg, aIter, &aResult->mPresShellId) && ReadParam(aMsg, aIter, &aResult->mIsRoot) && ReadParam(aMsg, aIter, &aResult->mHasScrollgrab) && ReadParam(aMsg, aIter, &aResult->mUpdateScrollOffset) && ReadParam(aMsg, aIter, &aResult->mDisableScrollingX) && ReadParam(aMsg, aIter, &aResult->mDisableScrollingY)); } }; template<> struct ParamTraits { typedef mozilla::layers::TextureFactoryIdentifier paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mParentBackend); WriteParam(aMsg, aParam.mMaxTextureSize); WriteParam(aMsg, aParam.mSupportsTextureBlitting); WriteParam(aMsg, aParam.mSupportsPartialUploads); } static bool Read(const Message* aMsg, void** aIter, paramType* aResult) { return ReadParam(aMsg, aIter, &aResult->mParentBackend) && ReadParam(aMsg, aIter, &aResult->mMaxTextureSize) && ReadParam(aMsg, aIter, &aResult->mSupportsTextureBlitting) && ReadParam(aMsg, aIter, &aResult->mSupportsPartialUploads); } }; template<> struct ParamTraits { typedef mozilla::layers::TextureInfo paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mCompositableType); WriteParam(aMsg, aParam.mDeprecatedTextureHostFlags); WriteParam(aMsg, aParam.mTextureFlags); } static bool Read(const Message* aMsg, void** aIter, paramType* aResult) { return ReadParam(aMsg, aIter, &aResult->mCompositableType) && ReadParam(aMsg, aIter, &aResult->mDeprecatedTextureHostFlags) && ReadParam(aMsg, aIter, &aResult->mTextureFlags); } }; template <> struct ParamTraits : public EnumSerializer {}; template <> struct ParamTraits : public TypedEnumSerializer {}; template <> struct ParamTraits { typedef mozilla::layers::ScrollableLayerGuid paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mLayersId); WriteParam(aMsg, aParam.mPresShellId); WriteParam(aMsg, aParam.mScrollId); } static bool Read(const Message* aMsg, void** aIter, paramType* aResult) { return (ReadParam(aMsg, aIter, &aResult->mLayersId) && ReadParam(aMsg, aIter, &aResult->mPresShellId) && ReadParam(aMsg, aIter, &aResult->mScrollId)); } }; template <> struct ParamTraits { typedef mozilla::layers::ZoomConstraints paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mAllowZoom); WriteParam(aMsg, aParam.mMinZoom); WriteParam(aMsg, aParam.mMaxZoom); } static bool Read(const Message* aMsg, void** aIter, paramType* aResult) { return (ReadParam(aMsg, aIter, &aResult->mAllowZoom) && ReadParam(aMsg, aIter, &aResult->mMinZoom) && ReadParam(aMsg, aIter, &aResult->mMaxZoom)); } }; template <> struct ParamTraits { typedef mozilla::layers::EventRegions paramType; static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, aParam.mHitRegion); WriteParam(aMsg, aParam.mDispatchToContentHitRegion); } static bool Read(const Message* aMsg, void** aIter, paramType* aResult) { return (ReadParam(aMsg, aIter, &aResult->mHitRegion) && ReadParam(aMsg, aIter, &aResult->mDispatchToContentHitRegion)); } }; } /* namespace IPC */ #endif /* __GFXMESSAGEUTILS_H__ */