Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 465fba1

Browse files
MortimerGorobluemarvin
authored andcommitted
Prevent deadlock when exiting WebXR/WebVR (#3382)
1 parent b86138a commit 465fba1

4 files changed

Lines changed: 22 additions & 7 deletions

File tree

app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ void onEnterWebXR() {
10481048

10491049
@Keep
10501050
@SuppressWarnings("unused")
1051-
void onExitWebXR() {
1051+
void onExitWebXR(long aCallback) {
10521052
if (Thread.currentThread() == mUiThread) {
10531053
return;
10541054
}
@@ -1070,6 +1070,9 @@ void onExitWebXR() {
10701070
if (!mWindows.isPaused()) {
10711071
Log.d(LOGTAG, "Compositor resume begin");
10721072
mWindows.resumeCompositor();
1073+
if (aCallback != 0) {
1074+
queueRunnable(() -> runCallbackNative(aCallback));
1075+
}
10731076
Log.d(LOGTAG, "Compositor resume end");
10741077
}
10751078
}, 20);

app/src/main/cpp/ExternalVR.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,17 @@ ExternalVR::SetCompositorEnabled(bool aEnabled) {
378378
}
379379
m.compositorEnabled = aEnabled;
380380
if (aEnabled) {
381-
VRBrowser::OnExitWebXR();
381+
// Set suppressFrames to avoid a deadlock between the sync surfaceChanged call
382+
// and the gecko VRManager SubmitFrame result wait.
383+
m.system.displayState.suppressFrames = true;
384+
PushSystemState();
385+
VRBrowser::OnExitWebXR([=]{
386+
m.system.displayState.suppressFrames = false;
387+
PushSystemState();
388+
});
382389
} else {
383-
// Set suppressFrames to avoid a deadlock between the compositor sync pause call and the gfxVRExternal SubmitFrame result wait.
390+
// Set suppressFrames to avoid a deadlock between the compositor sync pause call
391+
// and the gecko VRManager SubmitFrame result wait.
384392
m.system.displayState.suppressFrames = true;
385393
m.system.displayState.lastSubmittedFrameId = 0;
386394
m.lastFrameId = 0;

app/src/main/cpp/VRBrowser.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const char* const kRegisterExternalContextSignature = "(J)V";
3333
const char* const kOnEnterWebXRName = "onEnterWebXR";
3434
const char* const kOnEnterWebXRSignature = "()V";
3535
const char* const kOnExitWebXRName = "onExitWebXR";
36-
const char* const kOnExitWebXRSignature = "()V";
36+
const char* const kOnExitWebXRSignature = "(J)V";
3737
const char* const kOnDismissWebXRInterstitialName = "onDismissWebXRInterstitial";
3838
const char* const kOnDismissWebXRInterstitialSignature = "()V";
3939
const char* const kOnWebXRRenderStateChangeName = "onWebXRRenderStateChange";
@@ -263,9 +263,13 @@ VRBrowser::OnEnterWebXR() {
263263
}
264264

265265
void
266-
VRBrowser::OnExitWebXR() {
266+
VRBrowser::OnExitWebXR(const std::function<void()>& aCallback) {
267267
if (!ValidateMethodID(sEnv, sActivity, sOnExitWebXR, __FUNCTION__)) { return; }
268-
sEnv->CallVoidMethod(sActivity, sOnExitWebXR);
268+
jlong callback = 0;
269+
if (aCallback) {
270+
callback = reinterpret_cast<jlong>(new std::function<void()>(aCallback));
271+
}
272+
sEnv->CallVoidMethod(sActivity, sOnExitWebXR, callback);
269273
CheckJNIException(sEnv, __FUNCTION__);
270274
}
271275

app/src/main/cpp/VRBrowser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void HandleMoveEnd(jint aWidgetHandle, jfloat aX, jfloat aY, jfloat aZ, jfloat a
2929
void HandleBack();
3030
void RegisterExternalContext(jlong aContext);
3131
void OnEnterWebXR();
32-
void OnExitWebXR();
32+
void OnExitWebXR(const std::function<void()>& aCallback);
3333
void OnDismissWebXRInterstitial();
3434
void OnWebXRRenderStateChange(const bool aRendering);
3535
void RenderPointerLayer(jobject aSurface, const std::function<void()>& aFirstCompositeCallback);

0 commit comments

Comments
 (0)