From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- dom/gamepad/ipc/GamepadMessageUtils.h | 154 ++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 dom/gamepad/ipc/GamepadMessageUtils.h (limited to 'dom/gamepad/ipc/GamepadMessageUtils.h') diff --git a/dom/gamepad/ipc/GamepadMessageUtils.h b/dom/gamepad/ipc/GamepadMessageUtils.h new file mode 100644 index 0000000000..c29293d3a5 --- /dev/null +++ b/dom/gamepad/ipc/GamepadMessageUtils.h @@ -0,0 +1,154 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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 mozilla_dom_gamepad_GamepadMessageUtils_h +#define mozilla_dom_gamepad_GamepadMessageUtils_h + +#include "ipc/EnumSerializer.h" +#include "mozilla/dom/GamepadBinding.h" +#include "mozilla/dom/GamepadHandle.h" +#include "mozilla/dom/GamepadLightIndicatorBinding.h" +#include "mozilla/dom/GamepadPoseState.h" +#include "mozilla/dom/GamepadTouchState.h" + +namespace IPC { + +template <> +struct ParamTraits + : public ContiguousEnumSerializer< + mozilla::dom::GamepadLightIndicatorType, + mozilla::dom::GamepadLightIndicatorType(0), + mozilla::dom::GamepadLightIndicatorType( + mozilla::dom::GamepadLightIndicatorType::EndGuard_)> {}; + +template <> +struct ParamTraits + : public ContiguousEnumSerializer< + mozilla::dom::GamepadMappingType, mozilla::dom::GamepadMappingType(0), + mozilla::dom::GamepadMappingType( + mozilla::dom::GamepadMappingType::EndGuard_)> {}; + +template <> +struct ParamTraits + : public ContiguousEnumSerializer< + mozilla::dom::GamepadHand, mozilla::dom::GamepadHand(0), + mozilla::dom::GamepadHand(mozilla::dom::GamepadHand::EndGuard_)> {}; + +template <> +struct ParamTraits + : public BitFlagsEnumSerializer< + mozilla::dom::GamepadCapabilityFlags, + mozilla::dom::GamepadCapabilityFlags::Cap_All> {}; + +template <> +struct ParamTraits { + typedef mozilla::dom::GamepadPoseState paramType; + + static void Write(MessageWriter* aWriter, const paramType& aParam) { + WriteParam(aWriter, aParam.flags); + WriteParam(aWriter, aParam.orientation[0]); + WriteParam(aWriter, aParam.orientation[1]); + WriteParam(aWriter, aParam.orientation[2]); + WriteParam(aWriter, aParam.orientation[3]); + WriteParam(aWriter, aParam.position[0]); + WriteParam(aWriter, aParam.position[1]); + WriteParam(aWriter, aParam.position[2]); + WriteParam(aWriter, aParam.angularVelocity[0]); + WriteParam(aWriter, aParam.angularVelocity[1]); + WriteParam(aWriter, aParam.angularVelocity[2]); + WriteParam(aWriter, aParam.angularAcceleration[0]); + WriteParam(aWriter, aParam.angularAcceleration[1]); + WriteParam(aWriter, aParam.angularAcceleration[2]); + WriteParam(aWriter, aParam.linearVelocity[0]); + WriteParam(aWriter, aParam.linearVelocity[1]); + WriteParam(aWriter, aParam.linearVelocity[2]); + WriteParam(aWriter, aParam.linearAcceleration[0]); + WriteParam(aWriter, aParam.linearAcceleration[1]); + WriteParam(aWriter, aParam.linearAcceleration[2]); + WriteParam(aWriter, aParam.isPositionValid); + WriteParam(aWriter, aParam.isOrientationValid); + } + + static bool Read(MessageReader* aReader, paramType* aResult) { + if (!ReadParam(aReader, &(aResult->flags)) || + !ReadParam(aReader, &(aResult->orientation[0])) || + !ReadParam(aReader, &(aResult->orientation[1])) || + !ReadParam(aReader, &(aResult->orientation[2])) || + !ReadParam(aReader, &(aResult->orientation[3])) || + !ReadParam(aReader, &(aResult->position[0])) || + !ReadParam(aReader, &(aResult->position[1])) || + !ReadParam(aReader, &(aResult->position[2])) || + !ReadParam(aReader, &(aResult->angularVelocity[0])) || + !ReadParam(aReader, &(aResult->angularVelocity[1])) || + !ReadParam(aReader, &(aResult->angularVelocity[2])) || + !ReadParam(aReader, &(aResult->angularAcceleration[0])) || + !ReadParam(aReader, &(aResult->angularAcceleration[1])) || + !ReadParam(aReader, &(aResult->angularAcceleration[2])) || + !ReadParam(aReader, &(aResult->linearVelocity[0])) || + !ReadParam(aReader, &(aResult->linearVelocity[1])) || + !ReadParam(aReader, &(aResult->linearVelocity[2])) || + !ReadParam(aReader, &(aResult->linearAcceleration[0])) || + !ReadParam(aReader, &(aResult->linearAcceleration[1])) || + !ReadParam(aReader, &(aResult->linearAcceleration[2])) || + !ReadParam(aReader, &(aResult->isPositionValid)) || + !ReadParam(aReader, &(aResult->isOrientationValid))) { + return false; + } + return true; + } +}; + +template <> +struct ParamTraits { + typedef mozilla::dom::GamepadTouchState paramType; + + static void Write(MessageWriter* aWriter, const paramType& aParam) { + WriteParam(aWriter, aParam.touchId); + WriteParam(aWriter, aParam.surfaceId); + WriteParam(aWriter, aParam.position[0]); + WriteParam(aWriter, aParam.position[1]); + WriteParam(aWriter, aParam.surfaceDimensions[0]); + WriteParam(aWriter, aParam.surfaceDimensions[1]); + WriteParam(aWriter, aParam.isSurfaceDimensionsValid); + } + + static bool Read(MessageReader* aReader, paramType* aResult) { + if (!ReadParam(aReader, &(aResult->touchId)) || + !ReadParam(aReader, &(aResult->surfaceId)) || + !ReadParam(aReader, &(aResult->position[0])) || + !ReadParam(aReader, &(aResult->position[1])) || + !ReadParam(aReader, &(aResult->surfaceDimensions[0])) || + !ReadParam(aReader, &(aResult->surfaceDimensions[1])) || + !ReadParam(aReader, &(aResult->isSurfaceDimensionsValid))) { + return false; + } + return true; + } +}; + +template <> +struct ParamTraits + : public ContiguousEnumSerializerInclusive< + mozilla::dom::GamepadHandleKind, + mozilla::dom::GamepadHandleKind::GamepadPlatformManager, + mozilla::dom::GamepadHandleKind::VR> {}; + +template <> +struct ParamTraits { + typedef mozilla::dom::GamepadHandle paramType; + static void Write(MessageWriter* aWriter, const paramType& aParam) { + WriteParam(aWriter, aParam.mValue); + WriteParam(aWriter, aParam.mKind); + } + static bool Read(MessageReader* aReader, paramType* aParam) { + return ReadParam(aReader, &aParam->mValue) && + ReadParam(aReader, &aParam->mKind); + } +}; + +} // namespace IPC + +#endif // mozilla_dom_gamepad_GamepadMessageUtils_h -- cgit v1.2.3