Skip to content

Commit

Permalink
Disable vr
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedor committed Oct 6, 2023
1 parent 244b268 commit a6cc149
Show file tree
Hide file tree
Showing 56 changed files with 376 additions and 150 deletions.
2 changes: 2 additions & 0 deletions dom/base/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10199,12 +10199,14 @@ bool Document::CanSavePresentation(nsIRequest* aNewRequest,
ret = false;
}
#endif
#ifdef MOZ_VR
if (globalWindow->HasUsedVR()) {
MOZ_LOG(gPageCacheLog, mozilla::LogLevel::Verbose,
("Save of %s blocked due to having used VR", uri.get()));
aBFCacheCombo |= BFCacheStatus::HAS_USED_VR;
ret = false;
}
#endif
}

return ret;
Expand Down
4 changes: 3 additions & 1 deletion dom/base/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@
#include "mozilla/dom/KeyframeEffect.h"
#include "mozilla/dom/MouseEventBinding.h"
#include "mozilla/dom/WindowBinding.h"
#include "mozilla/dom/VRDisplay.h"
#ifdef MOZ_VR
# include "mozilla/dom/VRDisplay.h"
#endif
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/Preferences.h"
#include "nsComputedDOMStyle.h"
Expand Down
14 changes: 11 additions & 3 deletions dom/base/Navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@
#include "mozilla/dom/StorageManager.h"
#include "mozilla/dom/TCPSocket.h"
#include "mozilla/dom/URLSearchParams.h"
#include "mozilla/dom/VRDisplay.h"
#include "mozilla/dom/VRDisplayEvent.h"
#include "mozilla/dom/VRServiceTest.h"
#ifdef MOZ_VR
# include "mozilla/dom/VRDisplay.h"
# include "mozilla/dom/VRDisplayEvent.h"
# include "mozilla/dom/VRServiceTest.h"
#endif
#include "mozilla/dom/workerinternals/RuntimeService.h"
#include "mozilla/Hal.h"
#include "mozilla/ClearOnShutdown.h"
Expand Down Expand Up @@ -159,8 +161,10 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaKeySystemAccessManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPresentation)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGamepadServiceTest)
#ifdef MOZ_VR
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVRGetDisplaysPromises)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVRServiceTest)
#endif
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END

NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(Navigator)
Expand Down Expand Up @@ -216,12 +220,14 @@ void Navigator::Invalidate() {
mGamepadServiceTest = nullptr;
}

#ifdef MOZ_VR
mVRGetDisplaysPromises.Clear();

if (mVRServiceTest) {
mVRServiceTest->Shutdown();
mVRServiceTest = nullptr;
}
#endif

mMediaCapabilities = nullptr;

Expand Down Expand Up @@ -1325,6 +1331,7 @@ GamepadServiceTest* Navigator::RequestGamepadServiceTest() {
return mGamepadServiceTest;
}

