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

Prevent deadlock when exiting WebXR/WebVR #3382

Merged
merged 1 commit into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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