Skip to content

Commit

Permalink
Bug 1627331 - Do not dispatch WebVR events when the display is used v…
Browse files Browse the repository at this point in the history
…ia WebXR API r=kip,daoshengmu

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

--HG--
extra : moz-landing-system : lando
  • Loading branch information
MortimerGoro committed Apr 7, 2020
1 parent 3f6630e commit 3f977ef
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
24 changes: 16 additions & 8 deletions dom/vr/VREventObserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,31 @@ void VREventObserver::NotifyAfterLoad() {
}

void VREventObserver::NotifyVRDisplayMounted(uint32_t aDisplayID) {
if (mWindow && mWindow->IsCurrentInnerWindow()) {
if (mWindow && mWindow->IsCurrentInnerWindow() && IsWebVR(aDisplayID)) {
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
mWindow->DispatchVRDisplayActivate(aDisplayID,
VRDisplayEventReason::Mounted);
}
}

void VREventObserver::NotifyVRDisplayNavigation(uint32_t aDisplayID) {
if (mWindow && mWindow->IsCurrentInnerWindow()) {
if (mWindow && mWindow->IsCurrentInnerWindow() && IsWebVR(aDisplayID)) {
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
mWindow->DispatchVRDisplayActivate(aDisplayID,
VRDisplayEventReason::Navigation);
}
}

void VREventObserver::NotifyVRDisplayRequested(uint32_t aDisplayID) {
if (mWindow && mWindow->IsCurrentInnerWindow()) {
if (mWindow && mWindow->IsCurrentInnerWindow() && IsWebVR(aDisplayID)) {
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
mWindow->DispatchVRDisplayActivate(aDisplayID,
VRDisplayEventReason::Requested);
}
}

void VREventObserver::NotifyVRDisplayUnmounted(uint32_t aDisplayID) {
if (mWindow && mWindow->IsCurrentInnerWindow()) {
if (mWindow && mWindow->IsCurrentInnerWindow() && IsWebVR(aDisplayID)) {
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
mWindow->DispatchVRDisplayDeactivate(aDisplayID,
VRDisplayEventReason::Unmounted);
Expand All @@ -129,14 +129,14 @@ void VREventObserver::NotifyVRDisplayConnect(uint32_t aDisplayID) {
* can assume that a newly enumerated display is not presenting WebVR
* content.
*/
if (mWindow && mWindow->IsCurrentInnerWindow()) {
if (mWindow && mWindow->IsCurrentInnerWindow() && IsWebVR(aDisplayID)) {
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
mWindow->DispatchVRDisplayConnect(aDisplayID);
}
}

void VREventObserver::NotifyVRDisplayDisconnect(uint32_t aDisplayID) {
if (mWindow && mWindow->IsCurrentInnerWindow()) {
if (mWindow && mWindow->IsCurrentInnerWindow() && IsWebVR(aDisplayID)) {
mWindow->NotifyActiveVRDisplaysChanged();
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
mWindow->DispatchVRDisplayDisconnect(aDisplayID);
Expand All @@ -148,15 +148,15 @@ void VREventObserver::NotifyVRDisplayPresentChange(uint32_t aDisplayID) {
// to be a 2D view.
mIs2DView = false;

if (mWindow && mWindow->IsCurrentInnerWindow()) {
if (mWindow && mWindow->IsCurrentInnerWindow() && IsWebVR(aDisplayID)) {
mWindow->NotifyActiveVRDisplaysChanged();
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
mWindow->DispatchVRDisplayPresentChange(aDisplayID);
}
}

void VREventObserver::NotifyPresentationGenerationChanged(uint32_t aDisplayID) {
if (mWindow && mWindow->IsCurrentInnerWindow()) {
if (mWindow && mWindow->IsCurrentInnerWindow() && IsWebVR(aDisplayID)) {
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
mWindow->NotifyPresentationGenerationChanged(aDisplayID);
}
Expand All @@ -171,5 +171,13 @@ void VREventObserver::NotifyDetectRuntimesCompleted() {
}
}

bool VREventObserver::IsWebVR(uint32_t aDisplayID) const {
VRManagerChild* vmc = VRManagerChild::Get();
if (vmc) {
return vmc->GetVRAPIMode(aDisplayID) == gfx::VRAPIMode::WebVR;
}
return true;
}

} // namespace dom
} // namespace mozilla
2 changes: 2 additions & 0 deletions dom/vr/VREventObserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class VREventObserver final : public gfx::VRManagerEventObserver {
private:
~VREventObserver();

bool IsWebVR(uint32_t aDisplayID) const;

RefPtr<nsGlobalWindowInner> mWindow;
// For WebVR telemetry for tracking users who view content
// in the 2D view.
Expand Down
4 changes: 4 additions & 0 deletions gfx/vr/VRDisplayClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ void VRDisplayClient::MakePresentationGenerationCurrent() {
mLastPresentingGeneration = mDisplayInfo.mDisplayState.presentingGeneration;
}

gfx::VRAPIMode VRDisplayClient::GetXRAPIMode() const {
return mAPIMode;
}

void VRDisplayClient::SetXRAPIMode(gfx::VRAPIMode aMode) {
mAPIMode = aMode;
}
Expand Down
1 change: 1 addition & 0 deletions gfx/vr/VRDisplayClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class VRDisplayClient {

bool IsPresenting();
bool IsReferenceSpaceTypeSupported(dom::XRReferenceSpaceType aType) const;
gfx::VRAPIMode GetXRAPIMode() const;
void SetXRAPIMode(gfx::VRAPIMode aMode);

protected:
Expand Down
9 changes: 9 additions & 0 deletions gfx/vr/ipc/VRManagerChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,15 @@ void VRManagerChild::AddPromise(const uint32_t& aID, dom::Promise* aPromise) {
mGamepadPromiseList.Put(aID, RefPtr{aPromise});
}

gfx::VRAPIMode VRManagerChild::GetVRAPIMode(uint32_t aDisplayID) const {
for (auto& display : mDisplays) {
if (display->GetDisplayInfo().GetDisplayID() == aDisplayID) {
return display->GetXRAPIMode();
}
}
return VRAPIMode::WebXR;
}

mozilla::ipc::IPCResult VRManagerChild::RecvReplyGamepadVibrateHaptic(
const uint32_t& aPromiseID) {
// VRManagerChild could be at other processes, but GamepadManager
Expand Down
1 change: 1 addition & 0 deletions gfx/vr/ipc/VRManagerChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class VRManagerChild : public PVRManagerChild {
bool EnumerateVRDisplays();
void DetectRuntimes();
void AddPromise(const uint32_t& aID, dom::Promise* aPromise);
gfx::VRAPIMode GetVRAPIMode(uint32_t aDisplayID) const;

static void InitSameProcess();
static void InitWithGPUProcess(Endpoint<PVRManagerChild>&& aEndpoint);
Expand Down

0 comments on commit 3f977ef

Please sign in to comment.