Bug 1465643 - Part 1: Removing unused hasDpad logic in WindowsGamepad.cpp. r=qdot
authorDaosheng Mu <daoshengmu@gmail.com>
Mon, 08 Apr 2019 18:51:25 +0000
changeset 468416 9133f02b68c460407237f9935511c7ca0ee90de5
parent 468415 e0b954c335afc72de98143c7a7d3b0301b1337ca
child 468417 3c267ad86e3c01403df560077f0aa6ef9dd19933
push id35837
push userrmaries@mozilla.com
push dateTue, 09 Apr 2019 03:43:40 +0000
treeherdermozilla-central@9eb55c9bf557 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1465643
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1465643 - Part 1: Removing unused hasDpad logic in WindowsGamepad.cpp. r=qdot Differential Revision: https://phabricator.services.mozilla.com/D25886
dom/gamepad/windows/WindowsGamepad.cpp
--- a/dom/gamepad/windows/WindowsGamepad.cpp
+++ b/dom/gamepad/windows/WindowsGamepad.cpp
@@ -109,35 +109,31 @@ class Gamepad {
 
   // ID from the GamepadService, also used as the index into
   // WindowsGamepadService::mGamepads.
   int id;
 
   // Information about the physical device.
   unsigned numAxes;
   unsigned numButtons;
-  bool hasDpad;
-  HIDP_VALUE_CAPS dpadCaps;
 
   nsTArray<bool> buttons;
   struct axisValue {
     HIDP_VALUE_CAPS caps;
     double value;
   };
   nsTArray<axisValue> axes;
 
   // Used during rescan to find devices that were disconnected.
   bool present;
 
-  Gamepad(uint32_t aNumAxes, uint32_t aNumButtons, bool aHasDpad,
-          GamepadType aType)
+  Gamepad(uint32_t aNumAxes, uint32_t aNumButtons, GamepadType aType)
       : type(aType),
         numAxes(aNumAxes),
         numButtons(aNumButtons),
-        hasDpad(aHasDpad),
         present(true) {
     buttons.SetLength(numButtons);
     axes.SetLength(numAxes);
   }
 
  private:
   Gamepad() {}
 };
@@ -202,55 +198,16 @@ bool GetPreparsedData(HANDLE handle, nsT
  * Given an axis value and a minimum and maximum range,
  * scale it to be in the range -1.0 .. 1.0.
  */
 double ScaleAxis(ULONG value, LONG min, LONG max) {
   return 2.0 * (value - min) / (max - min) - 1.0;
 }
 
 /*
- * Given a value from a d-pad (POV hat in USB HID terminology),
- * represent it as 4 buttons, one for each cardinal direction.
- */
-void UnpackDpad(LONG dpad_value, const Gamepad* gamepad,
-                nsTArray<bool>& buttons) {
-  const unsigned kUp = gamepad->numButtons - 4;
-  const unsigned kDown = gamepad->numButtons - 3;
-  const unsigned kLeft = gamepad->numButtons - 2;
-  const unsigned kRight = gamepad->numButtons - 1;
-
-  // Different controllers have different ways of representing
-  // "nothing is pressed", but they're all outside the range of values.
-  if (dpad_value < gamepad->dpadCaps.LogicalMin ||
-      dpad_value > gamepad->dpadCaps.LogicalMax) {
-    // Nothing is pressed.
-    return;
-  }
-
-  // Normalize value to start at 0.
-  int value = dpad_value - gamepad->dpadCaps.LogicalMin;
-
-  // Value will be in the range 0-7. The value represents the
-  // position of the d-pad around a circle, with 0 being straight up,
-  // 2 being right, 4 being straight down, and 6 being left.
-  if ((value < 2 || value > 6) && buttons.Length() > kUp) {
-    buttons[kUp] = true;
-  }
-  if ((value > 2 && value < 6) && buttons.Length() > kDown) {
-    buttons[kDown] = true;
-  }
-  if (value > 4 && buttons.Length() > kLeft) {
-    buttons[kLeft] = true;
-  }
-  if ((value > 0 && value < 4) && buttons.Length() > kRight) {
-    buttons[kRight] = true;
-  }
-}
-
-/*
  * Return true if this USB HID usage page and usage are of a type we
  * know how to handle.
  */
 bool SupportedUsage(USHORT page, USHORT usage) {
   for (unsigned i = 0; i < ArrayLength(kUsagePages); i++) {
     if (page == kUsagePages[i].usagePage && usage == kUsagePages[i].usage) {
       return true;
     }
@@ -460,18 +417,17 @@ bool WindowsGamepadService::ScanForXInpu
     }
     found = true;
     // See if this device is already present in our list.
     if (HaveXInputGamepad(i)) {
       continue;
     }
 
     // Not already present, add it.
-    Gamepad gamepad(kStandardGamepadAxes, kStandardGamepadButtons, true,
-                    kXInputGamepad);
+    Gamepad gamepad(kStandardGamepadAxes, kStandardGamepadButtons, kXInputGamepad);
     gamepad.userIndex = i;
     gamepad.state = state;
     gamepad.id = service->AddGamepad(
         "xinput", GamepadMappingType::Standard, GamepadHand::_empty,
         kStandardGamepadButtons, kStandardGamepadAxes,
         0);  // TODO: Bug 680289, implement gamepad haptics for Windows.
     mGamepads.AppendElement(gamepad);
   }
@@ -820,28 +776,16 @@ bool WindowsGamepadService::HandleRawInp
     //
     // Usage ID of 0 is reserved, so it should always be 1 or higher.
     if (NS_WARN_IF((usages[i] - 1u) >= buttons.Length())) {
       continue;
     }
     buttons[usages[i] - 1u] = true;
   }
 
-  if (gamepad->hasDpad) {
-    // Get d-pad position as 4 buttons.
-    ULONG value;
-    if (mHID.mHidP_GetUsageValue(HidP_Input, gamepad->dpadCaps.UsagePage, 0,
-                                 gamepad->dpadCaps.Range.UsageMin, &value,
-                                 parsed, (PCHAR)raw->data.hid.bRawData,
-                                 raw->data.hid.dwSizeHid) ==
-        HIDP_STATUS_SUCCESS) {
-      UnpackDpad(static_cast<LONG>(value), gamepad, buttons);
-    }
-  }
-
   for (unsigned i = 0; i < gamepad->numButtons; i++) {
     if (gamepad->buttons[i] != buttons[i]) {
       service->NewButtonEvent(gamepad->id, i, buttons[i]);
       gamepad->buttons[i] = buttons[i];
     }
   }
 
   // Get all axis values.