Changeset 262899 in webkit
- Timestamp:
- Jun 11, 2020 1:58:28 AM (4 years ago)
- Location:
- trunk/Source
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r262898 r262899 1 2020-06-11 ChangSeok Oh <changseok@webkit.org> 2 3 [GTK] Implement button-press-event, button-release-event, and absolute-axis-event of GAMEPAD API. 4 https://bugs.webkit.org/show_bug.cgi?id=133850 5 6 Reviewed by Carlos Garcia Campos. 7 8 This is a follow-up change after r261965, implementing the rest of missing GAMEPAD API 9 for the gtk port. Buttons and analog sticks of standard gamepads work with this change. 10 11 No new tests since existing tests can cover this change. 12 13 * html/OffscreenCanvas.h: 14 * platform/gamepad/manette/ManetteGamepad.cpp: 15 (WebCore::toStandardGamepadAxis): 16 (WebCore::onAbsoluteAxisEvent): 17 (WebCore::toStandardGamepadButton): 18 (WebCore::onButtonPressEvent): 19 (WebCore::onButtonReleaseEvent): 20 (WebCore::ManetteGamepad::ManetteGamepad): 21 (WebCore::ManetteGamepad::~ManetteGamepad): 22 (WebCore::ManetteGamepad::buttonPressedOrReleased): 23 (WebCore::ManetteGamepad::absoluteAxisChanged): 24 * platform/gamepad/manette/ManetteGamepad.h: 25 * platform/gamepad/manette/ManetteGamepadProvider.cpp: 26 (WebCore::ManetteGamepadProvider::ManetteGamepadProvider): 27 (WebCore::ManetteGamepadProvider::~ManetteGamepadProvider): 28 (WebCore::ManetteGamepadProvider::gamepadHadInput): 29 (WebCore::ManetteGamepadProvider::inputNotificationTimerFired): 30 * platform/gamepad/manette/ManetteGamepadProvider.h: 31 1 32 2020-06-10 Sergio Villar Senin <svillar@igalia.com> 2 33 -
trunk/Source/WebCore/html/OffscreenCanvas.h
r262581 r262899 34 34 #include "ExceptionOr.h" 35 35 #include "IDLTypes.h" 36 #include "ImageBuffer.h" 36 37 #include "IntSize.h" 37 38 #include "ScriptWrappable.h" -
trunk/Source/WebCore/platform/gamepad/manette/ManetteGamepad.cpp
r261965 r262899 27 27 #include "ManetteGamepad.h" 28 28 29 #if ENABLE(GAMEPAD) 29 #if ENABLE(GAMEPAD) && OS(LINUX) 30 31 #include "ManetteGamepadProvider.h" 32 #include <linux/input-event-codes.h> 33 #include <wtf/HexNumber.h> 34 #include <wtf/text/CString.h> 30 35 31 36 namespace WebCore { 37 38 static ManetteGamepad::StandardGamepadAxis toStandardGamepadAxis(uint16_t axis) 39 { 40 switch (axis) { 41 case ABS_X: 42 return ManetteGamepad::StandardGamepadAxis::LeftStickX; 43 case ABS_Y: 44 return ManetteGamepad::StandardGamepadAxis::LeftStickY; 45 case ABS_RX: 46 return ManetteGamepad::StandardGamepadAxis::RightStickX; 47 case ABS_RY: 48 return ManetteGamepad::StandardGamepadAxis::RightStickY; 49 default: 50 ASSERT_NOT_REACHED(); 51 } 52 return ManetteGamepad::StandardGamepadAxis::Unknown; 53 } 54 55 static void onAbsoluteAxisEvent(ManetteDevice* device, ManetteEvent* event, ManetteGamepad* gamepad) 56 { 57 uint16_t axis; 58 double value; 59 if (!manette_event_get_absolute(event, &axis, &value)) 60 return; 61 62 gamepad->absoluteAxisChanged(device, toStandardGamepadAxis(axis), value); 63 } 64 65 static ManetteGamepad::StandardGamepadButton toStandardGamepadButton(uint16_t manetteButton) 66 { 67 switch (manetteButton) { 68 case BTN_A: 69 return ManetteGamepad::StandardGamepadButton::A; 70 case BTN_B: 71 return ManetteGamepad::StandardGamepadButton::B; 72 case BTN_X: 73 return ManetteGamepad::StandardGamepadButton::X; 74 case BTN_Y: 75 return ManetteGamepad::StandardGamepadButton::Y; 76 case BTN_TL: 77 return ManetteGamepad::StandardGamepadButton::LeftShoulder; 78 case BTN_TR: 79 return ManetteGamepad::StandardGamepadButton::RightShoulder; 80 case BTN_TL2: 81 return ManetteGamepad::StandardGamepadButton::LeftTrigger; 82 case BTN_TR2: 83 return ManetteGamepad::StandardGamepadButton::RightTrigger; 84 case BTN_SELECT: 85 return ManetteGamepad::StandardGamepadButton::Select; 86 case BTN_START: 87 return ManetteGamepad::StandardGamepadButton::Start; 88 case BTN_THUMBL: 89 return ManetteGamepad::StandardGamepadButton::LeftStick; 90 case BTN_THUMBR: 91 return ManetteGamepad::StandardGamepadButton::RightStick; 92 case BTN_DPAD_UP: 93 return ManetteGamepad::StandardGamepadButton::DPadUp; 94 case BTN_DPAD_DOWN: 95 return ManetteGamepad::StandardGamepadButton::DPadDown; 96 case BTN_DPAD_LEFT: 97 return ManetteGamepad::StandardGamepadButton::DPadLeft; 98 case BTN_DPAD_RIGHT: 99 return ManetteGamepad::StandardGamepadButton::DPadRight; 100 default: 101 ASSERT_NOT_REACHED(); 102 } 103 return ManetteGamepad::StandardGamepadButton::Unknown; 104 } 105 106 static void onButtonPressEvent(ManetteDevice* device, ManetteEvent* event, ManetteGamepad* gamepad) 107 { 108 uint16_t button; 109 if (!manette_event_get_button(event, &button)) 110 return; 111 112 gamepad->buttonPressedOrReleased(device, toStandardGamepadButton(button), true); 113 } 114 115 static void onButtonReleaseEvent(ManetteDevice* device, ManetteEvent* event, ManetteGamepad* gamepad) 116 { 117 uint16_t button; 118 if (!manette_event_get_button(event, &button)) 119 return; 120 121 gamepad->buttonPressedOrReleased(device, toStandardGamepadButton(button), false); 122 } 32 123 33 124 ManetteGamepad::ManetteGamepad(ManetteDevice* device, unsigned index) … … 35 126 , m_device(device) 36 127 { 128 ASSERT(index < 4); 129 130 m_connectTime = m_lastUpdateTime = MonotonicTime::now(); 131 132 m_id = String::fromUTF8(manette_device_get_name(m_device.get())); 133 m_mapping = String::fromUTF8("standard"); 134 135 m_axisValues.fill(0, static_cast<size_t>(StandardGamepadAxis::Count)); 136 m_buttonValues.fill(0, static_cast<size_t>(StandardGamepadButton::Count)); 137 138 g_signal_connect(device, "button-press-event", G_CALLBACK(onButtonPressEvent), this); 139 g_signal_connect(device, "button-release-event", G_CALLBACK(onButtonReleaseEvent), this); 140 g_signal_connect(device, "absolute-axis-event", G_CALLBACK(onAbsoluteAxisEvent), this); 141 } 142 143 ManetteGamepad::~ManetteGamepad() 144 { 145 g_signal_handlers_disconnect_by_data(m_device.get(), this); 146 } 147 148 void ManetteGamepad::buttonPressedOrReleased(ManetteDevice*, StandardGamepadButton button, bool pressed) 149 { 150 if (button == StandardGamepadButton::Unknown) 151 return; 152 153 m_lastUpdateTime = MonotonicTime::now(); 154 m_buttonValues[static_cast<int>(button)] = pressed ? 1.0 : 0.0; 155 156 ManetteGamepadProvider::singleton().gamepadHadInput(*this, pressed ? ManetteGamepadProvider::ShouldMakeGamepadsVisible::Yes : ManetteGamepadProvider::ShouldMakeGamepadsVisible::No); 157 } 158 159 void ManetteGamepad::absoluteAxisChanged(ManetteDevice*, StandardGamepadAxis axis, double value) 160 { 161 if (axis == StandardGamepadAxis::Unknown) 162 return; 163 164 m_lastUpdateTime = MonotonicTime::now(); 165 m_axisValues[static_cast<int>(axis)] = value; 166 167 ManetteGamepadProvider::singleton().gamepadHadInput(*this, ManetteGamepadProvider::ShouldMakeGamepadsVisible::No); 37 168 } 38 169 39 170 } // namespace WebCore 40 171 41 #endif // ENABLE(GAMEPAD) 172 #endif // ENABLE(GAMEPAD) && OS(LINUX) -
trunk/Source/WebCore/platform/gamepad/manette/ManetteGamepad.h
r261965 r262899 26 26 #pragma once 27 27 28 #if ENABLE(GAMEPAD) 28 #if ENABLE(GAMEPAD) && OS(LINUX) 29 29 30 30 #include "PlatformGamepad.h" … … 38 38 class ManetteGamepad final : public PlatformGamepad { 39 39 public: 40 // Refer https://www.w3.org/TR/gamepad/#gamepadbutton-interface 41 enum class StandardGamepadAxis : int8_t { 42 Unknown = -1, 43 LeftStickX, 44 LeftStickY, 45 RightStickX, 46 RightStickY, 47 Count, 48 }; 49 enum class StandardGamepadButton : int8_t { 50 Unknown = -1, 51 A, 52 B, 53 X, 54 Y, 55 LeftShoulder, 56 RightShoulder, 57 LeftTrigger, 58 RightTrigger, 59 Select, 60 Start, 61 LeftStick, 62 RightStick, 63 DPadUp, 64 DPadDown, 65 DPadLeft, 66 DPadRight, 67 Count, 68 }; 69 40 70 ManetteGamepad(ManetteDevice*, unsigned index); 71 virtual ~ManetteGamepad(); 41 72 42 73 const Vector<double>& axisValues() const final { return m_axisValues; } 43 74 const Vector<double>& buttonValues() const final { return m_buttonValues; } 75 76 void absoluteAxisChanged(ManetteDevice*, StandardGamepadAxis, double value); 77 void buttonPressedOrReleased(ManetteDevice*, StandardGamepadButton, bool pressed); 44 78 45 79 private: … … 52 86 } // namespace WebCore 53 87 54 #endif // ENABLE(GAMEPAD) 88 #endif // ENABLE(GAMEPAD) && OS(LINUX) -
trunk/Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp
r261965 r262899 28 28 #include "ManetteGamepadProvider.h" 29 29 30 #if ENABLE(GAMEPAD) 30 #if ENABLE(GAMEPAD) && OS(LINUX) 31 31 32 32 #include "GUniquePtrManette.h" … … 39 39 40 40 static const Seconds connectionDelayInterval { 500_ms }; 41 static const Seconds inputNotificationDelay { 50_ms }; 41 42 42 43 ManetteGamepadProvider& ManetteGamepadProvider::singleton() … … 59 60 : m_monitor(manette_monitor_new()) 60 61 , m_connectionDelayTimer(RunLoop::current(), this, &ManetteGamepadProvider::connectionDelayTimerFired) 62 , m_inputNotificationTimer(RunLoop::current(), this, &ManetteGamepadProvider::inputNotificationTimerFired) 61 63 { 62 64 g_signal_connect(m_monitor.get(), "device-connected", G_CALLBACK(onDeviceConnected), this); 63 65 g_signal_connect(m_monitor.get(), "device-disconnected", G_CALLBACK(onDeviceDisconnected), this); 66 67 ManetteDevice* device; 68 GUniquePtr<ManetteMonitorIter> iter(manette_monitor_iterate(m_monitor.get())); 69 while (manette_monitor_iter_next(iter.get(), &device)) 70 deviceConnected(device); 71 } 72 73 ManetteGamepadProvider::~ManetteGamepadProvider() 74 { 75 g_signal_handlers_disconnect_by_data(m_monitor.get(), this); 64 76 } 65 77 … … 91 103 m_connectionDelayTimer.stop(); 92 104 } 105 } 106 107 void ManetteGamepadProvider::gamepadHadInput(ManetteGamepad&, ShouldMakeGamepadsVisible shouldMakeGamepadsVisible) 108 { 109 if (!m_inputNotificationTimer.isActive()) 110 m_inputNotificationTimer.startOneShot(inputNotificationDelay); 111 112 if (shouldMakeGamepadsVisible == ShouldMakeGamepadsVisible::Yes) 113 setShouldMakeGamepadsVisibile(); 93 114 } 94 115 … … 157 178 } 158 179 180 void ManetteGamepadProvider::inputNotificationTimerFired() 181 { 182 if (!m_shouldDispatchCallbacks) 183 return; 184 185 dispatchPlatformGamepadInputActivity(); 186 } 187 159 188 std::unique_ptr<ManetteGamepad> ManetteGamepadProvider::removeGamepadForDevice(ManetteDevice* device) 160 189 { … … 171 200 } // namespace WebCore 172 201 173 #endif // ENABLE(GAMEPAD) 202 #endif // ENABLE(GAMEPAD) && OS(LINUX) -
trunk/Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.h
r261965 r262899 27 27 #pragma once 28 28 29 #if ENABLE(GAMEPAD) 29 #if ENABLE(GAMEPAD) && OS(LINUX) 30 30 31 31 #include "GamepadProvider.h" … … 45 45 static ManetteGamepadProvider& singleton(); 46 46 47 virtual ~ManetteGamepadProvider(); 48 47 49 void startMonitoringGamepads(GamepadProviderClient&) final; 48 50 void stopMonitoringGamepads(GamepadProviderClient&) final; … … 51 53 void deviceConnected(ManetteDevice*); 52 54 void deviceDisconnected(ManetteDevice*); 55 56 enum class ShouldMakeGamepadsVisible : bool { No, Yes }; 57 void gamepadHadInput(ManetteGamepad&, ShouldMakeGamepadsVisible); 53 58 54 59 private: … … 59 64 unsigned indexForNewlyConnectedDevice(); 60 65 void connectionDelayTimerFired(); 66 void inputNotificationTimerFired(); 61 67 62 68 Vector<PlatformGamepad*> m_gamepadVector; … … 66 72 GUniquePtr<ManetteMonitor> m_monitor; 67 73 RunLoop::Timer<ManetteGamepadProvider> m_connectionDelayTimer; 74 RunLoop::Timer<ManetteGamepadProvider> m_inputNotificationTimer; 68 75 }; 69 76 70 77 } // namespace WebCore 71 78 72 #endif // ENABLE(GAMEPAD) 79 #endif // ENABLE(GAMEPAD) && OS(LINUX) -
trunk/Source/WebKit/ChangeLog
r262895 r262899 1 2020-06-11 ChangSeok Oh <changseok@webkit.org> 2 3 [GTK] Implement button-press-event, button-release-event, and absolute-axis-event of GAMEPAD API. 4 https://bugs.webkit.org/show_bug.cgi?id=133850 5 6 Reviewed by Carlos Garcia Campos. 7 8 * UIProcess/Gamepad/UIGamepadProvider.cpp: Add the OS(LINUX) guard. 9 * UIProcess/Gamepad/gtk/UIGamepadProviderGtk.cpp: 10 (WebKit::getWebPageProxy): Build fix. WebKitWebViewBase is used, not WebKitWebViewPrivate. 11 * UIProcess/Gamepad/manette/UIGamepadProviderManette.cpp: Add the OS(LINUX) guard. 12 1 13 2020-06-10 Said Abou-Hallawa <sabouhallawa@apple.com> 2 14 -
trunk/Source/WebKit/UIProcess/Gamepad/UIGamepadProvider.cpp
r261965 r262899 224 224 } 225 225 226 #if !PLATFORM(COCOA) && ! USE(MANETTE)226 #if !PLATFORM(COCOA) && !(USE(MANETTE) && OS(LINUX)) 227 227 228 228 void UIGamepadProvider::platformSetDefaultGamepadProvider() … … 245 245 } 246 246 247 #endif // !PLATFORM(COCOA) && ! USE(MANETTE)247 #endif // !PLATFORM(COCOA) && !(USE(MANETTE) && OS(LINUX)) 248 248 249 249 } -
trunk/Source/WebKit/UIProcess/Gamepad/gtk/UIGamepadProviderGtk.cpp
r261965 r262899 44 44 return nullptr; 45 45 46 if (WEBKIT_IS_WEB_VIEW (widget))46 if (WEBKIT_IS_WEB_VIEW_BASE(widget)) 47 47 return gtk_widget_is_visible(widget) ? webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(widget)) : nullptr; 48 48 -
trunk/Source/WebKit/UIProcess/Gamepad/manette/UIGamepadProviderManette.cpp
r261965 r262899 27 27 #include "UIGamepadProvider.h" 28 28 29 #if ENABLE(GAMEPAD) 29 #if ENABLE(GAMEPAD) && OS(LINUX) 30 30 31 31 #include "WebPageProxy.h" … … 62 62 } 63 63 64 #endif // ENABLE(GAMEPAD) 64 #endif // ENABLE(GAMEPAD) && OS(LINUX)
Note: See TracChangeset
for help on using the changeset viewer.