tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

GamepadRemapping.h (6116B)


      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 file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_dom_GamepadRemapping_h_
      8 #define mozilla_dom_GamepadRemapping_h_
      9 
     10 #include "mozilla/dom/GamepadBinding.h"
     11 #include "mozilla/dom/GamepadLightIndicator.h"
     12 #include "mozilla/dom/GamepadPoseState.h"
     13 #include "mozilla/dom/GamepadTouchState.h"
     14 
     15 namespace mozilla::dom {
     16 
     17 // GamepadId is (vendorId << 16) | productId)
     18 enum class GamepadId : uint32_t {
     19  // Nexus Player Controller
     20  kAsusTekProduct4500 = 0x0b054500,
     21  // 2Axes 8Keys Game Pad
     22  kDragonRiseProduct0011 = 0x00790011,
     23  // ADT-1 Controller
     24  kGoogleProduct2c40 = 0x18d12c40,
     25  // Stadia Controller
     26  kGoogleProduct9400 = 0x18d19400,
     27  // Logitech F310, D-mode
     28  kLogitechProductc216 = 0x046dc216,
     29  // Logitech F510, D-mode
     30  kLogitechProductc218 = 0x046dc218,
     31  // Logitech F710, D-mode
     32  kLogitechProductc219 = 0x046dc219,
     33  // Microsoft Xbox 360
     34  kMicrosoftProductXbox360 = 0x045e028e,
     35  // Microsoft Xbox 360 Wireless
     36  kMicrosoftProductXbox360Wireless = 0x045e028f,
     37  // Microsoft Xbox 360 Wireless
     38  kMicrosoftProductXbox360Wireless2 = 0x045e0719,
     39  // Microsoft Xbox One 2013
     40  kMicrosoftProductXbox2013 = 0x045e02d1,
     41  // Microsoft Xbox One (2015 FW)
     42  kMicrosoftProductXbox2015 = 0x045e02dd,
     43  // Microsoft Xbox One S
     44  kMicrosoftProductXboxOneS = 0x045e02ea,
     45  // Microsoft Xbox One S Wireless
     46  kMicrosoftProductXboxOneSWireless = 0x045e02e0,
     47  // Microsoft Xbox One Elite
     48  kMicrosoftProductXboxOneElite = 0x045e02e3,
     49  // Microsoft Xbox One Elite 2
     50  kMicrosoftProductXboxOneElite2 = 0x045e0b00,
     51  // Microsoft Xbox One Elite 2 Wireless
     52  kMicrosoftProductXboxOneElite2Wireless = 0x045e0b05,
     53  // Xbox One S Wireless (2016 FW)
     54  kMicrosoftProductXboxOneSWireless2016 = 0x045e02fd,
     55  // Microsoft Xbox Adaptive
     56  kMicrosoftProductXboxAdaptive = 0x045e0b0a,
     57  // Microsoft Xbox Adaptive Wireless
     58  kMicrosoftProductXboxAdaptiveWireless = 0x045e0b0c,
     59  // Microsoft Xbox Series X Wireless
     60  kMicrosoftProductXboxSeriesXWireless = 0x045e0b13,
     61  // Switch Joy-Con L
     62  kNintendoProduct2006 = 0x057e2006,
     63  // Switch Joy-Con R
     64  kNintendoProduct2007 = 0x057e2007,
     65  // Switch Pro Controller
     66  kNintendoProduct2009 = 0x057e2009,
     67  // Switch Charging Grip
     68  kNintendoProduct200e = 0x057e200e,
     69  // Nvidia Shield gamepad (2015)
     70  kNvidiaProduct7210 = 0x09557210,
     71  // Nvidia Shield gamepad (2017)
     72  kNvidiaProduct7214 = 0x09557214,
     73  // iBuffalo Classic
     74  kPadixProduct2060 = 0x05832060,
     75  // XSkills Gamecube USB adapter
     76  kPlayComProduct0005 = 0x0b430005,
     77  // boom PSX+N64 USB Converter
     78  kPrototypeVendorProduct0667 = 0x66660667,
     79  // Analog game controller
     80  kPrototypeVendorProduct9401 = 0x66669401,
     81  // Razer Serval Controller
     82  kRazer1532Product0900 = 0x15320900,
     83  // Playstation 3 Controller
     84  kSonyProduct0268 = 0x054c0268,
     85  // Playstation Dualshock 4
     86  kSonyProduct05c4 = 0x054c05c4,
     87  // Dualshock 4 (PS4 Slim)
     88  kSonyProduct09cc = 0x054c09cc,
     89  // Dualshock 4 USB receiver
     90  kSonyProduct0ba0 = 0x054c0ba0,
     91  // Moga Pro Controller (HID mode)
     92  kVendor20d6Product6271 = 0x20d66271,
     93  // OnLive Controller (Bluetooth)
     94  kVendor2378Product1008 = 0x23781008,
     95  // OnLive Controller (Wired)
     96  kVendor2378Product100a = 0x2378100a,
     97  // OUYA Controller
     98  kVendor2836Product0001 = 0x28360001,
     99 };
    100 
    101 // Follow the canonical ordering recommendation for the "Standard Gamepad"
    102 // from https://www.w3.org/TR/gamepad/#remapping.
    103 enum CanonicalButtonIndex {
    104  BUTTON_INDEX_PRIMARY,
    105  BUTTON_INDEX_SECONDARY,
    106  BUTTON_INDEX_TERTIARY,
    107  BUTTON_INDEX_QUATERNARY,
    108  BUTTON_INDEX_LEFT_SHOULDER,
    109  BUTTON_INDEX_RIGHT_SHOULDER,
    110  BUTTON_INDEX_LEFT_TRIGGER,
    111  BUTTON_INDEX_RIGHT_TRIGGER,
    112  BUTTON_INDEX_BACK_SELECT,
    113  BUTTON_INDEX_START,
    114  BUTTON_INDEX_LEFT_THUMBSTICK,
    115  BUTTON_INDEX_RIGHT_THUMBSTICK,
    116  BUTTON_INDEX_DPAD_UP,
    117  BUTTON_INDEX_DPAD_DOWN,
    118  BUTTON_INDEX_DPAD_LEFT,
    119  BUTTON_INDEX_DPAD_RIGHT,
    120  BUTTON_INDEX_META,
    121  BUTTON_INDEX_COUNT
    122 };
    123 
    124 enum CanonicalAxisIndex {
    125  AXIS_INDEX_LEFT_STICK_X,
    126  AXIS_INDEX_LEFT_STICK_Y,
    127  AXIS_INDEX_RIGHT_STICK_X,
    128  AXIS_INDEX_RIGHT_STICK_Y,
    129  AXIS_INDEX_COUNT
    130 };
    131 
    132 static inline bool AxisNegativeAsButton(double input) { return input < -0.5; }
    133 
    134 static inline bool AxisPositiveAsButton(double input) { return input > 0.5; }
    135 
    136 class GamepadRemapper {
    137  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GamepadRemapper)
    138 
    139 public:
    140  virtual uint32_t GetAxisCount() const = 0;
    141  virtual uint32_t GetButtonCount() const = 0;
    142  virtual uint32_t GetLightIndicatorCount() const { return 0; }
    143  virtual void GetLightIndicators(
    144      nsTArray<GamepadLightIndicatorType>& aTypes) const {}
    145  virtual uint32_t GetTouchEventCount() const { return 0; }
    146  virtual void GetLightColorReport(uint8_t aRed, uint8_t aGreen, uint8_t aBlue,
    147                                   std::vector<uint8_t>& aReport) const {}
    148  virtual uint32_t GetMaxInputReportLength() const { return 0; }
    149 
    150  virtual void SetAxisCount(uint32_t aButtonCount) {}
    151  virtual void SetButtonCount(uint32_t aButtonCount) {}
    152  virtual GamepadMappingType GetMappingType() const {
    153    return GamepadMappingType::Standard;
    154  }
    155  virtual void ProcessTouchData(GamepadHandle aHandle, void* aInput) {}
    156  virtual void RemapAxisMoveEvent(GamepadHandle aHandle, uint32_t aAxis,
    157                                  double aValue) const = 0;
    158  virtual void RemapButtonEvent(GamepadHandle aHandle, uint32_t aButton,
    159                                bool aPressed) const = 0;
    160 
    161 protected:
    162  GamepadRemapper() = default;
    163  virtual ~GamepadRemapper() = default;
    164 };
    165 
    166 struct GamepadRemappingData {
    167  GamepadId id;
    168  RefPtr<GamepadRemapper> remapping;
    169 };
    170 
    171 already_AddRefed<GamepadRemapper> GetGamepadRemapper(const uint16_t aVendorId,
    172                                                     const uint16_t aProductId,
    173                                                     bool& aUsingDefault);
    174 
    175 }  // namespace mozilla::dom
    176 
    177 #endif  // mozilla_dom_GamepadRemapping_h_