Title: [264207] trunk/Source
Revision
264207
Author
[email protected]
Date
2020-07-09 18:27:58 -0700 (Thu, 09 Jul 2020)

Log Message

Multiplex the HID and GameController gamepad providers on Mac.
<rdar://problem/63192532> and https://bugs.webkit.org/show_bug.cgi?id=214126

Reviewed by Tim Horton.
Source/WebCore:

Mac has already supported both the HID provider and GameController provider.

By adding an intermediate provider to multiplex both and tweaking a few other things,
it can support both at the same time.

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

* platform/gamepad/PlatformGamepad.h:
(WebCore::PlatformGamepad::lastUpdateTime const):
(WebCore::PlatformGamepad::source const):

* platform/gamepad/cocoa/GameControllerGamepad.h:
* platform/gamepad/cocoa/GameControllerGamepadProvider.h:
* platform/gamepad/cocoa/GameControllerGamepadProvider.mm:
(WebCore::GameControllerGamepadProvider::controllerDidConnect):
(WebCore::GameControllerGamepadProvider::gamepadHadInput):
(WebCore::GameControllerGamepadProvider::makeInvisibleGamepadsVisible):
(WebCore::GameControllerGamepadProvider::inputNotificationTimerFired):
(WebCore::GameControllerGamepadProvider::makeInvisibileGamepadsVisible): Deleted.

* platform/gamepad/cocoa/GameControllerSPI.h:
* platform/gamepad/cocoa/GameControllerSoftLink.h:
* platform/gamepad/cocoa/GameControllerSoftLink.mm:

* platform/gamepad/mac/HIDGamepad.h:
* platform/gamepad/mac/HIDGamepadProvider.h:
(WebCore::HIDGamepadProvider::ignoreGameControllerFrameworkDevices):
* platform/gamepad/mac/HIDGamepadProvider.mm: Renamed from Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.cpp.
(WebCore::deviceMatchingDictionary):
(WebCore::deviceAddedCallback):
(WebCore::deviceRemovedCallback):
(WebCore::deviceValuesChangedCallback):
(WebCore::HIDGamepadProvider::singleton):
(WebCore::HIDGamepadProvider::HIDGamepadProvider):
(WebCore::HIDGamepadProvider::stopMonitoringInput):
(WebCore::HIDGamepadProvider::startMonitoringInput):
(WebCore::HIDGamepadProvider::indexForNewlyConnectedDevice):
(WebCore::HIDGamepadProvider::initialGamepadsConnectedTimerFired):
(WebCore::HIDGamepadProvider::openAndScheduleManager):
(WebCore::HIDGamepadProvider::closeAndUnscheduleManager):
(WebCore::HIDGamepadProvider::startMonitoringGamepads):
(WebCore::HIDGamepadProvider::stopMonitoringGamepads):
(WebCore::gameControllerFrameworkWillHandleHIDDevice):
(WebCore::HIDGamepadProvider::deviceAdded):
(WebCore::HIDGamepadProvider::deviceRemoved):
(WebCore::HIDGamepadProvider::valuesChanged):
(WebCore::HIDGamepadProvider::inputNotificationTimerFired):
(WebCore::HIDGamepadProvider::removeGamepadForDevice):

* platform/gamepad/mac/MultiGamepadProvider.h: Added.
(WebCore::MultiGamepadProvider::isMockGamepadProvider const):
(WebCore::MultiGamepadProvider::PlatformGamepadWrapper::PlatformGamepadWrapper):
* platform/gamepad/mac/MultiGamepadProvider.mm: Added.
(WebCore::MultiGamepadProvider::singleton):
(WebCore::MultiGamepadProvider::startMonitoringGamepads):
(WebCore::MultiGamepadProvider::stopMonitoringGamepads):
(WebCore::MultiGamepadProvider::indexForNewlyConnectedDevice):
(WebCore::MultiGamepadProvider::platformGamepadConnected):
(WebCore::MultiGamepadProvider::platformGamepadDisconnected):
(WebCore::MultiGamepadProvider::platformGamepadInputActivity):

Source/WebCore/PAL:

The current "IOKitSPI.h" is really weird.
It is mostly needed for iOS, but also used on Mac a little...
And since some of what it declares on Mac is actually public, anyone else
that uses public headers on Mac runs into redefinitions.

Since the use of it on iOS and Mac are so different, let's just make a Mac one.

* PAL.xcodeproj/project.pbxproj:
* pal/spi/mac/IOKitSPIMac.h: Copied from Source/WebCore/platform/gamepad/cocoa/GameControllerSoftLink.h.

Source/WebKit:

* UIProcess/Gamepad/cocoa/UIGamepadProviderCocoa.mm:
(WebKit::UIGamepadProvider::platformSetDefaultGamepadProvider):

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (264206 => 264207)


--- trunk/Source/WebCore/ChangeLog	2020-07-10 01:27:19 UTC (rev 264206)
+++ trunk/Source/WebCore/ChangeLog	2020-07-10 01:27:58 UTC (rev 264207)
@@ -1,3 +1,72 @@
+2020-07-09  Brady Eidson  <[email protected]>
+
+        Multiplex the HID and GameController gamepad providers on Mac.
+        <rdar://problem/63192532> and https://bugs.webkit.org/show_bug.cgi?id=214126
+
+        Reviewed by Tim Horton.
+        
+        Mac has already supported both the HID provider and GameController provider.
+        
+        By adding an intermediate provider to multiplex both and tweaking a few other things,
+        it can support both at the same time.
+
+        * SourcesCocoa.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+
+        * platform/gamepad/PlatformGamepad.h:
+        (WebCore::PlatformGamepad::lastUpdateTime const):
+        (WebCore::PlatformGamepad::source const):
+
+        * platform/gamepad/cocoa/GameControllerGamepad.h:
+        * platform/gamepad/cocoa/GameControllerGamepadProvider.h:
+        * platform/gamepad/cocoa/GameControllerGamepadProvider.mm:
+        (WebCore::GameControllerGamepadProvider::controllerDidConnect):
+        (WebCore::GameControllerGamepadProvider::gamepadHadInput):
+        (WebCore::GameControllerGamepadProvider::makeInvisibleGamepadsVisible):
+        (WebCore::GameControllerGamepadProvider::inputNotificationTimerFired):
+        (WebCore::GameControllerGamepadProvider::makeInvisibileGamepadsVisible): Deleted.
+
+        * platform/gamepad/cocoa/GameControllerSPI.h:
+        * platform/gamepad/cocoa/GameControllerSoftLink.h:
+        * platform/gamepad/cocoa/GameControllerSoftLink.mm:
+
+        * platform/gamepad/mac/HIDGamepad.h:
+        * platform/gamepad/mac/HIDGamepadProvider.h:
+        (WebCore::HIDGamepadProvider::ignoreGameControllerFrameworkDevices):
+        * platform/gamepad/mac/HIDGamepadProvider.mm: Renamed from Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.cpp.
+        (WebCore::deviceMatchingDictionary):
+        (WebCore::deviceAddedCallback):
+        (WebCore::deviceRemovedCallback):
+        (WebCore::deviceValuesChangedCallback):
+        (WebCore::HIDGamepadProvider::singleton):
+        (WebCore::HIDGamepadProvider::HIDGamepadProvider):
+        (WebCore::HIDGamepadProvider::stopMonitoringInput):
+        (WebCore::HIDGamepadProvider::startMonitoringInput):
+        (WebCore::HIDGamepadProvider::indexForNewlyConnectedDevice):
+        (WebCore::HIDGamepadProvider::initialGamepadsConnectedTimerFired):
+        (WebCore::HIDGamepadProvider::openAndScheduleManager):
+        (WebCore::HIDGamepadProvider::closeAndUnscheduleManager):
+        (WebCore::HIDGamepadProvider::startMonitoringGamepads):
+        (WebCore::HIDGamepadProvider::stopMonitoringGamepads):
+        (WebCore::gameControllerFrameworkWillHandleHIDDevice):
+        (WebCore::HIDGamepadProvider::deviceAdded):
+        (WebCore::HIDGamepadProvider::deviceRemoved):
+        (WebCore::HIDGamepadProvider::valuesChanged):
+        (WebCore::HIDGamepadProvider::inputNotificationTimerFired):
+        (WebCore::HIDGamepadProvider::removeGamepadForDevice):
+
+        * platform/gamepad/mac/MultiGamepadProvider.h: Added.
+        (WebCore::MultiGamepadProvider::isMockGamepadProvider const):
+        (WebCore::MultiGamepadProvider::PlatformGamepadWrapper::PlatformGamepadWrapper):
+        * platform/gamepad/mac/MultiGamepadProvider.mm: Added.
+        (WebCore::MultiGamepadProvider::singleton):
+        (WebCore::MultiGamepadProvider::startMonitoringGamepads):
+        (WebCore::MultiGamepadProvider::stopMonitoringGamepads):
+        (WebCore::MultiGamepadProvider::indexForNewlyConnectedDevice):
+        (WebCore::MultiGamepadProvider::platformGamepadConnected):
+        (WebCore::MultiGamepadProvider::platformGamepadDisconnected):
+        (WebCore::MultiGamepadProvider::platformGamepadInputActivity):
+
 2020-07-09  Tim Horton  <[email protected]>
 
         "ESPN Fantasy Sports" does not respond to mouse events, only touch events

