Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2310)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShell.java

Issue 2252103002: Introduce ChromeVR to Chrome on Android (behind a build flag) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShell.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShell.java b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShell.java
new file mode 100644
index 0000000000000000000000000000000000000000..16ff6c4517cd3dd53533d0f07d6ee85f3cb1f479
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShell.java
@@ -0,0 +1,137 @@
+// 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.graphics.SurfaceTexture;
+import android.graphics.SurfaceTexture.OnFrameAvailableListener;
+import android.opengl.GLSurfaceView;
+import android.view.MotionEvent;
+
+import com.google.vr.ndk.base.AndroidCompat;
+import com.google.vr.ndk.base.GvrLayout;
+
+import org.chromium.base.annotations.JNINamespace;
+import org.chromium.chrome.browser.ChromeVrActivity;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+/**
+ * This view extends from GvrLayout which wraps a GLSurfaceView that renders VR shell.
+ */
+@JNINamespace("vr_shell")
+public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, OnFrameAvailableListener {
+ private Activity mActivity;
+
+ private GLSurfaceView mGlSurfaceView;
+
+ private SurfaceTexture mSurfaceTexture;
+
+ private boolean mFirstTextureUpdate = true;
+ private long mNativeVrShell = 0;
+
+ public VrShell(Activity activity) {
+ super(activity);
+ mActivity = activity;
+ }
+
+ public void onNativeLibraryReady() {
+ mNativeVrShell = nativeInit();
+ mGlSurfaceView = new GLSurfaceView(getContext());
+ mGlSurfaceView.setEGLContextClientVersion(2);
+ mGlSurfaceView.setEGLConfigChooser(8, 8, 8, 0, 0, 0);
+ mGlSurfaceView.setPreserveEGLContextOnPause(true);
+ mGlSurfaceView.setRenderer(this);
+ setPresentationView(mGlSurfaceView);
+
+ if (setAsyncReprojectionEnabled(true)) {
+ AndroidCompat.setSustainedPerformanceMode(mActivity, true);
+ }
+ }
+
+ @Override
+ public void onFrameAvailable(SurfaceTexture surfaceTexture) {
+ mGlSurfaceView.queueEvent(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ if (!mFirstTextureUpdate) {
+ mSurfaceTexture.releaseTexImage();
+ }
+ mSurfaceTexture.updateTexImage();
+ mFirstTextureUpdate = false;
+ } catch (IllegalStateException e) {
+ mFirstTextureUpdate = true;
+ }
+ }
+ });
+ }
+
+ @Override
+ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ if (mNativeVrShell == 0) return;
+ int textureDataHandle = TextureHelper.createExternalTextureHandle();
+ mSurfaceTexture = new SurfaceTexture(textureDataHandle);
piman 2016/08/18 21:51:14 IIUC, createExternalTextureHandle generates a new
bshe 2016/08/19 16:48:09 This is created on the GL context in the rendering
no sievers 2016/08/22 22:55:02 The call to release() will cause all the gralloc b
+ mSurfaceTexture.setOnFrameAvailableListener(this);
+ if (mActivity instanceof ChromeVrActivity) {
+ ((ChromeVrActivity) mActivity).replaceCompositorSurface(mSurfaceTexture);
+ }
+ nativeGvrInit(mNativeVrShell, getGvrApi().getNativeGvrContext());
+ nativeInitializeGl(mNativeVrShell, textureDataHandle);
+ }
+
+ @Override
+ public void onSurfaceChanged(GL10 gl, int width, int height) {}
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ return false;
+ }
+
+ @Override
+ public void onDrawFrame(GL10 gl) {
+ nativeDrawFrame(mNativeVrShell);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ if (mNativeVrShell != 0) {
+ nativeOnResume(mNativeVrShell);
+ }
+ AndroidCompat.setVrModeEnabled(mActivity, true);
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ if (mNativeVrShell != 0) {
+ nativeOnPause(mNativeVrShell);
+ }
+ }
+
+ @Override
+ public void shutdown() {
+ super.shutdown();
+ if (mNativeVrShell != 0) {
+ nativeDestroy(mNativeVrShell);
+ }
+ }
+
+ private native long nativeInit();
+
+ private native void nativeGvrInit(long nativeVrShell, long nativeGvrApi);
+
+ private native void nativeDestroy(long nativeVrShell);
+
+ private native void nativeInitializeGl(long nativeVrShell, int textureDataHandle);
+
+ private native void nativeDrawFrame(long nativeVrShell);
+
+ private native void nativeOnPause(long nativeVrShell);
+
+ private native void nativeOnResume(long nativeVrShell);
+}

Powered by Google App Engine
This is Rietveld 408576698