1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef WEBGLIPDL_H_ 7 #define WEBGLIPDL_H_ 8 9 #include "WebGLTypes.h" 10 11 namespace IPC { 12 13 template <> 14 struct ParamTraits<mozilla::webgl::ContextLossReason> 15 : public ContiguousEnumSerializerInclusive< 16 mozilla::webgl::ContextLossReason, 17 mozilla::webgl::ContextLossReason::None, 18 mozilla::webgl::ContextLossReason::Guilty> {}; 19 20 // - 21 22 template <typename T> 23 bool ValidateParam(const T& val) { 24 return ParamTraits<T>::Validate(val); 25 } 26 27 template <typename T> 28 struct ValidatedPlainOldDataSerializer : public PlainOldDataSerializer<T> { 29 static void Write(Message* const msg, const T& in) { 30 MOZ_ASSERT(ValidateParam(in)); 31 PlainOldDataSerializer<T>::Write(msg, in); 32 } 33 34 static bool Read(const Message* const msg, PickleIterator* const itr, 35 T* const out) { 36 if (!PlainOldDataSerializer<T>::Read(msg, itr, out)) return false; 37 return ValidateParam(*out); 38 } 39 40 // static bool Validate(const T&) = 0; 41 }; 42 43 // - 44 45 template <> 46 struct ParamTraits<mozilla::webgl::InitContextDesc> final 47 : public ValidatedPlainOldDataSerializer<mozilla::webgl::InitContextDesc> { 48 using T = mozilla::webgl::InitContextDesc; 49 50 static bool Validate(const T& val) { 51 return ValidateParam(val.options) && (val.size.x && val.size.y); 52 } 53 }; 54 55 template <> 56 struct ParamTraits<mozilla::WebGLContextOptions> final 57 : public ValidatedPlainOldDataSerializer<mozilla::WebGLContextOptions> { 58 using T = mozilla::WebGLContextOptions; 59 60 static bool Validate(const T& val) { 61 return ValidateParam(val.powerPreference); 62 } 63 }; 64 65 template <> 66 struct ParamTraits<mozilla::dom::WebGLPowerPreference> final 67 : public ValidatedPlainOldDataSerializer< 68 mozilla::dom::WebGLPowerPreference> { 69 using T = mozilla::dom::WebGLPowerPreference; 70 71 static bool Validate(const T& val) { return val <= T::High_performance; } 72 }; 73 74 template <> 75 struct ParamTraits<mozilla::webgl::OpaqueFramebufferOptions> final 76 : public PlainOldDataSerializer<mozilla::webgl::OpaqueFramebufferOptions> { 77 }; 78 79 // - 80 81 template <> 82 struct ParamTraits<mozilla::webgl::InitContextResult> final { 83 using T = mozilla::webgl::InitContextResult; 84 85 static void Write(Message* const msg, const T& in) { 86 WriteParam(msg, in.error); 87 WriteParam(msg, in.options); 88 WriteParam(msg, in.limits); 89 } 90 91 static bool Read(const Message* const msg, PickleIterator* const itr, 92 T* const out) { 93 return ReadParam(msg, itr, &out->error) && 94 ReadParam(msg, itr, &out->options) && 95 ReadParam(msg, itr, &out->limits); 96 } 97 }; 98 99 template <> 100 struct ParamTraits<mozilla::webgl::ExtensionBits> final 101 : public PlainOldDataSerializer<mozilla::webgl::ExtensionBits> {}; 102 103 template <> 104 struct ParamTraits<mozilla::webgl::Limits> final 105 : public PlainOldDataSerializer<mozilla::webgl::Limits> {}; 106 107 } // namespace IPC 108 109 #endif 110