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" |
(...skipping 28 matching lines...) Expand all Loading... |
39 } | 39 } |
40 | 40 |
41 VrShellDelegate* VrShellDelegate::GetNativeVrShellDelegate(JNIEnv* env, | 41 VrShellDelegate* VrShellDelegate::GetNativeVrShellDelegate(JNIEnv* env, |
42 jobject jdelegate) { | 42 jobject jdelegate) { |
43 return reinterpret_cast<VrShellDelegate*>( | 43 return reinterpret_cast<VrShellDelegate*>( |
44 Java_VrShellDelegate_getNativePointer(env, jdelegate)); | 44 Java_VrShellDelegate_getNativePointer(env, jdelegate)); |
45 } | 45 } |
46 | 46 |
47 void VrShellDelegate::SetDelegate(device::GvrDelegate* delegate, | 47 void VrShellDelegate::SetDelegate(device::GvrDelegate* delegate, |
48 gvr_context* context) { | 48 gvr_context* context) { |
49 context_ = context; | |
50 delegate_ = delegate; | 49 delegate_ = delegate; |
51 // Clean up the non-presenting delegate. | 50 // Clean up the non-presenting delegate. |
52 if (non_presenting_delegate_) { | 51 if (delegate_ && non_presenting_delegate_) { |
53 device::mojom::VRVSyncProviderRequest request = | |
54 non_presenting_delegate_->OnSwitchToPresentingDelegate(); | |
55 if (request.is_pending()) | |
56 delegate->OnVRVsyncProviderRequest(std::move(request)); | |
57 non_presenting_delegate_ = nullptr; | 52 non_presenting_delegate_ = nullptr; |
58 JNIEnv* env = AttachCurrentThread(); | 53 JNIEnv* env = AttachCurrentThread(); |
59 Java_VrShellDelegate_shutdownNonPresentingNativeContext( | 54 Java_VrShellDelegate_shutdownNonPresentingNativeContext( |
60 env, j_vr_shell_delegate_.obj()); | 55 env, j_vr_shell_delegate_.obj()); |
61 } | 56 } |
62 if (device_provider_) { | 57 if (device_provider_) { |
63 device::GvrDevice* device = device_provider_->Device(); | 58 device::GvrDevice* device = device_provider_->Device(); |
64 device::GamepadDataFetcherManager::GetInstance()->AddFactory( | 59 device::GamepadDataFetcherManager::GetInstance()->AddFactory( |
65 new device::GvrGamepadDataFetcher::Factory(context, device->id())); | 60 new device::GvrGamepadDataFetcher::Factory(context, device->id())); |
66 device->OnDelegateChanged(); | 61 device->OnDelegateChanged(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 void VrShellDelegate::ShowTab(int id) { | 124 void VrShellDelegate::ShowTab(int id) { |
130 JNIEnv* env = AttachCurrentThread(); | 125 JNIEnv* env = AttachCurrentThread(); |
131 Java_VrShellDelegate_showTab(env, j_vr_shell_delegate_.obj(), id); | 126 Java_VrShellDelegate_showTab(env, j_vr_shell_delegate_.obj(), id); |
132 } | 127 } |
133 | 128 |
134 void VrShellDelegate::OpenNewTab(bool incognito) { | 129 void VrShellDelegate::OpenNewTab(bool incognito) { |
135 JNIEnv* env = AttachCurrentThread(); | 130 JNIEnv* env = AttachCurrentThread(); |
136 Java_VrShellDelegate_openNewTab(env, j_vr_shell_delegate_.obj(), incognito); | 131 Java_VrShellDelegate_openNewTab(env, j_vr_shell_delegate_.obj(), incognito); |
137 } | 132 } |
138 | 133 |
| 134 device::mojom::VRSubmitFrameClientPtr VrShellDelegate::TakeSubmitFrameClient() { |
| 135 return std::move(submit_client_); |
| 136 } |
| 137 |
139 void VrShellDelegate::SetDeviceProvider( | 138 void VrShellDelegate::SetDeviceProvider( |
140 device::GvrDeviceProvider* device_provider) { | 139 device::GvrDeviceProvider* device_provider) { |
| 140 if (device_provider_ == device_provider) |
| 141 return; |
| 142 if (device_provider_) |
| 143 ClearDeviceProvider(); |
141 CHECK(!device_provider_); | 144 CHECK(!device_provider_); |
142 device_provider_ = device_provider; | 145 device_provider_ = device_provider; |
143 if (!delegate_) | 146 if (!delegate_) |
144 CreateNonPresentingDelegate(); | 147 CreateNonPresentingDelegate(); |
145 device_provider_->Device()->OnDelegateChanged(); | 148 device_provider_->Device()->OnDelegateChanged(); |
146 } | 149 } |
147 | 150 |
148 void VrShellDelegate::ClearDeviceProvider() { | 151 void VrShellDelegate::ClearDeviceProvider() { |
149 non_presenting_delegate_ = nullptr; | 152 non_presenting_delegate_ = nullptr; |
150 JNIEnv* env = AttachCurrentThread(); | 153 JNIEnv* env = AttachCurrentThread(); |
151 Java_VrShellDelegate_shutdownNonPresentingNativeContext( | 154 Java_VrShellDelegate_shutdownNonPresentingNativeContext( |
152 env, j_vr_shell_delegate_.obj()); | 155 env, j_vr_shell_delegate_.obj()); |
153 device_provider_ = nullptr; | 156 device_provider_ = nullptr; |
154 } | 157 } |
155 | 158 |
156 void VrShellDelegate::RequestWebVRPresent( | 159 void VrShellDelegate::RequestWebVRPresent( |
| 160 device::mojom::VRSubmitFrameClientPtr submit_client, |
157 const base::Callback<void(bool)>& callback) { | 161 const base::Callback<void(bool)>& callback) { |
158 if (!present_callback_.is_null()) { | 162 if (!present_callback_.is_null()) { |
159 // Can only handle one request at a time. This is also extremely unlikely to | 163 // Can only handle one request at a time. This is also extremely unlikely to |
160 // happen in practice. | 164 // happen in practice. |
161 callback.Run(false); | 165 callback.Run(false); |
162 return; | 166 return; |
163 } | 167 } |
164 | 168 |
165 present_callback_ = std::move(callback); | 169 present_callback_ = std::move(callback); |
| 170 submit_client_ = std::move(submit_client); |
166 | 171 |
167 // If/When VRShell is ready for use it will call SetPresentResult. | 172 // If/When VRShell is ready for use it will call SetPresentResult. |
168 JNIEnv* env = AttachCurrentThread(); | 173 JNIEnv* env = AttachCurrentThread(); |
169 Java_VrShellDelegate_presentRequested(env, j_vr_shell_delegate_.obj()); | 174 Java_VrShellDelegate_presentRequested(env, j_vr_shell_delegate_.obj()); |
170 } | 175 } |
171 | 176 |
172 void VrShellDelegate::ExitWebVRPresent() { | 177 void VrShellDelegate::ExitWebVRPresent() { |
173 // VRShell is no longer needed by WebVR, allow it to shut down if it's not | 178 // VRShell is no longer needed by WebVR, allow it to shut down if it's not |
174 // being used elsewhere. | 179 // being used elsewhere. |
175 JNIEnv* env = AttachCurrentThread(); | 180 JNIEnv* env = AttachCurrentThread(); |
176 Java_VrShellDelegate_exitWebVR(env, j_vr_shell_delegate_.obj()); | 181 Java_VrShellDelegate_exitWebVR(env, j_vr_shell_delegate_.obj()); |
177 } | 182 } |
178 | 183 |
179 base::WeakPtr<VrShellDelegate> VrShellDelegate::GetWeakPtr() { | 184 base::WeakPtr<VrShellDelegate> VrShellDelegate::GetWeakPtr() { |
180 return weak_ptr_factory_.GetWeakPtr(); | 185 return weak_ptr_factory_.GetWeakPtr(); |
181 } | 186 } |
182 | 187 |
183 void VrShellDelegate::OnVRVsyncProviderRequest( | |
184 device::mojom::VRVSyncProviderRequest request) { | |
185 GetDelegate()->OnVRVsyncProviderRequest(std::move(request)); | |
186 } | |
187 | |
188 void VrShellDelegate::CreateNonPresentingDelegate() { | 188 void VrShellDelegate::CreateNonPresentingDelegate() { |
189 JNIEnv* env = AttachCurrentThread(); | 189 JNIEnv* env = AttachCurrentThread(); |
190 gvr_context* context = reinterpret_cast<gvr_context*>( | 190 gvr_context* context = reinterpret_cast<gvr_context*>( |
191 Java_VrShellDelegate_createNonPresentingNativeContext( | 191 Java_VrShellDelegate_createNonPresentingNativeContext( |
192 env, j_vr_shell_delegate_.obj())); | 192 env, j_vr_shell_delegate_.obj())); |
193 if (!context) | |
194 return; | |
195 context_ = context; | |
196 non_presenting_delegate_ = | 193 non_presenting_delegate_ = |
197 base::MakeUnique<NonPresentingGvrDelegate>(context); | 194 base::MakeUnique<NonPresentingGvrDelegate>(context); |
198 non_presenting_delegate_->UpdateVSyncInterval(timebase_nanos_, | 195 non_presenting_delegate_->UpdateVSyncInterval(timebase_nanos_, |
199 interval_seconds_); | 196 interval_seconds_); |
200 } | 197 } |
201 | 198 |
202 device::GvrDelegate* VrShellDelegate::GetDelegate() { | 199 device::GvrDelegate* VrShellDelegate::GetDelegate() { |
203 if (delegate_) | 200 if (delegate_) |
204 return delegate_; | 201 return delegate_; |
205 return non_presenting_delegate_.get(); | 202 return non_presenting_delegate_.get(); |
(...skipping 16 matching lines...) Expand all Loading... |
222 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 219 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
223 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); | 220 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); |
224 } | 221 } |
225 | 222 |
226 static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) { | 223 static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) { |
227 device::GvrDelegateProvider::SetInstance( | 224 device::GvrDelegateProvider::SetInstance( |
228 base::Bind(&VrShellDelegate::CreateVrShellDelegate)); | 225 base::Bind(&VrShellDelegate::CreateVrShellDelegate)); |
229 } | 226 } |
230 | 227 |
231 } // namespace vr_shell | 228 } // namespace vr_shell |
OLD | NEW |