Bug 1498625 - Part 1: Move VRHapticThread start/end to the main thread. r=kip,froydnj

Differential Revision: https://phabricator.services.mozilla.com/D10642

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Daosheng Mu 2018-11-02 21:54:12 +00:00
parent ab89743379
commit 764c6b0bd8
2 changed files with 21 additions and 3 deletions

View File

@ -114,6 +114,12 @@ VRParent::Init(base::ProcessId aParentPid,
MessageLoop* aIOLoop,
IPC::Channel* aChannel)
{
// Initialize the thread manager before starting IPC. Otherwise, messages
// may be posted to the main thread and we won't be able to process them.
if (NS_WARN_IF(NS_FAILED(nsThreadManager::get().Init()))) {
return false;
}
// Now it's safe to start IPC.
if (NS_WARN_IF(!Open(aChannel, aParentPid, aIOLoop))) {
return false;
@ -136,6 +142,10 @@ VRParent::Init(base::ProcessId aParentPid,
#if defined(XP_WIN)
DeviceManagerDx::Init();
#endif
if (NS_FAILED(NS_InitMinimalXPCOM())) {
return false;
}
return true;
}

View File

@ -157,8 +157,10 @@ OpenVRSession::Initialize(mozilla::gfx::VRSystemState& aSystemState)
return false;
}
StartHapticThread();
StartHapticTimer();
NS_DispatchToMainThread(NS_NewRunnableFunction(
"OpenVRSession::StartHapticThread", [this]() {
StartHapticThread();
}));
// Succeeded
return true;
@ -927,17 +929,23 @@ OpenVRSession::VibrateHaptic(uint32_t aControllerIdx, uint32_t aHapticIndex,
void
OpenVRSession::StartHapticThread()
{
MOZ_ASSERT(NS_IsMainThread());
if (!mHapticThread) {
mHapticThread = new VRThread(NS_LITERAL_CSTRING("VR_OpenVR_Haptics"));
}
mHapticThread->Start();
StartHapticTimer();
}
void
OpenVRSession::StopHapticThread()
{
if (mHapticThread) {
mHapticThread->Shutdown();
NS_DispatchToMainThread(NS_NewRunnableFunction(
"mHapticThread::Shutdown",
[thread = mHapticThread]() {
thread->Shutdown();
}));
mHapticThread = nullptr;
}
}