| 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 "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "chrome/browser/android/vr_shell/non_presenting_gvr_delegate.h" | 11 #include "chrome/browser/android/vr_shell/non_presenting_gvr_delegate.h" |
| 12 #include "chrome/browser/android/vr_shell/vr_metrics_util.h" |
| 12 #include "device/vr/android/gvr/gvr_delegate.h" | 13 #include "device/vr/android/gvr/gvr_delegate.h" |
| 13 #include "device/vr/android/gvr/gvr_device.h" | 14 #include "device/vr/android/gvr/gvr_device.h" |
| 14 #include "device/vr/android/gvr/gvr_device_provider.h" | 15 #include "device/vr/android/gvr/gvr_device_provider.h" |
| 15 #include "jni/VrShellDelegate_jni.h" | 16 #include "jni/VrShellDelegate_jni.h" |
| 16 | 17 |
| 17 using base::android::JavaParamRef; | 18 using base::android::JavaParamRef; |
| 18 using base::android::AttachCurrentThread; | 19 using base::android::AttachCurrentThread; |
| 20 using base::android::ScopedJavaLocalRef; |
| 19 | 21 |
| 20 namespace vr_shell { | 22 namespace vr_shell { |
| 21 | 23 |
| 22 VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj) | 24 VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj) |
| 23 : weak_ptr_factory_(this) { | 25 : weak_ptr_factory_(this) { |
| 24 DVLOG(1) << __FUNCTION__ << "=" << this; | 26 DVLOG(1) << __FUNCTION__ << "=" << this; |
| 25 j_vr_shell_delegate_.Reset(env, obj); | 27 j_vr_shell_delegate_.Reset(env, obj); |
| 26 } | 28 } |
| 27 | 29 |
| 28 VrShellDelegate::~VrShellDelegate() { | 30 VrShellDelegate::~VrShellDelegate() { |
| 29 DVLOG(1) << __FUNCTION__ << "=" << this; | 31 DVLOG(1) << __FUNCTION__ << "=" << this; |
| 30 if (device_provider_) { | 32 if (device_provider_) { |
| 31 device_provider_->Device()->OnExitPresent(); | 33 device_provider_->Device()->OnExitPresent(); |
| 32 device_provider_->Device()->OnDelegateChanged(); | 34 device_provider_->Device()->OnDelegateChanged(); |
| 33 } | 35 } |
| 34 if (!present_callback_.is_null()) { | 36 if (!present_callback_.is_null()) { |
| 35 base::ResetAndReturn(&present_callback_).Run(false); | 37 base::ResetAndReturn(&present_callback_).Run(false); |
| 36 } | 38 } |
| 37 } | 39 } |
| 38 | 40 |
| 39 device::GvrDelegateProvider* VrShellDelegate::CreateVrShellDelegate() { | 41 device::GvrDelegateProvider* VrShellDelegate::CreateVrShellDelegate() { |
| 40 JNIEnv* env = AttachCurrentThread(); | 42 JNIEnv* env = AttachCurrentThread(); |
| 41 base::android::ScopedJavaLocalRef<jobject> jdelegate = | 43 ScopedJavaLocalRef<jobject> jdelegate = Java_VrShellDelegate_getInstance(env); |
| 42 Java_VrShellDelegate_getInstance(env); | |
| 43 if (!jdelegate.is_null()) | 44 if (!jdelegate.is_null()) |
| 44 return GetNativeVrShellDelegate(env, jdelegate.obj()); | 45 return GetNativeVrShellDelegate(env, jdelegate.obj()); |
| 45 return nullptr; | 46 return nullptr; |
| 46 } | 47 } |
| 47 | 48 |
| 48 VrShellDelegate* VrShellDelegate::GetNativeVrShellDelegate(JNIEnv* env, | 49 VrShellDelegate* VrShellDelegate::GetNativeVrShellDelegate(JNIEnv* env, |
| 49 jobject jdelegate) { | 50 jobject jdelegate) { |
| 50 return reinterpret_cast<VrShellDelegate*>( | 51 return reinterpret_cast<VrShellDelegate*>( |
| 51 Java_VrShellDelegate_getNativePointer(env, jdelegate)); | 52 Java_VrShellDelegate_getNativePointer(env, jdelegate)); |
| 52 } | 53 } |
| 53 | 54 |
| 54 void VrShellDelegate::SetPresentingDelegate( | 55 void VrShellDelegate::SetPresentingDelegate( |
| 55 device::PresentingGvrDelegate* delegate, | 56 device::PresentingGvrDelegate* delegate, |
| 56 gvr_context* context) { | 57 gvr_context* context) { |
| 57 presenting_delegate_ = delegate; | 58 presenting_delegate_ = delegate; |
| 58 // Clean up the non-presenting delegate. | 59 // Clean up the non-presenting delegate. |
| 60 JNIEnv* env = AttachCurrentThread(); |
| 59 if (presenting_delegate_ && non_presenting_delegate_) { | 61 if (presenting_delegate_ && non_presenting_delegate_) { |
| 60 non_presenting_delegate_ = nullptr; | 62 non_presenting_delegate_ = nullptr; |
| 61 JNIEnv* env = AttachCurrentThread(); | |
| 62 Java_VrShellDelegate_shutdownNonPresentingNativeContext( | 63 Java_VrShellDelegate_shutdownNonPresentingNativeContext( |
| 63 env, j_vr_shell_delegate_.obj()); | 64 env, j_vr_shell_delegate_.obj()); |
| 64 } | 65 } |
| 65 if (device_provider_) { | 66 if (device_provider_) { |
| 66 device::GvrDevice* device = device_provider_->Device(); | 67 device::GvrDevice* device = device_provider_->Device(); |
| 67 device->OnDelegateChanged(); | 68 device->OnDelegateChanged(); |
| 68 } | 69 } |
| 69 | 70 |
| 70 presenting_delegate_->UpdateVSyncInterval(timebase_nanos_, interval_seconds_); | 71 presenting_delegate_->UpdateVSyncInterval(timebase_nanos_, interval_seconds_); |
| 71 | 72 |
| 72 if (pending_successful_present_request_) { | 73 if (pending_successful_present_request_) { |
| 73 presenting_delegate_->SetSubmitClient(std::move(submit_client_)); | 74 presenting_delegate_->SetSubmitClient(std::move(submit_client_)); |
| 74 base::ResetAndReturn(&present_callback_).Run(true); | 75 base::ResetAndReturn(&present_callback_).Run(true); |
| 75 pending_successful_present_request_ = false; | 76 pending_successful_present_request_ = false; |
| 76 } | 77 } |
| 78 |
| 79 std::unique_ptr<VrCoreInfo> vr_core_info = MakeVrCoreInfo(env); |
| 80 VrMetricsUtil::LogGvrVersionForVrViewerType(context, *vr_core_info); |
| 77 } | 81 } |
| 78 | 82 |
| 79 void VrShellDelegate::RemoveDelegate() { | 83 void VrShellDelegate::RemoveDelegate() { |
| 80 presenting_delegate_ = nullptr; | 84 presenting_delegate_ = nullptr; |
| 81 if (device_provider_) { | 85 if (device_provider_) { |
| 82 CreateNonPresentingDelegate(); | 86 CreateNonPresentingDelegate(); |
| 83 device_provider_->Device()->OnExitPresent(); | 87 device_provider_->Device()->OnExitPresent(); |
| 84 device_provider_->Device()->OnDelegateChanged(); | 88 device_provider_->Device()->OnDelegateChanged(); |
| 85 } | 89 } |
| 86 } | 90 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 // VRShell is no longer needed by WebVR, allow it to shut down if it's not | 202 // VRShell is no longer needed by WebVR, allow it to shut down if it's not |
| 199 // being used elsewhere. | 203 // being used elsewhere. |
| 200 JNIEnv* env = AttachCurrentThread(); | 204 JNIEnv* env = AttachCurrentThread(); |
| 201 if (Java_VrShellDelegate_exitWebVRPresent(env, j_vr_shell_delegate_.obj())) { | 205 if (Java_VrShellDelegate_exitWebVRPresent(env, j_vr_shell_delegate_.obj())) { |
| 202 if (device_provider_) { | 206 if (device_provider_) { |
| 203 device_provider_->Device()->OnExitPresent(); | 207 device_provider_->Device()->OnExitPresent(); |
| 204 } | 208 } |
| 205 } | 209 } |
| 206 } | 210 } |
| 207 | 211 |
| 212 std::unique_ptr<VrCoreInfo> VrShellDelegate::MakeVrCoreInfo(JNIEnv* env) { |
| 213 return base::WrapUnique(reinterpret_cast<VrCoreInfo*>( |
| 214 Java_VrShellDelegate_getVrCoreInfo(env, j_vr_shell_delegate_.obj()))); |
| 215 } |
| 216 |
| 208 void VrShellDelegate::CreateNonPresentingDelegate() { | 217 void VrShellDelegate::CreateNonPresentingDelegate() { |
| 209 JNIEnv* env = AttachCurrentThread(); | 218 JNIEnv* env = AttachCurrentThread(); |
| 210 gvr_context* context = reinterpret_cast<gvr_context*>( | 219 gvr_context* context = reinterpret_cast<gvr_context*>( |
| 211 Java_VrShellDelegate_createNonPresentingNativeContext( | 220 Java_VrShellDelegate_createNonPresentingNativeContext( |
| 212 env, j_vr_shell_delegate_.obj())); | 221 env, j_vr_shell_delegate_.obj())); |
| 213 non_presenting_delegate_ = | 222 non_presenting_delegate_ = |
| 214 base::MakeUnique<NonPresentingGvrDelegate>(context); | 223 base::MakeUnique<NonPresentingGvrDelegate>(context); |
| 215 non_presenting_delegate_->UpdateVSyncInterval(timebase_nanos_, | 224 non_presenting_delegate_->UpdateVSyncInterval(timebase_nanos_, |
| 216 interval_seconds_); | 225 interval_seconds_); |
| 226 std::unique_ptr<VrCoreInfo> vr_core_info = MakeVrCoreInfo(env); |
| 227 VrMetricsUtil::LogGvrVersionForVrViewerType(context, *vr_core_info); |
| 217 } | 228 } |
| 218 | 229 |
| 219 void VrShellDelegate::OnActivateDisplayHandled(bool will_not_present) { | 230 void VrShellDelegate::OnActivateDisplayHandled(bool will_not_present) { |
| 220 if (will_not_present) { | 231 if (will_not_present) { |
| 221 // WebVR page didn't request presentation in the vrdisplayactivate handler. | 232 // WebVR page didn't request presentation in the vrdisplayactivate handler. |
| 222 // Tell VrShell that we are in VR Browsing Mode. | 233 // Tell VrShell that we are in VR Browsing Mode. |
| 223 ExitWebVRPresent(); | 234 ExitWebVRPresent(); |
| 224 } | 235 } |
| 225 } | 236 } |
| 226 | 237 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 247 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 258 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 248 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); | 259 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); |
| 249 } | 260 } |
| 250 | 261 |
| 251 static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) { | 262 static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) { |
| 252 device::GvrDelegateProvider::SetInstance( | 263 device::GvrDelegateProvider::SetInstance( |
| 253 base::Bind(&VrShellDelegate::CreateVrShellDelegate)); | 264 base::Bind(&VrShellDelegate::CreateVrShellDelegate)); |
| 254 } | 265 } |
| 255 | 266 |
| 256 } // namespace vr_shell | 267 } // namespace vr_shell |
| OLD | NEW |