#ifdef MOZ_VR
already_AddRefed<Promise> Navigator::GetVRDisplays(ErrorResult& aRv) {
if (!mWindow || !mWindow->GetDocShell() || !mWindow->GetExtantDoc()) {
aRv.Throw(NS_ERROR_UNEXPECTED);
Expand Down Expand Up @@ -1431,6 +1438,7 @@ void Navigator::RequestVRPresentation(VRDisplay& aDisplay) {
win->DispatchVRDisplayActivate(aDisplay.DisplayId(),
VRDisplayEventReason::Requested);
}
#endif // MOZ_VR

already_AddRefed<Promise> Navigator::RequestMIDIAccess(
const MIDIOptions& aOptions, ErrorResult& aRv) {
Expand Down
8 changes: 8 additions & 0 deletions dom/base/Navigator.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ class Connection;

class Presentation;
class LegacyMozTCPSocket;
#ifdef MOZ_VR
class VRDisplay;
class VRServiceTest;
#endif
class StorageManager;
class MediaCapabilities;

Expand Down Expand Up @@ -172,12 +174,14 @@ class Navigator final : public nsISupports, public nsWrapperCache {

void GetGamepads(nsTArray<RefPtr<Gamepad>>& aGamepads, ErrorResult& aRv);
GamepadServiceTest* RequestGamepadServiceTest();
#ifdef MOZ_VR
already_AddRefed<Promise> GetVRDisplays(ErrorResult& aRv);
void GetActiveVRDisplays(nsTArray<RefPtr<VRDisplay>>& aDisplays) const;
VRServiceTest* RequestVRServiceTest();
bool IsWebVRContentDetected() const;
bool IsWebVRContentPresenting() const;
void RequestVRPresentation(VRDisplay& aDisplay);
#endif
already_AddRefed<Promise> RequestMIDIAccess(const MIDIOptions& aOptions,
ErrorResult& aRv);

Expand Down Expand Up @@ -238,9 +242,11 @@ class Navigator final : public nsISupports, public nsWrapperCache {
private:
RefPtr<MediaKeySystemAccessManager> mMediaKeySystemAccessManager;

#ifdef MOZ_VR
public:
void NotifyVRDisplaysUpdated();
void NotifyActiveVRDisplaysChanged();
#endif

private:
virtual ~Navigator();
Expand Down Expand Up @@ -270,8 +276,10 @@ class Navigator final : public nsISupports, public nsWrapperCache {
nsCOMPtr<nsPIDOMWindowInner> mWindow;
RefPtr<Presentation> mPresentation;
RefPtr<GamepadServiceTest> mGamepadServiceTest;
#ifdef MOZ_VR
nsTArray<RefPtr<Promise>> mVRGetDisplaysPromises;
RefPtr<VRServiceTest> mVRServiceTest;
#endif
nsTArray<uint32_t> mRequestedVibrationPattern;
RefPtr<StorageManager> mStorageManager;
RefPtr<dom::MediaCapabilities> mMediaCapabilities;
Expand Down
38 changes: 32 additions & 6 deletions dom/base/nsGlobalWindowInner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,13 @@
#include "mozilla/dom/Gamepad.h"
#include "mozilla/dom/GamepadManager.h"

#include "gfxVR.h"
#include "mozilla/dom/VRDisplay.h"
#include "mozilla/dom/VRDisplayEvent.h"
#include "mozilla/dom/VRDisplayEventBinding.h"
#include "mozilla/dom/VREventObserver.h"
#ifdef MOZ_VR
# include "gfxVR.h"
# include "mozilla/dom/VRDisplay.h"
# include "mozilla/dom/VRDisplayEvent.h"
# include "mozilla/dom/VRDisplayEventBinding.h"
# include "mozilla/dom/VREventObserver.h"
#endif

#include "nsRefreshDriver.h"
#include "Layers.h"
Expand Down Expand Up @@ -833,9 +835,11 @@ nsGlobalWindowInner::nsGlobalWindowInner(nsGlobalWindowOuter* aOuterWindow)
mFocusByKeyOccurred(false),
mDidFireDocElemInserted(false),
mHasGamepad(false),
mHasVREvents(false),
mHintedWasLoading(false),
#ifdef MOZ_VR
mHasVREvents(false),
mHasVRDisplayActivateEvents(false),
#endif
mHasSeenGamepadInput(false),
mSuspendDepth(0),
mFreezeDepth(0),
Expand Down Expand Up @@ -1147,10 +1151,12 @@ void nsGlobalWindowInner::FreeInnerObjects() {
DisableGamepadUpdates();
mHasGamepad = false;
mGamepads.Clear();
#ifdef MOZ_VR
DisableVRUpdates();
mHasVREvents = false;
mHasVRDisplayActivateEvents = false;
mVRDisplays.Clear();
#endif

// This breaks a cycle between the window and the ClientSource object.
mClientSource.reset();
Expand Down Expand Up @@ -1345,7 +1351,9 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowInner)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGamepads)

NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCacheStorage)
#ifdef MOZ_VR
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVRDisplays)
#endif

NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDebuggerNotificationManager)

Expand Down Expand Up @@ -1447,7 +1455,9 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowInner)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGamepads)

