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

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell_delegate.cc

Issue 2343023002: Switch WebVR to handle GvrApi management through VrShellDelegate (Closed)
Patch Set: Rebase 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h"
6
7 #include <jni.h>
8
9 #include "base/android/jni_android.h"
10 #include "chrome/browser/android/vr_shell/vr_shell.h"
11 #include "jni/VrShellDelegate_jni.h"
12
13 using base::android::JavaParamRef;
14 using base::android::AttachCurrentThread;
15
16 namespace vr_shell {
17
18 VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj)
19 : device_provider_(nullptr) {
20 j_vr_shell_delegate_.Reset(env, obj);
21 GvrDelegateProvider::SetInstance(this);
22 }
23
24 VrShellDelegate::~VrShellDelegate() {
25 GvrDelegateProvider::SetInstance(nullptr);
26 }
27
28 // Returns true if the GvrDeviceProvider needs to handle shutdown first.
29 bool VrShellDelegate::ExitVRIfNecessary(JNIEnv* env, jobject obj) {
30 if (!device_provider_)
31 return false;
32
33 device_provider_->OnGvrDelegateRemoved();
34 return true;
35 }
36
37 bool VrShellDelegate::RequestWebVRPresent(
38 device::GvrDeviceProvider* device_provider) {
39 // Only set one device provider at a time
40 DCHECK(!device_provider_);
41 device_provider_ = device_provider;
42
43 // If/When VRShell is ready for use it will call OnVrShellReady.
44 JNIEnv* env = AttachCurrentThread();
45 return Java_VrShellDelegate_enterWebVRIfNecessary(env,
46 j_vr_shell_delegate_.obj());
47 }
48
49 void VrShellDelegate::ExitWebVRPresent() {
50 if (!device_provider_)
51 return;
52
53 device_provider_ = nullptr;
54
55 // VRShell is no longer needed by WebVR, allow it to shut down if it's not
56 // being used elsewhere.
57 JNIEnv* env = AttachCurrentThread();
58 Java_VrShellDelegate_exitWebVRIfNecessary(env, j_vr_shell_delegate_.obj());
59 }
60
61 void VrShellDelegate::OnVrShellReady(VrShell* vr_shell) {
62 if (device_provider_)
63 device_provider_->OnGvrDelegateReady(vr_shell);
64 }
65
66 // ----------------------------------------------------------------------------
67 // Native JNI methods
68 // ----------------------------------------------------------------------------
69
70 bool RegisterVrShellDelegate(JNIEnv* env) {
71 return RegisterNativesImpl(env);
72 }
73
74 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
75 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj));
76 }
77
78 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698