Title: [262899] trunk/Source
Revision
262899
Author
[email protected]
Date
2020-06-11 01:58:28 -0700 (Thu, 11 Jun 2020)

Log Message

[GTK] Implement button-press-event, button-release-event, and absolute-axis-event of GAMEPAD API.
https://bugs.webkit.org/show_bug.cgi?id=133850

Reviewed by Carlos Garcia Campos.

Source/WebCore:

This is a follow-up change after r261965, implementing the rest of missing GAMEPAD API
for the gtk port. Buttons and analog sticks of standard gamepads work with this change.

No new tests since existing tests can cover this change.

* html/OffscreenCanvas.h:
* platform/gamepad/manette/ManetteGamepad.cpp:
(WebCore::toStandardGamepadAxis):
(WebCore::onAbsoluteAxisEvent):
(WebCore::toStandardGamepadButton):
(WebCore::onButtonPressEvent):
(WebCore::onButtonReleaseEvent):
(WebCore::ManetteGamepad::ManetteGamepad):
(WebCore::ManetteGamepad::~ManetteGamepad):
(WebCore::ManetteGamepad::buttonPressedOrReleased):
(WebCore::ManetteGamepad::absoluteAxisChanged):
* platform/gamepad/manette/ManetteGamepad.h:
* platform/gamepad/manette/ManetteGamepadProvider.cpp:
(WebCore::ManetteGamepadProvider::ManetteGamepadProvider):
(WebCore::ManetteGamepadProvider::~ManetteGamepadProvider):
(WebCore::ManetteGamepadProvider::gamepadHadInput):
(WebCore::ManetteGamepadProvider::inputNotificationTimerFired):
* platform/gamepad/manette/ManetteGamepadProvider.h:

Source/WebKit:

* UIProcess/Gamepad/UIGamepadProvider.cpp: Add the OS(LINUX) guard.
* UIProcess/Gamepad/gtk/UIGamepadProviderGtk.cpp:
(WebKit::getWebPageProxy): Build fix. WebKitWebViewBase is used, not WebKitWebViewPrivate.
* UIProcess/Gamepad/manette/UIGamepadProviderManette.cpp: Add the OS(LINUX) guard.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (262898 => 262899)


--- trunk/Source/WebCore/ChangeLog	2020-06-11 08:09:33 UTC (rev 262898)
+++ trunk/Source/WebCore/ChangeLog	2020-06-11 08:58:28 UTC (rev 262899)
@@ -1,3 +1,34 @@
+2020-06-11  ChangSeok Oh  <[email protected]>
+
+        [GTK] Implement button-press-event, button-release-event, and absolute-axis-event of GAMEPAD API.
+        https://bugs.webkit.org/show_bug.cgi?id=133850
+
+        Reviewed by Carlos Garcia Campos.
+
+        This is a follow-up change after r261965, implementing the rest of missing GAMEPAD API
+        for the gtk port. Buttons and analog sticks of standard gamepads work with this change.
+
+        No new tests since existing tests can cover this change.
+
+        * html/OffscreenCanvas.h:
+        * platform/gamepad/manette/ManetteGamepad.cpp:
+        (WebCore::toStandardGamepadAxis):
+        (WebCore::onAbsoluteAxisEvent):
+        (WebCore::toStandardGamepadButton):
+        (WebCore::onButtonPressEvent):
+        (WebCore::onButtonReleaseEvent):
+        (WebCore::ManetteGamepad::ManetteGamepad):
+        (WebCore::ManetteGamepad::~ManetteGamepad):
+        (WebCore::ManetteGamepad::buttonPressedOrReleased):
+        (WebCore::ManetteGamepad::absoluteAxisChanged):
+        * platform/gamepad/manette/ManetteGamepad.h:
+        * platform/gamepad/manette/ManetteGamepadProvider.cpp:
+        (WebCore::ManetteGamepadProvider::ManetteGamepadProvider):
+        (WebCore::ManetteGamepadProvider::~ManetteGamepadProvider):
+        (WebCore::ManetteGamepadProvider::gamepadHadInput):
+        (WebCore::ManetteGamepadProvider::inputNotificationTimerFired):
+        * platform/gamepad/manette/ManetteGamepadProvider.h:
+
 2020-06-10  Sergio Villar Senin  <[email protected]>
 
         [WebXR] Pass an unsigned long to cancelAnimationCallback() as handle

Modified: trunk/Source/WebCore/html/OffscreenCanvas.h (262898 => 262899)


--- trunk/Source/WebCore/html/OffscreenCanvas.h	2020-06-11 08:09:33 UTC (rev 262898)
+++ trunk/Source/WebCore/html/OffscreenCanvas.h	2020-06-11 08:58:28 UTC (rev 262899)
@@ -33,6 +33,7 @@
 #include "EventTarget.h"
 #include "ExceptionOr.h"
 #include "IDLTypes.h"
+#include "ImageBuffer.h"
 #include "IntSize.h"
 #include "ScriptWrappable.h"
 #include <wtf/Forward.h>

Modified: trunk/Source/WebCore/platform/gamepad/manette/ManetteGamepad.cpp (262898 => 262899)


--- trunk/Source/WebCore/platform/gamepad/manette/ManetteGamepad.cpp	2020-06-11 08:09:33 UTC (rev 262898)
+++ trunk/Source/WebCore/platform/gamepad/manette/ManetteGamepad.cpp	2020-06-11 08:58:28 UTC (rev 262899)
@@ -26,16 +26,147 @@
 #include "config.h"
 #include "ManetteGamepad.h"
 
-#if ENABLE(GAMEPAD)
+#if ENABLE(GAMEPAD) && OS(LINUX)
 
