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