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

Commit

Permalink
Prevent deadlock when exiting WebXR/WebVR
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed May 15, 2020
1 parent 9d848c4 commit bc5c08f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ void onEnterWebXR() {

@Keep
@SuppressWarnings("unused")
void onExitWebXR() {
void onExitWebXR(long aCallback) {
if (Thread.currentThread() == mUiThread) {
return;
}
Expand All @@ -1070,6 +1070,9 @@ void onExitWebXR() {
if (!mWindows.isPaused()) {
Log.d(LOGTAG, "Compositor resume begin");
mWindows.resumeCompositor();
if (aCallback != 0) {
queueRunnable(() -> runCallbackNative(aCallback));
}
Log.d(LOGTAG, "Compositor resume end");
}
}, 20);
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/cpp/ExternalVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,17 @@ ExternalVR::SetCompositorEnabled(bool aEnabled) {
}
m.compositorEnabled = aEnabled;
if (aEnabled) {
VRBrowser::OnExitWebXR();
// Set suppressFrames to avoid a deadlock between the sync surfaceChanged call
// and the gecko VRManager SubmitFrame result wait.
m.system.displayState.suppressFrames = true;
PushSystemState();
VRBrowser::OnExitWebXR([=]{
m.system.displayState.suppressFrames = false;
PushSystemState();
});
} else {
// Set suppressFrames to avoid a deadlock between the compositor sync pause call and the gfxVRExternal SubmitFrame result wait.
// Set suppressFrames to avoid a deadlock between the compositor sync pause call
// and the gecko VRManager SubmitFrame result wait.
m.system.displayState.suppressFrames = true;
m.system.displayState.lastSubmittedFrameId = 0;
m.lastFrameId = 0;
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/cpp/VRBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const char* const kRegisterExternalContextSignature = "(J)V";
const char* const kOnEnterWebXRName = "onEnterWebXR";
const char* const kOnEnterWebXRSignature = "()V";
const char* const kOnExitWebXRName = "onExitWebXR";
const char* const kOnExitWebXRSignature = "()V";
const char* const kOnExitWebXRSignature = "(J)V";
const char* const kOnDismissWebXRInterstitialName = "onDismissWebXRInterstitial";
const char* const kOnDismissWebXRInterstitialSignature = "()V";
const char* const kOnWebXRRenderStateChangeName = "onWebXRRenderStateChange";
Expand Down Expand Up @@ -263,9 +263,13 @@ VRBrowser::OnEnterWebXR() {
}

void
VRBrowser::OnExitWebXR() {
VRBrowser::OnExitWebXR(const std::function<void()>& aCallback) {
if (!ValidateMethodID(sEnv, sActivity, sOnExitWebXR, __FUNCTION__)) { return; }
sEnv->CallVoidMethod(sActivity, sOnExitWebXR);
jlong callback = 0;
if (aCallback) {
callback = reinterpret_cast<jlong>(new std::function<void()>(aCallback));
}
sEnv->CallVoidMethod(sActivity, sOnExitWebXR, callback);
CheckJNIException(sEnv, __FUNCTION__);
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/VRBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void HandleMoveEnd(jint aWidgetHandle, jfloat aX, jfloat aY, jfloat aZ, jfloat a
void HandleBack();
void RegisterExternalContext(jlong aContext);
void OnEnterWebXR();
void OnExitWebXR();
void OnExitWebXR(const std::function<void()>& aCallback);
void OnDismissWebXRInterstitial();
void OnWebXRRenderStateChange(const bool aRendering);
void RenderPointerLayer(jobject aSurface, const std::function<void()>& aFirstCompositeCallback);
Expand Down

0 comments on commit bc5c08f

Please sign in to comment.