Title: [265183] trunk
Revision
265183
Author
[email protected]
Date
2020-08-01 19:53:25 -0700 (Sat, 01 Aug 2020)

Log Message

Special HID mapping for the Logitech F310/F710 controllers.
https://bugs.webkit.org/show_bug.cgi?id=215050

Reviewed by Tim Horton.

Source/WebCore:

Covered by API test.

These two controllers match the standard mapping perfectly. Easy to support.

* SourcesCocoa.txt:
* WebCore.xcodeproj/project.pbxproj:

* platform/gamepad/KnownGamepads.h:

* platform/gamepad/mac/GamepadConstantsMac.h:

* platform/gamepad/mac/HIDGamepad.cpp:
(WebCore::HIDGamepad::create):

* platform/gamepad/mac/HIDGamepadElement.cpp:
(WebCore::HIDGamepadElement::HIDGamepadElement):
* platform/gamepad/mac/HIDGamepadElement.h:
(WebCore::HIDGamepadElement::isAxis const):

* platform/gamepad/mac/LogitechGamepad.cpp: Added.
(WebCore::LogitechGamepadHatswitch::gamepadValueChanged):
(WebCore::LogitechGamepad::LogitechGamepad):
* platform/gamepad/mac/LogitechGamepad.h:

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:

* TestWebKitAPI/Tests/mac/HIDGamepads.mm:

* TestWebKitAPI/mac/GamepadMappings/LogitechF310.mm: Added.
(TestWebKitAPI::publishReportCallback):
(TestWebKitAPI::VirtualGamepad::logitechF310Mapping):

* TestWebKitAPI/mac/GamepadMappings/LogitechF710.mm: Added.
(TestWebKitAPI::publishReportCallback):
(TestWebKitAPI::VirtualGamepad::logitechF710Mapping):

* TestWebKitAPI/mac/VirtualGamepad.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (265182 => 265183)


--- trunk/Source/WebCore/ChangeLog	2020-08-02 01:50:08 UTC (rev 265182)
+++ trunk/Source/WebCore/ChangeLog	2020-08-02 02:53:25 UTC (rev 265183)
@@ -1,3 +1,34 @@
+2020-08-01  Brady Eidson  <[email protected]>
+
+        Special HID mapping for the Logitech F310/F710 controllers.
+        https://bugs.webkit.org/show_bug.cgi?id=215050
+
+        Reviewed by Tim Horton.
+
+        Covered by API test.
+
+        These two controllers match the standard mapping perfectly. Easy to support.
+        
+        * SourcesCocoa.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        
+        * platform/gamepad/KnownGamepads.h:
+        
+        * platform/gamepad/mac/GamepadConstantsMac.h:
+        
+        * platform/gamepad/mac/HIDGamepad.cpp:
+        (WebCore::HIDGamepad::create):
+        
+        * platform/gamepad/mac/HIDGamepadElement.cpp:
+        (WebCore::HIDGamepadElement::HIDGamepadElement):
+        * platform/gamepad/mac/HIDGamepadElement.h:
+        (WebCore::HIDGamepadElement::isAxis const):
+        
+        * platform/gamepad/mac/LogitechGamepad.cpp: Added.
+        (WebCore::LogitechGamepadHatswitch::gamepadValueChanged):
+        (WebCore::LogitechGamepad::LogitechGamepad):
+        * platform/gamepad/mac/LogitechGamepad.h: 
+
 2020-08-01  Joonghun Park  <[email protected]>
 
         Unreviewed. Remove the build warnings below since r265150.

Modified: trunk/Source/WebCore/SourcesCocoa.txt (265182 => 265183)


--- trunk/Source/WebCore/SourcesCocoa.txt	2020-08-02 01:50:08 UTC (rev 265182)
+++ trunk/Source/WebCore/SourcesCocoa.txt	2020-08-02 02:53:25 UTC (rev 265183)
@@ -262,6 +262,7 @@
 platform/gamepad/mac/HIDGamepad.cpp
 platform/gamepad/mac/HIDGamepadElement.cpp
 platform/gamepad/mac/HIDGamepadProvider.mm
+platform/gamepad/mac/LogitechGamepad.cpp
 platform/gamepad/mac/MultiGamepadProvider.mm
 platform/gamepad/mac/StadiaHIDGamepad.cpp
 platform/graphics/MediaPlaybackTargetPicker.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (265182 => 265183)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-08-02 01:50:08 UTC (rev 265182)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-08-02 02:53:25 UTC (rev 265183)
@@ -1406,6 +1406,7 @@
 		510A91FD24D3C16200BFD89C /* GamepadConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 51715FE924CD05DD002C97E6 /* GamepadConstants.h */; };
 		510A91FE24D3C16700BFD89C /* GamepadConstantsMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 510A91FB24D3C0FD00BFD89C /* GamepadConstantsMac.h */; };
 		510A921224D5E60E00BFD89C /* StadiaHIDGamepad.h in Headers */ = {isa = PBXBuildFile; fileRef = 510A921124D5E21700BFD89C /* StadiaHIDGamepad.h */; };
+		510A920824D4F49900BFD89C /* LogitechGamepad.h in Headers */ = {isa = PBXBuildFile; fileRef = 510A920524D4F07A00BFD89C /* LogitechGamepad.h */; };
 		510D4A34103165EE0049EA54 /* SocketStreamError.h in Headers */ = {isa = PBXBuildFile; fileRef = 510D4A2E103165EE0049EA54 /* SocketStreamError.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		510D4A37103165EE0049EA54 /* SocketStreamHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = 510D4A31103165EE0049EA54 /* SocketStreamHandle.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		510D4A38103165EE0049EA54 /* SocketStreamHandleClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 510D4A32103165EE0049EA54 /* SocketStreamHandleClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -8239,6 +8240,8 @@
 		510A91FB24D3C0FD00BFD89C /* GamepadConstantsMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GamepadConstantsMac.h; sourceTree = "<group>"; };
 		510A920F24D5E21700BFD89C /* StadiaHIDGamepad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StadiaHIDGamepad.cpp; sourceTree = "<group>"; };
 		510A921124D5E21700BFD89C /* StadiaHIDGamepad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StadiaHIDGamepad.h; sourceTree = "<group>"; };
+		510A920524D4F07A00BFD89C /* LogitechGamepad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LogitechGamepad.h; sourceTree = "<group>"; };
+		510A920724D4F07A00BFD89C /* LogitechGamepad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LogitechGamepad.cpp; sourceTree = "<group>"; };
 		510D4A2E103165EE0049EA54 /* SocketStreamError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SocketStreamError.h; sourceTree = "<group>"; };
 		510D4A30103165EE0049EA54 /* SocketStreamHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SocketStreamHandle.cpp; sourceTree = "<group>"; };
 		510D4A31103165EE0049EA54 /* SocketStreamHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SocketStreamHandle.h; sourceTree = "<group>"; };
@@ -19702,6 +19705,8 @@
 				510A91D624CE8EDE00BFD89C /* HIDGamepadElement.h */,
 				515BE19A1D54F6BD00DD7C68 /* HIDGamepadProvider.h */,
 				515BE1991D54F6BD00DD7C68 /* HIDGamepadProvider.mm */,
+				510A920724D4F07A00BFD89C /* LogitechGamepad.cpp */,
+				510A920524D4F07A00BFD89C /* LogitechGamepad.h */,
 				517E03F424B6B9630054895A /* MultiGamepadProvider.h */,
 				517E03F524B6B9640054895A /* MultiGamepadProvider.mm */,
 				510A920F24D5E21700BFD89C /* StadiaHIDGamepad.cpp */,
@@ -32417,6 +32422,7 @@
 				A8239E0109B3CF8A00B60641 /* Logging.h in Headers */,
 				9BA273F4172206BB0097CE47 /* LogicalSelectionOffsetCaches.h in Headers */,
 				0FDCD7F31D47E655009F08BC /* LogInitialization.h in Headers */,
+				510A920824D4F49900BFD89C /* LogitechGamepad.h in Headers */,
 				93A806171E03B51C008A1F26 /* LongRange.h in Headers */,
 				46EFAF121E5FB9F100E7F34B /* LowPowerModeNotifier.h in Headers */,
 				7AE6C93C1BE0C60100E19E03 /* MainThreadSharedTimer.h in Headers */,

Modified: trunk/Source/WebCore/platform/gamepad/KnownGamepads.h (265182 => 265183)


--- trunk/Source/WebCore/platform/gamepad/KnownGamepads.h	2020-08-02 01:50:08 UTC (rev 265182)
+++ trunk/Source/WebCore/platform/gamepad/KnownGamepads.h	2020-08-02 02:53:25 UTC (rev 265183)
@@ -35,6 +35,8 @@
     Dualshock4_2 = 0x054c09cc,
     GamesirM2 = 0x0ec20475,
     HoripadUltimate = 0x0f0d0090,
+    LogitechF310 = 0x046dc216,
+    LogitechF710 = 0x046dc219,
     Nimbus1 = 0x01111420,
     Nimbus2 = 0x10381420,
     StadiaA = 0x18d19400,

Modified: trunk/Source/WebCore/platform/gamepad/mac/GamepadConstantsMac.h (265182 => 265183)


--- trunk/Source/WebCore/platform/gamepad/mac/GamepadConstantsMac.h	2020-08-02 01:50:08 UTC (rev 265182)
+++ trunk/Source/WebCore/platform/gamepad/mac/GamepadConstantsMac.h	2020-08-02 02:53:25 UTC (rev 265183)
@@ -46,8 +46,11 @@
 constexpr const uint64_t hidButton3FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 2);
 constexpr const uint64_t hidButton4FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 3);
 constexpr const uint64_t hidButton5FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 4);
+constexpr const uint64_t hidButton6FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 5);
 constexpr const uint64_t hidButton7FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 6);
 constexpr const uint64_t hidButton8FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 7);
+constexpr const uint64_t hidButton9FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 8);
+constexpr const uint64_t hidButton10FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 9);
 constexpr const uint64_t hidButton11FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 10);
 constexpr const uint64_t hidButton12FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 11);
 constexpr const uint64_t hidButton13FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 12);

Modified: trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.cpp (265182 => 265183)


--- trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.cpp	2020-08-02 01:50:08 UTC (rev 265182)
+++ trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.cpp	2020-08-02 02:53:25 UTC (rev 265183)
@@ -32,6 +32,7 @@
 #include "GenericHIDGamepad.h"
 #include "KnownGamepads.h"
 #include "Logging.h"
