diff --git a/gfx/ipc/GPUParent.cpp b/gfx/ipc/GPUParent.cpp index 029c4fc087b6..73d4f194d2fd 100644 --- a/gfx/ipc/GPUParent.cpp +++ b/gfx/ipc/GPUParent.cpp @@ -121,6 +121,8 @@ GPUParent::Init(base::ProcessId aParentPid, } CompositorThreadHolder::Start(); + // TODO: Bug 1406327, Start VRListenerThreadHolder when loading VR content. + VRListenerThreadHolder::Start(); APZThreadUtils::SetControllerThread(CompositorThreadHolder::Loop()); APZCTreeManager::InitializeGlobalState(); LayerTreeOwnerTracker::Initialize(); diff --git a/gfx/layers/ipc/CompositorBridgeParent.cpp b/gfx/layers/ipc/CompositorBridgeParent.cpp index e3de304b7bcb..1cf1c07b7dde 100644 --- a/gfx/layers/ipc/CompositorBridgeParent.cpp +++ b/gfx/layers/ipc/CompositorBridgeParent.cpp @@ -32,6 +32,7 @@ #include "mozilla/gfx/Point.h" // for IntSize #include "mozilla/gfx/Rect.h" // for IntSize #include "mozilla/gfx/gfxVars.h" // for gfxVars +#include "VRManager.h" // for VRManager #include "mozilla/ipc/Transport.h" // for Transport #include "mozilla/gfx/gfxVars.h" #include "mozilla/gfx/GPUParent.h" diff --git a/gfx/layers/ipc/CompositorVsyncScheduler.cpp b/gfx/layers/ipc/CompositorVsyncScheduler.cpp index 525d27e32c34..c1050b271ebc 100644 --- a/gfx/layers/ipc/CompositorVsyncScheduler.cpp +++ b/gfx/layers/ipc/CompositorVsyncScheduler.cpp @@ -133,37 +133,18 @@ CompositorVsyncScheduler::PostCompositeTask(TimeStamp aCompositeTimestamp) mCurrentCompositeTask = task; ScheduleTask(task.forget(), 0); } - if (mCurrentVRListenerTask == nullptr && VRListenerThreadHolder::IsActive()) { - const TimeDuration timeout = TimeDuration::FromSeconds(45); - VRManager* vm = VRManager::Get(); - TimeStamp activeTime(vm->GetLastVRListenerThreadActiveTime()); - - // Shutdown VR listener thread when no VR content in 45 sec. Shutdown threads - // only allows to be run at the main thread. - if (!activeTime.IsNull() && ((aCompositeTimestamp - activeTime) > timeout)) { - RefPtr runnable = NewRunnableMethod( - "layers::CompositorVsyncScheduler::ShutdownVRListenerThread", - this, &CompositorVsyncScheduler::ShutdownVRListenerThread); - NS_DispatchToMainThread(runnable.forget()); - } else { - RefPtr task = NewCancelableRunnableMethod( - "layers::CompositorVsyncScheduler::DispatchVREvents", - this, - &CompositorVsyncScheduler::DispatchVREvents, - aCompositeTimestamp); - mCurrentVRListenerTask = task; - MOZ_ASSERT(VRListenerThreadHolder::Loop()); - VRListenerThreadHolder::Loop()->PostTask(Move(task.forget())); - } + if (mCurrentVRListenerTask == nullptr && VRListenerThreadHolder::Loop()) { + RefPtr task = NewCancelableRunnableMethod( + "layers::CompositorVsyncScheduler::DispatchVREvents", + this, + &CompositorVsyncScheduler::DispatchVREvents, + aCompositeTimestamp); + mCurrentVRListenerTask = task; + MOZ_ASSERT(VRListenerThreadHolder::Loop()); + VRListenerThreadHolder::Loop()->PostDelayedTask(Move(task.forget()), 0); } } -void -CompositorVsyncScheduler::ShutdownVRListenerThread() -{ - VRListenerThreadHolder::Shutdown(); -} - void CompositorVsyncScheduler::ScheduleComposition() { diff --git a/gfx/layers/ipc/CompositorVsyncScheduler.h b/gfx/layers/ipc/CompositorVsyncScheduler.h index 84c29d52ff50..4c3e4ca02fe9 100644 --- a/gfx/layers/ipc/CompositorVsyncScheduler.h +++ b/gfx/layers/ipc/CompositorVsyncScheduler.h @@ -83,7 +83,6 @@ private: void DispatchTouchEvents(TimeStamp aVsyncTimestamp); void DispatchVREvents(TimeStamp aVsyncTimestamp); void CancelCurrentSetNeedsCompositeTask(); - void ShutdownVRListenerThread(); class Observer final : public VsyncObserver { diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index 760e1cda6dbb..8c4b4de6cb91 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -1044,6 +1044,7 @@ gfxPlatform::InitLayersIPC() } layers::CompositorThreadHolder::Start(); + gfx::VRListenerThreadHolder::Start(); } } diff --git a/gfx/vr/VRDisplayHost.cpp b/gfx/vr/VRDisplayHost.cpp index 64c3eab1fe0d..2a1e7708c177 100644 --- a/gfx/vr/VRDisplayHost.cpp +++ b/gfx/vr/VRDisplayHost.cpp @@ -10,7 +10,6 @@ #include "ipc/VRLayerParent.h" #include "mozilla/layers/TextureHost.h" #include "mozilla/dom/GamepadBinding.h" // For GamepadMappingType -#include "mozilla/layers/CompositorThread.h" #include "VRThread.h" #if defined(XP_WIN) @@ -261,7 +260,6 @@ VRDisplayHost::SubmitFrame(VRLayerParent* aLayer, { AUTO_PROFILER_TRACING("VR", "SubmitFrameAtVRDisplayHost"); - MOZ_ASSERT(NS_IsInCompositorThread()); if ((mDisplayInfo.mGroupMask & aLayer->GetGroup()) == 0) { // Suppress layers hidden by the group mask return; diff --git a/gfx/vr/VRManager.cpp b/gfx/vr/VRManager.cpp index 315ddef06d1d..d09d61c1f5c9 100644 --- a/gfx/vr/VRManager.cpp +++ b/gfx/vr/VRManager.cpp @@ -227,7 +227,6 @@ VRManager::NotifyVsync(const TimeStamp& aVsyncTimestamp) if (bHaveEventListener || bHaveControllerListener) { // We are using a VR device, keep it alive mLastActiveTime = TimeStamp::Now(); - mLastVRListenerThreadActiveTime = mLastActiveTime; } else if (mLastActiveTime.IsNull()) { Shutdown(); } else { @@ -260,7 +259,7 @@ void VRManager::RefreshVRDisplays(bool aMustDispatch) { nsTArray > displays; - mLastVRListenerThreadActiveTime = TimeStamp::Now(); + /** We don't wish to enumerate the same display from multiple managers, * so stop as soon as we get a display. * It is still possible to get multiple displays from a single manager, @@ -309,20 +308,13 @@ VRManager::RefreshVRDisplays(bool aMustDispatch) } if (displayInfoChanged || displaySetChanged || aMustDispatch) { - // Due to PVRManager is at Compositor thread. We have to post tasks - // to Compositor thread when sending to them the content processes. - MessageLoop* loop = CompositorThreadHolder::Loop(); - loop->PostTask( - NewRunnableMethod("gfx::VRManager::DispatchVRDisplayInfoUpdate", - this, - &VRManager::DispatchVRDisplayInfoUpdate)); + DispatchVRDisplayInfoUpdate(); } } void VRManager::DispatchVRDisplayInfoUpdate() { - MOZ_ASSERT(NS_IsInCompositorThread()); nsTArray update; GetVRDisplayInfo(update); @@ -331,6 +323,7 @@ VRManager::DispatchVRDisplayInfoUpdate() } } + /** * Get any VR displays that have already been enumerated without * activating any new devices. @@ -375,12 +368,6 @@ VRManager::GetVRControllerInfo(nsTArray& aControllerInfo) } } -TimeStamp -VRManager::GetLastVRListenerThreadActiveTime() -{ - return mLastVRListenerThreadActiveTime; -} - void VRManager::RefreshVRControllers() { @@ -455,22 +442,8 @@ VRManager::NotifyGamepadChange(uint32_t aIndex, const T& aInfo) dom::GamepadChangeEventBody body(aInfo); dom::GamepadChangeEvent e(aIndex, dom::GamepadServiceType::VR, body); - // Due to PVRManager is at Compositor thread. We have to post - // tasks to Compositor thread. - MessageLoop* loop = CompositorThreadHolder::Loop(); - loop->PostTask( - NewRunnableMethod( - "gfx::VRManager::NotifyGamepadChangeEventsToContent", - this, - &VRManager::NotifyGamepadChangeEventsToContent, e)); -} - -void -VRManager::NotifyGamepadChangeEventsToContent(const dom::GamepadChangeEvent& aEvent) -{ - MOZ_ASSERT(NS_IsInCompositorThread()); for (auto iter = mVRManagerParents.Iter(); !iter.Done(); iter.Next()) { - Unused << iter.Get()->GetKey()->SendGamepadUpdate(aEvent); + Unused << iter.Get()->GetKey()->SendGamepadUpdate(e); } } @@ -496,20 +469,6 @@ VRManager::StopVibrateHaptic(uint32_t aControllerIdx) void VRManager::NotifyVibrateHapticCompleted(uint32_t aPromiseID) { - // Due to PVRManager is at Compositor thread. We have to post - // tasks to Compositor thread. - MessageLoop* loop = CompositorThreadHolder::Loop(); - loop->PostTask( - NewRunnableMethod( - "gfx::VRManager::NotifyVibrateHapticCompletedToContent", - this, - &VRManager::NotifyVibrateHapticCompletedToContent, aPromiseID)); -} - -void -VRManager::NotifyVibrateHapticCompletedToContent(uint32_t aPromiseID) -{ - MOZ_ASSERT(NS_IsInCompositorThread()); for (auto iter = mVRManagerParents.Iter(); !iter.Done(); iter.Next()) { Unused << iter.Get()->GetKey()->SendReplyGamepadVibrateHaptic(aPromiseID); } @@ -518,7 +477,6 @@ VRManager::NotifyVibrateHapticCompletedToContent(uint32_t aPromiseID) void VRManager::DispatchSubmitFrameResult(uint32_t aDisplayID, const VRSubmitFrameResultInfo& aResult) { - MOZ_ASSERT(NS_IsInCompositorThread()); for (auto iter = mVRManagerParents.Iter(); !iter.Done(); iter.Next()) { Unused << iter.Get()->GetKey()->SendDispatchSubmitFrameResult(aDisplayID, aResult); } diff --git a/gfx/vr/VRManager.h b/gfx/vr/VRManager.h index b10fb9fd906d..7c79922ed442 100644 --- a/gfx/vr/VRManager.h +++ b/gfx/vr/VRManager.h @@ -15,8 +15,8 @@ #include "gfxVR.h" namespace mozilla { -namespace dom { -class GamepadChangeEvent; +namespace layers { +class TextureHost; } namespace gfx { @@ -52,7 +52,6 @@ public: void StopVibrateHaptic(uint32_t aControllerIdx); void NotifyVibrateHapticCompleted(uint32_t aPromiseID); void DispatchSubmitFrameResult(uint32_t aDisplayID, const VRSubmitFrameResultInfo& aResult); - TimeStamp GetLastVRListenerThreadActiveTime(); protected: VRManager(); @@ -65,8 +64,6 @@ private: void Shutdown(); void DispatchVRDisplayInfoUpdate(); - void NotifyGamepadChangeEventsToContent(const dom::GamepadChangeEvent& aEvent); - void NotifyVibrateHapticCompletedToContent(uint32_t aPromiseID); typedef nsTHashtable> VRManagerParentSet; VRManagerParentSet mVRManagerParents; @@ -84,7 +81,6 @@ private: TimeStamp mLastRefreshTime; TimeStamp mLastActiveTime; - TimeStamp mLastVRListenerThreadActiveTime; bool mVRTestSystemCreated; }; diff --git a/gfx/vr/VRThread.cpp b/gfx/vr/VRThread.cpp index 640970349206..3558eb08250b 100644 --- a/gfx/vr/VRThread.cpp +++ b/gfx/vr/VRThread.cpp @@ -13,7 +13,6 @@ namespace mozilla { namespace gfx { static StaticRefPtr sVRListenerThreadHolder; -static TimeStamp sStartTime; static bool sFinishedVRListenerShutDown = false; VRListenerThreadHolder* GetVRListenerThreadHolder() @@ -95,22 +94,11 @@ VRListenerThreadHolder::Start() MOZ_ASSERT(!sVRListenerThreadHolder, "The VR listener thread has already been started!"); sVRListenerThreadHolder = new VRListenerThreadHolder(); - sStartTime = TimeStamp::Now(); -} - -TimeStamp -VRListenerThreadHolder::GetStartTime() -{ - return sStartTime; } void VRListenerThreadHolder::Shutdown() { - if (!IsActive()) { - return; - } - MOZ_ASSERT(NS_IsMainThread(), "Should be on the main thread!"); MOZ_ASSERT(sVRListenerThreadHolder, "The VR listener thread has already been shut down!"); @@ -123,7 +111,7 @@ VRListenerThreadHolder::Shutdown() VRListenerThreadHolder::IsInVRListenerThread() { return VRListenerThread() && - VRListenerThread()->thread_id() == PlatformThread::CurrentId(); + VRListenerThread()->thread_id() == PlatformThread::CurrentId(); } } // namespace gfx diff --git a/gfx/vr/VRThread.h b/gfx/vr/VRThread.h index f83610aed146..7b973f6cc7c3 100644 --- a/gfx/vr/VRThread.h +++ b/gfx/vr/VRThread.h @@ -27,22 +27,21 @@ public: static VRListenerThreadHolder* GetSingleton(); static bool IsActive() { - return !!GetSingleton() && !!Loop(); + return !!GetSingleton(); } static void Start(); static void Shutdown(); static MessageLoop* Loop(); static bool IsInVRListenerThread(); - static TimeStamp GetStartTime(); private: ~VRListenerThreadHolder(); + base::Thread* const mThread; + static base::Thread* CreateThread(); static void DestroyThread(base::Thread* aThread); - - base::Thread* const mThread; }; base::Thread* VRListenerThread(); diff --git a/gfx/vr/gfxVROculus.cpp b/gfx/vr/gfxVROculus.cpp index 8afbdf10cdaa..c9cdfb6563a3 100644 --- a/gfx/vr/gfxVROculus.cpp +++ b/gfx/vr/gfxVROculus.cpp @@ -364,10 +364,9 @@ VROculusSession::Refresh(bool aForceRefresh) "gfx::VROculusSession::Refresh", this, &VROculusSession::Refresh, true)); + return; } - // Calling ovr_SubmitFrame() must be at Compositor thread. - MOZ_ASSERT(NS_IsInCompositorThread()); ovrLayerEyeFov layer; memset(&layer, 0, sizeof(layer)); layer.Header.Type = ovrLayerType_Disabled; diff --git a/gfx/vr/gfxVROculus.h b/gfx/vr/gfxVROculus.h index 8e3f0812a721..4cb17d19e75d 100644 --- a/gfx/vr/gfxVROculus.h +++ b/gfx/vr/gfxVROculus.h @@ -37,7 +37,7 @@ enum class OculusControllerAxisType : uint16_t { class VROculusSession { - NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VROculusSession); + NS_INLINE_DECL_REFCOUNTING(VROculusSession); friend class VRDisplayOculus; public: VROculusSession(); diff --git a/gfx/vr/gfxVROpenVR.cpp b/gfx/vr/gfxVROpenVR.cpp index 017493a5aead..c7a43df1050b 100644 --- a/gfx/vr/gfxVROpenVR.cpp +++ b/gfx/vr/gfxVROpenVR.cpp @@ -636,13 +636,6 @@ VRSystemManagerOpenVR::Shutdown() bool VRSystemManagerOpenVR::GetHMDs(nsTArray>& aHMDResult) { - // When running VR tests on local machines which have SteamVR runtime. - // VR_IsHmdPresent() would have chance to be true. Then, it makes us can't - // get the VRPuppet display. - if (gfxPrefs::VRPuppetEnabled()) { - return false; - } - if (!::vr::VR_IsHmdPresent() || (mOpenVRHMD && !mOpenVRHMD->GetIsHmdPresent())) { // OpenVR runtime could be quit accidentally, diff --git a/gfx/vr/gfxVRPuppet.cpp b/gfx/vr/gfxVRPuppet.cpp index 959a09868f22..19f040da1095 100644 --- a/gfx/vr/gfxVRPuppet.cpp +++ b/gfx/vr/gfxVRPuppet.cpp @@ -14,11 +14,11 @@ #include "mozilla/Base64.h" #include "mozilla/gfx/DataSurfaceHelpers.h" -#include "mozilla/layers/CompositorThread.h" #include "gfxPrefs.h" #include "gfxUtils.h" #include "gfxVRPuppet.h" #include "VRManager.h" +#include "VRThread.h" #include "mozilla/dom/GamepadEventTypes.h" #include "mozilla/dom/GamepadBinding.h" @@ -387,7 +387,11 @@ VRDisplayPuppet::SubmitFrame(ID3D11Texture2D* aSource, mContext->Unmap(mappedTexture, 0); // Dispatch the base64 encoded string to the DOM side. Then, it will be decoded // and convert to a PNG image there. - vm->DispatchSubmitFrameResult(mDisplayInfo.mDisplayID, result); + MessageLoop* loop = VRListenerThreadHolder::Loop(); + loop->PostTask(NewRunnableMethod( + "VRManager::DispatchSubmitFrameResult", + vm, &VRManager::DispatchSubmitFrameResult, mDisplayInfo.mDisplayID, result + )); break; } case 2: @@ -528,7 +532,11 @@ VRDisplayPuppet::SubmitFrame(MacIOSurface* aMacIOSurface, } // Dispatch the base64 encoded string to the DOM side. Then, it will be decoded // and convert to a PNG image there. - vm->DispatchSubmitFrameResult(mDisplayInfo.mDisplayID, result); + MessageLoop* loop = VRListenerThreadHolder::Loop(); + loop->PostTask(NewRunnableMethod( + "VRManager::DispatchSubmitFrameResult", + vm, &VRManager::DispatchSubmitFrameResult, mDisplayInfo.mDisplayID, result + )); } break; } diff --git a/gfx/vr/ipc/VRLayerParent.cpp b/gfx/vr/ipc/VRLayerParent.cpp index f8935536d89b..4f04e574dc31 100644 --- a/gfx/vr/ipc/VRLayerParent.cpp +++ b/gfx/vr/ipc/VRLayerParent.cpp @@ -8,6 +8,7 @@ #include "VRLayerParent.h" #include "mozilla/Unused.h" #include "VRDisplayHost.h" +#include "mozilla/layers/CompositorThread.h" namespace mozilla { using namespace layers; @@ -64,11 +65,18 @@ VRLayerParent::RecvSubmitFrame(const layers::SurfaceDescriptor &aTexture, const gfx::Rect& aRightEyeRect) { if (mVRDisplayID) { + MessageLoop* loop = layers::CompositorThreadHolder::Loop(); VRManager* vm = VRManager::Get(); RefPtr display = vm->GetDisplay(mVRDisplayID); if (display) { - // TODO: Move SubmitFrame to VRSubmitFrame thread in Bug 1392217. - SubmitFrame(display, aTexture, aFrameId, aLeftEyeRect, aRightEyeRect); + // Because VR compositor still shares the same graphics device with Compositor thread. + // We have to post sumbit frame tasks to Compositor thread. + // TODO: Move SubmitFrame to Bug 1392217. + loop->PostTask(NewRunnableMethod( + "gfx::VRLayerParent::SubmitFrame", + this, + &VRLayerParent::SubmitFrame, display, aTexture, aFrameId, aLeftEyeRect, aRightEyeRect)); } } diff --git a/gfx/vr/ipc/VRManagerChild.cpp b/gfx/vr/ipc/VRManagerChild.cpp index ce262f4185fa..03dc89771c0e 100644 --- a/gfx/vr/ipc/VRManagerChild.cpp +++ b/gfx/vr/ipc/VRManagerChild.cpp @@ -118,7 +118,7 @@ VRManagerChild::InitSameProcess() sVRManagerChildSingleton = new VRManagerChild(); sVRManagerParentSingleton = VRManagerParent::CreateSameProcess(); sVRManagerChildSingleton->Open(sVRManagerParentSingleton->GetIPCChannel(), - mozilla::layers::CompositorThreadHolder::Loop(), + VRListenerThreadHolder::Loop(), mozilla::ipc::ChildSide); } diff --git a/gfx/vr/ipc/VRManagerParent.cpp b/gfx/vr/ipc/VRManagerParent.cpp index 38ac984cdb8c..0c5da625d7b7 100644 --- a/gfx/vr/ipc/VRManagerParent.cpp +++ b/gfx/vr/ipc/VRManagerParent.cpp @@ -86,13 +86,15 @@ VRManagerParent::UnregisterFromManager() /* static */ bool VRManagerParent::CreateForContent(Endpoint&& aEndpoint) { - MessageLoop* loop = CompositorThreadHolder::Loop(); + MessageLoop* loop = VRListenerThreadHolder::Loop(); + RefPtr vmp = new VRManagerParent(aEndpoint.OtherPid(), true); loop->PostTask(NewRunnableMethod&&>( "gfx::VRManagerParent::Bind", vmp, &VRManagerParent::Bind, Move(aEndpoint))); + return true; } @@ -108,7 +110,7 @@ VRManagerParent::Bind(Endpoint&& aEndpoint) } /*static*/ void -VRManagerParent::RegisterVRManagerInCompositorThread(VRManagerParent* aVRManager) +VRManagerParent::RegisterVRManagerInVRListenerThread(VRManagerParent* aVRManager) { aVRManager->RegisterWithManager(); } @@ -116,21 +118,21 @@ VRManagerParent::RegisterVRManagerInCompositorThread(VRManagerParent* aVRManager /*static*/ VRManagerParent* VRManagerParent::CreateSameProcess() { - MessageLoop* loop = CompositorThreadHolder::Loop(); + MessageLoop* loop = VRListenerThreadHolder::Loop(); RefPtr vmp = new VRManagerParent(base::GetCurrentProcId(), false); - vmp->mCompositorThreadHolder = CompositorThreadHolder::GetSingleton(); + vmp->mVRListenerThreadHolder = VRListenerThreadHolder::GetSingleton(); vmp->mSelfRef = vmp; - loop->PostTask(NewRunnableFunction(RegisterVRManagerInCompositorThread, vmp.get())); + loop->PostTask(NewRunnableFunction(RegisterVRManagerInVRListenerThread, vmp.get())); return vmp.get(); } bool VRManagerParent::CreateForGPUProcess(Endpoint&& aEndpoint) { - MessageLoop* loop = CompositorThreadHolder::Loop(); + MessageLoop* loop = VRListenerThreadHolder::Loop(); RefPtr vmp = new VRManagerParent(aEndpoint.OtherPid(), false); - vmp->mCompositorThreadHolder = CompositorThreadHolder::GetSingleton(); + vmp->mVRListenerThreadHolder = VRListenerThreadHolder::GetSingleton(); loop->PostTask(NewRunnableMethod&&>( "gfx::VRManagerParent::Bind", vmp, @@ -142,25 +144,10 @@ VRManagerParent::CreateForGPUProcess(Endpoint&& aEndpoint) void VRManagerParent::DeferredDestroy() { - mCompositorThreadHolder = nullptr; + mVRListenerThreadHolder = nullptr; mSelfRef = nullptr; } -void -VRManagerParent::RefreshDisplays() -{ - // This is called to refresh the VR Displays for Navigator.GetVRDevices(). - // We must pass "true" to VRManager::RefreshVRDisplays() - // to ensure that the promise returned by Navigator.GetVRDevices - // can resolve even if there are no changes to the VR Displays. - VRManager* vm = VRManager::Get(); - MessageLoop* loop = VRListenerThreadHolder::Loop(); - loop->PostTask( - NewRunnableMethod( - "gfx::VRManager::RefreshVRDisplays", - vm, &VRManager::RefreshVRDisplays, true)); -} - void VRManagerParent::ActorDestroy(ActorDestroyReason why) { @@ -174,25 +161,21 @@ VRManagerParent::ActorDestroy(ActorDestroyReason why) void VRManagerParent::OnChannelConnected(int32_t aPid) { - mCompositorThreadHolder = CompositorThreadHolder::GetSingleton(); + mVRListenerThreadHolder = VRListenerThreadHolder::GetSingleton(); } mozilla::ipc::IPCResult VRManagerParent::RecvRefreshDisplays() { - MOZ_ASSERT(NS_IsInCompositorThread()); + // TODO: Bug 1406327, Launch VR listener thread here. + MOZ_ASSERT(VRListenerThreadHolder::IsInVRListenerThread()); - // When receiving refresh display messages at the first time, - // it is time to start the VR listener thread. - // Spawning threads needs to be at the main thread. - if (!VRListenerThreadHolder::IsActive()) { - RefPtr runnable = NewRunnableMethod( - "gfx::VRManagerParent::StartVRListenerThread", - this, &VRManagerParent::StartVRListenerThread); - NS_DispatchToMainThread(runnable.forget()); - } else { - RefreshDisplays(); - } + // This is called to refresh the VR Displays for Navigator.GetVRDevices(). + // We must pass "true" to VRManager::RefreshVRDisplays() + // to ensure that the promise returned by Navigator.GetVRDevices + // can resolve even if there are no changes to the VR Displays. + VRManager* vm = VRManager::Get(); + vm->RefreshVRDisplays(true); return IPC_OK(); } @@ -220,13 +203,6 @@ VRManagerParent::RecvSetGroupMask(const uint32_t& aDisplayID, const uint32_t& aG return IPC_OK(); } -void -VRManagerParent::StartVRListenerThread() -{ - VRListenerThreadHolder::Start(); - RefreshDisplays(); -} - bool VRManagerParent::HaveEventListener() { diff --git a/gfx/vr/ipc/VRManagerParent.h b/gfx/vr/ipc/VRManagerParent.h index 9a405051a23c..9129a3bbbef0 100644 --- a/gfx/vr/ipc/VRManagerParent.h +++ b/gfx/vr/ipc/VRManagerParent.h @@ -7,7 +7,7 @@ #ifndef MOZILLA_GFX_VR_VRMANAGERPARENT_H #define MOZILLA_GFX_VR_VRMANAGERPARENT_H -#include "mozilla/layers/CompositorThread.h" // for CompositorThreadHolder +#include "mozilla/layers/CompositableTransactionParent.h" // need? #include "mozilla/gfx/PVRManagerParent.h" // for PVRManagerParent #include "mozilla/gfx/PVRLayerParent.h" // for PVRLayerParent #include "mozilla/ipc/ProtocolUtils.h" // for IToplevelProtocol @@ -16,6 +16,7 @@ #include "VRThread.h" // for VRListenerThreadHolder namespace mozilla { +using namespace layers; namespace gfx { class VRManager; @@ -40,7 +41,6 @@ public: bool HaveControllerListener(); bool SendGamepadUpdate(const GamepadChangeEvent& aGamepadEvent); bool SendReplyGamepadVibrateHaptic(const uint32_t& aPromiseID); - void StartVRListenerThread(); protected: ~VRManagerParent(); @@ -80,17 +80,14 @@ private: void Bind(Endpoint&& aEndpoint); - static void RegisterVRManagerInCompositorThread(VRManagerParent* aVRManager); + static void RegisterVRManagerInVRListenerThread(VRManagerParent* aVRManager); void DeferredDestroy(); - void RefreshDisplays(); // This keeps us alive until ActorDestroy(), at which point we do a // deferred destruction of ourselves. RefPtr mSelfRef; - - // Keep the compositor thread alive, until we have destroyed ourselves. - RefPtr mCompositorThreadHolder; + RefPtr mVRListenerThreadHolder; // Keep the VRManager alive, until we have destroyed ourselves. RefPtr mVRManagerHolder;