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 "device/vr/android/gvr/gvr_device_provider.h" | 5 #include "device/vr/android/gvr/gvr_device_provider.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 | 8 |
9 #include "base/android/context_utils.h" | 9 #include "base/android/context_utils.h" |
10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 bool GvrDeviceProvider::RequestPresent() { | 58 bool GvrDeviceProvider::RequestPresent() { |
59 device::GvrDelegateProvider* delegate_provider = | 59 device::GvrDelegateProvider* delegate_provider = |
60 device::GvrDelegateProvider::GetInstance(); | 60 device::GvrDelegateProvider::GetInstance(); |
61 if (!delegate_provider) | 61 if (!delegate_provider) |
62 return false; | 62 return false; |
63 | 63 |
64 // RequestWebVRPresent is async as a render thread may be created. | 64 // RequestWebVRPresent is async as a render thread may be created. |
65 return delegate_provider->RequestWebVRPresent(this); | 65 return delegate_provider->RequestWebVRPresent(this); |
66 } | 66 } |
67 | 67 |
68 // VR presentation exit requested by the API | |
mthiesse
2016/11/14 16:24:12
super nit: periods at the end of comments, here an
| |
68 void GvrDeviceProvider::ExitPresent() { | 69 void GvrDeviceProvider::ExitPresent() { |
69 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); | 70 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
70 | 71 |
71 if (!vr_device_) | 72 SwitchToNonPresentingDelegate(); |
mthiesse
2016/11/14 16:24:12
Why do we not call vr_device_->OnExitPresent() her
bajones
2016/11/14 19:35:43
This is confusing (need to look at how to make thi
mthiesse
2016/11/14 20:06:49
Fine to leave it for now I guess, but that definit
| |
72 return; | |
73 | |
74 device::GvrDelegateProvider* delegate_provider = | |
75 device::GvrDelegateProvider::GetInstance(); | |
76 if (!delegate_provider) | |
77 return; | |
78 | |
79 vr_device_->SetDelegate(delegate_provider->GetNonPresentingDelegate()); | |
80 | |
81 GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory( | |
82 GAMEPAD_SOURCE_GVR); | |
83 | |
84 delegate_provider->ExitWebVRPresent(); | |
85 } | 73 } |
86 | 74 |
87 void GvrDeviceProvider::OnGvrDelegateReady(GvrDelegate* delegate) { | 75 void GvrDeviceProvider::OnGvrDelegateReady(GvrDelegate* delegate) { |
88 main_thread_task_runner_->PostTask( | 76 main_thread_task_runner_->PostTask( |
89 FROM_HERE, | 77 FROM_HERE, |
90 base::Bind(&GvrDeviceProvider::GvrDelegateReady, base::Unretained(this), | 78 base::Bind(&GvrDeviceProvider::GvrDelegateReady, base::Unretained(this), |
91 base::Unretained(delegate))); | 79 base::Unretained(delegate))); |
92 } | 80 } |
93 | 81 |
82 // VR presentation exit requested by the delegate (probably via UI) | |
94 void GvrDeviceProvider::OnGvrDelegateRemoved() { | 83 void GvrDeviceProvider::OnGvrDelegateRemoved() { |
95 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); | 84 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
96 if (!vr_device_) | 85 if (!vr_device_) |
97 return; | 86 return; |
98 ExitPresent(); | 87 |
88 SwitchToNonPresentingDelegate(); | |
89 vr_device_->OnExitPresent(); | |
99 } | 90 } |
100 | 91 |
101 void GvrDeviceProvider::GvrDelegateReady(GvrDelegate* delegate) { | 92 void GvrDeviceProvider::GvrDelegateReady(GvrDelegate* delegate) { |
102 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); | 93 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
103 | 94 |
104 vr_device_->SetDelegate(delegate); | 95 vr_device_->SetDelegate(delegate); |
105 GamepadDataFetcherManager::GetInstance()->AddFactory( | 96 GamepadDataFetcherManager::GetInstance()->AddFactory( |
106 new GvrGamepadDataFetcher::Factory(delegate, vr_device_->id())); | 97 new GvrGamepadDataFetcher::Factory(delegate, vr_device_->id())); |
107 } | 98 } |
108 | 99 |
100 void GvrDeviceProvider::SwitchToNonPresentingDelegate() { | |
101 GvrDelegateProvider* delegate_provider = GvrDelegateProvider::GetInstance(); | |
102 if (!vr_device_ || !delegate_provider) | |
103 return; | |
104 | |
105 vr_device_->SetDelegate(delegate_provider->GetNonPresentingDelegate()); | |
106 | |
107 // Remove GVR gamepad polling. | |
108 GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory( | |
109 GAMEPAD_SOURCE_GVR); | |
110 | |
111 // If we're presenting currently stop. | |
112 delegate_provider->ExitWebVRPresent(); | |
113 } | |
114 | |
109 } // namespace device | 115 } // namespace device |
OLD | NEW |