Bug 133854

Summary: [GTK] Implement connected and disconnected events of GAMEPAD API with libmanette
Product: WebKit Reporter: Michal Debski <m.debski>
Component: New BugsAssignee: ChangSeok Oh <changseok>
Status: RESOLVED FIXED    
Severity: Normal CC: agomez, alex, annulen, aperez, bugs-noreply, cgarcia, changseok, clopez, don.olmstead, ews-watchlist, gyuyoung.kim, ltilve, pnormand, ryuan.choi, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 133850    
Bug Blocks: 133847    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
cgarcia: review+
Patch to land none

Description Michal Debski 2014-06-13 06:57:21 PDT
This adds gamepad provider implementation for GTK port.
Comment 1 Michal Debski 2014-06-23 03:22:25 PDT
Created attachment 233594 [details]
Patch
Comment 2 ChangSeok Oh 2020-03-31 21:33:43 PDT
Created attachment 395125 [details]
Patch
Comment 3 ChangSeok Oh 2020-03-31 22:31:34 PDT
> src/meson.build:116:6: 
> : Program(s) ['vapigen'] not found or not executable

The build bot seems to not have vala package..
Comment 4 ChangSeok Oh 2020-03-31 22:48:50 PDT
Created attachment 395133 [details]
Patch
Comment 5 Philippe Normand 2020-04-01 01:08:24 PDT
(In reply to ChangSeok Oh from comment #3)
> > src/meson.build:116:6: 
> > : Program(s) ['vapigen'] not found or not executable
> 
> The build bot seems to not have vala package..

Please disable that and the "introspection" options in the meson build.
Comment 6 ChangSeok Oh 2020-04-01 01:50:37 PDT
Created attachment 395149 [details]
Patch
Comment 7 Philippe Normand 2020-04-01 01:56:29 PDT
Comment on attachment 395149 [details]
Patch

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

> Tools/gtk/jhbuild.modules:449
> +  <meson id="manette" mesonargs="-Dintrospection=false">

-Dvapi=false too please :)
Comment 8 ChangSeok Oh 2020-04-01 02:06:27 PDT
Created attachment 395150 [details]
Patch
Comment 9 ChangSeok Oh 2020-04-01 02:07:08 PDT
(In reply to Philippe Normand from comment #7)
> Comment on attachment 395149 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=395149&action=review
> 
> > Tools/gtk/jhbuild.modules:449
> > +  <meson id="manette" mesonargs="-Dintrospection=false">
> 
> -Dvapi=false too please :)

Thanks!
Comment 10 ChangSeok Oh 2020-04-01 20:55:38 PDT
Created attachment 395240 [details]
Patch
Comment 11 Don Olmstead 2020-04-10 13:31:28 PDT
Comment on attachment 395240 [details]
Patch

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

Any new Find modules should expose a target see https://github.com/WebKit/webkit/blob/master/Source/cmake/FindOpenJPEG.cmake for something you should be able to copy pasta for the most part.

> Source/cmake/FindManette.cmake:49
> +find_package(PkgConfig)
> +pkg_check_modules(PC_MANETTE manette-0.2)
> +
> +find_path(MANETTE_INCLUDE_DIRS
> +    NAMES libmanette.h
> +    HINTS ${PC_MANETTE_INCLUDEDIR}
> +          ${PC_MANETTE_INCLUDE_DIRS}
> +)
> +
> +find_library(MANETTE_LIBRARIES
> +    NAMES manette-0.2
> +    HINTS ${PC_MANETTE_LIBDIR}
> +          ${PC_MANETTE_LIBRARY_DIRS}
> +)
> +
> +include(FindPackageHandleStandardArgs)
> +find_package_handle_standard_args(Manette
> +    FOUND_VAR MANETTE_FOUND
> +    REQUIRED_VARS MANETTE_INCLUDE_DIRS MANETTE_LIBRARIES
> +)

Please add a proper target in CMake.
Comment 12 ChangSeok Oh 2020-04-11 10:12:50 PDT
Created attachment 396169 [details]
Patch
Comment 13 ChangSeok Oh 2020-04-11 10:15:03 PDT
(In reply to Don Olmstead from comment #11)
> Comment on attachment 395240 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=395240&action=review
> 
> Any new Find modules should expose a target see
> https://github.com/WebKit/webkit/blob/master/Source/cmake/FindOpenJPEG.cmake
> for something you should be able to copy pasta for the most part.
> 
> > Source/cmake/FindManette.cmake:49
> > +find_package(PkgConfig)
> > +pkg_check_modules(PC_MANETTE manette-0.2)
> > +
> > +find_path(MANETTE_INCLUDE_DIRS
> > +    NAMES libmanette.h
> > +    HINTS ${PC_MANETTE_INCLUDEDIR}
> > +          ${PC_MANETTE_INCLUDE_DIRS}
> > +)
> > +
> > +find_library(MANETTE_LIBRARIES
> > +    NAMES manette-0.2
> > +    HINTS ${PC_MANETTE_LIBDIR}
> > +          ${PC_MANETTE_LIBRARY_DIRS}
> > +)
> > +
> > +include(FindPackageHandleStandardArgs)
> > +find_package_handle_standard_args(Manette
> > +    FOUND_VAR MANETTE_FOUND
> > +    REQUIRED_VARS MANETTE_INCLUDE_DIRS MANETTE_LIBRARIES
> > +)
> 
> Please add a proper target in CMake.

O.K.
Comment 14 Adrian Perez 2020-04-15 09:28:02 PDT
Comment on attachment 396169 [details]
Patch

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

This looks all good to me, module a few nits. It would not hurt to have
someone else take a quick look and rubber-stamp it, though.

> Source/WebCore/platform/gamepad/manette/ManetteGamepad.cpp:35
> +    , m_device(adoptGRef(static_cast<ManetteDevice*>(g_object_ref(device))))

You don't need to use adopGRef() + g_object_ref() by here, you can pass the
pointer to the GRefPtr constructor and it will increase the reference count
automatically. The following should be enough:

    ManetteGamePad(ManetteDevice* device, unsigned index):
        : PlatformGamepad(index)
        , m_device(device)
    {
    }

=)

> Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp:104
> +    std::unique_ptr<ManetteGamepad> gamepad = makeUnique<ManetteGamepad>(device, index);

You could use “auto” for the variable type here, because it is clear
from the right side of the assignment which type it will have.

> Source/cmake/FindManette.cmake:56
> +pkg_check_modules(PC_MANETTE manette-0.2)

I would add the IMPORTED_TARGET flag here, and all lines from
from 58 to 71 will not be needed.

> Source/cmake/FindManette.cmake:87
> +endif ()

…and here use the PkgConfig::PC_MANETTE target:

    if (TARGET PkgConfig::PC_MANETTE AND NOT TARGET Manette::Manette)
        add_library(Manette::Manette INTERFACE IMPORTED GLOBAL)
        set_property(TARGET Manette::Manette INTERFACE_LINK_LIBRARIES PkgConfig::PC_MANETTE)
    endif ()

This is what we currently do in Source/cmake/FindGTK.cmake :)

> Source/cmake/FindManette.cmake:91
> +if (Manette_FOUND)

If the PkgConfig target is used, this if-block is not needed.
Comment 15 Carlos Garcia Campos 2020-04-17 05:52:03 PDT
Comment on attachment 396169 [details]
Patch

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

> Source/WebCore/platform/gamepad/manette/ManetteGamepad.h:38
> +class ManetteGamepad : public PlatformGamepad {

We can mark the class final too.

> Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp:50
> +    if (provider)

Can this really be nullptr? The provider is a singleton.

> Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp:56
> +    if (provider)

Ditto.

> Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp:61
> +    : m_shouldDispatchCallbacks(false)

This could be initialized in the header.

> Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp:66
> +    g_signal_connect(G_OBJECT(m_monitor.get()), "device-connected", G_CALLBACK(onDeviceConnected), this);
> +    g_signal_connect(G_OBJECT(m_monitor.get()), "device-disconnected", G_CALLBACK(onDeviceDisconnected), this);

No need to cast GObject for g_signal_connect

> Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp:76
> +    if (shouldOpenAndScheduleManager) {

We could early return instead.

> Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp:166
> +    auto i = m_gamepadVector.find(result.get());

i -> index

> Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.h:48
> +    WEBCORE_EXPORT static ManetteGamepadProvider& singleton();
> +
> +    WEBCORE_EXPORT void startMonitoringGamepads(GamepadProviderClient&) final;
> +    WEBCORE_EXPORT void stopMonitoringGamepads(GamepadProviderClient&) final;

WEBCORE_EXPORT macros aren't needed for GTK port.

> Source/WebKit/UIProcess/Gamepad/gtk/UIGamepadProviderGtk.cpp:46
> +    if (WEBKIT_IS_WEB_VIEW(widget) && gtk_widget_is_visible(widget))
> +        return &webkitWebViewGetPage(WEBKIT_WEB_VIEW(widget));

In case of being a WebView and not visible, I guess we want to return nullptr, not iterate the web view children, no?

> Source/WebKit/UIProcess/Gamepad/gtk/UIGamepadProviderGtk.cpp:58
> +    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));

