Bug 1921522: Mark WPTs gradient-external-reference.svg and pattern-external-reference...
[gecko.git] / gfx / vr / service / OpenVRControllerMapper.h
blob0fe96c8bbeca0962b729e590e53d914b82a70e42
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef GFX_VR_SERVICE_OPENVRCONTROLLERMAPPER_H
8 #define GFX_VR_SERVICE_OPENVRCONTROLLERMAPPER_H
10 #include "openvr.h"
11 #include "nsString.h"
13 #include "moz_external_vr.h"
15 namespace mozilla {
16 namespace gfx {
18 struct ControllerAction {
19 nsCString name;
20 nsCString type;
21 vr::VRActionHandle_t handle = vr::k_ulInvalidActionHandle;
23 ControllerAction() = default;
25 ControllerAction(const char* aName, const char* aType)
26 : name(aName), type(aType) {}
29 struct ControllerInfo {
30 vr::VRInputValueHandle_t mSource = vr::k_ulInvalidInputValueHandle;
32 ControllerAction mActionPose;
33 ControllerAction mActionHaptic;
35 ControllerAction mActionTrackpad_Analog;
36 ControllerAction mActionTrackpad_Pressed;
37 ControllerAction mActionTrackpad_Touched;
39 ControllerAction mActionTrigger_Value;
41 ControllerAction mActionGrip_Pressed;
42 ControllerAction mActionGrip_Touched;
43 ControllerAction mActionMenu_Pressed;
44 ControllerAction mActionMenu_Touched;
45 // It seems like there's no way to get response from a sys. btn.
46 ControllerAction mActionSystem_Pressed;
47 ControllerAction mActionSystem_Touched;
49 // --- Knuckles & Cosmos
50 ControllerAction mActionA_Pressed;
51 ControllerAction mActionA_Touched;
52 ControllerAction mActionB_Pressed;
53 ControllerAction mActionB_Touched;
55 // --- Knuckles, Cosmos, and WMR
56 ControllerAction mActionThumbstick_Analog;
57 ControllerAction mActionThumbstick_Pressed;
58 ControllerAction mActionThumbstick_Touched;
60 // --- Knuckles
61 ControllerAction mActionFingerIndex_Value;
62 ControllerAction mActionFingerMiddle_Value;
63 ControllerAction mActionFingerRing_Value;
64 ControllerAction mActionFingerPinky_Value;
66 // --- Cosmos
67 ControllerAction mActionBumper_Pressed;
70 class OpenVRControllerMapper {
71 public:
72 OpenVRControllerMapper();
73 virtual ~OpenVRControllerMapper() = default;
75 virtual void UpdateButtons(VRControllerState& aControllerState,
76 ControllerInfo& aControllerInfo) = 0;
77 uint32_t GetButtonCount() { return mNumButtons; }
78 uint32_t GetAxisCount() { return mNumAxes; }
80 protected:
81 void GetButtonValueFromAction(VRControllerState& aControllerState,
82 const ControllerAction& aPressAction,
83 const ControllerAction& aTouchAction);
84 void GetTriggerValueFromAction(VRControllerState& aControllerState,
85 const ControllerAction& aAction);
86 void GetAxisValueFromAction(VRControllerState& aControllerState,
87 const ControllerAction& aAction,
88 bool aInvertAxis = false);
89 uint32_t mNumButtons;
90 uint32_t mNumAxes;
93 } // namespace gfx
94 } // namespace mozilla
96 #endif // GFX_VR_SERVICE_OPENVRCONTROLLERMAPPER_H