Title: [264143] trunk/Source
Revision
264143
Author
[email protected]
Date
2020-07-08 18:20:16 -0700 (Wed, 08 Jul 2020)

Log Message

Aggressively prime GameController.framework gamepad provider.
https://bugs.webkit.org/show_bug.cgi?id=214094

Reviewed by Darin Adler.

Source/WebCore:

GameController.framework gets itself going by listening for application activation,
assuming that it is hard linked.

Soft linking breaks this.

There's an SPI to manually kickstart it.

Also add some logging I'd added while exploring issues around this.

* platform/gamepad/cocoa/GameControllerGamepadProvider.h:
* platform/gamepad/cocoa/GameControllerGamepadProvider.mm:
(WebCore::GameControllerGamepadProvider::controllerDidConnect):
(WebCore::GameControllerGamepadProvider::prewarmGameControllerDevicesIfNecessary):
(WebCore::GameControllerGamepadProvider::startMonitoringGamepads):
* platform/gamepad/cocoa/GameControllerSPI.h:

Source/WebKit:

* WebProcess/Gamepad/WebGamepadProvider.cpp:
(WebKit::WebGamepadProvider::gamepadConnected):
(WebKit::WebGamepadProvider::gamepadDisconnected):
(WebKit::WebGamepadProvider::gamepadActivity):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (264142 => 264143)


--- trunk/Source/WebCore/ChangeLog	2020-07-09 00:14:42 UTC (rev 264142)
+++ trunk/Source/WebCore/ChangeLog	2020-07-09 01:20:16 UTC (rev 264143)
@@ -1,3 +1,26 @@
+2020-07-08  Brady Eidson  <[email protected]>
+
+        Aggressively prime GameController.framework gamepad provider.
+        https://bugs.webkit.org/show_bug.cgi?id=214094
+
+        Reviewed by Darin Adler.
+
+        GameController.framework gets itself going by listening for application activation, 
+        assuming that it is hard linked.
+        
+        Soft linking breaks this.
+        
+        There's an SPI to manually kickstart it.
+        
+        Also add some logging I'd added while exploring issues around this.
+
+        * platform/gamepad/cocoa/GameControllerGamepadProvider.h:
+        * platform/gamepad/cocoa/GameControllerGamepadProvider.mm:
+        (WebCore::GameControllerGamepadProvider::controllerDidConnect):
+        (WebCore::GameControllerGamepadProvider::prewarmGameControllerDevicesIfNecessary):
+        (WebCore::GameControllerGamepadProvider::startMonitoringGamepads):
+        * platform/gamepad/cocoa/GameControllerSPI.h:
+
 2020-07-08  Sam Weinig  <[email protected]>
 
         Part 3 of SimpleColor and SRGBA<uint8_t> are essentially the same - let's converge them

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


--- trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.h	2020-07-09 00:14:42 UTC (rev 264142)
+++ trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.h	2020-07-09 01:20:16 UTC (rev 264143)
@@ -54,6 +54,7 @@
     WEBCORE_EXPORT void startMonitoringInput();
 
     void gamepadHadInput(GameControllerGamepad&, bool hadButtonPresses);
+    void prewarmGameControllerDevicesIfNecessary();
 
 private:
     GameControllerGamepadProvider();

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


--- trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.mm	2020-07-09 00:14:42 UTC (rev 264142)
+++ trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.mm	2020-07-09 01:20:16 UTC (rev 264143)
@@ -55,6 +55,11 @@
 {
     LOG(Gamepad, "GameControllerGamepadProvider controller %p added", controller);
 
+    // When initially starting up the GameController framework machinery,
+    // we might get the connection notification for an already-connected controller.
+    if (m_gamepadMap.contains(controller))
+        return;
+
     unsigned index = indexForNewlyConnectedDevice();
     auto gamepad = makeUnique<GameControllerGamepad>(controller, index);
 
@@ -93,6 +98,17 @@
         client->platformGamepadDisconnected(*removedGamepad);
 }
 