+#include "LogitechGamepad.h"
 #include "StadiaHIDGamepad.h"
 #include <IOKit/hid/IOHIDElement.h>
 #include <IOKit/hid/IOHIDUsageTables.h>
@@ -51,6 +52,10 @@
     case Dualshock3:
         newGamepad = makeUnique<Dualshock3HIDGamepad>(WTFMove(device), index);
         break;
+    case LogitechF310:
+    case LogitechF710:
+        newGamepad = makeUnique<LogitechGamepad>(WTFMove(device), index);
+        break;
     case StadiaA:
         newGamepad = makeUnique<StadiaHIDGamepad>(WTFMove(device), index);
         break;

Added: trunk/Source/WebCore/platform/gamepad/mac/LogitechGamepad.cpp (0 => 265183)


--- trunk/Source/WebCore/platform/gamepad/mac/LogitechGamepad.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/gamepad/mac/LogitechGamepad.cpp	2020-08-02 02:53:25 UTC (rev 265183)
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LogitechGamepad.h"
+
+#if ENABLE(GAMEPAD) && PLATFORM(MAC)
+
+#include "GamepadConstants.h"
+#include "GamepadConstantsMac.h"
+#include "Logging.h"
+#include <IOKit/hid/IOHIDUsageTables.h>
+#include <wtf/HexNumber.h>
+
+namespace WebCore {
+
+LogitechGamepad::LogitechGamepad(HIDDevice&& device, unsigned index)
+    : HIDGamepad(WTFMove(device), index)
+{
+    LOG(Gamepad, "Creating LogitechGamepad %p", this);
+
+    m_mapping = standardGamepadMappingString();
+
+    for (size_t i = 0; i < numberOfStandardGamepadButtonsWithoutHomeButton; ++i)
+        m_buttonValues.append(0.0);
+
+    static const size_t axisCount = 4;
+    for (size_t i = 0; i < axisCount; ++i)
+        m_axisValues.append(0.0);
+
+    auto inputElements = hidDevice().uniqueInputElementsInDeviceTreeOrder();
+
+    auto mapButton = [this] (HIDElement& element, GamepadButtonRole role) {
+        m_elementMap.set(element.cookie(), makeUnique<HIDGamepadButton>(element, m_buttonValues[(size_t)role]));
+    };
+
+    for (auto& element : inputElements) {
+        switch (element.fullUsage()) {
+        case hidHatswitchFullUsage: {
+            Vector<SharedGamepadValue> hatswitchValues;
+            hatswitchValues.append(m_buttonValues[(size_t)GamepadButtonRole::LeftClusterTop]);
+            hatswitchValues.append(m_buttonValues[(size_t)GamepadButtonRole::LeftClusterRight]);
+            hatswitchValues.append(m_buttonValues[(size_t)GamepadButtonRole::LeftClusterBottom]);
+            hatswitchValues.append(m_buttonValues[(size_t)GamepadButtonRole::LeftClusterLeft]);
+
+            m_elementMap.set(element.cookie(), makeUnique<HIDGamepadHatswitch>(element, WTFMove(hatswitchValues)));
+            break;
+        }
+        case hidXAxisFullUsage:
+            m_elementMap.set(element.cookie(), makeUnique<HIDGamepadAxis>(element, m_axisValues[0]));
+            break;
+        case hidYAxisFullUsage:
+            m_elementMap.set(element.cookie(), makeUnique<HIDGamepadAxis>(element, m_axisValues[1]));
+            break;
+        case hidZAxisFullUsage:
+            m_elementMap.set(element.cookie(), makeUnique<HIDGamepadAxis>(element, m_axisValues[2]));
+            break;
+        case hidRzAxisFullUsage:
+            m_elementMap.set(element.cookie(), makeUnique<HIDGamepadAxis>(element, m_axisValues[3]));
+            break;
+        case hidButton1FullUsage:
+            mapButton(element, GamepadButtonRole::RightClusterLeft);
+            break;
+        case hidButton2FullUsage:
+            mapButton(element, GamepadButtonRole::RightClusterBottom);
+            break;
+        case hidButton3FullUsage:
+            mapButton(element, GamepadButtonRole::RightClusterRight);
+            break;
+        case hidButton4FullUsage:
+            mapButton(element, GamepadButtonRole::RightClusterTop);
+            break;
+        case hidButton5FullUsage:
+            mapButton(element, GamepadButtonRole::LeftShoulderFront);
+            break;
+        case hidButton6FullUsage:
+            mapButton(element, GamepadButtonRole::RightShoulderFront);
+            break;
+        case hidButton7FullUsage:
+            mapButton(element, GamepadButtonRole::LeftShoulderBack);
+            break;
+        case hidButton8FullUsage:
+            mapButton(element, GamepadButtonRole::RightShoulderBack);
+            break;
+        case hidButton9FullUsage:
+            mapButton(element, GamepadButtonRole::CenterClusterLeft);
+            break;
+        case hidButton10FullUsage:
+            mapButton(element, GamepadButtonRole::CenterClusterRight);
+            break;
+        case hidButton11FullUsage:
+            mapButton(element, GamepadButtonRole::LeftStick);
+            break;
+        case hidButton12FullUsage:
+            mapButton(element, GamepadButtonRole::RightStick);
+            break;
+        default:
+            break;
+        }
+    }
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD) && PLATFORM(MAC)

Copied: trunk/Source/WebCore/platform/gamepad/mac/LogitechGamepad.h (from rev 265182, trunk/Source/WebCore/platform/gamepad/KnownGamepads.h) (0 => 265183)


--- trunk/Source/WebCore/platform/gamepad/mac/LogitechGamepad.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/gamepad/mac/LogitechGamepad.h	2020-08-02 02:53:25 UTC (rev 265183)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(GAMEPAD) && PLATFORM(MAC)
+
+#include "HIDGamepad.h"
+
+namespace WebCore {
+
+class LogitechGamepad final : public HIDGamepad {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    LogitechGamepad(HIDDevice&&, unsigned index);
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD) && PLATFORM(MAC)

Modified: trunk/Source/WebCore/platform/mac/HIDElement.cpp (265182 => 265183)


--- trunk/Source/WebCore/platform/mac/HIDElement.cpp	2020-08-02 01:50:08 UTC (rev 265182)
+++ trunk/Source/WebCore/platform/mac/HIDElement.cpp	2020-08-02 02:53:25 UTC (rev 265183)
@@ -28,6 +28,8 @@
 
 #if PLATFORM(MAC)
 
+#include "Logging.h"
+#include <IOKit/hid/IOHIDElement.h>
 #include <IOKit/hid/IOHIDValue.h>
 
 namespace WebCore {

Modified: trunk/Tools/ChangeLog (265182 => 265183)


--- trunk/Tools/ChangeLog	2020-08-02 01:50:08 UTC (rev 265182)
+++ trunk/Tools/ChangeLog	2020-08-02 02:53:25 UTC (rev 265183)
@@ -1,5 +1,26 @@
 2020-08-01  Brady Eidson  <[email protected]>
 
+        Special HID mapping for the Logitech F310/F710 controllers.
+        https://bugs.webkit.org/show_bug.cgi?id=215050
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+
+        * TestWebKitAPI/Tests/mac/HIDGamepads.mm:
+
+        * TestWebKitAPI/mac/GamepadMappings/LogitechF310.mm: Added.
+        (TestWebKitAPI::publishReportCallback):
+        (TestWebKitAPI::VirtualGamepad::logitechF310Mapping):
+
+        * TestWebKitAPI/mac/GamepadMappings/LogitechF710.mm: Added.
+        (TestWebKitAPI::publishReportCallback):
+        (TestWebKitAPI::VirtualGamepad::logitechF710Mapping):
+
+        * TestWebKitAPI/mac/VirtualGamepad.h:
+
+2020-08-01  Brady Eidson  <[email protected]>
+
         Special HID mapping for the Google Stadia controller
         https://bugs.webkit.org/show_bug.cgi?id=215061
 

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (265182 => 265183)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-08-02 01:50:08 UTC (rev 265182)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-08-02 02:53:25 UTC (rev 265183)
@@ -278,6 +278,8 @@
 		510477781D29923B009747EB /* IDBDeleteRecovery.mm in Sources */ = {isa = PBXBuildFile; fileRef = 510477751D298E03009747EB /* IDBDeleteRecovery.mm */; };
 		510A91F824D3622100BFD89C /* SonyDualShock3.mm in Sources */ = {isa = PBXBuildFile; fileRef = 510A91F724D3621900BFD89C /* SonyDualShock3.mm */; };
 		510A921424D615B400BFD89C /* GoogleStadia.mm in Sources */ = {isa = PBXBuildFile; fileRef = 510A921324D60A3E00BFD89C /* GoogleStadia.mm */; };
+		510A920A24D5048900BFD89C /* LogitechF310.mm in Sources */ = {isa = PBXBuildFile; fileRef = 510A920924D5048300BFD89C /* LogitechF310.mm */; };
+		510A920C24D5275500BFD89C /* LogitechF710.mm in Sources */ = {isa = PBXBuildFile; fileRef = 510A920B24D5275100BFD89C /* LogitechF710.mm */; };
 		5110FCF11E01CD64006F8D0B /* IDBIndexUpgradeToV2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5110FCF01E01CD53006F8D0B /* IDBIndexUpgradeToV2.html */; };
 		5110FCF61E01CD83006F8D0B /* IndexUpgrade.sqlite3 in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5110FCF31E01CD77006F8D0B /* IndexUpgrade.sqlite3 */; };
 		5110FCF91E01CD8A006F8D0B /* IndexUpgrade.blob in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5110FCF21E01CD77006F8D0B /* IndexUpgrade.blob */; };
@@ -1975,6 +1977,8 @@
 		510477761D298E57009747EB /* IDBDeleteRecovery.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = IDBDeleteRecovery.html; sourceTree = "<group>"; };
 		510A91F724D3621900BFD89C /* SonyDualShock3.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SonyDualShock3.mm; sourceTree = "<group>"; };
 		510A921324D60A3E00BFD89C /* GoogleStadia.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GoogleStadia.mm; sourceTree = "<group>"; };
+		510A920924D5048300BFD89C /* LogitechF310.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LogitechF310.mm; sourceTree = "<group>"; };
+		510A920B24D5275100BFD89C /* LogitechF710.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LogitechF710.mm; sourceTree = "<group>"; };
 		5110FCEF1E01CBAA006F8D0B /* IDBIndexUpgradeToV2.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = IDBIndexUpgradeToV2.mm; sourceTree = "<group>"; };
 		5110FCF01E01CD53006F8D0B /* IDBIndexUpgradeToV2.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = IDBIndexUpgradeToV2.html; sourceTree = "<group>"; };
 		5110FCF21E01CD77006F8D0B /* IndexUpgrade.blob */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = IndexUpgrade.blob; sourceTree = "<group>"; };
@@ -3471,6 +3475,8 @@
 			isa = PBXGroup;
 			children = (
 				510A921324D60A3E00BFD89C /* GoogleStadia.mm */,
+				510A920924D5048300BFD89C /* LogitechF310.mm */,
+				510A920B24D5275100BFD89C /* LogitechF710.mm */,
 				51EB126024CA6B5F000CB030 /* MicrosoftXboxOne.mm */,
 				51EB125E24CA6B5F000CB030 /* ShenzhenLongshengweiTechnologyGamepad.mm */,
 				510A91F724D3621900BFD89C /* SonyDualShock3.mm */,
@@ -5184,6 +5190,8 @@
 				7A6A2C701DCCFA8C00C0D085 /* LocalStorageQuirkTest.mm in Sources */,
 				6BF4A683239ED4CD00E2F45B /* LoggedInStatus.cpp in Sources */,
 				076E507F1F4513D6006E9F5A /* Logging.cpp in Sources */,
+				510A920A24D5048900BFD89C /* LogitechF310.mm in Sources */,
+				510A920C24D5275500BFD89C /* LogitechF710.mm in Sources */,
 				CE1866491F72E8F100A0CAB6 /* MarkedText.cpp in Sources */,
 				07CC7DFE2266330900E39181 /* MediaBufferingPolicy.mm in Sources */,
 				CD0370E324A44D9600BA3CAE /* MediaLoading.mm in Sources */,

Modified: trunk/Tools/TestWebKitAPI/Tests/mac/HIDGamepads.mm (265182 => 265183)


--- trunk/Tools/TestWebKitAPI/Tests/mac/HIDGamepads.mm	2020-08-02 01:50:08 UTC (rev 265182)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/HIDGamepads.mm	2020-08-02 02:53:25 UTC (rev 265183)
@@ -489,6 +489,84 @@
     didReceiveMessage = true;
 }
 
