diff options
Diffstat (limited to 'dom/canvas/WebGLIpdl.h')
-rw-r--r-- | dom/canvas/WebGLIpdl.h | 72 |
1 files changed, 43 insertions, 29 deletions
diff --git a/dom/canvas/WebGLIpdl.h b/dom/canvas/WebGLIpdl.h index 5a35c05909..45a5c5ad64 100644 --- a/dom/canvas/WebGLIpdl.h +++ b/dom/canvas/WebGLIpdl.h @@ -245,6 +245,45 @@ struct ParamTraits<mozilla::dom::PredefinedColorSpace> final mozilla::dom::PredefinedColorSpace> {}; // - +// ParamTraits_IsEnumCase + +/* +`IsEnumCase(T) -> bool` guarantees that we never have false negatives or false +positives due to adding or removing enum cases to enums, and forgetting to +update their serializations. Also, it allows enums to be non-continguous, unlike +ContiguousEnumSerializer. +*/ + +template <class T> +struct ParamTraits_IsEnumCase { + static bool Write(MessageWriter* const writer, const T& in) { + MOZ_ASSERT(IsEnumCase(in)); + const auto shadow = static_cast<std::underlying_type_t<T>>(in); + WriteParam(writer, shadow); + return true; + } + + static bool Read(MessageReader* const reader, T* const out) { + auto shadow = std::underlying_type_t<T>{}; + if (!ReadParam(reader, &shadow)) return false; + const auto e = mozilla::AsValidEnum<T>(shadow); + if (!e) return false; + *out = *e; + return true; + } +}; + +// - + +#define USE_IS_ENUM_CASE(T) \ + template <> \ + struct ParamTraits<T> : public ParamTraits_IsEnumCase<T> {}; + +USE_IS_ENUM_CASE(mozilla::webgl::OptionalRenderableFormatBits) + +#undef USE_IS_ENUM_CASE + +// - // ParamTraits_TiedFields template <class T> @@ -272,6 +311,10 @@ struct ParamTraits_TiedFields { } }; +template <class U, size_t N> +struct ParamTraits<mozilla::PaddingField<U, N>> final + : public ParamTraits_TiedFields<mozilla::PaddingField<U, N>> {}; + // - template <> @@ -609,35 +652,6 @@ struct ParamTraits<mozilla::avec3<U>> final { } }; -// - - -template <class TT> -struct ParamTraits_IsEnumCase { - using T = TT; - - static void Write(IPC::MessageWriter* const writer, const T& in) { - MOZ_RELEASE_ASSERT(IsEnumCase(in)); - WriteParam(writer, mozilla::UnderlyingValue(in)); - } - - static bool Read(IPC::MessageReader* const reader, T* const out) { - std::underlying_type_t<T> rawVal; - if (!ReadParam(reader, &rawVal)) return false; - *out = static_cast<T>(rawVal); - return IsEnumCase(*out); - } -}; - -// - - -#define USE_IS_ENUM_CASE(T) \ - template <> \ - struct ParamTraits<T> : public ParamTraits_IsEnumCase<T> {}; - -USE_IS_ENUM_CASE(mozilla::webgl::OptionalRenderableFormatBits) - -#undef USE_IS_ENUM_CASE - } // namespace IPC #endif |