Bug 214094

Summary: Aggressively prime GameController.framework gamepad provider
Product: WebKit Reporter: Brady Eidson <beidson>
Component: WebCore Misc.Assignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: darin, thorton, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
darin: review+
PFL none

Description Brady Eidson 2020-07-08 12:52:58 PDT
Aggressively prime GameController.framework gamepad provider

GC.framework does some work on app activation assuming it was hard linked.

Since we soft link it, it doesn't quite work right.

So let's give it a kickstart.
Comment 1 Brady Eidson 2020-07-08 16:05:14 PDT
Created attachment 403815 [details]
Patch
Comment 2 Darin Adler 2020-07-08 16:30:44 PDT
Comment on attachment 403815 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=403815&action=review

> Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.mm:107
> +    static dispatch_once_t onceToken;
> +    dispatch_once(&onceToken, ^{
> +        LOG(Gamepad, "GameControllerGamepadProvider explicitly starting GameController framework monitoring");
> +        [getGCControllerClass() __openXPC_and_CBApplicationDidBecomeActive__];
> +    });

Is thread safety an issue here? Otherwise, we would probably just want to use a boolean, not a dispatch_once_t.

> Source/WebKit/WebProcess/Gamepad/WebGamepadProvider.cpp:72
> +    LOG(Gamepad, "WebGamepadProvider::gamepadConnected - Gamepad index %i attached (visibility: %i)\n", gamepadData.index(), (int)eventVisibility);

Since gamepadData.index() is an unsigned, this should be %u, not %i.

> Source/WebKit/WebProcess/Gamepad/WebGamepadProvider.cpp:95
> +    LOG(Gamepad, "WebGamepadProvider::gamepadDisconnected - Gamepad index %i detached (m_gamepads size %lu, m_rawGamepads size %lu\n", index, m_gamepads.size(), m_rawGamepads.size());

Since index is an unsigned, this should be %u, not %i.

Since a Vector size is a size_t, the others should be %zu, not %lu.

> Source/WebKit/WebProcess/Gamepad/WebGamepadProvider.cpp:103
> +    LOG(Gamepad, "WebGamepadProvider::gamepadActivity - %lu gamepad datas with %lu local web gamepads\n", gamepadDatas.size(), m_gamepads.size());

Since a Vector size is a size_t, these should be %zu, not %lu.
Comment 3 Brady Eidson 2020-07-08 17:52:41 PDT
Created attachment 403829 [details]
PFL
Comment 4 Tim Horton 2020-07-08 17:55:35 PDT
Comment on attachment 403815 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=403815&action=review

>> Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.mm:107
>> +    });
> 
> Is thread safety an issue here? Otherwise, we would probably just want to use a boolean, not a dispatch_once_t.

That is a super-internal-looking method. What is the actual way that this works normally? Just linking the framework probably isn't it; is it +initialize on some class or something?
Comment 5 Brady Eidson 2020-07-08 17:56:45 PDT
(In reply to Tim Horton from comment #4)
> Comment on attachment 403815 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=403815&action=review
> 
> >> Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.mm:107
> >> +    });
> > 
> > Is thread safety an issue here? Otherwise, we would probably just want to use a boolean, not a dispatch_once_t.
> 
> That is a super-internal-looking method. What is the actual way that this
> works normally? Just linking the framework probably isn't it; is it
> +initialize on some class or something?

No, it's just linking the framework. (Will ping you on slack)
Comment 6 EWS 2020-07-08 18:20:22 PDT
Committed r264143: <https://trac.webkit.org/changeset/264143>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 403829 [details].
Comment 7 Radar WebKit Bug Importer 2020-07-08 18:21:16 PDT
<rdar://problem/65250548>