+TEST(Gamepad, LogitechBasic)
+{
+    auto keyWindowSwizzler = makeUnique<InstanceMethodSwizzler>([NSApplication class], @selector(keyWindow), reinterpret_cast<IMP>(getKeyWindowForTesting));
+
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    auto messageHandler = adoptNS([[GamepadMessageHandler alloc] init]);
+    [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"gamepad"];
+
+    auto schemeHandler = adoptNS([[TestURLSchemeHandler alloc] init]);
+    [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"gamepad"];
+
+    [schemeHandler setStartURLSchemeTaskHandler:^(WKWebView *, id<WKURLSchemeTask> task) {
+        auto response = adoptNS([[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:@"text/html" expectedContentLength:0 textEncodingName:nil]);
+        [task didReceiveResponse:response.get()];
+        [task didReceiveData:[NSData dataWithBytes:mainBytes length:strlen(mainBytes)]];
+        [task didFinish];
+    }];
+
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+    keyWindowForTesting = [webView window];
+    [webView synchronouslyLoadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"gamepad://host/main.html"]]];
+
+    [[webView window] makeFirstResponder:webView.get()];
+
+    // Resigning/reinstating the key window state triggers the "key window did change" notification that WKWebView currently
+    // needs to convince it to monitor gamepad devices
+    [[webView window] resignKeyWindow];
+    [[webView window] makeKeyWindow];
+
+    // Connect a gamepad and make it visible to the page
+    auto gamepad1 = makeUnique<VirtualGamepad>(VirtualGamepad::logitechF310Mapping());
+    auto gamepad2 = makeUnique<VirtualGamepad>(VirtualGamepad::logitechF710Mapping());
+    while ([webView.get().configuration.processPool _numberOfConnectedGamepadsForTesting] != 2u)
+        Util::sleep(0.01);
+
+    EXPECT_EQ([webView.get().configuration.processPool _numberOfConnectedHIDGamepadsForTesting], 2u);
+    EXPECT_EQ([webView.get().configuration.processPool _numberOfConnectedGameControllerFrameworkGamepadsForTesting], 0u);
+
+    gamepad1->setButtonValue(0, 1.0);
+    gamepad2->setButtonValue(0, 1.0);
+    gamepad1->publishReport();
+    gamepad2->publishReport();
+
+    // The page messages back once for each controller
+    while (messageHandler.get().messages.size() < 2) {
+        didReceiveMessage = false;
+        Util::run(&didReceiveMessage);
+    }
+
+    EXPECT_EQ(messageHandler.get().messages.size(), 2u);
+    EXPECT_TRUE([messageHandler.get().messages[0] isEqualToString:@"\"46d-c216-Virtual Logitech F310\""]);
+
+    NSSet *expectedGamepadNames = [NSSet setWithArray:@[
+        @"\"46d-c216-Virtual Logitech F310\"",
+        @"\"46d-c219-Virtual Logitech F710\""]];
+
+    for (size_t i = 0; i < 2; ++i)
+        EXPECT_TRUE([expectedGamepadNames containsObject:messageHandler.get().messages[i].get()]);
+
+    bool done = false;
+    auto resultBlock = [&] (id result, NSError *error) {
+        EXPECT_NULL(error);
+        EXPECT_TRUE([result[@"gamepadCount"] isEqualToNumber:@(2)]);
+        EXPECT_EQ(((NSArray *)result[@"gamepadButtons"][0]).count, 16u);
+        EXPECT_EQ(((NSArray *)result[@"gamepadButtons"][1]).count, 16u);
+        EXPECT_EQ(((NSArray *)result[@"gamepadAxes"][0]).count, 4u);
+        EXPECT_EQ(((NSArray *)result[@"gamepadAxes"][1]).count, 4u);
+
+        done = true;
+    };
+
+    [webView callAsyncJavaScript:@(pollGamepadStateFunction) arguments:nil inFrame:nil inContentWorld:WKContentWorld.pageWorld completionHandler:resultBlock];
+
+    Util::run(&done);
+    didReceiveMessage = true;
+}
+
+
 } // namespace TestWebKitAPI
 
 #endif // HAVE(HID_FRAMEWORK) && USE(APPLE_INTERNAL_SDK)

