| 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 android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.app.PendingIntent; | 8 import android.app.PendingIntent; |
| 9 import android.content.ComponentName; | 9 import android.content.ComponentName; |
| 10 import android.content.Context; |
| 10 import android.content.Intent; | 11 import android.content.Intent; |
| 11 import android.content.pm.ActivityInfo; | 12 import android.content.pm.ActivityInfo; |
| 12 import android.os.StrictMode; | 13 import android.os.StrictMode; |
| 13 import android.os.SystemClock; | 14 import android.os.SystemClock; |
| 14 import android.support.annotation.IntDef; | 15 import android.support.annotation.IntDef; |
| 16 import android.view.Choreographer; |
| 17 import android.view.Choreographer.FrameCallback; |
| 18 import android.view.Display; |
| 15 import android.view.View; | 19 import android.view.View; |
| 16 import android.view.ViewGroup; | 20 import android.view.ViewGroup; |
| 17 import android.view.ViewGroup.LayoutParams; | 21 import android.view.ViewGroup.LayoutParams; |
| 18 import android.view.WindowManager; | 22 import android.view.WindowManager; |
| 19 import android.widget.FrameLayout; | 23 import android.widget.FrameLayout; |
| 20 | 24 |
| 21 import org.chromium.base.Log; | 25 import org.chromium.base.Log; |
| 22 import org.chromium.base.annotations.CalledByNative; | 26 import org.chromium.base.annotations.CalledByNative; |
| 23 import org.chromium.base.annotations.JNINamespace; | 27 import org.chromium.base.annotations.JNINamespace; |
| 24 import org.chromium.base.library_loader.LibraryLoader; | 28 import org.chromium.base.library_loader.LibraryLoader; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 mVrSupportLevel = mVrDaydreamApi.isDaydreamReadyDevice() ? VR_DAYDREAM :
VR_CARDBOARD; | 151 mVrSupportLevel = mVrDaydreamApi.isDaydreamReadyDevice() ? VR_DAYDREAM :
VR_CARDBOARD; |
| 148 } | 152 } |
| 149 | 153 |
| 150 /** | 154 /** |
| 151 * Should be called once the native library is loaded so that the native por
tion of this | 155 * Should be called once the native library is loaded so that the native por
tion of this |
| 152 * class can be initialized. | 156 * class can be initialized. |
| 153 */ | 157 */ |
| 154 public void onNativeLibraryReady() { | 158 public void onNativeLibraryReady() { |
| 155 if (mVrSupportLevel == VR_NOT_AVAILABLE) return; | 159 if (mVrSupportLevel == VR_NOT_AVAILABLE) return; |
| 156 mNativeVrShellDelegate = nativeInit(); | 160 mNativeVrShellDelegate = nativeInit(); |
| 161 Choreographer choreographer = Choreographer.getInstance(); |
| 162 choreographer.postFrameCallback(new FrameCallback() { |
| 163 @Override |
| 164 public void doFrame(long frameTimeNanos) { |
| 165 Display display = ((WindowManager) mActivity.getSystemService( |
| 166 Context.WINDOW_SERVICE)).getDefaultDisplay(); |
| 167 nativeUpdateVSyncInterval(mNativeVrShellDelegate, frameTimeNanos
, |
| 168 1.0d / display.getRefreshRate()); |
| 169 } |
| 170 }); |
| 157 } | 171 } |
| 158 | 172 |
| 159 @SuppressWarnings("unchecked") | 173 @SuppressWarnings("unchecked") |
| 160 private VrClassesBuilder createVrClassesBuilder() { | 174 private VrClassesBuilder createVrClassesBuilder() { |
| 161 try { | 175 try { |
| 162 Class<? extends VrClassesBuilder> vrClassesBuilderClass = | 176 Class<? extends VrClassesBuilder> vrClassesBuilderClass = |
| 163 (Class<? extends VrClassesBuilder>) Class.forName( | 177 (Class<? extends VrClassesBuilder>) Class.forName( |
| 164 "org.chromium.chrome.browser.vr_shell.VrClassesBuild
erImpl"); | 178 "org.chromium.chrome.browser.vr_shell.VrClassesBuild
erImpl"); |
| 165 Constructor<?> vrClassesBuilderConstructor = | 179 Constructor<?> vrClassesBuilderConstructor = |
| 166 vrClassesBuilderClass.getConstructor(Activity.class); | 180 vrClassesBuilderClass.getConstructor(Activity.class); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 // If this is still set, it means the user backed out of the DON flow, a
nd we won't be | 357 // If this is still set, it means the user backed out of the DON flow, a
nd we won't be |
| 344 // receiving an intent from daydream. | 358 // receiving an intent from daydream. |
| 345 if (mRequestedWebVR) { | 359 if (mRequestedWebVR) { |
| 346 nativeSetPresentResult(mNativeVrShellDelegate, false); | 360 nativeSetPresentResult(mNativeVrShellDelegate, false); |
| 347 mRequestedWebVR = false; | 361 mRequestedWebVR = false; |
| 348 } | 362 } |
| 349 | 363 |
| 350 // TODO(bshe): Ideally, we do not need two gvr context exist at the same
time. We can | 364 // TODO(bshe): Ideally, we do not need two gvr context exist at the same
time. We can |
| 351 // probably shutdown non presenting gvr when presenting and create a new
one after exit | 365 // probably shutdown non presenting gvr when presenting and create a new
one after exit |
| 352 // presenting. See crbug.com/655242 | 366 // presenting. See crbug.com/655242 |
| 353 if (mNonPresentingGvrContext != null) { | 367 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 354 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites
(); | 368 try { |
| 355 try { | 369 nativeOnResume(mNativeVrShellDelegate); |
| 356 mNonPresentingGvrContext.resume(); | 370 } finally { |
| 357 } catch (IllegalArgumentException e) { | 371 StrictMode.setThreadPolicy(oldPolicy); |
| 358 Log.e(TAG, "Unable to resume mNonPresentingGvrContext", e); | |
| 359 } finally { | |
| 360 StrictMode.setThreadPolicy(oldPolicy); | |
| 361 } | |
| 362 } | 372 } |
| 363 | 373 |
| 364 if (mInVr) { | 374 if (mInVr) { |
| 365 setupVrModeWindowFlags(); | 375 setupVrModeWindowFlags(); |
| 366 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites
(); | 376 oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 367 try { | 377 try { |
| 368 mVrShell.resume(); | 378 mVrShell.resume(); |
| 369 } catch (IllegalArgumentException e) { | 379 } catch (IllegalArgumentException e) { |
| 370 Log.e(TAG, "Unable to resume VrShell", e); | 380 Log.e(TAG, "Unable to resume VrShell", e); |
| 371 } finally { | 381 } finally { |
| 372 StrictMode.setThreadPolicy(oldPolicy); | 382 StrictMode.setThreadPolicy(oldPolicy); |
| 373 } | 383 } |
| 374 } else if (mVrSupportLevel == VR_DAYDREAM && mVrDaydreamApi.isDaydreamCu
rrentViewer() | 384 } else if (mVrSupportLevel == VR_DAYDREAM && mVrDaydreamApi.isDaydreamCu
rrentViewer() |
| 375 && mLastVRExit + REENTER_VR_TIMEOUT_MS > SystemClock.uptimeMilli
s()) { | 385 && mLastVRExit + REENTER_VR_TIMEOUT_MS > SystemClock.uptimeMilli
s()) { |
| 376 enterVRIfNecessary(); | 386 enterVRIfNecessary(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 388 | 398 |
| 389 // When the active web page has a vrdisplayactivate event handler, | 399 // When the active web page has a vrdisplayactivate event handler, |
| 390 // mListeningForWebVrActivate should be set to true, which means a v
rdisplayactive event | 400 // mListeningForWebVrActivate should be set to true, which means a v
rdisplayactive event |
| 391 // should be fired once DON flow finished. However, DON flow will pa
use our activity, | 401 // should be fired once DON flow finished. However, DON flow will pa
use our activity, |
| 392 // which makes the active page becomes invisible. And the event fire
s before the active | 402 // which makes the active page becomes invisible. And the event fire
s before the active |
| 393 // page becomes visible again after DON finished. So here we remembe
r the value of | 403 // page becomes visible again after DON finished. So here we remembe
r the value of |
| 394 // mListeningForWebVrActivity before pause and use this value to dec
ide if | 404 // mListeningForWebVrActivity before pause and use this value to dec
ide if |
| 395 // vrdisplayactivate event should be dispatched in enterVRFromIntent
. | 405 // vrdisplayactivate event should be dispatched in enterVRFromIntent
. |
| 396 mListeningForWebVrActivateBeforePause = mListeningForWebVrActivate; | 406 mListeningForWebVrActivateBeforePause = mListeningForWebVrActivate; |
| 397 } | 407 } |
| 398 if (mNonPresentingGvrContext != null) { | 408 nativeOnPause(mNativeVrShellDelegate); |
| 399 mNonPresentingGvrContext.pause(); | |
| 400 } | |
| 401 | 409 |
| 402 // TODO(mthiesse): When VR Shell lives in its own activity, and integrat
es with Daydream | 410 // TODO(mthiesse): When VR Shell lives in its own activity, and integrat
es with Daydream |
| 403 // home, pause instead of exiting VR here. For now, because VR Apps shou
ldn't show up in the | 411 // home, pause instead of exiting VR here. For now, because VR Apps shou
ldn't show up in the |
| 404 // non-VR recents, and we don't want ChromeTabbedActivity disappearing,
exit VR. | 412 // non-VR recents, and we don't want ChromeTabbedActivity disappearing,
exit VR. |
| 405 exitVRIfNecessary(true); | 413 exitVRIfNecessary(true); |
| 406 } | 414 } |
| 407 | 415 |
| 408 /** | 416 /** |
| 409 * Exits the current VR mode (WebVR or VRShell) | 417 * Exits the current VR mode (WebVR or VRShell) |
| 410 * @return Whether or not we exited VR. | 418 * @return Whether or not we exited VR. |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 * @return Pointer to the native VrShellDelegate object. | 597 * @return Pointer to the native VrShellDelegate object. |
| 590 */ | 598 */ |
| 591 @CalledByNative | 599 @CalledByNative |
| 592 private long getNativePointer() { | 600 private long getNativePointer() { |
| 593 return mNativeVrShellDelegate; | 601 return mNativeVrShellDelegate; |
| 594 } | 602 } |
| 595 | 603 |
| 596 private native long nativeInit(); | 604 private native long nativeInit(); |
| 597 private native void nativeSetPresentResult(long nativeVrShellDelegate, boole
an result); | 605 private native void nativeSetPresentResult(long nativeVrShellDelegate, boole
an result); |
| 598 private native void nativeDisplayActivate(long nativeVrShellDelegate); | 606 private native void nativeDisplayActivate(long nativeVrShellDelegate); |
| 607 private native void nativeUpdateVSyncInterval(long nativeVrShellDelegate, lo
ng timebaseNanos, |
| 608 double intervalSeconds); |
| 609 private native void nativeOnPause(long nativeVrShellDelegate); |
| 610 private native void nativeOnResume(long nativeVrShellDelegate); |
| 599 } | 611 } |
| OLD | NEW |