diff --git a/gfx/ipc/GPUParent.cpp b/gfx/ipc/GPUParent.cpp index afee786ee0e9..1a60cd23adbe 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 a71d6cbf4bb9..d0f47d4e9947 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 317acdf96835..6ab1abd511f1 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 2b799fb3c156..0d45a1ef3d40 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 6c87b05baa23..a1d52a4f7137 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -1042,6 +1042,7 @@ gfxPlatform::InitLayersIPC() } layers::CompositorThreadHolder::Start(); + gfx::VRListenerThreadHolder::Start(); } } diff --git a/gfx/vr/VRDisplayHost.cpp b/gfx/vr/VRDisplayHost.cpp index fb2123529b8d..205a2375a0b9 100644 --- a/gfx/vr/VRDisplayHost.cpp +++ b/gfx/vr/VRDisplayHost.cpp @@ -9,7 +9,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) @@ -258,7 +257,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 7ce6dbad2508..dfa2d9dc3d9b 100644 --- a/gfx/vr/VRManager.cpp +++ b/gfx/vr/VRManager.cpp @@ -226,7 +226,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 { @@ -259,7 +258,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, @@ -308,20 +307,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); @@ -330,6 +322,7 @@ VRManager::DispatchVRDisplayInfoUpdate() } } + /** * Get any VR displays that have already been enumerated without * activating any new devices. @@ -374,12 +367,6 @@ VRManager::GetVRControllerInfo(nsTArray& aControllerInfo) } } -TimeStamp -VRManager::GetLastVRListenerThreadActiveTime() -{ - return mLastVRListenerThreadActiveTime; -} - void VRManager::RefreshVRControllers() { @@ -454,22 +441,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); } } @@ -495,20 +468,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); } @@ -517,7 +476,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 94a82dc781be..5a467cea22ba 100644 --- a/gfx/vr/VRManager.h +++ b/gfx/vr/VRManager.h @@ -14,8 +14,8 @@ #include "gfxVR.h" namespace mozilla { -namespace dom { -class GamepadChangeEvent; +namespace layers { +class TextureHost; } namespace gfx { @@ -51,7 +51,6 @@ public: void StopVibrateHaptic(uint32_t aControllerIdx); void NotifyVibrateHapticCompleted(uint32_t aPromiseID); void DispatchSubmitFrameResult(uint32_t aDisplayID, const VRSubmitFrameResultInfo& aResult); - TimeStamp GetLastVRListenerThreadActiveTime(); protected: VRManager(); @@ -64,8 +63,6 @@ private: void Shutdown(); void DispatchVRDisplayInfoUpdate(); - void NotifyGamepadChangeEventsToContent(const dom::GamepadChangeEvent& aEvent); - void NotifyVibrateHapticCompletedToContent(uint32_t aPromiseID); typedef nsTHashtable> VRManagerParentSet; VRManagerParentSet mVRManagerParents; @@ -83,7 +80,6 @@ private: TimeStamp mLastRefreshTime; TimeStamp mLastActiveTime; - TimeStamp mLastVRListenerThreadActiveTime; bool mVRTestSystemCreated; }; diff --git a/gfx/vr/VRThread.cpp b/gfx/vr/VRThread.cpp index d7bec26ba3d7..63dad4c85d17 100644 --- a/gfx/vr/VRThread.cpp +++ b/gfx/vr/VRThread.cpp @@ -12,7 +12,6 @@ namespace mozilla { namespace gfx { static StaticRefPtr sVRListenerThreadHolder; -static TimeStamp sStartTime; static bool sFinishedVRListenerShutDown = false; VRListenerThreadHolder* GetVRListenerThreadHolder() @@ -94,22 +93,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!"); @@ -122,7 +110,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 071c3dfcb12a..9faff13f033c 100644 --- a/gfx/vr/VRThread.h +++ b/gfx/vr/VRThread.h @@ -26,22 +26,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 a6e4224c78c0..0e6e38af007f 100644 --- a/gfx/vr/gfxVROculus.cpp +++ b/gfx/vr/gfxVROculus.cpp @@ -358,10 +358,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 55bb6eb07564..39ccd55703ca 100644 --- a/gfx/vr/gfxVROculus.h +++ b/gfx/vr/gfxVROculus.h @@ -36,7 +36,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 2f1dba642491..dc03c0645e6c 100644 --- a/gfx/vr/gfxVROpenVR.cpp +++ b/gfx/vr/gfxVROpenVR.cpp @@ -610,13 +610,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 531795bc11bf..a10e6eb59f02 100644 --- a/gfx/vr/gfxVRPuppet.cpp +++ b/gfx/vr/gfxVRPuppet.cpp @@ -13,11 +13,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" @@ -378,7 +378,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: @@ -519,7 +523,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 ebec71eea506..615ac82042f7 100644 --- a/gfx/vr/ipc/VRLayerParent.cpp +++ b/gfx/vr/ipc/VRLayerParent.cpp @@ -7,6 +7,7 @@ #include "VRLayerParent.h" #include "mozilla/Unused.h" #include "VRDisplayHost.h" +#include "mozilla/layers/CompositorThread.h" namespace mozilla { using namespace layers; @@ -63,11 +64,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 97bbe59a9d06..8972a0544166 100644 --- a/gfx/vr/ipc/VRManagerChild.cpp +++ b/gfx/vr/ipc/VRManagerChild.cpp @@ -120,7 +120,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 f95d7a436cef..a8a5d51a3146 100644 --- a/gfx/vr/ipc/VRManagerParent.cpp +++ b/gfx/vr/ipc/VRManagerParent.cpp @@ -87,13 +87,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; } @@ -109,7 +111,7 @@ VRManagerParent::Bind(Endpoint&& aEndpoint) } /*static*/ void -VRManagerParent::RegisterVRManagerInCompositorThread(VRManagerParent* aVRManager) +VRManagerParent::RegisterVRManagerInVRListenerThread(VRManagerParent* aVRManager) { aVRManager->RegisterWithManager(); } @@ -117,21 +119,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, @@ -143,25 +145,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) { @@ -175,25 +162,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(); } @@ -221,13 +204,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 b30cda1fc209..5e51ae6d7f95 100644 --- a/gfx/vr/ipc/VRManagerParent.h +++ b/gfx/vr/ipc/VRManagerParent.h @@ -8,7 +8,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 @@ -17,6 +17,7 @@ #include "VRThread.h" // for VRListenerThreadHolder namespace mozilla { +using namespace layers; namespace gfx { class VRManager; @@ -41,7 +42,6 @@ public: bool HaveControllerListener(); bool SendGamepadUpdate(const GamepadChangeEvent& aGamepadEvent); bool SendReplyGamepadVibrateHaptic(const uint32_t& aPromiseID); - void StartVRListenerThread(); protected: ~VRManagerParent(); @@ -81,17 +81,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;