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

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

Issue 2624633002: Remove Sync GetPose VRService call, implement VRVSyncProvider (Closed)
Patch Set: oops Created 3 years, 10 months 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 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.Handler; 13 import android.os.Handler;
13 import android.os.StrictMode; 14 import android.os.StrictMode;
14 import android.os.SystemClock; 15 import android.os.SystemClock;
15 import android.support.annotation.IntDef; 16 import android.support.annotation.IntDef;
17 import android.view.Choreographer;
18 import android.view.Choreographer.FrameCallback;
19 import android.view.Display;
16 import android.view.View; 20 import android.view.View;
17 import android.view.ViewGroup; 21 import android.view.ViewGroup;
18 import android.view.ViewGroup.LayoutParams; 22 import android.view.ViewGroup.LayoutParams;
19 import android.view.WindowManager; 23 import android.view.WindowManager;
20 import android.widget.FrameLayout; 24 import android.widget.FrameLayout;
21 25
22 import org.chromium.base.Log; 26 import org.chromium.base.Log;
23 import org.chromium.base.VisibleForTesting; 27 import org.chromium.base.VisibleForTesting;
24 import org.chromium.base.annotations.CalledByNative; 28 import org.chromium.base.annotations.CalledByNative;
25 import org.chromium.base.annotations.JNINamespace; 29 import org.chromium.base.annotations.JNINamespace;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 mVrSupportLevel = mVrDaydreamApi.isDaydreamReadyDevice() ? VR_DAYDREAM : VR_CARDBOARD; 167 mVrSupportLevel = mVrDaydreamApi.isDaydreamReadyDevice() ? VR_DAYDREAM : VR_CARDBOARD;
164 } 168 }
165 169
166 /** 170 /**
167 * Should be called once the native library is loaded so that the native por tion of this class 171 * Should be called once the native library is loaded so that the native por tion of this class
168 * can be initialized. 172 * can be initialized.
169 */ 173 */
170 public void onNativeLibraryReady() { 174 public void onNativeLibraryReady() {
171 if (mVrSupportLevel == VR_NOT_AVAILABLE) return; 175 if (mVrSupportLevel == VR_NOT_AVAILABLE) return;
172 mNativeVrShellDelegate = nativeInit(); 176 mNativeVrShellDelegate = nativeInit();
177 Choreographer choreographer = Choreographer.getInstance();
178 choreographer.postFrameCallback(new FrameCallback() {
179 @Override
180 public void doFrame(long frameTimeNanos) {
181 Display display = ((WindowManager) mActivity.getSystemService(
182 Context.WINDOW_SERVICE)).getDefaultDisplay();
183 nativeUpdateVSyncInterval(mNativeVrShellDelegate, frameTimeNanos ,
184 1.0d / display.getRefreshRate());
185 }
186 });
173 } 187 }
174 188
175 @SuppressWarnings("unchecked") 189 @SuppressWarnings("unchecked")
176 private VrClassesWrapper createVrClassesWrapper() { 190 private VrClassesWrapper createVrClassesWrapper() {
177 try { 191 try {
178 Class<? extends VrClassesWrapper> vrClassesBuilderClass = 192 Class<? extends VrClassesWrapper> vrClassesBuilderClass =
179 (Class<? extends VrClassesWrapper>) Class.forName( 193 (Class<? extends VrClassesWrapper>) Class.forName(
180 "org.chromium.chrome.browser.vr_shell.VrClassesWrapp erImpl"); 194 "org.chromium.chrome.browser.vr_shell.VrClassesWrapp erImpl");
181 Constructor<?> vrClassesBuilderConstructor = 195 Constructor<?> vrClassesBuilderConstructor =
182 vrClassesBuilderClass.getConstructor(Activity.class); 196 vrClassesBuilderClass.getConstructor(Activity.class);
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 // If this is still set, it means the user backed out of the DON flow, a nd we won't be 410 // If this is still set, it means the user backed out of the DON flow, a nd we won't be
397 // receiving an intent from daydream. 411 // receiving an intent from daydream.
398 if (mRequestedWebVR) { 412 if (mRequestedWebVR) {
399 nativeSetPresentResult(mNativeVrShellDelegate, false); 413 nativeSetPresentResult(mNativeVrShellDelegate, false);
400 mRequestedWebVR = false; 414 mRequestedWebVR = false;
401 } 415 }
402 416
403 // TODO(bshe): Ideally, we do not need two gvr context exist at the same time. We can 417 // TODO(bshe): Ideally, we do not need two gvr context exist at the same time. We can
404 // probably shutdown non presenting gvr when presenting and create a new one after exit 418 // probably shutdown non presenting gvr when presenting and create a new one after exit
405 // presenting. See crbug.com/655242 419 // presenting. See crbug.com/655242
406 if (mNonPresentingGvrContext != null) { 420 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
407 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites (); 421 try {
408 try { 422 nativeOnResume(mNativeVrShellDelegate);
409 mNonPresentingGvrContext.resume(); 423 } finally {
410 } catch (IllegalArgumentException e) { 424 StrictMode.setThreadPolicy(oldPolicy);
411 Log.e(TAG, "Unable to resume mNonPresentingGvrContext", e);
412 } finally {
413 StrictMode.setThreadPolicy(oldPolicy);
414 }
415 } 425 }
416 426
417 if (mInVr) { 427 if (mInVr) {
418 setupVrModeWindowFlags(); 428 setupVrModeWindowFlags();
419 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites (); 429 oldPolicy = StrictMode.allowThreadDiskWrites();
420 try { 430 try {
421 mVrShell.resume(); 431 mVrShell.resume();
422 } catch (IllegalArgumentException e) { 432 } catch (IllegalArgumentException e) {
423 Log.e(TAG, "Unable to resume VrShell", e); 433 Log.e(TAG, "Unable to resume VrShell", e);
424 } finally { 434 } finally {
425 StrictMode.setThreadPolicy(oldPolicy); 435 StrictMode.setThreadPolicy(oldPolicy);
426 } 436 }
427 } else if (mVrSupportLevel == VR_DAYDREAM && mVrDaydreamApi.isDaydreamCu rrentViewer() 437 } else if (mVrSupportLevel == VR_DAYDREAM && mVrDaydreamApi.isDaydreamCu rrentViewer()
428 && mLastVRExit + REENTER_VR_TIMEOUT_MS > SystemClock.uptimeMilli s()) { 438 && mLastVRExit + REENTER_VR_TIMEOUT_MS > SystemClock.uptimeMilli s()) {
429 enterVRIfNecessary(); 439 enterVRIfNecessary();
(...skipping 11 matching lines...) Expand all
441 451
442 // When the active web page has a vrdisplayactivate event handler, 452 // When the active web page has a vrdisplayactivate event handler,
443 // mListeningForWebVrActivate should be set to true, which means a v rdisplayactive event 453 // mListeningForWebVrActivate should be set to true, which means a v rdisplayactive event
444 // should be fired once DON flow finished. However, DON flow will pa use our activity, 454 // should be fired once DON flow finished. However, DON flow will pa use our activity,
445 // which makes the active page becomes invisible. And the event fire s before the active 455 // which makes the active page becomes invisible. And the event fire s before the active
446 // page becomes visible again after DON finished. So here we remembe r the value of 456 // page becomes visible again after DON finished. So here we remembe r the value of
447 // mListeningForWebVrActivity before pause and use this value to dec ide if 457 // mListeningForWebVrActivity before pause and use this value to dec ide if
448 // vrdisplayactivate event should be dispatched in enterVRFromIntent . 458 // vrdisplayactivate event should be dispatched in enterVRFromIntent .
449 mListeningForWebVrActivateBeforePause = mListeningForWebVrActivate; 459 mListeningForWebVrActivateBeforePause = mListeningForWebVrActivate;
450 } 460 }
451 if (mNonPresentingGvrContext != null) { 461 nativeOnPause(mNativeVrShellDelegate);
452 mNonPresentingGvrContext.pause();
453 }
454 462
455 // TODO(mthiesse): When VR Shell lives in its own activity, and integrat es with Daydream 463 // TODO(mthiesse): When VR Shell lives in its own activity, and integrat es with Daydream
456 // home, pause instead of exiting VR here. For now, because VR Apps shou ldn't show up in the 464 // home, pause instead of exiting VR here. For now, because VR Apps shou ldn't show up in the
457 // non-VR recents, and we don't want ChromeTabbedActivity disappearing, exit VR. 465 // non-VR recents, and we don't want ChromeTabbedActivity disappearing, exit VR.
458 exitVRIfNecessary(true); 466 exitVRIfNecessary(true);
459 } 467 }
460 468
461 /** 469 /**
462 * Exits the current VR mode (WebVR or VRShell) 470 * Exits the current VR mode (WebVR or VRShell)
463 * @return Whether or not we exited VR. 471 * @return Whether or not we exited VR.
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 * @return Pointer to the native VrShellDelegate object. 657 * @return Pointer to the native VrShellDelegate object.
650 */ 658 */
651 @CalledByNative 659 @CalledByNative
652 private long getNativePointer() { 660 private long getNativePointer() {
653 return mNativeVrShellDelegate; 661 return mNativeVrShellDelegate;
654 } 662 }
655 663
656 private native long nativeInit(); 664 private native long nativeInit();
657 private native void nativeSetPresentResult(long nativeVrShellDelegate, boole an result); 665 private native void nativeSetPresentResult(long nativeVrShellDelegate, boole an result);
658 private native void nativeDisplayActivate(long nativeVrShellDelegate); 666 private native void nativeDisplayActivate(long nativeVrShellDelegate);
667 private native void nativeUpdateVSyncInterval(long nativeVrShellDelegate, lo ng timebaseNanos,
668 double intervalSeconds);
669 private native void nativeOnPause(long nativeVrShellDelegate);
670 private native void nativeOnResume(long nativeVrShellDelegate);
659 } 671 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698