Added: trunk/Tools/TestWebKitAPI/mac/GamepadMappings/LogitechF310.mm (0 => 265183)


--- trunk/Tools/TestWebKitAPI/mac/GamepadMappings/LogitechF310.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/mac/GamepadMappings/LogitechF310.mm	2020-08-02 02:53:25 UTC (rev 265183)
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "VirtualGamepad.h"
+
+#if HAVE(HID_FRAMEWORK) && USE(APPLE_INTERNAL_SDK)
+
+#import <HID/HIDUserDevice.h>
+
+namespace TestWebKitAPI {
+
+const uint8_t F310Descriptor[] = {
+    0x05, 0x01,         // Usage Page (Generic Desktop Ctrls)
+    0x09, 0x04,         // Usage (Joystick)
+    0xA1, 0x01,         // Collection (Application)
+    0xA1, 0x02,         //   Collection (Logical)
+    0x75, 0x08,         //     Report Size (8)
+    0x95, 0x04,         //     Report Count (4)
+    0x15, 0x00,         //     Logical Minimum (0)
+    0x26, 0xFF, 0x00,   //     Logical Maximum (255)
+    0x35, 0x00,         //     Physical Minimum (0)
+    0x46, 0xFF, 0x00,   //     Physical Maximum (255)
+    0x09, 0x30,         //     Usage (X)
+    0x09, 0x31,         //     Usage (Y)
+    0x09, 0x32,         //     Usage (Z)
+    0x09, 0x35,         //     Usage (Rz)
+                        //     (4) axes, 1 byte each. Total - (4) bytes
+    0x81, 0x02,         //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
+    0x75, 0x04,         //     Report Size (4)
+    0x95, 0x01,         //     Report Count (1)
+    0x25, 0x07,         //     Logical Maximum (7)
+    0x46, 0x3B, 0x01,   //     Physical Maximum (315)
+    0x65, 0x14,         //     Unit (System: English Rotation, Length: Centimeter)
+    0x09, 0x39,         //     Usage (Hat switch)
+                        //     (1) Hat switch, 4 bits. Total - (4) bytes (4) bits
+    0x81, 0x42,         //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,Null State)
+    0x65, 0x00,         //     Unit (None)
+    0x75, 0x01,         //     Report Size (1)
+    0x95, 0x0C,         //     Report Count (12)
+    0x25, 0x01,         //     Logical Maximum (1)
+    0x45, 0x01,         //     Physical Maximum (1)
+    0x05, 0x09,         //     Usage Page (Button)
+    0x19, 0x01,         //     Usage Minimum (0x01)
+    0x29, 0x0C,         //     Usage Maximum (0x0C)
+                        //     (12) Button bits. Total - (6) bytes
+    0x81, 0x02,         //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
+    0x06, 0x00, 0xFF,   //     Usage Page (Vendor Defined 0xFF00)
+    0x75, 0x01,         //     Report Size (1)
+    0x95, 0x10,         //     Report Count (16)
+    0x25, 0x01,         //     Logical Maximum (1)
+    0x45, 0x01,         //     Physical Maximum (1)
+    0x09, 0x01,         //     Usage (0x01)
+                        //     (2) unknown bytes. Total - (8) bytes
+    0x81, 0x02,         //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
+    0xC0,               //   End Collection
+    0xA1, 0x02,         //   Collection (Logical)
+    0x75, 0x08,         //     Report Size (8)
+    0x95, 0x07,         //     Report Count (7)
+    0x46, 0xFF, 0x00,   //     Physical Maximum (255)
+    0x26, 0xFF, 0x00,   //     Logical Maximum (255)
+    0x09, 0x02,         //     Usage (0x02)
+    0x91, 0x02,         //     Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
+    0xC0,               //   End Collection
+    0xC0,               // End Collection
+};
+
+const size_t F310ButtonCount = 13;
+const size_t F310AxisCount = 4;
+const size_t F310ReportSize = 8;
+const char* F310Name = "Virtual Logitech F310";
+
+// Report layout:
+// |X| |Y| |Z| |Rz| |b1-b4, hatswitch| |b5-b12| |0x00| |0xff|
+
+static void publishReportCallback(Vector<float>& buttonValues, Vector<float>& axisValues, HIDUserDevice *userDevice)
+{
+    uint8_t reportData[F310ReportSize];
+
+    // First 4 bytes are the axis values
+    for (size_t i = 0; i < 4; ++i)
+        reportData[i] = (uint8_t)((int8_t)(axisValues[i] * 127));
+
+    // Next byte is the hatswitch and first 4 buttons
+    // FIXME: No API test configurability of the hatswitch yet
+    uint8_t buttonByte = 0x08;
+    long buttonBit;
+    for (size_t i = 0; i < 4; ++i) {
+        buttonBit = lround(buttonValues[i]);
+        buttonByte |= buttonBit << (i + 4);
+    }
+    reportData[4] = buttonByte;
+
+    // Next byte is buttons 5-12
+    buttonByte = 0x00;
+    for (size_t i = 4; i < 12; ++i) {
+        buttonBit = lround(buttonValues[i]);
+        buttonByte |= buttonBit << (i - 4);
+    }
+    reportData[5] = buttonByte;
+
+    // Final 2 bytes are constant
+    reportData[6] = 0x00;
+    reportData[7] = 0xff;
+
+    auto nsReportData = adoptNS([[NSData alloc] initWithBytes:reportData length:F310ReportSize]);
+    [userDevice handleReport:nsReportData.get() error:nil];
+}
+
+GamepadMapping VirtualGamepad::logitechF310Mapping()
+{
+    return {
+        F310Descriptor,
+        sizeof(F310Descriptor),
+        F310Name,
+        HIDVendorID::Logitech,
+        HIDProductID::F310,
+        F310ButtonCount,
+        F310AxisCount,
+        publishReportCallback
+    };
+}
+
+} // namespace TestWebKitAPI
+
+#endif // HAVE(HID_FRAMEWORK) && USE(APPLE_INTERNAL_SDK)

