Title: [265156] trunk
Revision
265156
Author
[email protected]
Date
2020-07-31 12:50:33 -0700 (Fri, 31 Jul 2020)

Log Message

Special HID mapping for the Dualshock 3 controller
<rdar://problem/66255198> and https://bugs.webkit.org/show_bug.cgi?id=214911

Reviewed by Tim Horton.

Source/WebCore:

Covered by API tests.

- Move GamepadButtons into a GamepadConstants header
- Add a "KnownGamepads" header to hold all vendor/product pairs that WebKit knows about
- Add a Dualshock3 controller mapping based on its HID report
- Add a basic DS3 test based on the HID report

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

* platform/gamepad/GamepadConstants.cpp: Copied from Source/WebCore/platform/gamepad/mac/GenericHIDGamepad.h.
(WebCore::standardGamepadMappingString):
* platform/gamepad/GamepadConstants.h: Added.

* platform/gamepad/KnownGamepads.h: Copied from Source/WebCore/platform/gamepad/mac/GenericHIDGamepad.h.

* platform/gamepad/cocoa/GameControllerGamepad.mm:
(WebCore::GameControllerGamepad::setupAsExtendedGamepad):

* platform/gamepad/mac/Dualshock3HIDGamepad.cpp: Added.
(WebCore::Dualshock3HIDGamepad::Dualshock3HIDGamepad):
* platform/gamepad/mac/Dualshock3HIDGamepad.h: Copied from Source/WebCore/platform/gamepad/mac/GenericHIDGamepad.h.

* platform/gamepad/mac/GenericHIDGamepad.cpp:
(WebCore::GenericHIDGamepad::GenericHIDGamepad):
(WebCore::GenericHIDGamepad::id): Deleted.
* platform/gamepad/mac/GenericHIDGamepad.h:

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

* platform/mac/HIDDevice.h:
(WebCore::HIDDevice::fullProductIdentifier const):
* platform/mac/HIDElement.h:
(WebCore::HIDElement::fullUsage const):

Tools:

Add a virtual Dualshock3 and verify a few attributes about it.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/mac/HIDGamepads.mm:
* TestWebKitAPI/mac/GamepadMappings/SonyDualShock3.mm: Added.
(TestWebKitAPI::publishReportCallback):
(TestWebKitAPI::VirtualGamepad::sonyDualshock3Mapping):
* TestWebKitAPI/mac/VirtualGamepad.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (265155 => 265156)


--- trunk/Source/WebCore/ChangeLog	2020-07-31 19:39:18 UTC (rev 265155)
+++ trunk/Source/WebCore/ChangeLog	2020-07-31 19:50:33 UTC (rev 265156)
@@ -1,3 +1,50 @@
+2020-07-31  Brady Eidson  <[email protected]>
+
+        Special HID mapping for the Dualshock 3 controller
+        <rdar://problem/66255198> and https://bugs.webkit.org/show_bug.cgi?id=214911
+
+        Reviewed by Tim Horton.
+
+        Covered by API tests.
+
+        - Move GamepadButtons into a GamepadConstants header
+        - Add a "KnownGamepads" header to hold all vendor/product pairs that WebKit knows about
+        - Add a Dualshock3 controller mapping based on its HID report
+        - Add a basic DS3 test based on the HID report
+        
+        * Sources.txt:
+        * SourcesCocoa.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+
+        * platform/gamepad/GamepadConstants.cpp: Copied from Source/WebCore/platform/gamepad/mac/GenericHIDGamepad.h.
+        (WebCore::standardGamepadMappingString):
+        * platform/gamepad/GamepadConstants.h: Added.
+
+        * platform/gamepad/KnownGamepads.h: Copied from Source/WebCore/platform/gamepad/mac/GenericHIDGamepad.h.
+
+        * platform/gamepad/cocoa/GameControllerGamepad.mm:
+        (WebCore::GameControllerGamepad::setupAsExtendedGamepad):
+
+        * platform/gamepad/mac/Dualshock3HIDGamepad.cpp: Added.
+        (WebCore::Dualshock3HIDGamepad::Dualshock3HIDGamepad):
+        * platform/gamepad/mac/Dualshock3HIDGamepad.h: Copied from Source/WebCore/platform/gamepad/mac/GenericHIDGamepad.h.
+
+        * platform/gamepad/mac/GenericHIDGamepad.cpp:
+        (WebCore::GenericHIDGamepad::GenericHIDGamepad):
+        (WebCore::GenericHIDGamepad::id): Deleted.
+        * platform/gamepad/mac/GenericHIDGamepad.h:
+
+        * platform/gamepad/mac/HIDGamepad.cpp:
+        (WebCore::HIDGamepad::create):
+        (WebCore::HIDGamepad::HIDGamepad):
+        (WebCore::HIDGamepad::initialize):
+        * platform/gamepad/mac/HIDGamepad.h:
+
+        * platform/mac/HIDDevice.h:
+        (WebCore::HIDDevice::fullProductIdentifier const):
+        * platform/mac/HIDElement.h:
+        (WebCore::HIDElement::fullUsage const):
+
 2020-07-31  Alex Christensen  <[email protected]>
 
         Fix Windows build.

Modified: trunk/Source/WebCore/Sources.txt (265155 => 265156)


--- trunk/Source/WebCore/Sources.txt	2020-07-31 19:39:18 UTC (rev 265155)
+++ trunk/Source/WebCore/Sources.txt	2020-07-31 19:50:33 UTC (rev 265156)
@@ -1816,6 +1816,7 @@
 platform/encryptedmedia/CDMPrivate.cpp
 platform/encryptedmedia/CDMProxy.cpp
 platform/gamepad/EmptyGamepadProvider.cpp
+platform/gamepad/GamepadConstants.cpp
 platform/gamepad/GamepadProvider.cpp
 platform/graphics/ANGLEWebKitBridge.cpp
 platform/graphics/BitmapImage.cpp

Modified: trunk/Source/WebCore/SourcesCocoa.txt (265155 => 265156)


--- trunk/Source/WebCore/SourcesCocoa.txt	2020-07-31 19:39:18 UTC (rev 265155)
+++ trunk/Source/WebCore/SourcesCocoa.txt	2020-07-31 19:50:33 UTC (rev 265156)
@@ -257,6 +257,7 @@
 platform/cocoa/WebCoreNSErrorExtras.mm
 platform/gamepad/cocoa/GameControllerGamepad.mm
 platform/gamepad/cocoa/GameControllerGamepadProvider.mm
+platform/gamepad/mac/Dualshock3HIDGamepad.cpp
 platform/gamepad/mac/GenericHIDGamepad.cpp
 platform/gamepad/mac/HIDGamepad.cpp
 platform/gamepad/mac/HIDGamepadElement.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (265155 => 265156)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-07-31 19:39:18 UTC (rev 265155)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-07-31 19:50:33 UTC (rev 265156)
@@ -1402,6 +1402,9 @@
 		510A91DC24CF46FE00BFD89C /* SharedGamepadValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 510A91DB24CF441800BFD89C /* SharedGamepadValue.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		510A91EA24D004C300BFD89C /* HIDElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 510A91E324CFCC1800BFD89C /* HIDElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		510A91EB24D004C800BFD89C /* HIDDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = 510A91E224CFCC1800BFD89C /* HIDDevice.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		510A91F624D32DDC00BFD89C /* Dualshock3HIDGamepad.h in Headers */ = {isa = PBXBuildFile; fileRef = 510A91F424D324FF00BFD89C /* Dualshock3HIDGamepad.h */; };
+		510A91FD24D3C16200BFD89C /* GamepadConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 51715FE924CD05DD002C97E6 /* GamepadConstants.h */; };
+		510A91FE24D3C16700BFD89C /* GamepadConstantsMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 510A91FB24D3C0FD00BFD89C /* GamepadConstantsMac.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, ); }; };
@@ -8228,6 +8231,10 @@
 		510A91E524CFCC1800BFD89C /* HIDDevice.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HIDDevice.cpp; sourceTree = "<group>"; };
 		510A91E724CFEA1700BFD89C /* GenericHIDGamepad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GenericHIDGamepad.cpp; sourceTree = "<group>"; };
 		510A91E924CFEA3200BFD89C /* GenericHIDGamepad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GenericHIDGamepad.h; sourceTree = "<group>"; };
+		510A91F224D324C600BFD89C /* KnownGamepads.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KnownGamepads.h; sourceTree = "<group>"; };
+		510A91F424D324FF00BFD89C /* Dualshock3HIDGamepad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Dualshock3HIDGamepad.h; sourceTree = "<group>"; };
+		510A91F524D3250000BFD89C /* Dualshock3HIDGamepad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Dualshock3HIDGamepad.cpp; sourceTree = "<group>"; };
+		510A91FB24D3C0FD00BFD89C /* GamepadConstantsMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GamepadConstantsMac.h; 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>"; };
@@ -19668,6 +19675,7 @@
 				515BE18A1D54F5F600DD7C68 /* GamepadProvider.cpp */,
 				515BE18B1D54F5F600DD7C68 /* GamepadProvider.h */,
 				515BE18C1D54F5F600DD7C68 /* GamepadProviderClient.h */,
+				510A91F224D324C600BFD89C /* KnownGamepads.h */,
 				515BE18E1D54F5F600DD7C68 /* PlatformGamepad.h */,
 				510A91DB24CF441800BFD89C /* SharedGamepadValue.h */,
 			);