What is this?

> Source/WebKit/UIProcess/Gamepad/gtk/UIGamepadProviderGtk.cpp:62
> +        if (!GTK_IS_WINDOW(iter->data))

WebCore::widgetIsOnscreenToplevelWindow()
Comment 16 ChangSeok Oh 2020-04-19 03:29:46 PDT
Comment on attachment 396169 [details]
Patch

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

Thanks for your review! A new patch is coming.

>> Source/WebCore/platform/gamepad/manette/ManetteGamepad.cpp:35
>> +    , m_device(adoptGRef(static_cast<ManetteDevice*>(g_object_ref(device))))
> 
> You don't need to use adopGRef() + g_object_ref() by here, you can pass the
> pointer to the GRefPtr constructor and it will increase the reference count
> automatically. The following should be enough:
> 
>     ManetteGamePad(ManetteDevice* device, unsigned index):
>         : PlatformGamepad(index)
>         , m_device(device)
>     {
>     }
> 
> =)

Good to know. Thanks.

>> Source/WebCore/platform/gamepad/manette/ManetteGamepad.h:38
>> +class ManetteGamepad : public PlatformGamepad {
> 
> We can mark the class final too.

O.K.

>> Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp:50
>> +    if (provider)
> 
> Can this really be nullptr? The provider is a singleton.

No. the if condition is removed.

>> Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp:56
>> +    if (provider)
> 
> Ditto.

Done.

>> Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp:61
>> +    : m_shouldDispatchCallbacks(false)
> 
> This could be initialized in the header.

Moved to the header.

>> Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp:66
>> +    g_signal_connect(G_OBJECT(m_monitor.get()), "device-disconnected", G_CALLBACK(onDeviceDisconnected), this);
> 
> No need to cast GObject for g_signal_connect

G_OBJECT removed.

>> Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp:76
>> +    if (shouldOpenAndScheduleManager) {
> 
> We could early return instead.

Done.

>> Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp:104
>> +    std::unique_ptr<ManetteGamepad> gamepad = makeUnique<ManetteGamepad>(device, index);
> 
> You could use “auto” for the variable type here, because it is clear
> from the right side of the assignment which type it will have.

O.K.

>> Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp:166
>> +    auto i = m_gamepadVector.find(result.get());
> 
> i -> index

Fixed.

>> Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.h:48
>> +    WEBCORE_EXPORT void stopMonitoringGamepads(GamepadProviderClient&) final;
> 
> WEBCORE_EXPORT macros aren't needed for GTK port.

Removed.

>> Source/WebKit/UIProcess/Gamepad/gtk/UIGamepadProviderGtk.cpp:46
>> +        return &webkitWebViewGetPage(WEBKIT_WEB_VIEW(widget));
> 
> In case of being a WebView and not visible, I guess we want to return nullptr, not iterate the web view children, no?

You are right. Let me change the return statement to 'return gtk_widget_is_visible(widget) ? &webkitWebViewGetPage(WEBKIT_WEB_VIEW(widget)) : nullptr;'

>> Source/WebKit/UIProcess/Gamepad/gtk/UIGamepadProviderGtk.cpp:58
>> +    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
> 
> What is this?

That is a security check in process level for mac port but I blindly copied it here. Let's remove it.

>> Source/WebKit/UIProcess/Gamepad/gtk/UIGamepadProviderGtk.cpp:62
>> +        if (!GTK_IS_WINDOW(iter->data))
> 
> WebCore::widgetIsOnscreenToplevelWindow()

Great! Thanks.

>> Source/cmake/FindManette.cmake:56
>> +pkg_check_modules(PC_MANETTE manette-0.2)
> 
> I would add the IMPORTED_TARGET flag here, and all lines from
> from 58 to 71 will not be needed.

Wow! I didn't know this macro. It folds many lines up. Thanks.

>> Source/cmake/FindManette.cmake:87
>> +endif ()
> 
> …and here use the PkgConfig::PC_MANETTE target:
> 
>     if (TARGET PkgConfig::PC_MANETTE AND NOT TARGET Manette::Manette)
>         add_library(Manette::Manette INTERFACE IMPORTED GLOBAL)
>         set_property(TARGET Manette::Manette INTERFACE_LINK_LIBRARIES PkgConfig::PC_MANETTE)
>     endif ()
> 
> This is what we currently do in Source/cmake/FindGTK.cmake :)

Done.

>> Source/cmake/FindManette.cmake:91
>> +if (Manette_FOUND)
> 
> If the PkgConfig target is used, this if-block is not needed.

👍
Comment 17 ChangSeok Oh 2020-04-19 03:35:16 PDT
Created attachment 396900 [details]
Patch
Comment 18 ChangSeok Oh 2020-04-19 03:39:02 PDT
@philn, could you bump up the version of libmanette to 0.2.4 for webkit flatpak sdk? https://ftp.gnome.org/pub/gnome/sources/libmanette/0.2/
Comment 19 Philippe Normand 2020-04-19 04:02:00 PDT
(In reply to ChangSeok Oh from comment #18)
> @philn, could you bump up the version of libmanette to 0.2.4 for webkit
> flatpak sdk? https://ftp.gnome.org/pub/gnome/sources/libmanette/0.2/

It's already in the SDK. Make sure you use the latest version:

$ webkit-flatpak --command=bash
[📦 org.webkit.Webkit WebKit]$ pkg-config --modversion manette-0.2
0.2.4
Comment 20 ChangSeok Oh 2020-04-20 11:53:15 PDT
(In reply to Philippe Normand from comment #19)
> (In reply to ChangSeok Oh from comment #18)
> > @philn, could you bump up the version of libmanette to 0.2.4 for webkit
> > flatpak sdk? https://ftp.gnome.org/pub/gnome/sources/libmanette/0.2/
> 
> It's already in the SDK. Make sure you use the latest version:
> 
> $ webkit-flatpak --command=bash
> [📦 org.webkit.Webkit WebKit]$ pkg-config --modversion manette-0.2
> 0.2.4

How fast your are! Thanks.

That said, the new patch is not guilty to the red window port.
Comment 21 ChangSeok Oh 2020-05-01 21:23:59 PDT
Any comment or r+?
Comment 22 ChangSeok Oh 2020-05-19 23:07:13 PDT
Created attachment 399815 [details]
Patch

Rebase
Comment 23 Carlos Garcia Campos 2020-05-20 08:58:11 PDT
Comment on attachment 399815 [details]
Patch

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

> Source/WebKit/UIProcess/Gamepad/gtk/UIGamepadProviderGtk.cpp:31
> +#include "WebKitWebViewPrivate.h"

Better use WebKitWebViewBase
Comment 24 ChangSeok Oh 2020-05-20 12:42:43 PDT
Comment on attachment 399815 [details]
Patch

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

>> Source/WebKit/UIProcess/Gamepad/gtk/UIGamepadProviderGtk.cpp:31
>> +#include "WebKitWebViewPrivate.h"
> 
> Better use WebKitWebViewBase

You meant WebKitWebViewBasePrivate?
Comment 25 ChangSeok Oh 2020-05-20 13:12:01 PDT
Created attachment 399882 [details]
Patch to land
Comment 26 ChangSeok Oh 2020-05-20 15:27:41 PDT
Comment on attachment 399882 [details]
Patch to land

Thanks!
Comment 27 EWS 2020-05-20 15:33:40 PDT
Committed r261965: <https://trac.webkit.org/changeset/261965>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 399882 [details].
Comment 28 Radar WebKit Bug Importer 2020-05-20 15:34:18 PDT
<rdar://problem/63466509>