| Index: chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellImpl.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellImpl.java
|
| index bb3e4a154ac16b35e4cdbae267117ff0b311a779..fd9f92d92a09236d1920ad4b9be7c1eba0d5b03b 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellImpl.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellImpl.java
|
| @@ -29,6 +29,7 @@ import com.google.vr.ndk.base.GvrLayout;
|
|
|
| import org.chromium.base.CommandLine;
|
| import org.chromium.base.ThreadUtils;
|
| +import org.chromium.base.annotations.CalledByNative;
|
| import org.chromium.base.annotations.JNINamespace;
|
| import org.chromium.base.annotations.UsedByReflection;
|
| import org.chromium.chrome.browser.ChromeSwitches;
|
| @@ -66,7 +67,8 @@ public class VrShellImpl extends GvrLayout implements GLSurfaceView.Renderer, Vr
|
| private FrameListener mContentFrameListener;
|
| private FrameListener mUiFrameListener;
|
|
|
| - private FrameLayout mContentViewCoreContainer;
|
| + private FrameLayout mContentCVCContainer;
|
| + private FrameLayout mUiCVCContainer;
|
|
|
| // The tab that holds the main ContentViewCore.
|
| private Tab mTab;
|
| @@ -88,19 +90,31 @@ public class VrShellImpl extends GvrLayout implements GLSurfaceView.Renderer, Vr
|
| private ContentViewCore mUiCVC;
|
| private VrWindowAndroid mUiVrWindowAndroid;
|
|
|
| + private boolean mSurfacesInitialized;
|
| + private int mContentSurfaceWidth = -1;
|
| + private int mContentSurfaceHeight = -1;
|
| + private int mUiSurfaceWidth = -1;
|
| + private int mUiSurfaceHeight = -1;
|
| +
|
| @UsedByReflection("VrShellDelegate.java")
|
| public VrShellImpl(Activity activity) {
|
| super(activity);
|
| mActivity = activity;
|
| - mContentViewCoreContainer = new FrameLayout(getContext()) {
|
| + mContentCVCContainer = new FrameLayout(getContext()) {
|
| @Override
|
| public boolean dispatchTouchEvent(MotionEvent event) {
|
| return true;
|
| }
|
| };
|
| - addView(mContentViewCoreContainer, 0, new FrameLayout.LayoutParams(
|
| - FrameLayout.LayoutParams.MATCH_PARENT,
|
| - FrameLayout.LayoutParams.MATCH_PARENT));
|
| + mUiCVCContainer = new FrameLayout(getContext()) {
|
| + @Override
|
| + public boolean dispatchTouchEvent(MotionEvent event) {
|
| + return true;
|
| + }
|
| + };
|
| + addView(mContentCVCContainer, 0, new FrameLayout.LayoutParams(0, 0));
|
| + addView(mUiCVCContainer, 0, new FrameLayout.LayoutParams(0, 0));
|
| +
|
| mGlSurfaceView = new GLSurfaceView(getContext());
|
| mGlSurfaceView.setEGLContextClientVersion(2);
|
| mGlSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 0, 0);
|
| @@ -145,7 +159,7 @@ public class VrShellImpl extends GvrLayout implements GLSurfaceView.Renderer, Vr
|
|
|
| uiContentView.setVisibility(View.VISIBLE);
|
| mUiCVC.onShow();
|
| - mContentViewCoreContainer.addView(uiContentView, new FrameLayout.LayoutParams(
|
| + mUiCVCContainer.addView(uiContentView, new FrameLayout.LayoutParams(
|
| FrameLayout.LayoutParams.MATCH_PARENT,
|
| FrameLayout.LayoutParams.MATCH_PARENT));
|
| mUiCVC.setBottomControlsHeight(0);
|
| @@ -172,7 +186,7 @@ public class VrShellImpl extends GvrLayout implements GLSurfaceView.Renderer, Vr
|
| mOriginalLayoutParams = contentContentView.getLayoutParams();
|
| mOriginalContentViewParent.removeView(contentContentView);
|
|
|
| - mContentViewCoreContainer.addView(contentContentView, new FrameLayout.LayoutParams(
|
| + mContentCVCContainer.addView(contentContentView, new FrameLayout.LayoutParams(
|
| FrameLayout.LayoutParams.MATCH_PARENT,
|
| FrameLayout.LayoutParams.MATCH_PARENT));
|
| }
|
| @@ -181,11 +195,61 @@ public class VrShellImpl extends GvrLayout implements GLSurfaceView.Renderer, Vr
|
| ViewGroup contentContentView = mContentCVC.getContainerView();
|
| mTab.updateWindowAndroid(null);
|
| mTab.updateWindowAndroid(mOriginalWindowAndroid);
|
| - mContentViewCoreContainer.removeView(contentContentView);
|
| + mContentCVCContainer.removeView(contentContentView);
|
| mOriginalContentViewParent.addView(contentContentView, mOriginalContentViewIndex,
|
| mOriginalLayoutParams);
|
| }
|
|
|
| + private final Runnable mUpdateContentBufferSize = new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + if (mSurfacesInitialized) {
|
| + mContentFrameListener.mSurfaceTexture.setDefaultBufferSize(
|
| + mContentSurfaceWidth, mContentSurfaceHeight);
|
| + }
|
| + }
|
| + };
|
| +
|
| + private final Runnable mUpdateUiBufferSize = new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + if (mSurfacesInitialized) {
|
| + mUiFrameListener.mSurfaceTexture.setDefaultBufferSize(
|
| + mUiSurfaceWidth, mUiSurfaceHeight);
|
| + }
|
| + }
|
| + };
|
| +
|
| + @CalledByNative
|
| + public void setUiCssSize(float width, float height, float dpr) {
|
| + ThreadUtils.assertOnUiThread();
|
| + float scale = mUiCVC.getDeviceScaleFactor();
|
| + mUiCVCContainer.setLayoutParams(new FrameLayout.LayoutParams(
|
| + (int) Math.ceil(width * scale), (int) Math.ceil(height * scale)));
|
| + mUiSurfaceWidth = (int) Math.ceil(width * dpr);
|
| + mUiSurfaceHeight = (int) Math.ceil(height * dpr);
|
| +
|
| + mGlSurfaceView.post(mUpdateUiBufferSize);
|
| +
|
| + mUiCVC.onPhysicalBackingSizeChanged(mUiSurfaceWidth, mUiSurfaceHeight);
|
| + nativeUIBoundsChanged(mNativeVrShell, mUiSurfaceWidth, mUiSurfaceHeight);
|
| + }
|
| +
|
| + @CalledByNative
|
| + public void setContentCssSize(float width, float height, float dpr) {
|
| + ThreadUtils.assertOnUiThread();
|
| + float scale = mContentCVC.getDeviceScaleFactor();
|
| + mContentCVCContainer.setLayoutParams(new FrameLayout.LayoutParams(
|
| + (int) Math.ceil(width * scale), (int) Math.ceil(height * scale)));
|
| + mContentSurfaceWidth = (int) Math.ceil(width * dpr);
|
| + mContentSurfaceHeight = (int) Math.ceil(height * dpr);
|
| +
|
| + mGlSurfaceView.post(mUpdateContentBufferSize);
|
| +
|
| + mContentCVC.onPhysicalBackingSizeChanged(mContentSurfaceWidth, mContentSurfaceHeight);
|
| + nativeContentBoundsChanged(mNativeVrShell, mContentSurfaceWidth, mContentSurfaceHeight);
|
| + }
|
| +
|
| private static class FrameListener implements OnFrameAvailableListener {
|
| final SurfaceTexture mSurfaceTexture;
|
| final GLSurfaceView mGlSurfaceView;
|
| @@ -216,26 +280,28 @@ public class VrShellImpl extends GvrLayout implements GLSurfaceView.Renderer, Vr
|
|
|
| @Override
|
| public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
| - final int width = mContentCVC.getContainerView().getWidth();
|
| - final int height = mContentCVC.getContainerView().getHeight();
|
| mContentTextureHandle = createExternalTextureHandle();
|
| mUiTextureHandle = createExternalTextureHandle();
|
|
|
| mContentFrameListener = new FrameListener(mContentTextureHandle, mGlSurfaceView);
|
| mUiFrameListener = new FrameListener(mUiTextureHandle, mGlSurfaceView);
|
|
|
| - mContentFrameListener.mSurfaceTexture.setDefaultBufferSize(width, height);
|
| - mUiFrameListener.mSurfaceTexture.setDefaultBufferSize(width, height);
|
| + if (mContentSurfaceWidth != -1) {
|
| + mContentFrameListener.mSurfaceTexture.setDefaultBufferSize(
|
| + mContentSurfaceWidth, mContentSurfaceHeight);
|
| + }
|
| + if (mUiSurfaceWidth != -1) {
|
| + mUiFrameListener.mSurfaceTexture.setDefaultBufferSize(
|
| + mUiSurfaceWidth, mUiSurfaceHeight);
|
| + }
|
| + mSurfacesInitialized = true;
|
|
|
| ThreadUtils.postOnUiThread(new Runnable() {
|
| @Override
|
| public void run() {
|
| - nativeContentSurfaceChanged(mNativeVrShell, width, height,
|
| - new Surface(mContentFrameListener.mSurfaceTexture));
|
| - mContentCVC.onPhysicalBackingSizeChanged(width, height);
|
| - nativeUiSurfaceChanged(mNativeVrShell, width, height,
|
| + nativeSurfacesChanged(mNativeVrShell,
|
| + new Surface(mContentFrameListener.mSurfaceTexture),
|
| new Surface(mUiFrameListener.mSurfaceTexture));
|
| - mUiCVC.onPhysicalBackingSizeChanged(width, height);
|
| }
|
| });
|
|
|
| @@ -373,10 +439,10 @@ public class VrShellImpl extends GvrLayout implements GLSurfaceView.Renderer, Vr
|
| private native void nativeOnTriggerEvent(long nativeVrShell);
|
| private native void nativeOnPause(long nativeVrShell);
|
| private native void nativeOnResume(long nativeVrShell);
|
| - private native void nativeContentSurfaceChanged(
|
| - long nativeVrShell, int width, int height, Surface surface);
|
| - private native void nativeUiSurfaceChanged(
|
| - long nativeVrShell, int width, int height, Surface surface);
|
| + private native void nativeSurfacesChanged(
|
| + long nativeVrShell, Surface contentSurface, Surface uiSurface);
|
| + private native void nativeContentBoundsChanged(long nativeVrShell, int width, int height);
|
| + private native void nativeUIBoundsChanged(long nativeVrShell, int width, int height);
|
| private native void nativeUpdateCompositorLayers(long nativeVrShell);
|
| private native void nativeSetWebVrMode(long nativeVrShell, boolean enabled);
|
| }
|
|
|