gfx/ipc/GfxMessageUtils.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set sw=2 ts=8 et tw=80 : */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #ifndef __GFXMESSAGEUTILS_H__
     8 #define __GFXMESSAGEUTILS_H__
    10 #include "base/process_util.h"
    11 #include "chrome/common/ipc_message_utils.h"
    12 #include "ipc/IPCMessageUtils.h"
    14 #include <stdint.h>
    16 #include "gfx3DMatrix.h"
    17 #include "gfxColor.h"
    18 #include "mozilla/gfx/Matrix.h"
    19 #include "GraphicsFilter.h"
    20 #include "gfxPoint.h"
    21 #include "gfxRect.h"
    22 #include "nsRect.h"
    23 #include "nsRegion.h"
    24 #include "gfxTypes.h"
    25 #include "mozilla/layers/LayersTypes.h"
    26 #include "mozilla/layers/CompositorTypes.h"
    27 #include "FrameMetrics.h"
    28 #include "FilterSupport.h"
    29 #include "mozilla/layers/GeckoContentController.h"
    31 #ifdef _MSC_VER
    32 #pragma warning( disable : 4800 )
    33 #endif
    35 namespace mozilla {
    37 typedef gfxImageFormat PixelFormat;
    38 #if defined(MOZ_HAVE_CXX11_STRONG_ENUMS)
    39 typedef ::GraphicsFilter GraphicsFilterType;
    40 #else
    41 // If we don't have support for enum classes, then we need to use the actual
    42 // enum type here instead of the simulated enum class.
    43 typedef GraphicsFilter::Enum GraphicsFilterType;
    44 #endif
    46 } // namespace mozilla
    48 namespace IPC {
    50 template<>
    51 struct ParamTraits<mozilla::gfx::Matrix>
    52 {
    53   typedef mozilla::gfx::Matrix paramType;
    55   static void Write(Message* aMsg, const paramType& aParam)
    56   {
    57     WriteParam(aMsg, aParam._11);
    58     WriteParam(aMsg, aParam._12);
    59     WriteParam(aMsg, aParam._21);
    60     WriteParam(aMsg, aParam._22);
    61     WriteParam(aMsg, aParam._31);
    62     WriteParam(aMsg, aParam._32);
    63   }
    65   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
    66   {
    67     if (ReadParam(aMsg, aIter, &aResult->_11) &&
    68         ReadParam(aMsg, aIter, &aResult->_12) &&
    69         ReadParam(aMsg, aIter, &aResult->_21) &&
    70         ReadParam(aMsg, aIter, &aResult->_22) &&
    71         ReadParam(aMsg, aIter, &aResult->_31) &&
    72         ReadParam(aMsg, aIter, &aResult->_32))
    73       return true;
    75     return false;
    76   }
    78   static void Log(const paramType& aParam, std::wstring* aLog)
    79   {
    80     aLog->append(StringPrintf(L"[[%g %g] [%g %g] [%g %g]]", aParam._11, aParam._12, aParam._21, aParam._22,
    81                                                             aParam._31, aParam._32));
    82   }
    83 };
    85 template<>
    86 struct ParamTraits<mozilla::gfx::Matrix4x4>
    87 {
    88   typedef mozilla::gfx::Matrix4x4 paramType;
    90   static void Write(Message* msg, const paramType& param)
    91   {
    92 #define Wr(_f)  WriteParam(msg, param. _f)
    93     Wr(_11); Wr(_12); Wr(_13); Wr(_14);
    94     Wr(_21); Wr(_22); Wr(_23); Wr(_24);
    95     Wr(_31); Wr(_32); Wr(_33); Wr(_34);
    96     Wr(_41); Wr(_42); Wr(_43); Wr(_44);
    97 #undef Wr
    98   }
   100   static bool Read(const Message* msg, void** iter, paramType* result)
   101   {
   102 #define Rd(_f)  ReadParam(msg, iter, &result-> _f)
   103     return (Rd(_11) && Rd(_12) && Rd(_13) && Rd(_14) &&
   104             Rd(_21) && Rd(_22) && Rd(_23) && Rd(_24) &&
   105             Rd(_31) && Rd(_32) && Rd(_33) && Rd(_34) &&
   106             Rd(_41) && Rd(_42) && Rd(_43) && Rd(_44));
   107 #undef Rd
   108   }
   109 };
   111 template<>
   112 struct ParamTraits<mozilla::gfx::Matrix5x4>
   113 {
   114   typedef mozilla::gfx::Matrix5x4 paramType;
   116   static void Write(Message* msg, const paramType& param)
   117   {
   118 #define Wr(_f)  WriteParam(msg, param. _f)
   119     Wr(_11); Wr(_12); Wr(_13); Wr(_14);
   120     Wr(_21); Wr(_22); Wr(_23); Wr(_24);
   121     Wr(_31); Wr(_32); Wr(_33); Wr(_34);
   122     Wr(_41); Wr(_42); Wr(_43); Wr(_44);
   123     Wr(_51); Wr(_52); Wr(_53); Wr(_54);
   124 #undef Wr
   125   }
   127   static bool Read(const Message* msg, void** iter, paramType* result)
   128   {
   129 #define Rd(_f)  ReadParam(msg, iter, &result-> _f)
   130     return (Rd(_11) && Rd(_12) && Rd(_13) && Rd(_14) &&
   131             Rd(_21) && Rd(_22) && Rd(_23) && Rd(_24) &&
   132             Rd(_31) && Rd(_32) && Rd(_33) && Rd(_34) &&
   133             Rd(_41) && Rd(_42) && Rd(_43) && Rd(_44) &&
   134             Rd(_51) && Rd(_52) && Rd(_53) && Rd(_54));
   135 #undef Rd
   136   }
   137 };
   139 template<>
   140 struct ParamTraits<gfxPoint>
   141 {
   142   typedef gfxPoint paramType;
   144   static void Write(Message* aMsg, const paramType& aParam)
   145   {
   146     WriteParam(aMsg, aParam.x);
   147     WriteParam(aMsg, aParam.y);
   148   }
   150   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   151   {
   152     return (ReadParam(aMsg, aIter, &aResult->x) &&
   153             ReadParam(aMsg, aIter, &aResult->y));
   154  }
   155 };
   157 template<>
   158 struct ParamTraits<gfxPoint3D>
   159 {
   160   typedef gfxPoint3D paramType;
   162   static void Write(Message* aMsg, const paramType& aParam)
   163   {
   164     WriteParam(aMsg, aParam.x);
   165     WriteParam(aMsg, aParam.y);
   166     WriteParam(aMsg, aParam.z);
   167   }
   169   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   170   {
   171     return (ReadParam(aMsg, aIter, &aResult->x) &&
   172             ReadParam(aMsg, aIter, &aResult->y) &&
   173             ReadParam(aMsg, aIter, &aResult->z));
   174   }
   175 };
   177 template<>
   178 struct ParamTraits<gfxSize>
   179 {
   180   typedef gfxSize paramType;
   182   static void Write(Message* aMsg, const paramType& aParam)
   183   {
   184     WriteParam(aMsg, aParam.width);
   185     WriteParam(aMsg, aParam.height);
   186   }
   188   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   189   {
   190     if (ReadParam(aMsg, aIter, &aResult->width) &&
   191         ReadParam(aMsg, aIter, &aResult->height))
   192       return true;
   194     return false;
   195   }
   196 };
   198 template<>
   199 struct ParamTraits<gfxRect>
   200 {
   201   typedef gfxRect paramType;
   203   static void Write(Message* aMsg, const paramType& aParam)
   204   {
   205     WriteParam(aMsg, aParam.x);
   206     WriteParam(aMsg, aParam.y);
   207     WriteParam(aMsg, aParam.width);
   208     WriteParam(aMsg, aParam.height);
   209   }
   211   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   212   {
   213     return ReadParam(aMsg, aIter, &aResult->x) &&
   214            ReadParam(aMsg, aIter, &aResult->y) &&
   215            ReadParam(aMsg, aIter, &aResult->width) &&
   216            ReadParam(aMsg, aIter, &aResult->height);
   217   }
   218 };
   220 template<>
   221 struct ParamTraits<gfx3DMatrix>
   222 {
   223   typedef gfx3DMatrix paramType;
   225   static void Write(Message* msg, const paramType& param)
   226   {
   227 #define Wr(_f)  WriteParam(msg, param. _f)
   228     Wr(_11); Wr(_12); Wr(_13); Wr(_14);
   229     Wr(_21); Wr(_22); Wr(_23); Wr(_24);
   230     Wr(_31); Wr(_32); Wr(_33); Wr(_34);
   231     Wr(_41); Wr(_42); Wr(_43); Wr(_44);
   232 #undef Wr
   233   }
   235   static bool Read(const Message* msg, void** iter, paramType* result)
   236   {
   237 #define Rd(_f)  ReadParam(msg, iter, &result-> _f)
   238     return (Rd(_11) && Rd(_12) && Rd(_13) && Rd(_14) &&
   239             Rd(_21) && Rd(_22) && Rd(_23) && Rd(_24) &&
   240             Rd(_31) && Rd(_32) && Rd(_33) && Rd(_34) &&
   241             Rd(_41) && Rd(_42) && Rd(_43) && Rd(_44));
   242 #undef Rd
   243   }
   244 };
   246 template <>
   247 struct ParamTraits<gfxContentType>
   248   : public ContiguousTypedEnumSerializer<
   249              gfxContentType,
   250              gfxContentType::COLOR,
   251              gfxContentType::SENTINEL>
   252 {};
   254 template <>
   255 struct ParamTraits<gfxSurfaceType>
   256   : public ContiguousTypedEnumSerializer<
   257              gfxSurfaceType,
   258              gfxSurfaceType::Image,
   259              gfxSurfaceType::Max>
   260 {};
   262 template <>
   263 struct ParamTraits<mozilla::GraphicsFilterType>
   264   : public ContiguousEnumSerializer<
   265              mozilla::GraphicsFilterType,
   266              GraphicsFilter::FILTER_FAST,
   267              GraphicsFilter::FILTER_SENTINEL>
   268 {};
   270 template <>
   271 struct ParamTraits<mozilla::layers::LayersBackend>
   272   : public ContiguousTypedEnumSerializer<
   273              mozilla::layers::LayersBackend,
   274              mozilla::layers::LayersBackend::LAYERS_NONE,
   275              mozilla::layers::LayersBackend::LAYERS_LAST>
   276 {};
   278 template <>
   279 struct ParamTraits<mozilla::layers::ScaleMode>
   280   : public ContiguousTypedEnumSerializer<
   281              mozilla::layers::ScaleMode,
   282              mozilla::layers::ScaleMode::SCALE_NONE,
   283              mozilla::layers::ScaleMode::SENTINEL>
   284 {};
   286 template <>
   287 struct ParamTraits<gfxImageFormat>
   288   : public ContiguousTypedEnumSerializer<
   289              gfxImageFormat,
   290              gfxImageFormat::ARGB32,
   291              gfxImageFormat::Unknown>
   292 {};
   294 template <>
   295 struct ParamTraits<mozilla::gfx::AttributeName>
   296   : public ContiguousEnumSerializer<
   297              mozilla::gfx::AttributeName,
   298              mozilla::gfx::eBlendBlendmode,
   299              mozilla::gfx::eLastAttributeName>
   300 {};
   302 template <>
   303 struct ParamTraits<mozilla::gfx::AttributeType>
   304   : public ContiguousTypedEnumSerializer<
   305              mozilla::gfx::AttributeType,
   306              mozilla::gfx::AttributeType::eBool,
   307              mozilla::gfx::AttributeType::Max>
   308 {};
   310 template <>
   311 struct ParamTraits<mozilla::gfx::PrimitiveType>
   312   : public ContiguousTypedEnumSerializer<
   313              mozilla::gfx::PrimitiveType,
   314              mozilla::gfx::PrimitiveType::Empty,
   315              mozilla::gfx::PrimitiveType::Max>
   316 {};
   318 template <>
   319 struct ParamTraits<mozilla::gfx::ColorSpace>
   320   : public ContiguousTypedEnumSerializer<
   321              mozilla::gfx::ColorSpace,
   322              mozilla::gfx::ColorSpace::SRGB,
   323              mozilla::gfx::ColorSpace::Max>
   324 {};
   326 /*
   327 template <>
   328 struct ParamTraits<mozilla::PixelFormat>
   329   : public EnumSerializer<mozilla::PixelFormat,
   330                           gfxImageFormat::ARGB32,
   331                           gfxImageFormat::Unknown>
   332 {};
   333 */
   335 template<>
   336 struct ParamTraits<gfxRGBA>
   337 {
   338   typedef gfxRGBA paramType;
   340   static void Write(Message* msg, const paramType& param)
   341   {
   342     WriteParam(msg, param.r);
   343     WriteParam(msg, param.g);
   344     WriteParam(msg, param.b);
   345     WriteParam(msg, param.a);
   346   }
   348   static bool Read(const Message* msg, void** iter, paramType* result)
   349   {
   350     return (ReadParam(msg, iter, &result->r) &&
   351             ReadParam(msg, iter, &result->g) &&
   352             ReadParam(msg, iter, &result->b) &&
   353             ReadParam(msg, iter, &result->a));
   354   }
   355 };
   357 template<>
   358 struct ParamTraits<mozilla::gfx::Color>
   359 {
   360   typedef mozilla::gfx::Color paramType;
   362   static void Write(Message* msg, const paramType& param)
   363   {
   364     WriteParam(msg, param.r);
   365     WriteParam(msg, param.g);
   366     WriteParam(msg, param.b);
   367     WriteParam(msg, param.a);
   368   }
   370   static bool Read(const Message* msg, void** iter, paramType* result)
   371   {
   372     return (ReadParam(msg, iter, &result->r) &&
   373             ReadParam(msg, iter, &result->g) &&
   374             ReadParam(msg, iter, &result->b) &&
   375             ReadParam(msg, iter, &result->a));
   376   }
   377 };
   379 template<>
   380 struct ParamTraits<nsPoint>
   381 {
   382   typedef nsPoint paramType;
   384   static void Write(Message* msg, const paramType& param)
   385   {
   386     WriteParam(msg, param.x);
   387     WriteParam(msg, param.y);
   388   }
   390   static bool Read(const Message* msg, void** iter, paramType* result)
   391   {
   392     return (ReadParam(msg, iter, &result->x) &&
   393             ReadParam(msg, iter, &result->y));
   394   }
   395 };
   397 template<>
   398 struct ParamTraits<nsIntPoint>
   399 {
   400   typedef nsIntPoint paramType;
   402   static void Write(Message* msg, const paramType& param)
   403   {
   404     WriteParam(msg, param.x);
   405     WriteParam(msg, param.y);
   406   }
   408   static bool Read(const Message* msg, void** iter, paramType* result)
   409   {
   410     return (ReadParam(msg, iter, &result->x) &&
   411             ReadParam(msg, iter, &result->y));
   412   }
   413 };
   415 template<>
   416 struct ParamTraits<mozilla::gfx::IntSize>
   417 {
   418   typedef mozilla::gfx::IntSize paramType;
   420   static void Write(Message* msg, const paramType& param)
   421   {
   422     WriteParam(msg, param.width);
   423     WriteParam(msg, param.height);
   424   }
   426   static bool Read(const Message* msg, void** iter, paramType* result)
   427   {
   428     return (ReadParam(msg, iter, &result->width) &&
   429             ReadParam(msg, iter, &result->height));
   430   }
   431 };
   433 template<>
   434 struct ParamTraits<nsIntRect>
   435 {
   436   typedef nsIntRect paramType;
   438   static void Write(Message* msg, const paramType& param)
   439   {
   440     WriteParam(msg, param.x);
   441     WriteParam(msg, param.y);
   442     WriteParam(msg, param.width);
   443     WriteParam(msg, param.height);
   444   }
   446   static bool Read(const Message* msg, void** iter, paramType* result)
   447   {
   448     return (ReadParam(msg, iter, &result->x) &&
   449             ReadParam(msg, iter, &result->y) &&
   450             ReadParam(msg, iter, &result->width) &&
   451             ReadParam(msg, iter, &result->height));
   452   }
   453 };
   455 template<typename Region, typename Rect, typename Iter>
   456 struct RegionParamTraits
   457 {
   458   typedef Region paramType;
   460   static void Write(Message* msg, const paramType& param)
   461   {
   462     Iter it(param);
   463     while (const Rect* r = it.Next())
   464       WriteParam(msg, *r);
   465     // empty rects are sentinel values because nsRegions will never
   466     // contain them
   467     WriteParam(msg, Rect());
   468   }
   470   static bool Read(const Message* msg, void** iter, paramType* result)
   471   {
   472     Rect rect;
   473     while (ReadParam(msg, iter, &rect)) {
   474       if (rect.IsEmpty())
   475         return true;
   476       result->Or(*result, rect);
   477     }
   478     return false;
   479   }
   480 };
   482 template<>
   483 struct ParamTraits<nsIntRegion>
   484   : RegionParamTraits<nsIntRegion, nsIntRect, nsIntRegionRectIterator>
   485 {};
   487 template<>
   488 struct ParamTraits<nsIntSize>
   489 {
   490   typedef nsIntSize paramType;
   492   static void Write(Message* msg, const paramType& param)
   493   {
   494     WriteParam(msg, param.width);
   495     WriteParam(msg, param.height);
   496   }
   498   static bool Read(const Message* msg, void** iter, paramType* result)
   499   {
   500     return (ReadParam(msg, iter, &result->width) &&
   501             ReadParam(msg, iter, &result->height));
   502   }
   503 };
   505 template<class T, class U>
   506 struct ParamTraits< mozilla::gfx::ScaleFactor<T, U> >
   507 {
   508   typedef mozilla::gfx::ScaleFactor<T, U> paramType;
   510   static void Write(Message* msg, const paramType& param)
   511   {
   512     WriteParam(msg, param.scale);
   513   }
   515   static bool Read(const Message* msg, void** iter, paramType* result)
   516   {
   517     return (ReadParam(msg, iter, &result->scale));
   518   }
   519 };
   521 template<class T>
   522 struct ParamTraits< mozilla::gfx::PointTyped<T> >
   523 {
   524   typedef mozilla::gfx::PointTyped<T> paramType;
   526   static void Write(Message* msg, const paramType& param)
   527   {
   528     WriteParam(msg, param.x);
   529     WriteParam(msg, param.y);
   530   }
   532   static bool Read(const Message* msg, void** iter, paramType* result)
   533   {
   534     return (ReadParam(msg, iter, &result->x) &&
   535             ReadParam(msg, iter, &result->y));
   536   }
   537 };
   539 template<class T>
   540 struct ParamTraits< mozilla::gfx::Point3DTyped<T> >
   541 {
   542   typedef mozilla::gfx::Point3DTyped<T> paramType;
   544   static void Write(Message* msg, const paramType& param)
   545   {
   546     WriteParam(msg, param.x);
   547     WriteParam(msg, param.y);
   548     WriteParam(msg, param.z);
   549   }
   551   static bool Read(const Message* msg, void** iter, paramType* result)
   552   {
   553     return (ReadParam(msg, iter, &result->x) &&
   554             ReadParam(msg, iter, &result->y) &&
   555             ReadParam(msg, iter, &result->z));
   556   }
   557 };
   559 template<class T>
   560 struct ParamTraits< mozilla::gfx::IntPointTyped<T> >
   561 {
   562   typedef mozilla::gfx::IntPointTyped<T> paramType;
   564   static void Write(Message* msg, const paramType& param)
   565   {
   566     WriteParam(msg, param.x);
   567     WriteParam(msg, param.y);
   568   }
   570   static bool Read(const Message* msg, void** iter, paramType* result)
   571   {
   572     return (ReadParam(msg, iter, &result->x) &&
   573             ReadParam(msg, iter, &result->y));
   574   }
   575 };
   577 template<class T>
   578 struct ParamTraits< mozilla::gfx::SizeTyped<T> >
   579 {
   580   typedef mozilla::gfx::SizeTyped<T> paramType;
   582   static void Write(Message* msg, const paramType& param)
   583   {
   584     WriteParam(msg, param.width);
   585     WriteParam(msg, param.height);
   586   }
   588   static bool Read(const Message* msg, void** iter, paramType* result)
   589   {
   590     return (ReadParam(msg, iter, &result->width) &&
   591             ReadParam(msg, iter, &result->height));
   592   }
   593 };
   595 template<class T>
   596 struct ParamTraits< mozilla::gfx::RectTyped<T> >
   597 {
   598   typedef mozilla::gfx::RectTyped<T> paramType;
   600   static void Write(Message* msg, const paramType& param)
   601   {
   602     WriteParam(msg, param.x);
   603     WriteParam(msg, param.y);
   604     WriteParam(msg, param.width);
   605     WriteParam(msg, param.height);
   606   }
   608   static bool Read(const Message* msg, void** iter, paramType* result)
   609   {
   610     return (ReadParam(msg, iter, &result->x) &&
   611             ReadParam(msg, iter, &result->y) &&
   612             ReadParam(msg, iter, &result->width) &&
   613             ReadParam(msg, iter, &result->height));
   614   }
   615 };
   617 template<class T>
   618 struct ParamTraits< mozilla::gfx::IntRectTyped<T> >
   619 {
   620   typedef mozilla::gfx::IntRectTyped<T> paramType;
   622   static void Write(Message* msg, const paramType& param)
   623   {
   624     WriteParam(msg, param.x);
   625     WriteParam(msg, param.y);
   626     WriteParam(msg, param.width);
   627     WriteParam(msg, param.height);
   628   }
   630   static bool Read(const Message* msg, void** iter, paramType* result)
   631   {
   632     return (ReadParam(msg, iter, &result->x) &&
   633             ReadParam(msg, iter, &result->y) &&
   634             ReadParam(msg, iter, &result->width) &&
   635             ReadParam(msg, iter, &result->height));
   636   }
   637 };
   639 template<>
   640 struct ParamTraits<mozilla::gfx::Margin>
   641 {
   642   typedef mozilla::gfx::Margin paramType;
   644   static void Write(Message* msg, const paramType& param)
   645   {
   646     WriteParam(msg, param.top);
   647     WriteParam(msg, param.right);
   648     WriteParam(msg, param.bottom);
   649     WriteParam(msg, param.left);
   650   }
   652   static bool Read(const Message* msg, void** iter, paramType* result)
   653   {
   654     return (ReadParam(msg, iter, &result->top) &&
   655             ReadParam(msg, iter, &result->right) &&
   656             ReadParam(msg, iter, &result->bottom) &&
   657             ReadParam(msg, iter, &result->left));
   658   }
   659 };
   661 template<class T>
   662 struct ParamTraits< mozilla::gfx::MarginTyped<T> >
   663 {
   664   typedef mozilla::gfx::MarginTyped<T> paramType;
   666   static void Write(Message* msg, const paramType& param)
   667   {
   668     WriteParam(msg, param.top);
   669     WriteParam(msg, param.right);
   670     WriteParam(msg, param.bottom);
   671     WriteParam(msg, param.left);
   672   }
   674   static bool Read(const Message* msg, void** iter, paramType* result)
   675   {
   676     return (ReadParam(msg, iter, &result->top) &&
   677             ReadParam(msg, iter, &result->right) &&
   678             ReadParam(msg, iter, &result->bottom) &&
   679             ReadParam(msg, iter, &result->left));
   680   }
   681 };
   683 template<>
   684 struct ParamTraits<nsRect>
   685 {
   686   typedef nsRect paramType;
   688   static void Write(Message* msg, const paramType& param)
   689   {
   690     WriteParam(msg, param.x);
   691     WriteParam(msg, param.y);
   692     WriteParam(msg, param.width);
   693     WriteParam(msg, param.height);
   694   }
   696   static bool Read(const Message* msg, void** iter, paramType* result)
   697   {
   698     return (ReadParam(msg, iter, &result->x) &&
   699             ReadParam(msg, iter, &result->y) &&
   700             ReadParam(msg, iter, &result->width) &&
   701             ReadParam(msg, iter, &result->height));
   702   }
   703 };
   705 template<>
   706 struct ParamTraits<nsRegion>
   707   : RegionParamTraits<nsRegion, nsRect, nsRegionRectIterator>
   708 {};
   710 template <>
   711 struct ParamTraits<mozilla::layers::FrameMetrics>
   712 {
   713   typedef mozilla::layers::FrameMetrics paramType;
   715   static void Write(Message* aMsg, const paramType& aParam)
   716   {
   717     WriteParam(aMsg, aParam.mScrollableRect);
   718     WriteParam(aMsg, aParam.mViewport);
   719     WriteParam(aMsg, aParam.mScrollOffset);
   720     WriteParam(aMsg, aParam.mDisplayPort);
   721     WriteParam(aMsg, aParam.mDisplayPortMargins);
   722     WriteParam(aMsg, aParam.mUseDisplayPortMargins);
   723     WriteParam(aMsg, aParam.mCriticalDisplayPort);
   724     WriteParam(aMsg, aParam.mCompositionBounds);
   725     WriteParam(aMsg, aParam.mRootCompositionSize);
   726     WriteParam(aMsg, aParam.mScrollId);
   727     WriteParam(aMsg, aParam.mResolution);
   728     WriteParam(aMsg, aParam.mCumulativeResolution);
   729     WriteParam(aMsg, aParam.mZoom);
   730     WriteParam(aMsg, aParam.mDevPixelsPerCSSPixel);
   731     WriteParam(aMsg, aParam.mMayHaveTouchListeners);
   732     WriteParam(aMsg, aParam.mPresShellId);
   733     WriteParam(aMsg, aParam.mIsRoot);
   734     WriteParam(aMsg, aParam.mHasScrollgrab);
   735     WriteParam(aMsg, aParam.mUpdateScrollOffset);
   736     WriteParam(aMsg, aParam.mScrollGeneration);
   737     WriteParam(aMsg, aParam.mContentDescription);
   738     WriteParam(aMsg, aParam.mTransformScale);
   739   }
   741   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   742   {
   743     return (ReadParam(aMsg, aIter, &aResult->mScrollableRect) &&
   744             ReadParam(aMsg, aIter, &aResult->mViewport) &&
   745             ReadParam(aMsg, aIter, &aResult->mScrollOffset) &&
   746             ReadParam(aMsg, aIter, &aResult->mDisplayPort) &&
   747             ReadParam(aMsg, aIter, &aResult->mDisplayPortMargins) &&
   748             ReadParam(aMsg, aIter, &aResult->mUseDisplayPortMargins) &&
   749             ReadParam(aMsg, aIter, &aResult->mCriticalDisplayPort) &&
   750             ReadParam(aMsg, aIter, &aResult->mCompositionBounds) &&
   751             ReadParam(aMsg, aIter, &aResult->mRootCompositionSize) &&
   752             ReadParam(aMsg, aIter, &aResult->mScrollId) &&
   753             ReadParam(aMsg, aIter, &aResult->mResolution) &&
   754             ReadParam(aMsg, aIter, &aResult->mCumulativeResolution) &&
   755             ReadParam(aMsg, aIter, &aResult->mZoom) &&
   756             ReadParam(aMsg, aIter, &aResult->mDevPixelsPerCSSPixel) &&
   757             ReadParam(aMsg, aIter, &aResult->mMayHaveTouchListeners) &&
   758             ReadParam(aMsg, aIter, &aResult->mPresShellId) &&
   759             ReadParam(aMsg, aIter, &aResult->mIsRoot) &&
   760             ReadParam(aMsg, aIter, &aResult->mHasScrollgrab) &&
   761             ReadParam(aMsg, aIter, &aResult->mUpdateScrollOffset) &&
   762             ReadParam(aMsg, aIter, &aResult->mScrollGeneration) &&
   763             ReadParam(aMsg, aIter, &aResult->mContentDescription) &&
   764             ReadParam(aMsg, aIter, &aResult->mTransformScale));
   765   }
   766 };
   768 template<>
   769 struct ParamTraits<mozilla::layers::TextureFactoryIdentifier>
   770 {
   771   typedef mozilla::layers::TextureFactoryIdentifier paramType;
   773   static void Write(Message* aMsg, const paramType& aParam)
   774   {
   775     WriteParam(aMsg, aParam.mParentBackend);
   776     WriteParam(aMsg, aParam.mMaxTextureSize);
   777     WriteParam(aMsg, aParam.mSupportsTextureBlitting);
   778     WriteParam(aMsg, aParam.mSupportsPartialUploads);
   779   }
   781   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   782   {
   783     return ReadParam(aMsg, aIter, &aResult->mParentBackend) &&
   784            ReadParam(aMsg, aIter, &aResult->mMaxTextureSize) &&
   785            ReadParam(aMsg, aIter, &aResult->mSupportsTextureBlitting) &&
   786            ReadParam(aMsg, aIter, &aResult->mSupportsPartialUploads);
   787   }
   788 };
   790 template<>
   791 struct ParamTraits<mozilla::layers::TextureInfo>
   792 {
   793   typedef mozilla::layers::TextureInfo paramType;
   795   static void Write(Message* aMsg, const paramType& aParam)
   796   {
   797     WriteParam(aMsg, aParam.mCompositableType);
   798     WriteParam(aMsg, aParam.mDeprecatedTextureHostFlags);
   799     WriteParam(aMsg, aParam.mTextureFlags);
   800   }
   802   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   803   {
   804     return ReadParam(aMsg, aIter, &aResult->mCompositableType) &&
   805            ReadParam(aMsg, aIter, &aResult->mDeprecatedTextureHostFlags) &&
   806            ReadParam(aMsg, aIter, &aResult->mTextureFlags);
   807   }
   808 };
   810 template <>
   811 struct ParamTraits<mozilla::layers::CompositableType>
   812   : public ContiguousEnumSerializer<
   813              mozilla::layers::CompositableType,
   814              mozilla::layers::BUFFER_UNKNOWN,
   815              mozilla::layers::BUFFER_COUNT>
   816 {};
   818 template <>
   819 struct ParamTraits<mozilla::gfx::SurfaceFormat>
   820   : public ContiguousTypedEnumSerializer<
   821              mozilla::gfx::SurfaceFormat,
   822              mozilla::gfx::SurfaceFormat::B8G8R8A8,
   823              mozilla::gfx::SurfaceFormat::UNKNOWN>
   824 {};
   826 template <>
   827 struct ParamTraits<mozilla::layers::ScrollableLayerGuid>
   828 {
   829   typedef mozilla::layers::ScrollableLayerGuid paramType;
   831   static void Write(Message* aMsg, const paramType& aParam)
   832   {
   833     WriteParam(aMsg, aParam.mLayersId);
   834     WriteParam(aMsg, aParam.mPresShellId);
   835     WriteParam(aMsg, aParam.mScrollId);
   836   }
   838   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   839   {
   840     return (ReadParam(aMsg, aIter, &aResult->mLayersId) &&
   841             ReadParam(aMsg, aIter, &aResult->mPresShellId) &&
   842             ReadParam(aMsg, aIter, &aResult->mScrollId));
   843   }
   844 };
   846 template <>
   847 struct ParamTraits<mozilla::layers::ZoomConstraints>
   848 {
   849   typedef mozilla::layers::ZoomConstraints paramType;
   851   static void Write(Message* aMsg, const paramType& aParam)
   852   {
   853     WriteParam(aMsg, aParam.mAllowZoom);
   854     WriteParam(aMsg, aParam.mAllowDoubleTapZoom);
   855     WriteParam(aMsg, aParam.mMinZoom);
   856     WriteParam(aMsg, aParam.mMaxZoom);
   857   }
   859   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   860   {
   861     return (ReadParam(aMsg, aIter, &aResult->mAllowZoom) &&
   862             ReadParam(aMsg, aIter, &aResult->mAllowDoubleTapZoom) &&
   863             ReadParam(aMsg, aIter, &aResult->mMinZoom) &&
   864             ReadParam(aMsg, aIter, &aResult->mMaxZoom));
   865   }
   866 };
   868 template <>
   869 struct ParamTraits<mozilla::layers::EventRegions>
   870 {
   871   typedef mozilla::layers::EventRegions paramType;
   873   static void Write(Message* aMsg, const paramType& aParam)
   874   {
   875     WriteParam(aMsg, aParam.mHitRegion);
   876     WriteParam(aMsg, aParam.mDispatchToContentHitRegion);
   877   }
   879   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   880   {
   881     return (ReadParam(aMsg, aIter, &aResult->mHitRegion) &&
   882             ReadParam(aMsg, aIter, &aResult->mDispatchToContentHitRegion));
   883   }
   884 };
   886 struct MessageAndAttributeMap
   887 {
   888   Message* msg;
   889   const mozilla::gfx::AttributeMap& map;
   890 };
   892 static bool
   893 WriteAttribute(mozilla::gfx::AttributeName aName,
   894                mozilla::gfx::AttributeType aType,
   895                void* aUserData)
   896 {
   897   MessageAndAttributeMap* msgAndMap =
   898     static_cast<MessageAndAttributeMap*>(aUserData);
   900   WriteParam(msgAndMap->msg, aType);
   901   WriteParam(msgAndMap->msg, aName);
   903   switch (aType) {
   905 #define HANDLE_TYPE(typeName)                                          \
   906     case mozilla::gfx::AttributeType::e##typeName:                     \
   907       WriteParam(msgAndMap->msg, msgAndMap->map.Get##typeName(aName)); \
   908       break;
   910     HANDLE_TYPE(Bool)
   911     HANDLE_TYPE(Uint)
   912     HANDLE_TYPE(Float)
   913     HANDLE_TYPE(Size)
   914     HANDLE_TYPE(IntSize)
   915     HANDLE_TYPE(IntPoint)
   916     HANDLE_TYPE(Matrix)
   917     HANDLE_TYPE(Matrix5x4)
   918     HANDLE_TYPE(Point3D)
   919     HANDLE_TYPE(Color)
   920     HANDLE_TYPE(AttributeMap)
   921     HANDLE_TYPE(Floats)
   923 #undef HANDLE_TYPE
   925     default:
   926       MOZ_CRASH("unhandled attribute type");
   927   }
   928   return true;
   929 }
   931 template <>
   932 struct ParamTraits<mozilla::gfx::AttributeMap>
   933 {
   934   typedef mozilla::gfx::AttributeMap paramType;
   936   static void Write(Message* aMsg, const paramType& aParam)
   937   {
   938     WriteParam(aMsg, aParam.Count());
   939     MessageAndAttributeMap msgAndMap = { aMsg, aParam };
   940     aParam.EnumerateRead(WriteAttribute, &msgAndMap);
   941   }
   943   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   944   {
   945     uint32_t count;
   946     if (!ReadParam(aMsg, aIter, &count)) {
   947       return false;
   948     }
   949     for (uint32_t i = 0; i < count; i++) {
   950       mozilla::gfx::AttributeType type;
   951       if (!ReadParam(aMsg, aIter, &type)) {
   952         return false;
   953       }
   954       mozilla::gfx::AttributeName name;
   955       if (!ReadParam(aMsg, aIter, &name)) {
   956         return false;
   957       }
   958       switch (type) {
   960 #define HANDLE_TYPE(type, typeName)                                    \
   961         case mozilla::gfx::AttributeType::e##typeName:                 \
   962         {                                                              \
   963           type value;                                                  \
   964           if (!ReadParam(aMsg, aIter, &value)) {                       \
   965             return false;                                              \
   966           }                                                            \
   967           aResult->Set(name, value);                                   \
   968         }
   970         HANDLE_TYPE(bool, Bool)
   971         HANDLE_TYPE(uint32_t, Uint)
   972         HANDLE_TYPE(float, Float)
   973         HANDLE_TYPE(mozilla::gfx::Size, Size)
   974         HANDLE_TYPE(mozilla::gfx::IntSize, IntSize)
   975         HANDLE_TYPE(mozilla::gfx::IntPoint, IntPoint)
   976         HANDLE_TYPE(mozilla::gfx::Matrix, Matrix)
   977         HANDLE_TYPE(mozilla::gfx::Matrix5x4, Matrix5x4)
   978         HANDLE_TYPE(mozilla::gfx::Point3D, Point3D)
   979         HANDLE_TYPE(mozilla::gfx::Color, Color)
   980         HANDLE_TYPE(mozilla::gfx::AttributeMap, AttributeMap)
   982 #undef HANDLE_TYPE
   984         case mozilla::gfx::AttributeType::eFloats:
   985         {
   986           nsTArray<float> value;
   987           if (!ReadParam(aMsg, aIter, &value)) {
   988             return false;
   989           }
   990           aResult->Set(name, &value[0], value.Length());
   991           break;
   992         }
   993         default:
   994           MOZ_CRASH("unhandled attribute type");
   995       }
   996     }
   997     return true;
   998   }
   999 };
  1001 template <>
  1002 struct ParamTraits<mozilla::gfx::FilterPrimitiveDescription>
  1004   typedef mozilla::gfx::FilterPrimitiveDescription paramType;
  1006   static void Write(Message* aMsg, const paramType& aParam)
  1008     WriteParam(aMsg, aParam.Type());
  1009     WriteParam(aMsg, aParam.PrimitiveSubregion());
  1010     WriteParam(aMsg, aParam.IsTainted());
  1011     WriteParam(aMsg, aParam.OutputColorSpace());
  1012     WriteParam(aMsg, aParam.NumberOfInputs());
  1013     for (size_t i = 0; i < aParam.NumberOfInputs(); i++) {
  1014       WriteParam(aMsg, aParam.InputPrimitiveIndex(i));
  1015       WriteParam(aMsg, aParam.InputColorSpace(i));
  1017     WriteParam(aMsg, aParam.Attributes());
  1020   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
  1022     mozilla::gfx::PrimitiveType type;
  1023     mozilla::gfx::IntRect primitiveSubregion;
  1024     bool isTainted = false;
  1025     mozilla::gfx::ColorSpace outputColorSpace;
  1026     size_t numberOfInputs = 0;
  1027     if (!ReadParam(aMsg, aIter, &type) ||
  1028         !ReadParam(aMsg, aIter, &primitiveSubregion) ||
  1029         !ReadParam(aMsg, aIter, &isTainted) ||
  1030         !ReadParam(aMsg, aIter, &outputColorSpace) ||
  1031         !ReadParam(aMsg, aIter, &numberOfInputs)) {
  1032       return false;
  1035     aResult->SetType(type);
  1036     aResult->SetPrimitiveSubregion(primitiveSubregion);
  1037     aResult->SetIsTainted(isTainted);
  1038     aResult->SetOutputColorSpace(outputColorSpace);
  1040     for (size_t i = 0; i < numberOfInputs; i++) {
  1041       int32_t inputPrimitiveIndex = 0;
  1042       mozilla::gfx::ColorSpace inputColorSpace;
  1043       if (!ReadParam(aMsg, aIter, &inputPrimitiveIndex) ||
  1044           !ReadParam(aMsg, aIter, &inputColorSpace)) {
  1045         return false;
  1047       aResult->SetInputPrimitive(i, inputPrimitiveIndex);
  1048       aResult->SetInputColorSpace(i, inputColorSpace);
  1051     return ReadParam(aMsg, aIter, &aResult->Attributes());
  1053 };
  1055 template <>
  1056 struct ParamTraits<mozilla::gfx::FilterDescription>
  1058   typedef mozilla::gfx::FilterDescription paramType;
  1060   static void Write(Message* aMsg, const paramType& aParam)
  1062     WriteParam(aMsg, aParam.mFilterSpaceBounds);
  1063     WriteParam(aMsg, aParam.mPrimitives);
  1066   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
  1068     return (ReadParam(aMsg, aIter, &aResult->mFilterSpaceBounds) &&
  1069             ReadParam(aMsg, aIter, &aResult->mPrimitives));
  1071 };
  1073 typedef mozilla::layers::GeckoContentController::APZStateChange APZStateChange;
  1075 template <>
  1076 struct ParamTraits<APZStateChange>
  1077   : public ContiguousTypedEnumSerializer<
  1078              APZStateChange,
  1079              APZStateChange::TransformBegin,
  1080              APZStateChange::APZStateChangeSentinel>
  1081 {};
  1083 } /* namespace IPC */
  1085 #endif /* __GFXMESSAGEUTILS_H__ */

mercurial