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

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

Issue 2319863005: Implement new compositor and ContentViewCore reparenting for VR Shell. (Closed)
Patch Set: Created 4 years, 3 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
index 64475a87c6e7eabff5f52614996abaf14026e1de..1f505af07154d6713e90f28bf650b11f47cd1b41 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;
amp 2016/09/09 00:00:27 ContentContent is really confusing. It might just
mthiesse 2016/09/09 14:45:25 This is not so much a 'relic' as a differentiation
+ private ViewGroup mContentContentView;
+ private ViewGroup mOldContentContentView;
+ private VRWindowAndroid mContentWindowAndroid;
+ 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,36 @@ public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, VrShel
}
@Override
- public void onNativeLibraryReady() {
- mNativeVrShell = nativeInit();
+ public void onNativeLibraryReady(ContentViewCore contentCVC) {
+ mContentWindowAndroid = new VRWindowAndroid(mActivity);
+ mContentContentViewCore = contentCVC;
+
+ mNativeVrShell = nativeInit(mContentContentViewCore.getWebContents(),
+ mContentWindowAndroid.getNativePointer());
+
+ mOldContentWindowAndroid = mContentContentViewCore.getWindowAndroid();
+ mContentContentViewCore.updateWindowAndroid(mContentWindowAndroid);
+
+ mContentContentView = mContentContentViewCore.getContainerView();
+ mOldContentContentView = ((ViewGroup) mContentContentView.getParent());
+ mOldContentContentView.removeView(mContentContentView);
+ mContentContentViewCore.disableInput();
amp 2016/09/09 00:00:27 I'm not sure of the implications, but wouldn't you
mthiesse 2016/09/09 14:45:25 You're right that disabling/enabling input should
+ FrameLayout content = (FrameLayout) mActivity.findViewById(android.R.id.content);
+ content.addView(mContentContentView, new FrameLayout.LayoutParams(
+ FrameLayout.LayoutParams.MATCH_PARENT,
+ FrameLayout.LayoutParams.MATCH_PARENT));
+
+ nativeUpdateCompositorLayers(mNativeVrShell);
+ }
+
+ private void restoreContentWindow() {
+ mContentContentViewCore.enableInput();
+ mContentContentViewCore.updateWindowAndroid(mOldContentWindowAndroid);
+ ((ViewGroup) mContentContentView.getParent()).removeView(mContentContentView);
+ mOldContentContentView.addView(mContentContentView, new FrameLayout.LayoutParams(
+ FrameLayout.LayoutParams.MATCH_PARENT,
+ FrameLayout.LayoutParams.MATCH_PARENT));
+ mActivity.setClankUIVisibilityForVR(View.VISIBLE);
}
private static class FrameListener implements OnFrameAvailableListener {
@@ -96,9 +141,22 @@ public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, VrShel
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ final int width = mContentContentView.getWidth();
amp 2016/09/09 00:00:27 Is this width and height still tied to the physica
mthiesse 2016/09/09 14:45:25 This is tied to the physical dimensions, yes. This
+ final int height = mContentContentView.getHeight();
mContentTextureHandle = createExternalTextureHandle();
mContentFrameListener = new FrameListener(new SurfaceTexture(mContentTextureHandle),
mGlSurfaceView);
+ mContentFrameListener.mSurfaceTexture.setDefaultBufferSize(width, height);
+
+ ThreadUtils.postOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ nativeContentSurfaceCreated(mNativeVrShell);
+ nativeContentSurfaceChanged(mNativeVrShell, 4, width, height,
amp 2016/09/09 00:00:27 What's the '4' for? Can we get a variable name or
mthiesse 2016/09/09 14:45:25 I've deleted format, and SurfaceCreated altogether
+ new Surface(mContentFrameListener.mSurfaceTexture));
+ mContentContentViewCore.onPhysicalBackingSizeChanged(width, height);
+ }
+ });
nativeGvrInit(mNativeVrShell, getGvrApi().getNativeGvrContext());
nativeInitializeGl(mNativeVrShell, mContentTextureHandle);
@@ -148,6 +206,7 @@ public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, VrShel
if (mContentFrameListener != null && mContentFrameListener.mSurfaceTexture != null) {
mContentFrameListener.mSurfaceTexture.release();
}
+ restoreContentWindow();
}
@Override
@@ -197,7 +256,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 +271,13 @@ public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, VrShel
private native void nativeOnPause(long nativeVrShell);
private native void nativeOnResume(long nativeVrShell);
+
+ private native void nativeContentSurfaceCreated(long nativeVrShell);
+
+ private native void nativeContentSurfaceDestroyed(long nativeVrShell);
+
+ private native void nativeContentSurfaceChanged(
+ long nativeVrShell, int format, int width, int height, Surface surface);
+
+ private native void nativeUpdateCompositorLayers(long nativeVrShell);
}

Powered by Google App Engine
This is Rietveld 408576698