Bug 1502527 - Keeping VR managers alive even though no focused VR windows. r=kip
authorDaosheng Mu <daoshengmu@gmail.com>
Fri, 26 Oct 2018 23:17:52 +0000
changeset 443268 d9b93ea9b5c442c401c50a779af2f3ab7382ffb8
parent 443267 dfb96d3d4e0a573056334c2f8dc0bb5243f49efb
child 443269 eb4b57c7a3e2c6cca1a124aca117da4eddd2351b
push id34950
push usercsabou@mozilla.com
push dateMon, 29 Oct 2018 04:16:25 +0000
treeherdermozilla-central@d2e24bdf0648 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskip
bugs1502527
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1502527 - Keeping VR managers alive even though no focused VR windows. r=kip Differential Revision: https://phabricator.services.mozilla.com/D9964
gfx/vr/VRManager.cpp
gfx/vr/VRManager.h
gfx/vr/ipc/VRManagerParent.cpp
--- a/gfx/vr/VRManager.cpp
+++ b/gfx/vr/VRManager.cpp
@@ -65,16 +65,17 @@ VRManager::ManagerInit()
     ClearOnShutdown(&sVRManagerSingleton);
   }
 }
 
 VRManager::VRManager()
   : mInitialized(false)
   , mAccumulator100ms(0.0f)
   , mVRDisplaysRequested(false)
+  , mVRDisplaysRequestedNonFocus(false)
   , mVRControllersRequested(false)
   , mVRServiceStarted(false)
   , mTaskInterval(0)
 {
   MOZ_COUNT_CTOR(VRManager);
   MOZ_ASSERT(sVRManagerSingleton == nullptr);
 
   RefPtr<VRSystemManager> mgr;
@@ -194,25 +195,28 @@ VRManager::RemoveVRManagerParent(VRManag
     Destroy();
   }
 }
 
 void
 VRManager::UpdateRequestedDevices()
 {
   bool bHaveEventListener = false;
+  bool bHaveEventListenerNonFocus = false;
   bool bHaveControllerListener = false;
 
   for (auto iter = mVRManagerParents.Iter(); !iter.Done(); iter.Next()) {
     VRManagerParent *vmp = iter.Get()->GetKey();
-    bHaveEventListener |= vmp->HaveEventListener();
+    bHaveEventListener |= vmp->HaveEventListener() && vmp->GetVRActiveStatus();
+    bHaveEventListenerNonFocus |= vmp->HaveEventListener() && !vmp->GetVRActiveStatus();
     bHaveControllerListener |= vmp->HaveControllerListener();
   }
 
   mVRDisplaysRequested = bHaveEventListener;
+  mVRDisplaysRequestedNonFocus = bHaveEventListenerNonFocus;
   // We only currently allow controllers to be used when
   // also activating a VR display
   mVRControllersRequested = mVRDisplaysRequested && bHaveControllerListener;
 }
 
 /**
  * VRManager::NotifyVsync must be called on every 2d vsync (usually at 60hz).
  * This must be called even when no WebVR site is active.
@@ -400,17 +404,18 @@ VRManager::Run100msTasks()
     display->Run100msTasks();
   }
 }
 
 void
 VRManager::CheckForInactiveTimeout()
 {
   // Shut down the VR devices when not in use
-  if (mVRDisplaysRequested || mVRControllersRequested) {
+  if (mVRDisplaysRequested || mVRDisplaysRequestedNonFocus ||
+      mVRControllersRequested) {
     // We are using a VR device, keep it alive
     mLastActiveTime = TimeStamp::Now();
   }
   else if (mLastActiveTime.IsNull()) {
     Shutdown();
   }
   else {
     TimeDuration duration = TimeStamp::Now() - mLastActiveTime;
--- a/gfx/vr/VRManager.h
+++ b/gfx/vr/VRManager.h
@@ -107,16 +107,17 @@ private:
   TimeStamp mLastTickTime;
   double mAccumulator100ms;
   RefPtr<VRSystemManagerPuppet> mPuppetManager;
   RefPtr<VRSystemManagerExternal> mExternalManager;
 #if !defined(MOZ_WIDGET_ANDROID)
   RefPtr<VRService> mVRService;
 #endif
   bool mVRDisplaysRequested;
+  bool mVRDisplaysRequestedNonFocus;
   bool mVRControllersRequested;
   bool mVRServiceStarted;
   uint32_t mTaskInterval;
   RefPtr<nsITimer> mTaskTimer;
 };
 
 } // namespace gfx
 } // namespace mozilla
--- a/gfx/vr/ipc/VRManagerParent.cpp
+++ b/gfx/vr/ipc/VRManagerParent.cpp
@@ -200,20 +200,16 @@ VRManagerParent::RecvSetGroupMask(const 
     display->SetGroupMask(aGroupMask);
   }
   return IPC_OK();
 }
 
 bool
 VRManagerParent::HaveEventListener()
 {
-  if (!mVRActiveStatus) {
-    return false;
-  }
-
   return mHaveEventListener;
 }
 
 bool
 VRManagerParent::HaveControllerListener()
 {
   return mHaveControllerListener;
 }