+#include "ManetteGamepadProvider.h"
+#include <linux/input-event-codes.h>
+#include <wtf/HexNumber.h>
+#include <wtf/text/CString.h>
+
 namespace WebCore {
 
+static ManetteGamepad::StandardGamepadAxis toStandardGamepadAxis(uint16_t axis)
+{
+    switch (axis) {
+    case ABS_X:
+        return ManetteGamepad::StandardGamepadAxis::LeftStickX;
+    case ABS_Y:
+        return ManetteGamepad::StandardGamepadAxis::LeftStickY;
+    case ABS_RX:
+        return ManetteGamepad::StandardGamepadAxis::RightStickX;
+    case ABS_RY:
+        return ManetteGamepad::StandardGamepadAxis::RightStickY;
+    default:
+        ASSERT_NOT_REACHED();
+    }
+    return ManetteGamepad::StandardGamepadAxis::Unknown;
+}
+
+static void onAbsoluteAxisEvent(ManetteDevice* device, ManetteEvent* event, ManetteGamepad* gamepad)
+{
+    uint16_t axis;
+    double value;
+    if (!manette_event_get_absolute(event, &axis, &value))
+        return;
+
+    gamepad->absoluteAxisChanged(device, toStandardGamepadAxis(axis), value);
+}
+
+static ManetteGamepad::StandardGamepadButton toStandardGamepadButton(uint16_t manetteButton)
+{
+    switch (manetteButton) {
+    case BTN_A:
+        return ManetteGamepad::StandardGamepadButton::A;
+    case BTN_B:
+        return ManetteGamepad::StandardGamepadButton::B;
+    case BTN_X:
+        return ManetteGamepad::StandardGamepadButton::X;
+    case BTN_Y:
+        return ManetteGamepad::StandardGamepadButton::Y;
+    case BTN_TL:
+        return ManetteGamepad::StandardGamepadButton::LeftShoulder;
+    case BTN_TR:
+        return ManetteGamepad::StandardGamepadButton::RightShoulder;
+    case BTN_TL2:
+        return ManetteGamepad::StandardGamepadButton::LeftTrigger;
+    case BTN_TR2:
+        return ManetteGamepad::StandardGamepadButton::RightTrigger;
+    case BTN_SELECT:
+        return ManetteGamepad::StandardGamepadButton::Select;
+    case BTN_START:
+        return ManetteGamepad::StandardGamepadButton::Start;
+    case BTN_THUMBL:
+        return ManetteGamepad::StandardGamepadButton::LeftStick;
+    case BTN_THUMBR:
+        return ManetteGamepad::StandardGamepadButton::RightStick;
+    case BTN_DPAD_UP:
+        return ManetteGamepad::StandardGamepadButton::DPadUp;
+    case BTN_DPAD_DOWN:
+        return ManetteGamepad::StandardGamepadButton::DPadDown;
+    case BTN_DPAD_LEFT:
+        return ManetteGamepad::StandardGamepadButton::DPadLeft;
+    case BTN_DPAD_RIGHT:
+        return ManetteGamepad::StandardGamepadButton::DPadRight;
+    default:
+        ASSERT_NOT_REACHED();
+    }
+    return ManetteGamepad::StandardGamepadButton::Unknown;
+}
+
+static void onButtonPressEvent(ManetteDevice* device, ManetteEvent* event, ManetteGamepad* gamepad)
+{
+    uint16_t button;
+    if (!manette_event_get_button(event, &button))
+        return;
+
+    gamepad->buttonPressedOrReleased(device, toStandardGamepadButton(button), true);
+}
+
+static void onButtonReleaseEvent(ManetteDevice* device, ManetteEvent* event, ManetteGamepad* gamepad)
+{
+    uint16_t button;
+    if (!manette_event_get_button(event, &button))
+        return;
+
+    gamepad->buttonPressedOrReleased(device, toStandardGamepadButton(button), false);
+}
+
 ManetteGamepad::ManetteGamepad(ManetteDevice* device, unsigned index)
     : PlatformGamepad(index)
     , m_device(device)
 {
+    ASSERT(index < 4);
+
+    m_connectTime = m_lastUpdateTime = MonotonicTime::now();
+
+    m_id = String::fromUTF8(manette_device_get_name(m_device.get()));
+    m_mapping = String::fromUTF8("standard");
+
+    m_axisValues.fill(0, static_cast<size_t>(StandardGamepadAxis::Count));
+    m_buttonValues.fill(0, static_cast<size_t>(StandardGamepadButton::Count));
+
+    g_signal_connect(device, "button-press-event", G_CALLBACK(onButtonPressEvent), this);
+    g_signal_connect(device, "button-release-event", G_CALLBACK(onButtonReleaseEvent), this);
+    g_signal_connect(device, "absolute-axis-event", G_CALLBACK(onAbsoluteAxisEvent), this);
 }
 
+ManetteGamepad::~ManetteGamepad()
+{
+    g_signal_handlers_disconnect_by_data(m_device.get(), this);
+}
+
+void ManetteGamepad::buttonPressedOrReleased(ManetteDevice*, StandardGamepadButton button, bool pressed)
+{
+    if (button == StandardGamepadButton::Unknown)
+        return;
+
+    m_lastUpdateTime = MonotonicTime::now();
+    m_buttonValues[static_cast<int>(button)] = pressed ? 1.0 : 0.0;
+
+    ManetteGamepadProvider::singleton().gamepadHadInput(*this, pressed ? ManetteGamepadProvider::ShouldMakeGamepadsVisible::Yes : ManetteGamepadProvider::ShouldMakeGamepadsVisible::No);
+}
+
+void ManetteGamepad::absoluteAxisChanged(ManetteDevice*, StandardGamepadAxis axis, double value)
+{
+    if (axis == StandardGamepadAxis::Unknown)
+        return;
+
+    m_lastUpdateTime = MonotonicTime::now();
+    m_axisValues[static_cast<int>(axis)] = value;
+
+    ManetteGamepadProvider::singleton().gamepadHadInput(*this, ManetteGamepadProvider::ShouldMakeGamepadsVisible::No);
+}
+
 } // namespace WebCore
 
-#endif // ENABLE(GAMEPAD)
+#endif // ENABLE(GAMEPAD) && OS(LINUX)

