Title: [265644] trunk
Revision
265644
Author
[email protected]
Date
2020-08-13 22:01:49 -0700 (Thu, 13 Aug 2020)

Log Message

(WK2 only) gamepad mapping stops being reported as “standard” in new tabs.
rdar://problem/66946505 and https://bugs.webkit.org/show_bug.cgi?id=215486

Reviewed by Tim Horton.

Source/WebKit:

Covered by new API test.

Get rid of the premature optimization that was "full gamepaddata" vs "condensed gamepaddata"

In practice, the actual button and axis values are larger than the mapping and id, so
not much IPC was being saved.

* Shared/Gamepad/GamepadData.cpp:
* Shared/Gamepad/GamepadData.h:

* UIProcess/Gamepad/UIGamepad.cpp:
(WebKit::UIGamepad::gamepadData const):
(WebKit::UIGamepad::condensedGamepadData const): Deleted.
(WebKit::UIGamepad::fullGamepadData const): Deleted.
* UIProcess/Gamepad/UIGamepad.h:

* UIProcess/Gamepad/UIGamepadProvider.cpp:
(WebKit::UIGamepadProvider::snapshotGamepads):

* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::gamepadConnected):

Tools:

* TestWebKitAPI/Tests/mac/HIDGamepads.mm:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (265643 => 265644)


--- trunk/Source/WebKit/ChangeLog	2020-08-14 04:31:25 UTC (rev 265643)
+++ trunk/Source/WebKit/ChangeLog	2020-08-14 05:01:49 UTC (rev 265644)
@@ -1,3 +1,32 @@
+2020-08-13  Brady Eidson  <[email protected]>
+
+        (WK2 only) gamepad mapping stops being reported as “standard” in new tabs.
+        rdar://problem/66946505 and https://bugs.webkit.org/show_bug.cgi?id=215486
+
+        Reviewed by Tim Horton.
+
+        Covered by new API test.
+        
+        Get rid of the premature optimization that was "full gamepaddata" vs "condensed gamepaddata"
+        
+        In practice, the actual button and axis values are larger than the mapping and id, so
+        not much IPC was being saved.
+
+        * Shared/Gamepad/GamepadData.cpp:
+        * Shared/Gamepad/GamepadData.h:
+
+        * UIProcess/Gamepad/UIGamepad.cpp:
+        (WebKit::UIGamepad::gamepadData const):
+        (WebKit::UIGamepad::condensedGamepadData const): Deleted.
+        (WebKit::UIGamepad::fullGamepadData const): Deleted.
+        * UIProcess/Gamepad/UIGamepad.h:
+
+        * UIProcess/Gamepad/UIGamepadProvider.cpp:
+        (WebKit::UIGamepadProvider::snapshotGamepads):
+
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::gamepadConnected):
+
 2020-08-13  Kate Cheney  <[email protected]>
 
         Create SharedMemory::IPCHandle object to validate the size of SharedMemory::Handle objects sent over IPC

Modified: trunk/Source/WebKit/Shared/Gamepad/GamepadData.cpp (265643 => 265644)


--- trunk/Source/WebKit/Shared/Gamepad/GamepadData.cpp	2020-08-14 04:31:25 UTC (rev 265643)
+++ trunk/Source/WebKit/Shared/Gamepad/GamepadData.cpp	2020-08-14 05:01:49 UTC (rev 265644)
@@ -35,14 +35,6 @@
 
 namespace WebKit {
 
-GamepadData::GamepadData(unsigned index, const Vector<SharedGamepadValue>& axisValues, const Vector<SharedGamepadValue>& buttonValues, MonotonicTime lastUpdateTime)
-    : m_index(index)
-    , m_axisValues(WTF::map(axisValues, [](const auto& value) { return value.value(); }))
-    , m_buttonValues(WTF::map(buttonValues, [](const auto& value) { return value.value(); }))
-    , m_lastUpdateTime(lastUpdateTime)
-{
-}
-
 GamepadData::GamepadData(unsigned index, const String& id, const String& mapping, const Vector<SharedGamepadValue>& axisValues, const Vector<SharedGamepadValue>& buttonValues, MonotonicTime lastUpdateTime)
     : m_index(index)
     , m_id(id)

Modified: trunk/Source/WebKit/Shared/Gamepad/GamepadData.h (265643 => 265644)


--- trunk/Source/WebKit/Shared/Gamepad/GamepadData.h	2020-08-14 04:31:25 UTC (rev 265643)
+++ trunk/Source/WebKit/Shared/Gamepad/GamepadData.h	2020-08-14 05:01:49 UTC (rev 265644)
@@ -46,7 +46,6 @@
     {
     }
 
-    GamepadData(unsigned index, const Vector<WebCore::SharedGamepadValue>& axisValues, const Vector<WebCore::SharedGamepadValue>& buttonValues, MonotonicTime lastUpdateTime);
     GamepadData(unsigned index, const String& id, const String& mapping, const Vector<WebCore::SharedGamepadValue>& axisValues, const Vector<WebCore::SharedGamepadValue>& buttonValues, MonotonicTime lastUpdateTime);
 
     void encode(IPC::Encoder&) const;

Modified: trunk/Source/WebKit/UIProcess/Gamepad/UIGamepad.cpp (265643 => 265644)


--- trunk/Source/WebKit/UIProcess/Gamepad/UIGamepad.cpp	2020-08-14 04:31:25 UTC (rev 265643)
+++ trunk/Source/WebKit/UIProcess/Gamepad/UIGamepad.cpp	2020-08-14 05:01:49 UTC (rev 265644)
@@ -57,13 +57,8 @@
     m_lastUpdateTime = platformGamepad.lastUpdateTime();
 }
 
-GamepadData UIGamepad::condensedGamepadData() const
+GamepadData UIGamepad::gamepadData() const
 {
-    return { m_index, m_axisValues, m_buttonValues, m_lastUpdateTime };
-}
-
-GamepadData UIGamepad::fullGamepadData() const
-{
     return { m_index, m_id, m_mapping, m_axisValues, m_buttonValues, m_lastUpdateTime };
 }
 

Modified: trunk/Source/WebKit/UIProcess/Gamepad/UIGamepad.h (265643 => 265644)


--- trunk/Source/WebKit/UIProcess/Gamepad/UIGamepad.h	2020-08-14 04:31:25 UTC (rev 265643)
+++ trunk/Source/WebKit/UIProcess/Gamepad/UIGamepad.h	2020-08-14 05:01:49 UTC (rev 265644)
@@ -47,8 +47,7 @@
 
     unsigned index() const { return m_index; }
 
-    GamepadData condensedGamepadData() const;
-    GamepadData fullGamepadData() const;
+    GamepadData gamepadData() const;
 
     void updateFromPlatformGamepad(WebCore::PlatformGamepad&);
 

Modified: trunk/Source/WebKit/UIProcess/Gamepad/UIGamepadProvider.cpp (265643 => 265644)


--- trunk/Source/WebKit/UIProcess/Gamepad/UIGamepadProvider.cpp	2020-08-14 04:31:25 UTC (rev 265643)
+++ trunk/Source/WebKit/UIProcess/Gamepad/UIGamepadProvider.cpp	2020-08-14 05:01:49 UTC (rev 265644)
@@ -199,7 +199,7 @@
 
     for (auto& gamepad : m_gamepads) {
         if (gamepad)
-            gamepadDatas.uncheckedAppend(gamepad->condensedGamepadData());
+            gamepadDatas.uncheckedAppend(gamepad->gamepadData());
         else
             gamepadDatas.uncheckedAppend({ });
     }

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (265643 => 265644)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2020-08-14 04:31:25 UTC (rev 265643)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2020-08-14 05:01:49 UTC (rev 265644)
@@ -1981,7 +1981,7 @@
 void WebProcessPool::gamepadConnected(const UIGamepad& gamepad, EventMakesGamepadsVisible eventVisibility)
 {
     for (auto& process : m_processesUsingGamepads)
-        process->send(Messages::WebProcess::GamepadConnected(gamepad.fullGamepadData(), eventVisibility), 0);
+        process->send(Messages::WebProcess::GamepadConnected(gamepad.gamepadData(), eventVisibility), 0);
 }
 
 void WebProcessPool::gamepadDisconnected(const UIGamepad& gamepad)

Modified: trunk/Tools/ChangeLog (265643 => 265644)