NS_IMPL_CYCLE_COLLECTION_UNLINK(mCacheStorage)
#ifdef MOZ_VR
NS_IMPL_CYCLE_COLLECTION_UNLINK(mVRDisplays)
#endif

NS_IMPL_CYCLE_COLLECTION_UNLINK(mDebuggerNotificationManager)

Expand Down Expand Up @@ -1925,6 +1935,7 @@ nsresult nsGlobalWindowInner::PostHandleEvent(EventChainPostVisitor& aVisitor) {
// will receive a vrdisplayactive event to indicate that it should
// immediately begin vr presentation. This should occur when navigating
// forwards, navigating backwards, and on page reload.
#ifdef MOZ_VR
for (const auto& display : mVRDisplays) {
if (display->IsPresenting()) {
display->StartVRNavigation();
Expand All @@ -1942,6 +1953,7 @@ nsresult nsGlobalWindowInner::PostHandleEvent(EventChainPostVisitor& aVisitor) {
break;
}
}
#endif
// Execute bindingdetached handlers before we tear ourselves
// down.
if (mDoc) {
Expand Down Expand Up @@ -1984,6 +1996,7 @@ nsresult nsGlobalWindowInner::PostHandleEvent(EventChainPostVisitor& aVisitor) {
}
}

#ifdef MOZ_VR
if (mVREventObserver) {
mVREventObserver->NotifyAfterLoad();
}
Expand All @@ -1997,6 +2010,7 @@ nsresult nsGlobalWindowInner::PostHandleEvent(EventChainPostVisitor& aVisitor) {
DispatchVRDisplayActivate(autoActivateVRDisplayID,
VRDisplayEventReason::Navigation);
}
#endif
}

return NS_OK;
Expand Down Expand Up @@ -4013,6 +4027,7 @@ void nsGlobalWindowInner::DisableGamepadUpdates() {
}
}

