Chromium Code Reviews| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "chrome/browser/android/vr_shell/non_presenting_gvr_delegate.h" | 10 #include "chrome/browser/android/vr_shell/non_presenting_gvr_delegate.h" |
| 11 #include "device/vr/android/gvr/gvr_device.h" | 11 #include "device/vr/android/gvr/gvr_device.h" |
| 12 #include "device/vr/android/gvr/gvr_device_provider.h" | 12 #include "device/vr/android/gvr/gvr_device_provider.h" |
| 13 #include "device/vr/android/gvr/gvr_gamepad_data_fetcher.h" | 13 #include "device/vr/android/gvr/gvr_gamepad_data_fetcher.h" |
| 14 #include "jni/VrShellDelegate_jni.h" | 14 #include "jni/VrShellDelegate_jni.h" |
| 15 | 15 |
| 16 using base::android::JavaParamRef; | 16 using base::android::JavaParamRef; |
| 17 using base::android::AttachCurrentThread; | 17 using base::android::AttachCurrentThread; |
| 18 | 18 |
| 19 namespace vr_shell { | 19 namespace vr_shell { |
| 20 | 20 |
| 21 VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj) | 21 VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj) |
| 22 : weak_ptr_factory_(this) { | 22 : weak_ptr_factory_(this) { |
| 23 j_vr_shell_delegate_.Reset(env, obj); | 23 j_vr_shell_delegate_.Reset(env, obj); |
| 24 GvrDelegateProvider::SetInstance(this); | |
| 25 } | 24 } |
| 26 | 25 |
| 27 VrShellDelegate::~VrShellDelegate() { | 26 VrShellDelegate::~VrShellDelegate() { |
| 28 GvrDelegateProvider::SetInstance(nullptr); | |
| 29 if (device_provider_) { | 27 if (device_provider_) { |
| 30 device_provider_->Device()->OnDelegateChanged(); | 28 device_provider_->Device()->OnDelegateChanged(); |
| 31 } | 29 } |
| 32 } | 30 } |
| 33 | 31 |
| 32 device::GvrDelegateProvider* VrShellDelegate::CreateVrShellDelegate() { | |
| 33 JNIEnv* env = AttachCurrentThread(); | |
| 34 base::android::ScopedJavaLocalRef<jobject> jdelegate = | |
| 35 Java_VrShellDelegate_getInstance(env); | |
| 36 if (!jdelegate.is_null()) | |
| 37 return GetNativeVrShellDelegate(env, jdelegate.obj()); | |
|
amp
2017/03/02 18:11:54
It looks it's possible for jdelegate to be non nul
mthiesse
2017/03/02 20:01:58
Fixed. jdelegate is never null now.
| |
| 38 return nullptr; | |
| 39 } | |
| 40 | |
| 34 VrShellDelegate* VrShellDelegate::GetNativeVrShellDelegate(JNIEnv* env, | 41 VrShellDelegate* VrShellDelegate::GetNativeVrShellDelegate(JNIEnv* env, |
| 35 jobject jdelegate) { | 42 jobject jdelegate) { |
| 36 return reinterpret_cast<VrShellDelegate*>( | 43 return reinterpret_cast<VrShellDelegate*>( |
| 37 Java_VrShellDelegate_getNativePointer(env, jdelegate)); | 44 Java_VrShellDelegate_getNativePointer(env, jdelegate)); |
| 38 } | 45 } |
| 39 | 46 |
| 40 void VrShellDelegate::SetDelegate(device::GvrDelegate* delegate, | 47 void VrShellDelegate::SetDelegate(device::GvrDelegate* delegate, |
| 41 gvr_context* context) { | 48 gvr_context* context) { |
| 42 context_ = context; | 49 context_ = context; |
| 43 delegate_ = delegate; | 50 delegate_ = delegate; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 non_presenting_delegate_->Pause(); | 115 non_presenting_delegate_->Pause(); |
| 109 } | 116 } |
| 110 } | 117 } |
| 111 | 118 |
| 112 void VrShellDelegate::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 119 void VrShellDelegate::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 113 if (non_presenting_delegate_) { | 120 if (non_presenting_delegate_) { |
| 114 non_presenting_delegate_->Resume(); | 121 non_presenting_delegate_->Resume(); |
| 115 } | 122 } |
| 116 } | 123 } |
| 117 | 124 |
| 125 void VrShellDelegate::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { | |
| 126 delete this; | |
| 127 } | |
| 128 | |
| 118 void VrShellDelegate::ShowTab(int id) { | 129 void VrShellDelegate::ShowTab(int id) { |
| 119 JNIEnv* env = AttachCurrentThread(); | 130 JNIEnv* env = AttachCurrentThread(); |
| 120 Java_VrShellDelegate_showTab(env, j_vr_shell_delegate_.obj(), id); | 131 Java_VrShellDelegate_showTab(env, j_vr_shell_delegate_.obj(), id); |
| 121 } | 132 } |
| 122 | 133 |
| 123 void VrShellDelegate::SetDeviceProvider( | 134 void VrShellDelegate::SetDeviceProvider( |
| 124 device::GvrDeviceProvider* device_provider) { | 135 device::GvrDeviceProvider* device_provider) { |
| 125 CHECK(!device_provider_); | 136 CHECK(!device_provider_); |
| 126 device_provider_ = device_provider; | 137 device_provider_ = device_provider; |
| 127 if (!delegate_) | 138 if (!delegate_) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 // ---------------------------------------------------------------------------- | 212 // ---------------------------------------------------------------------------- |
| 202 | 213 |
| 203 bool RegisterVrShellDelegate(JNIEnv* env) { | 214 bool RegisterVrShellDelegate(JNIEnv* env) { |
| 204 return RegisterNativesImpl(env); | 215 return RegisterNativesImpl(env); |
| 205 } | 216 } |
| 206 | 217 |
| 207 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 218 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 208 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); | 219 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); |
| 209 } | 220 } |
| 210 | 221 |
| 222 static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) { | |
| 223 device::GvrDelegateProvider::SetInstance( | |
| 224 base::Bind(&VrShellDelegate::CreateVrShellDelegate)); | |
| 225 } | |
| 226 | |
| 211 } // namespace vr_shell | 227 } // namespace vr_shell |
| OLD | NEW |