diff --git a/dom/gamepad/GamepadManager.cpp b/dom/gamepad/GamepadManager.cpp index 752db77c2911..dde71dd0a921 100644 --- a/dom/gamepad/GamepadManager.cpp +++ b/dom/gamepad/GamepadManager.cpp @@ -684,7 +684,6 @@ GamepadManager::ActorCreated(PBackgroundChild *aActor) // Construct VRManagerChannel and ask adding the connected // VR controllers to GamepadManager mVRChannelChild = gfx::VRManagerChild::Get(); - mVRChannelChild->SetGamepadManager(this); mVRChannelChild->SendControllerListenerAdded(); #endif } diff --git a/gfx/vr/ipc/VRManagerChild.cpp b/gfx/vr/ipc/VRManagerChild.cpp index 726ca5fb64b6..fb17d2b1f377 100644 --- a/gfx/vr/ipc/VRManagerChild.cpp +++ b/gfx/vr/ipc/VRManagerChild.cpp @@ -42,7 +42,6 @@ void ReleaseVRManagerParentSingleton() { VRManagerChild::VRManagerChild() : TextureForwarder() , mDisplaysInitialized(false) - , mGamepadManager(nullptr) , mInputFrameID(-1) , mMessageLoop(MessageLoop::current()) , mFrameRequestCallbackCounter(0) @@ -484,10 +483,13 @@ VRManagerChild::RecvGamepadUpdate(const GamepadChangeEvent& aGamepadEvent) { #ifdef MOZ_GAMEPAD // VRManagerChild could be at other processes, but GamepadManager - // only exists at the content process or the parent process + // only exists at the content process or the same process // in non-e10s mode. - if (mGamepadManager) { - mGamepadManager->Update(aGamepadEvent); + MOZ_ASSERT(XRE_IsContentProcess() || IsSameProcess()); + + RefPtr gamepadManager(GamepadManager::GetService()); + if (gamepadManager) { + gamepadManager->Update(aGamepadEvent); } #endif @@ -587,13 +589,5 @@ VRManagerChild::HandleFatalError(const char* aName, const char* aMsg) const dom::ContentChild::FatalErrorIfNotUsingGPUProcess(aName, aMsg, OtherPid()); } -void -VRManagerChild::SetGamepadManager(dom::GamepadManager* aGamepadManager) -{ - MOZ_ASSERT(aGamepadManager); - - mGamepadManager = aGamepadManager; -} - } // namespace gfx } // namespace mozilla diff --git a/gfx/vr/ipc/VRManagerChild.h b/gfx/vr/ipc/VRManagerChild.h index dbe9139be11b..1d62c5f0c3fa 100644 --- a/gfx/vr/ipc/VRManagerChild.h +++ b/gfx/vr/ipc/VRManagerChild.h @@ -78,9 +78,6 @@ public: int32_t *aHandle); void CancelFrameRequestCallback(int32_t aHandle); void RunFrameRequestCallbacks(); - // GamepadManager has to be set by the content side to make sure we are using - // the same singleton GamepadManager from the same process. - void SetGamepadManager(dom::GamepadManager* aGamepadManager); void UpdateDisplayInfo(nsTArray& aDisplayUpdates); void FireDOMVRDisplayConnectEvent(); @@ -153,7 +150,6 @@ private: nsTArray > mDisplays; bool mDisplaysInitialized; nsTArray mNavigatorCallbacks; - dom::GamepadManager* mGamepadManager; int32_t mInputFrameID; diff --git a/gfx/vr/ipc/VRManagerParent.cpp b/gfx/vr/ipc/VRManagerParent.cpp index 588e2426bd48..cff33fde10d5 100644 --- a/gfx/vr/ipc/VRManagerParent.cpp +++ b/gfx/vr/ipc/VRManagerParent.cpp @@ -19,9 +19,10 @@ namespace mozilla { using namespace layers; namespace gfx { -VRManagerParent::VRManagerParent(ProcessId aChildProcessId) +VRManagerParent::VRManagerParent(ProcessId aChildProcessId, bool aIsContentChild) : HostIPCAllocator() , mHaveEventListener(false) + , mIsContentChild(aIsContentChild) { MOZ_COUNT_CTOR(VRManagerParent); MOZ_ASSERT(NS_IsMainThread()); @@ -156,7 +157,7 @@ VRManagerParent::CreateForContent(Endpoint&& aEndpoint) { MessageLoop* loop = layers::CompositorThreadHolder::Loop(); - RefPtr vmp = new VRManagerParent(aEndpoint.OtherPid()); + RefPtr vmp = new VRManagerParent(aEndpoint.OtherPid(), true); loop->PostTask(NewRunnableMethod&&>( vmp, &VRManagerParent::Bind, Move(aEndpoint))); @@ -184,7 +185,7 @@ VRManagerParent::RegisterVRManagerInCompositorThread(VRManagerParent* aVRManager VRManagerParent::CreateSameProcess() { MessageLoop* loop = mozilla::layers::CompositorThreadHolder::Loop(); - RefPtr vmp = new VRManagerParent(base::GetCurrentProcId()); + RefPtr vmp = new VRManagerParent(base::GetCurrentProcId(), false); vmp->mCompositorThreadHolder = layers::CompositorThreadHolder::GetSingleton(); vmp->mSelfRef = vmp; loop->PostTask(NewRunnableFunction(RegisterVRManagerInCompositorThread, vmp.get())); @@ -196,7 +197,7 @@ VRManagerParent::CreateForGPUProcess(Endpoint&& aEndpoint) { MessageLoop* loop = mozilla::layers::CompositorThreadHolder::Loop(); - RefPtr vmp = new VRManagerParent(aEndpoint.OtherPid()); + RefPtr vmp = new VRManagerParent(aEndpoint.OtherPid(), false); vmp->mCompositorThreadHolder = layers::CompositorThreadHolder::GetSingleton(); loop->PostTask(NewRunnableMethod&&>( vmp, &VRManagerParent::Bind, Move(aEndpoint))); @@ -315,5 +316,17 @@ VRManagerParent::RecvGetControllers(nsTArray *aControllers) return IPC_OK(); } +bool +VRManagerParent::SendGamepadUpdate(const GamepadChangeEvent& aGamepadEvent) +{ + // GamepadManager only exists at the content process + // or the same process in non-e10s mode. + if (mIsContentChild || IsSameProcess()) { + return PVRManagerParent::SendGamepadUpdate(aGamepadEvent); + } else { + return true; + } +} + } // namespace gfx } // namespace mozilla diff --git a/gfx/vr/ipc/VRManagerParent.h b/gfx/vr/ipc/VRManagerParent.h index df95749b5591..814f0415dd96 100644 --- a/gfx/vr/ipc/VRManagerParent.h +++ b/gfx/vr/ipc/VRManagerParent.h @@ -27,7 +27,7 @@ class VRManagerParent final : public PVRManagerParent , public ShmemAllocator { public: - explicit VRManagerParent(ProcessId aChildProcessId); + explicit VRManagerParent(ProcessId aChildProcessId, bool aIsContentChild); static VRManagerParent* CreateSameProcess(); static bool CreateForGPUProcess(Endpoint&& aEndpoint); @@ -54,6 +54,7 @@ public: virtual void NotifyNotUsed(PTextureParent* aTexture, uint64_t aTransactionId) override; virtual void SendAsyncMessage(const InfallibleTArray& aMessage) override; + bool SendGamepadUpdate(const GamepadChangeEvent& aGamepadEvent); protected: ~VRManagerParent(); @@ -108,6 +109,7 @@ private: // Keep the VRManager alive, until we have destroyed ourselves. RefPtr mVRManagerHolder; bool mHaveEventListener; + bool mIsContentChild; }; } // namespace mozilla