Added: trunk/Tools/TestWebKitAPI/mac/GamepadMappings/LogitechF710.mm (0 => 265183)


--- trunk/Tools/TestWebKitAPI/mac/GamepadMappings/LogitechF710.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/mac/GamepadMappings/LogitechF710.mm	2020-08-02 02:53:25 UTC (rev 265183)
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "VirtualGamepad.h"
+
+#if HAVE(HID_FRAMEWORK) && USE(APPLE_INTERNAL_SDK)
+
+#import <HID/HIDUserDevice.h>
+
+namespace TestWebKitAPI {
+
+const uint8_t F710Descriptor[] = {
+    0x05, 0x01,         // Usage Page (Generic Desktop Ctrls)
+    0x09, 0x05,         // Usage (Game Pad)
+    0xA1, 0x01,         // Collection (Application)
+    0xA1, 0x02,         //   Collection (Logical)
+                        //     (1) Byte report ID. Total - (1) bytes
+    0x85, 0x01,         //     Report ID (1)
+    0x75, 0x08,         //     Report Size (8)
+    0x95, 0x04,         //     Report Count (4)
+    0x15, 0x00,         //     Logical Minimum (0)
+    0x26, 0xFF, 0x00,   //     Logical Maximum (255)
+    0x35, 0x00,         //     Physical Minimum (0)
+    0x46, 0xFF, 0x00,   //     Physical Maximum (255)
+    0x09, 0x30,         //     Usage (X)
+    0x09, 0x31,         //     Usage (Y)
+    0x09, 0x32,         //     Usage (Z)
+    0x09, 0x35,         //     Usage (Rz)
+                        //     (4) axes, 1 byte each. Total - (5) bytes
+    0x81, 0x02,         //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
+    0x75, 0x04,         //     Report Size (4)
+    0x95, 0x01,         //     Report Count (1)
+    0x25, 0x07,         //     Logical Maximum (7)
+    0x46, 0x3B, 0x01,   //     Physical Maximum (315)
+    0x66, 0x14, 0x00,   //     Unit (System: English Rotation, Length: Centimeter)
+    0x09, 0x39,         //     Usage (Hat switch)
+                        //     (1) Hat switch, 4 bits. Total - (5) bytes (4) bits
+    0x81, 0x42,         //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,Null State)
+    0x66, 0x00, 0x00,   //     Unit (None)
+    0x75, 0x01,         //     Report Size (1)
+    0x95, 0x0C,         //     Report Count (12)
+    0x25, 0x01,         //     Logical Maximum (1)
+    0x45, 0x01,         //     Physical Maximum (1)
+    0x05, 0x09,         //     Usage Page (Button)
+    0x19, 0x01,         //     Usage Minimum (0x01)
+    0x29, 0x0C,         //     Usage Maximum (0x0C)
+                        //     (12) Button bits. Total - (7) bytes
+    0x81, 0x02,         //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
+    0x95, 0x01,         //     Report Count (1)
+    0x75, 0x08,         //     Report Size (8)
+    0x06, 0x00, 0xFF,   //     Usage Page (Vendor Defined 0xFF00)
+    0x26, 0xFF, 0x00,   //     Logical Maximum (255)
+    0x46, 0xFF, 0x00,   //     Physical Maximum (255)
+    0x09, 0x00,         //     Usage (0x00)
+                        //     (1) vendor specific byte. Total - (8) bytes
+    0x81, 0x02,         //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
+    0xC0,               //   End Collection
+    0xA1, 0x02,         //   Collection (Logical)
+    0x85, 0x02,         //     Report ID (2)
+    0x95, 0x07,         //     Report Count (7)
+    0x75, 0x08,         //     Report Size (8)
+    0x26, 0xFF, 0x00,   //     Logical Maximum (255)
+    0x46, 0xFF, 0x00,   //     Physical Maximum (255)
+    0x06, 0x00, 0xFF,   //     Usage Page (Vendor Defined 0xFF00)
+    0x09, 0x03,         //     Usage (0x03)
+    0x81, 0x02,         //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
+    0xC0,               //   End Collection
+    0xA1, 0x02,         //   Collection (Logical)
+    0x85, 0x03,         //     Report ID (3)
+    0x09, 0x04,         //     Usage (0x04)
+    0x91, 0x02,         //     Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
+    0xC0,               //   End Collection
+    0xC0,               // End Collection
+};
+
+const size_t F710ButtonCount = 13;
+const size_t F710AxisCount = 4;
+const size_t F710ReportSize = 8;
+const char* F710Name = "Virtual Logitech F710";
+
+// Report layout:
+// |ReportID| |X| |Y| |Z| |Rz| |b1-b4, hatswitch| |b5-b12| |vendor specific|
+
+static void publishReportCallback(Vector<float>& buttonValues, Vector<float>& axisValues, HIDUserDevice *userDevice)
+{
+    uint8_t reportData[F710ReportSize];
+
+    // Report ID
+    reportData[0] = 0x01;
+
+    // Next 4 bytes are the axis values
+    for (size_t i = 0; i < 4; ++i)
+        reportData[i + 1] = (uint8_t)((int8_t)(axisValues[i] * 127));
+
+    // Next byte is the hatswitch and first 4 buttons
+    // FIXME: No API test configurability of the hatswitch yet
+    uint8_t buttonByte = 0x08;
+    long buttonBit;
+    for (size_t i = 0; i < 4; ++i) {
+        buttonBit = lround(buttonValues[i]);
+        buttonByte |= buttonBit << (i + 4);
+    }
+    reportData[5] = buttonByte;
+
+    // Next byte is buttons 5-12
+    buttonByte = 0x00;
+    for (size_t i = 4; i < 12; ++i) {
+        buttonBit = lround(buttonValues[i]);
+        buttonByte |= buttonBit << (i - 4);
+    }
+    reportData[6] = buttonByte;
+
+    // Final is vendor specific (changes with vibration mode, I know, but not relevant to the gamepad spec at this time)
+    reportData[7] = 0x5f;
+
+    auto nsReportData = adoptNS([[NSData alloc] initWithBytes:reportData length:F710ReportSize]);
+    [userDevice handleReport:nsReportData.get() error:nil];
+}
+
+GamepadMapping VirtualGamepad::logitechF710Mapping()
+{
+    return {
+        F710Descriptor,
+        sizeof(F710Descriptor),
+        F710Name,
+        HIDVendorID::Logitech,
+        HIDProductID::F710,
+        F710ButtonCount,
+        F710AxisCount,
+        publishReportCallback
+    };
+}
+
+} // namespace TestWebKitAPI
+
+#endif // HAVE(HID_FRAMEWORK) && USE(APPLE_INTERNAL_SDK)