@@ -19677,6 +19685,9 @@
 		515BE1961D54F64500DD7C68 /* mac */ = {
 			isa = PBXGroup;
 			children = (
+				510A91F524D3250000BFD89C /* Dualshock3HIDGamepad.cpp */,
+				510A91F424D324FF00BFD89C /* Dualshock3HIDGamepad.h */,
+				510A91FB24D3C0FD00BFD89C /* GamepadConstantsMac.h */,
 				510A91E724CFEA1700BFD89C /* GenericHIDGamepad.cpp */,
 				510A91E924CFEA3200BFD89C /* GenericHIDGamepad.h */,
 				515BE1971D54F6BD00DD7C68 /* HIDGamepad.cpp */,
@@ -30765,6 +30776,7 @@
 				A7CFB3D20B7ED10A0070C32D /* DragImage.h in Headers */,
 				1AF5E4D91E5677A9004A1F01 /* DragItem.h in Headers */,
 				81F65FF613788FAA00FF6F2D /* DragState.h in Headers */,
+				510A91F624D32DDC00BFD89C /* Dualshock3HIDGamepad.h in Headers */,
 				E1BA66F11742BD8600C20251 /* DynamicLinkerInterposing.h in Headers */,
 				FD6ED2C8136B8E66003CF072 /* DynamicsCompressor.h in Headers */,
 				FD537357137B653B00008DCE /* DynamicsCompressorKernel.h in Headers */,
@@ -30990,6 +31002,8 @@
 				FD31600D12B0267600C1A359 /* GainNode.h in Headers */,
 				51E399001D6E4750009C8831 /* GameControllerGamepad.h in Headers */,
 				51E399021D6E4750009C8831 /* GameControllerGamepadProvider.h in Headers */,
+				510A91FD24D3C16200BFD89C /* GamepadConstants.h in Headers */,
+				510A91FE24D3C16700BFD89C /* GamepadConstantsMac.h in Headers */,
 				516C62211950D48700337E75 /* GamepadEvent.h in Headers */,
 				51A9D9EA195B931F001B2B5C /* GamepadManager.h in Headers */,
 				515BE1921D54F5FB00DD7C68 /* GamepadProvider.h in Headers */,

Copied: trunk/Source/WebCore/platform/gamepad/GamepadConstants.cpp (from rev 265155, trunk/Source/WebCore/platform/gamepad/mac/GenericHIDGamepad.h) (0 => 265156)


--- trunk/Source/WebCore/platform/gamepad/GamepadConstants.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/gamepad/GamepadConstants.cpp	2020-07-31 19:50:33 UTC (rev 265156)
@@ -0,0 +1,49 @@
+/*
+ * 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 "GamepadConstants.h"
+
+#if ENABLE(GAMEPAD)
+
+#import <wtf/NeverDestroyed.h>
+#import <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+const GamepadButtonRole maximumGamepadButton = GamepadButtonRole::CenterClusterCenter;
+const size_t numberOfStandardGamepadButtonsWithoutHomeButton = static_cast<size_t>(maximumGamepadButton);
+const size_t numberOfStandardGamepadButtonsWithHomeButton = numberOfStandardGamepadButtonsWithoutHomeButton + 1;
+
+const WTF::String& standardGamepadMappingString()
+{
+    static NeverDestroyed<String> standardGamepadMapping = "standard";
+    return standardGamepadMapping;
+}
+
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD)

Copied: trunk/Source/WebCore/platform/gamepad/GamepadConstants.h (from rev 265155, trunk/Source/WebCore/platform/mac/HIDElement.h) (0 => 265156)


--- trunk/Source/WebCore/platform/gamepad/GamepadConstants.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/gamepad/GamepadConstants.h	2020-07-31 19:50:33 UTC (rev 265156)
@@ -0,0 +1,66 @@
+/*
+ * 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)
+
+namespace WTF {
+class String;
+};
+
+namespace WebCore {
+
+// Buttons in the "standard" gamepad layout in the Web Gamepad spec
+// https://www.w3.org/TR/gamepad/#dfn-standard-gamepad-layout
+enum class GamepadButtonRole : uint8_t {
+    RightClusterBottom = 0,
+    RightClusterRight = 1,
+    RightClusterLeft = 2,
+    RightClusterTop = 3,
+    LeftShoulderFront = 4,
+    RightShoulderFront = 5,
+    LeftShoulderBack = 6,
+    RightShoulderBack = 7,
+    CenterClusterLeft = 8,
+    CenterClusterRight = 9,
+    LeftStick = 10,
+    RightStick = 11,
+    LeftClusterTop = 12,
+    LeftClusterBottom = 13,
+    LeftClusterLeft = 14,
+    LeftClusterRight = 15,
+    CenterClusterCenter = 16,
+};
+
+extern const size_t numberOfStandardGamepadButtonsWithoutHomeButton;
+extern const size_t numberOfStandardGamepadButtonsWithHomeButton;
+extern const GamepadButtonRole maximumGamepadButton;
+
+const WTF::String& standardGamepadMappingString();
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD)

Copied: trunk/Source/WebCore/platform/gamepad/KnownGamepads.h (from rev 265155, trunk/Source/WebCore/platform/gamepad/mac/GenericHIDGamepad.h) (0 => 265156)


--- trunk/Source/WebCore/platform/gamepad/KnownGamepads.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/gamepad/KnownGamepads.h	2020-07-31 19:50:33 UTC (rev 265156)
@@ -0,0 +1,51 @@
+/*
+ * 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)
+
+namespace WebCore {
+
+enum KnownGamepad {
+    Nimbus1 = 0x01111420,
+    Nimbus2 = 0x10381420,
+    StratusXL1 = 0x01111418,
+    StratusXL2 = 0x10381418,
+    StratusXL3 = 0x01111419,
+    StratusXL4 = 0x10381419,
+    HoripadUltimate = 0x0f0d0090,
+    GamesirM2 = 0x0ec20475,
+    XboxOne1 = 0x045e02e0,
+    XboxOne2 = 0x045e02ea,
+    XboxOne3 = 0x045e02fd,
+    Dualshock3 = 0x054c0268,
+    Dualshock4_1 = 0x054c05c4,
+    Dualshock4_2 = 0x054c09cc,
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD)

Modified: trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.mm (265155 => 265156)


--- trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.mm	2020-07-31 19:39:18 UTC (rev 265155)
+++ trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.mm	2020-07-31 19:50:33 UTC (rev 265156)
@@ -27,36 +27,13 @@
 
 #if ENABLE(GAMEPAD)
 #import "GameControllerGamepadProvider.h"
-#import "GameControllerSoftLink.h"
+#import "GamepadConstants.h"
 #import <GameController/GameController.h>
 
+#import "GameControllerSoftLink.h"
+
 namespace WebCore {
 
-// Buttons in the "standard" gamepad layout in the Web Gamepad spec
-// https://www.w3.org/TR/gamepad/#dfn-standard-gamepad-layout
-enum class GamepadButtons : uint8_t {
-    RightClusterBottom = 0,
-    RightClusterRight = 1,
-    RightClusterLeft = 2,
-    RightClusterTop = 3,
-    LeftShoulderFront = 4,
-    RightShoulderFront = 5,
-    LeftShoulderBack = 6,
-    RightShoulderBack = 7,
-    CenterClusterLeft = 8,
-    CenterClusterRight = 9,
-    LeftStick = 10,
-    RightStick = 11,
-    LeftClusterTop = 12,
-    LeftClusterBottom = 13,
-    LeftClusterLeft = 14,
-    LeftClusterRight = 15,
-    CenterClusterCenter = 16,
-};
-
-static constexpr auto numGamepadButtonsWithoutHomeButton = static_cast<size_t>(GamepadButtons::CenterClusterCenter);
-static constexpr auto numGamepadButtonsWithHomeButton = static_cast<size_t>(GamepadButtons::CenterClusterCenter) + 1;
-
 GameControllerGamepad::GameControllerGamepad(GCController *controller, unsigned index)
     : PlatformGamepad(index)
     , m_gcController(controller)
@@ -98,10 +75,10 @@
     ASSERT(m_extendedGamepad);
 
     m_id = makeString(String(m_gcController.get().vendorName), " Extended Gamepad"_s);
-    m_mapping = String("standard");
+    m_mapping = standardGamepadMappingString();
 
     auto *homeButton = homeButtonFromExtendedGamepad(m_extendedGamepad.get());
-    m_buttonValues.resize(homeButton ? numGamepadButtonsWithHomeButton : numGamepadButtonsWithoutHomeButton);
+    m_buttonValues.resize(homeButton ? numberOfStandardGamepadButtonsWithHomeButton : numberOfStandardGamepadButtonsWithoutHomeButton);
 
     m_extendedGamepad.get().valueChangedHandler = ^(GCExtendedGamepad *, GCControllerElement *) {
         m_lastUpdateTime = MonotonicTime::now();
@@ -109,7 +86,7 @@
         m_hadButtonPresses = false;
     };
 
-    auto bindButton = ^(GCControllerButtonInput *button, GamepadButtons index) {
+    auto bindButton = ^(GCControllerButtonInput *button, GamepadButtonRole index) {
         m_buttonValues[(size_t)index].setValue(button.value);
         button.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
             m_buttonValues[(size_t)index].setValue(value);
@@ -119,30 +96,30 @@
     };
 
     // Button Pad
-    bindButton(m_extendedGamepad.get().buttonA, GamepadButtons::RightClusterBottom);
-    bindButton(m_extendedGamepad.get().buttonB, GamepadButtons::RightClusterRight);
-    bindButton(m_extendedGamepad.get().buttonX, GamepadButtons::RightClusterLeft);
-    bindButton(m_extendedGamepad.get().buttonY, GamepadButtons::RightClusterTop);
+    bindButton(m_extendedGamepad.get().buttonA, GamepadButtonRole::RightClusterBottom);
+    bindButton(m_extendedGamepad.get().buttonB, GamepadButtonRole::RightClusterRight);
+    bindButton(m_extendedGamepad.get().buttonX, GamepadButtonRole::RightClusterLeft);
+    bindButton(m_extendedGamepad.get().buttonY, GamepadButtonRole::RightClusterTop);
 
     // Shoulders, Triggers
-    bindButton(m_extendedGamepad.get().leftShoulder, GamepadButtons::LeftShoulderFront);
-    bindButton(m_extendedGamepad.get().rightShoulder, GamepadButtons::RightShoulderFront);
-    bindButton(m_extendedGamepad.get().leftTrigger, GamepadButtons::LeftShoulderBack);
-    bindButton(m_extendedGamepad.get().rightTrigger, GamepadButtons::RightShoulderBack);
+    bindButton(m_extendedGamepad.get().leftShoulder, GamepadButtonRole::LeftShoulderFront);
+    bindButton(m_extendedGamepad.get().rightShoulder, GamepadButtonRole::RightShoulderFront);
+    bindButton(m_extendedGamepad.get().leftTrigger, GamepadButtonRole::LeftShoulderBack);
+    bindButton(m_extendedGamepad.get().rightTrigger, GamepadButtonRole::RightShoulderBack);
 
     // D Pad
-    bindButton(m_extendedGamepad.get().dpad.up, GamepadButtons::LeftClusterTop);
-    bindButton(m_extendedGamepad.get().dpad.down, GamepadButtons::LeftClusterBottom);
-    bindButton(m_extendedGamepad.get().dpad.left, GamepadButtons::LeftClusterLeft);
-    bindButton(m_extendedGamepad.get().dpad.right, GamepadButtons::LeftClusterRight);
+    bindButton(m_extendedGamepad.get().dpad.up, GamepadButtonRole::LeftClusterTop);
+    bindButton(m_extendedGamepad.get().dpad.down, GamepadButtonRole::LeftClusterBottom);
+    bindButton(m_extendedGamepad.get().dpad.left, GamepadButtonRole::LeftClusterLeft);
+    bindButton(m_extendedGamepad.get().dpad.right, GamepadButtonRole::LeftClusterRight);
 
     if (homeButton)
-        bindButton(homeButton, GamepadButtons::CenterClusterCenter);
+        bindButton(homeButton, GamepadButtonRole::CenterClusterCenter);
 
     // Select, Start
 #if HAVE(GCEXTENDEDGAMEPAD_BUTTONS_OPTIONS_MENU)
-    bindButton(m_extendedGamepad.get().buttonOptions, GamepadButtons::CenterClusterLeft);
-    bindButton(m_extendedGamepad.get().buttonMenu, GamepadButtons::CenterClusterRight);
+    bindButton(m_extendedGamepad.get().buttonOptions, GamepadButtonRole::CenterClusterLeft);
+    bindButton(m_extendedGamepad.get().buttonMenu, GamepadButtonRole::CenterClusterRight);
 #endif
 
     // L3, R3
@@ -151,8 +128,8 @@
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wunguarded-availability"
     if ([m_extendedGamepad.get() respondsToSelector:@selector(leftThumbstickButton)]) {
-        bindButton(m_extendedGamepad.get().leftThumbstickButton, GamepadButtons::LeftStick);
-        bindButton(m_extendedGamepad.get().rightThumbstickButton, GamepadButtons::RightStick);
+        bindButton(m_extendedGamepad.get().leftThumbstickButton, GamepadButtonRole::LeftStick);
+        bindButton(m_extendedGamepad.get().rightThumbstickButton, GamepadButtonRole::RightStick);
     }
 #pragma clang diagnostic pop
 #endif

Modified: trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.mm (265155 => 265156)


--- trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.mm	2020-07-31 19:39:18 UTC (rev 265155)
+++ trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.mm	2020-07-31 19:50:33 UTC (rev 265156)
@@ -30,6 +30,7 @@
 
 #import "GameControllerGamepad.h"
 #import "GamepadProviderClient.h"
+#import "KnownGamepads.h"
 #import "Logging.h"
 #import <GameController/GameController.h>
 #import <pal/spi/mac/IOKitSPIMac.h>
@@ -44,42 +45,27 @@
 {
     // Check the vendor/product IDs agains a hard coded list of controllers we expect to work well with
     // GameController.framework on 10.15.
-    enum GameControllerCompatible {
-        Nimbus1 = 0x01111420,
-        Nimbus2 = 0x10381420,
-        StratusXL1 = 0x01111418,
-        StratusXL2 = 0x10381418,
-        StratusXL3 = 0x01111419,
-        StratusXL4 = 0x10381419,
-        HoripadUltimate = 0x0f0d0090,
-        GamesirM2 = 0x0ec20475,
-        XboxOne1 = 0x045e02e0,
-        XboxOne2 = 0x045e02ea,
-        XboxOne3 = 0x045e02fd,
-        Dualshock4_1 = 0x054c05c4,
-        Dualshock4_2 = 0x054c09cc,
-    };
+    static NeverDestroyed<HashSet<uint32_t>> gameControllerCompatibleGamepads;
 
-    GameControllerCompatible fullProductID = (GameControllerCompatible)((vendorID << 16) | (productID & 0xFFFF));
+    static std::once_flag onceFlag;
+    std::call_once(onceFlag, [] {
+        gameControllerCompatibleGamepads->add(Nimbus1);
+        gameControllerCompatibleGamepads->add(Nimbus2);
+        gameControllerCompatibleGamepads->add(StratusXL1);
+        gameControllerCompatibleGamepads->add(StratusXL2);
+        gameControllerCompatibleGamepads->add(StratusXL3);
+        gameControllerCompatibleGamepads->add(StratusXL4);
+        gameControllerCompatibleGamepads->add(HoripadUltimate);
+        gameControllerCompatibleGamepads->add(GamesirM2);
+        gameControllerCompatibleGamepads->add(XboxOne1);
+        gameControllerCompatibleGamepads->add(XboxOne2);
+        gameControllerCompatibleGamepads->add(XboxOne3);
+        gameControllerCompatibleGamepads->add(Dualshock4_1);
+        gameControllerCompatibleGamepads->add(Dualshock4_2);
+    });
 
-    switch (fullProductID) {
-    case Nimbus1:
-    case Nimbus2:
-    case StratusXL1:
-    case StratusXL2:
-    case StratusXL3:
-    case StratusXL4:
-    case HoripadUltimate:
-    case GamesirM2:
-    case XboxOne1:
-    case XboxOne2:
-    case XboxOne3:
-    case Dualshock4_1:
-    case Dualshock4_2:
-        return true;
-    default:
-        return false;
-    }
+    uint32_t fullProductID = (((uint32_t)vendorID) << 16) | productID;
+    return gameControllerCompatibleGamepads->contains(fullProductID);
 }
 #endif // !HAVE(GCCONTROLLER_HID_DEVICE_CHECK)
 

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


--- trunk/Source/WebCore/platform/gamepad/mac/Dualshock3HIDGamepad.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/gamepad/mac/Dualshock3HIDGamepad.cpp	2020-07-31 19:50:33 UTC (rev 265156)
@@ -0,0 +1,121 @@
+/*
+ * 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 "Dualshock3HIDGamepad.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 {
+
+Dualshock3HIDGamepad::Dualshock3HIDGamepad(HIDDevice&& device, unsigned index)
+    : HIDGamepad(WTFMove(device), index)
+{
+    LOG(Gamepad, "Creating Dualshock3HIDGamepad %p", this);
+
+    m_mapping = standardGamepadMappingString();
+
+    for (size_t i = 0; i < numberOfStandardGamepadButtonsWithHomeButton; ++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();
+
+    Vector<HIDElement> pointerElements;
+
+    auto mapButton = [this] (HIDElement& element, GamepadButtonRole role) {
+        m_elementMap.set(element.cookie(), makeUnique<HIDGamepadButton>(element, m_buttonValues[(size_t)role]));
+    };
+
+    // Look specifically for the axes and digital buttons
+    for (auto& element : inputElements) {
+        switch (element.fullUsage()) {
+        case hidPointerFullUsage:
+            pointerElements.append(element);
+            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::CenterClusterLeft);
+            break;
+        case hidButton2FullUsage:
+            mapButton(element, GamepadButtonRole::LeftStick);
+            break;
+        case hidButton3FullUsage:
+            mapButton(element, GamepadButtonRole::RightStick);
+            break;
+        case hidButton4FullUsage:
+            mapButton(element, GamepadButtonRole::CenterClusterRight);
+            break;
+        case hidButton17FullUsage:
+            mapButton(element, GamepadButtonRole::CenterClusterCenter);
+            break;
+        default:
+            break;
+        }
+    }
+
+    const size_t expectedGenericPointerElements = 40;
+    if (pointerElements.size() != expectedGenericPointerElements) {
+        LOG(Gamepad, "Dualshock3 controller was expected to have %lu generic pointer elements, has %lu instead", expectedGenericPointerElements, pointerElements.size());
+        return;
+    }
+
+    mapButton(pointerElements[5], GamepadButtonRole::LeftClusterTop);
+    mapButton(pointerElements[6], GamepadButtonRole::LeftClusterRight);
+    mapButton(pointerElements[7], GamepadButtonRole::LeftClusterBottom);
+    mapButton(pointerElements[8], GamepadButtonRole::LeftClusterLeft);
+    mapButton(pointerElements[9], GamepadButtonRole::LeftShoulderBack);
+    mapButton(pointerElements[10], GamepadButtonRole::RightShoulderBack);
+    mapButton(pointerElements[11], GamepadButtonRole::LeftShoulderFront);
+    mapButton(pointerElements[12], GamepadButtonRole::RightShoulderFront);
+    mapButton(pointerElements[13], GamepadButtonRole::RightClusterTop);
+    mapButton(pointerElements[14], GamepadButtonRole::RightClusterRight);
+    mapButton(pointerElements[15], GamepadButtonRole::RightClusterBottom);
+    mapButton(pointerElements[16], GamepadButtonRole::RightClusterLeft);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD) && PLATFORM(MAC)

Copied: trunk/Source/WebCore/platform/gamepad/mac/Dualshock3HIDGamepad.h (from rev 265155, trunk/Source/WebCore/platform/gamepad/mac/GenericHIDGamepad.h) (0 => 265156)


--- trunk/Source/WebCore/platform/gamepad/mac/Dualshock3HIDGamepad.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/gamepad/mac/Dualshock3HIDGamepad.h	2020-07-31 19:50:33 UTC (rev 265156)
@@ -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 Dualshock3HIDGamepad final : public HIDGamepad {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    Dualshock3HIDGamepad(HIDDevice&&, unsigned index);
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD) && PLATFORM(MAC)

Copied: trunk/Source/WebCore/platform/gamepad/mac/GamepadConstantsMac.h (from rev 265155, trunk/Source/WebCore/platform/gamepad/mac/GenericHIDGamepad.h) (0 => 265156)


--- trunk/Source/WebCore/platform/gamepad/mac/GamepadConstantsMac.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/gamepad/mac/GamepadConstantsMac.h	2020-07-31 19:50:33 UTC (rev 265156)
@@ -0,0 +1,47 @@
+/*
+ * 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)
+
+#import <IOKit/hid/IOHIDUsageTables.h>
+
+namespace WebCore {
+
+constexpr const uint64_t hidPointerFullUsage = ((uint64_t)kHIDPage_GenericDesktop) << 32 | kHIDUsage_GD_Pointer;
+constexpr const uint64_t hidXAxisFullUsage = ((uint64_t)kHIDPage_GenericDesktop) << 32 | kHIDUsage_GD_X;
+constexpr const uint64_t hidYAxisFullUsage = ((uint64_t)kHIDPage_GenericDesktop) << 32 | kHIDUsage_GD_Y;
+constexpr const uint64_t hidZAxisFullUsage = ((uint64_t)kHIDPage_GenericDesktop) << 32 | kHIDUsage_GD_Z;
+constexpr const uint64_t hidRzAxisFullUsage = ((uint64_t)kHIDPage_GenericDesktop) << 32 | kHIDUsage_GD_Rz;
+constexpr const uint64_t hidButton1FullUsage = ((uint64_t)kHIDPage_Button) << 32 | kHIDUsage_Button_1;
+constexpr const uint64_t hidButton2FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 1);
+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 hidButton17FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 16);
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD) && PLATFORM(MAC)

Modified: trunk/Source/WebCore/platform/gamepad/mac/GenericHIDGamepad.cpp (265155 => 265156)


--- trunk/Source/WebCore/platform/gamepad/mac/GenericHIDGamepad.cpp	2020-07-31 19:39:18 UTC (rev 265155)
+++ trunk/Source/WebCore/platform/gamepad/mac/GenericHIDGamepad.cpp	2020-07-31 19:50:33 UTC (rev 265156)
@@ -36,6 +36,8 @@
 GenericHIDGamepad::GenericHIDGamepad(HIDDevice&& device, unsigned index)
     : HIDGamepad(WTFMove(device), index)
 {
+    LOG(Gamepad, "Creating GenericHIDGamepad %p", this);
+
     auto inputElements = hidDevice().uniqueInputElementsInDeviceTreeOrder();
 
     for (auto& element : inputElements) {
@@ -52,13 +54,6 @@
     }
 }
 
-String GenericHIDGamepad::id()
-{
-    // Currently the spec has no formatting for the id string.
-    // This string formatting matches Firefox.
-    return makeString(hex(hidDevice().vendorID(), Lowercase), '-', hex(hidDevice().productID(), Lowercase), '-', hidDevice().productName());
-}
-
 void GenericHIDGamepad::maybeAddGenericDesktopElement(HIDElement& element)
 {
     switch (element.usage()) {

Modified: trunk/Source/WebCore/platform/gamepad/mac/GenericHIDGamepad.h (265155 => 265156)


--- trunk/Source/WebCore/platform/gamepad/mac/GenericHIDGamepad.h	2020-07-31 19:39:18 UTC (rev 265155)
+++ trunk/Source/WebCore/platform/gamepad/mac/GenericHIDGamepad.h	2020-07-31 19:50:33 UTC (rev 265156)
@@ -36,8 +36,6 @@
     GenericHIDGamepad(HIDDevice&&, unsigned index);
 
 private:
-    String id() final;
-
     void maybeAddGenericDesktopElement(HIDElement&);
     void maybeAddButtonElement(HIDElement&);
 };

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


--- trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.cpp	2020-07-31 19:39:18 UTC (rev 265155)
+++ trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.cpp	2020-07-31 19:50:33 UTC (rev 265156)
@@ -28,7 +28,9 @@
 
 #if ENABLE(GAMEPAD) && PLATFORM(MAC)
 
+#include "Dualshock3HIDGamepad.h"
 #include "GenericHIDGamepad.h"
+#include "KnownGamepads.h"
 #include "Logging.h"
 #include <IOKit/hid/IOHIDElement.h>
 #include <IOKit/hid/IOHIDUsageTables.h>
@@ -42,12 +44,18 @@
 {
     auto device = HIDDevice { rawDevice };
 
-    // When we support specific mapping for a particular device, here is where we'll decide what kind of HIDGamepad to make.
-    // For now, it's only the GenericHIDGamepad
-    auto newGamepad = makeUnique<GenericHIDGamepad>(WTFMove(device), index);
+    std::unique_ptr<HIDGamepad> newGamepad;
 
+    switch ((KnownGamepad)device.fullProductIdentifier()) {
+    case Dualshock3:
+        newGamepad = makeUnique<Dualshock3HIDGamepad>(WTFMove(device), index);
+        break;
+    default:
+        newGamepad = makeUnique<GenericHIDGamepad>(WTFMove(device), index);
+    }
+
     newGamepad->initialize();
-    return WTFMove(newGamepad);
+    return newGamepad;
 }
 
 HIDGamepad::HIDGamepad(HIDDevice&& device, unsigned index)
@@ -55,12 +63,14 @@
     , m_device(WTFMove(device))
 {
     m_connectTime = m_lastUpdateTime = MonotonicTime::now();
+
+    // Currently the spec has no formatting for the id string.
+    // This string formatting matches Firefox.
+    m_id = makeString(hex(m_device.vendorID(), Lowercase), '-', hex(m_device.productID(), Lowercase), '-', m_device.productName());
 }
 
 void HIDGamepad::initialize()
 {
-    m_id = id();
-
     for (auto& element : m_elementMap.values())
         element->refreshCurrentValue();
 }

Modified: trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.h (265155 => 265156)


--- trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.h	2020-07-31 19:39:18 UTC (rev 265155)
+++ trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.h	2020-07-31 19:50:33 UTC (rev 265156)
@@ -52,8 +52,6 @@
 protected:
     HIDGamepad(HIDDevice&&, unsigned index);
 
-    virtual String id() = 0;
-
     HashMap<IOHIDElementCookie, std::unique_ptr<HIDGamepadElement>> m_elementMap;
     Vector<SharedGamepadValue> m_buttonValues;
     Vector<SharedGamepadValue> m_axisValues;

Modified: trunk/Source/WebCore/platform/mac/HIDDevice.h (265155 => 265156)


--- trunk/Source/WebCore/platform/mac/HIDDevice.h	2020-07-31 19:39:18 UTC (rev 265155)
+++ trunk/Source/WebCore/platform/mac/HIDDevice.h	2020-07-31 19:50:33 UTC (rev 265156)
@@ -50,6 +50,7 @@
 
     uint16_t vendorID() const { return m_vendorID; }
     uint16_t productID() const { return m_productID; }
+    uint32_t fullProductIdentifier() const { return m_vendorID << 16 | m_productID; }
     const String& productName() const { return m_productName; }
 
 private:

Modified: trunk/Source/WebCore/platform/mac/HIDElement.h (265155 => 265156)


--- trunk/Source/WebCore/platform/mac/HIDElement.h	2020-07-31 19:39:18 UTC (rev 265155)
+++ trunk/Source/WebCore/platform/mac/HIDElement.h	2020-07-31 19:50:33 UTC (rev 265156)
@@ -44,6 +44,7 @@
     CFIndex physicalValue() const { return m_physicalValue; }
     uint32_t usage() const { return m_usage; }
     uint32_t usagePage() const { return m_usagePage; }
+    uint64_t fullUsage() const { return ((uint64_t)m_usagePage) << 32 | m_usage; }
     IOHIDElementCookie cookie() const { return m_cookie; }
 
     void valueChanged(IOHIDValueRef);

Modified: trunk/Tools/ChangeLog (265155 => 265156)


--- trunk/Tools/ChangeLog	2020-07-31 19:39:18 UTC (rev 265155)
+++ trunk/Tools/ChangeLog	2020-07-31 19:50:33 UTC (rev 265156)
@@ -1,3 +1,19 @@
+2020-07-31  Brady Eidson  <[email protected]>
+
+        Special HID mapping for the Dualshock 3 controller
+        <rdar://problem/66255198> and https://bugs.webkit.org/show_bug.cgi?id=214911
+
+        Reviewed by Tim Horton.
+
+        Add a virtual Dualshock3 and verify a few attributes about it.
+        
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/mac/HIDGamepads.mm:
+        * TestWebKitAPI/mac/GamepadMappings/SonyDualShock3.mm: Added.
+        (TestWebKitAPI::publishReportCallback):
+        (TestWebKitAPI::VirtualGamepad::sonyDualshock3Mapping):
+        * TestWebKitAPI/mac/VirtualGamepad.h:
+
 2020-07-31  Youenn Fablet  <[email protected]>
 
         Update service worker if certificate info does not match when soft updating

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (265155 => 265156)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-07-31 19:39:18 UTC (rev 265155)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-07-31 19:50:33 UTC (rev 265156)
@@ -276,6 +276,7 @@
 		510477741D298DDD009747EB /* IDBDeleteRecovery.sqlite3-wal in Copy Resources */ = {isa = PBXBuildFile; fileRef = 510477711D298D85009747EB /* IDBDeleteRecovery.sqlite3-wal */; };
 		510477771D298E72009747EB /* IDBDeleteRecovery.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 510477761D298E57009747EB /* IDBDeleteRecovery.html */; };
 		510477781D29923B009747EB /* IDBDeleteRecovery.mm in Sources */ = {isa = PBXBuildFile; fileRef = 510477751D298E03009747EB /* IDBDeleteRecovery.mm */; };
+		510A91F824D3622100BFD89C /* SonyDualShock3.mm in Sources */ = {isa = PBXBuildFile; fileRef = 510A91F724D3621900BFD89C /* SonyDualShock3.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 */; };
@@ -1971,6 +1972,7 @@
 		510477711D298D85009747EB /* IDBDeleteRecovery.sqlite3-wal */ = {isa = PBXFileReference; lastKnownFileType = file; path = "IDBDeleteRecovery.sqlite3-wal"; sourceTree = "<group>"; };
 		510477751D298E03009747EB /* IDBDeleteRecovery.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = IDBDeleteRecovery.mm; sourceTree = "<group>"; };
 		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>"; };
 		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>"; };
@@ -3468,6 +3470,7 @@
 			children = (
 				51EB126024CA6B5F000CB030 /* MicrosoftXboxOne.mm */,
 				51EB125E24CA6B5F000CB030 /* ShenzhenLongshengweiTechnologyGamepad.mm */,
+				510A91F724D3621900BFD89C /* SonyDualShock3.mm */,
 				51EB125F24CA6B5F000CB030 /* SonyDualShock4.mm */,
 				51EB126124CA6B5F000CB030 /* SteelSeriesNimbus.mm */,
 				51EB126624CB8493000CB030 /* SunLightApplicationGenericNES.mm */,
@@ -5317,6 +5320,7 @@
 				C149D550242E98DF003EBB12 /* SleepDisabler.mm in Sources */,
 				2DFF7B6D1DA487AF00814614 /* SnapshotStore.mm in Sources */,
 				0F4FFA9E1ED3AA8500F7111F /* SnapshotViaRenderInContext.mm in Sources */,
+				510A91F824D3622100BFD89C /* SonyDualShock3.mm in Sources */,
 				51EB126424CA6B66000CB030 /* SonyDualShock4.mm in Sources */,
 				7CCE7F151A411AE600447C4C /* SpacebarScrolling.cpp in Sources */,
 				57F4AAA0208FAEF000A68E9E /* SSLKeyGenerator.mm in Sources */,

Modified: trunk/Tools/TestWebKitAPI/Tests/mac/HIDGamepads.mm (265155 => 265156)


--- trunk/Tools/TestWebKitAPI/Tests/mac/HIDGamepads.mm	2020-07-31 19:39:18 UTC (rev 265155)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/HIDGamepads.mm	2020-07-31 19:50:33 UTC (rev 265156)
@@ -358,6 +358,69 @@
     EXPECT_TRUE([messageHandler.get().messages[1] isEqualToString:@"Disconnect: \"79-11-Virtual Shenzhen Longshengwei Technology Gamepad\""]);
 }
 
