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

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: Address comments 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 dd6c4d6cd6b96b0c5a2c9f85cfd09e5d1a8d5069..8a949cce412dc5f54855a815c2e6fcd8ffec1745 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,19 @@ import android.opengl.GLES11Ext;
import android.opengl.GLSurfaceView;
import android.os.StrictMode;
import android.view.MotionEvent;
+import android.view.Surface;
+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.tab.Tab;
+import org.chromium.content.browser.ContentViewCore;
+import org.chromium.content_public.browser.WebContents;
+import org.chromium.ui.base.WindowAndroid;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
@@ -46,9 +53,21 @@ public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, VrShel
private int mContentTextureHandle;
private FrameListener mContentFrameListener;
- public VrShell(Activity activity) {
+ // The tab that holds the main ContentViewCore.
+ private Tab mContentTab;
+ // The ContentViewCore for the main content rect in VR.
+ private ContentViewCore mContentCVC;
+ // The parent of the @ContentView for mContentContentViewCore.
+ private ViewGroup mContentCVParent;
+ private VrWindowAndroid mContentVRWindowAndroid;
+ private WindowAndroid mOldContentWindowAndroid;
+
+ private ViewGroup mParent;
+
+ public VrShell(Activity activity, ViewGroup parent) {
super(activity);
mActivity = activity;
+ mParent = parent;
mGlSurfaceView = new GLSurfaceView(getContext());
mGlSurfaceView.setEGLContextClientVersion(2);
mGlSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 0, 0);
@@ -62,8 +81,44 @@ public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, VrShel
}
@Override
- public void onNativeLibraryReady() {
- mNativeVrShell = nativeInit();
+ public void onNativeLibraryReady(Tab currentTab) {
+ assert currentTab.getContentViewCore() != null;
+ mContentTab = currentTab;
+ mContentCVC = mContentTab.getContentViewCore();
+ mContentCVC.disableInput();
+ mContentVRWindowAndroid = new VrWindowAndroid(mActivity);
+
+ mNativeVrShell = nativeInit(mContentCVC.getWebContents(),
+ mContentVRWindowAndroid.getNativePointer());
+
+ reparentContentWindow();
+
+ nativeUpdateCompositorLayers(mNativeVrShell);
+ }
+
+ private void reparentContentWindow() {
+ mOldContentWindowAndroid = mContentCVC.getWindowAndroid();
+
+ // TODO(mthiesse): Update the WindowAndroid in ChromeActivity too?
+ mContentTab.updateWindowAndroid(mContentVRWindowAndroid);
+
+ ViewGroup contentContentView = mContentCVC.getContainerView();
+ mContentCVParent = ((ViewGroup) contentContentView.getParent());
+ mContentCVParent.removeView(contentContentView);
+
+ mParent.addView(contentContentView, new FrameLayout.LayoutParams(
+ FrameLayout.LayoutParams.MATCH_PARENT,
+ FrameLayout.LayoutParams.MATCH_PARENT));
+ }
+
+ private void restoreContentWindow() {
+ ViewGroup contentContentView = mContentCVC.getContainerView();
+ mContentTab.updateWindowAndroid(mOldContentWindowAndroid);
+ mParent.removeView(contentContentView);
+ mContentCVParent.addView(contentContentView, new FrameLayout.LayoutParams(
+ FrameLayout.LayoutParams.MATCH_PARENT,
+ FrameLayout.LayoutParams.MATCH_PARENT));
+ mContentCVC.enableInput();
}
private static class FrameListener implements OnFrameAvailableListener {
@@ -96,9 +151,21 @@ public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, VrShel
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ final int width = mContentCVC.getContainerView().getWidth();
+ final int height = mContentCVC.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));
+ mContentCVC.onPhysicalBackingSizeChanged(width, height);
+ }
+ });
nativeGvrInit(mNativeVrShell, getGvrApi().getNativeGvrContext());
nativeInitializeGl(mNativeVrShell, mContentTextureHandle);
@@ -152,6 +219,7 @@ public class VrShell extends GvrLayout implements GLSurfaceView.Renderer, VrShel
if (mContentFrameListener != null && mContentFrameListener.mSurfaceTexture != null) {
mContentFrameListener.mSurfaceTexture.release();
}
+ restoreContentWindow();
}
@Override
@@ -201,7 +269,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);
@@ -215,4 +284,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);
}

Powered by Google App Engine
This is Rietveld 408576698