#ifdef MOZ_VR
void nsGlobalWindowInner::EnableVRUpdates() {
if (mHasVREvents && !mVREventObserver) {
mVREventObserver = new VREventObserver(this);
Expand Down Expand Up @@ -4043,6 +4058,7 @@ void nsGlobalWindowInner::StopVRActivity() {
mVREventObserver->StopActivity();
}
}
#endif

#ifndef XP_WIN // This guard should match the guard at the callsite.
static bool ShouldShowFocusRingIfFocusedByMouse(nsIContent* aNode) {
Expand Down Expand Up @@ -5127,7 +5143,9 @@ void nsGlobalWindowInner::Suspend() {
ac->RemoveWindowListener(mEnabledSensors[i], this);
}
DisableGamepadUpdates();
#ifdef MOZ_VR
DisableVRUpdates();
#endif

SuspendWorkersForWindow(this);

Expand Down Expand Up @@ -5180,7 +5198,9 @@ void nsGlobalWindowInner::Resume() {
ac->AddWindowListener(mEnabledSensors[i], this);
}
EnableGamepadUpdates();
#ifdef MOZ_VR
EnableVRUpdates();
#endif

// Resume all of the AudioContexts for this window
for (uint32_t i = 0; i < mAudioContexts.Length(); ++i) {
Expand Down Expand Up @@ -5979,6 +5999,7 @@ void nsGlobalWindowInner::SetHasGamepadEventListener(
}

void nsGlobalWindowInner::EventListenerAdded(nsAtom* aType) {
#ifdef MOZ_VR
if (aType == nsGkAtoms::onvrdisplayactivate ||
aType == nsGkAtoms::onvrdisplayconnect ||
aType == nsGkAtoms::onvrdisplaydeactivate ||
Expand All @@ -5990,6 +6011,7 @@ void nsGlobalWindowInner::EventListenerAdded(nsAtom* aType) {
if (aType == nsGkAtoms::onvrdisplayactivate) {
mHasVRDisplayActivateEvents = true;
}
#endif

if (aType == nsGkAtoms::onbeforeunload && mBrowserChild &&
(!mDoc || !(mDoc->GetSandboxFlags() & SANDBOXED_MODALS))) {
Expand Down Expand Up @@ -6035,6 +6057,7 @@ void nsGlobalWindowInner::EventListenerRemoved(nsAtom* aType) {
}
}

#ifdef MOZ_VR
void nsGlobalWindowInner::NotifyVREventListenerAdded() {
mHasVREvents = true;
EnableVRUpdates();
Expand All @@ -6060,6 +6083,7 @@ bool nsGlobalWindowInner::IsVRContentPresenting() const {
}
return false;
}
#endif

void nsGlobalWindowInner::AddSizeOfIncludingThis(
nsWindowSizes& aWindowSizes) const {
Expand Down Expand Up @@ -6183,6 +6207,7 @@ void nsGlobalWindowInner::StopGamepadHaptics() {
}
}

#ifdef MOZ_VR
bool nsGlobalWindowInner::UpdateVRDisplays(
nsTArray<RefPtr<mozilla::dom::VRDisplay>>& aDevices) {
VRDisplay::UpdateVRDisplays(mVRDisplays, this);
Expand Down Expand Up @@ -6352,6 +6377,7 @@ void nsGlobalWindowInner::DispatchVRDisplayPresentChange(uint32_t aDisplayID) {
}
}
}
#endif // MOZ_VR

enum WindowState {
// These constants need to match the constants in Window.webidl
Expand Down
12 changes: 12 additions & 0 deletions dom/base/nsGlobalWindowInner.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,11 @@ class TabGroup;
class Timeout;
class U2F;
class VisualViewport;
#ifdef MOZ_VR
class VRDisplay;
enum class VRDisplayEventReason : uint8_t;
class VREventObserver;
#endif
class WakeLock;
#if defined(MOZ_WIDGET_ANDROID)
class WindowOrientationObserver;
Expand Down Expand Up @@ -369,10 +371,12 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,

// Inner windows only.
virtual void SetHasGamepadEventListener(bool aHasGamepad = true) override;
#ifdef MOZ_VR
void NotifyVREventListenerAdded();
bool HasUsedVR() const;
bool IsVRContentDetected() const;
bool IsVRContentPresenting() const;
#endif

using EventTarget::EventListenerAdded;
virtual void EventListenerAdded(nsAtom* aType) override;
Expand Down Expand Up @@ -513,6 +517,7 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,

// Inner windows only.
// Enable/disable updates for VR
#ifdef MOZ_VR
void EnableVRUpdates();
void DisableVRUpdates();
// Reset telemetry data when switching windows.
Expand All @@ -538,6 +543,7 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
void DispatchVRDisplayConnect(uint32_t aDisplayID);
void DispatchVRDisplayDisconnect(uint32_t aDisplayID);
void DispatchVRDisplayPresentChange(uint32_t aDisplayID);
#endif

#define EVENT(name_, id_, type_, struct_) \
mozilla::dom::EventHandlerNonNull* GetOn##name_() { \
Expand Down Expand Up @@ -1299,13 +1305,17 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
bool mHasGamepad : 1;

// Indicates whether this window wants VR events
#ifdef MOZ_VR
bool mHasVREvents : 1;
#endif

// Whether we told the JS engine that we were in pageload.
bool mHintedWasLoading : 1;

// Indicates whether this window wants VRDisplayActivate events
#ifdef MOZ_VR
bool mHasVRDisplayActivateEvents : 1;
#endif
nsCheapSet<nsUint32HashKey> mGamepadIndexSet;
nsRefPtrHashtable<nsUint32HashKey, mozilla::dom::Gamepad> mGamepads;
bool mHasSeenGamepadInput;
Expand Down Expand Up @@ -1422,9 +1432,11 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
uint32_t mCanSkipCCGeneration;

// The VR Displays for this window
#ifdef MOZ_VR
nsTArray<RefPtr<mozilla::dom::VRDisplay>> mVRDisplays;

RefPtr<mozilla::dom::VREventObserver> mVREventObserver;
#endif

int64_t mBeforeUnloadListenerCount;

Expand Down
Loading

0 comments on commit a6cc149

Please sign in to comment.