Commit ba4f0e6b authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Disable VR on standalone headsets

Currently we've got some bugs that can lead to crashes on standalone
VR headsets (https://vr.google.com/daydream/standalonevr/), so we
should detect devices that boot into VR, and disable VR there.

This will make sure we just use the fallback 2D-in-VR path that is
supposed to work for all apps :)

This also fixes a bug in scheduling rAF when presentation is rejected
that lead to the rAF loop doubling up every time presentation was
rejected.

Bug: 791090
Change-Id: I7511299935486dd018b558f3489ddd00f314ba8e
Reviewed-on: https://chromium-review.googlesource.com/809194
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarBrandon Jones <bajones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521879}
parent c6469d97
...@@ -63,4 +63,10 @@ public interface VrDaydreamApi { ...@@ -63,4 +63,10 @@ public interface VrDaydreamApi {
* Launch the stereoscopic, 3D VR launcher homescreen. * Launch the stereoscopic, 3D VR launcher homescreen.
*/ */
boolean launchVrHomescreen(); boolean launchVrHomescreen();
/**
* @return Whether this device boots directly into VR mode. May be used to detect standalone VR
* devices.
*/
boolean bootsToVr();
} }
...@@ -14,8 +14,10 @@ import android.os.StrictMode; ...@@ -14,8 +14,10 @@ import android.os.StrictMode;
import com.google.vr.ndk.base.DaydreamApi; import com.google.vr.ndk.base.DaydreamApi;
import com.google.vr.ndk.base.GvrApi; import com.google.vr.ndk.base.GvrApi;
import org.chromium.base.Log;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
import java.lang.reflect.Method;
/** /**
* A wrapper for DaydreamApi. Note that we have to recreate the DaydreamApi instance each time we * A wrapper for DaydreamApi. Note that we have to recreate the DaydreamApi instance each time we
...@@ -24,6 +26,10 @@ import org.chromium.ui.base.WindowAndroid; ...@@ -24,6 +26,10 @@ import org.chromium.ui.base.WindowAndroid;
public class VrDaydreamApiImpl implements VrDaydreamApi { public class VrDaydreamApiImpl implements VrDaydreamApi {
private final Context mContext; private final Context mContext;
private Boolean mBootsToVr = null;
public static final String VR_BOOT_SYSTEM_PROPERTY = "ro.boot.vr";
public VrDaydreamApiImpl(Context context) { public VrDaydreamApiImpl(Context context) {
mContext = context; mContext = context;
} }
...@@ -112,4 +118,28 @@ public class VrDaydreamApiImpl implements VrDaydreamApi { ...@@ -112,4 +118,28 @@ public class VrDaydreamApiImpl implements VrDaydreamApi {
daydreamApi.close(); daydreamApi.close();
return true; return true;
} }
@Override
public boolean bootsToVr() {
if (mBootsToVr == null) {
// TODO(mthiesse): Replace this with a Daydream API call when supported.
// Note that System.GetProperty is unable to read system ro properties, so we have to
// resort to reflection as seen below. This method of reading system properties has been
// available since API level 1.
mBootsToVr = getIntSystemProperty(VR_BOOT_SYSTEM_PROPERTY, 0) == 1;
}
return mBootsToVr;
}
private int getIntSystemProperty(String key, int defaultValue) {
try {
final Class<?> systemProperties = Class.forName("android.os.SystemProperties");
final Method getInt = systemProperties.getMethod("getInt", String.class, int.class);
return (Integer) getInt.invoke(null, key, defaultValue);
} catch (Exception e) {
Log.e("Exception while getting system property %s. Using default %s.", key,
defaultValue, e);
return defaultValue;
}
}
} }
...@@ -318,7 +318,9 @@ public class VrShellDelegate ...@@ -318,7 +318,9 @@ public class VrShellDelegate
*/ */
public static int getVrSupportLevel(VrDaydreamApi daydreamApi, public static int getVrSupportLevel(VrDaydreamApi daydreamApi,
VrCoreVersionChecker versionChecker, Tab tabToShowInfobarIn) { VrCoreVersionChecker versionChecker, Tab tabToShowInfobarIn) {
if (versionChecker == null || daydreamApi == null // TODO(mthiesse, crbug.com/791090): Re-enable VR mode for devices that boot to VR once we
// support those devices.
if (versionChecker == null || daydreamApi == null || daydreamApi.bootsToVr()
|| !isVrCoreCompatible(versionChecker, tabToShowInfobarIn)) { || !isVrCoreCompatible(versionChecker, tabToShowInfobarIn)) {
return VR_NOT_AVAILABLE; return VR_NOT_AVAILABLE;
} }
......
...@@ -65,4 +65,9 @@ public class MockVrDaydreamApi implements VrDaydreamApi { ...@@ -65,4 +65,9 @@ public class MockVrDaydreamApi implements VrDaydreamApi {
public boolean getLaunchInVrCalled() { public boolean getLaunchInVrCalled() {
return mLaunchInVrCalled; return mLaunchInVrCalled;
} }
@Override
public boolean bootsToVr() {
return false;
}
} }
...@@ -1035,9 +1035,11 @@ void VRDisplay::OnMagicWindowPose(device::mojom::blink::VRPosePtr pose) { ...@@ -1035,9 +1035,11 @@ void VRDisplay::OnMagicWindowPose(device::mojom::blink::VRPosePtr pose) {
void VRDisplay::OnPresentationProviderConnectionError() { void VRDisplay::OnPresentationProviderConnectionError() {
vr_presentation_provider_.reset(); vr_presentation_provider_.reset();
ForceExitPresent(); if (is_presenting_) {
pending_vsync_ = false; ForceExitPresent();
RequestVSync(); pending_vsync_ = false;
RequestVSync();
}
} }
ScriptedAnimationController& VRDisplay::EnsureScriptedAnimationController( ScriptedAnimationController& VRDisplay::EnsureScriptedAnimationController(
......
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