Skip to content

Commit

Permalink
Pause WebXR spinner AnimatedVectorDrawable during immersive mode (#3255)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed Apr 27, 2020
1 parent 240f611 commit 1fe893a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 6 deletions.
19 changes: 13 additions & 6 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1077,12 +1077,19 @@ void onExitWebXR() {
@Keep
@SuppressWarnings("unused")
void onDismissWebXRInterstitial() {
runOnUiThread(new Runnable() {
@Override
public void run() {
for (WebXRListener listener: mWebXRListeners) {
listener.onDismissWebXRInterstitial();
}
runOnUiThread(() -> {
for (WebXRListener listener: mWebXRListeners) {
listener.onDismissWebXRInterstitial();
}
});
}

@Keep
@SuppressWarnings("unused")
void onWebXRRenderStateChange(boolean aRendering) {
runOnUiThread(() -> {
for (WebXRListener listener: mWebXRListeners) {
listener.onWebXRRenderStateChange(aRendering);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class WebXRInterstitialWidget extends UIWidget implements WidgetManagerDe
private ArrayList<WebXRInterstitialController> mControllers = new ArrayList<>();
private boolean firstEnterXR = true;
private AnimatedVectorDrawable mSpinnerAnimation;
private boolean mWebXRRendering = false;
private boolean mInterstitialDismissed = false;

public WebXRInterstitialWidget(Context aContext) {
super(aContext);
Expand Down Expand Up @@ -151,8 +153,22 @@ public void onExitWebXR() {

@Override
public void onDismissWebXRInterstitial() {
mInterstitialDismissed = true;
setHowToVisible(false);
hideControllers();
if (!mWebXRRendering) {
stopAnimation();
}
mWidgetManager.updateWidget(this);
}

@Override
public void onWebXRRenderStateChange(boolean aRendering) {
mWebXRRendering = aRendering;
if (aRendering && mInterstitialDismissed) {
stopAnimation();
} else if (!aRendering) {
startAnimation();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ interface WebXRListener {
void onEnterWebXR();
void onExitWebXR();
void onDismissWebXRInterstitial();
void onWebXRRenderStateChange(boolean aRendering);
}

float DEFAULT_DIM_BRIGHTNESS = 0.25f;
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ struct BrowserWorld::State {
std::function<void()> frameEndHandler;
bool wasInGazeMode = false;
WebXRInterstialState webXRInterstialState;
bool wasWebXRRendering = false;

State() : paused(true), glInitialized(false), modelsLoaded(false), env(nullptr), cylinderDensity(0.0f), nearClip(0.1f),
farClip(300.0f), activity(nullptr), windowsInitialized(false), exitImmersiveRequested(false), loaderDelay(0) {
Expand Down Expand Up @@ -261,6 +262,10 @@ bool
BrowserWorld::State::CheckExitImmersive() {
if (exitImmersiveRequested && externalVR->IsPresenting()) {
webXRInterstialState = WebXRInterstialState::HIDDEN;
if (wasWebXRRendering) {
VRBrowser::OnWebXRRenderStateChange(false);
wasWebXRRendering = false;
}
externalVR->StopPresenting();
blitter->StopPresenting();
exitImmersiveRequested = false;
Expand Down Expand Up @@ -1524,6 +1529,11 @@ BrowserWorld::TickImmersive() {
if (m.webXRInterstialState != WebXRInterstialState::HIDDEN) {
TickWebXRInterstitial();
} else {
if (!m.wasWebXRRendering) {
// Disable Spinner animation in Java to avoid triggering superfluous Android Draw calls.
VRBrowser::OnWebXRRenderStateChange(true);
m.wasWebXRRendering = true;
}
m.drawHandler = [=](device::Eye aEye) {
DrawImmersive(aEye);
};
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/cpp/VRBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const char* const kOnExitWebXRName = "onExitWebXR";
const char* const kOnExitWebXRSignature = "()V";
const char* const kOnDismissWebXRInterstitialName = "onDismissWebXRInterstitial";
const char* const kOnDismissWebXRInterstitialSignature = "()V";
const char* const kOnWebXRRenderStateChangeName = "onWebXRRenderStateChange";
const char* const kOnWebXRRenderStateChangeSignature = "(Z)V";
const char* const kRenderPointerLayerName = "renderPointerLayer";
const char* const kRenderPointerLayerSignature = "(Landroid/view/Surface;J)V";
const char* const kGetStorageAbsolutePathName = "getStorageAbsolutePath";
Expand Down Expand Up @@ -77,6 +79,7 @@ jmethodID sRegisterExternalContext = nullptr;
jmethodID sOnEnterWebXR = nullptr;
jmethodID sOnExitWebXR = nullptr;
jmethodID sOnDismissWebXRInterstitial = nullptr;
jmethodID sOnWebXRRenderStateChange = nullptr;
jmethodID sRenderPointerLayer = nullptr;
jmethodID sGetStorageAbsolutePath = nullptr;
jmethodID sIsOverrideEnvPathEnabled = nullptr;
Expand Down Expand Up @@ -121,6 +124,7 @@ VRBrowser::InitializeJava(JNIEnv* aEnv, jobject aActivity) {
sOnEnterWebXR = FindJNIMethodID(sEnv, sBrowserClass, kOnEnterWebXRName, kOnEnterWebXRSignature);
sOnExitWebXR = FindJNIMethodID(sEnv, sBrowserClass, kOnExitWebXRName, kOnExitWebXRSignature);
sOnDismissWebXRInterstitial = FindJNIMethodID(sEnv, sBrowserClass, kOnDismissWebXRInterstitialName, kOnDismissWebXRInterstitialSignature);
sOnWebXRRenderStateChange = FindJNIMethodID(sEnv, sBrowserClass, kOnWebXRRenderStateChangeName, kOnWebXRRenderStateChangeSignature);
sRenderPointerLayer = FindJNIMethodID(sEnv, sBrowserClass, kRenderPointerLayerName, kRenderPointerLayerSignature);
sGetStorageAbsolutePath = FindJNIMethodID(sEnv, sBrowserClass, kGetStorageAbsolutePathName, kGetStorageAbsolutePathSignature);
sIsOverrideEnvPathEnabled = FindJNIMethodID(sEnv, sBrowserClass, kIsOverrideEnvPathEnabledName, kIsOverrideEnvPathEnabledSignature);
Expand Down Expand Up @@ -160,6 +164,7 @@ VRBrowser::ShutdownJava() {
sOnEnterWebXR = nullptr;
sOnExitWebXR = nullptr;
sOnDismissWebXRInterstitial = nullptr;
sOnWebXRRenderStateChange = nullptr;
sRenderPointerLayer = nullptr;
sGetStorageAbsolutePath = nullptr;
sIsOverrideEnvPathEnabled = nullptr;
Expand Down Expand Up @@ -270,6 +275,12 @@ void VRBrowser::OnDismissWebXRInterstitial() {
CheckJNIException(sEnv, __FUNCTION__);
}

void VRBrowser::OnWebXRRenderStateChange(const bool aRendering) {
if (!ValidateMethodID(sEnv, sActivity, sOnWebXRRenderStateChange, __FUNCTION__)) { return; }
sEnv->CallVoidMethod(sActivity, sOnWebXRRenderStateChange, (jboolean) aRendering);
CheckJNIException(sEnv, __FUNCTION__);
}

void
VRBrowser::RenderPointerLayer(jobject aSurface, const std::function<void()>& aFirstCompositeCallback) {
if (!ValidateMethodID(sEnv, sActivity, sRenderPointerLayer, __FUNCTION__)) { return; }
Expand Down
1 change: 1 addition & 0 deletions app/src/main/cpp/VRBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void RegisterExternalContext(jlong aContext);
void OnEnterWebXR();
void OnExitWebXR();
void OnDismissWebXRInterstitial();
void OnWebXRRenderStateChange(const bool aRendering);
void RenderPointerLayer(jobject aSurface, const std::function<void()>& aFirstCompositeCallback);
std::string GetStorageAbsolutePath(const std::string& aRelativePath);
bool isOverrideEnvPathEnabled();
Expand Down

0 comments on commit 1fe893a

Please sign in to comment.