OLD | NEW |
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; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 mGlSurfaceView.setPreserveEGLContextOnPause(true); | 96 mGlSurfaceView.setPreserveEGLContextOnPause(true); |
97 mGlSurfaceView.setRenderer(this); | 97 mGlSurfaceView.setRenderer(this); |
98 setPresentationView(mGlSurfaceView); | 98 setPresentationView(mGlSurfaceView); |
99 | 99 |
100 if (setAsyncReprojectionEnabled(true)) { | 100 if (setAsyncReprojectionEnabled(true)) { |
101 AndroidCompat.setSustainedPerformanceMode(mActivity, true); | 101 AndroidCompat.setSustainedPerformanceMode(mActivity, true); |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 @Override | 105 @Override |
106 public void onNativeLibraryReady(Tab currentTab) { | 106 public void initializeNative(Tab currentTab, VrShellDelegate delegate) { |
107 assert currentTab.getContentViewCore() != null; | 107 assert currentTab.getContentViewCore() != null; |
108 mTab = currentTab; | 108 mTab = currentTab; |
109 mCVC = mTab.getContentViewCore(); | 109 mCVC = mTab.getContentViewCore(); |
110 mVRWindowAndroid = new VrWindowAndroid(mActivity); | 110 mVRWindowAndroid = new VrWindowAndroid(mActivity); |
111 | 111 |
112 mNativeVrShell = nativeInit(mCVC.getWebContents(), | 112 mNativeVrShell = nativeInit(mCVC.getWebContents(), |
113 mVRWindowAndroid.getNativePointer()); | 113 mVRWindowAndroid.getNativePointer()); |
114 | 114 |
| 115 nativeSetDelegate(mNativeVrShell, delegate); |
| 116 |
115 reparentContentWindow(); | 117 reparentContentWindow(); |
116 | 118 |
117 nativeUpdateCompositorLayers(mNativeVrShell); | 119 nativeUpdateCompositorLayers(mNativeVrShell); |
118 } | 120 } |
119 | 121 |
120 private void reparentContentWindow() { | 122 private void reparentContentWindow() { |
121 mOriginalWindowAndroid = mCVC.getWindowAndroid(); | 123 mOriginalWindowAndroid = mCVC.getWindowAndroid(); |
122 | 124 |
123 // TODO(mthiesse): Update the WindowAndroid in ChromeActivity too? | 125 // TODO(mthiesse): Update the WindowAndroid in ChromeActivity too? |
124 mTab.updateWindowAndroid(null); | 126 mTab.updateWindowAndroid(null); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 public void teardown() { | 261 public void teardown() { |
260 shutdown(); | 262 shutdown(); |
261 } | 263 } |
262 | 264 |
263 @Override | 265 @Override |
264 public void setVrModeEnabled(boolean enabled) { | 266 public void setVrModeEnabled(boolean enabled) { |
265 AndroidCompat.setVrModeEnabled(mActivity, enabled); | 267 AndroidCompat.setVrModeEnabled(mActivity, enabled); |
266 } | 268 } |
267 | 269 |
268 @Override | 270 @Override |
| 271 public void setWebVrModeEnabled(boolean enabled) { |
| 272 nativeSetWebVrMode(mNativeVrShell, enabled); |
| 273 } |
| 274 |
| 275 @Override |
269 public boolean onTouchEvent(MotionEvent event) { | 276 public boolean onTouchEvent(MotionEvent event) { |
270 return true; | 277 return true; |
271 } | 278 } |
272 | 279 |
273 @Override | 280 @Override |
274 public FrameLayout getContainer() { | 281 public FrameLayout getContainer() { |
275 return (FrameLayout) this; | 282 return (FrameLayout) this; |
276 } | 283 } |
277 | 284 |
278 /** | 285 /** |
279 * Create a new GLES11Ext.GL_TEXTURE_EXTERNAL_OES texture handle. | 286 * Create a new GLES11Ext.GL_TEXTURE_EXTERNAL_OES texture handle. |
280 * @return New texture handle. | 287 * @return New texture handle. |
281 */ | 288 */ |
282 private int createExternalTextureHandle() { | 289 private int createExternalTextureHandle() { |
283 int[] textureDataHandle = new int[1]; | 290 int[] textureDataHandle = new int[1]; |
284 glGenTextures(1, textureDataHandle, 0); | 291 glGenTextures(1, textureDataHandle, 0); |
285 if (textureDataHandle[0] != 0) { | 292 if (textureDataHandle[0] != 0) { |
286 glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureDataHandle[0
]); | 293 glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureDataHandle[0
]); |
287 glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FI
LTER, GL_NEAREST); | 294 glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FI
LTER, GL_NEAREST); |
288 glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FI
LTER, GL_NEAREST); | 295 glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FI
LTER, GL_NEAREST); |
289 return textureDataHandle[0]; | 296 return textureDataHandle[0]; |
290 } else { | 297 } else { |
291 throw new RuntimeException("Error generating texture handle."); | 298 throw new RuntimeException("Error generating texture handle."); |
292 } | 299 } |
293 } | 300 } |
294 | 301 |
295 private native long nativeInit(WebContents contentWebContents, | 302 private native long nativeInit(WebContents contentWebContents, |
296 long nativeContentWindowAndroid); | 303 long nativeContentWindowAndroid); |
297 | 304 private native void nativeSetDelegate(long nativeVrShell, VrShellDelegate de
legate); |
298 private native void nativeGvrInit(long nativeVrShell, long nativeGvrApi); | 305 private native void nativeGvrInit(long nativeVrShell, long nativeGvrApi); |
299 | |
300 private native void nativeDestroy(long nativeVrShell); | 306 private native void nativeDestroy(long nativeVrShell); |
301 | |
302 private native void nativeInitializeGl( | 307 private native void nativeInitializeGl( |
303 long nativeVrShell, int contentDataHandle); | 308 long nativeVrShell, int contentDataHandle); |
304 | |
305 private native void nativeDrawFrame(long nativeVrShell); | 309 private native void nativeDrawFrame(long nativeVrShell); |
306 | |
307 private native void nativeOnPause(long nativeVrShell); | 310 private native void nativeOnPause(long nativeVrShell); |
308 | |
309 private native void nativeOnResume(long nativeVrShell); | 311 private native void nativeOnResume(long nativeVrShell); |
310 | |
311 private native void nativeContentSurfaceDestroyed(long nativeVrShell); | 312 private native void nativeContentSurfaceDestroyed(long nativeVrShell); |
312 | |
313 private native void nativeContentSurfaceChanged( | 313 private native void nativeContentSurfaceChanged( |
314 long nativeVrShell, int width, int height, Surface surface); | 314 long nativeVrShell, int width, int height, Surface surface); |
315 | |
316 private native void nativeUpdateCompositorLayers(long nativeVrShell); | 315 private native void nativeUpdateCompositorLayers(long nativeVrShell); |
| 316 private native void nativeSetWebVrMode(long nativeVrShell, boolean enabled); |
317 } | 317 } |
OLD | NEW |