+void GameControllerGamepadProvider::prewarmGameControllerDevicesIfNecessary()
+{
+    static bool prewarmed;
+    if (prewarmed)
+        return;
+
+    LOG(Gamepad, "GameControllerGamepadProvider explicitly starting GameController framework monitoring");
+    [getGCControllerClass() __openXPC_and_CBApplicationDidBecomeActive__];
+    prewarmed = true;
+}
+
 void GameControllerGamepadProvider::startMonitoringGamepads(GamepadProviderClient& client)
 {
     ASSERT(!m_clients.contains(&client));
@@ -101,8 +117,11 @@
     if (m_connectObserver)
         return;
 
+    prewarmGameControllerDevicesIfNecessary();
+
     if (canLoad_GameController_GCControllerDidConnectNotification()) {
         m_connectObserver = [[NSNotificationCenter defaultCenter] addObserverForName:get_GameController_GCControllerDidConnectNotification() object:nil queue:nil usingBlock:^(NSNotification *notification) {
+            LOG(Gamepad, "GameControllerGamepadProvider notified of new GCController %p", notification.object);
             GameControllerGamepadProvider::singleton().controllerDidConnect(notification.object, ConnectionVisibility::Visible);
         }];
     }
@@ -109,12 +128,19 @@
 
     if (canLoad_GameController_GCControllerDidDisconnectNotification()) {
         m_disconnectObserver = [[NSNotificationCenter defaultCenter] addObserverForName:get_GameController_GCControllerDidDisconnectNotification() object:nil queue:nil usingBlock:^(NSNotification *notification) {
+            LOG(Gamepad, "GameControllerGamepadProvider notified of disconnected GCController %p", notification.object);
             GameControllerGamepadProvider::singleton().controllerDidDisconnect(notification.object);
         }];
     }
 
-    for (GCController *controller in [getGCControllerClass() controllers])
+    auto *controllers = [getGCControllerClass() controllers];
+    if (!controllers || !controllers.count)
+        LOG(Gamepad, "GameControllerGamepadProvider has no initial GCControllers attached");
+
+    for (GCController *controller in controllers) {
+        LOG(Gamepad, "GameControllerGamepadProvider has initial GCController %p", controller);
         controllerDidConnect(controller, ConnectionVisibility::Invisible);
+    }
 }
 
 void GameControllerGamepadProvider::stopMonitoringGamepads(GamepadProviderClient& client)

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


--- trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerSPI.h	2020-07-09 00:14:42 UTC (rev 264142)
+++ trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerSPI.h	2020-07-09 01:20:16 UTC (rev 264143)
@@ -25,6 +25,10 @@
 
 #if ENABLE(GAMEPAD) && PLATFORM(COCOA)
 
-// FIXME: Refactor more GC framework stuff into this header
+#import <GameController/GCController.h>
 
+@interface GCController ()
++ (void)__openXPC_and_CBApplicationDidBecomeActive__;
+@end
+
 #endif // ENABLE(GAMEPAD) && PLATFORM(COCOA)

Modified: trunk/Source/WebKit/ChangeLog (264142 => 264143)


--- trunk/Source/WebKit/ChangeLog	2020-07-09 00:14:42 UTC (rev 264142)
+++ trunk/Source/WebKit/ChangeLog	2020-07-09 01:20:16 UTC (rev 264143)
@@ -1,3 +1,15 @@
+2020-07-08  Brady Eidson  <[email protected]>
+
+        Aggressively prime GameController.framework gamepad provider.
+        https://bugs.webkit.org/show_bug.cgi?id=214094
+
+        Reviewed by Darin Adler.
+
+        * WebProcess/Gamepad/WebGamepadProvider.cpp:
+        (WebKit::WebGamepadProvider::gamepadConnected):
+        (WebKit::WebGamepadProvider::gamepadDisconnected):
+        (WebKit::WebGamepadProvider::gamepadActivity):
+
 2020-07-08  Commit Queue  <[email protected]>
 
         Unreviewed, reverting r264132 and r264139.

Modified: trunk/Source/WebKit/WebProcess/Gamepad/WebGamepadProvider.cpp (264142 => 264143)


--- trunk/Source/WebKit/WebProcess/Gamepad/WebGamepadProvider.cpp	2020-07-09 00:14:42 UTC (rev 264142)
+++ trunk/Source/WebKit/WebProcess/Gamepad/WebGamepadProvider.cpp	2020-07-09 01:20:16 UTC (rev 264143)
@@ -69,7 +69,7 @@
 
 void WebGamepadProvider::gamepadConnected(const GamepadData& gamepadData, EventMakesGamepadsVisible eventVisibility)
 {
-    LOG(Gamepad, "WebGamepadProvider::gamepadConnected - Index %i attached (visibility: %i)\n", gamepadData.index(), (int)eventVisibility);
+    LOG(Gamepad, "WebGamepadProvider::gamepadConnected - Gamepad index %u attached (visibility: %i)\n", gamepadData.index(), (int)eventVisibility);
 
     if (m_gamepads.size() <= gamepadData.index()) {
         m_gamepads.resize(gamepadData.index() + 1);
@@ -92,6 +92,8 @@
     std::unique_ptr<WebGamepad> disconnectedGamepad = WTFMove(m_gamepads[index]);
     m_rawGamepads[index] = nullptr;
 
+    LOG(Gamepad, "WebGamepadProvider::gamepadDisconnected - Gamepad index %u detached (m_gamepads size %zu, m_rawGamepads size %zu\n", index, m_gamepads.size(), m_rawGamepads.size());
+
     for (auto* client : m_clients)
         client->platformGamepadDisconnected(*disconnectedGamepad);
 }
@@ -98,6 +100,8 @@
 
 void WebGamepadProvider::gamepadActivity(const Vector<GamepadData>& gamepadDatas, EventMakesGamepadsVisible eventVisibility)
 {
+    LOG(Gamepad, "WebGamepadProvider::gamepadActivity - %zu gamepad datas with %zu local web gamepads\n", gamepadDatas.size(), m_gamepads.size());
+
     ASSERT(m_gamepads.size() == gamepadDatas.size());
 
     for (size_t i = 0; i < m_gamepads.size(); ++i) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to