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

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

Powered by Google App Engine
This is Rietveld 408576698