diff --git a/gfx/vr/VRManager.cpp b/gfx/vr/VRManager.cpp index 34884ad76cf3..5a1a395ba4ed 100644 --- a/gfx/vr/VRManager.cpp +++ b/gfx/vr/VRManager.cpp @@ -200,15 +200,26 @@ VRManager::NotifyVsync(const TimeStamp& aVsyncTimestamp) mLastRefreshTime = TimeStamp::Now(); } } + + if (bHaveControllerListener) { + for (const auto& manager: mManagers) { + if (!manager->GetIsPresenting()) { + manager->HandleInput(); + } + } + } } } void VRManager::NotifyVRVsync(const uint32_t& aDisplayID) { - for (uint32_t i = 0; i < mManagers.Length(); ++i) { - mManagers[i]->HandleInput(); + for (const auto& manager: mManagers) { + if (manager->GetIsPresenting()) { + manager->HandleInput(); + } } + for (auto iter = mVRManagerParents.Iter(); !iter.Done(); iter.Next()) { Unused << iter.Get()->GetKey()->SendNotifyVRVSync(aDisplayID); } @@ -352,7 +363,7 @@ VRManager::RefreshVRControllers() controllerInfoChanged = true; } - for (const auto& controller : controllers) { + for (const auto& controller: controllers) { if (!GetController(controller->GetControllerInfo().GetControllerID())) { // This is a new controller controllerInfoChanged = true; @@ -362,7 +373,7 @@ VRManager::RefreshVRControllers() if (controllerInfoChanged) { mVRControllers.Clear(); - for (const auto& controller : controllers) { + for (const auto& controller: controllers) { mVRControllers.Put(controller->GetControllerInfo().GetControllerID(), controller); } diff --git a/gfx/vr/gfxVR.h b/gfx/vr/gfxVR.h index 552b02a772a9..a8489a0c3416 100644 --- a/gfx/vr/gfxVR.h +++ b/gfx/vr/gfxVR.h @@ -251,6 +251,7 @@ public: virtual bool Init() = 0; virtual void Destroy() = 0; virtual void GetHMDs(nsTArray>& aHMDResult) = 0; + virtual bool GetIsPresenting() = 0; virtual void HandleInput() = 0; virtual void GetControllers(nsTArray>& aControllerResult) = 0; virtual void ScanForControllers() = 0; diff --git a/gfx/vr/gfxVROSVR.cpp b/gfx/vr/gfxVROSVR.cpp index 152dca0404ca..ab2381529032 100644 --- a/gfx/vr/gfxVROSVR.cpp +++ b/gfx/vr/gfxVROSVR.cpp @@ -526,6 +526,17 @@ VRSystemManagerOSVR::GetHMDs(nsTArray>& aHMDResult) } } +bool +VRSystemManagerOSVR::GetIsPresenting() +{ + if (mHMDInfo) { + VRDisplayInfo displayInfo(mHMDInfo->GetDisplayInfo()); + return displayInfo.GetIsPresenting(); + } + + return false; +} + void VRSystemManagerOSVR::HandleInput() { diff --git a/gfx/vr/gfxVROSVR.h b/gfx/vr/gfxVROSVR.h index 221a8846f784..6e27d8458f35 100644 --- a/gfx/vr/gfxVROSVR.h +++ b/gfx/vr/gfxVROSVR.h @@ -67,6 +67,7 @@ public: virtual bool Init() override; virtual void Destroy() override; virtual void GetHMDs(nsTArray>& aHMDResult) override; + virtual bool GetIsPresenting() override; virtual void HandleInput() override; virtual void GetControllers(nsTArray>& aControllerResult) override; diff --git a/gfx/vr/gfxVROculus.cpp b/gfx/vr/gfxVROculus.cpp index b9d1bd4972c8..789a4d329b39 100644 --- a/gfx/vr/gfxVROculus.cpp +++ b/gfx/vr/gfxVROculus.cpp @@ -1048,6 +1048,17 @@ VRSystemManagerOculus::GetHMDs(nsTArray>& aHMDResult) } } +bool +VRSystemManagerOculus::GetIsPresenting() +{ + if (mHMDInfo) { + VRDisplayInfo displayInfo(mHMDInfo->GetDisplayInfo()); + return displayInfo.GetIsPresenting(); + } + + return false; +} + void VRSystemManagerOculus::HandleInput() { diff --git a/gfx/vr/gfxVROculus.h b/gfx/vr/gfxVROculus.h index 3d99138f5a93..92f2e6b85aa1 100644 --- a/gfx/vr/gfxVROculus.h +++ b/gfx/vr/gfxVROculus.h @@ -123,6 +123,7 @@ public: virtual bool Init() override; virtual void Destroy() override; virtual void GetHMDs(nsTArray >& aHMDResult) override; + virtual bool GetIsPresenting() override; virtual void HandleInput() override; virtual void GetControllers(nsTArray>& aControllerResult) override; diff --git a/gfx/vr/gfxVROpenVR.cpp b/gfx/vr/gfxVROpenVR.cpp index bdb933cef1d2..d8954c6d5f35 100644 --- a/gfx/vr/gfxVROpenVR.cpp +++ b/gfx/vr/gfxVROpenVR.cpp @@ -523,6 +523,17 @@ VRSystemManagerOpenVR::GetHMDs(nsTArray>& aHMDResult) } } +bool +VRSystemManagerOpenVR::GetIsPresenting() +{ + if (mOpenVRHMD) { + VRDisplayInfo displayInfo(mOpenVRHMD->GetDisplayInfo()); + return displayInfo.GetIsPresenting(); + } + + return false; +} + void VRSystemManagerOpenVR::HandleInput() { diff --git a/gfx/vr/gfxVROpenVR.h b/gfx/vr/gfxVROpenVR.h index 64ae2f1ff93e..8b1a4ed5e247 100644 --- a/gfx/vr/gfxVROpenVR.h +++ b/gfx/vr/gfxVROpenVR.h @@ -97,6 +97,7 @@ public: virtual bool Init() override; virtual void Destroy() override; virtual void GetHMDs(nsTArray >& aHMDResult) override; + virtual bool GetIsPresenting() override; virtual void HandleInput() override; virtual void GetControllers(nsTArray>& aControllerResult) override; diff --git a/gfx/vr/gfxVRPuppet.cpp b/gfx/vr/gfxVRPuppet.cpp index e681c2ee920c..5cfd709490cc 100644 --- a/gfx/vr/gfxVRPuppet.cpp +++ b/gfx/vr/gfxVRPuppet.cpp @@ -341,6 +341,17 @@ VRSystemManagerPuppet::GetHMDs(nsTArray>& aHMDResult) aHMDResult.AppendElement(mPuppetHMD); } +bool +VRSystemManagerPuppet::GetIsPresenting() +{ + if (mPuppetHMD) { + VRDisplayInfo displayInfo(mPuppetHMD->GetDisplayInfo()); + return displayInfo.GetIsPresenting(); + } + + return false; +} + void VRSystemManagerPuppet::HandleInput() { diff --git a/gfx/vr/gfxVRPuppet.h b/gfx/vr/gfxVRPuppet.h index 28435ae8c293..a45f6a01406b 100644 --- a/gfx/vr/gfxVRPuppet.h +++ b/gfx/vr/gfxVRPuppet.h @@ -89,6 +89,7 @@ public: virtual bool Init() override; virtual void Destroy() override; virtual void GetHMDs(nsTArray>& aHMDResult) override; + virtual bool GetIsPresenting() override; virtual void HandleInput() override; virtual void GetControllers(nsTArray>& aControllerResult) override; diff --git a/gfx/vr/ipc/VRManagerParent.cpp b/gfx/vr/ipc/VRManagerParent.cpp index af72b18a7253..59cbe94a9e69 100644 --- a/gfx/vr/ipc/VRManagerParent.cpp +++ b/gfx/vr/ipc/VRManagerParent.cpp @@ -443,7 +443,8 @@ VRManagerParent::SendGamepadUpdate(const GamepadChangeEvent& aGamepadEvent) { // GamepadManager only exists at the content process // or the same process in non-e10s mode. - if (mIsContentChild || IsSameProcess()) { + if (mHaveControllerListener && + (mIsContentChild || IsSameProcess())) { return PVRManagerParent::SendGamepadUpdate(aGamepadEvent); } else { return true;