Modified: trunk/Source/WebCore/PAL/ChangeLog (264206 => 264207)


--- trunk/Source/WebCore/PAL/ChangeLog	2020-07-10 01:27:19 UTC (rev 264206)
+++ trunk/Source/WebCore/PAL/ChangeLog	2020-07-10 01:27:58 UTC (rev 264207)
@@ -1,3 +1,20 @@
+2020-07-09  Brady Eidson  <[email protected]>
+
+        Multiplex the HID and GameController gamepad providers on Mac.
+        <rdar://problem/63192532> and https://bugs.webkit.org/show_bug.cgi?id=214126
+
+        Reviewed by Tim Horton.
+
+        The current "IOKitSPI.h" is really weird.
+        It is mostly needed for iOS, but also used on Mac a little...
+        And since some of what it declares on Mac is actually public, anyone else
+        that uses public headers on Mac runs into redefinitions.
+        
+        Since the use of it on iOS and Mac are so different, let's just make a Mac one.
+
+        * PAL.xcodeproj/project.pbxproj:
+        * pal/spi/mac/IOKitSPIMac.h: Copied from Source/WebCore/platform/gamepad/cocoa/GameControllerSoftLink.h.
+
 2020-07-09  Per Arne Vollan  <[email protected]>
 
         [Cocoa] Update Launch Services database in the WebContent process from the Network process

Modified: trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj (264206 => 264207)


--- trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj	2020-07-10 01:27:19 UTC (rev 264206)
+++ trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj	2020-07-10 01:27:58 UTC (rev 264207)
@@ -127,6 +127,7 @@
 		4450FCA021F5F602004DFA56 /* QuickLookSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = 4450FC9E21F5F602004DFA56 /* QuickLookSoftLink.h */; };
 		44E1A8AF21FA54E600C3048E /* LookupSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = 44E1A8AD21FA54DA00C3048E /* LookupSoftLink.h */; };
 		44E1A8B021FA54EB00C3048E /* LookupSoftLink.mm in Sources */ = {isa = PBXBuildFile; fileRef = 44E1A8AE21FA54DA00C3048E /* LookupSoftLink.mm */; };
+		517E03F924B7C0070054895A /* IOKitSPIMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 517E03F824B7C0060054895A /* IOKitSPIMac.h */; };
 		570AB8F120AE2E8D00B8BE87 /* SecKeyProxySPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 570AB8F020AE2E8D00B8BE87 /* SecKeyProxySPI.h */; };
 		570AB8F920AF6E3D00B8BE87 /* NSXPCConnectionSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 570AB8F820AF6E3D00B8BE87 /* NSXPCConnectionSPI.h */; };
 		572A107822B456F500F410C8 /* AuthKitSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 572A107722B456F500F410C8 /* AuthKitSPI.h */; };
@@ -313,6 +314,7 @@
 		4450FC9E21F5F602004DFA56 /* QuickLookSoftLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QuickLookSoftLink.h; sourceTree = "<group>"; };
 		44E1A8AD21FA54DA00C3048E /* LookupSoftLink.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LookupSoftLink.h; sourceTree = "<group>"; };
 		44E1A8AE21FA54DA00C3048E /* LookupSoftLink.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = LookupSoftLink.mm; sourceTree = "<group>"; };
+		517E03F824B7C0060054895A /* IOKitSPIMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IOKitSPIMac.h; sourceTree = "<group>"; };
 		570AB8F020AE2E8D00B8BE87 /* SecKeyProxySPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SecKeyProxySPI.h; sourceTree = "<group>"; };
 		570AB8F820AF6E3D00B8BE87 /* NSXPCConnectionSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSXPCConnectionSPI.h; sourceTree = "<group>"; };
 		572A107722B456F500F410C8 /* AuthKitSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AuthKitSPI.h; sourceTree = "<group>"; };
@@ -514,6 +516,7 @@
 				0C7785711F45130F00F4EBB6 /* DataDetectorsSPI.h */,
 				A102658D1F567E9D00B4C844 /* HIServicesSPI.h */,
 				A10265881F56747A00B4C844 /* HIToolboxSPI.h */,
+				517E03F824B7C0060054895A /* IOKitSPIMac.h */,
 				0C7785721F45130F00F4EBB6 /* LookupSPI.h */,
 				0C7785731F45130F00F4EBB6 /* MediaRemoteSPI.h */,
 				1CCEE4F620D8743F0047B097 /* NSAppearanceSPI.h */,
@@ -877,6 +880,7 @@
 				2E1342CC215AA10A007199D2 /* UIKitSoftLink.h in Headers */,
 				0C5AF9221F43A4C7002EAC02 /* UIKitSPI.h in Headers */,
 				0C2DA1471F3BEB4900DBC317 /* URLFormattingSPI.h in Headers */,
+				517E03F924B7C0070054895A /* IOKitSPIMac.h in Headers */,
 				07611DB6243FA5BF00D80704 /* UsageTrackingSoftLink.h in Headers */,
 				0C2DA1591F3BEB4900DBC317 /* WebFilterEvaluatorSPI.h in Headers */,
 				A10826F91F576292004772AC /* WebPanel.h in Headers */,

Copied: trunk/Source/WebCore/PAL/pal/spi/mac/IOKitSPIMac.h (from rev 264206, trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerSoftLink.h) (0 => 264207)


--- trunk/Source/WebCore/PAL/pal/spi/mac/IOKitSPIMac.h	                        (rev 0)
+++ trunk/Source/WebCore/PAL/pal/spi/mac/IOKitSPIMac.h	2020-07-10 01:27:58 UTC (rev 264207)
@@ -0,0 +1,43 @@
+/*
+ * 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 PLATFORM(MAC)
+#if USE(APPLE_INTERNAL_SDK)
+
+#import <IOKit/hid/IOHIDEventSystemClient.h>
+
+#else
+
+WTF_EXTERN_C_BEGIN
+typedef struct CF_BRIDGED_TYPE(id) __IOHIDEventSystemClient * IOHIDEventSystemClientRef;
+IOHIDEventSystemClientRef IOHIDEventSystemClientCreate(CFAllocatorRef);
+void IOHIDEventSystemClientSetMatching(IOHIDEventSystemClientRef, CFDictionaryRef);
+IOHIDServiceClientRef IOHIDEventSystemClientCopyServiceForRegistryID(IOHIDEventSystemClientRef, uint64_t registryID);
+WTF_EXTERN_C_END
+
+#endif // USE(APPLE_INTERNAL_SDK)
+#endif // PLATFORM(MAC)

Modified: trunk/Source/WebCore/SourcesCocoa.txt (264206 => 264207)


--- trunk/Source/WebCore/SourcesCocoa.txt	2020-07-10 01:27:19 UTC (rev 264206)
+++ trunk/Source/WebCore/SourcesCocoa.txt	2020-07-10 01:27:58 UTC (rev 264207)
@@ -257,7 +257,8 @@
 platform/gamepad/cocoa/GameControllerGamepad.mm
 platform/gamepad/cocoa/GameControllerGamepadProvider.mm
 platform/gamepad/mac/HIDGamepad.cpp
-platform/gamepad/mac/HIDGamepadProvider.cpp
+platform/gamepad/mac/HIDGamepadProvider.mm
+platform/gamepad/mac/MultiGamepadProvider.mm
 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 (264206 => 264207)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-07-10 01:27:19 UTC (rev 264206)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-07-10 01:27:58 UTC (rev 264207)
@@ -1472,6 +1472,7 @@
 		517A63C61B74319200E7DCDC /* KeyedEncoderCF.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A63C21B74317E00E7DCDC /* KeyedEncoderCF.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		517B25AA1CC82B2A0061C011 /* IDBConnectionProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 517B25A81CC820320061C011 /* IDBConnectionProxy.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		517DEEE81DE94B0800B91644 /* ScrollingMomentumCalculatorMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 517DEEE71DE94B0800B91644 /* ScrollingMomentumCalculatorMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		517E03F724B6D9840054895A /* MultiGamepadProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 517E03F424B6B9630054895A /* MultiGamepadProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		5182C2561F3143CD0059BA7C /* JSServiceWorker.h in Headers */ = {isa = PBXBuildFile; fileRef = 5182C2521F3142500059BA7C /* JSServiceWorker.h */; };
 		5182C2581F3143CD0059BA7C /* JSServiceWorkerContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 5182C2541F3142500059BA7C /* JSServiceWorkerContainer.h */; };
 		5182C25A1F3143CD0059BA7C /* JSServiceWorkerGlobalScope.h in Headers */ = {isa = PBXBuildFile; fileRef = 5182C24D1F3142500059BA7C /* JSServiceWorkerGlobalScope.h */; };
@@ -8279,7 +8280,7 @@
 		515BE18E1D54F5F600DD7C68 /* PlatformGamepad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformGamepad.h; sourceTree = "<group>"; };
 		515BE1971D54F6BD00DD7C68 /* HIDGamepad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HIDGamepad.cpp; sourceTree = "<group>"; };
 		515BE1981D54F6BD00DD7C68 /* HIDGamepad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HIDGamepad.h; sourceTree = "<group>"; };
-		515BE1991D54F6BD00DD7C68 /* HIDGamepadProvider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HIDGamepadProvider.cpp; sourceTree = "<group>"; };
+		515BE1991D54F6BD00DD7C68 /* HIDGamepadProvider.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = HIDGamepadProvider.mm; sourceTree = "<group>"; };
 		515BE19A1D54F6BD00DD7C68 /* HIDGamepadProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HIDGamepadProvider.h; sourceTree = "<group>"; };
 		515E37F41FAA938800D7F22A /* ServiceWorkerTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerTypes.h; sourceTree = "<group>"; };
 		515F79511CFCA3C700CCED93 /* WebCoreCrossThreadCopier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCoreCrossThreadCopier.cpp; sourceTree = "<group>"; };
@@ -8368,6 +8369,8 @@
 		517C87161F8FD4D300EB8076 /* ServiceWorkerContextData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerContextData.cpp; sourceTree = "<group>"; };
 		517DEEE31DE94ADC00B91644 /* ScrollingMomentumCalculatorMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollingMomentumCalculatorMac.mm; sourceTree = "<group>"; };
 		517DEEE71DE94B0800B91644 /* ScrollingMomentumCalculatorMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollingMomentumCalculatorMac.h; sourceTree = "<group>"; };
+		517E03F424B6B9630054895A /* MultiGamepadProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MultiGamepadProvider.h; sourceTree = "<group>"; };
+		517E03F524B6B9640054895A /* MultiGamepadProvider.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MultiGamepadProvider.mm; sourceTree = "<group>"; };
 		517FBA17151AA71B00B57959 /* DOMWindowExtension.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMWindowExtension.cpp; sourceTree = "<group>"; };
 		517FBA18151AA71B00B57959 /* DOMWindowExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMWindowExtension.h; sourceTree = "<group>"; };
 		5182C24B1F313AE00059BA7C /* NavigatorServiceWorker.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = NavigatorServiceWorker.idl; sourceTree = "<group>"; };
@@ -19575,8 +19578,10 @@
 			children = (
 				515BE1971D54F6BD00DD7C68 /* HIDGamepad.cpp */,
 				515BE1981D54F6BD00DD7C68 /* HIDGamepad.h */,
-				515BE1991D54F6BD00DD7C68 /* HIDGamepadProvider.cpp */,
+				515BE1991D54F6BD00DD7C68 /* HIDGamepadProvider.mm */,
 				515BE19A1D54F6BD00DD7C68 /* HIDGamepadProvider.h */,
+				517E03F424B6B9630054895A /* MultiGamepadProvider.h */,
+				517E03F524B6B9640054895A /* MultiGamepadProvider.mm */,
 			);
 			path = mac;
 			sourceTree = "<group>";
@@ -33269,6 +33274,7 @@
 				ECA680C71E67724500731D20 /* StringUtilities.h in Headers */,
 				9B6C41531344949000085B62 /* StringWithDirection.h in Headers */,
 				849F77760EFEC6200090849D /* StrokeStyleApplier.h in Headers */,
+				517E03F724B6D9840054895A /* MultiGamepadProvider.h in Headers */,
 				414B82051D6DF0E50077EBE3 /* StructuredClone.h in Headers */,
 				E45BA6B6237622A3004DFC07 /* StyleAdjuster.h in Headers */,
 				BC5EB6A30E81DC4F00B25965 /* StyleBackgroundData.h in Headers */,

Modified: trunk/Source/WebCore/platform/gamepad/PlatformGamepad.h (264206 => 264207)


--- trunk/Source/WebCore/platform/gamepad/PlatformGamepad.h	2020-07-10 01:27:19 UTC (rev 264206)
+++ trunk/Source/WebCore/platform/gamepad/PlatformGamepad.h	2020-07-10 01:27:58 UTC (rev 264207)
@@ -41,11 +41,13 @@
     const String& id() const { return m_id; }
     const String& mapping() const { return m_mapping; }
     unsigned index() const { return m_index; }
-    MonotonicTime lastUpdateTime() const { return m_lastUpdateTime; }
+    virtual MonotonicTime lastUpdateTime() const { return m_lastUpdateTime; }
     MonotonicTime connectTime() const { return m_connectTime; }
     virtual const Vector<double>& axisValues() const = 0;
     virtual const Vector<double>& buttonValues() const = 0;
 
+    virtual const char* source() const { return "Unknown"_s; }
+
 protected:
     explicit PlatformGamepad(unsigned index)
         : m_index(index)

Modified: trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.h (264206 => 264207)


--- trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.h	2020-07-10 01:27:19 UTC (rev 264206)
+++ trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.h	2020-07-10 01:27:58 UTC (rev 264207)
@@ -47,6 +47,8 @@
     const Vector<double>& axisValues() const final { return m_axisValues; }
     const Vector<double>& buttonValues() const final { return m_buttonValues; }
 
+    const char* source() const final { return "GameController"_s; }
+
 private:
     void setupAsExtendedGamepad();
     void setupAsGamepad();

Modified: trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.h (264206 => 264207)


--- trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.h	2020-07-10 01:27:19 UTC (rev 264206)
+++ trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.h	2020-07-10 01:27:58 UTC (rev 264207)
@@ -56,6 +56,8 @@
     void gamepadHadInput(GameControllerGamepad&, bool hadButtonPresses);
     void prewarmGameControllerDevicesIfNecessary();
 
