Index: chrome/android/java/src/org/chromium/chrome/browser/vr_shell/NonPresentingGvrContext.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/NonPresentingGvrContext.java b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/NonPresentingGvrContext.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fb0fcb760ca4350eda2e088c167cebd3235e93a5 |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/NonPresentingGvrContext.java |
@@ -0,0 +1,53 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.chrome.browser.vr_shell; |
+ |
+import android.app.Activity; |
+import android.os.StrictMode; |
+ |
+import com.google.vr.ndk.base.GvrLayout; |
+ |
+import org.chromium.base.Log; |
+import org.chromium.base.annotations.UsedByReflection; |
+ |
+/** |
+ * Creates an active GvrContext from a detached GvrLayout. This is used by magic window mode. |
+ */ |
+@UsedByReflection("VrShellDelegate.java") |
+public class NonPresentingGvrContext implements NonPresentingGvrContextInterface { |
+ private static final String TAG = "NPGvrContext"; |
+ private GvrLayout mGvrLayout; |
+ |
+ @UsedByReflection("VrShellDelegate.java") |
+ public NonPresentingGvrContext(Activity activity) { |
+ mGvrLayout = new GvrLayout(activity); |
+ } |
+ |
+ public long getNativeGvrContext() { |
+ long nativeGvrContext = 0; |
+ StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
+ try { |
+ nativeGvrContext = mGvrLayout.getGvrApi().getNativeGvrContext(); |
+ } catch (Exception ex) { |
+ Log.e(TAG, "Unable to instantiate GvrApi", ex); |
+ return 0; |
+ } finally { |
+ StrictMode.setThreadPolicy(oldPolicy); |
+ } |
+ return nativeGvrContext; |
+ } |
+ |
+ public void resume() { |
+ mGvrLayout.onResume(); |
+ } |
+ |
+ public void pause() { |
+ mGvrLayout.onPause(); |
+ } |
+ |
+ public void shutdown() { |
+ mGvrLayout.shutdown(); |
+ } |
+} |