Commit 9d0e9866 authored by Matt Reynolds's avatar Matt Reynolds Committed by Commit Bot

Communicate gamepad button/axis changes to blink

This CL extends the device::GamepadConsumer,
device::mojom::GamepadConsumer, and blink::WebGamepadListener interfaces
to allow gamepad button and axis events to be communicated from //device
to blink. These will be used to implement gamepad button and axis
events in javascript.

BUG=856290

Change-Id: I8ce83d5e4225e79c3b25c7d7ef65684e9ada404f
Reviewed-on: https://chromium-review.googlesource.com/1161492Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarBrandon Jones <bajones@chromium.org>
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581421}
parent 164c3c53
......@@ -49,11 +49,13 @@ class CONTENT_EXPORT PepperGamepadHost :
const IPC::Message& msg,
ppapi::host::HostMessageContext* context) override;
// GamepadConsumer implementation.
void OnGamepadConnected(unsigned index,
// device::GamepadConsumer implementation.
void OnGamepadConnected(uint32_t index,
const device::Gamepad& gamepad) override {}
void OnGamepadDisconnected(unsigned index,
void OnGamepadDisconnected(uint32_t index,
const device::Gamepad& gamepad) override {}
void OnGamepadButtonOrAxisChanged(uint32_t index,
const device::Gamepad& gamepad) override {}
private:
int32_t OnRequestMemory(ppapi::host::HostMessageContext* context);
......
......@@ -15,9 +15,11 @@ class DEVICE_GAMEPAD_EXPORT GamepadConsumer {
GamepadConsumer();
virtual ~GamepadConsumer();
virtual void OnGamepadConnected(unsigned index, const Gamepad& gamepad) = 0;
virtual void OnGamepadDisconnected(unsigned index,
virtual void OnGamepadConnected(uint32_t index, const Gamepad& gamepad) = 0;
virtual void OnGamepadDisconnected(uint32_t index,
const Gamepad& gamepad) = 0;
virtual void OnGamepadButtonOrAxisChanged(uint32_t index,
const Gamepad& gamepad) = 0;
};
} // namespace device
......
......@@ -24,7 +24,7 @@ void GamepadHapticsManager::Create(
}
void GamepadHapticsManager::PlayVibrationEffectOnce(
int pad_index,
uint32_t pad_index,
mojom::GamepadHapticEffectType type,
mojom::GamepadEffectParametersPtr params,
PlayVibrationEffectOnceCallback callback) {
......@@ -33,7 +33,7 @@ void GamepadHapticsManager::PlayVibrationEffectOnce(
}
void GamepadHapticsManager::ResetVibrationActuator(
int pad_index,
uint32_t pad_index,
ResetVibrationActuatorCallback callback) {
GamepadService::GetInstance()->ResetVibrationActuator(pad_index,
std::move(callback));
......
......@@ -20,11 +20,11 @@ class DEVICE_GAMEPAD_EXPORT GamepadHapticsManager
static void Create(mojom::GamepadHapticsManagerRequest request);
// mojom::GamepadHapticsManager implementation.
void PlayVibrationEffectOnce(int pad_index,
void PlayVibrationEffectOnce(uint32_t pad_index,
mojom::GamepadHapticEffectType,
mojom::GamepadEffectParametersPtr,
PlayVibrationEffectOnceCallback) override;
void ResetVibrationActuator(int pad_index,
void ResetVibrationActuator(uint32_t pad_index,
ResetVibrationActuatorCallback) override;
private:
......
......@@ -27,18 +27,24 @@ void GamepadMonitor::Create(mojom::GamepadMonitorRequest request) {
std::move(request));
}
void GamepadMonitor::OnGamepadConnected(unsigned index,
void GamepadMonitor::OnGamepadConnected(uint32_t index,
const Gamepad& gamepad) {
if (gamepad_observer_)
gamepad_observer_->GamepadConnected(index, gamepad);
}
void GamepadMonitor::OnGamepadDisconnected(unsigned index,
void GamepadMonitor::OnGamepadDisconnected(uint32_t index,
const Gamepad& gamepad) {
if (gamepad_observer_)
gamepad_observer_->GamepadDisconnected(index, gamepad);
}
void GamepadMonitor::OnGamepadButtonOrAxisChanged(uint32_t index,
const Gamepad& gamepad) {
if (gamepad_observer_)
gamepad_observer_->GamepadButtonOrAxisChanged(index, gamepad);
}
void GamepadMonitor::GamepadStartPolling(GamepadStartPollingCallback callback) {
DCHECK(!is_started_);
is_started_ = true;
......
......@@ -22,8 +22,10 @@ class DEVICE_GAMEPAD_EXPORT GamepadMonitor : public GamepadConsumer,
static void Create(mojom::GamepadMonitorRequest request);
// GamepadConsumer implementation.
void OnGamepadConnected(unsigned index, const Gamepad& gamepad) override;
void OnGamepadDisconnected(unsigned index, const Gamepad& gamepad) override;
void OnGamepadConnected(uint32_t index, const Gamepad& gamepad) override;
void OnGamepadDisconnected(uint32_t index, const Gamepad& gamepad) override;
void OnGamepadButtonOrAxisChanged(uint32_t index,
const Gamepad& gamepad) override;
// mojom::GamepadMonitor implementation.
void GamepadStartPolling(GamepadStartPollingCallback callback) override;
......
......@@ -20,7 +20,7 @@ const float kMinAxisResetValue = 0.1f;
GamepadPadStateProvider::GamepadPadStateProvider() {
pad_states_.reset(new PadState[Gamepads::kItemsLengthCap]);
for (unsigned i = 0; i < Gamepads::kItemsLengthCap; ++i)
for (size_t i = 0; i < Gamepads::kItemsLengthCap; ++i)
ClearPadState(pad_states_.get()[i]);
}
......@@ -50,8 +50,8 @@ PadState* GamepadPadStateProvider::GetPadState(GamepadSource source,
return empty_slot;
}
PadState* GamepadPadStateProvider::GetConnectedPadState(int pad_index) {
if (pad_index < 0 || pad_index >= (int)Gamepads::kItemsLengthCap)
PadState* GamepadPadStateProvider::GetConnectedPadState(uint32_t pad_index) {
if (pad_index >= Gamepads::kItemsLengthCap)
return nullptr;
PadState& pad_state = pad_states_.get()[pad_index];
......
......@@ -91,7 +91,7 @@ class DEVICE_GAMEPAD_EXPORT GamepadPadStateProvider {
// Gets a PadState object for a connected gamepad by specifying its index in
// the pad_states_ array. Returns NULL if there is no connected gamepad at
// that index.
PadState* GetConnectedPadState(int pad_index);
PadState* GetConnectedPadState(uint32_t pad_index);
protected:
void ClearPadState(PadState& state);
......
......@@ -288,11 +288,7 @@ void GamepadPlatformDataFetcherLinux::EnumerateSubsystemDevices(
}
void GamepadPlatformDataFetcherLinux::ReadDeviceData(size_t index) {
// Linker does not like CHECK_LT(index, Gamepads::kItemsLengthCap). =/
if (index >= Gamepads::kItemsLengthCap) {
CHECK(false);
return;
}
CHECK_LT(index, Gamepads::kItemsLengthCap);
GamepadDeviceLinux* device = GetDeviceWithJoydevIndex(index);
if (!device)
......
......@@ -97,7 +97,7 @@ void GamepadProvider::GetCurrentGamepadData(Gamepads* data) {
}
void GamepadProvider::PlayVibrationEffectOnce(
int pad_index,
uint32_t pad_index,
mojom::GamepadHapticEffectType type,
mojom::GamepadEffectParametersPtr params,
mojom::GamepadHapticsManager::PlayVibrationEffectOnceCallback callback) {
......@@ -120,7 +120,7 @@ void GamepadProvider::PlayVibrationEffectOnce(
}
void GamepadProvider::ResetVibrationActuator(
int pad_index,
uint32_t pad_index,
mojom::GamepadHapticsManager::ResetVibrationActuatorCallback callback) {
PadState* pad_state = GetConnectedPadState(pad_index);
if (!pad_state) {
......@@ -284,7 +284,7 @@ void GamepadProvider::DoPoll() {
devices_changed_ = false;
}
for (unsigned i = 0; i < Gamepads::kItemsLengthCap; ++i)
for (size_t i = 0; i < Gamepads::kItemsLengthCap; ++i)
pad_states_.get()[i].is_active = false;
// Loop through each registered data fetcher and poll its gamepad data.
......@@ -300,7 +300,7 @@ void GamepadProvider::DoPoll() {
// Send out disconnect events using the last polled data before we wipe it out
// in the mapping step.
if (ever_had_user_gesture_) {
for (unsigned i = 0; i < Gamepads::kItemsLengthCap; ++i) {
for (size_t i = 0; i < Gamepads::kItemsLengthCap; ++i) {
PadState& state = pad_states_.get()[i];
if (!state.is_newly_active && !state.is_active &&
......@@ -319,7 +319,7 @@ void GamepadProvider::DoPoll() {
// Acquire the SeqLock. There is only ever one writer to this data.
// See gamepad_shared_buffer.h.
gamepad_shared_buffer_->WriteBegin();
for (unsigned i = 0; i < Gamepads::kItemsLengthCap; ++i) {
for (size_t i = 0; i < Gamepads::kItemsLengthCap; ++i) {
PadState& state = pad_states_.get()[i];
// Must run through the map+sanitize here or CheckForUserGesture may fail.
MapAndSanitizeGamepadData(&state, &buffer->items[i], sanitize_);
......@@ -328,7 +328,7 @@ void GamepadProvider::DoPoll() {
}
if (ever_had_user_gesture_) {
for (unsigned i = 0; i < Gamepads::kItemsLengthCap; ++i) {
for (size_t i = 0; i < Gamepads::kItemsLengthCap; ++i) {
PadState& state = pad_states_.get()[i];
if (state.is_newly_active && buffer->items[i].connected) {
......@@ -348,7 +348,7 @@ void GamepadProvider::DoPoll() {
// CheckForUserGesture call above. If we don't clear |is_newly_active| here,
// we will notify again for the same gamepad on the next polling cycle.
if (did_notify) {
for (unsigned i = 0; i < Gamepads::kItemsLengthCap; ++i)
for (size_t i = 0; i < Gamepads::kItemsLengthCap; ++i)
pad_states_.get()[i].is_newly_active = false;
}
......@@ -374,7 +374,7 @@ void GamepadProvider::ScheduleDoPoll() {
}
void GamepadProvider::OnGamepadConnectionChange(bool connected,
int index,
uint32_t index,
const Gamepad& pad) {
if (connection_change_client_)
connection_change_client_->OnGamepadConnectionChange(connected, index, pad);
......
......@@ -35,7 +35,7 @@ class GamepadDataFetcher;
class DEVICE_GAMEPAD_EXPORT GamepadConnectionChangeClient {
public:
virtual void OnGamepadConnectionChange(bool connected,
int index,
uint32_t index,
const Gamepad& pad) = 0;
};
......@@ -59,13 +59,13 @@ class DEVICE_GAMEPAD_EXPORT GamepadProvider
void GetCurrentGamepadData(Gamepads* data);
void PlayVibrationEffectOnce(
int pad_index,
uint32_t pad_index,
mojom::GamepadHapticEffectType,
mojom::GamepadEffectParametersPtr,
mojom::GamepadHapticsManager::PlayVibrationEffectOnceCallback);
void ResetVibrationActuator(
int pad_index,
uint32_t pad_index,
mojom::GamepadHapticsManager::ResetVibrationActuatorCallback);
// Pause and resume the background polling thread. Can be called from any
......@@ -106,7 +106,9 @@ class DEVICE_GAMEPAD_EXPORT GamepadProvider
void DoPoll();
void ScheduleDoPoll();
void OnGamepadConnectionChange(bool connected, int index, const Gamepad& pad);
void OnGamepadConnectionChange(bool connected,
uint32_t index,
const Gamepad& pad);
// Checks the gamepad state to see if the user has interacted with it. Returns
// true if any user gesture observers were notified.
......
......@@ -72,7 +72,7 @@ void GamepadService::ConsumerBecameActive(device::GamepadConsumer* consumer) {
const std::vector<bool>& old_connected_state = consumer_state_it->second;
Gamepads gamepads;
provider_->GetCurrentGamepadData(&gamepads);
for (unsigned i = 0; i < Gamepads::kItemsLengthCap; ++i) {
for (size_t i = 0; i < Gamepads::kItemsLengthCap; ++i) {
const Gamepad& gamepad = gamepads.items[i];
if (gamepad.connected) {
info.consumer->OnGamepadConnected(i, gamepad);
......@@ -109,7 +109,7 @@ void GamepadService::ConsumerBecameInactive(device::GamepadConsumer* consumer) {
Gamepads gamepads;
provider_->GetCurrentGamepadData(&gamepads);
std::vector<bool> connected_state(Gamepads::kItemsLengthCap);
for (unsigned i = 0; i < Gamepads::kItemsLengthCap; ++i)
for (size_t i = 0; i < Gamepads::kItemsLengthCap; ++i)
connected_state[i] = gamepads.items[i].connected;
inactive_consumer_state_[consumer] = connected_state;
}
......@@ -136,7 +136,7 @@ void GamepadService::Terminate() {
}
void GamepadService::OnGamepadConnectionChange(bool connected,
int index,
uint32_t index,
const Gamepad& pad) {
if (connected) {
main_thread_task_runner_->PostTask(
......@@ -149,7 +149,7 @@ void GamepadService::OnGamepadConnectionChange(bool connected,
}
}
void GamepadService::OnGamepadConnected(int index, const Gamepad& pad) {
void GamepadService::OnGamepadConnected(uint32_t index, const Gamepad& pad) {
DCHECK(main_thread_task_runner_->BelongsToCurrentThread());
for (ConsumerSet::iterator it = consumers_.begin(); it != consumers_.end();
......@@ -159,7 +159,7 @@ void GamepadService::OnGamepadConnected(int index, const Gamepad& pad) {
}
}
void GamepadService::OnGamepadDisconnected(int index, const Gamepad& pad) {
void GamepadService::OnGamepadDisconnected(uint32_t index, const Gamepad& pad) {
DCHECK(main_thread_task_runner_->BelongsToCurrentThread());
for (ConsumerSet::iterator it = consumers_.begin(); it != consumers_.end();
......@@ -170,7 +170,7 @@ void GamepadService::OnGamepadDisconnected(int index, const Gamepad& pad) {
}
void GamepadService::PlayVibrationEffectOnce(
int pad_index,
uint32_t pad_index,
mojom::GamepadHapticEffectType type,
mojom::GamepadEffectParametersPtr params,
mojom::GamepadHapticsManager::PlayVibrationEffectOnceCallback callback) {
......@@ -187,7 +187,7 @@ void GamepadService::PlayVibrationEffectOnce(
}
void GamepadService::ResetVibrationActuator(
int pad_index,
uint32_t pad_index,
mojom::GamepadHapticsManager::ResetVibrationActuatorCallback callback) {
DCHECK(main_thread_task_runner_->BelongsToCurrentThread());
......@@ -220,7 +220,7 @@ void GamepadService::OnUserGesture() {
info.did_observe_user_gesture = true;
Gamepads gamepads;
provider_->GetCurrentGamepadData(&gamepads);
for (unsigned i = 0; i < Gamepads::kItemsLengthCap; ++i) {
for (size_t i = 0; i < Gamepads::kItemsLengthCap; ++i) {
const Gamepad& pad = gamepads.items[i];
if (pad.connected)
info.consumer->OnGamepadConnected(i, pad);
......
......@@ -77,16 +77,16 @@ class DEVICE_GAMEPAD_EXPORT GamepadService
void Terminate();
// Called on IO thread when a gamepad is connected.
void OnGamepadConnected(int index, const Gamepad& pad);
void OnGamepadConnected(uint32_t index, const Gamepad& pad);
// Called on IO thread when a gamepad is disconnected.
void OnGamepadDisconnected(int index, const Gamepad& pad);
void OnGamepadDisconnected(uint32_t index, const Gamepad& pad);
// Request playback of a haptic effect on the specified gamepad. Once effect
// playback is complete or is preempted by a different effect, the callback
// will be called.
void PlayVibrationEffectOnce(
int pad_index,
uint32_t pad_index,
mojom::GamepadHapticEffectType,
mojom::GamepadEffectParametersPtr,
mojom::GamepadHapticsManager::PlayVibrationEffectOnceCallback);
......@@ -95,7 +95,7 @@ class DEVICE_GAMEPAD_EXPORT GamepadService
// effects are currently being played, they are preempted and vibration is
// stopped.
void ResetVibrationActuator(
int pad_index,
uint32_t pad_index,
mojom::GamepadHapticsManager::ResetVibrationActuatorCallback);
private:
......@@ -116,7 +116,7 @@ class DEVICE_GAMEPAD_EXPORT GamepadService
void OnUserGesture();
void OnGamepadConnectionChange(bool connected,
int index,
uint32_t index,
const Gamepad& pad) override;
void SetSanitizationEnabled(bool sanitize);
......
......@@ -25,12 +25,14 @@ class ConnectionListener : public device::GamepadConsumer {
public:
ConnectionListener() { ClearCounters(); }
void OnGamepadConnected(unsigned index, const Gamepad& gamepad) override {
void OnGamepadConnected(uint32_t index, const Gamepad& gamepad) override {
connected_counter_++;
}
void OnGamepadDisconnected(unsigned index, const Gamepad& gamepad) override {
void OnGamepadDisconnected(uint32_t index, const Gamepad& gamepad) override {
disconnected_counter_++;
}
void OnGamepadButtonOrAxisChanged(uint32_t index,
const Gamepad& gamepad) override {}
void ClearCounters() {
connected_counter_ = 0;
......
......@@ -21,7 +21,7 @@ void MockGamepadDataFetcher::GetGamepadData(bool devices_changed_hint) {
{
base::AutoLock lock(lock_);
for (unsigned int i = 0; i < Gamepads::kItemsLengthCap; ++i) {
for (size_t i = 0; i < Gamepads::kItemsLengthCap; ++i) {
if (test_data_.items[i].connected) {
PadState* pad = GetPadState(i);
if (pad)
......
......@@ -18,7 +18,7 @@ const float kAxisMoveAmountThreshold = 0.5;
namespace device {
bool GamepadsHaveUserGesture(const Gamepads& gamepads) {
for (unsigned int i = 0; i < Gamepads::kItemsLengthCap; i++) {
for (size_t i = 0; i < Gamepads::kItemsLengthCap; i++) {
const Gamepad& pad = gamepads.items[i];
// If the device is physically connected, then check the buttons and axes
......@@ -33,14 +33,13 @@ bool GamepadsHaveUserGesture(const Gamepads& gamepads) {
if (pad.display_id != 0)
return true;
for (unsigned int button_index = 0; button_index < pad.buttons_length;
for (size_t button_index = 0; button_index < pad.buttons_length;
button_index++) {
if (pad.buttons[button_index].pressed)
return true;
}
for (unsigned int axes_index = 0; axes_index < pad.axes_length;
axes_index++) {
for (size_t axes_index = 0; axes_index < pad.axes_length; axes_index++) {
if (fabs(pad.axes[axes_index]) > kAxisMoveAmountThreshold)
return true;
}
......
......@@ -17,6 +17,7 @@ source_set("shared_with_blink") {
sources = [
"gamepad.cc",
"gamepad.h",
"gamepads.cc",
"gamepads.h",
]
# Do not add deps here per the above comment.
......
......@@ -6,6 +6,11 @@
namespace device {
const size_t Gamepad::kIdLengthCap;
const size_t Gamepad::kMappingLengthCap;
const size_t Gamepad::kAxesLengthCap;
const size_t Gamepad::kButtonsLengthCap;
Gamepad::Gamepad()
: connected(false),
timestamp(0),
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "device/gamepad/public/cpp/gamepads.h"
namespace device {
const size_t Gamepads::kItemsLengthCap;
} // namespace device
......@@ -67,8 +67,19 @@ struct Gamepad {
};
interface GamepadObserver {
GamepadConnected(int32 index, Gamepad gamepad);
GamepadDisconnected(int32 index, Gamepad gamepad);
// Called when a gamepad is connected. |index| is the index of the gamepad in
// the gamepad array, and |gamepad| is a reference to the connected gamepad.
GamepadConnected(uint32 index, Gamepad gamepad);
// Called when a gamepad is disconnected. |index| is the former index of the
// gamepad in the gamepad array, and |gamepad| is a reference to the
// connected gamepad.
GamepadDisconnected(uint32 index, Gamepad gamepad);
// Called when a button or axis is changed on a connected gamepad. |index| is
// the index of the gamepad in the gamepad array, and |gamepad| is a reference
// to the gamepad.
GamepadButtonOrAxisChanged(uint32 index, Gamepad gamepad);
};
// Asks the browser process to start polling, and return a shared memory
......@@ -102,9 +113,9 @@ enum GamepadHapticsResult {
};
interface GamepadHapticsManager {
PlayVibrationEffectOnce(int32 pad_index,
PlayVibrationEffectOnce(uint32 pad_index,
GamepadHapticEffectType type,
GamepadEffectParameters params)
=> (GamepadHapticsResult result);
ResetVibrationActuator(int32 pad_index) => (GamepadHapticsResult result);
ResetVibrationActuator(uint32 pad_index) => (GamepadHapticsResult result);
};
......@@ -15,8 +15,22 @@ namespace blink {
class WebGamepadListener : public WebPlatformEventListener {
public:
virtual void DidConnectGamepad(unsigned index, const device::Gamepad&) = 0;
virtual void DidDisconnectGamepad(unsigned index, const device::Gamepad&) = 0;
// Called when a gamepad is connected. |index| is the index of the gamepad in
// the gamepad array, and |gamepad| is a reference to the connected gamepad.
virtual void DidConnectGamepad(uint32_t index,
const device::Gamepad& gamepad) = 0;
// Called when a gamepad is disconnected. |index| is the former index of the
// gamepad in the gamepad array, and |gamepad| is a reference to the
// connected gamepad.
virtual void DidDisconnectGamepad(uint32_t index,
const device::Gamepad& gamepad) = 0;
// Called when a button or axis is changed on a connected gamepad. |index| is
// the index of the gamepad in the gamepad array, and |gamepad| is a reference
// to the gamepad.
virtual void ButtonOrAxisDidChange(uint32_t index,
const device::Gamepad& gamepad) = 0;
protected:
~WebGamepadListener() override = default;
......
......@@ -26,7 +26,7 @@ void GamepadDispatcher::SampleGamepads(device::Gamepads& gamepads) {
}
void GamepadDispatcher::PlayVibrationEffectOnce(
int pad_index,
uint32_t pad_index,
device::mojom::blink::GamepadHapticEffectType type,
device::mojom::blink::GamepadEffectParametersPtr params,
GamepadHapticsManager::PlayVibrationEffectOnceCallback callback) {
......@@ -36,7 +36,7 @@ void GamepadDispatcher::PlayVibrationEffectOnce(
}
void GamepadDispatcher::ResetVibrationActuator(
int pad_index,
uint32_t pad_index,
GamepadHapticsManager::ResetVibrationActuatorCallback callback) {
InitializeHaptics();
gamepad_haptics_manager_->ResetVibrationActuator(pad_index,
......@@ -58,21 +58,27 @@ void GamepadDispatcher::Trace(blink::Visitor* visitor) {
PlatformEventDispatcher::Trace(visitor);
}
void GamepadDispatcher::DidConnectGamepad(unsigned index,
void GamepadDispatcher::DidConnectGamepad(uint32_t index,
const device::Gamepad& gamepad) {
DispatchDidConnectOrDisconnectGamepad(index, gamepad, true);
}
void GamepadDispatcher::DidDisconnectGamepad(unsigned index,
void GamepadDispatcher::DidDisconnectGamepad(uint32_t index,
const device::Gamepad& gamepad) {
DispatchDidConnectOrDisconnectGamepad(index, gamepad, false);
}
void GamepadDispatcher::ButtonOrAxisDidChange(uint32_t index,
const device::Gamepad& gamepad) {
DCHECK_LT(index, device::Gamepads::kItemsLengthCap);
NotifyControllers();
}
void GamepadDispatcher::DispatchDidConnectOrDisconnectGamepad(
unsigned index,
uint32_t index,
const device::Gamepad& gamepad,
bool connected) {
DCHECK(index < device::Gamepads::kItemsLengthCap);
DCHECK_LT(index, device::Gamepads::kItemsLengthCap);
DCHECK_EQ(connected, gamepad.connected);
NotifyControllers();
......
......@@ -27,12 +27,12 @@ class GamepadDispatcher final
void SampleGamepads(device::Gamepads&);
void PlayVibrationEffectOnce(int pad_index,
void PlayVibrationEffectOnce(uint32_t pad_index,
device::mojom::blink::GamepadHapticEffectType,
device::mojom::blink::GamepadEffectParametersPtr,
device::mojom::blink::GamepadHapticsManager::
PlayVibrationEffectOnceCallback);
void ResetVibrationActuator(int pad_index,
void ResetVibrationActuator(uint32_t pad_index,
device::mojom::blink::GamepadHapticsManager::
ResetVibrationActuatorCallback);
......@@ -44,14 +44,15 @@ class GamepadDispatcher final
void InitializeHaptics();
// WebGamepadListener
void DidConnectGamepad(unsigned index, const device::Gamepad&) override;
void DidDisconnectGamepad(unsigned index, const device::Gamepad&) override;
void DidConnectGamepad(uint32_t index, const device::Gamepad&) override;
void DidDisconnectGamepad(uint32_t index, const device::Gamepad&) override;
void ButtonOrAxisDidChange(uint32_t index, const device::Gamepad&) override;
// PlatformEventDispatcher
void StartListening(LocalFrame* frame) override;
void StopListening() override;
void DispatchDidConnectOrDisconnectGamepad(unsigned index,
void DispatchDidConnectOrDisconnectGamepad(uint32_t index,
const device::Gamepad&,
bool connected);
......
......@@ -110,7 +110,7 @@ void GamepadSharedMemoryReader::SampleGamepads(device::Gamepads& gamepads) {
// gamepads to prevent fingerprinting. The actual data is not cleared.
// WebKit will only copy out data into the JS buffers for connected
// gamepads so this is sufficient.
for (unsigned i = 0; i < device::Gamepads::kItemsLengthCap; i++)
for (size_t i = 0; i < device::Gamepads::kItemsLengthCap; i++)
gamepads.items[i].connected = false;
}
}
......@@ -121,7 +121,7 @@ GamepadSharedMemoryReader::~GamepadSharedMemoryReader() {
}
void GamepadSharedMemoryReader::GamepadConnected(
int index,
uint32_t index,
const device::Gamepad& gamepad) {
// The browser already checks if the user actually interacted with a device.
ever_interacted_with_ = true;
......@@ -131,10 +131,17 @@ void GamepadSharedMemoryReader::GamepadConnected(
}
void GamepadSharedMemoryReader::GamepadDisconnected(
int index,
uint32_t index,
const device::Gamepad& gamepad) {
if (listener_)
listener_->DidDisconnectGamepad(index, gamepad);
}
void GamepadSharedMemoryReader::GamepadButtonOrAxisChanged(
uint32_t index,
const device::Gamepad& gamepad) {
if (listener_)
listener_->ButtonOrAxisDidChange(index, gamepad);
}
} // namespace blink
......@@ -37,8 +37,12 @@ class GamepadSharedMemoryReader : public device::mojom::blink::GamepadObserver {
private:
// device::mojom::blink::GamepadObserver methods.
void GamepadConnected(int index, const device::Gamepad& gamepad) override;
void GamepadDisconnected(int index, const device::Gamepad& gamepad) override;
void GamepadConnected(uint32_t index,
const device::Gamepad& gamepad) override;
void GamepadDisconnected(uint32_t index,
const device::Gamepad& gamepad) override;
void GamepadButtonOrAxisChanged(uint32_t index,
const device::Gamepad& gamepad) override;
base::ReadOnlySharedMemoryRegion renderer_shared_buffer_region_;
base::ReadOnlySharedMemoryMapping renderer_shared_buffer_mapping_;
......
......@@ -88,7 +88,7 @@ bool HasUserActivation(GamepadList* gamepads) {
} // namespace
template <typename T>
static void SampleGamepad(unsigned index,
static void SampleGamepad(size_t index,
T& gamepad,
const device::Gamepad& device_gamepad,
const TimeTicks& navigation_start) {
......@@ -138,7 +138,7 @@ static void SampleGamepads(ListType* into,
GamepadDispatcher::Instance().SampleGamepads(gamepads);
for (unsigned i = 0; i < device::Gamepads::kItemsLengthCap; ++i) {
for (size_t i = 0; i < device::Gamepads::kItemsLengthCap; ++i) {
device::Gamepad& web_gamepad = gamepads.items[i];
bool hide_xr_gamepad = false;
......@@ -384,7 +384,7 @@ void NavigatorGamepad::SampleAndCheckConnectedGamepads() {
bool NavigatorGamepad::CheckConnectedGamepads(GamepadList* old_gamepads,
GamepadList* new_gamepads) {
int disconnection_count = 0;
for (unsigned i = 0; i < device::Gamepads::kItemsLengthCap; ++i) {
for (size_t i = 0; i < device::Gamepads::kItemsLengthCap; ++i) {
Gamepad* old_gamepad = old_gamepads ? old_gamepads->item(i) : nullptr;
Gamepad* new_gamepad = new_gamepads->item(i);
bool connected, disconnected;
......
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