| OLD | NEW |
| 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 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" | 5 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "chrome/browser/android/vr_shell/vr_shell.h" | 8 #include "chrome/browser/android/vr_shell/vr_shell.h" |
| 9 #include "device/vr/android/gvr/gvr_device_provider.h" | 9 #include "device/vr/android/gvr/gvr_device_provider.h" |
| 10 #include "jni/VrShellDelegate_jni.h" | 10 #include "jni/VrShellDelegate_jni.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 VrShellDelegate* VrShellDelegate::GetNativeDelegate( | 56 VrShellDelegate* VrShellDelegate::GetNativeDelegate( |
| 57 JNIEnv* env, jobject jdelegate) { | 57 JNIEnv* env, jobject jdelegate) { |
| 58 long native_delegate = Java_VrShellDelegate_getNativePointer(env, jdelegate); | 58 long native_delegate = Java_VrShellDelegate_getNativePointer(env, jdelegate); |
| 59 return reinterpret_cast<VrShellDelegate*>(native_delegate); | 59 return reinterpret_cast<VrShellDelegate*>(native_delegate); |
| 60 } | 60 } |
| 61 | 61 |
| 62 base::WeakPtr<device::GvrDeviceProvider> VrShellDelegate::GetDeviceProvider() { | 62 base::WeakPtr<device::GvrDeviceProvider> VrShellDelegate::GetDeviceProvider() { |
| 63 return device_provider_; | 63 return device_provider_; |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool VrShellDelegate::RequestWebVRPresent( | 66 void VrShellDelegate::SetPresentResult(JNIEnv* env, jobject obj, |
| 67 base::WeakPtr<device::GvrDeviceProvider> device_provider) { | 67 jboolean result) { |
| 68 // Only set one device provider at a time | 68 CHECK(!present_callback_.is_null()); |
| 69 DCHECK(!device_provider_); | 69 present_callback_.Run(result); |
| 70 present_callback_.Reset(); |
| 71 } |
| 72 |
| 73 void VrShellDelegate::RequestWebVRPresent( |
| 74 base::WeakPtr<device::GvrDeviceProvider> device_provider, |
| 75 const base::Callback<void(bool)>& callback) { |
| 76 if (!present_callback_.is_null()) { |
| 77 // Can only handle one request at a time. This is also extremely unlikely to |
| 78 // happen in practice. |
| 79 callback.Run(false); |
| 80 return; |
| 81 } |
| 82 |
| 83 // TODO(mthiesse): Clean this up, there's no reason to be setting the device |
| 84 // provider from RequestWebVRPresent. |
| 70 device_provider_ = device_provider; | 85 device_provider_ = device_provider; |
| 86 present_callback_ = std::move(callback); |
| 71 | 87 |
| 72 // If/When VRShell is ready for use it will call OnVrShellReady. | 88 // If/When VRShell is ready for use it will call SetPresentResult. |
| 73 JNIEnv* env = AttachCurrentThread(); | 89 JNIEnv* env = AttachCurrentThread(); |
| 74 Java_VrShellDelegate_enterVRIfNecessary(env, j_vr_shell_delegate_.obj(), | 90 Java_VrShellDelegate_presentRequested(env, j_vr_shell_delegate_.obj(), true); |
| 75 true); | |
| 76 return true; | |
| 77 } | 91 } |
| 78 | 92 |
| 79 void VrShellDelegate::ExitWebVRPresent() { | 93 void VrShellDelegate::ExitWebVRPresent() { |
| 80 device_provider_.reset(); | |
| 81 | |
| 82 // VRShell is no longer needed by WebVR, allow it to shut down if it's not | 94 // VRShell is no longer needed by WebVR, allow it to shut down if it's not |
| 83 // being used elsewhere. | 95 // being used elsewhere. |
| 84 JNIEnv* env = AttachCurrentThread(); | 96 JNIEnv* env = AttachCurrentThread(); |
| 85 Java_VrShellDelegate_exitWebVR(env, j_vr_shell_delegate_.obj()); | 97 Java_VrShellDelegate_exitWebVR(env, j_vr_shell_delegate_.obj()); |
| 86 } | 98 } |
| 87 | 99 |
| 88 base::WeakPtr<device::GvrDelegate> VrShellDelegate::GetNonPresentingDelegate() { | 100 base::WeakPtr<device::GvrDelegate> VrShellDelegate::GetNonPresentingDelegate() { |
| 89 if (!non_presenting_delegate_) { | 101 if (!non_presenting_delegate_) { |
| 90 JNIEnv* env = AttachCurrentThread(); | 102 JNIEnv* env = AttachCurrentThread(); |
| 91 jlong context = Java_VrShellDelegate_createNonPresentingNativeContext( | 103 jlong context = Java_VrShellDelegate_createNonPresentingNativeContext( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 114 | 126 |
| 115 bool RegisterVrShellDelegate(JNIEnv* env) { | 127 bool RegisterVrShellDelegate(JNIEnv* env) { |
| 116 return RegisterNativesImpl(env); | 128 return RegisterNativesImpl(env); |
| 117 } | 129 } |
| 118 | 130 |
| 119 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 131 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 120 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); | 132 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); |
| 121 } | 133 } |
| 122 | 134 |
| 123 } // namespace vr_shell | 135 } // namespace vr_shell |
| OLD | NEW |