Modified: trunk/Source/WebCore/platform/gamepad/manette/ManetteGamepad.h (262898 => 262899)


--- trunk/Source/WebCore/platform/gamepad/manette/ManetteGamepad.h	2020-06-11 08:09:33 UTC (rev 262898)
+++ trunk/Source/WebCore/platform/gamepad/manette/ManetteGamepad.h	2020-06-11 08:58:28 UTC (rev 262899)
@@ -25,7 +25,7 @@
 
 #pragma once
 
-#if ENABLE(GAMEPAD)
+#if ENABLE(GAMEPAD) && OS(LINUX)
 
 #include "PlatformGamepad.h"
 
@@ -37,11 +37,45 @@
 
 class ManetteGamepad final : public PlatformGamepad {
 public:
+    // Refer https://www.w3.org/TR/gamepad/#gamepadbutton-interface
+    enum class StandardGamepadAxis : int8_t {
+        Unknown = -1,
+        LeftStickX,
+        LeftStickY,
+        RightStickX,
+        RightStickY,
+        Count,
+    };
+    enum class StandardGamepadButton : int8_t {
+        Unknown = -1,
+        A,
+        B,
+        X,
+        Y,
+        LeftShoulder,
+        RightShoulder,
+        LeftTrigger,
+        RightTrigger,
+        Select,
+        Start,
+        LeftStick,
+        RightStick,
+        DPadUp,
+        DPadDown,
+        DPadLeft,
+        DPadRight,
+        Count,
+    };
+
     ManetteGamepad(ManetteDevice*, unsigned index);
+    virtual ~ManetteGamepad();
 
     const Vector<double>& axisValues() const final { return m_axisValues; }
     const Vector<double>& buttonValues() const final { return m_buttonValues; }
 
+    void absoluteAxisChanged(ManetteDevice*, StandardGamepadAxis, double value);
+    void buttonPressedOrReleased(ManetteDevice*, StandardGamepadButton, bool pressed);
+
 private:
     GRefPtr<ManetteDevice> m_device;
 
@@ -51,4 +85,4 @@
 
 } // namespace WebCore
 
-#endif // ENABLE(GAMEPAD)
+#endif // ENABLE(GAMEPAD) && OS(LINUX)

Modified: trunk/Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp (262898 => 262899)


--- trunk/Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp	2020-06-11 08:09:33 UTC (rev 262898)
+++ trunk/Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp	2020-06-11 08:58:28 UTC (rev 262899)
@@ -27,7 +27,7 @@
 #include "config.h"
 #include "ManetteGamepadProvider.h"
 
-#if ENABLE(GAMEPAD)
+#if ENABLE(GAMEPAD) && OS(LINUX)
 
 #include "GUniquePtrManette.h"
 #include "GamepadProviderClient.h"
