Bug 1501869 - Part 2: Stop calling VR tasks when they are at background. r=kip

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Daosheng Mu 2018-10-28 22:49:15 +00:00
Родитель 4db1e662d5
Коммит 09b5ef8f66
11 изменённых файлов: 105 добавлений и 1 удалений

Просмотреть файл

@ -4446,6 +4446,22 @@ nsGlobalWindowInner::ResetVRTelemetry(bool aUpdate)
}
}
void
nsGlobalWindowInner::StartVRActivity()
{
if (mVREventObserver) {
mVREventObserver->StartActivity();
}
}
void
nsGlobalWindowInner::StopVRActivity()
{
if (mVREventObserver) {
mVREventObserver->StopActivity();
}
}
#ifndef XP_WIN // This guard should match the guard at the callsite.
static bool ShouldShowFocusRingIfFocusedByMouse(nsIContent* aNode)
{

Просмотреть файл

@ -559,6 +559,9 @@ public:
// false for only resetting the timestamp.
void ResetVRTelemetry(bool aUpdate);
void StartVRActivity();
void StopVRActivity();
// Update the VR displays for this window
bool UpdateVRDisplays(nsTArray<RefPtr<mozilla::dom::VRDisplay>>& aDisplays);

Просмотреть файл

@ -6641,6 +6641,7 @@ nsGlobalWindowOuter::SetIsBackground(bool aIsBackground)
// the background window.
if (inner && changed) {
inner->StopGamepadHaptics();
inner->StopVRActivity();
// true is for asking to set the delta time to
// the telemetry.
inner->ResetVRTelemetry(true);
@ -6653,6 +6654,7 @@ nsGlobalWindowOuter::SetIsBackground(bool aIsBackground)
// false is for only resetting the timestamp.
inner->ResetVRTelemetry(false);
inner->SyncGamepadState();
inner->StartVRActivity();
}
}

Просмотреть файл

@ -26,6 +26,7 @@ VREventObserver::VREventObserver(nsGlobalWindowInner* aGlobalWindow)
: mWindow(aGlobalWindow)
, mIs2DView(true)
, mHasReset(false)
, mStopActivity(false)
{
MOZ_ASSERT(aGlobalWindow);
@ -55,6 +56,7 @@ VREventObserver::DisconnectFromOwner()
VRManagerChild* vmc = VRManagerChild::Get();
vmc->RemoveListener(this);
}
mStopActivity = true;
}
void
@ -77,6 +79,28 @@ VREventObserver::UpdateSpentTimeIn2DTelemetry(bool aUpdate)
}
}
void
VREventObserver::StartActivity()
{
mStopActivity = false;
VRManagerChild* vmc = VRManagerChild::Get();
vmc->StartActivity();
}
void
VREventObserver::StopActivity()
{
mStopActivity = true;
VRManagerChild* vmc = VRManagerChild::Get();
vmc->StopActivity();
}
bool
VREventObserver::GetStopActivityStatus()
{
return mStopActivity;
}
void
VREventObserver::NotifyAfterLoad()
{

Просмотреть файл

@ -33,6 +33,9 @@ public:
void DisconnectFromOwner();
void UpdateSpentTimeIn2DTelemetry(bool aUpdate);
void StartActivity();
void StopActivity();
bool GetStopActivityStatus();
private:
~VREventObserver();
@ -43,6 +46,7 @@ private:
TimeStamp mSpendTimeIn2DView;
bool mIs2DView;
bool mHasReset;
bool mStopActivity;
};
} // namespace dom

Просмотреть файл

@ -33,7 +33,6 @@ class VRSystemManagerExternal;
class VRManager
{
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(mozilla::gfx::VRManager)
friend class VRManagerParent;
public:
static void ManagerInit();

Просмотреть файл

@ -67,6 +67,8 @@ parent:
async NewPoseMoveToMockController(uint32_t aDeviceID, GamepadPoseState aPose);
async StartVRNavigation(uint32_t aDeviceID);
async StopVRNavigation(uint32_t aDeviceID, TimeDuration aDuration);
async StartActivity();
async StopActivity();
child:
// Notify children of updated VR display enumeration and details. This will

Просмотреть файл

@ -618,6 +618,25 @@ VRManagerChild::RemoveListener(dom::VREventObserver* aObserver)
}
}
void
VRManagerChild::StartActivity()
{
Unused << SendStartActivity();
}
void
VRManagerChild::StopActivity()
{
for (auto& listener : mListeners) {
if (!listener->GetStopActivityStatus()) {
// We are still showing VR in the active window.
return;
}
}
Unused << SendStopActivity();
}
void
VRManagerChild::HandleFatalError(const char* aMsg) const
{

Просмотреть файл

@ -42,6 +42,8 @@ public:
void AddListener(dom::VREventObserver* aObserver);
// Indicate that an observer should no longer receive VR events.
void RemoveListener(dom::VREventObserver* aObserver);
void StartActivity();
void StopActivity();
bool GetVRDisplays(nsTArray<RefPtr<VRDisplayClient> >& aDisplays);
bool RefreshVRDisplaysWithCallback(uint64_t aWindowId);

Просмотреть файл

@ -24,6 +24,7 @@ VRManagerParent::VRManagerParent(ProcessId aChildProcessId, bool aIsContentChild
, mHaveEventListener(false)
, mHaveControllerListener(false)
, mIsContentChild(aIsContentChild)
, mVRActiveStatus(true)
{
MOZ_COUNT_CTOR(VRManagerParent);
MOZ_ASSERT(NS_IsMainThread());
@ -204,6 +205,10 @@ VRManagerParent::RecvSetGroupMask(const uint32_t& aDisplayID, const uint32_t& aG
bool
VRManagerParent::HaveEventListener()
{
if (!mVRActiveStatus) {
return false;
}
return mHaveEventListener;
}
@ -213,6 +218,12 @@ VRManagerParent::HaveControllerListener()
return mHaveControllerListener;
}
bool
VRManagerParent::GetVRActiveStatus()
{
return mVRActiveStatus;
}
mozilla::ipc::IPCResult
VRManagerParent::RecvSetHaveEventListener(const bool& aHaveEventListener)
{
@ -469,5 +480,19 @@ VRManagerParent::RecvStopVRNavigation(const uint32_t& aDeviceID, const TimeDurat
return IPC_OK();
}
mozilla::ipc::IPCResult
VRManagerParent::RecvStartActivity()
{
mVRActiveStatus = true;
return IPC_OK();
}
mozilla::ipc::IPCResult
VRManagerParent::RecvStopActivity()
{
mVRActiveStatus = false;
return IPC_OK();
}
} // namespace gfx
} // namespace mozilla

Просмотреть файл

@ -39,6 +39,7 @@ public:
bool IsSameProcess() const;
bool HaveEventListener();
bool HaveControllerListener();
bool GetVRActiveStatus();
bool SendGamepadUpdate(const GamepadChangeEvent& aGamepadEvent);
bool SendReplyGamepadVibrateHaptic(const uint32_t& aPromiseID);
@ -75,6 +76,9 @@ protected:
virtual mozilla::ipc::IPCResult RecvNewPoseMoveToMockController(const uint32_t& aDeviceID, const GamepadPoseState& pose) override;
virtual mozilla::ipc::IPCResult RecvStartVRNavigation(const uint32_t& aDeviceID) override;
virtual mozilla::ipc::IPCResult RecvStopVRNavigation(const uint32_t& aDeviceID, const TimeDuration& aTimeout) override;
virtual mozilla::ipc::IPCResult RecvStartActivity() override;
virtual mozilla::ipc::IPCResult RecvStopActivity() override;
private:
void RegisterWithManager();
void UnregisterFromManager();
@ -99,6 +103,10 @@ private:
bool mHaveEventListener;
bool mHaveControllerListener;
bool mIsContentChild;
// When VR tabs are switched the background, we won't need to
// initialize its session in VRService thread.
bool mVRActiveStatus;
};
class VRManagerPromise final