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 "jni/VrShellDelegate_jni.h" | 13 #include "jni/VrShellDelegate_jni.h" |
| 14 | 14 |
| 15 using base::android::JavaParamRef; | 15 using base::android::JavaParamRef; |
| 16 using base::android::AttachCurrentThread; | 16 using base::android::AttachCurrentThread; |
| 17 | 17 |
| 18 namespace vr_shell { | 18 namespace vr_shell { |
| 19 | 19 |
| 20 VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj) { | 20 VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj) { |
| 21 DVLOG(1) << __FUNCTION__ << "=" << this; | 21 DVLOG(1) << __FUNCTION__ << "=" << this; |
| 22 j_vr_shell_delegate_.Reset(env, obj); | 22 j_vr_shell_delegate_.Reset(env, obj); |
| 23 } | 23 } |
| 24 | 24 |
| 25 VrShellDelegate::~VrShellDelegate() { | 25 VrShellDelegate::~VrShellDelegate() { |
|
mthiesse
2017/03/30 15:29:46
While you're cleaning this up, can you make sure t
tiborg
2017/03/30 22:19:57
Done.
| |
| 26 DVLOG(1) << __FUNCTION__ << "=" << this; | 26 DVLOG(1) << __FUNCTION__ << "=" << this; |
| 27 if (device_provider_) { | 27 if (device_provider_) { |
| 28 device_provider_->Device()->OnExitPresent(); | 28 device_provider_->Device()->OnExitPresent(); |
| 29 device_provider_->Device()->OnDelegateChanged(); | 29 device_provider_->Device()->OnDelegateChanged(); |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 | 32 |
| 33 device::GvrDelegateProvider* VrShellDelegate::CreateVrShellDelegate() { | 33 device::GvrDelegateProvider* VrShellDelegate::CreateVrShellDelegate() { |
| 34 JNIEnv* env = AttachCurrentThread(); | 34 JNIEnv* env = AttachCurrentThread(); |
| 35 base::android::ScopedJavaLocalRef<jobject> jdelegate = | 35 base::android::ScopedJavaLocalRef<jobject> jdelegate = |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 55 JNIEnv* env = AttachCurrentThread(); | 55 JNIEnv* env = AttachCurrentThread(); |
| 56 Java_VrShellDelegate_shutdownNonPresentingNativeContext( | 56 Java_VrShellDelegate_shutdownNonPresentingNativeContext( |
| 57 env, j_vr_shell_delegate_.obj()); | 57 env, j_vr_shell_delegate_.obj()); |
| 58 } | 58 } |
| 59 if (device_provider_) { | 59 if (device_provider_) { |
| 60 device::GvrDevice* device = device_provider_->Device(); | 60 device::GvrDevice* device = device_provider_->Device(); |
| 61 device->OnDelegateChanged(); | 61 device->OnDelegateChanged(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 presenting_delegate_->UpdateVSyncInterval(timebase_nanos_, interval_seconds_); | 64 presenting_delegate_->UpdateVSyncInterval(timebase_nanos_, interval_seconds_); |
| 65 | |
| 66 if (pending_successful_present_request_) { | |
| 67 presenting_delegate_->SetSubmitClient(std::move(submit_client_)); | |
| 68 present_callback_.Run(true); | |
|
mthiesse
2017/03/30 15:29:46
nit: base::ResetAndReturn(presenting_delegate_).Ru
tiborg
2017/03/30 22:19:57
Done.
| |
| 69 present_callback_.Reset(); | |
| 70 pending_successful_present_request_ = false; | |
| 71 } | |
| 65 } | 72 } |
| 66 | 73 |
| 67 void VrShellDelegate::RemoveDelegate() { | 74 void VrShellDelegate::RemoveDelegate() { |
| 68 presenting_delegate_ = nullptr; | 75 presenting_delegate_ = nullptr; |
| 69 if (device_provider_) { | 76 if (device_provider_) { |
| 70 CreateNonPresentingDelegate(); | 77 CreateNonPresentingDelegate(); |
| 71 device_provider_->Device()->OnExitPresent(); | 78 device_provider_->Device()->OnExitPresent(); |
| 72 device_provider_->Device()->OnDelegateChanged(); | 79 device_provider_->Device()->OnDelegateChanged(); |
| 73 } | 80 } |
| 74 } | 81 } |
| 75 | 82 |
| 76 void VrShellDelegate::SetPresentResult(JNIEnv* env, | 83 void VrShellDelegate::SetPresentResult(JNIEnv* env, |
| 77 const JavaParamRef<jobject>& obj, | 84 const JavaParamRef<jobject>& obj, |
| 78 jboolean result) { | 85 jboolean success) { |
| 79 CHECK(!present_callback_.is_null()); | 86 CHECK(!present_callback_.is_null()); |
| 80 present_callback_.Run(result); | 87 if (success && !presenting_delegate_) { |
| 88 // We have to wait until the GL thread is ready since we have to pass it | |
| 89 // the VRSubmitFrameClient. | |
| 90 pending_successful_present_request_ = true; | |
| 91 return; | |
| 92 } | |
| 93 | |
| 94 if (success) { | |
| 95 presenting_delegate_->SetSubmitClient(std::move(submit_client_)); | |
| 96 } | |
| 97 | |
| 98 present_callback_.Run(success); | |
| 81 present_callback_.Reset(); | 99 present_callback_.Reset(); |
| 100 pending_successful_present_request_ = false; | |
| 82 } | 101 } |
| 83 | 102 |
| 84 void VrShellDelegate::DisplayActivate(JNIEnv* env, | 103 void VrShellDelegate::DisplayActivate(JNIEnv* env, |
| 85 const JavaParamRef<jobject>& obj) { | 104 const JavaParamRef<jobject>& obj) { |
| 86 if (device_provider_) { | 105 if (device_provider_) { |
| 87 device_provider_->Device()->OnActivate( | 106 device_provider_->Device()->OnActivate( |
| 88 device::mojom::VRDisplayEventReason::MOUNTED); | 107 device::mojom::VRDisplayEventReason::MOUNTED); |
| 89 } | 108 } |
| 90 } | 109 } |
| 91 | 110 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 114 void VrShellDelegate::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 133 void VrShellDelegate::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 115 if (non_presenting_delegate_) { | 134 if (non_presenting_delegate_) { |
| 116 non_presenting_delegate_->Resume(); | 135 non_presenting_delegate_->Resume(); |
| 117 } | 136 } |
| 118 } | 137 } |
| 119 | 138 |
| 120 void VrShellDelegate::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 139 void VrShellDelegate::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 121 delete this; | 140 delete this; |
| 122 } | 141 } |
| 123 | 142 |
| 124 device::mojom::VRSubmitFrameClientPtr VrShellDelegate::TakeSubmitFrameClient() { | |
| 125 return std::move(submit_client_); | |
| 126 } | |
| 127 | |
| 128 void VrShellDelegate::SetDeviceProvider( | 143 void VrShellDelegate::SetDeviceProvider( |
| 129 device::GvrDeviceProvider* device_provider) { | 144 device::GvrDeviceProvider* device_provider) { |
| 130 if (device_provider_ == device_provider) | 145 if (device_provider_ == device_provider) |
| 131 return; | 146 return; |
| 132 if (device_provider_) | 147 if (device_provider_) |
| 133 ClearDeviceProvider(); | 148 ClearDeviceProvider(); |
| 134 CHECK(!device_provider_); | 149 CHECK(!device_provider_); |
| 135 device_provider_ = device_provider; | 150 device_provider_ = device_provider; |
| 136 if (!presenting_delegate_) { | 151 if (!presenting_delegate_) { |
| 137 CreateNonPresentingDelegate(); | 152 CreateNonPresentingDelegate(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 222 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 208 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); | 223 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); |
| 209 } | 224 } |
| 210 | 225 |
| 211 static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) { | 226 static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) { |
| 212 device::GvrDelegateProvider::SetInstance( | 227 device::GvrDelegateProvider::SetInstance( |
| 213 base::Bind(&VrShellDelegate::CreateVrShellDelegate)); | 228 base::Bind(&VrShellDelegate::CreateVrShellDelegate)); |
| 214 } | 229 } |
| 215 | 230 |
| 216 } // namespace vr_shell | 231 } // namespace vr_shell |
| OLD | NEW |