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 e479484bc0a87756a3ab30a730e332fc0fce5651..a89aad8233a8cacf7020d9559eb80fdb080a10ea 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 |
@@ -9,6 +9,9 @@ import android.app.Activity; |
import android.graphics.Point; |
import android.os.StrictMode; |
import android.view.MotionEvent; |
+import android.view.Surface; |
+import android.view.SurfaceHolder; |
+import android.view.SurfaceView; |
import android.view.View; |
import android.widget.FrameLayout; |
@@ -37,7 +40,7 @@ import org.chromium.ui.display.VirtualDisplayAndroid; |
* This view extends from GvrLayout which wraps a GLSurfaceView that renders VR shell. |
*/ |
@JNINamespace("vr_shell") |
-public class VrShellImpl extends GvrLayout implements VrShell { |
+public class VrShellImpl extends GvrLayout implements VrShell, SurfaceHolder.Callback { |
private static final String TAG = "VrShellImpl"; |
// TODO(mthiesse): These values work well for Pixel/Pixel XL in VR, but we need to come up with |
@@ -63,7 +66,7 @@ public class VrShellImpl extends GvrLayout implements VrShell { |
private long mNativeVrShell; |
private FrameLayout mUiCVCContainer; |
- private FrameLayout mPresentationView; |
+ private View mPresentationView; |
// The tab that holds the main ContentViewCore. |
private Tab mTab; |
@@ -77,6 +80,8 @@ public class VrShellImpl extends GvrLayout implements VrShell { |
private ContentViewCore mUiCVC; |
private VrWindowAndroid mUiVrWindowAndroid; |
+ private boolean mReprojectedRendering; |
+ |
public VrShellImpl(Activity activity) { |
super(activity); |
mActivity = activity; |
@@ -88,12 +93,23 @@ public class VrShellImpl extends GvrLayout implements VrShell { |
}; |
addView(mUiCVCContainer, 0, new FrameLayout.LayoutParams(0, 0)); |
- mPresentationView = new FrameLayout(mActivity); |
- setPresentationView(mPresentationView); |
+ mReprojectedRendering = setAsyncReprojectionEnabled(true); |
+ if (mReprojectedRendering) { |
+ // No need render to a Surface if we're reprojected. We'll be rendering with surfaceless |
+ // EGL. |
+ mPresentationView = new FrameLayout(mActivity); |
- if (setAsyncReprojectionEnabled(true)) { |
+ // Only enable sustained performance mode when Async reprojection decouples the app |
+ // framerate from the display framerate. |
AndroidCompat.setSustainedPerformanceMode(mActivity, true); |
+ } else { |
+ SurfaceView surfaceView = new SurfaceView(mActivity); |
+ surfaceView.getHolder().addCallback(this); |
+ mPresentationView = surfaceView; |
} |
+ |
+ setPresentationView(mPresentationView); |
+ |
DisplayAndroid primaryDisplay = DisplayAndroid.getNonMultiDisplay(activity); |
mContentVirtualDisplay = VirtualDisplayAndroid.createVirtualDisplay(); |
mContentVirtualDisplay.setTo(primaryDisplay); |
@@ -118,7 +134,7 @@ public class VrShellImpl extends GvrLayout implements VrShell { |
mNativeVrShell = nativeInit(mContentCVC.getWebContents(), |
mContentVrWindowAndroid.getNativePointer(), mUiContents, |
mUiVrWindowAndroid.getNativePointer(), forWebVR, delegate, |
- getGvrApi().getNativeGvrContext()); |
+ getGvrApi().getNativeGvrContext(), mReprojectedRendering); |
// Set the UI and content sizes before we load the UI. |
setUiCssSize(DEFAULT_UI_WIDTH, DEFAULT_UI_HEIGHT, DEFAULT_DPR); |
@@ -277,9 +293,23 @@ public class VrShellImpl extends GvrLayout implements VrShell { |
getUiLayout().setCloseButtonListener(runner); |
} |
+ @Override |
+ public void surfaceCreated(SurfaceHolder holder) { |
+ nativeSetSurface(mNativeVrShell, holder.getSurface()); |
+ } |
+ |
+ @Override |
+ public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
bshe
2017/01/04 16:40:23
can you add comment on why we dont need to do anyt
mthiesse
2017/01/04 16:58:09
Done.
|
+ } |
+ |
+ @Override |
+ public void surfaceDestroyed(SurfaceHolder holder) { |
+ } |
+ |
private native long nativeInit(WebContents contentWebContents, |
long nativeContentWindowAndroid, WebContents uiWebContents, long nativeUiWindowAndroid, |
- boolean forWebVR, VrShellDelegate delegate, long gvrApi); |
+ boolean forWebVR, VrShellDelegate delegate, long gvrApi, boolean reprojectedRendering); |
+ private native void nativeSetSurface(long nativeVrShell, Surface surface); |
private native void nativeLoadUIContent(long nativeVrShell); |
private native void nativeDestroy(long nativeVrShell); |
private native void nativeOnTriggerEvent(long nativeVrShell); |