| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 return device_provider_; | 63 return device_provider_; |
| 64 } | 64 } |
| 65 | 65 |
| 66 void VrShellDelegate::SetPresentResult(JNIEnv* env, jobject obj, | 66 void VrShellDelegate::SetPresentResult(JNIEnv* env, jobject obj, |
| 67 jboolean result) { | 67 jboolean result) { |
| 68 CHECK(!present_callback_.is_null()); | 68 CHECK(!present_callback_.is_null()); |
| 69 present_callback_.Run(result); | 69 present_callback_.Run(result); |
| 70 present_callback_.Reset(); | 70 present_callback_.Reset(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void VrShellDelegate::DisplayActivate(JNIEnv* env, jobject obj) { |
| 74 if (device_provider_) { |
| 75 device_provider_->OnDisplayActivate(); |
| 76 } |
| 77 } |
| 78 |
| 79 void VrShellDelegate::SetDeviceProvider( |
| 80 base::WeakPtr<device::GvrDeviceProvider> device_provider) { |
| 81 device_provider_ = device_provider; |
| 82 } |
| 83 |
| 73 void VrShellDelegate::RequestWebVRPresent( | 84 void VrShellDelegate::RequestWebVRPresent( |
| 74 base::WeakPtr<device::GvrDeviceProvider> device_provider, | |
| 75 const base::Callback<void(bool)>& callback) { | 85 const base::Callback<void(bool)>& callback) { |
| 76 if (!present_callback_.is_null()) { | 86 if (!present_callback_.is_null()) { |
| 77 // Can only handle one request at a time. This is also extremely unlikely to | 87 // Can only handle one request at a time. This is also extremely unlikely to |
| 78 // happen in practice. | 88 // happen in practice. |
| 79 callback.Run(false); | 89 callback.Run(false); |
| 80 return; | 90 return; |
| 81 } | 91 } |
| 82 | 92 |
| 83 // TODO(mthiesse): Clean this up, there's no reason to be setting the device | |
| 84 // provider from RequestWebVRPresent. | |
| 85 device_provider_ = device_provider; | |
| 86 present_callback_ = std::move(callback); | 93 present_callback_ = std::move(callback); |
| 87 | 94 |
| 88 // If/When VRShell is ready for use it will call SetPresentResult. | 95 // If/When VRShell is ready for use it will call SetPresentResult. |
| 89 JNIEnv* env = AttachCurrentThread(); | 96 JNIEnv* env = AttachCurrentThread(); |
| 90 Java_VrShellDelegate_presentRequested(env, j_vr_shell_delegate_.obj(), true); | 97 Java_VrShellDelegate_presentRequested(env, j_vr_shell_delegate_.obj(), true); |
| 91 } | 98 } |
| 92 | 99 |
| 93 void VrShellDelegate::ExitWebVRPresent() { | 100 void VrShellDelegate::ExitWebVRPresent() { |
| 94 // VRShell is no longer needed by WebVR, allow it to shut down if it's not | 101 // VRShell is no longer needed by WebVR, allow it to shut down if it's not |
| 95 // being used elsewhere. | 102 // being used elsewhere. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 139 |
| 133 bool RegisterVrShellDelegate(JNIEnv* env) { | 140 bool RegisterVrShellDelegate(JNIEnv* env) { |
| 134 return RegisterNativesImpl(env); | 141 return RegisterNativesImpl(env); |
| 135 } | 142 } |
| 136 | 143 |
| 137 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 144 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 138 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); | 145 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); |
| 139 } | 146 } |
| 140 | 147 |
| 141 } // namespace vr_shell | 148 } // namespace vr_shell |
| OLD | NEW |