Diff
Modified: trunk/Source/WebCore/ChangeLog (265179 => 265180)
--- trunk/Source/WebCore/ChangeLog 2020-08-01 21:48:25 UTC (rev 265179)
+++ trunk/Source/WebCore/ChangeLog 2020-08-01 22:55:47 UTC (rev 265180)
@@ -1,3 +1,33 @@
+2020-08-01 Brady Eidson <[email protected]>
+
+ Special HID mapping for the Google Stadia controller
+ https://bugs.webkit.org/show_bug.cgi?id=215061
+
+ Reviewed by Tim Horton.
+
+ New API test coverage.
+
+ * SourcesCocoa.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * platform/gamepad/GamepadConstants.h:
+ * 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):
+ (WebCore::HIDGamepadHatswitch::gamepadValueChanged):
+ (WebCore::HIDGamepadHatswitch::normalizedValue):
+ * platform/gamepad/mac/HIDGamepadElement.h:
+ (WebCore::HIDGamepadElement::isAxis const):
+ (WebCore::HIDGamepadHatswitch::HIDGamepadHatswitch):
+
+ * platform/gamepad/mac/StadiaHIDGamepad.cpp: Added.
+ (WebCore::StadiaHIDGamepad::StadiaHIDGamepad):
+ * platform/gamepad/mac/StadiaHIDGamepad.h:
+
2020-08-01 Sam Weinig <[email protected]>
Convert LinkHeader to use StringParsingBuffer
Modified: trunk/Source/WebCore/SourcesCocoa.txt (265179 => 265180)
--- trunk/Source/WebCore/SourcesCocoa.txt 2020-08-01 21:48:25 UTC (rev 265179)
+++ trunk/Source/WebCore/SourcesCocoa.txt 2020-08-01 22:55:47 UTC (rev 265180)
@@ -263,6 +263,7 @@
platform/gamepad/mac/HIDGamepadElement.cpp
platform/gamepad/mac/HIDGamepadProvider.mm
platform/gamepad/mac/MultiGamepadProvider.mm
+platform/gamepad/mac/StadiaHIDGamepad.cpp
platform/graphics/MediaPlaybackTargetPicker.cpp
platform/graphics/avfoundation/AVTrackPrivateAVFObjCImpl.mm @no-unify
platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm @no-unify
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (265179 => 265180)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-08-01 21:48:25 UTC (rev 265179)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-08-01 22:55:47 UTC (rev 265180)
@@ -1405,6 +1405,7 @@
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 */; };
+ 510A921224D5E60E00BFD89C /* StadiaHIDGamepad.h in Headers */ = {isa = PBXBuildFile; fileRef = 510A921124D5E21700BFD89C /* StadiaHIDGamepad.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, ); }; };
@@ -8236,6 +8237,8 @@
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>"; };
+ 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>"; };
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>"; };
@@ -19701,6 +19704,8 @@
515BE1991D54F6BD00DD7C68 /* HIDGamepadProvider.mm */,
517E03F424B6B9630054895A /* MultiGamepadProvider.h */,
517E03F524B6B9640054895A /* MultiGamepadProvider.mm */,
+ 510A920F24D5E21700BFD89C /* StadiaHIDGamepad.cpp */,
+ 510A921124D5E21700BFD89C /* StadiaHIDGamepad.h */,
);
path = mac;
sourceTree = "<group>";
@@ -33452,6 +33457,7 @@
1A2E6E5A0CC55213004A2062 /* SQLValue.h in Headers */,
93F1996308245E59001E9ABC /* SSLKeyGenerator.h in Headers */,
26B999911803B3C900D01121 /* StackAllocator.h in Headers */,
+ 510A921224D5E60E00BFD89C /* StadiaHIDGamepad.h in Headers */,
BC7FA62D0D1F0EFF00DB22A9 /* StaticNodeList.h in Headers */,
F433E9031DBBDBA200EF0D14 /* StaticPasteboard.h in Headers */,
F44EBBD91DB5D21400277334 /* StaticRange.h in Headers */,
Modified: trunk/Source/WebCore/platform/gamepad/GamepadConstants.h (265179 => 265180)
--- trunk/Source/WebCore/platform/gamepad/GamepadConstants.h 2020-08-01 21:48:25 UTC (rev 265179)
+++ trunk/Source/WebCore/platform/gamepad/GamepadConstants.h 2020-08-01 22:55:47 UTC (rev 265180)
@@ -53,6 +53,8 @@
LeftClusterLeft = 14,
LeftClusterRight = 15,
CenterClusterCenter = 16,
+ Nonstandard1 = 17,
+ Nonstandard2 = 18,
};
extern const size_t numberOfStandardGamepadButtonsWithoutHomeButton;
Modified: trunk/Source/WebCore/platform/gamepad/KnownGamepads.h (265179 => 265180)
--- trunk/Source/WebCore/platform/gamepad/KnownGamepads.h 2020-08-01 21:48:25 UTC (rev 265179)
+++ trunk/Source/WebCore/platform/gamepad/KnownGamepads.h 2020-08-01 22:55:47 UTC (rev 265180)
@@ -30,20 +30,21 @@
namespace WebCore {
enum KnownGamepad {
+ Dualshock3 = 0x054c0268,
+ Dualshock4_1 = 0x054c05c4,
+ Dualshock4_2 = 0x054c09cc,
+ GamesirM2 = 0x0ec20475,
+ HoripadUltimate = 0x0f0d0090,
Nimbus1 = 0x01111420,
Nimbus2 = 0x10381420,
+ StadiaA = 0x18d19400,
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
Modified: trunk/Source/WebCore/platform/gamepad/mac/GamepadConstantsMac.h (265179 => 265180)
--- trunk/Source/WebCore/platform/gamepad/mac/GamepadConstantsMac.h 2020-08-01 21:48:25 UTC (rev 265179)
+++ trunk/Source/WebCore/platform/gamepad/mac/GamepadConstantsMac.h 2020-08-01 22:55:47 UTC (rev 265180)
@@ -31,16 +31,32 @@
namespace WebCore {
+constexpr const uint64_t hidHatswitchFullUsage = ((uint64_t)kHIDPage_GenericDesktop) << 32 | kHIDUsage_GD_Hatswitch;
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 hidAcceleratorFullUsage = ((uint64_t)kHIDPage_Simulation) << 32 | kHIDUsage_Sim_Accelerator;
+constexpr const uint64_t hidBrakeFullUsage = ((uint64_t)kHIDPage_Simulation) << 32 | kHIDUsage_Sim_Brake;
+
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 hidButton5FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 4);
+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 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);
+constexpr const uint64_t hidButton14FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 13);
+constexpr const uint64_t hidButton15FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 14);
constexpr const uint64_t hidButton17FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 16);
+constexpr const uint64_t hidButton18FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 17);
+constexpr const uint64_t hidButton19FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 18);
+constexpr const uint64_t hidButton20FullUsage = ((uint64_t)kHIDPage_Button) << 32 | (kHIDUsage_Button_1 + 19);
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.cpp (265179 => 265180)
--- trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.cpp 2020-08-01 21:48:25 UTC (rev 265179)
+++ trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.cpp 2020-08-01 22:55:47 UTC (rev 265180)
@@ -32,6 +32,7 @@
#include "GenericHIDGamepad.h"
#include "KnownGamepads.h"
#include "Logging.h"
+#include "StadiaHIDGamepad.h"
#include <IOKit/hid/IOHIDElement.h>
#include <IOKit/hid/IOHIDUsageTables.h>
#include <IOKit/hid/IOHIDValue.h>
@@ -50,6 +51,9 @@
case Dualshock3:
newGamepad = makeUnique<Dualshock3HIDGamepad>(WTFMove(device), index);
break;
+ case StadiaA:
+ newGamepad = makeUnique<StadiaHIDGamepad>(WTFMove(device), index);
+ break;
default:
newGamepad = makeUnique<GenericHIDGamepad>(WTFMove(device), index);
}
Modified: trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadElement.cpp (265179 => 265180)
--- trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadElement.cpp 2020-08-01 21:48:25 UTC (rev 265179)
+++ trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadElement.cpp 2020-08-01 22:55:47 UTC (rev 265180)
@@ -32,9 +32,8 @@
#pragma mark HIDGamepadElement
-HIDGamepadElement::HIDGamepadElement(const HIDElement& element, SharedGamepadValue& value)
+HIDGamepadElement::HIDGamepadElement(const HIDElement& element)
: HIDElement(element)
- , m_value(value)
{
}
@@ -75,6 +74,57 @@
return (HIDGamepadElement::normalizedValue() * 2.0) - 1.0;
}
+#pragma mark HIDGamepadHatswitch
+
+HIDInputType HIDGamepadHatswitch::gamepadValueChanged(IOHIDValueRef value)
+{
+ valueChanged(value);
+
+ for (size_t i = 0; i < 4; ++i)
+ m_buttonValues[i].setValue(0.0);
+
+ switch (physicalValue()) {
+ case 0:
+ m_buttonValues[0].setValue(1.0);
+ break;
+ case 45:
+ m_buttonValues[0].setValue(1.0);
+ m_buttonValues[1].setValue(1.0);
+ break;
+ case 90:
+ m_buttonValues[1].setValue(1.0);
+ break;
+ case 135:
+ m_buttonValues[1].setValue(1.0);
+ m_buttonValues[2].setValue(1.0);
+ break;
+ case 180:
+ m_buttonValues[2].setValue(1.0);
+ break;
+ case 225:
+ m_buttonValues[2].setValue(1.0);
+ m_buttonValues[3].setValue(1.0);
+ break;
+ case 270:
+ m_buttonValues[3].setValue(1.0);
+ break;
+ case 315:
+ m_buttonValues[3].setValue(1.0);
+ m_buttonValues[0].setValue(1.0);
+ break;
+ default:
+ break;
+ };
+
+ return HIDInputType::ButtonPress;
+}
+
+double HIDGamepadHatswitch::normalizedValue()
+{
+ // Hatswitch normalizedValue should never be accessed.
+ RELEASE_ASSERT_NOT_REACHED();
+}
+
} // namespace WebCore
#endif // ENABLE(GAMEPAD) && PLATFORM(MAC)
Modified: trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadElement.h (265179 => 265180)
--- trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadElement.h 2020-08-01 21:48:25 UTC (rev 265179)
+++ trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadElement.h 2020-08-01 22:55:47 UTC (rev 265180)
@@ -45,24 +45,23 @@
public:
virtual ~HIDGamepadElement() { }
- virtual double normalizedValue();
virtual HIDInputType gamepadValueChanged(IOHIDValueRef) = 0;
void refreshCurrentValue();
protected:
- HIDGamepadElement(const HIDElement&, SharedGamepadValue&);
+ HIDGamepadElement(const HIDElement&);
+ virtual double normalizedValue();
virtual bool isButton() const { return false; }
virtual bool isAxis() const { return false; }
-
- SharedGamepadValue m_value;
};
class HIDGamepadButton final : public HIDGamepadElement {
public:
HIDGamepadButton(const HIDElement& element, SharedGamepadValue& value)
- : HIDGamepadElement(element, value)
+ : HIDGamepadElement(element)
+ , m_value(value)
{
}
@@ -70,22 +69,45 @@
private:
HIDInputType gamepadValueChanged(IOHIDValueRef) override;
+
+ SharedGamepadValue m_value;
};
class HIDGamepadAxis final : public HIDGamepadElement {
public:
HIDGamepadAxis(const HIDElement& element, SharedGamepadValue& value)
- : HIDGamepadElement(element, value)
+ : HIDGamepadElement(element)
+ , m_value(value)
{
}
bool isAxis() const final { return true; }
- double normalizedValue() final;
private:
HIDInputType gamepadValueChanged(IOHIDValueRef) override;
+ double normalizedValue() final;
+
+ SharedGamepadValue m_value;
};
+class HIDGamepadHatswitch : public HIDGamepadElement {
+public:
+ HIDGamepadHatswitch(const HIDElement& element, Vector<SharedGamepadValue>&& buttonValues)
+ : HIDGamepadElement(element)
+ , m_buttonValues(WTFMove(buttonValues))
+ {
+ }
+
+ // Treat hatswitch value changes as a button press
+ bool isButton() const final { return true; }
+
+private:
+ HIDInputType gamepadValueChanged(IOHIDValueRef) final;
+ double normalizedValue() final;
+
+ Vector<SharedGamepadValue> m_buttonValues;
+};
+
} // namespace WebCore
#endif // ENABLE(GAMEPAD) && PLATFORM(MAC)
Added: trunk/Source/WebCore/platform/gamepad/mac/StadiaHIDGamepad.cpp (0 => 265180)
--- trunk/Source/WebCore/platform/gamepad/mac/StadiaHIDGamepad.cpp (rev 0)
+++ trunk/Source/WebCore/platform/gamepad/mac/StadiaHIDGamepad.cpp 2020-08-01 22:55:47 UTC (rev 265180)
@@ -0,0 +1,137 @@
+/*
+ * 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 "StadiaHIDGamepad.h"
+
+#if ENABLE(GAMEPAD) && PLATFORM(MAC)
+
+#include "GamepadConstants.h"
+#include "GamepadConstantsMac.h"
+#include "Logging.h"
+
+namespace WebCore {
+
+StadiaHIDGamepad::StadiaHIDGamepad(HIDDevice&& device, unsigned index)
+ : HIDGamepad(WTFMove(device), index)
+{
+ LOG(Gamepad, "Creating StadiaHIDGamepad %p", this);
+
+ m_mapping = standardGamepadMappingString();
+
+ for (size_t i = 0; i < 19; ++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 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 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 hidAcceleratorFullUsage:
+ mapButton(element, GamepadButtonRole::RightShoulderBack);
+ break;
+ case hidBrakeFullUsage:
+ mapButton(element, GamepadButtonRole::LeftShoulderBack);
+ break;
+
+ case hidButton1FullUsage:
+ mapButton(element, GamepadButtonRole::RightClusterBottom);
+ break;
+ case hidButton2FullUsage:
+ mapButton(element, GamepadButtonRole::RightClusterRight);
+ break;
+ case hidButton4FullUsage:
+ mapButton(element, GamepadButtonRole::RightClusterLeft);
+ break;
+ case hidButton5FullUsage:
+ mapButton(element, GamepadButtonRole::RightClusterTop);
+ break;
+ case hidButton7FullUsage:
+ mapButton(element, GamepadButtonRole::LeftShoulderFront);
+ break;
+ case hidButton8FullUsage:
+ mapButton(element, GamepadButtonRole::RightShoulderFront);
+ break;
+ case hidButton11FullUsage:
+ mapButton(element, GamepadButtonRole::CenterClusterLeft);
+ break;
+ case hidButton12FullUsage:
+ mapButton(element, GamepadButtonRole::CenterClusterRight);
+ break;
+ case hidButton13FullUsage:
+ mapButton(element, GamepadButtonRole::CenterClusterCenter);
+ break;
+ case hidButton14FullUsage:
+ mapButton(element, GamepadButtonRole::LeftStick);
+ break;
+ case hidButton15FullUsage:
+ mapButton(element, GamepadButtonRole::RightStick);
+ break;
+ case hidButton17FullUsage:
+ mapButton(element, GamepadButtonRole::Nonstandard1);
+ break;
+ case hidButton18FullUsage:
+ mapButton(element, GamepadButtonRole::Nonstandard2);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD) && PLATFORM(MAC)
Copied: trunk/Source/WebCore/platform/gamepad/mac/StadiaHIDGamepad.h (from rev 265179, trunk/Source/WebCore/platform/gamepad/KnownGamepads.h) (0 => 265180)
--- trunk/Source/WebCore/platform/gamepad/mac/StadiaHIDGamepad.h (rev 0)
+++ trunk/Source/WebCore/platform/gamepad/mac/StadiaHIDGamepad.h 2020-08-01 22:55:47 UTC (rev 265180)
@@ -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 StadiaHIDGamepad final : public HIDGamepad {
+ WTF_MAKE_FAST_ALLOCATED;
+public:
+ StadiaHIDGamepad(HIDDevice&&, unsigned index);
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD) && PLATFORM(MAC)
Modified: trunk/Tools/ChangeLog (265179 => 265180)
--- trunk/Tools/ChangeLog 2020-08-01 21:48:25 UTC (rev 265179)
+++ trunk/Tools/ChangeLog 2020-08-01 22:55:47 UTC (rev 265180)
@@ -1,3 +1,19 @@
+2020-08-01 Brady Eidson <[email protected]>
+
+ Special HID mapping for the Google Stadia controller
+ https://bugs.webkit.org/show_bug.cgi?id=215061
+
+ Reviewed by Tim Horton.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/mac/HIDGamepads.mm:
+
+ * TestWebKitAPI/mac/GamepadMappings/GoogleStadia.mm: Added.
+ (TestWebKitAPI::publishReportCallback):
+
+ (TestWebKitAPI::VirtualGamepad::googleStadiaMapping):
+ * TestWebKitAPI/mac/VirtualGamepad.h:
+
2020-07-31 Alex Christensen <[email protected]>
Use more inclusive terminology in Tools
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (265179 => 265180)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2020-08-01 21:48:25 UTC (rev 265179)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2020-08-01 22:55:47 UTC (rev 265180)
@@ -277,6 +277,7 @@
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 */; };
+ 510A921424D615B400BFD89C /* GoogleStadia.mm in Sources */ = {isa = PBXBuildFile; fileRef = 510A921324D60A3E00BFD89C /* GoogleStadia.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 */; };
@@ -1973,6 +1974,7 @@
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>"; };
+ 510A921324D60A3E00BFD89C /* GoogleStadia.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GoogleStadia.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 @@
51EB125D24CA6B3E000CB030 /* GamepadMappings */ = {
isa = PBXGroup;
children = (
+ 510A921324D60A3E00BFD89C /* GoogleStadia.mm */,
51EB126024CA6B5F000CB030 /* MicrosoftXboxOne.mm */,
51EB125E24CA6B5F000CB030 /* ShenzhenLongshengweiTechnologyGamepad.mm */,
510A91F724D3621900BFD89C /* SonyDualShock3.mm */,
@@ -4856,6 +4859,7 @@
CE78705F2107AB980053AC67 /* MoveOnlyLifecycleLogger.cpp in Sources */,
7C83DEFE1D0A590C00FEBCF3 /* NakedPtr.cpp in Sources */,
A57D54F31F338C3600A97AA7 /* NeverDestroyed.cpp in Sources */,
+ CD48A87324C8A66F00F5800C /* Observer.cpp in Sources */,
7C83DF011D0A590C00FEBCF3 /* Optional.cpp in Sources */,
1A77BAA31D9AFFFC005FC568 /* OptionSet.cpp in Sources */,
7C83DF021D0A590C00FEBCF3 /* OSObjectPtr.cpp in Sources */,
@@ -4862,7 +4866,6 @@
E32B549222810AC4008AD702 /* Packed.cpp in Sources */,
E38D65CA23A45FAA0063D69A /* PackedRef.cpp in Sources */,
E38D65CB23A45FAA0063D69A /* PackedRefPtr.cpp in Sources */,
- CD48A87324C8A66F00F5800C /* Observer.cpp in Sources */,
7C83DF591D0A590C00FEBCF3 /* ParkingLot.cpp in Sources */,
53EC25411E96FD87000831B9 /* PriorityQueue.cpp in Sources */,
7C83DF131D0A590C00FEBCF3 /* RedBlackTree.cpp in Sources */,
@@ -5104,6 +5107,7 @@
41157237234B240C0050A1D1 /* GetUserMedia.mm in Sources */,
07CE1CF31F06A7E000BF89F5 /* GetUserMediaNavigation.mm in Sources */,
07E499911F9E56DF002F1EF3 /* GetUserMediaReprompt.mm in Sources */,
+ 510A921424D615B400BFD89C /* GoogleStadia.mm in Sources */,
E394AE6F23F2303E005B4936 /* GrantAccessToMobileAssets.mm in Sources */,
E34A6D192412DE390012AB6E /* GrantAccessToPreferencesService.mm in Sources */,
8E4A85371E1D1AB200F53B0F /* GridPosition.cpp in Sources */,
Modified: trunk/Tools/TestWebKitAPI/Tests/mac/HIDGamepads.mm (265179 => 265180)
--- trunk/Tools/TestWebKitAPI/Tests/mac/HIDGamepads.mm 2020-08-01 21:48:25 UTC (rev 265179)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/HIDGamepads.mm 2020-08-01 22:55:47 UTC (rev 265180)
@@ -421,6 +421,74 @@
didReceiveMessage = true;
}
+TEST(Gamepad, Stadia)
+{
+ 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::googleStadiaMapping());
+ 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, 1.0);
+ gamepad->setButtonValue(1, 1.0);
+ gamepad->setButtonValue(2, 1.0);
+ gamepad->setButtonValue(3, 1.0);
+ gamepad->setButtonValue(4, 1.0);
+ gamepad->setButtonValue(5, 1.0);
+ 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:@"\"18d1-9400-Virtual Stadia\""]);
+
+ 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, 19u);
+ 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/GoogleStadia.mm (0 => 265180)
--- trunk/Tools/TestWebKitAPI/mac/GamepadMappings/GoogleStadia.mm (rev 0)
+++ trunk/Tools/TestWebKitAPI/mac/GamepadMappings/GoogleStadia.mm 2020-08-01 22:55:47 UTC (rev 265180)
@@ -0,0 +1,209 @@
+/*
+ * 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 StadiaDescriptor[] = {
+ 0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
+ 0x09, 0x05, // Usage (Game Pad)
+ 0xA1, 0x01, // Collection (Application)
+ // (1) byte report ID - (1) byte total
+ 0x85, 0x03, // Report ID (3)
+ 0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
+ 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)
+ // (4) bit hatswitch - (1) byte (4) bits total
+ 0x81, 0x42, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,Null State)
+ 0x45, 0x00, // Physical Maximum (0)
+ 0x65, 0x00, // Unit (None)
+ 0x75, 0x01, // Report Size (1)
+ 0x95, 0x04, // Report Count (4)
+ // (4) bit padding - (2) bytes total
+ 0x81, 0x01, // Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
+ 0x05, 0x09, // Usage Page (Button)
+ 0x15, 0x00, // Logical Minimum (0)
+ 0x25, 0x01, // Logical Maximum (1)
+ 0x75, 0x01, // Report Size (1)
+ 0x95, 0x0F, // Report Count (15)
+ 0x09, 0x12, // Usage (0x12)
+ 0x09, 0x11, // Usage (0x11)
+ 0x09, 0x14, // Usage (0x14)
+ 0x09, 0x13, // Usage (0x13)
+ 0x09, 0x0D, // Usage (0x0D)
+ 0x09, 0x0C, // Usage (0x0C)
+ 0x09, 0x0B, // Usage (0x0B)
+ 0x09, 0x0F, // Usage (0x0F)
+ 0x09, 0x0E, // Usage (0x0E)
+ 0x09, 0x08, // Usage (0x08)
+ 0x09, 0x07, // Usage (0x07)
+ 0x09, 0x05, // Usage (0x05)
+ 0x09, 0x04, // Usage (0x04)
+ 0x09, 0x02, // Usage (0x02)
+ 0x09, 0x01, // Usage (0x01)
+ // (15) buttons - (3) bytes (7) bits total
+ 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
+ 0x75, 0x01, // Report Size (1)
+ 0x95, 0x01, // Report Count (1)
+ // (1) padding - (4) bytes total
+ 0x81, 0x01, // Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
+ 0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
+ 0x15, 0x01, // Logical Minimum (1)
+ 0x26, 0xFF, 0x00, // Logical Maximum (255)
+ 0x09, 0x01, // Usage (Pointer)
+ 0xA1, 0x00, // Collection (Physical)
+ 0x09, 0x30, // Usage (X)
+ 0x09, 0x31, // Usage (Y)
+ 0x75, 0x08, // Report Size (8)
+ 0x95, 0x02, // Report Count (2)
+ // (2) axes 1 byte each - (6) bytes total
+ 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
+ 0xC0, // End Collection
+ 0x09, 0x01, // Usage (Pointer)
+ 0xA1, 0x00, // Collection (Physical)
+ 0x09, 0x32, // Usage (Z)
+ 0x09, 0x35, // Usage (Rz)
+ 0x75, 0x08, // Report Size (8)
+ 0x95, 0x02, // Report Count (2)
+ // (2) axes 1 byte each - (8) bytes total
+ 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
+ 0xC0, // End Collection
+ 0x05, 0x02, // Usage Page (Sim Ctrls)
+ 0x75, 0x08, // Report Size (8)
+ 0x95, 0x02, // Report Count (2)
+ 0x15, 0x00, // Logical Minimum (0)
+ 0x26, 0xFF, 0x00, // Logical Maximum (255)
+ 0x09, 0xC5, // Usage (Brake)
+ 0x09, 0xC4, // Usage (Accelerator)
+ // (2) "analog buttons"" 1 byte each - (10) bytes total
+ 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
+ 0x05, 0x0C, // Usage Page (Consumer)
+ 0x15, 0x00, // Logical Minimum (0)
+ 0x25, 0x01, // Logical Maximum (1)
+ 0x09, 0xE9, // Usage (Volume Increment)
+ 0x09, 0xEA, // Usage (Volume Decrement)
+ 0x75, 0x01, // Report Size (1)
+ 0x95, 0x02, // Report Count (2)
+ // (2) 1 bit buttons - (10) bytes (2) bits total
+ 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
+ 0x09, 0xCD, // Usage (Play/Pause)
+ 0x95, 0x01, // Report Count (1)
+ // (1) 1 bit buttons - (10) bytes (3) bits total
+ 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
+ 0x95, 0x05, // Report Count (5)
+ // (5) bits padding - (11) bytes total
+ 0x81, 0x01, // Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
+ 0x85, 0x05, // Report ID (5)
+ 0x06, 0x0F, 0x00, // Usage Page (PID Page)
+ 0x09, 0x97, // Usage (0x97)
+ 0x75, 0x10, // Report Size (16)
+ 0x95, 0x02, // Report Count (2)
+ 0x27, 0xFF, 0xFF, 0x00, 0x00, // Logical Maximum (65534)
+ 0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
+ 0xC0, // End Collection
+};
+
+// FIXME: Hatswitch is not yet addressable by test
+const size_t StadiaButtonCount = 19;
+const size_t StadiaAxisCount = 4;
+const size_t StadiaReportSize = 11;
+const char* StadiaName = "Virtual Stadia";
+
+// Report layout:
+// |ReportID| |Pad, 4bit hat| |8 buttons| |Pad 7 buttons| |X| |Y| |Z| |Rz| |Brake| |Accelerator| |Pad, vup vdown pause|
+
+// Brake and acclerator are analog values for back shoulder buttons, which are also represented in the 15 digital buttons
+// I cannot identify physical actuators for volume-up, volume-down, and pause.
+
+static void publishReportCallback(Vector<float>& buttonValues, Vector<float>& axisValues, HIDUserDevice *userDevice)
+{
+ uint8_t reportData[StadiaReportSize];
+ bzero(reportData, StadiaReportSize);
+ size_t reportIndex = 0;
+
+ // Report ID (Normal input report is #3)
+ reportData[reportIndex++] = 0x03;
+
+ // No interface to change hatswitch value at this time
+ reportData[reportIndex++] = 0x08;
+
+ // Digital buttons span the next 2 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 < 15; ++i) {
+ buttonBit = lround(buttonValues[i]);
+ buttonByte |= buttonBit << (i - 8);
+ }
+ reportData[reportIndex++] = buttonByte;
+
+ // Axes (1 byte each)
+ for (size_t i = 0; i < 4; ++i)
+ reportData[reportIndex++] = (uint8_t)(axisValues[i] * 255);
+
+ // Brake and Accelerator are also button 14 and 15
+ reportData[reportIndex++] = (uint8_t)(buttonValues[13] * 255);
+ reportData[reportIndex++] = (uint8_t)(buttonValues[14] * 255);
+
+ // Final byte has 5 padding bits, 3 button bits in it, but no way to actuate them
+ reportData[reportIndex++] = 0x00;
+
+ auto nsReportData = adoptNS([[NSData alloc] initWithBytes:reportData length:StadiaReportSize]);
+ [userDevice handleReport:nsReportData.get() error:nil];
+}
+
+GamepadMapping VirtualGamepad::googleStadiaMapping()
+{
+ return {
+ StadiaDescriptor,
+ sizeof(StadiaDescriptor),
+ StadiaName,
+ HIDVendorID::Google,
+ HIDProductID::StadiaA,
+ StadiaButtonCount,
+ StadiaAxisCount,
+ publishReportCallback
+ };
+}
+
+} // namespace TestWebKitAPI
+
+#endif // HAVE(HID_FRAMEWORK) && USE(APPLE_INTERNAL_SDK)
Modified: trunk/Tools/TestWebKitAPI/mac/VirtualGamepad.h (265179 => 265180)
--- trunk/Tools/TestWebKitAPI/mac/VirtualGamepad.h 2020-08-01 21:48:25 UTC (rev 265179)
+++ trunk/Tools/TestWebKitAPI/mac/VirtualGamepad.h 2020-08-01 22:55:47 UTC (rev 265180)
@@ -40,6 +40,7 @@
namespace TestWebKitAPI {
enum class HIDVendorID : uint16_t {
+ Google = 0x18d1,
Microsoft = 0x045e,
ShenzhenLongshengweiTechnology = 0x0079,
Sony = 0x054c,
@@ -52,17 +53,18 @@
// Technically different products from different vendors can have the same product ID,
// But in practice that probably won't happen.
enum class HIDProductID : uint16_t {
+ Dualshock3 = 0x0268,
+ Dualshock4_1 = 0x05c4,
+ Dualshock4_2 = 0x09cc,
+ Gamepad = 0x0011,
+ GenericNES = 0xd015,
+ Nimbus = 0x1420,
+ StadiaA = 0x9400,
StratusXL1 = 0x1418,
StratusXL2 = 0x1419,
- Nimbus = 0x1420,
- Gamepad = 0x0011,
- GenericNES = 0xd015,
XboxOne1 = 0x02ea,
XboxOne2 = 0x02e0,
XboxOne3 = 0x02fd,
- Dualshock3 = 0x0268,
- Dualshock4_1 = 0x05c4,
- Dualshock4_2 = 0x09cc,
};
typedef void (*PublishReportCallback)(Vector<float>&, Vector<float>&, HIDUserDevice*);
@@ -81,6 +83,7 @@
class VirtualGamepad {
WTF_MAKE_FAST_ALLOCATED;
public:
+ static GamepadMapping googleStadiaMapping();
static GamepadMapping microsoftXboxOneMapping();
static GamepadMapping shenzhenLongshengweiTechnologyGamepadMapping();
static GamepadMapping sonyDualshock3Mapping();