| 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
|
| index 6c4b688ad4e7c7059a26103ccd6224bdfc41e3b2..c67bb0fff5624fb23ebd24181e88580afe9ebd42 100644
|
| --- 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
|
| @@ -30,25 +30,26 @@ 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 {
|
| +public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, VrShellInterface {
|
| + private static final String TAG = "cr.VrShell";
|
| +
|
| + public static final String VR_EXTRA = com.google.vr.sdk.base.Constants.EXTRA_VR_LAUNCH;
|
| +
|
| private Activity mActivity;
|
|
|
| private GLSurfaceView mGlSurfaceView;
|
|
|
| - private SurfaceTexture mSurfaceTexture;
|
| -
|
| private long mNativeVrShell = 0;
|
|
|
| + private int mContentTextureHandle;
|
| + private FrameListener mContentFrameListener;
|
| +
|
| 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.setEGLConfigChooser(8, 8, 8, 8, 0, 0);
|
| mGlSurfaceView.setPreserveEGLContextOnPause(true);
|
| mGlSurfaceView.setRenderer(this);
|
| setPresentationView(mGlSurfaceView);
|
| @@ -59,42 +60,52 @@ public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, OnFram
|
| }
|
|
|
| @Override
|
| - public void onFrameAvailable(SurfaceTexture surfaceTexture) {
|
| - mGlSurfaceView.queueEvent(new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - try {
|
| - mSurfaceTexture.updateTexImage();
|
| - } catch (IllegalStateException e) {
|
| + public void onNativeLibraryReady() {
|
| + mNativeVrShell = nativeInit();
|
| + }
|
| +
|
| + class FrameListener implements OnFrameAvailableListener {
|
| + SurfaceTexture mSurfaceTexture;
|
| + boolean mFirstTex = true;
|
| +
|
| + public FrameListener(SurfaceTexture texture) {
|
| + mSurfaceTexture = texture;
|
| + mSurfaceTexture.setOnFrameAvailableListener(this);
|
| + }
|
| +
|
| + @Override
|
| + public void onFrameAvailable(SurfaceTexture surfaceTexture) {
|
| + mFirstTex = false;
|
| + mGlSurfaceView.queueEvent(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + try {
|
| + mSurfaceTexture.updateTexImage();
|
| + } catch (IllegalStateException e) {
|
| + }
|
| }
|
| - }
|
| - });
|
| + });
|
| + }
|
| }
|
|
|
| @Override
|
| public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
| - // This handle doesn't get deleted anywhere because we create it in onSurfaceCreated() and
|
| - // rely on onSurfaceDestroyed() according to the GLSurfaceView documentation to delete the
|
| - // context and clean up resources.
|
| - int textureDataHandle = createExternalTextureHandle();
|
| - mSurfaceTexture = new SurfaceTexture(textureDataHandle);
|
| - mSurfaceTexture.setOnFrameAvailableListener(this);
|
| - // TODO(bshe): Use this SurfaceTexture to create a Surface and then pass the Surface to a
|
| - // compositor to get frames of web page.
|
| + mContentTextureHandle = createExternalTextureHandle();
|
| + mContentFrameListener = new FrameListener(new SurfaceTexture(mContentTextureHandle));
|
| +
|
| nativeGvrInit(mNativeVrShell, getGvrApi().getNativeGvrContext());
|
| - nativeInitializeGl(mNativeVrShell, textureDataHandle);
|
| + nativeInitializeGl(mNativeVrShell, mContentTextureHandle);
|
| }
|
|
|
| @Override
|
| public void onSurfaceChanged(GL10 gl, int width, int height) {}
|
|
|
| @Override
|
| - public boolean onTouchEvent(MotionEvent event) {
|
| - return false;
|
| - }
|
| -
|
| - @Override
|
| public void onDrawFrame(GL10 gl) {
|
| + if (mContentFrameListener.mFirstTex) {
|
| + mContentFrameListener.mSurfaceTexture.updateTexImage();
|
| + mContentFrameListener.mFirstTex = false;
|
| + }
|
| nativeDrawFrame(mNativeVrShell);
|
| }
|
|
|
| @@ -104,7 +115,6 @@ public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, OnFram
|
| if (mNativeVrShell != 0) {
|
| nativeOnResume(mNativeVrShell);
|
| }
|
| - AndroidCompat.setVrModeEnabled(mActivity, true);
|
| }
|
|
|
| @Override
|
| @@ -121,11 +131,37 @@ public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, OnFram
|
| if (mNativeVrShell != 0) {
|
| nativeDestroy(mNativeVrShell);
|
| }
|
| - if (mSurfaceTexture != null) {
|
| - mSurfaceTexture.release();
|
| + if (mContentFrameListener != null && mContentFrameListener.mSurfaceTexture != null) {
|
| + mContentFrameListener.mSurfaceTexture.release();
|
| }
|
| }
|
|
|
| + @Override
|
| + public void pause() {
|
| + onPause();
|
| + }
|
| +
|
| + @Override
|
| + public void resume() {
|
| + onResume();
|
| + }
|
| +
|
| + @Override
|
| + public void teardown() {
|
| + shutdown();
|
| + }
|
| +
|
| + @Override
|
| + public void setVrModeEnabled(boolean enabled) {
|
| + AndroidCompat.setVrModeEnabled(mActivity, enabled);
|
| + }
|
| +
|
| + @Override
|
| + public boolean onTouchEvent(MotionEvent event) {
|
| + return true;
|
| + }
|
| +
|
| +
|
| /**
|
| * Create a new GLES11Ext.GL_TEXTURE_EXTERNAL_OES texture handle.
|
| * @return New texture handle.
|
| @@ -149,7 +185,8 @@ public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, OnFram
|
|
|
| private native void nativeDestroy(long nativeVrShell);
|
|
|
| - private native void nativeInitializeGl(long nativeVrShell, int textureDataHandle);
|
| + private native void nativeInitializeGl(
|
| + long nativeVrShell, int contentDataHandle);
|
|
|
| private native void nativeDrawFrame(long nativeVrShell);
|
|
|
|
|