--- trunk/Tools/ChangeLog	2020-08-14 04:31:25 UTC (rev 265643)
+++ trunk/Tools/ChangeLog	2020-08-14 05:01:49 UTC (rev 265644)
@@ -1,3 +1,12 @@
+2020-08-13  Brady Eidson  <[email protected]>
+
+        (WK2 only) gamepad mapping stops being reported as “standard” in new tabs.
+        rdar://problem/66946505 and https://bugs.webkit.org/show_bug.cgi?id=215486
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Tests/mac/HIDGamepads.mm:
+
 2020-08-13  Aakash Jain  <[email protected]>
 
         Regression(r265580): apply-watchlist is broken

Modified: trunk/Tools/TestWebKitAPI/Tests/mac/HIDGamepads.mm (265643 => 265644)


--- trunk/Tools/TestWebKitAPI/Tests/mac/HIDGamepads.mm	2020-08-14 04:31:25 UTC (rev 265643)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/HIDGamepads.mm	2020-08-14 05:01:49 UTC (rev 265644)
@@ -209,6 +209,7 @@
 result.gamepadCount = gamepads.length;
 result.gamepadButtons = new Array;
 result.gamepadAxes = new Array;
+result.gamepadMapping = new Array;
 
 for (var i = 0; i < gamepads.length; ++i) {
     result.gamepadButtons[i] = new Array;
@@ -218,6 +219,8 @@
     result.gamepadAxes[i] = new Array;
     for (var j = 0; j < gamepads[i].axes.length; ++j)
         result.gamepadAxes[i][j] = gamepads[i].axes[j];
+
+    result.gamepadMapping[i] = gamepads[i].mapping;
 }
 
 return result;
@@ -517,6 +520,7 @@
     // needs to convince it to monitor gamepad devices
     [[webView window] resignKeyWindow];
     [[webView window] makeKeyWindow];
+    [[webView window] makeFirstResponder:webView.get()];
 
     // Connect a gamepad and make it visible to the page
     auto gamepad1 = makeUnique<VirtualGamepad>(VirtualGamepad::logitechF310Mapping());
@@ -566,7 +570,87 @@
     didReceiveMessage = true;
 }
 
+TEST(Gamepad, FullInfoAfterConnection)
+{
+    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 gamepad1 = makeUnique<VirtualGamepad>(VirtualGamepad::logitechF310Mapping());
+    while ([webView.get().configuration.processPool _numberOfConnectedGamepadsForTesting] != 1u)
+        Util::sleep(0.01);
+
+    gamepad1->setButtonValue(0, 1.0);
+    gamepad1->publishReport();
+
+    // Wait until the page sees the gamepad
+    while (messageHandler.get().messages.size() < 1) {
+        didReceiveMessage = false;
+        Util::run(&didReceiveMessage);
+    }
+
+    bool done = false;
+    auto resultBlock = [&] (id result, NSError *error) {
+        EXPECT_NULL(error);
+        EXPECT_TRUE([result[@"gamepadCount"] isEqualToNumber:@(1)]);
+        EXPECT_TRUE([result[@"gamepadMapping"][0] isEqualToString:@"standard"]);
+        done = true;
+    };
+
+    // Verify the gamepad has the expected mapping.
+    [webView callAsyncJavaScript:@(pollGamepadStateFunction) arguments:nil inFrame:nil inContentWorld:WKContentWorld.pageWorld completionHandler:resultBlock];
+    Util::run(&done);
+    done = false;
+
+    // Make a second web view to make the same gamepad visible to it.
+    auto webView2 = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+    keyWindowForTesting = [webView2 window];
+    [webView2 synchronouslyLoadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"gamepad://host/main.html"]]];
+    [[webView2 window] makeFirstResponder:webView2.get()];
+
+    // The gamepad is already connected, but this new web view can't see it.
+    // Press buttons to make it visible.
+    gamepad1->setButtonValue(1, 1.0);
+    gamepad1->publishReport();
+
+    // The gamepad is already connected, but this new web view can't see it.
+    // Press buttons to make it visible.
+    while (messageHandler.get().messages.size() < 2) {
+        didReceiveMessage = false;
+        Util::run(&didReceiveMessage);
+    }
+
+    // Verify the gamepad has the expected mapping in the second web view.
+    [webView2 callAsyncJavaScript:@(pollGamepadStateFunction) arguments:nil inFrame:nil inContentWorld:WKContentWorld.pageWorld completionHandler:resultBlock];
+    Util::run(&done);
+    done = false;
+}
+
+
 } // namespace TestWebKitAPI
 
 #endif // HAVE(HID_FRAMEWORK) && USE(APPLE_INTERNAL_SDK)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to