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

Commit

Permalink
Implement WebXR Interstitial (#3136)
Browse files Browse the repository at this point in the history
* Implement WebXR Interstitial

* Fix for AnimatedVectorDrawables in Pico devices

* Improve layout and flow.

* Remove old spinner

* Hide controller input until the interstitial is hidden.

* Fix grip button detection in Oculus

* Rebase and update to latest spec

* Restore required disabling hw acceleration for voice animation

Co-authored-by: Manuel Martin <imanol.martin@gmail.com>
  • Loading branch information
MortimerGoro and keianhzo authored Apr 17, 2020
1 parent f914e0d commit 93b3f9f
Show file tree
Hide file tree
Showing 46 changed files with 1,280 additions and 5,123 deletions.
1 change: 0 additions & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ add_library( # Sets the name of the library.
src/main/cpp/ExternalVR.cpp
src/main/cpp/GeckoSurfaceTexture.cpp
src/main/cpp/GestureDelegate.cpp
src/main/cpp/LoadingAnimation.cpp
src/main/cpp/JNIUtil.cpp
src/main/cpp/Pointer.cpp
src/main/cpp/Skybox.cpp
Expand Down
62 changes: 54 additions & 8 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.mozilla.vrbrowser.ui.widgets.TrayWidget;
import org.mozilla.vrbrowser.ui.widgets.UISurfaceTextureRenderer;
import org.mozilla.vrbrowser.ui.widgets.UIWidget;
import org.mozilla.vrbrowser.ui.widgets.WebXRInterstitialWidget;
import org.mozilla.vrbrowser.ui.widgets.Widget;
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;
Expand Down Expand Up @@ -167,11 +168,13 @@ public void run() {
NavigationBarWidget mNavigationBar;
CrashDialogWidget mCrashDialog;
TrayWidget mTray;
WebXRInterstitialWidget mWebXRInterstitial;
PermissionDelegate mPermissionDelegate;
LinkedList<UpdateListener> mWidgetUpdateListeners;
LinkedList<PermissionListener> mPermissionListeners;
LinkedList<FocusChangeListener> mFocusChangeListeners;
LinkedList<WorldClickListener> mWorldClickListeners;
LinkedList<WebXRListener> mWebXRListeners;
CopyOnWriteArrayList<Delegate> mConnectivityListeners;
LinkedList<Runnable> mBackHandlers;
private boolean mIsPresentingImmersive = false;
Expand Down Expand Up @@ -261,6 +264,7 @@ protected void onCreate(Bundle savedInstanceState) {
mPermissionListeners = new LinkedList<>();
mFocusChangeListeners = new LinkedList<>();
mWorldClickListeners = new LinkedList<>();
mWebXRListeners = new LinkedList<>();
mBackHandlers = new LinkedList<>();
mBrightnessQueue = new LinkedList<>();
mConnectivityListeners = new CopyOnWriteArrayList<>();
Expand Down Expand Up @@ -326,6 +330,9 @@ protected void initializeWidgets() {
// Create keyboard widget
mKeyboard = new KeyboardWidget(this);

// Create the WebXR interstitial
mWebXRInterstitial = new WebXRInterstitialWidget(this);

// Windows
mWindows = new Windows(this);
mWindows.setDelegate(new Windows.Delegate() {
Expand Down Expand Up @@ -369,7 +376,7 @@ public void onWindowVideoAvailabilityChanged(@NonNull WindowWidget aWindow) {

attachToWindow(mWindows.getFocusedWindow(), null);

addWidgets(Arrays.asList(mRootWidget, mNavigationBar, mKeyboard, mTray));
addWidgets(Arrays.asList(mRootWidget, mNavigationBar, mKeyboard, mTray, mWebXRInterstitial));

// Show the what's upp dialog if we haven't showed it yet and this is v6.
if (!SettingsStore.getInstance(this).isWhatsNewDisplayed()) {
Expand Down Expand Up @@ -976,15 +983,20 @@ public void run() {

@Keep
@SuppressWarnings("unused")
void pauseGeckoViewCompositor() {
void onEnterWebXR() {
if (Thread.currentThread() == mUiThread) {
return;
}
mIsPresentingImmersive = true;
runOnUiThread(() -> mWindows.enterImmersiveMode());

runOnUiThread(() -> {
mWindows.enterImmersiveMode();
for (WebXRListener listener: mWebXRListeners) {
listener.onEnterWebXR();
}
});
TelemetryWrapper.startImmersive();
GleanMetricsService.startImmersive();

PauseCompositorRunnable runnable = new PauseCompositorRunnable();

synchronized (mCompositorLock) {
Expand All @@ -1001,12 +1013,17 @@ void pauseGeckoViewCompositor() {

@Keep
@SuppressWarnings("unused")
void resumeGeckoViewCompositor() {
void onExitWebXR() {
if (Thread.currentThread() == mUiThread) {
return;
}
mIsPresentingImmersive = false;
runOnUiThread(() -> mWindows.exitImmersiveMode());
runOnUiThread(() -> {
mWindows.exitImmersiveMode();
for (WebXRListener listener: mWebXRListeners) {
listener.onExitWebXR();
}
});

// Show the window in front of you when you exit immersive mode.
resetUIYaw();
Expand All @@ -1022,6 +1039,18 @@ void resumeGeckoViewCompositor() {
}
}, 20);
}
@Keep
@SuppressWarnings("unused")
void onDismissWebXRInterstitial() {
runOnUiThread(new Runnable() {
@Override
public void run() {
for (WebXRListener listener: mWebXRListeners) {
listener.onDismissWebXRInterstitial();
}
}
});
}

@Keep
@SuppressWarnings("unused")
Expand Down Expand Up @@ -1091,8 +1120,9 @@ public int getPointerColor() {
@Keep
@SuppressWarnings("unused")
private void setDeviceType(int aType) {

runOnUiThread(() -> DeviceType.setType(aType));
if (DeviceType.isOculusBuild()) {
runOnUiThread(() -> DeviceType.setType(aType));
}
}

@Keep
Expand Down Expand Up @@ -1386,6 +1416,21 @@ public void removeWorldClickListener(WorldClickListener aListener) {
mWorldClickListeners.remove(aListener);
}

@Override
public void addWebXRListener(WebXRListener aListener) {
mWebXRListeners.add(aListener);
}

@Override
public void removeWebXRListener(WebXRListener aListener) {
mWebXRListeners.remove(aListener);
}

@Override
public void setWebXRIntersitialState(@WebXRInterstitialState int aState) {
queueRunnable(() -> setWebXRIntersitialStateNative(aState));
}

@Override
public void addConnectivityListener(Delegate aListener) {
if (!mConnectivityListeners.contains(aListener)) {
Expand Down Expand Up @@ -1624,5 +1669,6 @@ public AppServicesProvider getServicesProvider() {
private native void runCallbackNative(long aCallback);
private native void setCylinderDensityNative(float aDensity);
private native void setCPULevelNative(@CPULevelFlags int aCPULevel);
private native void setWebXRIntersitialStateNative(@WebXRInterstitialState int aState);
private native void setIsServo(boolean aIsServo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.parentAnchorX = 0.5f;
aPlacement.parentAnchorY = 0.0f;
aPlacement.translationY = -35;
aPlacement.opaque = false;
aPlacement.cylinder = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.parentAnchorX = 0.5f;
aPlacement.parentAnchorY = 0.0f;
aPlacement.translationY = -35;
aPlacement.opaque = false;
aPlacement.cylinder = true;
aPlacement.visible = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.anchorY = 0.0f;
aPlacement.parentAnchorX = 0.5f;
aPlacement.parentAnchorY = 1.0f;
aPlacement.opaque = false;
}

private void updateUI() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.parentAnchorY = 0.0f;
aPlacement.rotationAxisX = 1.0f;
aPlacement.rotation = (float)Math.toRadians(-45);
aPlacement.opaque = false;
aPlacement.cylinder = false;
aPlacement.textureScale = 1.0f;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.mozilla.vrbrowser.ui.widgets;

import android.content.Context;
import android.view.LayoutInflater;

import androidx.annotation.IntDef;
import androidx.databinding.DataBindingUtil;

import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.VRBrowserActivity;
import org.mozilla.vrbrowser.databinding.WebxrInterstitialControllerBinding;
import org.mozilla.vrbrowser.utils.DeviceType;

public class WebXRInterstitialController extends UIWidget {
private WebxrInterstitialControllerBinding mBinding;

@IntDef(value = { HAND_NONE, HAND_LEFT, HAND_RIGHT })
public @interface Hand {}
public static final int HAND_NONE = -1;
public static final int HAND_LEFT = 0;
public static final int HAND_RIGHT = 1;

public WebXRInterstitialController(Context aContext, int aModel, @Hand int aHand ) {
super(aContext);
initialize(aModel, aHand);
}

@Override
protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.scene = WidgetPlacement.SCENE_WEBXR_INTERSTITIAL;
aPlacement.visible = false;
aPlacement.cylinder = false;
}

private void updatePlacement() {
mWidgetPlacement.setSizeFromMeasure(getContext(), this);
mWidgetPlacement.worldWidth = mWidgetPlacement.width * WidgetPlacement.worldToDpRatio(getContext()) * 1.15f;
if (mBinding.getHand() == HAND_LEFT) {
mWidgetPlacement.anchorX = 1.0f;
mWidgetPlacement.anchorY = 0.5f;
mWidgetPlacement.parentAnchorX = 0.0f;
mWidgetPlacement.parentAnchorY = 0.5f;
mWidgetPlacement.translationX = -WidgetPlacement.dpDimension(getContext(), R.dimen.webxr_interstitial_controller_margin_h);
} else if (mBinding.getHand() == HAND_RIGHT) {
mWidgetPlacement.anchorX = 0.0f;
mWidgetPlacement.anchorY = 0.5f;
mWidgetPlacement.parentAnchorX = 1.0f;
mWidgetPlacement.parentAnchorY = 0.5f;
mWidgetPlacement.translationX = WidgetPlacement.dpDimension(getContext(), R.dimen.webxr_interstitial_controller_margin_h);
} else {
mWidgetPlacement.anchorX = 0.5f;
mWidgetPlacement.anchorY = 1.0f;
mWidgetPlacement.parentAnchorX = 0.5f;
mWidgetPlacement.parentAnchorY = 0.0f;
mWidgetPlacement.translationY = 0;//-WidgetPlacement.dpDimension(getContext(), R.dimen.webxr_interstitial_controller_margin_v);
}
}

private void initialize(int aModel, @Hand int aHand) {
LayoutInflater inflater = LayoutInflater.from(getContext());
mBinding = DataBindingUtil.inflate(inflater, R.layout.webxr_interstitial_controller, this, true);
mBinding.setLifecycleOwner((VRBrowserActivity)getContext());
mBinding.setModel(aModel);
mBinding.setHand(aHand);
mBinding.executePendingBindings();
updatePlacement();
}


}
Loading

0 comments on commit 93b3f9f

Please sign in to comment.