Commit a22648ac authored by bshe's avatar bshe Committed by Commit bot

Enable cardboard support for non-Daydream devices

If VrCore exists on non-Daydream devices, WebVR Cardboard support should be enabled.

BUG=671370

Review-Url: https://codereview.chromium.org/2556093002
Cr-Commit-Position: refs/heads/master@{#437962}
parent 312059d8
...@@ -68,7 +68,7 @@ public class VrShellDelegate { ...@@ -68,7 +68,7 @@ public class VrShellDelegate {
private final Intent mEnterVRIntent; private final Intent mEnterVRIntent;
private boolean mVrAvailable; private boolean mVrAvailable;
private boolean mDaydreamReadyDevice; private boolean mCardboardSupportOnly;
private Boolean mVrShellEnabled; private Boolean mVrShellEnabled;
private VrClassesBuilder mVrClassesBuilder; private VrClassesBuilder mVrClassesBuilder;
...@@ -90,30 +90,42 @@ public class VrShellDelegate { ...@@ -90,30 +90,42 @@ public class VrShellDelegate {
public VrShellDelegate(ChromeTabbedActivity activity) { public VrShellDelegate(ChromeTabbedActivity activity) {
mActivity = activity; mActivity = activity;
mVrAvailable = createVrClassesBuilder() && isVrCoreCompatible() && createVrDaydreamApi() // TODO(bshe): refactor code so that mCardboardSupportOnly does not depend on mVrAvailable
&& mVrDaydreamApi.isDaydreamReadyDevice(); // and mVrAvailable does not depend on createVrDaydreamApi.
if (mVrAvailable) { mVrAvailable = createVrClassesBuilder() && isVrCoreCompatible() && createVrDaydreamApi();
mEnterVRIntent = mVrDaydreamApi.createVrIntent( // Make sure mVrDaydreamApi is created as createVrDaydreamApi might not get called above.
new ComponentName(mActivity, VR_ACTIVITY_ALIAS)); if (mVrDaydreamApi == null) createVrDaydreamApi();
// Only Cardboard mode is supported on non-daydream devices.
mCardboardSupportOnly = !mVrDaydreamApi.isDaydreamReadyDevice();
if (mVrAvailable && !mCardboardSupportOnly) {
mEnterVRIntent =
mVrDaydreamApi.createVrIntent(new ComponentName(mActivity, VR_ACTIVITY_ALIAS));
} else { } else {
mEnterVRIntent = null; mEnterVRIntent = null;
} }
mTabObserver = new EmptyTabObserver() { if (mVrAvailable) {
@Override mTabObserver = new EmptyTabObserver() {
public void onContentChanged(Tab tab) { @Override
if (tab.getNativePage() != null || tab.isShowingSadTab()) { public void onContentChanged(Tab tab) {
// For now we don't handle native pages. crbug.com/661609 if (tab.getNativePage() != null || tab.isShowingSadTab()) {
shutdownVR(false, true); // For now we don't handle native pages. crbug.com/661609.
shutdownVR(false, !mCardboardSupportOnly /* showTransition */);
}
} }
}
@Override @Override
public void onWebContentsSwapped(Tab tab, boolean didStartLoad, boolean didFinishLoad) { public void onWebContentsSwapped(
// TODO(mthiesse): Update the native WebContents pointer and compositor. This Tab tab, boolean didStartLoad, boolean didFinishLoad) {
// doesn't seem to get triggered in VR Shell currently, but that's likely to change // TODO(mthiesse): Update the native WebContents pointer and compositor. This
// when we have omnibar navigation. // doesn't seem to get triggered in VR Shell currently, but that's likely to
} // change
}; // when we have omnibar navigation.
}
};
} else {
mTabObserver = null;
}
} }
/** /**
...@@ -149,7 +161,8 @@ public class VrShellDelegate { ...@@ -149,7 +161,8 @@ public class VrShellDelegate {
* Handle a VR intent, entering VR in the process unless we're unable to. * Handle a VR intent, entering VR in the process unless we're unable to.
*/ */
public void enterVRFromIntent(Intent intent) { public void enterVRFromIntent(Intent intent) {
if (!mVrAvailable) return; // Vr Intent is only used on Daydream devices.
if (!mVrAvailable || mCardboardSupportOnly) return;
assert isVrIntent(intent); assert isVrIntent(intent);
if (mListeningForWebVrActivateBeforePause && !mRequestedWebVR) { if (mListeningForWebVrActivateBeforePause && !mRequestedWebVR) {
nativeDisplayActivate(mNativeVrShellDelegate); nativeDisplayActivate(mNativeVrShellDelegate);
...@@ -269,7 +282,7 @@ public class VrShellDelegate { ...@@ -269,7 +282,7 @@ public class VrShellDelegate {
if (mInVr) return ENTER_VR_NOT_NECESSARY; if (mInVr) return ENTER_VR_NOT_NECESSARY;
if (!canEnterVR(mActivity.getActivityTab())) return ENTER_VR_CANCELLED; if (!canEnterVR(mActivity.getActivityTab())) return ENTER_VR_CANCELLED;
if (!mVrDaydreamApi.isDaydreamCurrentViewer()) { if (mCardboardSupportOnly || !mVrDaydreamApi.isDaydreamCurrentViewer()) {
// Avoid using launchInVr which would trigger DON flow regardless current viewer type // Avoid using launchInVr which would trigger DON flow regardless current viewer type
// due to the lack of support for unexported activities. // due to the lack of support for unexported activities.
return enterVR() ? ENTER_VR_SUCCEEDED : ENTER_VR_CANCELLED; return enterVR() ? ENTER_VR_SUCCEEDED : ENTER_VR_CANCELLED;
...@@ -283,10 +296,16 @@ public class VrShellDelegate { ...@@ -283,10 +296,16 @@ public class VrShellDelegate {
private boolean exitWebVR() { private boolean exitWebVR() {
if (!mInVr) return false; if (!mInVr) return false;
mVrShell.setWebVrModeEnabledOnUI(false); mVrShell.setWebVrModeEnabledOnUI(false);
// TODO(bajones): Once VR Shell can be invoked outside of WebVR this if (mCardboardSupportOnly) {
// should no longer exit the shell outright. Need a way to determine // Transition screen is not available for Cardboard only (non-Daydream) devices.
// how VrShell was created. // TODO(bshe): Fix this once b/33490788 is fixed.
shutdownVR(false, !isVrShellEnabled()); shutdownVR(false, false);
} else {
// TODO(bajones): Once VR Shell can be invoked outside of WebVR this
// should no longer exit the shell outright. Need a way to determine
// how VrShell was created.
shutdownVR(false, !isVrShellEnabled());
}
return true; return true;
} }
...@@ -300,7 +319,8 @@ public class VrShellDelegate { ...@@ -300,7 +319,8 @@ public class VrShellDelegate {
*/ */
public void maybeResumeVR() { public void maybeResumeVR() {
if (!mVrAvailable) return; if (!mVrAvailable) return;
if (isVrShellEnabled() || mListeningForWebVrActivateBeforePause) { if ((isVrShellEnabled() || mListeningForWebVrActivateBeforePause)
&& !mCardboardSupportOnly) {
registerDaydreamIntent(); registerDaydreamIntent();
} }
// If this is still set, it means the user backed out of the DON flow, and we won't be // If this is still set, it means the user backed out of the DON flow, and we won't be
...@@ -334,7 +354,7 @@ public class VrShellDelegate { ...@@ -334,7 +354,7 @@ public class VrShellDelegate {
} finally { } finally {
StrictMode.setThreadPolicy(oldPolicy); StrictMode.setThreadPolicy(oldPolicy);
} }
} else if (mVrDaydreamApi.isDaydreamCurrentViewer() } else if (!mCardboardSupportOnly && mVrDaydreamApi.isDaydreamCurrentViewer()
&& mLastVRExit + REENTER_VR_TIMEOUT_MS > SystemClock.uptimeMillis()) { && mLastVRExit + REENTER_VR_TIMEOUT_MS > SystemClock.uptimeMillis()) {
enterVRIfNecessary(); enterVRIfNecessary();
} }
...@@ -345,16 +365,19 @@ public class VrShellDelegate { ...@@ -345,16 +365,19 @@ public class VrShellDelegate {
*/ */
public void maybePauseVR() { public void maybePauseVR() {
if (!mVrAvailable) return; if (!mVrAvailable) return;
unregisterDaydreamIntent();
if (!mCardboardSupportOnly) {
// When the active web page has a vrdisplayactivate event handler, unregisterDaydreamIntent();
// mListeningForWebVrActivate should be set to true, which means a vrdisplayactive event
// should be fired once DON flow finished. However, DON flow will pause our activity, which // When the active web page has a vrdisplayactivate event handler,
// makes the active page becomes invisible. And the event fires before the active page // mListeningForWebVrActivate should be set to true, which means a vrdisplayactive event
// becomes visible again after DON finished. So here we remember the value of // should be fired once DON flow finished. However, DON flow will pause our activity,
// mListeningForWebVrActivity before pause and use this value to decide if vrdisplayactivate // which makes the active page becomes invisible. And the event fires before the active
// event should be dispatched in enterVRFromIntent. // page becomes visible again after DON finished. So here we remember the value of
mListeningForWebVrActivateBeforePause = mListeningForWebVrActivate; // mListeningForWebVrActivity before pause and use this value to decide if
// vrdisplayactivate event should be dispatched in enterVRFromIntent.
mListeningForWebVrActivateBeforePause = mListeningForWebVrActivate;
}
if (mNonPresentingGvrContext != null) { if (mNonPresentingGvrContext != null) {
mNonPresentingGvrContext.pause(); mNonPresentingGvrContext.pause();
} }
...@@ -422,7 +445,9 @@ public class VrShellDelegate { ...@@ -422,7 +445,9 @@ public class VrShellDelegate {
@CalledByNative @CalledByNative
private void setListeningForWebVrActivate(boolean listening) { private void setListeningForWebVrActivate(boolean listening) {
if (!mVrAvailable) return; // Non-Daydream devices may not have the concept of display activate. So disable
// mListeningForWebVrActivate for them.
if (!mVrAvailable || mCardboardSupportOnly) return;
mListeningForWebVrActivate = listening; mListeningForWebVrActivate = listening;
if (listening) { if (listening) {
registerDaydreamIntent(); registerDaydreamIntent();
...@@ -548,10 +573,13 @@ public class VrShellDelegate { ...@@ -548,10 +573,13 @@ public class VrShellDelegate {
* @return Whether or not VR Shell is currently enabled. * @return Whether or not VR Shell is currently enabled.
*/ */
public boolean isVrShellEnabled() { public boolean isVrShellEnabled() {
// Disable VR Shell for Cardboard only (non-Daydream) devices.
// TODO(amp|bshe): Investigate if removing LibraryLoader.isInitialized from the check is
// possible.
if (!mVrAvailable || mCardboardSupportOnly || !LibraryLoader.isInitialized()) {
return false;
}
if (mVrShellEnabled == null) { if (mVrShellEnabled == null) {
if (!LibraryLoader.isInitialized()) {
return false;
}
mVrShellEnabled = ChromeFeatureList.isEnabled(ChromeFeatureList.VR_SHELL); mVrShellEnabled = ChromeFeatureList.isEnabled(ChromeFeatureList.VR_SHELL);
} }
return mVrShellEnabled; return mVrShellEnabled;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment