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

Unified Diff: chrome/browser/android/vr_shell/vr_shell_delegate.cc

Issue 2343023002: Switch WebVR to handle GvrApi management through VrShellDelegate (Closed)
Patch Set: Renamed onNativeLibraryReady to initializeNative Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_delegate.h ('k') | device/vr/android/gvr/gvr_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/vr_shell/vr_shell_delegate.cc
diff --git a/chrome/browser/android/vr_shell/vr_shell_delegate.cc b/chrome/browser/android/vr_shell/vr_shell_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bce8ccae1470eb649321c6b47df456715fba5eb2
--- /dev/null
+++ b/chrome/browser/android/vr_shell/vr_shell_delegate.cc
@@ -0,0 +1,84 @@
+// 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.
+
+#include "chrome/browser/android/vr_shell/vr_shell_delegate.h"
+
+#include <jni.h>
+
+#include "base/android/jni_android.h"
+#include "chrome/browser/android/vr_shell/vr_shell.h"
+#include "jni/VrShellDelegate_jni.h"
+
+using base::android::JavaParamRef;
+using base::android::AttachCurrentThread;
+
+namespace vr_shell {
+
+VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj)
+ : device_provider_(nullptr) {
+ j_vr_shell_delegate_.Reset(env, obj);
+ GvrDelegateProvider::SetInstance(this);
+}
+
+VrShellDelegate::~VrShellDelegate() {
+ GvrDelegateProvider::SetInstance(nullptr);
+}
+
+VrShellDelegate* VrShellDelegate::getNativeDelegate(
+ JNIEnv* env, jobject jdelegate) {
+ long native_delegate = Java_VrShellDelegate_getNativePointer(env, jdelegate);
+ return reinterpret_cast<VrShellDelegate*>(native_delegate);
+}
+
+bool VrShellDelegate::ExitWebVRIfNecessary(JNIEnv* env, jobject obj) {
+ if (!device_provider_)
+ return false;
+
+ device_provider_->OnGvrDelegateRemoved();
+ return true;
+}
+
+bool VrShellDelegate::RequestWebVRPresent(
+ device::GvrDeviceProvider* device_provider) {
+ // Only set one device provider at a time
+ DCHECK(!device_provider_);
+ device_provider_ = device_provider;
+
+ // If/When VRShell is ready for use it will call OnVrShellReady.
+ JNIEnv* env = AttachCurrentThread();
+ return Java_VrShellDelegate_enterVRIfNecessary(env,
+ j_vr_shell_delegate_.obj(),
+ true);
+}
+
+void VrShellDelegate::ExitWebVRPresent() {
+ if (!device_provider_)
+ return;
+
+ device_provider_ = nullptr;
+
+ // VRShell is no longer needed by WebVR, allow it to shut down if it's not
+ // being used elsewhere.
+ JNIEnv* env = AttachCurrentThread();
+ Java_VrShellDelegate_exitWebVR(env, j_vr_shell_delegate_.obj());
+}
+
+void VrShellDelegate::OnVrShellReady(VrShell* vr_shell) {
+ if (device_provider_)
+ device_provider_->OnGvrDelegateReady(vr_shell);
+}
+
+// ----------------------------------------------------------------------------
+// Native JNI methods
+// ----------------------------------------------------------------------------
+
+bool RegisterVrShellDelegate(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
+ return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj));
+}
+
+} // namespace vr_shell
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_delegate.h ('k') | device/vr/android/gvr/gvr_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698