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

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: Addressed tedchoc@'s last feedback 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 VrShellDelegate* VrShellDelegate::getNativePointer(
29 JNIEnv* env, jobject jdelegate) {
30 long native_delegate = Java_VrShellDelegate_getNativePointer(env, jdelegate);
31 return reinterpret_cast<VrShellDelegate*>(native_delegate);
32 }
33
34 // Returns true if the GvrDeviceProvider needs to handle shutdown first.
Ted C 2016/09/21 17:59:25 would this fit better in the header?
35 bool VrShellDelegate::ExitWebVRIfNecessary(JNIEnv* env, jobject obj) {
36 if (!device_provider_)
37 return false;
38
39 device_provider_->OnGvrDelegateRemoved();
40 return true;
41 }
42
43 bool VrShellDelegate::RequestWebVRPresent(
44 device::GvrDeviceProvider* device_provider) {
45 // Only set one device provider at a time
46 DCHECK(!device_provider_);
47 device_provider_ = device_provider;
48
49 // If/When VRShell is ready for use it will call OnVrShellReady.
50 JNIEnv* env = AttachCurrentThread();
51 return Java_VrShellDelegate_enterVRIfNecessary(env,
52 j_vr_shell_delegate_.obj(),
53 true);
54 }
55
56 void VrShellDelegate::ExitWebVRPresent() {
57 if (!device_provider_)
58 return;
59
60 device_provider_ = nullptr;
61
62 // VRShell is no longer needed by WebVR, allow it to shut down if it's not
63 // being used elsewhere.
64 JNIEnv* env = AttachCurrentThread();
65 Java_VrShellDelegate_exitWebVR(env, j_vr_shell_delegate_.obj());
66 }
67
68 void VrShellDelegate::OnVrShellReady(VrShell* vr_shell) {
69 if (device_provider_)
70 device_provider_->OnGvrDelegateReady(vr_shell);
71 }
72
73 // ----------------------------------------------------------------------------
74 // Native JNI methods
75 // ----------------------------------------------------------------------------
76
77 bool RegisterVrShellDelegate(JNIEnv* env) {
78 return RegisterNativesImpl(env);
79 }
80
81 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
82 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj));
83 }
84
85 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698