@@ -38,6 +38,7 @@
 namespace WebCore {
 
 static const Seconds connectionDelayInterval { 500_ms };
+static const Seconds inputNotificationDelay { 50_ms };
 
 ManetteGamepadProvider& ManetteGamepadProvider::singleton()
 {
@@ -58,11 +59,22 @@
 ManetteGamepadProvider::ManetteGamepadProvider()
     : m_monitor(manette_monitor_new())
     , m_connectionDelayTimer(RunLoop::current(), this, &ManetteGamepadProvider::connectionDelayTimerFired)
+    , m_inputNotificationTimer(RunLoop::current(), this, &ManetteGamepadProvider::inputNotificationTimerFired)
 {
     g_signal_connect(m_monitor.get(), "device-connected", G_CALLBACK(onDeviceConnected), this);
     g_signal_connect(m_monitor.get(), "device-disconnected", G_CALLBACK(onDeviceDisconnected), this);
+
+    ManetteDevice* device;
+    GUniquePtr<ManetteMonitorIter> iter(manette_monitor_iterate(m_monitor.get()));
+    while (manette_monitor_iter_next(iter.get(), &device))
+        deviceConnected(device);
 }
 
+ManetteGamepadProvider::~ManetteGamepadProvider()
+{
+    g_signal_handlers_disconnect_by_data(m_monitor.get(), this);
+}
+
 void ManetteGamepadProvider::startMonitoringGamepads(GamepadProviderClient& client)
 {
     bool shouldOpenAndScheduleManager = m_clients.isEmpty();
@@ -92,6 +104,15 @@
     }
 }
 
+void ManetteGamepadProvider::gamepadHadInput(ManetteGamepad&, ShouldMakeGamepadsVisible shouldMakeGamepadsVisible)
+{
+    if (!m_inputNotificationTimer.isActive())
+        m_inputNotificationTimer.startOneShot(inputNotificationDelay);
+
+    if (shouldMakeGamepadsVisible == ShouldMakeGamepadsVisible::Yes)
+        setShouldMakeGamepadsVisibile();
+}
+
 void ManetteGamepadProvider::deviceConnected(ManetteDevice* device)
 {
     ASSERT(!m_gamepadMap.get(device));
@@ -156,6 +177,14 @@
         client->setInitialConnectedGamepads(m_gamepadVector);
 }
 
+void ManetteGamepadProvider::inputNotificationTimerFired()
+{
+    if (!m_shouldDispatchCallbacks)
+        return;
+
+    dispatchPlatformGamepadInputActivity();
+}
+
 std::unique_ptr<ManetteGamepad> ManetteGamepadProvider::removeGamepadForDevice(ManetteDevice* device)
 {
     std::unique_ptr<ManetteGamepad> result = m_gamepadMap.take(device);
@@ -170,4 +199,4 @@
 
 } // namespace WebCore
 
-#endif // ENABLE(GAMEPAD)
+#endif // ENABLE(GAMEPAD) && OS(LINUX)

Modified: trunk/Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.h (262898 => 262899)


--- trunk/Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.h	2020-06-11 08:09:33 UTC (rev 262898)
+++ trunk/Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.h	2020-06-11 08:58:28 UTC (rev 262899)
@@ -26,7 +26,7 @@
 
 #pragma once
 
-#if ENABLE(GAMEPAD)
+#if ENABLE(GAMEPAD) && OS(LINUX)
 
 #include "GamepadProvider.h"
 #include <libmanette.h>
@@ -44,6 +44,8 @@
 public:
     static ManetteGamepadProvider& singleton();
 
+    virtual ~ManetteGamepadProvider();
+
     void startMonitoringGamepads(GamepadProviderClient&) final;
     void stopMonitoringGamepads(GamepadProviderClient&) final;
     const Vector<PlatformGamepad*>& platformGamepads() final { return m_gamepadVector; }
@@ -51,6 +53,9 @@
     void deviceConnected(ManetteDevice*);
     void deviceDisconnected(ManetteDevice*);
 
+    enum class ShouldMakeGamepadsVisible : bool { No, Yes };
+    void gamepadHadInput(ManetteGamepad&, ShouldMakeGamepadsVisible);
+
 private:
     ManetteGamepadProvider();
 
@@ -58,6 +63,7 @@
 
     unsigned indexForNewlyConnectedDevice();
     void connectionDelayTimerFired();
+    void inputNotificationTimerFired();
 
     Vector<PlatformGamepad*> m_gamepadVector;
     HashMap<ManetteDevice*, std::unique_ptr<ManetteGamepad>> m_gamepadMap;
@@ -65,8 +71,9 @@
 
     GUniquePtr<ManetteMonitor> m_monitor;
     RunLoop::Timer<ManetteGamepadProvider> m_connectionDelayTimer;
+    RunLoop::Timer<ManetteGamepadProvider> m_inputNotificationTimer;
 };
 
 } // namespace WebCore
 
-#endif // ENABLE(GAMEPAD)
+#endif // ENABLE(GAMEPAD) && OS(LINUX)

Modified: trunk/Source/WebKit/ChangeLog (262898 => 262899)