Modified: trunk/Tools/TestWebKitAPI/mac/VirtualGamepad.h (265182 => 265183)


--- trunk/Tools/TestWebKitAPI/mac/VirtualGamepad.h	2020-08-02 01:50:08 UTC (rev 265182)
+++ trunk/Tools/TestWebKitAPI/mac/VirtualGamepad.h	2020-08-02 02:53:25 UTC (rev 265183)
@@ -41,6 +41,7 @@
 
 enum class HIDVendorID : uint16_t {
     Google = 0x18d1,
+    Logitech = 0x046d,
     Microsoft = 0x045e,
     ShenzhenLongshengweiTechnology = 0x0079,
     Sony = 0x054c,
@@ -56,6 +57,8 @@
     Dualshock3 = 0x0268,
     Dualshock4_1 = 0x05c4,
     Dualshock4_2 = 0x09cc,
+    F310 = 0xc216,
+    F710 = 0xc219,
     Gamepad = 0x0011,
     GenericNES = 0xd015,
     Nimbus = 0x1420,
@@ -84,6 +87,8 @@
     WTF_MAKE_FAST_ALLOCATED;
 public:
     static GamepadMapping googleStadiaMapping();
+    static GamepadMapping logitechF310Mapping();
+    static GamepadMapping logitechF710Mapping();
     static GamepadMapping microsoftXboxOneMapping();
     static GamepadMapping shenzhenLongshengweiTechnologyGamepadMapping();
     static GamepadMapping sonyDualshock3Mapping();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to