+    void makeInvisibleGamepadsVisible();
+
 private:
     GameControllerGamepadProvider();
 
@@ -71,8 +73,6 @@
 
     void inputNotificationTimerFired();
 
-    void makeInvisibileGamepadsVisible();
-
     HashMap<CFTypeRef, std::unique_ptr<GameControllerGamepad>> m_gamepadMap;
     Vector<PlatformGamepad*> m_gamepadVector;
     HashSet<PlatformGamepad*> m_invisibleGamepads;
@@ -81,7 +81,7 @@
     RetainPtr<NSObject> m_disconnectObserver;
 
     RunLoop::Timer<GameControllerGamepadProvider> m_inputNotificationTimer;
-    bool m_shouldMakeInvisibileGamepadsVisible { false };
+    bool m_shouldMakeInvisibleGamepadsVisible { false };
 };
 
 } // namespace WebCore

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


--- trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.mm	2020-07-10 01:27:19 UTC (rev 264206)
+++ trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.mm	2020-07-10 01:27:58 UTC (rev 264207)
@@ -29,12 +29,13 @@
 #if ENABLE(GAMEPAD)
 
 #import "GameControllerGamepad.h"
-#import "GameControllerSoftLink.h"
 #import "GamepadProviderClient.h"
 #import "Logging.h"
 #import <GameController/GameController.h>
 #import <wtf/NeverDestroyed.h>
 
+#import "GameControllerSoftLink.h"
+
 namespace WebCore {
 
 static const Seconds inputNotificationDelay { 16_ms };
@@ -75,7 +76,7 @@
         return;
     }
 
-    makeInvisibileGamepadsVisible();
+    makeInvisibleGamepadsVisible();
 
     for (auto& client : m_clients)
         client->platformGamepadConnected(*m_gamepadVector[index], EventMakesGamepadsVisible::Yes);
@@ -170,10 +171,10 @@
         m_inputNotificationTimer.startOneShot(inputNotificationDelay);
 
     if (hadButtonPresses)
-        m_shouldMakeInvisibileGamepadsVisible = true;
+        m_shouldMakeInvisibleGamepadsVisible = true;
 }
 
