Bug 1349750 - Introduce a PlainOldDataSerializer utility class and use it for SimpleLayerAttributes. r=kats
MozReview-Commit-ID: 2tntLfnAINy
--- a/gfx/ipc/GfxMessageUtils.h
+++ b/gfx/ipc/GfxMessageUtils.h
@@ -1371,23 +1371,14 @@ struct ParamTraits<mozilla::layers::Comp
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) {
return ReadParam(aMsg, aIter, &aResult->mUseAPZ)
&& ReadParam(aMsg, aIter, &aResult->mUseWebRender);
}
};
template <>
struct ParamTraits<mozilla::layers::SimpleLayerAttributes>
-{
- typedef mozilla::layers::SimpleLayerAttributes paramType;
-
- static void Write(Message* aMsg, const paramType& aParam) {
- aMsg->WriteBytes(&aParam, sizeof(aParam));
- }
-
- static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) {
- return aMsg->ReadBytesInto(aIter, aResult, sizeof(paramType));
- }
-};
+ : public PlainOldDataSerializer<mozilla::layers::SimpleLayerAttributes>
+{ };
} /* namespace IPC */
#endif /* __GFXMESSAGEUTILS_H__ */
--- a/ipc/glue/IPCMessageUtils.h
+++ b/ipc/glue/IPCMessageUtils.h
@@ -225,16 +225,40 @@ struct BitFlagsEnumSerializer
template <>
struct ParamTraits<base::ChildPrivileges>
: public ContiguousEnumSerializer<base::ChildPrivileges,
base::PRIVILEGES_DEFAULT,
base::PRIVILEGES_LAST>
{ };
+/**
+ * A helper class for serializing plain-old data (POD) structures.
+ * The memory representation of the structure is written to and read from
+ * the serialized stream directly, without individual processing of the
+ * structure's members.
+ *
+ * Derive ParamTraits<T> from PlainOldDataSerializer<T> if T is POD.
+ */
+template <typename T>
+struct PlainOldDataSerializer
+{
+ // TODO: Once the mozilla::IsPod trait is in good enough shape (bug 900042),
+ // static_assert that mozilla::IsPod<T>::value is true.
+ typedef T paramType;
+
+ static void Write(Message* aMsg, const paramType& aParam) {
+ aMsg->WriteBytes(&aParam, sizeof(aParam));
+ }
+
+ static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) {
+ return aMsg->ReadBytesInto(aIter, aResult, sizeof(paramType));
+ }
+};
+
template<>
struct ParamTraits<int8_t>
{
typedef int8_t paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
aMsg->WriteBytes(&aParam, sizeof(aParam));