diff --git a/dom/vr/VRServiceTest.cpp b/dom/vr/VRServiceTest.cpp index 331aef0a1381..f4dc2e8cc42a 100644 --- a/dom/vr/VRServiceTest.cpp +++ b/dom/vr/VRServiceTest.cpp @@ -140,7 +140,6 @@ void VRMockDisplay::Update() { gfx::VRManagerChild* vm = gfx::VRManagerChild::Get(); - MOZ_ASSERT(vm); vm->SendSetSensorStateToMockDisplay(mDeviceID, mSensorState); vm->SendSetDisplayInfoToMockDisplay(mDeviceID, mDisplayInfo); @@ -177,7 +176,6 @@ void VRMockController::NewButtonEvent(unsigned long aButton, bool aPressed) { gfx::VRManagerChild* vm = gfx::VRManagerChild::Get(); - MOZ_ASSERT(vm); vm->SendNewButtonEventToMockController(mDeviceID, aButton, aPressed); } @@ -185,7 +183,6 @@ void VRMockController::NewAxisMoveEvent(unsigned long aAxis, double aValue) { gfx::VRManagerChild* vm = gfx::VRManagerChild::Get(); - MOZ_ASSERT(vm); vm->SendNewAxisMoveEventToMockController(mDeviceID, aAxis, aValue); } @@ -198,9 +195,8 @@ VRMockController::NewPoseMove(const Nullable& aPosition, const Nullable& aAngularAcceleration) { gfx::VRManagerChild* vm = gfx::VRManagerChild::Get(); - MOZ_ASSERT(vm); - GamepadPoseState poseState; + poseState.flags = GamepadCapabilityFlags::Cap_Orientation | GamepadCapabilityFlags::Cap_Position | GamepadCapabilityFlags::Cap_AngularAcceleration | @@ -292,7 +288,10 @@ VRServiceTest::CreateTestService(nsPIDOMWindowInner* aWindow) VRServiceTest::VRServiceTest(nsPIDOMWindowInner* aWindow) : mWindow(aWindow), mShuttingDown(false) -{} +{ + gfx::VRManagerChild* vm = gfx::VRManagerChild::Get(); + vm->SendCreateVRTestSystem(); +} VRServiceTest::~VRServiceTest() {} @@ -320,7 +319,6 @@ VRServiceTest::AttachVRDisplay(const nsAString& aID, ErrorResult& aRv) } gfx::VRManagerChild* vm = gfx::VRManagerChild::Get(); - MOZ_ASSERT(vm); vm->CreateVRServiceTestDisplay(nsCString(ToNewUTF8String(aID)), p); return p.forget(); @@ -341,7 +339,6 @@ VRServiceTest::AttachVRController(const nsAString& aID, ErrorResult& aRv) } gfx::VRManagerChild* vm = gfx::VRManagerChild::Get(); - MOZ_ASSERT(vm); vm->CreateVRServiceTestController(nsCString(ToNewUTF8String(aID)), p); return p.forget(); diff --git a/gfx/thebes/gfxPrefs.h b/gfx/thebes/gfxPrefs.h index b89ebe9fb856..bf66516e6f09 100644 --- a/gfx/thebes/gfxPrefs.h +++ b/gfx/thebes/gfxPrefs.h @@ -325,7 +325,7 @@ private: DECL_GFX_PREF(Once, "dom.vr.openvr.enabled", VROpenVREnabled, bool, false); DECL_GFX_PREF(Once, "dom.vr.osvr.enabled", VROSVREnabled, bool, false); DECL_GFX_PREF(Live, "dom.vr.poseprediction.enabled", VRPosePredictionEnabled, bool, false); - DECL_GFX_PREF(Once, "dom.vr.puppet.enabled", VRPuppetEnabled, bool, false); + DECL_GFX_PREF(Live, "dom.vr.puppet.enabled", VRPuppetEnabled, bool, false); DECL_GFX_PREF(Live, "dom.w3c_pointer_events.enabled", PointerEventsEnabled, bool, false); DECL_GFX_PREF(Live, "dom.w3c_touch_events.enabled", TouchEventsEnabled, int32_t, 0); diff --git a/gfx/vr/VRManager.cpp b/gfx/vr/VRManager.cpp index 417156de40f3..34884ad76cf3 100644 --- a/gfx/vr/VRManager.cpp +++ b/gfx/vr/VRManager.cpp @@ -48,6 +48,7 @@ VRManager::ManagerInit() VRManager::VRManager() : mInitialized(false) + , mVRTestSystemCreated(false) { MOZ_COUNT_CTOR(VRManager); MOZ_ASSERT(sVRManagerSingleton == nullptr); @@ -89,10 +90,6 @@ VRManager::VRManager() mManagers.AppendElement(mgr); } #endif - mgr = VRSystemManagerPuppet::Create(); - if (mgr) { - mManagers.AppendElement(mgr); - } // Enable gamepad extensions while VR is enabled. // Preference only can be set at the Parent process. if (XRE_IsParentProcess() && gfxPrefs::VREnabled()) { @@ -389,6 +386,21 @@ VRManager::RemoveControllers() mVRControllers.Clear(); } +void +VRManager::CreateVRTestSystem() +{ + if (mVRTestSystemCreated) { + return; + } + + RefPtr mgr = VRSystemManagerPuppet::Create(); + if (mgr) { + mgr->Init(); + mManagers.AppendElement(mgr); + mVRTestSystemCreated = true; + } +} + template void VRManager::NotifyGamepadChange(const T& aInfo) diff --git a/gfx/vr/VRManager.h b/gfx/vr/VRManager.h index 1a7064690f84..e05e882181e4 100644 --- a/gfx/vr/VRManager.h +++ b/gfx/vr/VRManager.h @@ -48,6 +48,7 @@ public: const gfx::Rect& aRightEyeRect); RefPtr GetController(const uint32_t& aControllerID); void GetVRControllerInfo(nsTArray& aControllerInfo); + void CreateVRTestSystem(); protected: VRManager(); @@ -77,6 +78,7 @@ private: Atomic mInitialized; TimeStamp mLastRefreshTime; + bool mVRTestSystemCreated; }; } // namespace gfx diff --git a/gfx/vr/gfxVRPuppet.cpp b/gfx/vr/gfxVRPuppet.cpp index d4020c7d085d..d0b42a80aaf6 100644 --- a/gfx/vr/gfxVRPuppet.cpp +++ b/gfx/vr/gfxVRPuppet.cpp @@ -314,8 +314,6 @@ VRSystemManagerPuppet::VRSystemManagerPuppet() /*static*/ already_AddRefed VRSystemManagerPuppet::Create() { - MOZ_ASSERT(NS_IsMainThread()); - if (!gfxPrefs::VREnabled() || !gfxPrefs::VRPuppetEnabled()) { return nullptr; } diff --git a/gfx/vr/ipc/PVRManager.ipdl b/gfx/vr/ipc/PVRManager.ipdl index c84ebf2d1757..8e9506056d65 100644 --- a/gfx/vr/ipc/PVRManager.ipdl +++ b/gfx/vr/ipc/PVRManager.ipdl @@ -62,6 +62,7 @@ parent: // GetControllers synchronously returns the VR controllers that have already been // enumerated by RefreshVRControllers() but does not enumerate new ones. sync GetControllers() returns(VRControllerInfo[] aControllerInfo); + async CreateVRTestSystem(); async CreateVRServiceTestDisplay(nsCString aID, uint32_t aPromiseID); async CreateVRServiceTestController(nsCString aID, uint32_t aPromiseID); async SetDisplayInfoToMockDisplay(uint32_t aDeviceID, VRDisplayInfo aDisplayInfo); diff --git a/gfx/vr/ipc/VRManagerParent.cpp b/gfx/vr/ipc/VRManagerParent.cpp index 7d1cc9a631f1..bd9dd9511ac8 100644 --- a/gfx/vr/ipc/VRManagerParent.cpp +++ b/gfx/vr/ipc/VRManagerParent.cpp @@ -329,6 +329,14 @@ VRManagerParent::RecvGetControllers(nsTArray *aControllers) return IPC_OK(); } +mozilla::ipc::IPCResult +VRManagerParent::RecvCreateVRTestSystem() +{ + VRManager* vm = VRManager::Get(); + vm->CreateVRTestSystem(); + return IPC_OK(); +} + mozilla::ipc::IPCResult VRManagerParent::RecvCreateVRServiceTestDisplay(const nsCString& aID, const uint32_t& aPromiseID) { diff --git a/gfx/vr/ipc/VRManagerParent.h b/gfx/vr/ipc/VRManagerParent.h index 3fa4534c8b54..f969f1c28f28 100644 --- a/gfx/vr/ipc/VRManagerParent.h +++ b/gfx/vr/ipc/VRManagerParent.h @@ -94,6 +94,7 @@ protected: virtual mozilla::ipc::IPCResult RecvControllerListenerAdded() override; virtual mozilla::ipc::IPCResult RecvControllerListenerRemoved() override; virtual mozilla::ipc::IPCResult RecvGetControllers(nsTArray *aControllers) override; + virtual mozilla::ipc::IPCResult RecvCreateVRTestSystem() override; virtual mozilla::ipc::IPCResult RecvCreateVRServiceTestDisplay(const nsCString& aID, const uint32_t& aPromiseID) override; virtual mozilla::ipc::IPCResult RecvCreateVRServiceTestController(const nsCString& aID, const uint32_t& aPromiseID) override; virtual mozilla::ipc::IPCResult RecvSetDisplayInfoToMockDisplay(const uint32_t& aDeviceID,