-void GameControllerGamepadProvider::makeInvisibileGamepadsVisible()
+void GameControllerGamepadProvider::makeInvisibleGamepadsVisible()
 {
     for (auto* gamepad : m_invisibleGamepads) {
         for (auto& client : m_clients)
@@ -185,12 +186,12 @@
 
 void GameControllerGamepadProvider::inputNotificationTimerFired()
 {
-    if (m_shouldMakeInvisibileGamepadsVisible) {
+    if (m_shouldMakeInvisibleGamepadsVisible) {
         setShouldMakeGamepadsVisibile();
-        makeInvisibileGamepadsVisible();
+        makeInvisibleGamepadsVisible();
     }
 
-    m_shouldMakeInvisibileGamepadsVisible = false;
+    m_shouldMakeInvisibleGamepadsVisible = false;
 
     dispatchPlatformGamepadInputActivity();
 }

Modified: trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerSPI.h (264206 => 264207)


--- trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerSPI.h	2020-07-10 01:27:19 UTC (rev 264206)
+++ trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerSPI.h	2020-07-10 01:27:58 UTC (rev 264207)
@@ -31,4 +31,20 @@
 + (void)__openXPC_and_CBApplicationDidBecomeActive__;
 @end
 
+#if PLATFORM(MAC)
+#if USE(APPLE_INTERNAL_SDK)
+
+WTF_EXTERN_C_BEGIN
+#import <GameController/GCUtility.h>
+WTF_EXTERN_C_END
+
+#else
+
+WTF_EXTERN_C_BEGIN
+typedef struct CF_BRIDGED_TYPE(id) IOHIDServiceClient * IOHIDServiceClientRef;
+Class ControllerClassForService(IOHIDServiceClientRef);
+WTF_EXTERN_C_END
+
+#endif // USE(APPLE_INTERNAL_SDK)
+#endif // PLATFORM(MAC)
 #endif // ENABLE(GAMEPAD) && PLATFORM(COCOA)

Modified: trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerSoftLink.h (264206 => 264207)


--- trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerSoftLink.h	2020-07-10 01:27:19 UTC (rev 264206)
+++ trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerSoftLink.h	2020-07-10 01:27:58 UTC (rev 264207)
@@ -36,4 +36,8 @@
 SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(WebCore, GameController, GCControllerDidConnectNotification, NSString *)
 SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(WebCore, GameController, GCControllerDidDisconnectNotification, NSString *)
 
+#if PLATFORM(MAC)
+SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, GameController, ControllerClassForService, Class, (IOHIDServiceClientRef service), (service))
+#endif
+
 #endif // ENABLE(GAMEPAD) && PLATFORM(COCOA)

Modified: trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerSoftLink.mm (264206 => 264207)


--- trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerSoftLink.mm	2020-07-10 01:27:19 UTC (rev 264206)
+++ trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerSoftLink.mm	2020-07-10 01:27:58 UTC (rev 264207)
@@ -36,4 +36,8 @@
 SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE(WebCore, GameController, GCControllerDidConnectNotification, NSString *)
 SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE(WebCore, GameController, GCControllerDidDisconnectNotification, NSString *)
 
+#if PLATFORM(MAC)
+SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, GameController, ControllerClassForService, Class, (IOHIDServiceClientRef service), (service))
+#endif
+
 #endif // ENABLE(GAMEPAD) && PLATFORM(COCOA)

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


--- trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.h	2020-07-10 01:27:19 UTC (rev 264206)
+++ trunk/Source/WebCore/platform/gamepad/mac/HIDGamepad.h	2020-07-10 01:27:58 UTC (rev 264207)
@@ -121,6 +121,8 @@
     const Vector<double>& axisValues() const final { return m_axisValues; }
     const Vector<double>& buttonValues() const final { return m_buttonValues; }
 
+    const char* source() const final { return "HID"_s; }
+
 private:
     void initElements();
     void initElementsFromArray(CFArrayRef);

Deleted: trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.cpp (264206 => 264207)


--- trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.cpp	2020-07-10 01:27:19 UTC (rev 264206)
+++ trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.cpp	2020-07-10 01:27:58 UTC (rev 264207)
@@ -1,263 +0,0 @@
-/*
- * Copyright (C) 2014 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 "HIDGamepadProvider.h"
-
-#if ENABLE(GAMEPAD) && PLATFORM(MAC)
-
-#import "GamepadProviderClient.h"
-#import "Logging.h"
-#import "PlatformGamepad.h"
-#import <wtf/NeverDestroyed.h>
-
-namespace WebCore {
-
-static const Seconds connectionDelayInterval { 500_ms };
-static const Seconds inputNotificationDelay { 50_ms };
-
-static RetainPtr<CFDictionaryRef> deviceMatchingDictionary(uint32_t usagePage, uint32_t usage)
-{
-    ASSERT(usagePage);
-    ASSERT(usage);
-
-    RetainPtr<CFNumberRef> pageNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usagePage));
-    RetainPtr<CFNumberRef> usageNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage));
-
-    CFStringRef keys[] = { CFSTR(kIOHIDDeviceUsagePageKey), CFSTR(kIOHIDDeviceUsageKey) };
-    CFNumberRef values[] = { pageNumber.get(), usageNumber.get() };
-
-    return adoptCF(CFDictionaryCreate(kCFAllocatorDefault, (const void**)keys, (const void**)values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
-}
-
-static void deviceAddedCallback(void* context, IOReturn, void*, IOHIDDeviceRef device)
-{
-    HIDGamepadProvider* listener = static_cast<HIDGamepadProvider*>(context);
-    listener->deviceAdded(device);
-}
-
-static void deviceRemovedCallback(void* context, IOReturn, void*, IOHIDDeviceRef device)
-{
-    HIDGamepadProvider* listener = static_cast<HIDGamepadProvider*>(context);
-    listener->deviceRemoved(device);
-}
-
-static void deviceValuesChangedCallback(void* context, IOReturn result, void*, IOHIDValueRef value)
-{
-    // A non-zero result value indicates an error that we can do nothing about for input values.
-    if (result)
-        return;
-
-    HIDGamepadProvider* listener = static_cast<HIDGamepadProvider*>(context);
-    listener->valuesChanged(value);
-}
-
-HIDGamepadProvider& HIDGamepadProvider::singleton()
-{
-    static NeverDestroyed<HIDGamepadProvider> sharedListener;
-    return sharedListener;
-}
-
-HIDGamepadProvider::HIDGamepadProvider()
-    : m_initialGamepadsConnectedTimer(*this, &HIDGamepadProvider::initialGamepadsConnectedTimerFired)
-    , m_inputNotificationTimer(*this, &HIDGamepadProvider::inputNotificationTimerFired)
-{
-    m_manager = adoptCF(IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone));
-
-    RetainPtr<CFDictionaryRef> joystickDictionary = deviceMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick);
-    RetainPtr<CFDictionaryRef> gamepadDictionary = deviceMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad);
-
-    CFDictionaryRef devices[] = { joystickDictionary.get(), gamepadDictionary.get() };
-
-    RetainPtr<CFArrayRef> matchingArray = adoptCF(CFArrayCreate(kCFAllocatorDefault, (const void**)devices, 2, &kCFTypeArrayCallBacks));
-
-    IOHIDManagerSetDeviceMatchingMultiple(m_manager.get(), matchingArray.get());
-    IOHIDManagerRegisterDeviceMatchingCallback(m_manager.get(), deviceAddedCallback, this);
-    IOHIDManagerRegisterDeviceRemovalCallback(m_manager.get(), deviceRemovedCallback, this);
-
-    startMonitoringInput();
-}
-
-void HIDGamepadProvider::stopMonitoringInput()
-{
-    IGNORE_NULL_CHECK_WARNINGS_BEGIN
-    IOHIDManagerRegisterInputValueCallback(m_manager.get(), nullptr, nullptr);
-    IGNORE_NULL_CHECK_WARNINGS_END
-}
-
-void HIDGamepadProvider::startMonitoringInput()
-{
-    IOHIDManagerRegisterInputValueCallback(m_manager.get(), deviceValuesChangedCallback, this);
-}
-
-unsigned HIDGamepadProvider::indexForNewlyConnectedDevice()
-{
-    unsigned index = 0;
-    while (index < m_gamepadVector.size() && m_gamepadVector[index])
-        ++index;
-
-    return index;
-}
-
-void HIDGamepadProvider::initialGamepadsConnectedTimerFired()
-{
-    m_initialGamepadsConnected = true;
-}
-
-void HIDGamepadProvider::openAndScheduleManager()
-{
-    LOG(Gamepad, "HIDGamepadProvider opening/scheduling HID manager");
-
-    ASSERT(m_gamepadVector.isEmpty());
-    ASSERT(m_gamepadMap.isEmpty());
-
-    m_initialGamepadsConnected = false;
-
-    IOHIDManagerScheduleWithRunLoop(m_manager.get(), CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
-    IOHIDManagerOpen(m_manager.get(), kIOHIDOptionsTypeNone);
-
-    // Any connections we are notified of within the connectionDelayInterval of listening likely represent
-    // devices that were already connected, so we suppress notifying clients of these.
-    m_initialGamepadsConnectedTimer.startOneShot(connectionDelayInterval);
-}
-
-void HIDGamepadProvider::closeAndUnscheduleManager()
-{
-    LOG(Gamepad, "HIDGamepadProvider closing/unscheduling HID manager");
-
-    IOHIDManagerUnscheduleFromRunLoop(m_manager.get(), CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
-    IOHIDManagerClose(m_manager.get(), kIOHIDOptionsTypeNone);
-
-    m_gamepadVector.clear();
-    m_gamepadMap.clear();
-
-    m_initialGamepadsConnectedTimer.stop();
-}
-
-void HIDGamepadProvider::startMonitoringGamepads(GamepadProviderClient& client)
-{
-    bool shouldOpenAndScheduleManager = m_clients.isEmpty();
-
-    ASSERT(!m_clients.contains(&client));
-    m_clients.add(&client);
-
-    if (shouldOpenAndScheduleManager)
-        openAndScheduleManager();
-}
-void HIDGamepadProvider::stopMonitoringGamepads(GamepadProviderClient& client)
-{
-    ASSERT(m_clients.contains(&client));
-
-    bool shouldCloseAndUnscheduleManager = m_clients.remove(&client) && m_clients.isEmpty();
-
-    if (shouldCloseAndUnscheduleManager)
-        closeAndUnscheduleManager();
-}
-
-void HIDGamepadProvider::deviceAdded(IOHIDDeviceRef device)
-{
-    ASSERT(!m_gamepadMap.get(device));
-
-    LOG(Gamepad, "HIDGamepadProvider device %p added", device);
-
-    unsigned index = indexForNewlyConnectedDevice();
-    std::unique_ptr<HIDGamepad> gamepad = makeUnique<HIDGamepad>(device, index);
-
-    if (m_gamepadVector.size() <= index)
-        m_gamepadVector.grow(index + 1);
-
-    m_gamepadVector[index] = gamepad.get();
-    m_gamepadMap.set(device, WTFMove(gamepad));
-
-    if (!m_initialGamepadsConnected) {
-        // This added device is the result of us starting to monitor gamepads.
-        // We'll get notified of all connected devices during this current spin of the runloop
-        // and the client should be told they were already connected.
-        // The m_initialGamepadsConnectedTimer fires in a subsequent spin of the runloop after which
-        // any connection events are actual new devices and can trigger gamepad visibility.
-        if (!m_initialGamepadsConnectedTimer.isActive())
-            m_initialGamepadsConnectedTimer.startOneShot(0_s);
-    }
-
-    for (auto& client : m_clients)
-        client->platformGamepadConnected(*m_gamepadVector[index], m_initialGamepadsConnected ? EventMakesGamepadsVisible::Yes : EventMakesGamepadsVisible::No);
-}
-
-void HIDGamepadProvider::deviceRemoved(IOHIDDeviceRef device)
-{
-    LOG(Gamepad, "HIDGamepadProvider device %p removed", device);
-
-    std::unique_ptr<HIDGamepad> removedGamepad = removeGamepadForDevice(device);
-    ASSERT(removedGamepad);
-
-    for (auto& client : m_clients)
-        client->platformGamepadDisconnected(*removedGamepad);
-}
-
-void HIDGamepadProvider::valuesChanged(IOHIDValueRef value)
-{
-    IOHIDDeviceRef device = IOHIDElementGetDevice(IOHIDValueGetElement(value));
-
-    HIDGamepad* gamepad = m_gamepadMap.get(device);
-
-    // When starting monitoring we might get a value changed callback before we even know the device is connected.
-    if (!gamepad)
-        return;
-
-    if (gamepad->valueChanged(value) == HIDInputType::ButtonPress)
-        setShouldMakeGamepadsVisibile();
-
-    // This isActive check is necessary as we want to delay input notifications from the time of the first input,
-    // and not push the notification out on every subsequent input.
-    if (!m_inputNotificationTimer.isActive())
-        m_inputNotificationTimer.startOneShot(inputNotificationDelay);
-}
-
-void HIDGamepadProvider::inputNotificationTimerFired()
-{
-    if (!m_initialGamepadsConnected) {
-        if (!m_inputNotificationTimer.isActive())
-            m_inputNotificationTimer.startOneShot(0_s);
-        return;
-    }
-
-    dispatchPlatformGamepadInputActivity();
-}
-
-std::unique_ptr<HIDGamepad> HIDGamepadProvider::removeGamepadForDevice(IOHIDDeviceRef device)
-{
-    std::unique_ptr<HIDGamepad> result = m_gamepadMap.take(device);
-    ASSERT(result);
-
-    auto i = m_gamepadVector.find(result.get());
-    if (i != notFound)
-        m_gamepadVector[i] = nullptr;
-
-    return result;
-}
-
-} // namespace WebCore
-
-#endif // ENABLE(GAMEPAD) && PLATFORM(MAC)

Modified: trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.h (264206 => 264207)


--- trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.h	2020-07-10 01:27:19 UTC (rev 264206)
+++ trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.h	2020-07-10 01:27:58 UTC (rev 264207)
@@ -56,6 +56,8 @@
     void deviceRemoved(IOHIDDeviceRef);
     void valuesChanged(IOHIDValueRef);
 
+    void ignoreGameControllerFrameworkDevices() { m_ignoresGameControllerFrameworkDevices = true; }
+
 private:
     HIDGamepadProvider();
 
@@ -71,10 +73,12 @@
 
     Vector<PlatformGamepad*> m_gamepadVector;
     HashMap<IOHIDDeviceRef, std::unique_ptr<HIDGamepad>> m_gamepadMap;
+    HashSet<IOHIDDeviceRef> m_gameControllerManagedGamepads;
 
     RetainPtr<IOHIDManagerRef> m_manager;
 
     bool m_initialGamepadsConnected { false };
+    bool m_ignoresGameControllerFrameworkDevices { false };
 
     Timer m_initialGamepadsConnectedTimer;
     Timer m_inputNotificationTimer;

Copied: trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.mm (from rev 264206, trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.cpp) (0 => 264207)


--- trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.mm	2020-07-10 01:27:58 UTC (rev 264207)
@@ -0,0 +1,329 @@
+/*
+ * Copyright (C) 2014 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 "HIDGamepadProvider.h"
+
+#if ENABLE(GAMEPAD) && PLATFORM(MAC)
+
+#import "GamepadProviderClient.h"
+#import "Logging.h"
+#import "PlatformGamepad.h"
+#import <pal/spi/mac/IOKitSPIMac.h>
+#import <wtf/NeverDestroyed.h>
+
+#import "GameControllerSoftLink.h"
+
+namespace WebCore {
+
+static const Seconds connectionDelayInterval { 500_ms };
+static const Seconds hidInputNotificationDelay { 50_ms };
+
+static RetainPtr<CFDictionaryRef> deviceMatchingDictionary(uint32_t usagePage, uint32_t usage)
+{
+    ASSERT(usagePage);
+    ASSERT(usage);
+
+    RetainPtr<CFNumberRef> pageNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usagePage));
+    RetainPtr<CFNumberRef> usageNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage));
+
+    CFStringRef keys[] = { CFSTR(kIOHIDDeviceUsagePageKey), CFSTR(kIOHIDDeviceUsageKey) };
+    CFNumberRef values[] = { pageNumber.get(), usageNumber.get() };
+
+    return adoptCF(CFDictionaryCreate(kCFAllocatorDefault, (const void**)keys, (const void**)values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
+}
+
+static void deviceAddedCallback(void* context, IOReturn, void*, IOHIDDeviceRef device)
+{
+    HIDGamepadProvider* listener = static_cast<HIDGamepadProvider*>(context);
+    listener->deviceAdded(device);
+}
+
+static void deviceRemovedCallback(void* context, IOReturn, void*, IOHIDDeviceRef device)
+{
+    HIDGamepadProvider* listener = static_cast<HIDGamepadProvider*>(context);
+    listener->deviceRemoved(device);
+}
+
+static void deviceValuesChangedCallback(void* context, IOReturn result, void*, IOHIDValueRef value)
+{
+    // A non-zero result value indicates an error that we can do nothing about for input values.
+    if (result)
+        return;
+
+    HIDGamepadProvider* listener = static_cast<HIDGamepadProvider*>(context);
+    listener->valuesChanged(value);
+}
+
+HIDGamepadProvider& HIDGamepadProvider::singleton()
+{
+    static NeverDestroyed<HIDGamepadProvider> sharedListener;
+    return sharedListener;
+}
+
+HIDGamepadProvider::HIDGamepadProvider()
+    : m_initialGamepadsConnectedTimer(*this, &HIDGamepadProvider::initialGamepadsConnectedTimerFired)
+    , m_inputNotificationTimer(*this, &HIDGamepadProvider::inputNotificationTimerFired)
+{
+    m_manager = adoptCF(IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone));
+
+    RetainPtr<CFDictionaryRef> joystickDictionary = deviceMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick);
+    RetainPtr<CFDictionaryRef> gamepadDictionary = deviceMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad);
+
+    CFDictionaryRef devices[] = { joystickDictionary.get(), gamepadDictionary.get() };
+
+    RetainPtr<CFArrayRef> matchingArray = adoptCF(CFArrayCreate(kCFAllocatorDefault, (const void**)devices, 2, &kCFTypeArrayCallBacks));
+
+    IOHIDManagerSetDeviceMatchingMultiple(m_manager.get(), matchingArray.get());
+    IOHIDManagerRegisterDeviceMatchingCallback(m_manager.get(), deviceAddedCallback, this);
+    IOHIDManagerRegisterDeviceRemovalCallback(m_manager.get(), deviceRemovedCallback, this);
+
+    startMonitoringInput();
+}
+
+void HIDGamepadProvider::stopMonitoringInput()
+{
+    IGNORE_NULL_CHECK_WARNINGS_BEGIN
+    IOHIDManagerRegisterInputValueCallback(m_manager.get(), nullptr, nullptr);
+    IGNORE_NULL_CHECK_WARNINGS_END
+}
+
+void HIDGamepadProvider::startMonitoringInput()
+{
+    IOHIDManagerRegisterInputValueCallback(m_manager.get(), deviceValuesChangedCallback, this);
+}
+
+unsigned HIDGamepadProvider::indexForNewlyConnectedDevice()
+{
+    unsigned index = 0;
+    while (index < m_gamepadVector.size() && m_gamepadVector[index])
+        ++index;
+
+    return index;
+}
+
+void HIDGamepadProvider::initialGamepadsConnectedTimerFired()
+{
+    m_initialGamepadsConnected = true;
+}
+
+void HIDGamepadProvider::openAndScheduleManager()
+{
+    LOG(Gamepad, "HIDGamepadProvider opening/scheduling HID manager");
+
+    ASSERT(m_gamepadVector.isEmpty());
+    ASSERT(m_gamepadMap.isEmpty());
+
+    m_initialGamepadsConnected = false;
+
+    IOHIDManagerScheduleWithRunLoop(m_manager.get(), CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
+    IOHIDManagerOpen(m_manager.get(), kIOHIDOptionsTypeNone);
+
+    // Any connections we are notified of within the connectionDelayInterval of listening likely represent
+    // devices that were already connected, so we suppress notifying clients of these.
+    m_initialGamepadsConnectedTimer.startOneShot(connectionDelayInterval);
+}
+
+void HIDGamepadProvider::closeAndUnscheduleManager()
+{
+    LOG(Gamepad, "HIDGamepadProvider closing/unscheduling HID manager");
+
+    IOHIDManagerUnscheduleFromRunLoop(m_manager.get(), CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
+    IOHIDManagerClose(m_manager.get(), kIOHIDOptionsTypeNone);
+
+    m_gamepadVector.clear();
+    m_gamepadMap.clear();
+
+    m_initialGamepadsConnectedTimer.stop();
+}
+
+void HIDGamepadProvider::startMonitoringGamepads(GamepadProviderClient& client)
+{
+    bool shouldOpenAndScheduleManager = m_clients.isEmpty();
+
+    ASSERT(!m_clients.contains(&client));
+    m_clients.add(&client);
+
+    if (shouldOpenAndScheduleManager)
+        openAndScheduleManager();
+}
+void HIDGamepadProvider::stopMonitoringGamepads(GamepadProviderClient& client)
+{
+    ASSERT(m_clients.contains(&client));
+
+    bool shouldCloseAndUnscheduleManager = m_clients.remove(&client) && m_clients.isEmpty();
+
+    if (shouldCloseAndUnscheduleManager)
+        closeAndUnscheduleManager();
+}
+
+static bool gameControllerFrameworkWillHandleHIDDevice(IOHIDDeviceRef device)
+{
+    if (!isGameControllerFrameworkAvailable())
+        return false;
+
+    auto deviceService = IOHIDDeviceGetService(device);
+    if (!deviceService)
+        return false;
+
+    // Check the service directly backing this device
+    uint64_t registryID;
+    if (IORegistryEntryGetRegistryEntryID(deviceService, &registryID) != KERN_SUCCESS)
+        return false;
+
+    auto eventSystemClient = adoptCF(IOHIDEventSystemClientCreate(nullptr));
+    IOHIDEventSystemClientSetMatching(eventSystemClient.get(), nullptr);
+    auto serviceClient = adoptCF(IOHIDEventSystemClientCopyServiceForRegistryID(eventSystemClient.get(), registryID));
+    if (serviceClient) {
+        if (ControllerClassForService(serviceClient.get()))
+            return true;
+    }
+
+    // Otherwise, check its grandchild service
+    io_registry_entry_t child;
+    if (IORegistryEntryGetChildEntry(deviceService, kIOServicePlane, &child) != KERN_SUCCESS)
+        return false;
+    if (!child)
+        return false;
+
+    if (IORegistryEntryGetChildEntry(child, kIOServicePlane, &child) != KERN_SUCCESS)
+        return false;
+    if (!child)
+        return false;
+
+    if (IORegistryEntryGetRegistryEntryID(child, &registryID) != KERN_SUCCESS)
+        return false;
+
+    serviceClient = adoptCF(IOHIDEventSystemClientCopyServiceForRegistryID(eventSystemClient.get(), registryID));
+    if (!serviceClient)
+        return false;
+
+    return ControllerClassForService(serviceClient.get());
+}
+
+void HIDGamepadProvider::deviceAdded(IOHIDDeviceRef device)
+{
+    if (m_ignoresGameControllerFrameworkDevices && gameControllerFrameworkWillHandleHIDDevice(device)) {
+        LOG(Gamepad, "GameController framework will handle attached device %p - HIDGamepadProvider ignoring it", device);
+        m_gameControllerManagedGamepads.add(device);
+        return;
+    }
+
+    ASSERT(!m_gamepadMap.get(device));
+
+    LOG(Gamepad, "HIDGamepadProvider device %p added", device);
+
+    unsigned index = indexForNewlyConnectedDevice();
+    std::unique_ptr<HIDGamepad> gamepad = makeUnique<HIDGamepad>(device, index);
+
+    if (m_gamepadVector.size() <= index)
+        m_gamepadVector.grow(index + 1);
+
+    m_gamepadVector[index] = gamepad.get();
+    m_gamepadMap.set(device, WTFMove(gamepad));
+
+    if (!m_initialGamepadsConnected) {
+        // This added device is the result of us starting to monitor gamepads.
+        // We'll get notified of all connected devices during this current spin of the runloop
+        // and the client should be told they were already connected.
+        // The m_initialGamepadsConnectedTimer fires in a subsequent spin of the runloop after which
+        // any connection events are actual new devices and can trigger gamepad visibility.
+        if (!m_initialGamepadsConnectedTimer.isActive())
+            m_initialGamepadsConnectedTimer.startOneShot(0_s);
+    }
+
+    auto eventVisibility = m_initialGamepadsConnected ? EventMakesGamepadsVisible::Yes : EventMakesGamepadsVisible::No;
+    for (auto& client : m_clients)
+        client->platformGamepadConnected(*m_gamepadVector[index], eventVisibility);
+
+    // If we are working together with the GameController provider, let it know
+    // that gamepads should now be visible.
+    if (m_ignoresGameControllerFrameworkDevices && eventVisibility == EventMakesGamepadsVisible::Yes)
+        GameControllerGamepadProvider::singleton().makeInvisibleGamepadsVisible();
+}
+
+void HIDGamepadProvider::deviceRemoved(IOHIDDeviceRef device)
+{
+    std::unique_ptr<HIDGamepad> removedGamepad = removeGamepadForDevice(device);
+
+    if (!removedGamepad) {
+        auto taken = m_gameControllerManagedGamepads.take(device);
+        ASSERT_UNUSED(taken, taken);
+        LOG(Gamepad, "HIDGamepadProvider informed of removal of device %p, which is managed by GameController framework. Ignoring.", device);
+        return;
+    }
+
+    LOG(Gamepad, "HIDGamepadProvider device %p removed", device);
+
+    for (auto& client : m_clients)
+        client->platformGamepadDisconnected(*removedGamepad);
+}
+
+void HIDGamepadProvider::valuesChanged(IOHIDValueRef value)
+{
+    IOHIDDeviceRef device = IOHIDElementGetDevice(IOHIDValueGetElement(value));
+
+    HIDGamepad* gamepad = m_gamepadMap.get(device);
+
+    // When starting monitoring we might get a value changed callback before we even know the device is connected.
+    if (!gamepad)
+        return;
+
+    if (gamepad->valueChanged(value) == HIDInputType::ButtonPress)
+        setShouldMakeGamepadsVisibile();
+
+    // This isActive check is necessary as we want to delay input notifications from the time of the first input,
+    // and not push the notification out on every subsequent input.
+    if (!m_inputNotificationTimer.isActive())
+        m_inputNotificationTimer.startOneShot(hidInputNotificationDelay);
+}
+
+void HIDGamepadProvider::inputNotificationTimerFired()
+{
+    if (!m_initialGamepadsConnected) {
+        if (!m_inputNotificationTimer.isActive())
+            m_inputNotificationTimer.startOneShot(0_s);
+        return;
+    }
+
+    dispatchPlatformGamepadInputActivity();
+}
+
+std::unique_ptr<HIDGamepad> HIDGamepadProvider::removeGamepadForDevice(IOHIDDeviceRef device)
+{
+    std::unique_ptr<HIDGamepad> result = m_gamepadMap.take(device);
+    if (!result)
+        return nullptr;
+
+    auto i = m_gamepadVector.find(result.get());
+    if (i != notFound)
+        m_gamepadVector[i] = nullptr;
+
+    return result;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD) && PLATFORM(MAC)

Added: trunk/Source/WebCore/platform/gamepad/mac/MultiGamepadProvider.h (0 => 264207)


--- trunk/Source/WebCore/platform/gamepad/mac/MultiGamepadProvider.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/gamepad/mac/MultiGamepadProvider.h	2020-07-10 01:27:58 UTC (rev 264207)
@@ -0,0 +1,94 @@
+/*
+ * 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 "GamepadProvider.h"
+#include "GamepadProviderClient.h"
+#include <wtf/Forward.h>
+#include <wtf/HashSet.h>
+
+namespace WebCore {
+
+class MultiGamepadProvider : public GamepadProvider, public GamepadProviderClient {
+public:
+    virtual ~MultiGamepadProvider() = default;
+
+    WEBCORE_EXPORT static MultiGamepadProvider& singleton();
+
+    // GamepadProvider
+    void startMonitoringGamepads(GamepadProviderClient&) final;
+    void stopMonitoringGamepads(GamepadProviderClient&) final;
+    const Vector<PlatformGamepad*>& platformGamepads() final { return m_gamepadVector; }
+    bool isMockGamepadProvider() const { return false; }
+
+    // GamepadProviderClient
+    void platformGamepadConnected(PlatformGamepad&, EventMakesGamepadsVisible) final;
+    void platformGamepadDisconnected(PlatformGamepad&) final;
+    void platformGamepadInputActivity(EventMakesGamepadsVisible) final;
+
+protected:
+    WEBCORE_EXPORT void dispatchPlatformGamepadInputActivity();
+
+private:
+    unsigned indexForNewlyConnectedDevice();
+
+    bool m_shouldMakeGamepadsVisible { false };
+    size_t m_initialGamepadsCount { 0 };
+    Vector<PlatformGamepad*> m_gamepadVector;
+
+    // We create our own Gamepad type - to wrap both HID and GameControler gamepads -
+    // because MultiGamepadProvider needs to manage the indexes of its own gamepads
+    // no matter what the HID or GameController index is.
+    class PlatformGamepadWrapper : public PlatformGamepad {
+    public:
+        PlatformGamepadWrapper(unsigned index, PlatformGamepad* wrapped)
+            : PlatformGamepad(index)
+            , m_platformGamepad(wrapped)
+        {
+            m_id = wrapped->id();
+            m_mapping = wrapped->mapping();
+            m_connectTime = wrapped->connectTime();
+        }
+
+        MonotonicTime lastUpdateTime() const final { return m_platformGamepad->lastUpdateTime(); }
+        const Vector<double>& axisValues() const final { return m_platformGamepad->axisValues(); }
+        const Vector<double>& buttonValues() const final { return m_platformGamepad->buttonValues(); }
+
+        const char* source() const final { return m_platformGamepad->source(); }
+
+    private:
+        PlatformGamepad* m_platformGamepad;
+    };
+
+    HashMap<PlatformGamepad*, std::unique_ptr<PlatformGamepadWrapper>> m_gamepadMap;
+    bool m_hidImportComplete { false };
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD) && PLATFORM(MAC)

Added: trunk/Source/WebCore/platform/gamepad/mac/MultiGamepadProvider.mm (0 => 264207)


--- trunk/Source/WebCore/platform/gamepad/mac/MultiGamepadProvider.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/gamepad/mac/MultiGamepadProvider.mm	2020-07-10 01:27:58 UTC (rev 264207)
@@ -0,0 +1,132 @@
+/*
+ * 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 "MultiGamepadProvider.h"
+
+#if ENABLE(GAMEPAD) && PLATFORM(MAC)
+
+#import "GameControllerGamepadProvider.h"
+#import "HIDGamepadProvider.h"
+#import "Logging.h"
+#import "PlatformGamepad.h"
+#import <wtf/NeverDestroyed.h>
+
+namespace WebCore {
+
+static size_t numberOfGamepadProviders = 2;
+
+MultiGamepadProvider& MultiGamepadProvider::singleton()
+{
+    static NeverDestroyed<MultiGamepadProvider> sharedProvider;
+    return sharedProvider;
+}
+
+void MultiGamepadProvider::startMonitoringGamepads(GamepadProviderClient& client)
+{
+    bool monitorOtherProviders = m_clients.isEmpty();
+
+    ASSERT(!m_clients.contains(&client));
+    m_clients.add(&client);
+
+    HIDGamepadProvider::singleton().ignoreGameControllerFrameworkDevices();
+    GameControllerGamepadProvider::singleton().prewarmGameControllerDevicesIfNecessary();
+
+    if (monitorOtherProviders) {
+        HIDGamepadProvider::singleton().startMonitoringGamepads(*this);
+        GameControllerGamepadProvider::singleton().startMonitoringGamepads(*this);
+    }
+}
+
+void MultiGamepadProvider::stopMonitoringGamepads(GamepadProviderClient& client)
+{
+    ASSERT(m_clients.contains(&client));
+
+    bool shouldStopMonitoringOtherProviders = m_clients.remove(&client) && m_clients.isEmpty();
+
+    if (shouldStopMonitoringOtherProviders) {
+        HIDGamepadProvider::singleton().stopMonitoringGamepads(*this);
+        GameControllerGamepadProvider::singleton().stopMonitoringGamepads(*this);
+    }
+}
+
+unsigned MultiGamepadProvider::indexForNewlyConnectedDevice()
+{
+    unsigned index = 0;
+    while (index < m_gamepadVector.size() && m_gamepadVector[index])
+        ++index;
+
+    ASSERT(index <= m_gamepadVector.size());
+
+    if (index == m_gamepadVector.size())
+        m_gamepadVector.resize(index + 1);
+
+    return index;
+}
+
+void MultiGamepadProvider::platformGamepadConnected(PlatformGamepad& gamepad, EventMakesGamepadsVisible eventVisibility)
+{
+    auto index = indexForNewlyConnectedDevice();
+
+    LOG(Gamepad, "MultiGamepadProvider adding new platform gamepad to index %i from a %s source", index, gamepad.source());
+
+    ASSERT(m_gamepadVector.size() > index);
+
+    auto addResult = m_gamepadMap.set(&gamepad, WTF::makeUnique<PlatformGamepadWrapper>(index, &gamepad));
+    ASSERT(addResult.isNewEntry);
+    m_gamepadVector[index] = addResult.iterator->value.get();
+
+    for (auto& client : m_clients)
+        client->platformGamepadConnected(*m_gamepadVector[index], eventVisibility);
+}
+
+void MultiGamepadProvider::platformGamepadDisconnected(PlatformGamepad& gamepad)
+{
+    LOG(Gamepad, "MultiGamepadProvider disconnecting gamepad from a %s source", gamepad.source());
+
+    auto gamepadWrapper = m_gamepadMap.take(&gamepad);
+
+    ASSERT(gamepadWrapper);
+    ASSERT(gamepadWrapper->index() < m_gamepadVector.size());
+    ASSERT(m_gamepadVector[gamepadWrapper->index()] == gamepadWrapper.get());
+
+    m_gamepadVector[gamepadWrapper->index()] = nullptr;
+
+    for (auto& client : m_clients)
+        client->platformGamepadDisconnected(*gamepadWrapper);
+}
+
+void MultiGamepadProvider::platformGamepadInputActivity(EventMakesGamepadsVisible eventVisibility)
+{
+    if (eventVisibility == EventMakesGamepadsVisible::Yes)
+        GameControllerGamepadProvider::singleton().makeInvisibleGamepadsVisible();
+
+    for (auto& client : m_clients)
+        client->platformGamepadInputActivity(eventVisibility);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(GAMEPAD) && PLATFORM(MAC)

Modified: trunk/Source/WebKit/ChangeLog (264206 => 264207)


--- trunk/Source/WebKit/ChangeLog	2020-07-10 01:27:19 UTC (rev 264206)
+++ trunk/Source/WebKit/ChangeLog	2020-07-10 01:27:58 UTC (rev 264207)
@@ -1,3 +1,13 @@
+2020-07-09  Brady Eidson  <[email protected]>
+
+        Multiplex the HID and GameController gamepad providers on Mac.
+        <rdar://problem/63192532> and https://bugs.webkit.org/show_bug.cgi?id=214126
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/Gamepad/cocoa/UIGamepadProviderCocoa.mm:
+        (WebKit::UIGamepadProvider::platformSetDefaultGamepadProvider):
+
 2020-07-09  Tim Horton  <[email protected]>
 
         "ESPN Fantasy Sports" does not respond to mouse events, only touch events

Modified: trunk/Source/WebKit/UIProcess/Gamepad/cocoa/UIGamepadProviderCocoa.mm (264206 => 264207)


--- trunk/Source/WebKit/UIProcess/Gamepad/cocoa/UIGamepadProviderCocoa.mm	2020-07-10 01:27:19 UTC (rev 264206)
+++ trunk/Source/WebKit/UIProcess/Gamepad/cocoa/UIGamepadProviderCocoa.mm	2020-07-10 01:27:58 UTC (rev 264207)
@@ -31,6 +31,7 @@
 #import <WebCore/GameControllerGamepadProvider.h>
 #import <WebCore/HIDGamepadProvider.h>
 #import <WebCore/MockGamepadProvider.h>
+#import <WebCore/MultiGamepadProvider.h>
 
 namespace WebKit {
 using namespace WebCore;
@@ -53,7 +54,7 @@
     if (useGameControllerFramework)
         GamepadProvider::setSharedProvider(GameControllerGamepadProvider::singleton());
     else
-        GamepadProvider::setSharedProvider(HIDGamepadProvider::singleton());
+        GamepadProvider::setSharedProvider(MultiGamepadProvider::singleton());
 #endif
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to