/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* 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 WEBGLIPDL_H_ #define WEBGLIPDL_H_ #include "WebGLTypes.h" namespace IPC { template <> struct ParamTraits : public ContiguousEnumSerializerInclusive< mozilla::webgl::ContextLossReason, mozilla::webgl::ContextLossReason::None, mozilla::webgl::ContextLossReason::Guilty> {}; // - template bool ValidateParam(const T& val) { return ParamTraits::Validate(val); } template struct ValidatedPlainOldDataSerializer : public PlainOldDataSerializer { static void Write(Message* const msg, const T& in) { MOZ_ASSERT(ValidateParam(in)); PlainOldDataSerializer::Write(msg, in); } static bool Read(const Message* const msg, PickleIterator* const itr, T* const out) { if (!PlainOldDataSerializer::Read(msg, itr, out)) return false; return ValidateParam(*out); } // static bool Validate(const T&) = 0; }; // - template <> struct ParamTraits final : public ValidatedPlainOldDataSerializer { using T = mozilla::webgl::InitContextDesc; static bool Validate(const T& val) { return ValidateParam(val.options) && (val.size.x && val.size.y); } }; template <> struct ParamTraits final : public ValidatedPlainOldDataSerializer { using T = mozilla::WebGLContextOptions; static bool Validate(const T& val) { return ValidateParam(val.powerPreference); } }; template <> struct ParamTraits final : public ValidatedPlainOldDataSerializer< mozilla::dom::WebGLPowerPreference> { using T = mozilla::dom::WebGLPowerPreference; static bool Validate(const T& val) { return val <= T::High_performance; } }; template <> struct ParamTraits final : public PlainOldDataSerializer { }; // - template <> struct ParamTraits final { using T = mozilla::webgl::InitContextResult; static void Write(Message* const msg, const T& in) { WriteParam(msg, in.error); WriteParam(msg, in.options); WriteParam(msg, in.limits); } static bool Read(const Message* const msg, PickleIterator* const itr, T* const out) { return ReadParam(msg, itr, &out->error) && ReadParam(msg, itr, &out->options) && ReadParam(msg, itr, &out->limits); } }; template <> struct ParamTraits final : public PlainOldDataSerializer {}; template <> struct ParamTraits final : public PlainOldDataSerializer {}; } // namespace IPC #endif