--- trunk/Source/WebKit/ChangeLog	2020-06-11 08:09:33 UTC (rev 262898)
+++ trunk/Source/WebKit/ChangeLog	2020-06-11 08:58:28 UTC (rev 262899)
@@ -1,3 +1,15 @@
+2020-06-11  ChangSeok Oh  <[email protected]>
+
+        [GTK] Implement button-press-event, button-release-event, and absolute-axis-event of GAMEPAD API.
+        https://bugs.webkit.org/show_bug.cgi?id=133850
+
+        Reviewed by Carlos Garcia Campos.
+
+        * UIProcess/Gamepad/UIGamepadProvider.cpp: Add the OS(LINUX) guard.
+        * UIProcess/Gamepad/gtk/UIGamepadProviderGtk.cpp:
+        (WebKit::getWebPageProxy): Build fix. WebKitWebViewBase is used, not WebKitWebViewPrivate.
+        * UIProcess/Gamepad/manette/UIGamepadProviderManette.cpp: Add the OS(LINUX) guard.
+
 2020-06-10  Said Abou-Hallawa  <[email protected]>
 
         [macOS]: The File Picker of the <input> file element should show the selection filter

Modified: trunk/Source/WebKit/UIProcess/Gamepad/UIGamepadProvider.cpp (262898 => 262899)


--- trunk/Source/WebKit/UIProcess/Gamepad/UIGamepadProvider.cpp	2020-06-11 08:09:33 UTC (rev 262898)
+++ trunk/Source/WebKit/UIProcess/Gamepad/UIGamepadProvider.cpp	2020-06-11 08:58:28 UTC (rev 262899)
@@ -223,7 +223,7 @@
     return gamepadDatas;
 }
 
-#if !PLATFORM(COCOA) && !USE(MANETTE)
+#if !PLATFORM(COCOA) && !(USE(MANETTE) && OS(LINUX))
 
 void UIGamepadProvider::platformSetDefaultGamepadProvider()
 {
@@ -244,7 +244,7 @@
 {
 }
 
-#endif // !PLATFORM(COCOA) && !USE(MANETTE)
+#endif // !PLATFORM(COCOA) && !(USE(MANETTE) && OS(LINUX))
 
 }
 

Modified: trunk/Source/WebKit/UIProcess/Gamepad/gtk/UIGamepadProviderGtk.cpp (262898 => 262899)


--- trunk/Source/WebKit/UIProcess/Gamepad/gtk/UIGamepadProviderGtk.cpp	2020-06-11 08:09:33 UTC (rev 262898)
+++ trunk/Source/WebKit/UIProcess/Gamepad/gtk/UIGamepadProviderGtk.cpp	2020-06-11 08:58:28 UTC (rev 262899)
@@ -43,7 +43,7 @@
     if (!widget || !GTK_IS_CONTAINER(widget))
         return nullptr;
 
-    if (WEBKIT_IS_WEB_VIEW(widget))
+    if (WEBKIT_IS_WEB_VIEW_BASE(widget))
         return gtk_widget_is_visible(widget) ? webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(widget)) : nullptr;
 
     GUniquePtr<GList> children(gtk_container_get_children(GTK_CONTAINER(widget)));

Modified: trunk/Source/WebKit/UIProcess/Gamepad/manette/UIGamepadProviderManette.cpp (262898 => 262899)


--- trunk/Source/WebKit/UIProcess/Gamepad/manette/UIGamepadProviderManette.cpp	2020-06-11 08:09:33 UTC (rev 262898)
+++ trunk/Source/WebKit/UIProcess/Gamepad/manette/UIGamepadProviderManette.cpp	2020-06-11 08:58:28 UTC (rev 262899)
@@ -26,7 +26,7 @@
 #include "config.h"
 #include "UIGamepadProvider.h"
 
-#if ENABLE(GAMEPAD)
+#if ENABLE(GAMEPAD) && OS(LINUX)
 
 #include "WebPageProxy.h"
 #include <WebCore/ManetteGamepadProvider.h>
@@ -61,4 +61,4 @@
 
 }
 
-#endif // ENABLE(GAMEPAD)
+#endif // ENABLE(GAMEPAD) && OS(LINUX)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to