Chromium Code Reviews| 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 64475a87c6e7eabff5f52614996abaf14026e1de..cd96ec0836106dc57eae37b43607afed3c7e2bba 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 |
| @@ -18,12 +18,21 @@ import android.opengl.GLES11Ext; |
| import android.opengl.GLSurfaceView; |
| import android.os.StrictMode; |
| import android.view.MotionEvent; |
| +import android.view.Surface; |
| +import android.view.View; |
| +import android.view.ViewGroup; |
| import android.widget.FrameLayout; |
| import com.google.vr.ndk.base.AndroidCompat; |
| import com.google.vr.ndk.base.GvrLayout; |
| +import org.chromium.base.ThreadUtils; |
| import org.chromium.base.annotations.JNINamespace; |
| +import org.chromium.chrome.browser.ChromeTabbedActivity; |
| +import org.chromium.content.browser.ContentViewCore; |
| +import org.chromium.content_public.browser.WebContents; |
| +import org.chromium.ui.base.VRWindowAndroid; |
| +import org.chromium.ui.base.WindowAndroid; |
| import javax.microedition.khronos.egl.EGLConfig; |
| import javax.microedition.khronos.opengles.GL10; |
| @@ -37,7 +46,7 @@ public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, VrShel |
| public static final String VR_EXTRA = com.google.vr.sdk.base.Constants.EXTRA_VR_LAUNCH; |
| - private Activity mActivity; |
| + private ChromeTabbedActivity mActivity; |
| private final GLSurfaceView mGlSurfaceView; |
| @@ -46,9 +55,17 @@ public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, VrShel |
| private int mContentTextureHandle; |
| private FrameListener mContentFrameListener; |
| + private ContentViewCore mContentContentViewCore; |
|
bshe
2016/09/12 16:39:56
It is a little bit uncommon to have two Content in
mthiesse
2016/09/12 21:46:04
To distinguish it from the ui ContentViewCore that
|
| + // This is the parent of the @ContentView for mContentContentViewCore. |
| + private ViewGroup mContentContentViewParent; |
| + private VRWindowAndroid mContentWindowAndroid; |
|
bshe
2016/09/12 16:39:56
mVrWindowAndroid to match the class name?
mthiesse
2016/09/12 21:46:04
Done.
|
| + private WindowAndroid mOldContentWindowAndroid; |
| + |
| public VrShell(Activity activity) { |
| super(activity); |
| - mActivity = activity; |
| + assert activity instanceof ChromeTabbedActivity; |
| + mActivity = (ChromeTabbedActivity) activity; |
| + mActivity.setClankUIVisibilityForVR(View.GONE); |
| mGlSurfaceView = new GLSurfaceView(getContext()); |
| mGlSurfaceView.setEGLContextClientVersion(2); |
| mGlSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 0, 0); |
| @@ -62,8 +79,38 @@ public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, VrShel |
| } |
| @Override |
| - public void onNativeLibraryReady() { |
| - mNativeVrShell = nativeInit(); |
| + public void onNativeLibraryReady(ContentViewCore contentCVC) { |
| + mContentContentViewCore = contentCVC; |
| + mContentContentViewCore.disableInput(); |
| + mContentWindowAndroid = new VRWindowAndroid(mActivity); |
|
bshe
2016/09/12 16:39:56
I suspect that there are some unexpected behaviors
mthiesse
2016/09/12 21:46:03
I'm not sure what purpose creating a bug would ser
|
| + |
| + mNativeVrShell = nativeInit(mContentContentViewCore.getWebContents(), |
| + mContentWindowAndroid.getNativePointer()); |
| + |
| + mOldContentWindowAndroid = mContentContentViewCore.getWindowAndroid(); |
| + mContentContentViewCore.updateWindowAndroid(mContentWindowAndroid); |
| + |
| + ViewGroup contentContentView = mContentContentViewCore.getContainerView(); |
| + mContentContentViewParent = ((ViewGroup) contentContentView.getParent()); |
| + mContentContentViewParent.removeView(contentContentView); |
| + |
| + FrameLayout content = (FrameLayout) mActivity.findViewById(android.R.id.content); |
| + content.addView(contentContentView, new FrameLayout.LayoutParams( |
| + FrameLayout.LayoutParams.MATCH_PARENT, |
| + FrameLayout.LayoutParams.MATCH_PARENT)); |
| + |
| + nativeUpdateCompositorLayers(mNativeVrShell); |
| + } |
| + |
| + private void restoreContentWindow() { |
| + ViewGroup contentContentView = mContentContentViewCore.getContainerView(); |
| + mContentContentViewCore.updateWindowAndroid(mOldContentWindowAndroid); |
| + ((ViewGroup) contentContentView.getParent()).removeView(contentContentView); |
| + mContentContentViewParent.addView(contentContentView, new FrameLayout.LayoutParams( |
| + FrameLayout.LayoutParams.MATCH_PARENT, |
| + FrameLayout.LayoutParams.MATCH_PARENT)); |
| + mActivity.setClankUIVisibilityForVR(View.VISIBLE); |
| + mContentContentViewCore.enableInput(); |
| } |
| private static class FrameListener implements OnFrameAvailableListener { |
| @@ -96,9 +143,21 @@ public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, VrShel |
| @Override |
| public void onSurfaceCreated(GL10 gl, EGLConfig config) { |
| + final int width = mContentContentViewCore.getContainerView().getWidth(); |
| + final int height = mContentContentViewCore.getContainerView().getHeight(); |
| mContentTextureHandle = createExternalTextureHandle(); |
| mContentFrameListener = new FrameListener(new SurfaceTexture(mContentTextureHandle), |
| mGlSurfaceView); |
| + mContentFrameListener.mSurfaceTexture.setDefaultBufferSize(width, height); |
| + |
| + ThreadUtils.postOnUiThread(new Runnable() { |
| + @Override |
| + public void run() { |
| + nativeContentSurfaceChanged(mNativeVrShell, width, height, |
| + new Surface(mContentFrameListener.mSurfaceTexture)); |
| + mContentContentViewCore.onPhysicalBackingSizeChanged(width, height); |
| + } |
| + }); |
| nativeGvrInit(mNativeVrShell, getGvrApi().getNativeGvrContext()); |
| nativeInitializeGl(mNativeVrShell, mContentTextureHandle); |
| @@ -148,6 +207,7 @@ public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, VrShel |
| if (mContentFrameListener != null && mContentFrameListener.mSurfaceTexture != null) { |
| mContentFrameListener.mSurfaceTexture.release(); |
| } |
| + restoreContentWindow(); |
| } |
| @Override |
| @@ -197,7 +257,8 @@ public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, VrShel |
| } |
| } |
| - private native long nativeInit(); |
| + private native long nativeInit(WebContents contentWebContents, |
| + long nativeContentWindowAndroid); |
| private native void nativeGvrInit(long nativeVrShell, long nativeGvrApi); |
| @@ -211,4 +272,11 @@ public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, VrShel |
| private native void nativeOnPause(long nativeVrShell); |
| private native void nativeOnResume(long nativeVrShell); |
| + |
| + private native void nativeContentSurfaceDestroyed(long nativeVrShell); |
| + |
| + private native void nativeContentSurfaceChanged( |
| + long nativeVrShell, int width, int height, Surface surface); |
| + |
| + private native void nativeUpdateCompositorLayers(long nativeVrShell); |
| } |