Skip to content

Commit

Permalink
Restart XR immersive session foreground activity if needed when proce…
Browse files Browse the repository at this point in the history
…ss is unsuspended

https://bugs.webkit.org/show_bug.cgi?id=260226
rdar://107913685

Reviewed by Chris Dumez and Dean Jackson.

The "XR immersive session" foreground activity is added when an
XR session starts so the web process has the foreground priority
to do rendering work. That activity gets invalidated when the
process is suspended. So if the process resumes again while an
XR session is still in progress, we need to add that foreground
activity again.

* Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::setProcessesShouldSuspend):
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::restartXRSessionActivityOnProcessResumeIfNeeded):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/XR/PlatformXRSystem.cpp:
(WebKit::PlatformXRSystem::ensureImmersiveSessionActivity):
(WebKit::PlatformXRSystem::initializeTrackingAndRendering):
* Source/WebKit/UIProcess/XR/PlatformXRSystem.h:

Canonical link: https://commits.webkit.org/267097@main
  • Loading branch information
achan00 committed Aug 21, 2023
1 parent e78e75e commit ce151b9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
10 changes: 9 additions & 1 deletion Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1067,8 +1067,16 @@ void setLockdownModeEnabledGloballyForTesting(std::optional<bool> enabledForTest
return;

m_processesShouldSuspend = shouldSuspend;
for (auto& process : m_processes)
for (auto& process : m_processes) {
process->throttler().setAllowsActivities(!m_processesShouldSuspend);

#if ENABLE(WEBXR) && !USE(OPENXR)
if (!m_processesShouldSuspend) {
for (auto& page : process->pages())
page->restartXRSessionActivityOnProcessResumeIfNeeded();
}
#endif
}
}

#endif
Expand Down
6 changes: 6 additions & 0 deletions Source/WebKit/UIProcess/WebPageProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7422,6 +7422,12 @@ PlatformXRSystem* WebPageProxy::xrSystem() const
{
return internals().xrSystem.get();
}

void WebPageProxy::restartXRSessionActivityOnProcessResumeIfNeeded()
{
if (xrSystem() && xrSystem()->hasActiveSession())
xrSystem()->ensureImmersiveSessionActivity();
}
#endif

#if ENABLE(INPUT_TYPE_COLOR)
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/UIProcess/WebPageProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -2256,6 +2256,7 @@ class WebPageProxy final : public API::ObjectImpl<API::Object::Type::Page>, publ

#if ENABLE(WEBXR) && !USE(OPENXR)
PlatformXRSystem* xrSystem() const;
void restartXRSessionActivityOnProcessResumeIfNeeded();
#endif

#if ENABLE(INPUT_TYPE_COLOR)
Expand Down
10 changes: 9 additions & 1 deletion Source/WebKit/UIProcess/XR/PlatformXRSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ void PlatformXRSystem::invalidate()
xrCoordinator()->endSessionIfExists(m_page);
}

void PlatformXRSystem::ensureImmersiveSessionActivity()
{
if (m_immersiveSessionActivity && m_immersiveSessionActivity->isValid())
return;

m_immersiveSessionActivity = m_page.process().throttler().foregroundActivity("XR immersive session"_s).moveToUniquePtr();
}

void PlatformXRSystem::enumerateImmersiveXRDevices(CompletionHandler<void(Vector<XRDeviceInfo>&&)>&& completionHandler)
{
auto* xrCoordinator = PlatformXRSystem::xrCoordinator();
Expand Down Expand Up @@ -91,7 +99,7 @@ void PlatformXRSystem::initializeTrackingAndRendering(const WebCore::SecurityOri
if (!xrCoordinator)
return;

m_immersiveSessionActivity = m_page.process().throttler().foregroundActivity("XR immersive session"_s).moveToUniquePtr();
ensureImmersiveSessionActivity();

WeakPtr weakThis { *this };
xrCoordinator->startSession(m_page, weakThis, securityOriginData, mode, requestedFeatures);
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/UIProcess/XR/PlatformXRSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class PlatformXRSystem : public IPC::MessageReceiver, public PlatformXRCoordinat
void invalidate();

bool hasActiveSession() const { return !!m_immersiveSessionActivity; }
void ensureImmersiveSessionActivity();

private:
static PlatformXRCoordinator* xrCoordinator();
Expand Down

0 comments on commit ce151b9

Please sign in to comment.