Bug 1299929 - Part 1: Send GamepadServiceType in the the button and axis events; r?kip, lenzak800
MozReview-Commit-ID: AmrTpNFgkVj
--- a/dom/gamepad/GamepadManager.cpp
+++ b/dom/gamepad/GamepadManager.cpp
@@ -257,24 +257,26 @@ GamepadManager::RemoveGamepad(uint32_t a
return;
}
gamepad->SetConnected(false);
NewConnectionEvent(newIndex, false);
mGamepads.Remove(newIndex);
}
void
-GamepadManager::NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed,
- double aValue)
+GamepadManager::NewButtonEvent(uint32_t aIndex, GamepadServiceType aServiceType,
+ uint32_t aButton, bool aPressed, double aValue)
{
if (mShuttingDown) {
return;
}
- RefPtr<Gamepad> gamepad = GetGamepad(aIndex);
+ uint32_t newIndex = GetGamepadIndexWithServiceType(aIndex, aServiceType);
+
+ RefPtr<Gamepad> gamepad = GetGamepad(newIndex);
if (!gamepad) {
return;
}
gamepad->SetButton(aButton, aPressed, aValue);
// Hold on to listeners in a separate array because firing events
// can mutate the mListeners array.
@@ -286,19 +288,19 @@ GamepadManager::NewButtonEvent(uint32_t
MOZ_ASSERT(listeners[i]->IsInnerWindow());
// Only send events to non-background windows
if (!listeners[i]->AsInner()->IsCurrentInnerWindow() ||
listeners[i]->GetOuterWindow()->IsBackground()) {
continue;
}
- bool firstTime = MaybeWindowHasSeenGamepad(listeners[i], aIndex);
+ bool firstTime = MaybeWindowHasSeenGamepad(listeners[i], newIndex);
- RefPtr<Gamepad> listenerGamepad = listeners[i]->GetGamepad(aIndex);
+ RefPtr<Gamepad> listenerGamepad = listeners[i]->GetGamepad(newIndex);
if (listenerGamepad) {
listenerGamepad->SetButton(aButton, aPressed, aValue);
if (firstTime) {
FireConnectionEvent(listeners[i], listenerGamepad, true);
}
if (mNonstandardEventsEnabled) {
// Fire event
FireButtonEvent(listeners[i], listenerGamepad, aButton, aValue);
@@ -325,23 +327,26 @@ GamepadManager::FireButtonEvent(EventTar
event->SetTrusted(true);
bool defaultActionEnabled = true;
aTarget->DispatchEvent(event, &defaultActionEnabled);
}
void
-GamepadManager::NewAxisMoveEvent(uint32_t aIndex, uint32_t aAxis, double aValue)
+GamepadManager::NewAxisMoveEvent(uint32_t aIndex, GamepadServiceType aServiceType,
+ uint32_t aAxis, double aValue)
{
if (mShuttingDown) {
return;
}
- RefPtr<Gamepad> gamepad = GetGamepad(aIndex);
+ uint32_t newIndex = GetGamepadIndexWithServiceType(aIndex, aServiceType);
+
+ RefPtr<Gamepad> gamepad = GetGamepad(newIndex);
if (!gamepad) {
return;
}
gamepad->SetAxis(aAxis, aValue);
// Hold on to listeners in a separate array because firing events
// can mutate the mListeners array.
nsTArray<RefPtr<nsGlobalWindow>> listeners(mListeners);
@@ -352,19 +357,19 @@ GamepadManager::NewAxisMoveEvent(uint32_
MOZ_ASSERT(listeners[i]->IsInnerWindow());
// Only send events to non-background windows
if (!listeners[i]->AsInner()->IsCurrentInnerWindow() ||
listeners[i]->GetOuterWindow()->IsBackground()) {
continue;
}
- bool firstTime = MaybeWindowHasSeenGamepad(listeners[i], aIndex);
+ bool firstTime = MaybeWindowHasSeenGamepad(listeners[i], newIndex);
- RefPtr<Gamepad> listenerGamepad = listeners[i]->GetGamepad(aIndex);
+ RefPtr<Gamepad> listenerGamepad = listeners[i]->GetGamepad(newIndex);
if (listenerGamepad) {
listenerGamepad->SetAxis(aAxis, aValue);
if (firstTime) {
FireConnectionEvent(listeners[i], listenerGamepad, true);
}
if (mNonstandardEventsEnabled) {
// Fire event
FireAxisMoveEvent(listeners[i], listenerGamepad, aAxis, aValue);
@@ -587,22 +592,23 @@ GamepadManager::Update(const GamepadChan
}
if (aEvent.type() == GamepadChangeEvent::TGamepadRemoved) {
const GamepadRemoved& a = aEvent.get_GamepadRemoved();
RemoveGamepad(a.index(), a.service_type());
return;
}
if (aEvent.type() == GamepadChangeEvent::TGamepadButtonInformation) {
const GamepadButtonInformation& a = aEvent.get_GamepadButtonInformation();
- NewButtonEvent(a.index(), a.button(), a.pressed(), a.value());
+ NewButtonEvent(a.index(), a.service_type(), a.button(),
+ a.pressed(), a.value());
return;
}
if (aEvent.type() == GamepadChangeEvent::TGamepadAxisInformation) {
const GamepadAxisInformation& a = aEvent.get_GamepadAxisInformation();
- NewAxisMoveEvent(a.index(), a.axis(), a.value());
+ NewAxisMoveEvent(a.index(), a.service_type(), a.axis(), a.value());
return;
}
MOZ_CRASH("We shouldn't be here!");
}
//Override nsIIPCBackgroundChildCreateCallback
--- a/dom/gamepad/GamepadManager.h
+++ b/dom/gamepad/GamepadManager.h
@@ -54,23 +54,24 @@ class GamepadManager final : public nsIO
// Remove the gamepad at |aIndex| from the list of known gamepads.
void RemoveGamepad(uint32_t aIndex, GamepadServiceType aServiceType);
// Update the state of |aButton| for the gamepad at |aIndex| for all
// windows that are listening and visible, and fire one of
// a gamepadbutton{up,down} event at them as well.
// aPressed is used for digital buttons, aValue is for analog buttons.
- void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed,
- double aValue);
+ void NewButtonEvent(uint32_t aIndex, GamepadServiceType aServiceType, uint32_t aButton,
+ bool aPressed, double aValue);
// Update the state of |aAxis| for the gamepad at |aIndex| for all
// windows that are listening and visible, and fire a gamepadaxismove
// event at them as well.
- void NewAxisMoveEvent(uint32_t aIndex, uint32_t aAxis, double aValue);
+ void NewAxisMoveEvent(uint32_t aIndex, GamepadServiceType aServiceType,
+ uint32_t aAxis, double aValue);
// Synchronize the state of |aGamepad| to match the gamepad stored at |aIndex|
void SyncGamepadState(uint32_t aIndex, Gamepad* aGamepad);
// Returns gamepad object if index exists, null otherwise
already_AddRefed<Gamepad> GetGamepad(uint32_t aIndex) const;
// Receive GamepadChangeEvent messages from parent process to fire DOM events
--- a/dom/gamepad/GamepadPlatformService.cpp
+++ b/dom/gamepad/GamepadPlatformService.cpp
@@ -106,17 +106,18 @@ GamepadPlatformService::RemoveGamepad(ui
void
GamepadPlatformService::NewButtonEvent(uint32_t aIndex, uint32_t aButton,
bool aPressed, double aValue)
{
// This method is called by monitor thread populated in
// platform-dependent backends
MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT(!NS_IsMainThread());
- GamepadButtonInformation a(aIndex, aButton, aPressed, aValue);
+ GamepadButtonInformation a(aIndex, GamepadServiceType::Standard,
+ aButton, aPressed, aValue);
NotifyGamepadChange<GamepadButtonInformation>(a);
}
void
GamepadPlatformService::NewButtonEvent(uint32_t aIndex, uint32_t aButton,
bool aPressed)
{
// This method is called by monitor thread populated in
@@ -130,17 +131,18 @@ GamepadPlatformService::NewButtonEvent(u
void
GamepadPlatformService::NewAxisMoveEvent(uint32_t aIndex, uint32_t aAxis,
double aValue)
{
// This method is called by monitor thread populated in
// platform-dependent backends
MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT(!NS_IsMainThread());
- GamepadAxisInformation a(aIndex, aAxis, aValue);
+ GamepadAxisInformation a(aIndex, GamepadServiceType::Standard,
+ aAxis, aValue);
NotifyGamepadChange<GamepadAxisInformation>(a);
}
void
GamepadPlatformService::ResetGamepadIndexes()
{
// This method is called by monitor thread populated in
// platform-dependent backends
--- a/dom/gamepad/GamepadServiceTest.cpp
+++ b/dom/gamepad/GamepadServiceTest.cpp
@@ -170,17 +170,18 @@ void
GamepadServiceTest::NewButtonEvent(uint32_t aIndex,
uint32_t aButton,
bool aPressed)
{
if (mShuttingDown) {
return;
}
- GamepadButtonInformation a(aIndex, aButton, aPressed, aPressed ? 1.0 : 0);
+ GamepadButtonInformation a(aIndex, GamepadServiceType::Standard,
+ aButton, aPressed, aPressed ? 1.0 : 0);
GamepadChangeEvent e(a);
uint32_t id = ++mEventNumber;
if (mChild) {
mChild->SendGamepadTestEvent(id, e);
} else {
PendingOperation op(id, e);
mPendingOperations.AppendElement(op);
@@ -192,17 +193,18 @@ GamepadServiceTest::NewButtonValueEvent(
uint32_t aButton,
bool aPressed,
double aValue)
{
if (mShuttingDown) {
return;
}
- GamepadButtonInformation a(aIndex, aButton, aPressed, aValue);
+ GamepadButtonInformation a(aIndex, GamepadServiceType::Standard,
+ aButton, aPressed, aValue);
GamepadChangeEvent e(a);
uint32_t id = ++mEventNumber;
if (mChild) {
mChild->SendGamepadTestEvent(id, e);
} else {
PendingOperation op(id, e);
mPendingOperations.AppendElement(op);
@@ -213,17 +215,18 @@ void
GamepadServiceTest::NewAxisMoveEvent(uint32_t aIndex,
uint32_t aAxis,
double aValue)
{
if (mShuttingDown) {
return;
}
- GamepadAxisInformation a(aIndex, aAxis, aValue);
+ GamepadAxisInformation a(aIndex, GamepadServiceType::Standard,
+ aAxis, aValue);
GamepadChangeEvent e(a);
uint32_t id = ++mEventNumber;
if (mChild) {
mChild->SendGamepadTestEvent(id, e);
} else {
PendingOperation op(id, e);
mPendingOperations.AppendElement(op);
--- a/dom/gamepad/ipc/GamepadEventTypes.ipdlh
+++ b/dom/gamepad/ipc/GamepadEventTypes.ipdlh
@@ -20,22 +20,24 @@ struct GamepadAdded {
struct GamepadRemoved {
uint32_t index;
GamepadServiceType service_type;
};
struct GamepadAxisInformation {
uint32_t index;
+ GamepadServiceType service_type;
uint32_t axis;
double value;
};
struct GamepadButtonInformation {
uint32_t index;
+ GamepadServiceType service_type;
uint32_t button;
bool pressed;
double value;
};
union GamepadChangeEvent {
GamepadAdded;
GamepadRemoved;
--- a/gfx/vr/gfxVR.cpp
+++ b/gfx/vr/gfxVR.cpp
@@ -75,16 +75,17 @@ VRControllerManager::AddGamepad(const ch
VRManager* vm = VRManager::Get();
MOZ_ASSERT(vm);
vm->NotifyGamepadChange<dom::GamepadAdded>(a);
}
void
VRControllerManager::NewButtonEvent(uint32_t aIndex, uint32_t aButton,
- bool aPressed, double aValue)
+ bool aPressed)
{
- dom::GamepadButtonInformation a(aIndex, aButton, aPressed, aValue);
+ dom::GamepadButtonInformation a(aIndex, dom::GamepadServiceType::VR,
+ aButton, aPressed, aPressed ? 1.0L : 0.0L);
VRManager* vm = VRManager::Get();
MOZ_ASSERT(vm);
vm->NotifyGamepadChange<dom::GamepadButtonInformation>(a);
}
--- a/gfx/vr/gfxVR.h
+++ b/gfx/vr/gfxVR.h
@@ -246,18 +246,17 @@ public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRControllerManager)
static uint32_t AllocateControllerID();
virtual bool Init() = 0;
virtual void Destroy() = 0;
virtual void HandleInput() = 0;
virtual void GetControllers(nsTArray<RefPtr<VRControllerHost>>& aControllerResult) = 0;
virtual void ScanForDevices() = 0;
- void NewButtonEvent(uint32_t aIndex, uint32_t aButton,
- bool aPressed, double aValue);
+ void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed);
void AddGamepad(const char* aID, dom::GamepadMappingType aMapping,
uint32_t aNumButtons, uint32_t aNumAxes);
protected:
VRControllerManager() : mInstalled(false), mControllerCount(0) {}
virtual ~VRControllerManager() {}
bool mInstalled;