Commit 60e71c58 authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

exo: gamepad: Send device information to ARC

This CL adds a feature to forward gamepad device information to ARC
container. The feature can be enabled by ExoRawGamepad feature flag.

In order to forward the information, this CL adds a new Wayland event
gamepad_added_with_device_info.

This is a part of the effort to improve ARC Gampad compatibility.
Design doc: go/arc-improved-gamepad

TEST=manual(--enable-features=ExoRawGamepad to /etc/chrome_dev.conf)
BUG=b:130597086

Change-Id: If492a8a7a46d1cf321e4e8b3daa94645bb55a7c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1602193
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Reviewed-by: default avatarYuichiro Hanada <yhanada@chromium.org>
Reviewed-by: default avatarMitsuru Oshima (slow - gardening) <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659365}
parent 375dfac3
...@@ -84,7 +84,7 @@ void GamingSeat::OnGamepadDevicesUpdated() { ...@@ -84,7 +84,7 @@ void GamingSeat::OnGamepadDevicesUpdated() {
// Add each new connected gamepad. // Add each new connected gamepad.
for (auto& device : gamepad_devices) { for (auto& device : gamepad_devices) {
if (new_gamepads.find(device.id) == new_gamepads.end()) if (new_gamepads.find(device.id) == new_gamepads.end())
new_gamepads[device.id] = delegate_->GamepadAdded(); new_gamepads[device.id] = delegate_->GamepadAdded(device);
} }
new_gamepads.swap(gamepads_); new_gamepads.swap(gamepads_);
......
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
#ifndef COMPONENTS_EXO_GAMING_SEAT_DELEGATE_H_ #ifndef COMPONENTS_EXO_GAMING_SEAT_DELEGATE_H_
#define COMPONENTS_EXO_GAMING_SEAT_DELEGATE_H_ #define COMPONENTS_EXO_GAMING_SEAT_DELEGATE_H_
namespace ui {
struct InputDevice;
} // namespace ui
namespace exo { namespace exo {
class Surface; class Surface;
class GamepadDelegate; class GamepadDelegate;
...@@ -23,7 +27,7 @@ class GamingSeatDelegate { ...@@ -23,7 +27,7 @@ class GamingSeatDelegate {
// When a new gamepad is connected, gaming seat call this to get the // When a new gamepad is connected, gaming seat call this to get the
// gamepad delegate. // gamepad delegate.
virtual GamepadDelegate* GamepadAdded() = 0; virtual GamepadDelegate* GamepadAdded(const ui::InputDevice& device) = 0;
protected: protected:
virtual ~GamingSeatDelegate() {} virtual ~GamingSeatDelegate() {}
......
...@@ -25,7 +25,7 @@ namespace { ...@@ -25,7 +25,7 @@ namespace {
class MockGamingSeatDelegate : public GamingSeatDelegate { class MockGamingSeatDelegate : public GamingSeatDelegate {
public: public:
MOCK_CONST_METHOD1(CanAcceptGamepadEventsForSurface, bool(Surface*)); MOCK_CONST_METHOD1(CanAcceptGamepadEventsForSurface, bool(Surface*));
MOCK_METHOD0(GamepadAdded, GamepadDelegate*()); MOCK_METHOD1(GamepadAdded, GamepadDelegate*(const ui::InputDevice&));
MOCK_METHOD0(Die, void()); MOCK_METHOD0(Die, void());
void OnGamingSeatDestroying(GamingSeat*) override { delete this; } void OnGamingSeatDestroying(GamingSeat*) override { delete this; }
~MockGamingSeatDelegate() { Die(); } ~MockGamingSeatDelegate() { Die(); }
...@@ -99,14 +99,14 @@ TEST_F(GamingSeatTest, ConnectionChange) { ...@@ -99,14 +99,14 @@ TEST_F(GamingSeatTest, ConnectionChange) {
{ // Test sequence { // Test sequence
testing::InSequence s; testing::InSequence s;
// Connect 2 gamepads. // Connect 2 gamepads.
EXPECT_CALL(*gaming_seat_delegate, GamepadAdded()) EXPECT_CALL(*gaming_seat_delegate, GamepadAdded(testing::_))
.WillOnce(testing::Return(&gamepad_delegate[0])) .WillOnce(testing::Return(&gamepad_delegate[0]))
.WillOnce(testing::Return(&gamepad_delegate[1])); .WillOnce(testing::Return(&gamepad_delegate[1]));
// Send frame to connected gamepad. // Send frame to connected gamepad.
EXPECT_CALL(gamepad_delegate[0], OnFrame()).Times(1); EXPECT_CALL(gamepad_delegate[0], OnFrame()).Times(1);
EXPECT_CALL(gamepad_delegate[1], OnFrame()).Times(1); EXPECT_CALL(gamepad_delegate[1], OnFrame()).Times(1);
// Connect 3 more. // Connect 3 more.
EXPECT_CALL(*gaming_seat_delegate, GamepadAdded()) EXPECT_CALL(*gaming_seat_delegate, GamepadAdded(testing::_))
.WillOnce(testing::Return(&gamepad_delegate[2])) .WillOnce(testing::Return(&gamepad_delegate[2]))
.WillOnce(testing::Return(&gamepad_delegate[3])) .WillOnce(testing::Return(&gamepad_delegate[3]))
.WillOnce(testing::Return(&gamepad_delegate[4])); .WillOnce(testing::Return(&gamepad_delegate[4]));
...@@ -120,7 +120,7 @@ TEST_F(GamingSeatTest, ConnectionChange) { ...@@ -120,7 +120,7 @@ TEST_F(GamingSeatTest, ConnectionChange) {
EXPECT_CALL(gamepad_delegate[0], OnRemoved()).Times(1); EXPECT_CALL(gamepad_delegate[0], OnRemoved()).Times(1);
EXPECT_CALL(gamepad_delegate[2], OnRemoved()).Times(1); EXPECT_CALL(gamepad_delegate[2], OnRemoved()).Times(1);
EXPECT_CALL(gamepad_delegate[4], OnRemoved()).Times(1); EXPECT_CALL(gamepad_delegate[4], OnRemoved()).Times(1);
EXPECT_CALL(*gaming_seat_delegate, GamepadAdded()) EXPECT_CALL(*gaming_seat_delegate, GamepadAdded(testing::_))
.WillOnce(testing::Return(&gamepad_delegate[5])); .WillOnce(testing::Return(&gamepad_delegate[5]));
// Send frame to all gamepads. // Send frame to all gamepads.
EXPECT_CALL(gamepad_delegate[1], OnFrame()).Times(1); EXPECT_CALL(gamepad_delegate[1], OnFrame()).Times(1);
......
...@@ -146,6 +146,7 @@ source_set("wayland") { ...@@ -146,6 +146,7 @@ source_set("wayland") {
"//ui/display/manager", "//ui/display/manager",
"//ui/events:dom_keycode_converter", "//ui/events:dom_keycode_converter",
"//ui/events:events_base", "//ui/events:events_base",
"//ui/events/devices:devices",
"//ui/views", "//ui/views",
"//ui/wm:wm", "//ui/wm:wm",
"//ui/wm/public", "//ui/wm/public",
......
...@@ -9,17 +9,34 @@ ...@@ -9,17 +9,34 @@
#include <wayland-server-core.h> #include <wayland-server-core.h>
#include <wayland-server-protocol-core.h> #include <wayland-server-protocol-core.h>
#include "base/feature_list.h"
#include "base/macros.h" #include "base/macros.h"
#include "components/exo/gamepad_delegate.h" #include "components/exo/gamepad_delegate.h"
#include "components/exo/gaming_seat.h" #include "components/exo/gaming_seat.h"
#include "components/exo/gaming_seat_delegate.h" #include "components/exo/gaming_seat_delegate.h"
#include "components/exo/wayland/server_util.h" #include "components/exo/wayland/server_util.h"
#include "ui/events/devices/input_device.h"
namespace exo { namespace exo {
namespace wayland { namespace wayland {
namespace { namespace {
// Expose raw gamepad device information to the client.
// TODO(tetsui): Remove when the change becomes default.
const base::Feature kRawGamepadInfoFeature{"ExoRawGamepadInfo",
base::FEATURE_DISABLED_BY_DEFAULT};
unsigned int GetGamepadBusType(ui::InputDeviceType type) {
switch (type) {
case ui::INPUT_DEVICE_BLUETOOTH:
return ZCR_GAMING_SEAT_V2_BUS_TYPE_BLUETOOTH;
default:
// Internal and unknown types also default to USB.
return ZCR_GAMING_SEAT_V2_BUS_TYPE_USB;
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// gaming_input_interface: // gaming_input_interface:
...@@ -113,7 +130,7 @@ class WaylandGamingSeatDelegate : public GamingSeatDelegate { ...@@ -113,7 +130,7 @@ class WaylandGamingSeatDelegate : public GamingSeatDelegate {
wl_resource_get_client(surface_resource) == wl_resource_get_client(surface_resource) ==
wl_resource_get_client(gaming_seat_resource_); wl_resource_get_client(gaming_seat_resource_);
} }
GamepadDelegate* GamepadAdded() override { GamepadDelegate* GamepadAdded(const ui::InputDevice& device) override {
wl_resource* gamepad_resource = wl_resource* gamepad_resource =
wl_resource_create(wl_resource_get_client(gaming_seat_resource_), wl_resource_create(wl_resource_get_client(gaming_seat_resource_),
&zcr_gamepad_v2_interface, &zcr_gamepad_v2_interface,
...@@ -126,8 +143,20 @@ class WaylandGamingSeatDelegate : public GamingSeatDelegate { ...@@ -126,8 +143,20 @@ class WaylandGamingSeatDelegate : public GamingSeatDelegate {
gamepad_resource, &gamepad_implementation, gamepad_delegate, gamepad_resource, &gamepad_implementation, gamepad_delegate,
&WaylandGamepadDelegate::ResetGamepadResource); &WaylandGamepadDelegate::ResetGamepadResource);
zcr_gaming_seat_v2_send_gamepad_added(gaming_seat_resource_, if (base::FeatureList::IsEnabled(kRawGamepadInfoFeature)) {
gamepad_resource); // The version is temporarily set to 0 because the information is not
// available in ui::InputDevice.
// TODO(tetsui): Add version field to ui::InputDevice
zcr_gaming_seat_v2_send_gamepad_added_with_device_info(
gaming_seat_resource_, gamepad_resource, device.name.c_str(),
GetGamepadBusType(device.type), device.vendor_id, device.product_id,
/*version=*/0);
// TODO(tetsui): Send joystick motion range.
} else {
zcr_gaming_seat_v2_send_gamepad_added(gaming_seat_resource_,
gamepad_resource);
}
wl_client_flush(wl_resource_get_client(gaming_seat_resource_)); wl_client_flush(wl_resource_get_client(gaming_seat_resource_));
return gamepad_delegate; return gamepad_delegate;
......
...@@ -76,6 +76,26 @@ ...@@ -76,6 +76,26 @@
</description> </description>
<arg name="gamepad" type="new_id" interface="zcr_gamepad_v2" summary="new connected gamepad"/> <arg name="gamepad" type="new_id" interface="zcr_gamepad_v2" summary="new connected gamepad"/>
</event> </event>
<enum name="bus_type">
<description summary="gamepad device bus type">
Device connection type e.g. Bluetooth
</description>
<entry name="usb" value="0" summary="Universal Serial Bus" />
<entry name="bluetooth" value="1" summary="Bluetooth" />
</enum>
<event name="gamepad_added_with_device_info">
<description summary="gamepad added event">
Notification that there is gamepad connected at this seat.
</description>
<arg name="gamepad" type="new_id" interface="zcr_gamepad_v2" summary="new connected gamepad"/>
<arg name="name" type="string" summary="name of the gamepad device" />
<arg name="bus" type="uint" enum="bus_type" summary="type of the device connection e.g. Bluetooth" />
<arg name="vendor_id" type="uint" summary="vendor ID of the gamepad device" />
<arg name="product_id" type="uint" summary="product ID of the gamepad device" />
<arg name="version" type="uint" summary="product version of the gamepad device" />
</event>
</interface> </interface>
<interface name="zcr_gamepad_v2" version="1"> <interface name="zcr_gamepad_v2" version="1">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment