Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java |
| index 85cef3a1bbad4e9c429007641fa42d1edd525125..2c4726b2e121a3d497e935206bba4971f3eea6ba 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java |
| @@ -32,10 +32,12 @@ public class VrShellDelegate { |
| private ChromeTabbedActivity mActivity; |
| - private boolean mVrShellEnabled; |
| + private boolean mVrEnabled; |
| private Class<? extends VrShellInterface> mVrShellClass; |
| + private Class<? extends NonPresentingGvrContextInterface> mNonPresentingGvrContextClass; |
| private VrShellInterface mVrShell; |
| + private NonPresentingGvrContextInterface mNonPresentingGvrContext; |
| private boolean mInVr; |
| private int mRestoreSystemUiVisibilityFlag = -1; |
| private String mVrExtra; |
| @@ -44,14 +46,13 @@ public class VrShellDelegate { |
| public VrShellDelegate(ChromeTabbedActivity activity) { |
| mActivity = activity; |
| - mVrShellClass = maybeFindVrShell(); |
| - if (mVrShellClass != null) { |
| - mVrShellEnabled = true; |
| + mVrEnabled = maybeFindVrClasses(); |
| + if (mVrEnabled) { |
| try { |
| mVrExtra = (String) mVrShellClass.getField("VR_EXTRA").get(null); |
| } catch (IllegalAccessException | IllegalArgumentException | NoSuchFieldException e) { |
| Log.e(TAG, "Unable to read VR_EXTRA field", e); |
| - mVrShellEnabled = false; |
| + mVrEnabled = false; |
| } |
| } |
| } |
| @@ -61,18 +62,24 @@ public class VrShellDelegate { |
| * class can be initialized. |
| */ |
| public void onNativeLibraryReady() { |
| - if (mVrShellEnabled) { |
| + if (mVrEnabled) { |
| mNativeVrShellDelegate = nativeInit(); |
| } |
| } |
| @SuppressWarnings("unchecked") |
| - private Class<? extends VrShellInterface> maybeFindVrShell() { |
| + private boolean maybeFindVrClasses() { |
| try { |
| - return (Class<? extends VrShellInterface>) Class |
| - .forName("org.chromium.chrome.browser.vr_shell.VrShell"); |
| + mVrShellClass = (Class<? extends VrShellInterface>) Class.forName( |
| + "org.chromium.chrome.browser.vr_shell.VrShell"); |
| + mNonPresentingGvrContextClass = |
| + (Class<? extends NonPresentingGvrContextInterface>) Class.forName( |
| + "org.chromium.chrome.browser.vr_shell.NonPresentingGvrContext"); |
| + return true; |
| } catch (ClassNotFoundException e) { |
| - return null; |
| + mVrShellClass = null; |
| + mNonPresentingGvrContextClass = null; |
| + return false; |
| } |
| } |
| @@ -86,7 +93,7 @@ public class VrShellDelegate { |
| */ |
| @CalledByNative |
| public boolean enterVRIfNecessary(boolean inWebVR) { |
| - if (!mVrShellEnabled || mNativeVrShellDelegate == 0) return false; |
| + if (!mVrEnabled || mNativeVrShellDelegate == 0) return false; |
| Tab tab = mActivity.getActivityTab(); |
| // TODO(mthiesse): When we have VR UI for opening new tabs, etc., allow VR Shell to be |
| // entered without any current tabs. |
| @@ -125,14 +132,27 @@ public class VrShellDelegate { |
| * Resumes VR Shell. |
| */ |
| public void resumeVR() { |
|
mthiesse
2016/10/11 18:10:44
nit: Rename to maybeResumeVR() and maybePauseVR()
bshe
2016/10/12 19:02:17
Done.
|
| - setupVrModeWindowFlags(); |
| - StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| - try { |
| - mVrShell.resume(); |
| - } catch (IllegalArgumentException e) { |
| - Log.e(TAG, "Unable to resume VrShell", e); |
| - } finally { |
| - StrictMode.setThreadPolicy(oldPolicy); |
| + if (mNonPresentingGvrContext != null) { |
|
mthiesse
2016/10/11 18:10:44
Is there a reason to have both a non-presenting GV
bshe
2016/10/12 19:02:17
I can't think of any reason. And we might want to
|
| + StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| + try { |
| + mNonPresentingGvrContext.resume(); |
| + } catch (IllegalArgumentException e) { |
| + Log.e(TAG, "Unable to resume mNonPresentingGvrContext", e); |
| + } finally { |
| + StrictMode.setThreadPolicy(oldPolicy); |
| + } |
| + } |
| + |
| + if (mInVr) { |
| + setupVrModeWindowFlags(); |
| + StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| + try { |
| + mVrShell.resume(); |
| + } catch (IllegalArgumentException e) { |
| + Log.e(TAG, "Unable to resume VrShell", e); |
| + } finally { |
| + StrictMode.setThreadPolicy(oldPolicy); |
| + } |
| } |
| } |
| @@ -140,7 +160,12 @@ public class VrShellDelegate { |
| * Pauses VR Shell. |
| */ |
| public void pauseVR() { |
| - mVrShell.pause(); |
| + if (mNonPresentingGvrContext != null) { |
| + mNonPresentingGvrContext.pause(); |
| + } |
| + if (mInVr) { |
| + mVrShell.pause(); |
| + } |
| } |
| /** |
| @@ -159,6 +184,30 @@ public class VrShellDelegate { |
| return true; |
| } |
| + @CalledByNative |
| + private long createNonPresentingNativeContext() { |
| + if (!mVrEnabled) return 0; |
| + |
| + try { |
| + Constructor<?> nonPresentingGvrContextConstructor = |
| + mNonPresentingGvrContextClass.getConstructor(Activity.class); |
| + mNonPresentingGvrContext = |
| + (NonPresentingGvrContextInterface) |
| + nonPresentingGvrContextConstructor.newInstance(mActivity); |
| + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException |
| + | InvocationTargetException | NoSuchMethodException e) { |
| + Log.e(TAG, "Unable to instantiate NonPresentingGvrContext", e); |
| + return 0; |
| + } |
| + return mNonPresentingGvrContext.getNativeGvrContext(); |
| + } |
| + |
| + @CalledByNative |
| + private void shutdownNonPresentingNativeContext() { |
| + mNonPresentingGvrContext.shutdown(); |
| + mNonPresentingGvrContext = null; |
| + } |
| + |
| /** |
| * Exits VR Shell, performing all necessary cleanup. |
| */ |
| @@ -256,7 +305,7 @@ public class VrShellDelegate { |
| * @return Whether or not VR Shell is currently enabled. |
| */ |
| public boolean isVrShellEnabled() { |
| - return mVrShellEnabled; |
| + return mVrEnabled; |
| } |
| /** |