Bug 1406327 - Part 4: RefreshVRDisplays needs to be at VRListenerThread; r=kip

MozReview-Commit-ID: KuhPFqMhTDB

--HG--
extra : rebase_source : 53dac47c5ede72acbe2760f056ca88f8cbc0c6b9
This commit is contained in:
Daosheng Mu 2017-11-01 22:15:06 +08:00
parent 1b3cb570af
commit f10ab3c49f
5 changed files with 26 additions and 10 deletions

View File

@ -259,6 +259,23 @@ VRManager::NotifyVRVsync(const uint32_t& aDisplayID)
void
VRManager::RefreshVRDisplays(bool aMustDispatch)
{
if (VRListenerThreadHolder::IsInVRListenerThread()) {
RefreshVRDisplaysInternal(aMustDispatch);
} else {
if (VRListenerThreadHolder::IsActive()) {
MessageLoop* loop = VRListenerThreadHolder::Loop();
loop->PostTask(NewRunnableMethod<bool>(
"gfx::VRManager::RefreshVRDisplaysInternal",
this, &VRManager::RefreshVRDisplaysInternal, aMustDispatch
));
}
}
}
void
VRManager::RefreshVRDisplaysInternal(bool aMustDispatch)
{
MOZ_ASSERT(VRListenerThreadHolder::IsInVRListenerThread());
nsTArray<RefPtr<gfx::VRDisplayHost> > displays;
mLastVRListenerThreadActiveTime = TimeStamp::Now();
/** We don't wish to enumerate the same display from multiple managers,
@ -446,6 +463,14 @@ VRManager::CreateVRTestSystem()
mManagers.AppendElement(mgr);
mVRTestSystemCreated = true;
}
// Force to refresh VRPuppet display here
// because we need it to setup data early.
nsTArray<RefPtr<gfx::VRDisplayHost> > displays;
mgr->GetHMDs(displays);
for (const auto& display: displays) {
mVRDisplays.Put(display->GetDisplayInfo().GetDisplayID(), display);
}
}
template<class T>

View File

@ -65,6 +65,7 @@ private:
void Shutdown();
void DispatchVRDisplayInfoUpdate();
void RefreshVRDisplaysInternal(bool aMustDispatch);
void NotifyGamepadChangeEventsToContent(const dom::GamepadChangeEvent& aEvent);
void NotifyVibrateHapticCompletedToContent(uint32_t aPromiseID);

View File

@ -636,13 +636,6 @@ VRSystemManagerOpenVR::Shutdown()
bool
VRSystemManagerOpenVR::GetHMDs(nsTArray<RefPtr<VRDisplayHost>>& 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,

View File

@ -282,7 +282,6 @@ VRManagerParent::RecvCreateVRServiceTestDisplay(const nsCString& aID, const uint
nsTArray<VRDisplayInfo> displayInfoArray;
impl::VRDisplayPuppet* displayPuppet = nullptr;
VRManager* vm = VRManager::Get();
vm->RefreshVRDisplays();
// Get VRDisplayPuppet from VRManager
vm->GetVRDisplayInfo(displayInfoArray);

View File

@ -344,8 +344,6 @@ SpinEventLoopUntil(Pred&& aPredicate, nsIThread* aThread = nullptr)
*/
extern bool NS_IsInCompositorThread();
extern bool NS_IsInVRThread();
//-----------------------------------------------------------------------------
// Helpers that work with nsCOMPtr: