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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellImpl.java

Issue 2428383006: Decouple VR Shell DPR and CSS size from Physical Displays. (Closed)
Patch Set: Address cjgrant's comments. Created 4 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.vr_shell; 5 package org.chromium.chrome.browser.vr_shell;
6 6
7 import static android.opengl.GLES20.GL_NEAREST; 7 import static android.opengl.GLES20.GL_NEAREST;
8 import static android.opengl.GLES20.GL_TEXTURE_MAG_FILTER; 8 import static android.opengl.GLES20.GL_TEXTURE_MAG_FILTER;
9 import static android.opengl.GLES20.GL_TEXTURE_MIN_FILTER; 9 import static android.opengl.GLES20.GL_TEXTURE_MIN_FILTER;
10 import static android.opengl.GLES20.glBindTexture; 10 import static android.opengl.GLES20.glBindTexture;
11 import static android.opengl.GLES20.glGenTextures; 11 import static android.opengl.GLES20.glGenTextures;
12 import static android.opengl.GLES20.glTexParameteri; 12 import static android.opengl.GLES20.glTexParameteri;
13 13
14 import android.annotation.SuppressLint; 14 import android.annotation.SuppressLint;
15 import android.app.Activity; 15 import android.app.Activity;
16 import android.graphics.Point;
16 import android.graphics.SurfaceTexture; 17 import android.graphics.SurfaceTexture;
17 import android.graphics.SurfaceTexture.OnFrameAvailableListener; 18 import android.graphics.SurfaceTexture.OnFrameAvailableListener;
18 import android.opengl.GLES11Ext; 19 import android.opengl.GLES11Ext;
19 import android.opengl.GLSurfaceView; 20 import android.opengl.GLSurfaceView;
20 import android.os.StrictMode; 21 import android.os.StrictMode;
21 import android.view.MotionEvent; 22 import android.view.MotionEvent;
22 import android.view.Surface; 23 import android.view.Surface;
23 import android.view.View; 24 import android.view.View;
24 import android.view.ViewGroup; 25 import android.view.ViewGroup;
25 import android.widget.FrameLayout; 26 import android.widget.FrameLayout;
26 27
27 import com.google.vr.ndk.base.AndroidCompat; 28 import com.google.vr.ndk.base.AndroidCompat;
28 import com.google.vr.ndk.base.GvrLayout; 29 import com.google.vr.ndk.base.GvrLayout;
29 30
30 import org.chromium.base.CommandLine; 31 import org.chromium.base.CommandLine;
31 import org.chromium.base.ThreadUtils; 32 import org.chromium.base.ThreadUtils;
33 import org.chromium.base.annotations.CalledByNative;
32 import org.chromium.base.annotations.JNINamespace; 34 import org.chromium.base.annotations.JNINamespace;
33 import org.chromium.chrome.browser.ChromeSwitches; 35 import org.chromium.chrome.browser.ChromeSwitches;
34 import org.chromium.chrome.browser.ChromeVersionInfo; 36 import org.chromium.chrome.browser.ChromeVersionInfo;
35 import org.chromium.chrome.browser.WebContentsFactory; 37 import org.chromium.chrome.browser.WebContentsFactory;
36 import org.chromium.chrome.browser.tab.Tab; 38 import org.chromium.chrome.browser.tab.Tab;
37 import org.chromium.chrome.browser.tab.TabContentViewParent; 39 import org.chromium.chrome.browser.tab.TabContentViewParent;
38 import org.chromium.content.browser.ContentView; 40 import org.chromium.content.browser.ContentView;
39 import org.chromium.content.browser.ContentViewCore; 41 import org.chromium.content.browser.ContentViewCore;
40 import org.chromium.content_public.browser.WebContents; 42 import org.chromium.content_public.browser.WebContents;
41 import org.chromium.ui.base.ViewAndroidDelegate; 43 import org.chromium.ui.base.ViewAndroidDelegate;
42 import org.chromium.ui.base.WindowAndroid; 44 import org.chromium.ui.base.WindowAndroid;
45 import org.chromium.ui.display.DisplayAndroid;
46 import org.chromium.ui.display.VirtualDisplayAndroid;
43 47
44 import javax.microedition.khronos.egl.EGLConfig; 48 import javax.microedition.khronos.egl.EGLConfig;
45 import javax.microedition.khronos.opengles.GL10; 49 import javax.microedition.khronos.opengles.GL10;
46 50
47 /** 51 /**
48 * This view extends from GvrLayout which wraps a GLSurfaceView that renders VR shell. 52 * This view extends from GvrLayout which wraps a GLSurfaceView that renders VR shell.
49 */ 53 */
50 @JNINamespace("vr_shell") 54 @JNINamespace("vr_shell")
51 public class VrShellImpl extends GvrLayout implements GLSurfaceView.Renderer, Vr Shell { 55 public class VrShellImpl extends GvrLayout implements GLSurfaceView.Renderer, Vr Shell {
52 private static final String TAG = "VrShellImpl"; 56 private static final String TAG = "VrShellImpl";
53 57
54 private Activity mActivity; 58 // TODO(mthiesse): These values work well for Pixel/Pixel XL in VR, but we n eed to come up with
59 // a way to compute good values for any screen size/scaling ratio.
60
61 // Increasing DPR any more than this doesn't appear to increase text quality .
62 private static final float DEFAULT_DPR = 1.2f;
63 // Fairly arbitrary values that put a good amount of content on the screen w ithout making the
64 // text too small to read.
65 private static final float DEFAULT_CONTENT_WIDTH = 1024f;
66 private static final float DEFAULT_CONTENT_HEIGHT = 576f;
67 // Temporary values that will be changed when the UI loads and figures out h ow what size it
68 // needs to be.
69 private static final float DEFAULT_UI_WIDTH = 1920f;
70 private static final float DEFAULT_UI_HEIGHT = 1080f;
55 71
56 private final GLSurfaceView mGlSurfaceView; 72 private final GLSurfaceView mGlSurfaceView;
73 private final Activity mActivity;
74 private final VirtualDisplayAndroid mContentVirtualDisplay;
75 private final VirtualDisplayAndroid mUiVirtualDisplay;
57 76
58 private long mNativeVrShell = 0; 77 private long mNativeVrShell = 0;
59 78
60 private int mContentTextureHandle; 79 private int mContentTextureHandle;
61 private int mUiTextureHandle; 80 private int mUiTextureHandle;
62 private FrameListener mContentFrameListener; 81 private FrameListener mContentFrameListener;
63 private FrameListener mUiFrameListener; 82 private FrameListener mUiFrameListener;
64 83
65 private FrameLayout mContentViewCoreContainer; 84 private FrameLayout mContentCVCContainer;
85 private FrameLayout mUiCVCContainer;
66 86
67 // The tab that holds the main ContentViewCore. 87 // The tab that holds the main ContentViewCore.
68 private Tab mTab; 88 private Tab mTab;
69 89
70 // The ContentViewCore for the main content rect in VR. 90 // The ContentViewCore for the main content rect in VR.
71 private ContentViewCore mContentCVC; 91 private ContentViewCore mContentCVC;
72 private TabContentViewParent mTabParent; 92 private TabContentViewParent mTabParent;
73 private ViewGroup mTabParentParent; 93 private ViewGroup mTabParentParent;
74 94
75 // TODO(mthiesse): Instead of caching these values, make tab reparenting wor k for this case. 95 // TODO(mthiesse): Instead of caching these values, make tab reparenting wor k for this case.
76 private int mOriginalTabParentIndex; 96 private int mOriginalTabParentIndex;
77 private ViewGroup.LayoutParams mOriginalLayoutParams; 97 private ViewGroup.LayoutParams mOriginalLayoutParams;
78 private WindowAndroid mOriginalWindowAndroid; 98 private WindowAndroid mOriginalWindowAndroid;
79 99
80 private VrWindowAndroid mContentVrWindowAndroid; 100 private VrWindowAndroid mContentVrWindowAndroid;
81 101
82 private WebContents mUiContents; 102 private WebContents mUiContents;
83 private ContentViewCore mUiCVC; 103 private ContentViewCore mUiCVC;
84 private VrWindowAndroid mUiVrWindowAndroid; 104 private VrWindowAndroid mUiVrWindowAndroid;
85 105
106 private boolean mSurfacesInitialized;
107 private int mContentSurfaceWidth = -1;
108 private int mContentSurfaceHeight = -1;
109 private int mUiSurfaceWidth = -1;
110 private int mUiSurfaceHeight = -1;
111
86 public VrShellImpl(Activity activity) { 112 public VrShellImpl(Activity activity) {
87 super(activity); 113 super(activity);
88 mActivity = activity; 114 mActivity = activity;
89 mContentViewCoreContainer = new FrameLayout(getContext()) { 115 mContentCVCContainer = new FrameLayout(getContext()) {
90 @Override 116 @Override
91 public boolean dispatchTouchEvent(MotionEvent event) { 117 public boolean dispatchTouchEvent(MotionEvent event) {
92 return true; 118 return true;
93 } 119 }
94 }; 120 };
95 addView(mContentViewCoreContainer, 0, new FrameLayout.LayoutParams( 121 mUiCVCContainer = new FrameLayout(getContext()) {
96 FrameLayout.LayoutParams.MATCH_PARENT, 122 @Override
97 FrameLayout.LayoutParams.MATCH_PARENT)); 123 public boolean dispatchTouchEvent(MotionEvent event) {
124 return true;
125 }
126 };
127 addView(mContentCVCContainer, 0, new FrameLayout.LayoutParams(0, 0));
128 addView(mUiCVCContainer, 0, new FrameLayout.LayoutParams(0, 0));
129
98 mGlSurfaceView = new GLSurfaceView(getContext()); 130 mGlSurfaceView = new GLSurfaceView(getContext());
99 mGlSurfaceView.setEGLContextClientVersion(2); 131 mGlSurfaceView.setEGLContextClientVersion(2);
100 mGlSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 0, 0); 132 mGlSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 0, 0);
101 mGlSurfaceView.setPreserveEGLContextOnPause(true); 133 mGlSurfaceView.setPreserveEGLContextOnPause(true);
102 mGlSurfaceView.setRenderer(this); 134 mGlSurfaceView.setRenderer(this);
103 setPresentationView(mGlSurfaceView); 135 setPresentationView(mGlSurfaceView);
104 136
105 if (setAsyncReprojectionEnabled(true)) { 137 if (setAsyncReprojectionEnabled(true)) {
106 AndroidCompat.setSustainedPerformanceMode(mActivity, true); 138 AndroidCompat.setSustainedPerformanceMode(mActivity, true);
107 } 139 }
140 DisplayAndroid primaryDisplay = DisplayAndroid.getNonMultiDisplay(activi ty);
141 mContentVirtualDisplay = VirtualDisplayAndroid.createVirtualDisplay();
142 mContentVirtualDisplay.setTo(primaryDisplay);
143 mUiVirtualDisplay = VirtualDisplayAndroid.createVirtualDisplay();
144 mUiVirtualDisplay.setTo(primaryDisplay);
108 } 145 }
109 146
110 @Override 147 @Override
111 public void initializeNative(Tab currentTab, VrShellDelegate delegate, boole an forWebVR) { 148 public void initializeNative(Tab currentTab, VrShellDelegate delegate, boole an forWebVR) {
112 assert currentTab.getContentViewCore() != null; 149 assert currentTab.getContentViewCore() != null;
113 mTab = currentTab; 150 mTab = currentTab;
114 mContentCVC = mTab.getContentViewCore(); 151 mContentCVC = mTab.getContentViewCore();
115 mContentVrWindowAndroid = new VrWindowAndroid(mActivity); 152 mContentVrWindowAndroid = new VrWindowAndroid(mActivity, mContentVirtual Display);
116 153
117 mUiVrWindowAndroid = new VrWindowAndroid(mActivity); 154 mUiVrWindowAndroid = new VrWindowAndroid(mActivity, mUiVirtualDisplay);
118 mUiContents = WebContentsFactory.createWebContents(true, false); 155 mUiContents = WebContentsFactory.createWebContents(true, false);
119 mUiCVC = new ContentViewCore(mActivity, ChromeVersionInfo.getProductVers ion()); 156 mUiCVC = new ContentViewCore(mActivity, ChromeVersionInfo.getProductVers ion());
120 ContentView uiContentView = ContentView.createContentView(mActivity, mUi CVC); 157 ContentView uiContentView = ContentView.createContentView(mActivity, mUi CVC);
121 mUiCVC.initialize(ViewAndroidDelegate.createBasicDelegate(uiContentView) , 158 mUiCVC.initialize(ViewAndroidDelegate.createBasicDelegate(uiContentView) ,
122 uiContentView, mUiContents, mUiVrWindowAndroid); 159 uiContentView, mUiContents, mUiVrWindowAndroid);
123 160
161 // Set the UI and content sizes before we initialize VR Shell and load t he UI.
162 setUiCssSize(DEFAULT_UI_WIDTH, DEFAULT_UI_HEIGHT, DEFAULT_DPR);
bshe 2016/11/30 23:00:46 can line 161 -172 moved after we create mNativeVrS
mthiesse 2016/11/30 23:25:05 If you'd like I can split up initialization into m
163 float dpr;
164 if (forWebVR) {
165 DisplayAndroid primaryDisplay = DisplayAndroid.getNonMultiDisplay(mA ctivity);
166 dpr = 1f;
bshe 2016/11/30 23:00:46 nit: avoid magic number
mthiesse 2016/11/30 23:25:05 Done.
167 setContentCssSize(primaryDisplay.getPhysicalDisplayWidth(),
168 primaryDisplay.getPhysicalDisplayHeight(), dpr);
169 } else {
170 dpr = DEFAULT_DPR;
171 setContentCssSize(DEFAULT_CONTENT_WIDTH, DEFAULT_CONTENT_HEIGHT, dpr );
172 }
173
124 mNativeVrShell = nativeInit(mContentCVC.getWebContents(), 174 mNativeVrShell = nativeInit(mContentCVC.getWebContents(),
125 mContentVrWindowAndroid.getNativePointer(), mUiContents, 175 mContentVrWindowAndroid.getNativePointer(), mUiContents,
126 mUiVrWindowAndroid.getNativePointer(), forWebVR); 176 mUiVrWindowAndroid.getNativePointer(), forWebVR);
177
178 // Set the initial Content and UI bounds, as they won't have been propag ated yet.
179 nativeContentBoundsChanged(mNativeVrShell, mContentSurfaceWidth, mConten tSurfaceHeight,
180 dpr);
181 nativeUIBoundsChanged(mNativeVrShell, mUiSurfaceWidth, mUiSurfaceHeight, 1f);
bshe 2016/11/30 23:00:46 ditto
mthiesse 2016/11/30 23:25:05 Good catch, that was a typo.
182
127 mGlSurfaceView.setOnTouchListener(new View.OnTouchListener() { 183 mGlSurfaceView.setOnTouchListener(new View.OnTouchListener() {
128 @Override 184 @Override
129 @SuppressLint("ClickableViewAccessibility") 185 @SuppressLint("ClickableViewAccessibility")
130 public boolean onTouch(View v, MotionEvent event) { 186 public boolean onTouch(View v, MotionEvent event) {
131 if (!CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_V R_SHELL_DEV) 187 if (!CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_V R_SHELL_DEV)
132 && event.getActionMasked() == MotionEvent.ACTION_DOWN) { 188 && event.getActionMasked() == MotionEvent.ACTION_DOWN) {
133 nativeOnTriggerEvent(mNativeVrShell); 189 nativeOnTriggerEvent(mNativeVrShell);
134 return true; 190 return true;
135 } 191 }
136 return false; 192 return false;
137 } 193 }
138 }); 194 });
139 195
140 uiContentView.setVisibility(View.VISIBLE); 196 uiContentView.setVisibility(View.VISIBLE);
141 mUiCVC.onShow(); 197 mUiCVC.onShow();
142 mContentViewCoreContainer.addView(uiContentView, new FrameLayout.LayoutP arams( 198 mUiCVCContainer.addView(uiContentView, new FrameLayout.LayoutParams(
143 FrameLayout.LayoutParams.MATCH_PARENT, 199 FrameLayout.LayoutParams.MATCH_PARENT,
144 FrameLayout.LayoutParams.MATCH_PARENT)); 200 FrameLayout.LayoutParams.MATCH_PARENT));
145 mUiCVC.setBottomControlsHeight(0); 201 mUiCVC.setBottomControlsHeight(0);
146 mUiCVC.setTopControlsHeight(0, false); 202 mUiCVC.setTopControlsHeight(0, false);
147 mUiVrWindowAndroid.onVisibilityChanged(true); 203 mUiVrWindowAndroid.onVisibilityChanged(true);
148 204
149 nativeSetDelegate(mNativeVrShell, delegate); 205 nativeSetDelegate(mNativeVrShell, delegate);
150 206
151 reparentContentWindow(); 207 reparentContentWindow();
152 208
153 nativeUpdateCompositorLayers(mNativeVrShell); 209 nativeUpdateCompositorLayers(mNativeVrShell);
154 } 210 }
155 211
156 private void reparentContentWindow() { 212 private void reparentContentWindow() {
157 mOriginalWindowAndroid = mContentCVC.getWindowAndroid(); 213 mOriginalWindowAndroid = mContentCVC.getWindowAndroid();
158 214
159 mTab.updateWindowAndroid(mContentVrWindowAndroid); 215 mTab.updateWindowAndroid(mContentVrWindowAndroid);
160 216
161 mTabParent = mTab.getView(); 217 mTabParent = mTab.getView();
162 mTabParentParent = (ViewGroup) mTabParent.getParent(); 218 mTabParentParent = (ViewGroup) mTabParent.getParent();
163 mOriginalTabParentIndex = mTabParentParent.indexOfChild(mTabParent); 219 mOriginalTabParentIndex = mTabParentParent.indexOfChild(mTabParent);
164 mOriginalLayoutParams = mTabParent.getLayoutParams(); 220 mOriginalLayoutParams = mTabParent.getLayoutParams();
165 mTabParentParent.removeView(mTabParent); 221 mTabParentParent.removeView(mTabParent);
166 222
167 mContentViewCoreContainer.addView(mTabParent, new FrameLayout.LayoutPara ms( 223 mContentCVCContainer.addView(mTabParent, new FrameLayout.LayoutParams(
168 FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams. MATCH_PARENT)); 224 FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams. MATCH_PARENT));
169 } 225 }
170 226
171 private void restoreContentWindow() { 227 private void restoreContentWindow() {
172 mTab.updateWindowAndroid(mOriginalWindowAndroid); 228 mTab.updateWindowAndroid(mOriginalWindowAndroid);
173 229
174 // If the tab's view has changed, the necessary view reparenting has alr eady been done. 230 // If the tab's view has changed, the necessary view reparenting has alr eady been done.
175 if (mTab.getView() == mTabParent) { 231 if (mTab.getView() == mTabParent) {
176 mContentViewCoreContainer.removeView(mTabParent); 232 mContentCVCContainer.removeView(mTabParent);
177 mTabParentParent.addView(mTabParent, mOriginalTabParentIndex, mOrigi nalLayoutParams); 233 mTabParentParent.addView(mTabParent, mOriginalTabParentIndex, mOrigi nalLayoutParams);
178 mTabParent.requestFocus(); 234 mTabParent.requestFocus();
179 } 235 }
180 mTabParent = null; 236 mTabParent = null;
181 } 237 }
182 238
239 private final Runnable mUpdateContentBufferSize = new Runnable() {
240 @Override
241 public void run() {
242 if (mSurfacesInitialized) {
243 mContentFrameListener.mSurfaceTexture.setDefaultBufferSize(
244 mContentSurfaceWidth, mContentSurfaceHeight);
245 }
246 }
247 };
248
249 private final Runnable mUpdateUiBufferSize = new Runnable() {
250 @Override
251 public void run() {
252 if (mSurfacesInitialized) {
253 mUiFrameListener.mSurfaceTexture.setDefaultBufferSize(
254 mUiSurfaceWidth, mUiSurfaceHeight);
255 }
256 }
257 };
258
259 @CalledByNative
260 public void setUiCssSize(float width, float height, float dpr) {
261 ThreadUtils.assertOnUiThread();
262 mUiSurfaceWidth = (int) Math.ceil(width * dpr);
263 mUiSurfaceHeight = (int) Math.ceil(height * dpr);
264
265 Point size = new Point(mUiSurfaceWidth, mUiSurfaceHeight);
266 mUiVirtualDisplay.update(size, size, dpr, null, null, null);
267
268 mGlSurfaceView.post(mUpdateUiBufferSize);
269 mUiCVCContainer.setLayoutParams(new FrameLayout.LayoutParams(
270 mUiSurfaceWidth, mUiSurfaceHeight));
271 mUiCVC.onPhysicalBackingSizeChanged(mUiSurfaceWidth, mUiSurfaceHeight);
272 if (mNativeVrShell == 0) return;
273 nativeUIBoundsChanged(mNativeVrShell, mUiSurfaceWidth, mUiSurfaceHeight, dpr);
274 }
275
276 @CalledByNative
277 public void setContentCssSize(float width, float height, float dpr) {
278 ThreadUtils.assertOnUiThread();
279 mContentSurfaceWidth = (int) Math.ceil(width * dpr);
280 mContentSurfaceHeight = (int) Math.ceil(height * dpr);
281
282 Point size = new Point(mContentSurfaceWidth, mContentSurfaceHeight);
283 mContentVirtualDisplay.update(size, size, dpr, null, null, null);
284
285 mGlSurfaceView.post(mUpdateContentBufferSize);
286 mContentCVCContainer.setLayoutParams(new FrameLayout.LayoutParams(
287 mContentSurfaceWidth, mContentSurfaceHeight));
288 mContentCVC.onPhysicalBackingSizeChanged(mContentSurfaceWidth, mContentS urfaceHeight);
289 if (mNativeVrShell == 0) return;
290 nativeContentBoundsChanged(mNativeVrShell, mContentSurfaceWidth, mConten tSurfaceHeight,
291 dpr);
292 }
293
183 private static class FrameListener implements OnFrameAvailableListener { 294 private static class FrameListener implements OnFrameAvailableListener {
184 final SurfaceTexture mSurfaceTexture; 295 final SurfaceTexture mSurfaceTexture;
185 final GLSurfaceView mGlSurfaceView; 296 final GLSurfaceView mGlSurfaceView;
186 boolean mFirstTex = true; 297 boolean mFirstTex = true;
187 298
188 final Runnable mUpdateTexImage = new Runnable() { 299 final Runnable mUpdateTexImage = new Runnable() {
189 @Override 300 @Override
190 public void run() { 301 public void run() {
191 try { 302 try {
192 mSurfaceTexture.updateTexImage(); 303 mSurfaceTexture.updateTexImage();
(...skipping 10 matching lines...) Expand all
203 314
204 @Override 315 @Override
205 public void onFrameAvailable(SurfaceTexture surfaceTexture) { 316 public void onFrameAvailable(SurfaceTexture surfaceTexture) {
206 mFirstTex = false; 317 mFirstTex = false;
207 mGlSurfaceView.queueEvent(mUpdateTexImage); 318 mGlSurfaceView.queueEvent(mUpdateTexImage);
208 } 319 }
209 } 320 }
210 321
211 @Override 322 @Override
212 public void onSurfaceCreated(GL10 gl, EGLConfig config) { 323 public void onSurfaceCreated(GL10 gl, EGLConfig config) {
213 final int width = mContentCVC.getContainerView().getWidth();
214 final int height = mContentCVC.getContainerView().getHeight();
215 mContentTextureHandle = createExternalTextureHandle(); 324 mContentTextureHandle = createExternalTextureHandle();
216 mUiTextureHandle = createExternalTextureHandle(); 325 mUiTextureHandle = createExternalTextureHandle();
217 326
218 mContentFrameListener = new FrameListener(mContentTextureHandle, mGlSurf aceView); 327 mContentFrameListener = new FrameListener(mContentTextureHandle, mGlSurf aceView);
219 mUiFrameListener = new FrameListener(mUiTextureHandle, mGlSurfaceView); 328 mUiFrameListener = new FrameListener(mUiTextureHandle, mGlSurfaceView);
220 329
221 mContentFrameListener.mSurfaceTexture.setDefaultBufferSize(width, height ); 330 if (mContentSurfaceWidth != -1) {
222 mUiFrameListener.mSurfaceTexture.setDefaultBufferSize(width, height); 331 mContentFrameListener.mSurfaceTexture.setDefaultBufferSize(
332 mContentSurfaceWidth, mContentSurfaceHeight);
333 }
334 if (mUiSurfaceWidth != -1) {
335 mUiFrameListener.mSurfaceTexture.setDefaultBufferSize(
336 mUiSurfaceWidth, mUiSurfaceHeight);
337 }
338 mSurfacesInitialized = true;
223 339
224 ThreadUtils.postOnUiThread(new Runnable() { 340 ThreadUtils.postOnUiThread(new Runnable() {
225 @Override 341 @Override
226 public void run() { 342 public void run() {
227 nativeContentSurfaceChanged(mNativeVrShell, width, height, 343 nativeSurfacesChanged(mNativeVrShell,
228 new Surface(mContentFrameListener.mSurfaceTexture)); 344 new Surface(mContentFrameListener.mSurfaceTexture),
229 mContentCVC.onPhysicalBackingSizeChanged(width, height);
230 nativeUiSurfaceChanged(mNativeVrShell, width, height,
231 new Surface(mUiFrameListener.mSurfaceTexture)); 345 new Surface(mUiFrameListener.mSurfaceTexture));
232 mUiCVC.onPhysicalBackingSizeChanged(width, height);
233 } 346 }
234 }); 347 });
235 348
236 nativeGvrInit(mNativeVrShell, getGvrApi().getNativeGvrContext()); 349 nativeGvrInit(mNativeVrShell, getGvrApi().getNativeGvrContext());
237 nativeInitializeGl(mNativeVrShell, mContentTextureHandle, mUiTextureHand le); 350 nativeInitializeGl(mNativeVrShell, mContentTextureHandle, mUiTextureHand le);
238 } 351 }
239 352
240 @Override 353 @Override
241 public void onSurfaceChanged(GL10 gl, int width, int height) {} 354 public void onSurfaceChanged(GL10 gl, int width, int height) {}
242 355
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 mNativeVrShell = 0; 418 mNativeVrShell = 0;
306 } 419 }
307 if (mContentFrameListener != null && mContentFrameListener.mSurfaceTextu re != null) { 420 if (mContentFrameListener != null && mContentFrameListener.mSurfaceTextu re != null) {
308 mContentFrameListener.mSurfaceTexture.release(); 421 mContentFrameListener.mSurfaceTexture.release();
309 } 422 }
310 if (mUiFrameListener != null && mUiFrameListener.mSurfaceTexture != null ) { 423 if (mUiFrameListener != null && mUiFrameListener.mSurfaceTexture != null ) {
311 mUiFrameListener.mSurfaceTexture.release(); 424 mUiFrameListener.mSurfaceTexture.release();
312 } 425 }
313 restoreContentWindow(); 426 restoreContentWindow();
314 mUiContents.destroy(); 427 mUiContents.destroy();
428 mContentVirtualDisplay.destroy();
429 mUiVirtualDisplay.destroy();
315 } 430 }
316 431
317 @Override 432 @Override
318 public void pause() { 433 public void pause() {
319 onPause(); 434 onPause();
320 } 435 }
321 436
322 @Override 437 @Override
323 public void resume() { 438 public void resume() {
324 onResume(); 439 onResume();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 WebContents uiWebContents, long nativeUiWindowAndroid, boolean forWe bVR); 480 WebContents uiWebContents, long nativeUiWindowAndroid, boolean forWe bVR);
366 private native void nativeSetDelegate(long nativeVrShell, VrShellDelegate de legate); 481 private native void nativeSetDelegate(long nativeVrShell, VrShellDelegate de legate);
367 private native void nativeGvrInit(long nativeVrShell, long nativeGvrApi); 482 private native void nativeGvrInit(long nativeVrShell, long nativeGvrApi);
368 private native void nativeDestroy(long nativeVrShell); 483 private native void nativeDestroy(long nativeVrShell);
369 private native void nativeInitializeGl( 484 private native void nativeInitializeGl(
370 long nativeVrShell, int contentTextureHandle, int uiTextureHandle); 485 long nativeVrShell, int contentTextureHandle, int uiTextureHandle);
371 private native void nativeDrawFrame(long nativeVrShell); 486 private native void nativeDrawFrame(long nativeVrShell);
372 private native void nativeOnTriggerEvent(long nativeVrShell); 487 private native void nativeOnTriggerEvent(long nativeVrShell);
373 private native void nativeOnPause(long nativeVrShell); 488 private native void nativeOnPause(long nativeVrShell);
374 private native void nativeOnResume(long nativeVrShell); 489 private native void nativeOnResume(long nativeVrShell);
375 private native void nativeContentSurfaceChanged( 490 private native void nativeSurfacesChanged(
376 long nativeVrShell, int width, int height, Surface surface); 491 long nativeVrShell, Surface contentSurface, Surface uiSurface);
377 private native void nativeUiSurfaceChanged( 492 private native void nativeContentBoundsChanged(long nativeVrShell, int width , int height,
378 long nativeVrShell, int width, int height, Surface surface); 493 float dpr);
494 private native void nativeUIBoundsChanged(long nativeVrShell, int width, int height, float dpr);
379 private native void nativeUpdateCompositorLayers(long nativeVrShell); 495 private native void nativeUpdateCompositorLayers(long nativeVrShell);
380 private native void nativeSetWebVrMode(long nativeVrShell, boolean enabled); 496 private native void nativeSetWebVrMode(long nativeVrShell, boolean enabled);
381 } 497 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698