VR: Move non-presenting gvr context creation/ownership into device/vr/
No functional changes, just cleanup and preparation for moving the focus related code down into device/vr/ as well, dramatically simplifying VrShellDelegate. Bug: 752193 Change-Id: Id4820613f44b74da7b696921ff4af56bc1f10861 Reviewed-on: https://chromium-review.googlesource.com/621486 Commit-Queue: Michael Thiessen <mthiesse@chromium.org> Reviewed-by: David Trainor <dtrainor@chromium.org> Reviewed-by: Biao She <bshe@chromium.org> Reviewed-by: Brandon Jones <bajones@chromium.org> Cr-Commit-Position: refs/heads/master@{#499697}
This commit is contained in:

committed by
Commit Bot

parent
3220623dee
commit
126077576f
@@ -1,21 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package org.chromium.chrome.browser.vr_shell;
|
||||
|
||||
/**
|
||||
* Abstracts away the NonPresentingGvrContext class, which may or may not be present at runtime
|
||||
* depending on compile flags.
|
||||
*/
|
||||
public interface NonPresentingGvrContext {
|
||||
/**
|
||||
* Returns the native gvr context.
|
||||
*/
|
||||
long getNativeGvrContext();
|
||||
|
||||
/**
|
||||
* Shutdown the native gvr context.
|
||||
*/
|
||||
void shutdown();
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package org.chromium.chrome.browser.vr_shell;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.StrictMode;
|
||||
|
||||
import com.google.vr.ndk.base.GvrLayout;
|
||||
|
||||
/**
|
||||
* Creates an active GvrContext from a detached GvrLayout. This is used by magic window mode.
|
||||
*/
|
||||
public class NonPresentingGvrContextImpl implements NonPresentingGvrContext {
|
||||
private GvrLayout mGvrLayout;
|
||||
|
||||
public NonPresentingGvrContextImpl(Activity activity) {
|
||||
// Creating the GvrLayout can sometimes create the Daydream config file.
|
||||
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
|
||||
try {
|
||||
mGvrLayout = new GvrLayout(activity);
|
||||
} finally {
|
||||
StrictMode.setThreadPolicy(oldPolicy);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getNativeGvrContext() {
|
||||
return mGvrLayout.getGvrApi().getNativeGvrContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
mGvrLayout.shutdown();
|
||||
}
|
||||
}
|
@@ -16,11 +16,6 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelector;
|
||||
* depending on compile flags.
|
||||
*/
|
||||
public interface VrClassesWrapper {
|
||||
/**
|
||||
* Creates a NonPresentingGvrContextImpl instance.
|
||||
*/
|
||||
public NonPresentingGvrContext createNonPresentingGvrContext(ChromeActivity activity);
|
||||
|
||||
/**
|
||||
* Creates a VrShellImpl instance.
|
||||
*/
|
||||
|
@@ -26,19 +26,6 @@ public class VrClassesWrapperImpl implements VrClassesWrapper {
|
||||
@UsedByReflection("VrShellDelegate.java")
|
||||
public VrClassesWrapperImpl() {}
|
||||
|
||||
@Override
|
||||
public NonPresentingGvrContext createNonPresentingGvrContext(ChromeActivity activity) {
|
||||
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
|
||||
try {
|
||||
return new NonPresentingGvrContextImpl(activity);
|
||||
} catch (Exception ex) {
|
||||
Log.e(TAG, "Unable to instantiate NonPresentingGvrContextImpl", ex);
|
||||
return null;
|
||||
} finally {
|
||||
StrictMode.setThreadPolicy(oldPolicy);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VrShell createVrShell(
|
||||
ChromeActivity activity, VrShellDelegate delegate, TabModelSelector tabModelSelector) {
|
||||
|
@@ -124,7 +124,6 @@ public class VrShellDelegate
|
||||
|
||||
private final VrClassesWrapper mVrClassesWrapper;
|
||||
private VrShell mVrShell;
|
||||
private NonPresentingGvrContext mNonPresentingGvrContext;
|
||||
private VrDaydreamApi mVrDaydreamApi;
|
||||
private Boolean mIsDaydreamCurrentViewer;
|
||||
private VrCoreVersionChecker mVrCoreVersionChecker;
|
||||
@@ -512,7 +511,6 @@ public class VrShellDelegate
|
||||
mStopped = ApplicationStatus.getStateForActivity(activity) == ActivityState.STOPPED;
|
||||
updateVrSupportLevel(null);
|
||||
mNativeVrShellDelegate = nativeInit();
|
||||
createNonPresentingNativeContext();
|
||||
mFeedbackFrequency = VrFeedbackStatus.getFeedbackFrequency();
|
||||
mEnterVrHandler = new Handler();
|
||||
mExpectPauseOrDonSucceeded = new Handler();
|
||||
@@ -562,8 +560,6 @@ public class VrShellDelegate
|
||||
if (mActivity == activity) return;
|
||||
mActivity = activity;
|
||||
mVrDaydreamApi = mVrClassesWrapper.createVrDaydreamApi(mActivity);
|
||||
if (mNativeVrShellDelegate == 0 || mNonPresentingGvrContext == null) return;
|
||||
resetNonPresentingNativeContext();
|
||||
}
|
||||
|
||||
private void maybeUpdateVrSupportLevel() {
|
||||
@@ -590,7 +586,6 @@ public class VrShellDelegate
|
||||
private void updateVrSupportLevel(Integer vrCorePackageVersion) {
|
||||
if (mVrClassesWrapper == null) {
|
||||
mVrSupportLevel = VR_NOT_AVAILABLE;
|
||||
shutdownNonPresentingNativeContext();
|
||||
return;
|
||||
}
|
||||
if (vrCorePackageVersion == null) vrCorePackageVersion = getVrCorePackageVersion();
|
||||
@@ -606,7 +601,6 @@ public class VrShellDelegate
|
||||
mVrDaydreamApi, mVrCoreVersionChecker, mActivity.getActivityTab());
|
||||
if (supportLevel == mVrSupportLevel) return;
|
||||
mVrSupportLevel = supportLevel;
|
||||
resetNonPresentingNativeContext();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -705,7 +699,6 @@ public class VrShellDelegate
|
||||
return;
|
||||
}
|
||||
mExitedDueToUnsupportedMode = false;
|
||||
shutdownNonPresentingNativeContext();
|
||||
|
||||
// Lock orientation to landscape after enter VR.
|
||||
mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
@@ -989,10 +982,7 @@ public class VrShellDelegate
|
||||
new Handler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!mPaused) {
|
||||
registerDaydreamIntent(mVrDaydreamApi, mActivity);
|
||||
createNonPresentingNativeContext();
|
||||
}
|
||||
if (!mPaused) registerDaydreamIntent(mVrDaydreamApi, mActivity);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1141,31 +1131,6 @@ public class VrShellDelegate
|
||||
return mIsDaydreamCurrentViewer;
|
||||
}
|
||||
|
||||
private void resetNonPresentingNativeContext() {
|
||||
shutdownNonPresentingNativeContext();
|
||||
createNonPresentingNativeContext();
|
||||
}
|
||||
|
||||
private void createNonPresentingNativeContext() {
|
||||
if (mNonPresentingGvrContext != null) return;
|
||||
if (mVrClassesWrapper == null) return;
|
||||
if (mVrSupportLevel == VR_NOT_AVAILABLE) return;
|
||||
if (mNativeVrShellDelegate == 0) return;
|
||||
mNonPresentingGvrContext = mVrClassesWrapper.createNonPresentingGvrContext(mActivity);
|
||||
if (mNonPresentingGvrContext == null) return;
|
||||
nativeUpdateNonPresentingContext(
|
||||
mNativeVrShellDelegate, mNonPresentingGvrContext.getNativeGvrContext());
|
||||
}
|
||||
|
||||
private void shutdownNonPresentingNativeContext() {
|
||||
if (mNonPresentingGvrContext == null) return;
|
||||
if (mNativeVrShellDelegate != 0) {
|
||||
nativeUpdateNonPresentingContext(mNativeVrShellDelegate, 0);
|
||||
}
|
||||
mNonPresentingGvrContext.shutdown();
|
||||
mNonPresentingGvrContext = null;
|
||||
}
|
||||
|
||||
@CalledByNative
|
||||
private void setListeningForWebVrActivate(boolean listening) {
|
||||
// Non-Daydream devices may not have the concept of display activate. So disable
|
||||
@@ -1227,7 +1192,6 @@ public class VrShellDelegate
|
||||
if (disableVrMode) mVrClassesWrapper.setVrModeEnabled(mActivity, false);
|
||||
|
||||
promptForFeedbackIfNeeded(stayingInChrome);
|
||||
if (stayingInChrome) createNonPresentingNativeContext();
|
||||
|
||||
assert mOnExitVrRequestListener == null;
|
||||
}
|
||||
@@ -1551,7 +1515,6 @@ public class VrShellDelegate
|
||||
shutdownVr(false /* disableVrMode */, false /* stayingInChrome */);
|
||||
if (mNativeVrShellDelegate != 0) nativeDestroy(mNativeVrShellDelegate);
|
||||
mNativeVrShellDelegate = 0;
|
||||
shutdownNonPresentingNativeContext();
|
||||
ApplicationStatus.unregisterActivityStateListener(this);
|
||||
sInstance = null;
|
||||
}
|
||||
@@ -1562,7 +1525,6 @@ public class VrShellDelegate
|
||||
private native void nativeDisplayActivate(long nativeVrShellDelegate);
|
||||
private native void nativeOnPause(long nativeVrShellDelegate);
|
||||
private native void nativeOnResume(long nativeVrShellDelegate);
|
||||
private native void nativeUpdateNonPresentingContext(long nativeVrShellDelegate, long context);
|
||||
private native boolean nativeIsClearActivatePending(long nativeVrShellDelegate);
|
||||
private native void nativeDestroy(long nativeVrShellDelegate);
|
||||
}
|
||||
|
@@ -1184,7 +1184,6 @@ chrome_java_sources = [
|
||||
"java/src/org/chromium/chrome/browser/util/ViewUtils.java",
|
||||
"java/src/org/chromium/chrome/browser/vr_shell/SeparateTaskCustomTabVrActivity.java",
|
||||
"java/src/org/chromium/chrome/browser/vr_shell/VrCancelAnimationActivity.java",
|
||||
"java/src/org/chromium/chrome/browser/vr_shell/NonPresentingGvrContext.java",
|
||||
"java/src/org/chromium/chrome/browser/vr_shell/VrClassesWrapper.java",
|
||||
"java/src/org/chromium/chrome/browser/vr_shell/VrCoreVersionChecker.java",
|
||||
"java/src/org/chromium/chrome/browser/vr_shell/VrDaydreamApi.java",
|
||||
@@ -1330,7 +1329,6 @@ chrome_java_sources = [
|
||||
chrome_vr_java_sources = [
|
||||
"java/src/org/chromium/chrome/browser/vr_shell/AndroidUiGestureTarget.java",
|
||||
"java/src/org/chromium/chrome/browser/vr_shell/AndroidVSyncHelper.java",
|
||||
"java/src/org/chromium/chrome/browser/vr_shell/NonPresentingGvrContextImpl.java",
|
||||
"java/src/org/chromium/chrome/browser/vr_shell/VrClassesWrapperImpl.java",
|
||||
"java/src/org/chromium/chrome/browser/vr_shell/VrCoreInfo.java",
|
||||
"java/src/org/chromium/chrome/browser/vr_shell/VrCoreVersionCheckerImpl.java",
|
||||
|
@@ -194,26 +194,19 @@ void VrShellDelegate::DisplayActivate(JNIEnv* env,
|
||||
}
|
||||
|
||||
void VrShellDelegate::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) {
|
||||
if (gvr_api_) {
|
||||
gvr_api_->PauseTracking();
|
||||
}
|
||||
if (vr_shell_)
|
||||
return;
|
||||
device::VRDevice* device = GetDevice();
|
||||
if (device)
|
||||
device->PauseTracking();
|
||||
}
|
||||
|
||||
void VrShellDelegate::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) {
|
||||
if (gvr_api_) {
|
||||
gvr_api_->ResumeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
void VrShellDelegate::UpdateNonPresentingContext(
|
||||
JNIEnv* env,
|
||||
const JavaParamRef<jobject>& obj,
|
||||
jlong context) {
|
||||
if (context == 0) {
|
||||
gvr_api_ = nullptr;
|
||||
if (vr_shell_)
|
||||
return;
|
||||
}
|
||||
gvr_api_ = gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(context));
|
||||
device::VRDevice* device = GetDevice();
|
||||
if (device)
|
||||
device->ResumeTracking();
|
||||
}
|
||||
|
||||
bool VrShellDelegate::IsClearActivatePending(JNIEnv* env,
|
||||
@@ -364,19 +357,20 @@ void VrShellDelegate::SetListeningForActivate(bool listening) {
|
||||
}
|
||||
|
||||
void VrShellDelegate::GetNextMagicWindowPose(
|
||||
gvr::GvrApi* gvr_api,
|
||||
device::VRDisplayImpl* display,
|
||||
device::mojom::VRDisplay::GetNextMagicWindowPoseCallback callback) {
|
||||
content::RenderFrameHost* host = GetHostForDisplay(display);
|
||||
if (!gvr_api_ || vr_shell_ || host == nullptr ||
|
||||
!host->GetView()->HasFocus()) {
|
||||
if (vr_shell_ || host == nullptr || !host->GetView()->HasFocus()) {
|
||||
std::move(callback).Run(nullptr);
|
||||
return;
|
||||
}
|
||||
std::move(callback).Run(
|
||||
device::GvrDelegate::GetVRPosePtrWithNeckModel(gvr_api_.get(), nullptr));
|
||||
device::GvrDelegate::GetVRPosePtrWithNeckModel(gvr_api, nullptr));
|
||||
}
|
||||
|
||||
void VrShellDelegate::CreateVRDisplayInfo(
|
||||
gvr::GvrApi* gvr_api,
|
||||
const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback,
|
||||
uint32_t device_id) {
|
||||
if (vr_shell_) {
|
||||
@@ -384,8 +378,8 @@ void VrShellDelegate::CreateVRDisplayInfo(
|
||||
return;
|
||||
}
|
||||
// This is for magic window mode, which doesn't care what the render size is.
|
||||
callback.Run(device::GvrDelegate::CreateDefaultVRDisplayInfo(gvr_api_.get(),
|
||||
device_id));
|
||||
callback.Run(
|
||||
device::GvrDelegate::CreateDefaultVRDisplayInfo(gvr_api, device_id));
|
||||
}
|
||||
|
||||
device::VRDevice* VrShellDelegate::GetDevice() {
|
||||
|
@@ -54,10 +54,6 @@ class VrShellDelegate : public device::GvrDelegateProvider {
|
||||
const base::android::JavaParamRef<jobject>& obj);
|
||||
void OnPause(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
|
||||
void OnResume(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
|
||||
void UpdateNonPresentingContext(
|
||||
JNIEnv* env,
|
||||
const base::android::JavaParamRef<jobject>& obj,
|
||||
jlong context);
|
||||
bool IsClearActivatePending(JNIEnv* env,
|
||||
const base::android::JavaParamRef<jobject>& obj);
|
||||
void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
|
||||
@@ -69,9 +65,6 @@ class VrShellDelegate : public device::GvrDelegateProvider {
|
||||
|
||||
// device::GvrDelegateProvider implementation.
|
||||
void ExitWebVRPresent() override;
|
||||
void CreateVRDisplayInfo(
|
||||
const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback,
|
||||
uint32_t device_id) override;
|
||||
|
||||
private:
|
||||
// device::GvrDelegateProvider implementation.
|
||||
@@ -82,7 +75,12 @@ class VrShellDelegate : public device::GvrDelegateProvider {
|
||||
void OnDisplayAdded(device::VRDisplayImpl* display) override;
|
||||
void OnDisplayRemoved(device::VRDisplayImpl* display) override;
|
||||
void OnListeningForActivateChanged(device::VRDisplayImpl* display) override;
|
||||
void CreateVRDisplayInfo(
|
||||
gvr::GvrApi* gvr_api,
|
||||
const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback,
|
||||
uint32_t device_id) override;
|
||||
void GetNextMagicWindowPose(
|
||||
gvr::GvrApi* gvr_api,
|
||||
device::VRDisplayImpl* display,
|
||||
device::mojom::VRDisplay::GetNextMagicWindowPoseCallback callback)
|
||||
override;
|
||||
@@ -102,7 +100,6 @@ class VrShellDelegate : public device::GvrDelegateProvider {
|
||||
device::mojom::VRSubmitFrameClientPtr submit_client_;
|
||||
device::mojom::VRPresentationProviderRequest presentation_provider_request_;
|
||||
bool pending_successful_present_request_ = false;
|
||||
std::unique_ptr<gvr::GvrApi> gvr_api_;
|
||||
|
||||
std::map<content::RenderWidgetHost*, device::VRDisplayImpl*> displays_;
|
||||
std::map<device::VRDisplayImpl*, std::unique_ptr<DelegateWebContentsObserver>>
|
||||
|
@@ -4,6 +4,7 @@
|
||||
|
||||
import("//build/config/android/config.gni")
|
||||
import("//build/config/android/rules.gni")
|
||||
import("//device/vr/features/features.gni")
|
||||
|
||||
android_aidl("common_aidl") {
|
||||
interface_file = "java/src/org/chromium/content/common/common.aidl"
|
||||
@@ -63,6 +64,10 @@ android_library("content_java") {
|
||||
"//ui/gfx/geometry/mojo:mojo_java",
|
||||
]
|
||||
|
||||
if (enable_vr) {
|
||||
deps += [ "//device/vr:java" ]
|
||||
}
|
||||
|
||||
srcjar_deps = [
|
||||
":common_aidl",
|
||||
":is_ready_to_pay_service_aidl",
|
||||
|
@@ -248,6 +248,7 @@ test("device_unittests") {
|
||||
deps += [
|
||||
"//device/vr",
|
||||
"//device/vr:fakes",
|
||||
"//device/vr:java",
|
||||
"//device/vr:mojo_bindings",
|
||||
]
|
||||
}
|
||||
|
@@ -60,6 +60,7 @@ if (enable_vr) {
|
||||
]
|
||||
|
||||
deps += [
|
||||
":jni_headers",
|
||||
"//device/gamepad",
|
||||
"//device/gamepad/public/cpp:shared_with_blink",
|
||||
"//third_party/WebKit/public:blink_headers",
|
||||
@@ -116,6 +117,24 @@ if (enable_vr) {
|
||||
}
|
||||
}
|
||||
|
||||
if (is_android && (current_cpu == "arm" || current_cpu == "arm64")) {
|
||||
java_sources_needing_jni =
|
||||
[ "android/java/src/org/chromium/device/vr/NonPresentingGvrContext.java" ]
|
||||
|
||||
generate_jni("jni_headers") {
|
||||
sources = java_sources_needing_jni
|
||||
jni_package = "device"
|
||||
}
|
||||
|
||||
android_library("java") {
|
||||
java_files = java_sources_needing_jni
|
||||
deps = [
|
||||
"//base:base_java",
|
||||
"//third_party/gvr-android-sdk:gvr_common_java",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
mojom_component("mojo_bindings") {
|
||||
output_prefix = "device_vr_mojo_bindings"
|
||||
macro_prefix = "DEVICE_VR_MOJO_BINDINGS"
|
||||
|
@@ -10,6 +10,10 @@
|
||||
#include "device/vr/vr_export.h"
|
||||
#include "device/vr/vr_service.mojom.h"
|
||||
|
||||
namespace gvr {
|
||||
class GvrApi;
|
||||
}
|
||||
|
||||
namespace device {
|
||||
|
||||
class VRDisplayImpl;
|
||||
@@ -26,10 +30,13 @@ class DEVICE_VR_EXPORT GvrDelegateProvider {
|
||||
virtual void OnDisplayAdded(VRDisplayImpl* display) = 0;
|
||||
virtual void OnDisplayRemoved(VRDisplayImpl* display) = 0;
|
||||
virtual void OnListeningForActivateChanged(VRDisplayImpl* display) = 0;
|
||||
// TODO(mthiesse): Remove the GvrApi from these calls.
|
||||
virtual void CreateVRDisplayInfo(
|
||||
gvr::GvrApi* gvr_api,
|
||||
const base::Callback<void(mojom::VRDisplayInfoPtr)>& callback,
|
||||
uint32_t device_id) = 0;
|
||||
virtual void GetNextMagicWindowPose(
|
||||
gvr::GvrApi* gvr_api,
|
||||
VRDisplayImpl* display,
|
||||
mojom::VRDisplay::GetNextMagicWindowPoseCallback callback) = 0;
|
||||
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#include <math.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/time/time.h"
|
||||
#include "base/trace_event/trace_event.h"
|
||||
#include "device/vr/android/gvr/gvr_delegate.h"
|
||||
@@ -15,23 +16,44 @@
|
||||
#include "device/vr/android/gvr/gvr_device_provider.h"
|
||||
#include "device/vr/vr_device_manager.h"
|
||||
#include "device/vr/vr_display_impl.h"
|
||||
#include "jni/NonPresentingGvrContext_jni.h"
|
||||
#include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/gvr.h"
|
||||
#include "ui/gfx/geometry/rect_f.h"
|
||||
#include "ui/gfx/transform.h"
|
||||
#include "ui/gfx/transform_util.h"
|
||||
|
||||
namespace device {
|
||||
|
||||
GvrDevice::GvrDevice() : VRDevice() {
|
||||
GetGvrDelegateProvider();
|
||||
std::unique_ptr<GvrDevice> GvrDevice::Create() {
|
||||
std::unique_ptr<GvrDevice> device = base::WrapUnique(new GvrDevice());
|
||||
if (!device->gvr_api_)
|
||||
return nullptr;
|
||||
return device;
|
||||
}
|
||||
|
||||
GvrDevice::~GvrDevice() {}
|
||||
GvrDevice::GvrDevice() : VRDevice() {
|
||||
GetGvrDelegateProvider();
|
||||
JNIEnv* env = base::android::AttachCurrentThread();
|
||||
non_presenting_context_.Reset(Java_NonPresentingGvrContext_create(env));
|
||||
if (!non_presenting_context_.obj())
|
||||
return;
|
||||
jlong context = Java_NonPresentingGvrContext_getNativeGvrContext(
|
||||
env, non_presenting_context_);
|
||||
gvr_api_ = gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(context));
|
||||
}
|
||||
|
||||
GvrDevice::~GvrDevice() {
|
||||
if (!non_presenting_context_.obj())
|
||||
return;
|
||||
JNIEnv* env = base::android::AttachCurrentThread();
|
||||
Java_NonPresentingGvrContext_shutdown(env, non_presenting_context_);
|
||||
}
|
||||
|
||||
void GvrDevice::CreateVRDisplayInfo(
|
||||
const base::Callback<void(mojom::VRDisplayInfoPtr)>& on_created) {
|
||||
GvrDelegateProvider* delegate_provider = GetGvrDelegateProvider();
|
||||
if (delegate_provider) {
|
||||
delegate_provider->CreateVRDisplayInfo(on_created, id());
|
||||
delegate_provider->CreateVRDisplayInfo(gvr_api_.get(), on_created, id());
|
||||
} else {
|
||||
on_created.Run(nullptr);
|
||||
}
|
||||
@@ -65,7 +87,8 @@ void GvrDevice::GetNextMagicWindowPose(
|
||||
std::move(callback).Run(nullptr);
|
||||
return;
|
||||
}
|
||||
delegate_provider->GetNextMagicWindowPose(display, std::move(callback));
|
||||
delegate_provider->GetNextMagicWindowPose(gvr_api_.get(), display,
|
||||
std::move(callback));
|
||||
}
|
||||
|
||||
void GvrDevice::OnDisplayAdded(VRDisplayImpl* display) {
|
||||
@@ -89,6 +112,14 @@ void GvrDevice::OnListeningForActivateChanged(VRDisplayImpl* display) {
|
||||
delegate_provider->OnListeningForActivateChanged(display);
|
||||
}
|
||||
|
||||
void GvrDevice::PauseTracking() {
|
||||
gvr_api_->PauseTracking();
|
||||
}
|
||||
|
||||
void GvrDevice::ResumeTracking() {
|
||||
gvr_api_->ResumeTracking();
|
||||
}
|
||||
|
||||
GvrDelegateProvider* GvrDevice::GetGvrDelegateProvider() {
|
||||
// GvrDelegateProviderFactory::Create() may fail transiently, so every time we
|
||||
// try to get it, set the device ID.
|
||||
|
@@ -5,8 +5,12 @@
|
||||
#ifndef DEVICE_VR_ANDROID_GVR_DEVICE_H
|
||||
#define DEVICE_VR_ANDROID_GVR_DEVICE_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "base/android/scoped_java_ref.h"
|
||||
#include "base/macros.h"
|
||||
#include "device/vr/vr_device.h"
|
||||
#include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/gvr_types.h"
|
||||
|
||||
namespace device {
|
||||
|
||||
@@ -15,7 +19,7 @@ class VRDisplayImpl;
|
||||
|
||||
class DEVICE_VR_EXPORT GvrDevice : public VRDevice {
|
||||
public:
|
||||
GvrDevice();
|
||||
static std::unique_ptr<GvrDevice> Create();
|
||||
~GvrDevice() override;
|
||||
|
||||
// VRDevice
|
||||
@@ -32,10 +36,16 @@ class DEVICE_VR_EXPORT GvrDevice : public VRDevice {
|
||||
void OnDisplayAdded(VRDisplayImpl* display) override;
|
||||
void OnDisplayRemoved(VRDisplayImpl* display) override;
|
||||
void OnListeningForActivateChanged(VRDisplayImpl* display) override;
|
||||
void PauseTracking() override;
|
||||
void ResumeTracking() override;
|
||||
|
||||
private:
|
||||
GvrDevice();
|
||||
GvrDelegateProvider* GetGvrDelegateProvider();
|
||||
|
||||
base::android::ScopedJavaGlobalRef<jobject> non_presenting_context_;
|
||||
std::unique_ptr<gvr::GvrApi> gvr_api_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(GvrDevice);
|
||||
};
|
||||
|
||||
|
@@ -14,11 +14,12 @@ GvrDeviceProvider::GvrDeviceProvider() = default;
|
||||
GvrDeviceProvider::~GvrDeviceProvider() = default;
|
||||
|
||||
void GvrDeviceProvider::GetDevices(std::vector<VRDevice*>* devices) {
|
||||
devices->push_back(vr_device_.get());
|
||||
if (vr_device_.get())
|
||||
devices->push_back(vr_device_.get());
|
||||
}
|
||||
|
||||
void GvrDeviceProvider::Initialize() {
|
||||
vr_device_ = std::make_unique<GvrDevice>();
|
||||
vr_device_ = GvrDevice::Create();
|
||||
}
|
||||
|
||||
} // namespace device
|
||||
|
@@ -0,0 +1,62 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package org.chromium.device.vr;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.StrictMode;
|
||||
import android.view.Display;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.google.vr.cardboard.DisplaySynchronizer;
|
||||
import com.google.vr.ndk.base.GvrApi;
|
||||
|
||||
import org.chromium.base.ContextUtils;
|
||||
import org.chromium.base.annotations.CalledByNative;
|
||||
import org.chromium.base.annotations.JNINamespace;
|
||||
|
||||
/**
|
||||
* Creates an active GvrContext from a GvrApi created from the Application Context. This GvrContext
|
||||
* cannot be used for VR rendering, and should only be used to query pose information and device
|
||||
* parameters.
|
||||
*/
|
||||
@JNINamespace("device")
|
||||
public class NonPresentingGvrContext {
|
||||
private GvrApi mGvrApi;
|
||||
|
||||
private NonPresentingGvrContext() {
|
||||
Context context = ContextUtils.getApplicationContext();
|
||||
WindowManager windowManager =
|
||||
(WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
Display display = windowManager.getDefaultDisplay();
|
||||
DisplaySynchronizer synchronizer = new DisplaySynchronizer(context, display);
|
||||
|
||||
// Creating the GvrApi can sometimes create the Daydream config file.
|
||||
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
|
||||
try {
|
||||
mGvrApi = new GvrApi(context, synchronizer);
|
||||
} finally {
|
||||
StrictMode.setThreadPolicy(oldPolicy);
|
||||
}
|
||||
}
|
||||
|
||||
@CalledByNative
|
||||
private static NonPresentingGvrContext create() {
|
||||
try {
|
||||
return new NonPresentingGvrContext();
|
||||
} catch (IllegalStateException | UnsatisfiedLinkError e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@CalledByNative
|
||||
private long getNativeGvrContext() {
|
||||
return mGvrApi.getNativeGvrContext();
|
||||
}
|
||||
|
||||
@CalledByNative
|
||||
private void shutdown() {
|
||||
mGvrApi.shutdown();
|
||||
}
|
||||
}
|
@@ -43,12 +43,15 @@ class DEVICE_VR_EXPORT VRDevice {
|
||||
void RemoveDisplay(VRDisplayImpl* display);
|
||||
virtual void OnDisplayAdded(VRDisplayImpl* display) {}
|
||||
virtual void OnDisplayRemoved(VRDisplayImpl* display) {}
|
||||
virtual void OnListeningForActivateChanged(VRDisplayImpl* display){};
|
||||
virtual void OnListeningForActivateChanged(VRDisplayImpl* display) {}
|
||||
|
||||
bool IsAccessAllowed(VRDisplayImpl* display);
|
||||
bool CheckPresentingDisplay(VRDisplayImpl* display);
|
||||
VRDisplayImpl* GetPresentingDisplay() { return presenting_display_; }
|
||||
|
||||
virtual void PauseTracking() {}
|
||||
virtual void ResumeTracking() {}
|
||||
|
||||
void OnChanged();
|
||||
void OnExitPresent();
|
||||
void OnBlur();
|
||||
|
@@ -18,10 +18,7 @@ namespace device {
|
||||
|
||||
VRServiceImpl::VRServiceImpl(int render_frame_process_id,
|
||||
int render_frame_routing_id)
|
||||
: in_set_client_(false),
|
||||
connected_devices_(0),
|
||||
handled_devices_(0),
|
||||
render_frame_process_id_(render_frame_process_id),
|
||||
: render_frame_process_id_(render_frame_process_id),
|
||||
render_frame_routing_id_(render_frame_routing_id),
|
||||
weak_ptr_factory_(this) {}
|
||||
|
||||
|
@@ -52,9 +52,9 @@ class VRServiceImpl : public mojom::VRService {
|
||||
|
||||
mojom::VRServiceClientPtr client_;
|
||||
|
||||
bool in_set_client_;
|
||||
unsigned connected_devices_;
|
||||
unsigned handled_devices_;
|
||||
bool in_set_client_ = false;
|
||||
unsigned connected_devices_ = 0;
|
||||
unsigned handled_devices_ = 0;
|
||||
const int render_frame_process_id_;
|
||||
const int render_frame_routing_id_;
|
||||
|
||||
|
Reference in New Issue
Block a user