summaryrefslogtreecommitdiff
path: root/chromium/device/gamepad/gamepad_device_linux.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-12 14:27:29 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-13 09:35:20 +0000
commitc30a6232df03e1efbd9f3b226777b07e087a1122 (patch)
treee992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/device/gamepad/gamepad_device_linux.cc
parent7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff)
downloadqtwebengine-chromium-85-based.tar.gz
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/device/gamepad/gamepad_device_linux.cc')
-rw-r--r--chromium/device/gamepad/gamepad_device_linux.cc82
1 files changed, 45 insertions, 37 deletions
diff --git a/chromium/device/gamepad/gamepad_device_linux.cc b/chromium/device/gamepad/gamepad_device_linux.cc
index f188c2a69e8..ea02ce18f51 100644
--- a/chromium/device/gamepad/gamepad_device_linux.cc
+++ b/chromium/device/gamepad/gamepad_device_linux.cc
@@ -197,6 +197,40 @@ uint16_t HexStringToUInt16WithDefault(base::StringPiece input,
return static_cast<uint16_t>(out);
}
+#if defined(OS_CHROMEOS)
+void OnOpenPathSuccess(
+ chromeos::PermissionBrokerClient::OpenPathCallback callback,
+ scoped_refptr<base::SequencedTaskRunner> polling_runner,
+ base::ScopedFD fd) {
+ polling_runner->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), std::move(fd)));
+}
+
+void OnOpenPathError(
+ chromeos::PermissionBrokerClient::OpenPathCallback callback,
+ scoped_refptr<base::SequencedTaskRunner> polling_runner,
+ const std::string& error_name,
+ const std::string& error_message) {
+ polling_runner->PostTask(
+ FROM_HERE, base::BindOnce(std::move(callback), base::ScopedFD()));
+}
+
+void OpenPathWithPermissionBroker(
+ const std::string& path,
+ chromeos::PermissionBrokerClient::OpenPathCallback callback,
+ scoped_refptr<base::SequencedTaskRunner> polling_runner) {
+ auto* client = chromeos::PermissionBrokerClient::Get();
+ DCHECK(client) << "Could not get permission broker client.";
+ auto copyable_callback = base::AdaptCallbackForRepeating(std::move(callback));
+ auto success_callback =
+ base::BindOnce(&OnOpenPathSuccess, copyable_callback, polling_runner);
+ auto error_callback =
+ base::BindOnce(&OnOpenPathError, copyable_callback, polling_runner);
+ client->OpenPath(path, std::move(success_callback),
+ std::move(error_callback));
+}
+#endif // defined(OS_CHROMEOS)
+
} // namespace
GamepadDeviceLinux::GamepadDeviceLinux(
@@ -250,6 +284,12 @@ void GamepadDeviceLinux::ReadPadState(Gamepad* pad) {
pad_updated = true;
}
+ // Mark used buttons.
+ for (size_t button_index = 0; button_index < Gamepad::kButtonsLengthCap;
+ ++button_index) {
+ pad->buttons[button_index].used = button_indices_used_[button_index];
+ }
+
if (pad_updated)
pad->timestamp = GamepadDataFetcher::CurrentTimeInMicroseconds();
}
@@ -272,6 +312,7 @@ bool GamepadDeviceLinux::ReadJoydevState(Gamepad* pad) {
continue;
pad->axes[item] = event.value / kMaxLinuxAxisValue;
+ pad->axes_used |= 1 << item;
if (item >= pad->axes_length)
pad->axes_length = item + 1;
@@ -280,6 +321,7 @@ bool GamepadDeviceLinux::ReadJoydevState(Gamepad* pad) {
if (item >= Gamepad::kButtonsLengthCap)
continue;
+ pad->buttons[item].used = true;
pad->buttons[item].pressed = event.value;
pad->buttons[item].value = event.value ? 1.0 : 0.0;
@@ -530,9 +572,8 @@ void GamepadDeviceLinux::OpenHidrawNode(const UdevGamepadLinux& pad_info,
weak_factory_.GetWeakPtr(), std::move(callback));
dbus_runner_->PostTask(
FROM_HERE,
- base::BindOnce(&GamepadDeviceLinux::OpenPathWithPermissionBroker,
- weak_factory_.GetWeakPtr(), pad_info.path,
- std::move(open_path_callback)));
+ base::BindOnce(&OpenPathWithPermissionBroker, pad_info.path,
+ std::move(open_path_callback), polling_runner_));
return;
}
#endif // defined(OS_CHROMEOS)
@@ -601,40 +642,6 @@ void GamepadDeviceLinux::CloseHidrawNode() {
hidraw_fd_.reset();
}
-#if defined(OS_CHROMEOS)
-void GamepadDeviceLinux::OpenPathWithPermissionBroker(
- const std::string& path,
- OpenPathCallback callback) {
- DCHECK(dbus_runner_->RunsTasksInCurrentSequence());
- auto* client = chromeos::PermissionBrokerClient::Get();
- DCHECK(client) << "Could not get permission broker client.";
- auto copyable_callback = base::AdaptCallbackForRepeating(std::move(callback));
- auto success_callback =
- base::BindOnce(&GamepadDeviceLinux::OnOpenPathSuccess,
- weak_factory_.GetWeakPtr(), copyable_callback);
- auto error_callback =
- base::BindOnce(&GamepadDeviceLinux::OnOpenPathError,
- weak_factory_.GetWeakPtr(), copyable_callback);
- client->OpenPath(path, std::move(success_callback),
- std::move(error_callback));
-}
-
-void GamepadDeviceLinux::OnOpenPathSuccess(OpenPathCallback callback,
- base::ScopedFD fd) {
- DCHECK(dbus_runner_->RunsTasksInCurrentSequence());
- polling_runner_->PostTask(FROM_HERE,
- base::BindOnce(std::move(callback), std::move(fd)));
-}
-
-void GamepadDeviceLinux::OnOpenPathError(OpenPathCallback callback,
- const std::string& error_name,
- const std::string& error_message) {
- DCHECK(dbus_runner_->RunsTasksInCurrentSequence());
- polling_runner_->PostTask(
- FROM_HERE, base::BindOnce(std::move(callback), base::ScopedFD()));
-}
-#endif
-
void GamepadDeviceLinux::SetVibration(double strong_magnitude,
double weak_magnitude) {
DCHECK(polling_runner_->RunsTasksInCurrentSequence());
@@ -696,6 +703,7 @@ void GamepadDeviceLinux::SetZeroVibration() {
}
base::WeakPtr<AbstractHapticGamepad> GamepadDeviceLinux::GetWeakPtr() {
+ DCHECK(polling_runner_->RunsTasksInCurrentSequence());
return weak_factory_.GetWeakPtr();
}