+TEST(Gamepad, Dualshock3Basic)
+{
+    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 gamepad = makeUnique<VirtualGamepad>(VirtualGamepad::sonyDualshock3Mapping());
+    while (![webView.get().configuration.processPool _numberOfConnectedGamepadsForTesting])
+        Util::sleep(0.01);
+
+    EXPECT_EQ([webView.get().configuration.processPool _numberOfConnectedHIDGamepadsForTesting], 1u);
+    EXPECT_EQ([webView.get().configuration.processPool _numberOfConnectedGameControllerFrameworkGamepadsForTesting], 0u);
+
+    gamepad->setButtonValue(0, 0.75);
+    gamepad->publishReport();
+
+    // Wait for the page to tell us a gamepad connected
+    Util::run(&didReceiveMessage);
+    didReceiveMessage = false;
+
+    EXPECT_EQ(messageHandler.get().messages.size(), 1u);
+    EXPECT_TRUE([messageHandler.get().messages[0] isEqualToString:@"\"54c-268-Virtual Dualshock3\""]);
+
+    bool done = false;
+    auto resultBlock = [&] (id result, NSError *error) {
+        EXPECT_NULL(error);
+        EXPECT_TRUE([result[@"gamepadCount"] isEqualToNumber:@(1)]);
+        EXPECT_EQ(((NSArray *)result[@"gamepadButtons"][0]).count, 17u);
+        EXPECT_EQ(((NSArray *)result[@"gamepadAxes"][0]).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/SonyDualShock3.mm (0 => 265156)


--- trunk/Tools/TestWebKitAPI/mac/GamepadMappings/SonyDualShock3.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/mac/GamepadMappings/SonyDualShock3.mm	2020-07-31 19:50:33 UTC (rev 265156)
@@ -0,0 +1,204 @@
+/*
+ * 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 Dualshock3Descriptor[] = {
+    0x05, 0x01,        // Usage Page (Generic Desktop Ctrls)
+    0x09, 0x04,        // Usage (Joystick)
+    0xA1, 0x01,        // Collection (Application)
+    0xA1, 0x02,        //   Collection (Logical)
+                       //     Report ID - Total (1) byte
+    0x85, 0x01,        //     Report ID (1)
+    0x75, 0x08,        //     Report Size (8)
+    0x95, 0x01,        //     Report Count (1)
+    0x15, 0x00,        //     Logical Minimum (0)
+    0x26, 0xFF, 0x00,  //     Logical Maximum (255)
+                       //     (1) byte report for unknown pointer - Total (2) bytes
+    0x81, 0x03,        //     Input (Const,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
+    0x75, 0x01,        //     Report Size (1)
+    0x95, 0x13,        //     Report Count (19)
+    0x15, 0x00,        //     Logical Minimum (0)
+    0x25, 0x01,        //     Logical Maximum (1)
+    0x35, 0x00,        //     Physical Minimum (0)
+    0x45, 0x01,        //     Physical Maximum (1)
+    0x05, 0x09,        //     Usage Page (Button)
+    0x19, 0x01,        //     Usage Minimum (0x01)
+    0x29, 0x13,        //     Usage Maximum (0x13)
+                       //     (19) bits for digital buttons - Total (4) bytes (3) bits
+    0x81, 0x02,        //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
+    0x75, 0x01,        //     Report Size (1)
+    0x95, 0x0D,        //     Report Count (13)
+    0x06, 0x00, 0xFF,  //     Usage Page (Vendor Defined 0xFF00)
+                       //     (13) bits padding - Total (6) bytes
+    0x81, 0x03,        //     Input (Const,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
+    0x15, 0x00,        //     Logical Minimum (0)
+    0x26, 0xFF, 0x00,  //     Logical Maximum (255)
+    0x05, 0x01,        //     Usage Page (Generic Desktop Ctrls)
+    0x09, 0x01,        //     Usage (Pointer)
+    0xA1, 0x00,        //     Collection (Physical)
+    0x75, 0x08,        //       Report Size (8)
+    0x95, 0x04,        //       Report Count (4)
+    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 at 1 byte each - Total (10) bytes
+    0x81, 0x02,        //       Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
+    0xC0,              //     End Collection
+    0x05, 0x01,        //     Usage Page (Generic Desktop Ctrls)
+    0x75, 0x08,        //     Report Size (8)
+    0x95, 0x27,        //     Report Count (39)
+    0x09, 0x01,        //     Usage (Pointer)
+                       //     (39) pointers at 1 byte each - Total (49) bytes
+    0x81, 0x02,        //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
+    0x75, 0x08,        //     Report Size (8)
+    0x95, 0x30,        //     Report Count (48)
+    0x09, 0x01,        //     Usage (Pointer)
+    0x91, 0x02,        //     Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
+    0x75, 0x08,        //     Report Size (8)
+    0x95, 0x30,        //     Report Count (48)
+    0x09, 0x01,        //     Usage (Pointer)
+    0xB1, 0x02,        //     Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
+    0xC0,              //   End Collection
+    0xA1, 0x02,        //   Collection (Logical)
+    0x85, 0x02,        //     Report ID (2)
+    0x75, 0x08,        //     Report Size (8)
+    0x95, 0x30,        //     Report Count (48)
+    0x09, 0x01,        //     Usage (Pointer)
+    0xB1, 0x02,        //     Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
+    0xC0,              //   End Collection
+    0xA1, 0x02,        //   Collection (Logical)
+    0x85, 0xEE,        //     Report ID (-18)
+    0x75, 0x08,        //     Report Size (8)
+    0x95, 0x30,        //     Report Count (48)
+    0x09, 0x01,        //     Usage (Pointer)
+    0xB1, 0x02,        //     Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
+    0xC0,              //   End Collection
+    0xA1, 0x02,        //   Collection (Logical)
+    0x85, 0xEF,        //     Report ID (-17)
+    0x75, 0x08,        //     Report Size (8)
+    0x95, 0x30,        //     Report Count (48)
+    0x09, 0x01,        //     Usage (Pointer)
+    0xB1, 0x02,        //     Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
+    0xC0,              //   End Collection
+    0xC0,              // End Collection
+};
+
+// FIXME: Hatswitch is not yet addressable by test
+const size_t Dualshock3ButtonCount = 19;
+const size_t Dualshock3AxisCount = 4;
+const size_t Dualshock3ReportSize = 49;
+const char* Dualshock3Name = "Virtual Dualshock3";
+
+// Report layout:
+// |ReportID| |<none>| |b1-b8| |b9-b16| |(5 bits padding high) b17-b19| |padding| |Axis1| |Axis2| |Axis3| |Axis4|
+// (39x) |Generic pointer|
+// Analog button readouts show up at specific places in those 39 generic 1 byte pointers
+// Physical buttons on the device map to button bits 1-17, but there is no actuator for b18 and b19
+// 12 of those physical buttons also have an analog value mapping into the generic pointers
+
+static void publishReportCallback(Vector<float>& buttonValues, Vector<float>& axisValues, HIDUserDevice *userDevice)
+{
+    uint8_t reportData[Dualshock3ReportSize];
+    bzero(reportData, Dualshock3ReportSize);
+    size_t reportIndex = 0;
+
+    // Report ID
+    reportData[reportIndex++] = 0x01;
+
+    // Constant
+    reportData[reportIndex++] = 0x00;
+
+    // Digital buttons span the next 3 bytes
+    uint8_t buttonByte = 0x00;
+    long buttonBit;
+    for (size_t i = 0; i < 8; ++i) {
+        buttonBit = lround(buttonValues[i]);
+        buttonByte |= buttonBit << i;
+    }
+    reportData[reportIndex++] = buttonByte;
+
+    buttonByte = 0x00;
+    for (size_t i = 8; i < 16; ++i) {
+        buttonBit = lround(buttonValues[i]);
+        buttonByte |= buttonBit << (i - 8);
+    }
+    reportData[reportIndex++] = buttonByte;
+
+    buttonByte = 0x00;
+    for (size_t i = 16; i < 19; ++i) {
+        buttonBit = lround(buttonValues[i]);
+        buttonByte |= buttonBit << (i - 16);
+    }
+    reportData[reportIndex++] = buttonByte;
+
+    // Padding byte
+    reportData[reportIndex++] = 0x00;
+
+    // Axes (1 byte each)
+    for (size_t i = 0; i < 4; ++i)
+        reportData[reportIndex++] = (uint8_t)(axisValues[i] * 255);
+
+    // First 4 generic points are always 0x00
+    reportData[reportIndex++] = 0x00;
+    reportData[reportIndex++] = 0x00;
+    reportData[reportIndex++] = 0x00;
+    reportData[reportIndex++] = 0x00;
+
+    // The next twelve generic pointers map to specific buttons in order
+    for (size_t i = 4; i < 16; ++i)
+        reportData[reportIndex++] = (uint8_t)(buttonValues[i] * 255);
+
+    auto nsReportData = adoptNS([[NSData alloc] initWithBytes:reportData length:Dualshock3ReportSize]);
+    [userDevice handleReport:nsReportData.get() error:nil];
+}
+
+GamepadMapping VirtualGamepad::sonyDualshock3Mapping()
+{
+    return {
+        Dualshock3Descriptor,
+        sizeof(Dualshock3Descriptor),
+        Dualshock3Name,
+        HIDVendorID::Sony,
+        HIDProductID::Dualshock3,
+        Dualshock3ButtonCount,
+        Dualshock3AxisCount,
+        publishReportCallback
+    };
+}
+
+} // namespace TestWebKitAPI
+
+#endif // HAVE(HID_FRAMEWORK) && USE(APPLE_INTERNAL_SDK)

Modified: trunk/Tools/TestWebKitAPI/mac/VirtualGamepad.h (265155 => 265156)


--- trunk/Tools/TestWebKitAPI/mac/VirtualGamepad.h	2020-07-31 19:39:18 UTC (rev 265155)
+++ trunk/Tools/TestWebKitAPI/mac/VirtualGamepad.h	2020-07-31 19:50:33 UTC (rev 265156)
@@ -60,6 +60,7 @@
     XboxOne1 = 0x02ea,
     XboxOne2 = 0x02e0,
     XboxOne3 = 0x02fd,
+    Dualshock3 = 0x0268,
     Dualshock4_1 = 0x05c4,
     Dualshock4_2 = 0x09cc,
 };
@@ -82,6 +83,7 @@
 public:
     static GamepadMapping microsoftXboxOneMapping();
     static GamepadMapping shenzhenLongshengweiTechnologyGamepadMapping();
+    static GamepadMapping sonyDualshock3Mapping();
     static GamepadMapping sonyDualshock4Mapping();
     static GamepadMapping steelSeriesNimbusMapping();
     static GamepadMapping sunLightApplicationGenericNESMapping();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to